Feat: nullable roomid
This commit is contained in:
		| @@ -300,11 +300,14 @@ func recoverBots() { | ||||
|  | ||||
| func recoverBot(bm models.Player) error { | ||||
| 	// check if room still exists | ||||
| 	if _, err := repo.RoomGetByID(context.Background(), bm.RoomID); err != nil { | ||||
| 		return fmt.Errorf("no such room: %s; err: %w", bm.RoomID, err) | ||||
| 	if bm.RoomID == nil { | ||||
| 		return errors.New("bot has no room id") | ||||
| 	} | ||||
| 	if _, err := repo.RoomGetByID(context.Background(), *bm.RoomID); err != nil { | ||||
| 		return fmt.Errorf("no such room: %s; err: %w", *bm.RoomID, err) | ||||
| 	} | ||||
| 	log.Debug("recovering bot", "bot", bm) | ||||
| 	_, err := llmapi.NewBot(string(bm.Role), string(bm.Team), bm.Username, bm.RoomID, cfg, true) | ||||
| 	_, err := llmapi.NewBot(string(bm.Role), string(bm.Team), bm.Username, *bm.RoomID, cfg, true) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|   | ||||
| @@ -110,8 +110,11 @@ func HandleFrontLogin(w http.ResponseWriter, r *http.Request) { | ||||
| 		// room.PlayerList = append(room.PlayerList, fi.State.Username) | ||||
| 		fi.Room = room | ||||
| 		fi.List = nil | ||||
| 		fi.State.RoomID = room.ID | ||||
| 		repo.PlayerSetRoomID(r.Context(), fi.State.Username, room.ID) | ||||
| 		fi.State.RoomID = &room.ID | ||||
| 		if err := repo.PlayerSetRoomID(r.Context(), fi.State.Username, room.ID); err != nil { | ||||
| 			abortWithError(w, err.Error()) | ||||
| 			return | ||||
| 		} | ||||
| 		// repo.RoomUpdate() | ||||
| 		// save full info instead | ||||
| 		// if err := saveFullInfo(r.Context(), fi); err != nil { | ||||
| @@ -191,6 +194,7 @@ func makeCookie(username string, remote string) (*http.Cookie, error) { | ||||
| 	return cookie, nil | ||||
| } | ||||
|  | ||||
| //nolint: unused | ||||
| func cacheGetSession(key string) (*models.Session, error) { | ||||
| 	userSessionB, err := cache.MemCache.Get(key) | ||||
| 	if err != nil { | ||||
|   | ||||
| @@ -38,7 +38,7 @@ func HandleCreateRoom(w http.ResponseWriter, r *http.Request) { | ||||
| 		abortWithError(w, msg) | ||||
| 		return | ||||
| 	} | ||||
| 	fi.State.RoomID = room.ID | ||||
| 	fi.State.RoomID = &room.ID | ||||
| 	fi.Room = room | ||||
| 	if err := repo.RoomCreate(r.Context(), room); err != nil { | ||||
| 		log.Error("failed to create a room", "error", err) | ||||
| @@ -223,7 +223,7 @@ func HandleJoinRoom(w http.ResponseWriter, r *http.Request) { | ||||
| 		return | ||||
| 	} | ||||
| 	// room.PlayerList = append(room.PlayerList, fi.State.Username) | ||||
| 	fi.State.RoomID = room.ID | ||||
| 	fi.State.RoomID = &room.ID | ||||
| 	fi.Room = room | ||||
| 	fi.List = nil | ||||
| 	if err := saveFullInfo(r.Context(), fi); err != nil { | ||||
|   | ||||
| @@ -2,8 +2,8 @@ package handlers | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"fmt" | ||||
| 	"gralias/models" | ||||
| 	"strconv" | ||||
| 	"sync" | ||||
| 	"time" | ||||
| ) | ||||
| @@ -46,7 +46,7 @@ func StartTurnTimer(roomID string, duration time.Duration) { | ||||
| 					if err := repo.RoomUpdate(context.Background(), room); err != nil { | ||||
| 						log.Error("failed to save room", "error", err) | ||||
| 					} | ||||
| 					notify(models.NotifyTurnTimerPrefix+room.ID, fmt.Sprintf("%d", room.Settings.TurnSecondsLeft)) | ||||
| 					notify(models.NotifyTurnTimerPrefix+room.ID, strconv.FormatUint(uint64(room.Settings.TurnSecondsLeft), 10)) | ||||
| 					notifyBotIfNeeded(room) | ||||
| 					StopTurnTimer(roomID) | ||||
| 					return | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder