diff --git a/internal/common/room.go b/internal/common/room.go index ef0a8f4..d8ec238 100644 --- a/internal/common/room.go +++ b/internal/common/room.go @@ -185,20 +185,8 @@ func (room *Room) UpdateFromParticipant(voterReceived Participant) { for i, voter := range room.Voters { // update room with data received from player if voter.Id == voterReceived.Id { - room.Voters[i] = &voterReceived - log.Debug().Msgf("last command from %s: %s, vote: %s", room.Voters[i].Name, voterReceived.LastCommand, voterReceived.Vote) - switch voterReceived.LastCommand { - case CommandStartVote: - room.OpenVote() - case CommandCloseVote: - // update status of the received voter based on existing vote existence - if voterReceived.Vote == VoteNotReceived { - voterReceived.LastCommand = VoteNotReceived - } else { - voterReceived.LastCommand = VoteReceived - } - room.CloseVote() - } + // update status of the received voter based on existing vote existence + updateRoomFromReceivedPlayer(room, i, voterReceived) break } @@ -213,6 +201,23 @@ func (room *Room) UpdateFromParticipant(voterReceived Participant) { room.updateFromVotes() } +func updateRoomFromReceivedPlayer(room *Room, i int, voterReceived Participant) { + room.Voters[i] = &voterReceived + log.Debug().Msgf("last command from %s: %s, vote: %s", room.Voters[i].Name, voterReceived.LastCommand, voterReceived.Vote) + switch voterReceived.LastCommand { + case CommandStartVote: + room.OpenVote() + case CommandCloseVote: + + if voterReceived.Vote == VoteNotReceived { + voterReceived.LastCommand = VoteNotReceived + } else { + voterReceived.LastCommand = VoteReceived + } + room.CloseVote() + } +} + func updateCommandMenu(room *Room, i int, voterReceived Participant) { if room.RoomStatus == VoteOpen { for k := range room.TurnStartedCommands() {