gameServer/Votes.hs
author nemo
Sun, 24 Mar 2024 14:33:57 -0400
changeset 16024 4c523ed1d35c
parent 16012 2c92499daa67
permissions -rw-r--r--
merge the lobby suppression
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10464
d08611b52000 Added two copyrights on gameServer
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
     1
{-
d08611b52000 Added two copyrights on gameServer
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
     2
 * Hedgewars, a free turn based strategy game
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10881
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
10464
d08611b52000 Added two copyrights on gameServer
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
     4
 *
d08611b52000 Added two copyrights on gameServer
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
d08611b52000 Added two copyrights on gameServer
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
d08611b52000 Added two copyrights on gameServer
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
d08611b52000 Added two copyrights on gameServer
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
     8
 *
d08611b52000 Added two copyrights on gameServer
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
d08611b52000 Added two copyrights on gameServer
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d08611b52000 Added two copyrights on gameServer
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d08611b52000 Added two copyrights on gameServer
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
    12
 * GNU General Public License for more details.
d08611b52000 Added two copyrights on gameServer
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
    13
 *
d08611b52000 Added two copyrights on gameServer
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
    14
 * You should have received a copy of the GNU General Public License
d08611b52000 Added two copyrights on gameServer
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
    15
 * along with this program; if not, write to the Free Software
d08611b52000 Added two copyrights on gameServer
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
    16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
d08611b52000 Added two copyrights on gameServer
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
    17
 \-}
d08611b52000 Added two copyrights on gameServer
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10392
diff changeset
    18
10058
4ed428389c4e - Implement /callvote
unc0rr
parents: 10049
diff changeset
    19
{-# LANGUAGE OverloadedStrings #-}
10049
ca11d122f54e Oops, forgot this
unc0rr
parents:
diff changeset
    20
module Votes where
ca11d122f54e Oops, forgot this
unc0rr
parents:
diff changeset
    21
16012
2c92499daa67 Fix server build with modern mtl library
Vekhir
parents: 14138
diff changeset
    22
import Control.Monad
10049
ca11d122f54e Oops, forgot this
unc0rr
parents:
diff changeset
    23
import Control.Monad.Reader
10216
6928a323097f Fix build
unc0rr
parents: 10215
diff changeset
    24
import Control.Monad.State.Strict
10049
ca11d122f54e Oops, forgot this
unc0rr
parents:
diff changeset
    25
import ServerState
10058
4ed428389c4e - Implement /callvote
unc0rr
parents: 10049
diff changeset
    26
import qualified Data.ByteString.Char8 as B
10081
0af84e5cbd4d Implement 'voted' function
unc0rr
parents: 10058
diff changeset
    27
import qualified Data.List as L
10195
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10090
diff changeset
    28
import qualified Data.Map as Map
10058
4ed428389c4e - Implement /callvote
unc0rr
parents: 10049
diff changeset
    29
import Data.Maybe
10880
bf64f1bef1cc Send notice when accepting vote
unc0rr
parents: 10879
diff changeset
    30
import Control.Applicative
10058
4ed428389c4e - Implement /callvote
unc0rr
parents: 10049
diff changeset
    31
-------------------
13509
f747c385b5ba Server: Replace hardcoded hog-related numbers with consts
Wuzzy <Wuzzy2@mail.ru>
parents: 13079
diff changeset
    32
import Consts
10058
4ed428389c4e - Implement /callvote
unc0rr
parents: 10049
diff changeset
    33
import Utils
4ed428389c4e - Implement /callvote
unc0rr
parents: 10049
diff changeset
    34
import CoreTypes
4ed428389c4e - Implement /callvote
unc0rr
parents: 10049
diff changeset
    35
import HandlerUtils
10392
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10218
diff changeset
    36
import EngineInteraction
10049
ca11d122f54e Oops, forgot this
unc0rr
parents:
diff changeset
    37
10081
0af84e5cbd4d Implement 'voted' function
unc0rr
parents: 10058
diff changeset
    38
10881
941b5ab9e5a6 "/force" command for server admin to force voting result
unc0rr
parents: 10880
diff changeset
    39
voted :: Bool -> Bool -> Reader (ClientIndex, IRnC) [Action]
941b5ab9e5a6 "/force" command for server admin to force voting result
unc0rr
parents: 10880
diff changeset
    40
voted forced vote = do
10081
0af84e5cbd4d Implement 'voted' function
unc0rr
parents: 10058
diff changeset
    41
    cl <- thisClient
0af84e5cbd4d Implement 'voted' function
unc0rr
parents: 10058
diff changeset
    42
    rm <- thisRoom
0af84e5cbd4d Implement 'voted' function
unc0rr
parents: 10058
diff changeset
    43
    uid <- liftM clUID thisClient
0af84e5cbd4d Implement 'voted' function
unc0rr
parents: 10058
diff changeset
    44
10392
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10218
diff changeset
    45
    case voting rm of
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10218
diff changeset
    46
        Nothing -> 
14138
d6915d15b6de GameServer: Turn some messages into warnings
Wuzzy <Wuzzy2@mail.ru>
parents: 13696
diff changeset
    47
            return [Warning $ loc "There's no voting going on."]
10392
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10218
diff changeset
    48
        Just voting ->
10881
941b5ab9e5a6 "/force" command for server admin to force voting result
unc0rr
parents: 10880
diff changeset
    49
            if (not forced) && (uid `L.notElem` entitledToVote voting) then
10392
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10218
diff changeset
    50
                return []
10881
941b5ab9e5a6 "/force" command for server admin to force voting result
unc0rr
parents: 10880
diff changeset
    51
            else if (not forced) && (uid `L.elem` map fst (votes voting)) then
14138
d6915d15b6de GameServer: Turn some messages into warnings
Wuzzy <Wuzzy2@mail.ru>
parents: 13696
diff changeset
    52
                return [Warning $ loc "You already have voted."]
10881
941b5ab9e5a6 "/force" command for server admin to force voting result
unc0rr
parents: 10880
diff changeset
    53
            else if forced && (not $ isAdministrator cl) then
941b5ab9e5a6 "/force" command for server admin to force voting result
unc0rr
parents: 10880
diff changeset
    54
                return []
10392
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10218
diff changeset
    55
            else
13696
d732ca5dcab9 GameServer: Refactor fake nick names into Consts
Wuzzy <Wuzzy2@mail.ru>
parents: 13509
diff changeset
    56
                ((:) (AnswerClients [sendChan cl] ["CHAT", nickServer, loc "Your vote has been counted."]))
10880
bf64f1bef1cc Send notice when accepting vote
unc0rr
parents: 10879
diff changeset
    57
                <$> (actOnVoting $ voting{votes = (uid, vote):votes voting})
10786
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10464
diff changeset
    58
10087
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    59
    where
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    60
    actOnVoting :: Voting -> Reader (ClientIndex, IRnC) [Action]
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    61
    actOnVoting vt = do
10212
5fb3bb2de9d2 Some fixes to voting + small refactoring
unc0rr
parents: 10195
diff changeset
    62
        let (pro, contra) = L.partition snd $ votes vt
10392
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10218
diff changeset
    63
        let totalV = length $ entitledToVote vt 
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10218
diff changeset
    64
        let successV = totalV `div` 2 + 1
10087
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    65
10881
941b5ab9e5a6 "/force" command for server admin to force voting result
unc0rr
parents: 10880
diff changeset
    66
        if (forced && not vote) || (length contra > totalV - successV) then
10087
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    67
            closeVoting
10881
941b5ab9e5a6 "/force" command for server admin to force voting result
unc0rr
parents: 10880
diff changeset
    68
        else if (forced && vote) || (length pro >= successV) then do
10215
26fc5502ba22 - Fix applying vote result
unc0rr
parents: 10212
diff changeset
    69
            a <- act $ voteType vt
26fc5502ba22 - Fix applying vote result
unc0rr
parents: 10212
diff changeset
    70
            c <- closeVoting
26fc5502ba22 - Fix applying vote result
unc0rr
parents: 10212
diff changeset
    71
            return $ c ++ a
10087
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    72
        else
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    73
            return [ModifyRoom $ \r -> r{voting = Just vt}]
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    74
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    75
    closeVoting = do
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    76
        chans <- roomClientsChans
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    77
        return [
13696
d732ca5dcab9 GameServer: Refactor fake nick names into Consts
Wuzzy <Wuzzy2@mail.ru>
parents: 13509
diff changeset
    78
            AnswerClients chans ["CHAT", nickServer, loc "Voting closed."]
10087
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    79
            , ModifyRoom (\r -> r{voting = Nothing})
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    80
            ]
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    81
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    82
    act (VoteKick nickname) = do
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    83
        (thisClientId, rnc) <- ask
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    84
        maybeClientId <- clientByNick nickname
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    85
        rm <- thisRoom
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    86
        let kickId = fromJust maybeClientId
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    87
        let kickCl = rnc `client` kickId
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    88
        let sameRoom = clientRoom rnc thisClientId == clientRoom rnc kickId
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    89
        return
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    90
            [KickRoomClient kickId |
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    91
                isJust maybeClientId
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    92
                && sameRoom
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    93
                && ((isNothing $ gameInfo rm) || teamsInGame kickCl == 0)
5ba891578621 Implement kick voting
unc0rr
parents: 10081
diff changeset
    94
            ]
10195
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10090
diff changeset
    95
    act (VoteMap roomSave) = do
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10090
diff changeset
    96
        rm <- thisRoom
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10090
diff changeset
    97
        let rs = Map.lookup roomSave (roomSaves rm)
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10090
diff changeset
    98
        case rs of
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10090
diff changeset
    99
             Nothing -> return []
11575
db7743e2fad1 More work on best time ghost feature
unc0rr
parents: 11046
diff changeset
   100
             Just (location, mp, p) -> do
10218
1d7112ccb3e9 Send updated info on map switched by voting
unc0rr
parents: 10216
diff changeset
   101
                 cl <- thisClient
1d7112ccb3e9 Send updated info on map switched by voting
unc0rr
parents: 10216
diff changeset
   102
                 chans <- roomClientsChans
11575
db7743e2fad1 More work on best time ghost feature
unc0rr
parents: 11046
diff changeset
   103
                 return $
db7743e2fad1 More work on best time ghost feature
unc0rr
parents: 11046
diff changeset
   104
                    [ModifyRoom $ \r -> r{params = p, mapParams = mp}
13696
d732ca5dcab9 GameServer: Refactor fake nick names into Consts
Wuzzy <Wuzzy2@mail.ru>
parents: 13509
diff changeset
   105
                    , AnswerClients chans ["CHAT", nickServer, location]
11575
db7743e2fad1 More work on best time ghost feature
unc0rr
parents: 11046
diff changeset
   106
                    , SendUpdateOnThisRoom
db7743e2fad1 More work on best time ghost feature
unc0rr
parents: 11046
diff changeset
   107
                    , LoadGhost location]
10392
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10218
diff changeset
   108
    act (VotePause) = do
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10218
diff changeset
   109
        rm <- thisRoom
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10218
diff changeset
   110
        chans <- roomClientsChans
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10218
diff changeset
   111
        let modifyGameInfo f room  = room{gameInfo = fmap f $ gameInfo room}
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10218
diff changeset
   112
        return [ModifyRoom (modifyGameInfo $ \g -> g{isPaused = not $ isPaused g}),
13696
d732ca5dcab9 GameServer: Refactor fake nick names into Consts
Wuzzy <Wuzzy2@mail.ru>
parents: 13509
diff changeset
   113
                AnswerClients chans ["CHAT", nickServer, loc "Pause toggled."],
10392
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10218
diff changeset
   114
                AnswerClients chans ["EM", toEngineMsg "I"]]
10786
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10464
diff changeset
   115
    act (VoteNewSeed) =
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10464
diff changeset
   116
        return [SetRandomSeed]
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10464
diff changeset
   117
    act (VoteHedgehogsPerTeam h) = do
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10464
diff changeset
   118
        rm <- thisRoom
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10464
diff changeset
   119
        chans <- roomClientsChans
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10464
diff changeset
   120
        let answers = concatMap (\t -> 
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10464
diff changeset
   121
                [ModifyRoom $ modifyTeam t{hhnum = h}
10787
50a4cdeedb44 Oops, misspelled protocol command
unC0Rr
parents: 10786
diff changeset
   122
                , AnswerClients chans ["HH_NUM", teamname t, showB h]]
13509
f747c385b5ba Server: Replace hardcoded hog-related numbers with consts
Wuzzy <Wuzzy2@mail.ru>
parents: 13079
diff changeset
   123
                ) $ if length curteams * h > cMaxHHs then [] else curteams
10879
9bedbd36de49 Don't change hedgehogs total number to a value > 48 as result of voting.
unc0rr
parents: 10787
diff changeset
   124
            ;
9bedbd36de49 Don't change hedgehogs total number to a value > 48 as result of voting.
unc0rr
parents: 10787
diff changeset
   125
            curteams =
10786
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10464
diff changeset
   126
                if isJust $ gameInfo rm then
10879
9bedbd36de49 Don't change hedgehogs total number to a value > 48 as result of voting.
unc0rr
parents: 10787
diff changeset
   127
                    teamsAtStart . fromJust . gameInfo $ rm
10786
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10464
diff changeset
   128
                else
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10464
diff changeset
   129
                    teams rm
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10464
diff changeset
   130
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10464
diff changeset
   131
        return $ ModifyRoom (\r -> r{defaultHedgehogsNumber = h}) : answers
10081
0af84e5cbd4d Implement 'voted' function
unc0rr
parents: 10058
diff changeset
   132
10049
ca11d122f54e Oops, forgot this
unc0rr
parents:
diff changeset
   133
ca11d122f54e Oops, forgot this
unc0rr
parents:
diff changeset
   134
startVote :: VoteType -> Reader (ClientIndex, IRnC) [Action]
10058
4ed428389c4e - Implement /callvote
unc0rr
parents: 10049
diff changeset
   135
startVote vt = do
4ed428389c4e - Implement /callvote
unc0rr
parents: 10049
diff changeset
   136
    (ci, rnc) <- ask
10090
a471a7bbc339 - Start work on flood detector
unc0rr
parents: 10087
diff changeset
   137
    --cl <- thisClient
10058
4ed428389c4e - Implement /callvote
unc0rr
parents: 10049
diff changeset
   138
    rm <- thisRoom
4ed428389c4e - Implement /callvote
unc0rr
parents: 10049
diff changeset
   139
    chans <- roomClientsChans
4ed428389c4e - Implement /callvote
unc0rr
parents: 10049
diff changeset
   140
4ed428389c4e - Implement /callvote
unc0rr
parents: 10049
diff changeset
   141
    let uids = map (clUID . client rnc) . roomClients rnc $ clientRoom rnc ci
4ed428389c4e - Implement /callvote
unc0rr
parents: 10049
diff changeset
   142
4ed428389c4e - Implement /callvote
unc0rr
parents: 10049
diff changeset
   143
    if isJust $ voting rm then
4ed428389c4e - Implement /callvote
unc0rr
parents: 10049
diff changeset
   144
        return []
4ed428389c4e - Implement /callvote
unc0rr
parents: 10049
diff changeset
   145
    else
10212
5fb3bb2de9d2 Some fixes to voting + small refactoring
unc0rr
parents: 10195
diff changeset
   146
        return [
5fb3bb2de9d2 Some fixes to voting + small refactoring
unc0rr
parents: 10195
diff changeset
   147
            ModifyRoom (\r -> r{voting = Just (newVoting vt){entitledToVote = uids}})
13696
d732ca5dcab9 GameServer: Refactor fake nick names into Consts
Wuzzy <Wuzzy2@mail.ru>
parents: 13509
diff changeset
   148
            , AnswerClients chans ["CHAT", nickServer, B.concat [loc "New voting started", ": ", voteInfo vt]]
10212
5fb3bb2de9d2 Some fixes to voting + small refactoring
unc0rr
parents: 10195
diff changeset
   149
            , ReactCmd ["VOTE", "YES"]
10215
26fc5502ba22 - Fix applying vote result
unc0rr
parents: 10212
diff changeset
   150
        ]
10081
0af84e5cbd4d Implement 'voted' function
unc0rr
parents: 10058
diff changeset
   151
10049
ca11d122f54e Oops, forgot this
unc0rr
parents:
diff changeset
   152
10215
26fc5502ba22 - Fix applying vote result
unc0rr
parents: 10212
diff changeset
   153
checkVotes :: StateT ServerState IO [Action]
26fc5502ba22 - Fix applying vote result
unc0rr
parents: 10212
diff changeset
   154
checkVotes = do
26fc5502ba22 - Fix applying vote result
unc0rr
parents: 10212
diff changeset
   155
    rnc <- gets roomsClients
10216
6928a323097f Fix build
unc0rr
parents: 10215
diff changeset
   156
    liftM concat $ io $ do
10215
26fc5502ba22 - Fix applying vote result
unc0rr
parents: 10212
diff changeset
   157
        ris <- allRoomsM rnc
10216
6928a323097f Fix build
unc0rr
parents: 10215
diff changeset
   158
        mapM (check rnc) ris
10215
26fc5502ba22 - Fix applying vote result
unc0rr
parents: 10212
diff changeset
   159
    where
26fc5502ba22 - Fix applying vote result
unc0rr
parents: 10212
diff changeset
   160
        check rnc ri = do
26fc5502ba22 - Fix applying vote result
unc0rr
parents: 10212
diff changeset
   161
            e <- room'sM rnc voting ri
26fc5502ba22 - Fix applying vote result
unc0rr
parents: 10212
diff changeset
   162
            case e of
26fc5502ba22 - Fix applying vote result
unc0rr
parents: 10212
diff changeset
   163
                 Just rv -> do
26fc5502ba22 - Fix applying vote result
unc0rr
parents: 10212
diff changeset
   164
                     modifyRoom rnc (\r -> r{voting = if voteTTL rv == 0 then Nothing else Just rv{voteTTL = voteTTL rv - 1}}) ri
26fc5502ba22 - Fix applying vote result
unc0rr
parents: 10212
diff changeset
   165
                     if voteTTL rv == 0 then do
10216
6928a323097f Fix build
unc0rr
parents: 10215
diff changeset
   166
                        chans <- liftM (map sendChan) $ roomClientsM rnc ri
13696
d732ca5dcab9 GameServer: Refactor fake nick names into Consts
Wuzzy <Wuzzy2@mail.ru>
parents: 13509
diff changeset
   167
                        return [AnswerClients chans ["CHAT", nickServer, loc "Voting expired."]]
10215
26fc5502ba22 - Fix applying vote result
unc0rr
parents: 10212
diff changeset
   168
                        else
26fc5502ba22 - Fix applying vote result
unc0rr
parents: 10212
diff changeset
   169
                        return []
10216
6928a323097f Fix build
unc0rr
parents: 10215
diff changeset
   170
                 Nothing -> return []
10058
4ed428389c4e - Implement /callvote
unc0rr
parents: 10049
diff changeset
   171
10081
0af84e5cbd4d Implement 'voted' function
unc0rr
parents: 10058
diff changeset
   172
10058
4ed428389c4e - Implement /callvote
unc0rr
parents: 10049
diff changeset
   173
voteInfo :: VoteType -> B.ByteString
4ed428389c4e - Implement /callvote
unc0rr
parents: 10049
diff changeset
   174
voteInfo (VoteKick n) = B.concat [loc "kick", " ", n]
10195
d1c23bb73346 - Room save/load into/from file
unc0rr
parents: 10090
diff changeset
   175
voteInfo (VoteMap n) = B.concat [loc "map", " ", n]
10392
5012e1f9e893 - Support for pausing multiplayer games
alfadur
parents: 10218
diff changeset
   176
voteInfo (VotePause) = B.concat [loc "pause"]
10786
712283ed86e0 Implement /newseed and /hedgehogs commands. Only tested for building.
unc0rr
parents: 10464
diff changeset
   177
voteInfo (VoteNewSeed) = B.concat [loc "new seed"]
13079
81c154fd4380 More user-friendly server messages
Wuzzy <Wuzzy2@mail.ru>
parents: 11575
diff changeset
   178
voteInfo (VoteHedgehogsPerTeam i) = B.concat [loc "hedgehogs per team: ", " ", showB i]