Compare commits
2 Commits
f97d91ac74
...
a685686b32
Author | SHA1 | Date | |
---|---|---|---|
a685686b32 | |||
9900ebd3dd |
3
Makefile
3
Makefile
@ -1,7 +1,6 @@
|
|||||||
.PHONY: all init deps install test lint run stop
|
.PHONY: all init deps install test lint run stop
|
||||||
|
|
||||||
run:
|
run: migrate-up
|
||||||
make migrate-up
|
|
||||||
go build
|
go build
|
||||||
./gralias start
|
./gralias start
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
Server says: <br>
|
Server says: <br>
|
||||||
<ul>
|
<ul>
|
||||||
{{range .Room.LogJournal}}
|
{{range .Room.LogJournal}}
|
||||||
<li>{{.}}</li>
|
<li>{{.Username}}: {{.Entry}}</li>
|
||||||
{{end}}
|
{{end}}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
@ -46,7 +46,6 @@ func (cm *CronManager) CleanupRooms() {
|
|||||||
panic(r)
|
panic(r)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
rooms, err := cm.repo.RoomList(ctx)
|
rooms, err := cm.repo.RoomList(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cm.log.Error("failed to get rooms list", "err", err)
|
cm.log.Error("failed to get rooms list", "err", err)
|
||||||
@ -55,7 +54,6 @@ func (cm *CronManager) CleanupRooms() {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, room := range rooms {
|
for _, room := range rooms {
|
||||||
players, err := cm.repo.PlayerListByRoom(ctx, room.ID)
|
players, err := cm.repo.PlayerListByRoom(ctx, room.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -73,7 +71,6 @@ func (cm *CronManager) CleanupRooms() {
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
creatorInRoom := false
|
creatorInRoom := false
|
||||||
for _, player := range players {
|
for _, player := range players {
|
||||||
if player.Username == room.CreatorName {
|
if player.Username == room.CreatorName {
|
||||||
@ -81,7 +78,6 @@ func (cm *CronManager) CleanupRooms() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !creatorInRoom {
|
if !creatorInRoom {
|
||||||
cm.log.Info("deleting room because creator left", "room_id", room.ID)
|
cm.log.Info("deleting room because creator left", "room_id", room.ID)
|
||||||
for _, player := range players {
|
for _, player := range players {
|
||||||
@ -103,7 +99,6 @@ func (cm *CronManager) CleanupRooms() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := tx.Commit(); err != nil {
|
if err := tx.Commit(); err != nil {
|
||||||
cm.log.Error("failed to commit transaction", "err", err)
|
cm.log.Error("failed to commit transaction", "err", err)
|
||||||
}
|
}
|
||||||
@ -123,7 +118,6 @@ func (cm *CronManager) CleanupActions() {
|
|||||||
panic(r)
|
panic(r)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err := cm.repo.ActionDeleteOrphaned(ctx); err != nil {
|
if err := cm.repo.ActionDeleteOrphaned(ctx); err != nil {
|
||||||
cm.log.Error("failed to delete orphaned actions", "err", err)
|
cm.log.Error("failed to delete orphaned actions", "err", err)
|
||||||
if err := tx.Rollback(); err != nil {
|
if err := tx.Rollback(); err != nil {
|
||||||
@ -131,7 +125,6 @@ func (cm *CronManager) CleanupActions() {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := tx.Commit(); err != nil {
|
if err := tx.Commit(); err != nil {
|
||||||
cm.log.Error("failed to commit transaction for actions cleanup", "err", err)
|
cm.log.Error("failed to commit transaction for actions cleanup", "err", err)
|
||||||
}
|
}
|
||||||
@ -183,4 +176,3 @@ func (cm *CronManager) CleanupInactiveRooms() {
|
|||||||
cm.log.Error("failed to commit transaction for inactive rooms cleanup", "err", err)
|
cm.log.Error("failed to commit transaction for inactive rooms cleanup", "err", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,26 +174,6 @@ func joinTeam(ctx context.Context, role, team string) (*models.FullInfo, error)
|
|||||||
return fi, nil
|
return fi, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// get all rooms
|
|
||||||
// func listRooms(allRooms bool) []*models.Room {
|
|
||||||
// cacheMap := memcache.GetAll()
|
|
||||||
// publicRooms := []*models.Room{}
|
|
||||||
// // no way to know if room is public until unmarshal -_-;
|
|
||||||
// for key, value := range cacheMap {
|
|
||||||
// if strings.HasPrefix(key, models.CacheRoomPrefix) {
|
|
||||||
// room := &models.Room{}
|
|
||||||
// if err := json.Unmarshal(value, &room); err != nil {
|
|
||||||
// log.Warn("failed to unmarshal room", "error", err)
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
// if room.IsPublic || allRooms {
|
|
||||||
// publicRooms = append(publicRooms, room)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return publicRooms
|
|
||||||
// }
|
|
||||||
|
|
||||||
// get bots
|
// get bots
|
||||||
func listBots() []models.Player {
|
func listBots() []models.Player {
|
||||||
bots, err := repo.PlayerList(context.Background(), true)
|
bots, err := repo.PlayerList(context.Background(), true)
|
||||||
@ -214,6 +194,9 @@ func notify(event, msg string) {
|
|||||||
func loadCards(room *models.Room) {
|
func loadCards(room *models.Room) {
|
||||||
// remove old cards
|
// remove old cards
|
||||||
room.Cards = []models.WordCard{}
|
room.Cards = []models.WordCard{}
|
||||||
|
// try to delete old cards from db (in case players play another round)
|
||||||
|
// nolint: errcheck
|
||||||
|
repo.WordCardsDeleteByRoomID(context.Background(), room.ID)
|
||||||
// store it somewhere
|
// store it somewhere
|
||||||
wordMap := map[string]string{
|
wordMap := map[string]string{
|
||||||
"en": "assets/words/en_nouns.txt",
|
"en": "assets/words/en_nouns.txt",
|
||||||
|
@ -188,7 +188,8 @@ func (b *Bot) BotMove() {
|
|||||||
b.log.Error("bot loop", "error", err)
|
b.log.Error("bot loop", "error", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
eventName := models.NotifyBacklogPrefix + room.ID
|
// eventName := models.NotifyBacklogPrefix + room.ID
|
||||||
|
eventName := models.NotifyRoomUpdatePrefix + room.ID
|
||||||
eventPayload := ""
|
eventPayload := ""
|
||||||
defer func() { // save room
|
defer func() { // save room
|
||||||
if err := saveRoom(room); err != nil {
|
if err := saveRoom(room); err != nil {
|
||||||
@ -247,11 +248,15 @@ func (b *Bot) BotMove() {
|
|||||||
room.ActionHistory = append(room.ActionHistory, action)
|
room.ActionHistory = append(room.ActionHistory, action)
|
||||||
room.MimeDone = true
|
room.MimeDone = true
|
||||||
entry := fmt.Sprintf("meant to open: %v", tempMap["words_I_mean_my_team_to_open"])
|
entry := fmt.Sprintf("meant to open: %v", tempMap["words_I_mean_my_team_to_open"])
|
||||||
room.LogJournal = append(room.LogJournal, models.Journal{
|
lj := models.Journal{
|
||||||
Entry: entry,
|
Entry: entry,
|
||||||
Username: b.BotName,
|
Username: b.BotName,
|
||||||
RoomID: room.ID,
|
RoomID: room.ID,
|
||||||
})
|
}
|
||||||
|
room.LogJournal = append(room.LogJournal, lj)
|
||||||
|
if err := repo.JournalCreate(context.Background(), &lj); err != nil {
|
||||||
|
b.log.Warn("failed to write to journal", "entry", lj)
|
||||||
|
}
|
||||||
eventPayload = mimeResp.Clue + mimeResp.Number
|
eventPayload = mimeResp.Clue + mimeResp.Number
|
||||||
guessLimitU64, err := strconv.ParseUint(mimeResp.Number, 10, 8)
|
guessLimitU64, err := strconv.ParseUint(mimeResp.Number, 10, 8)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -267,6 +272,7 @@ func (b *Bot) BotMove() {
|
|||||||
b.log.Error("failed to create action", "error", err)
|
b.log.Error("failed to create action", "error", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// StartTurnTimer(fi.Room.ID, fi.Room.Settings.RoundTime)
|
||||||
if err := saveRoom(room); err != nil {
|
if err := saveRoom(room); err != nil {
|
||||||
b.log.Error("failed to save room", "error", err)
|
b.log.Error("failed to save room", "error", err)
|
||||||
return
|
return
|
||||||
@ -291,13 +297,17 @@ func (b *Bot) BotMove() {
|
|||||||
b.log.Warn("failed to parse could_be", "bot_resp", tempMap, "bot_name", b.BotName)
|
b.log.Warn("failed to parse could_be", "bot_resp", tempMap, "bot_name", b.BotName)
|
||||||
}
|
}
|
||||||
entry := fmt.Sprintf("also considered this: %v", couldBe)
|
entry := fmt.Sprintf("also considered this: %v", couldBe)
|
||||||
room.LogJournal = append(room.LogJournal, models.Journal{
|
lj := models.Journal{
|
||||||
Entry: entry,
|
Entry: entry,
|
||||||
Username: b.BotName,
|
Username: b.BotName,
|
||||||
RoomID: room.ID,
|
RoomID: room.ID,
|
||||||
})
|
}
|
||||||
eventName = models.NotifyRoomUpdatePrefix + room.ID
|
room.LogJournal = append(room.LogJournal, lj)
|
||||||
eventPayload = ""
|
if err := repo.JournalCreate(context.Background(), &lj); err != nil {
|
||||||
|
b.log.Warn("failed to write to journal", "entry", lj)
|
||||||
|
}
|
||||||
|
// eventName = models.NotifyRoomUpdatePrefix + room.ID
|
||||||
|
// eventPayload = ""
|
||||||
// TODO: needs to decide if it wants to open the next cardword or end turn
|
// TODO: needs to decide if it wants to open the next cardword or end turn
|
||||||
// or end turn on limit
|
// or end turn on limit
|
||||||
default:
|
default:
|
||||||
|
7
todos.md
7
todos.md
@ -78,3 +78,10 @@
|
|||||||
|
|
||||||
- bot mime makes a clue -> no update in the room for players;
|
- bot mime makes a clue -> no update in the room for players;
|
||||||
- red moves after bot gave (metal - 3) ended after two guesses (showed in logs, that opened 3. double click on the same card? or somewhere counter is not dropped?); the first guess moved counter to 2, in logs only two requests as expected;
|
- red moves after bot gave (metal - 3) ended after two guesses (showed in logs, that opened 3. double click on the same card? or somewhere counter is not dropped?); the first guess moved counter to 2, in logs only two requests as expected;
|
||||||
|
- bot mime gve a blue -> timer did not start; timer should be in third package, maybe in crons;
|
||||||
|
- log journal is not shown on the page;
|
||||||
|
- marks did not clear after end of the turn (feature?)
|
||||||
|
|
||||||
|
- start new game satrted timer for a mime; (feature? in other cases mime has no timer);
|
||||||
|
- old cards are still around;
|
||||||
|
- timer ended and went to 300;
|
||||||
|
Reference in New Issue
Block a user