Skip to content

Commit 224d24c

Browse files
committed
Fix editing lobby settings
1 parent e59e35b commit 224d24c

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

internal/api/v1.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ func GetPlayer(lobby *game.Lobby, request *http.Request) *game.Player {
513513
return nil
514514
}
515515

516-
return lobby.GetPlayer(userSession)
516+
return lobby.GetPlayerBySession(userSession)
517517
}
518518

519519
// GetPlayername either retrieves the playername from a cookie, the URL form.

internal/api/ws.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (handler *V1Handler) websocketUpgrade(writer http.ResponseWriter, request *
5656
}
5757

5858
lobby.Synchronized(func() {
59-
player := lobby.GetPlayer(userSession)
59+
player := lobby.GetPlayerBySession(userSession)
6060
if player == nil {
6161
http.Error(writer, "you don't have access to this lobby;usersession unknown", http.StatusUnauthorized)
6262
return

internal/game/data.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,17 @@ const (
138138
Spectating PlayerState = "spectating"
139139
)
140140

141-
// GetPlayer searches for a player, identifying them by usersession.
142-
func (lobby *Lobby) GetPlayer(userSession uuid.UUID) *Player {
141+
func (lobby *Lobby) GetPlayerByID(id uuid.UUID) *Player {
142+
for _, player := range lobby.players {
143+
if player.ID == player.ID {
144+
return player
145+
}
146+
}
147+
148+
return nil
149+
}
150+
151+
func (lobby *Lobby) GetPlayerBySession(userSession uuid.UUID) *Player {
143152
for _, player := range lobby.players {
144153
if player.userSession == userSession {
145154
return player
@@ -150,7 +159,7 @@ func (lobby *Lobby) GetPlayer(userSession uuid.UUID) *Player {
150159
}
151160

152161
func (lobby *Lobby) GetOwner() *Player {
153-
return lobby.GetPlayer(lobby.OwnerID)
162+
return lobby.GetPlayerByID(lobby.OwnerID)
154163
}
155164

156165
func (lobby *Lobby) ClearDrawing() {

0 commit comments

Comments
 (0)