Auto-generate nicknames for invitees joining via link

Invitees no longer need to enter a nickname - they automatically
join with a random name like "Swift Tiger" or "Happy Falcon".
Game creators still enter their nickname manually.
This commit is contained in:
Ryan Hamamura
2026-01-14 14:45:04 -10:00
parent 63d0773ab5
commit 32e4e61635
2 changed files with 46 additions and 9 deletions

37
main.go
View File

@@ -106,16 +106,35 @@ func main() {
c.Sync()
})
// If nickname exists in session and game exists, join immediately
if gameExists && sessionNickname != "" && gi.GetPlayerColor(playerID) == 0 {
player := &game.Player{
ID: playerID,
Nickname: sessionNickname,
// 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,
})
}
gi.Join(&game.PlayerSession{
Player: player,
Sync: c,
})
}
c.View(func() h.H {