feat(authentication): authed lobby-joining method
Players can now join by their authenticatied account to lobbies. Only one account can join to a specific lobby.
This commit is contained in:
+10
-4
@@ -1024,7 +1024,7 @@ func (lobby *Lobby) selectWord(index int) error {
|
||||
// optionally returns an error, if any occurred during creation.
|
||||
func CreateLobby(
|
||||
desiredLobbyId string,
|
||||
playerName, chosenLanguage string,
|
||||
playerName string, playerID uuid.UUID, chosenLanguage string,
|
||||
publicLobby bool,
|
||||
drawingTime, rounds, maxPlayers, wordsPerTurn, customWordsPerTurn, clientsPerIPLimit int,
|
||||
customWords []string,
|
||||
@@ -1074,7 +1074,7 @@ func CreateLobby(
|
||||
}
|
||||
}
|
||||
|
||||
player := lobby.JoinPlayer(playerName)
|
||||
player := lobby.JoinPlayer(playerName, playerID)
|
||||
lobby.OwnerID = player.ID
|
||||
|
||||
return player, lobby, nil
|
||||
@@ -1202,10 +1202,10 @@ func (lobby *Lobby) GetAvailableWordHints(player *Player) []*WordHint {
|
||||
|
||||
// JoinPlayer creates a new player object using the given name and adds it
|
||||
// to the lobbies playerlist. The new players is returned.
|
||||
func (lobby *Lobby) JoinPlayer(name string) *Player {
|
||||
func (lobby *Lobby) JoinPlayer(name string, id uuid.UUID) *Player {
|
||||
player := &Player{
|
||||
Name: SanitizeName(name),
|
||||
ID: uuid.Must(uuid.NewV4()),
|
||||
ID: id,
|
||||
userSession: uuid.Must(uuid.NewV4()),
|
||||
votedForKick: make(map[uuid.UUID]bool),
|
||||
messageTimestamps: NewRing[time.Time](5),
|
||||
@@ -1220,6 +1220,12 @@ func (lobby *Lobby) JoinPlayer(name string) *Player {
|
||||
}
|
||||
lobby.players = append(lobby.players, player)
|
||||
|
||||
// log.Print("List of players {")
|
||||
// for _, v := range lobby.players {
|
||||
// log.Print(v.ID, " ", v.Name, " ", v.userSession)
|
||||
// }
|
||||
// log.Print("}")
|
||||
|
||||
return player
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user