diff --git a/game/store.go b/game/store.go index 13a9972..2f820c3 100644 --- a/game/store.go +++ b/game/store.go @@ -50,24 +50,6 @@ func GenerateID(size int) string { return hex.EncodeToString(b) } -func GenerateNickname() string { - adjectives := []string{ - "Swift", "Happy", "Clever", "Brave", "Mighty", - "Quick", "Calm", "Bold", "Lucky", "Wise", - "Eager", "Noble", "Keen", "Bright", "Vivid", - } - nouns := []string{ - "Tiger", "Falcon", "Dragon", "Phoenix", "Wolf", - "Eagle", "Panda", "Otter", "Fox", "Bear", - "Hawk", "Lion", "Raven", "Shark", "Owl", - } - b := make([]byte, 2) - rand.Read(b) - adj := adjectives[int(b[0])%len(adjectives)] - noun := nouns[int(b[1])%len(nouns)] - return adj + " " + noun -} - type GameInstance struct { game *Game gameMu sync.RWMutex diff --git a/main.go b/main.go index 9e0c77d..c22b782 100644 --- a/main.go +++ b/main.go @@ -106,35 +106,16 @@ func main() { c.Sync() }) - // Auto-join logic - if gameExists && gi.GetPlayerColor(playerID) == 0 { - g := gi.GetGame() - // Invitee: game is waiting for second player - auto-generate nickname and join - if g.Status == game.StatusWaitingForPlayer { - name := sessionNickname - if name == "" { - name = game.GenerateNickname() - c.Session().Set("nickname", name) - } - player := &game.Player{ - ID: playerID, - Nickname: name, - } - gi.Join(&game.PlayerSession{ - Player: player, - Sync: c, - }) - } else if sessionNickname != "" { - // Reconnecting player with existing nickname - player := &game.Player{ - ID: playerID, - Nickname: sessionNickname, - } - gi.Join(&game.PlayerSession{ - Player: player, - Sync: c, - }) + // If nickname exists in session and game exists, join immediately + if gameExists && sessionNickname != "" && gi.GetPlayerColor(playerID) == 0 { + player := &game.Player{ + ID: playerID, + Nickname: sessionNickname, } + gi.Join(&game.PlayerSession{ + Player: player, + Sync: c, + }) } c.View(func() h.H {