mirror of
https://github.com/HexCardGames/HexDeck.git
synced 2025-09-05 19:18:39 +02:00
feat(backend): implement changing card deck
This commit is contained in:
@ -95,6 +95,36 @@ func onPlayerJoin(client *socketio.Socket, room *types.Room, player *types.Playe
|
||||
game.OnRoomUpdate(room)
|
||||
})
|
||||
|
||||
client.On("SetCardDeck", func(datas ...any) {
|
||||
setCardDeckRequest := types.C2S_SetCardDeck{}
|
||||
unpackData(datas, &setCardDeckRequest)
|
||||
|
||||
if room.GameState != types.StateLobby {
|
||||
client.Emit("Status", types.S2C_Status{
|
||||
IsError: true,
|
||||
StatusCode: "game_already_running",
|
||||
Message: "You can't change the card deck while the game is running",
|
||||
})
|
||||
return
|
||||
}
|
||||
if !player.HasPermissionBit(types.PermissionHost) {
|
||||
client.Emit("Status", types.S2C_Status{
|
||||
IsError: true,
|
||||
StatusCode: "insufficient_permission",
|
||||
Message: "You can't change the card deck unless you are host",
|
||||
})
|
||||
return
|
||||
}
|
||||
if !game.SetCardDeck(room, setCardDeckRequest.CardDeckId) {
|
||||
client.Emit("Status", types.S2C_Status{
|
||||
IsError: true,
|
||||
StatusCode: "invalid_card_deck",
|
||||
Message: "No card deck exists with this ID",
|
||||
})
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
client.On("UpdatePlayer", func(datas ...any) {
|
||||
player.Mutex.Lock()
|
||||
defer player.Mutex.Unlock()
|
||||
|
Reference in New Issue
Block a user