# HG changeset patch # User unc0rr # Date 1427832113 -10800 # Node ID 941b5ab9e5a6043ea9b4d195b0616da2f64a1f91 # Parent bf64f1bef1cceaee8fb1ebfccaa6690de9d0c133 "/force" command for server admin to force voting result diff -r bf64f1bef1cc -r 941b5ab9e5a6 gameServer/HWProtoCore.hs --- a/gameServer/HWProtoCore.hs Tue Mar 31 22:50:12 2015 +0300 +++ b/gameServer/HWProtoCore.hs Tue Mar 31 23:01:53 2015 +0300 @@ -76,6 +76,7 @@ | otherwise = let (c, p) = extractParameters msg in if B.null p then handleCmd ["CALLVOTE", c] else handleCmd ["CALLVOTE", c, p] h "VOTE" msg = handleCmd ["VOTE", upperCase msg] + h "FORCE" msg = handleCmd ["VOTE", upperCase msg, "FORCE"] h c p = return [Warning $ B.concat ["Unknown cmd: /", c, " ", p]] extractParameters p = let (a, b) = B.break (== ' ') p in (upperCase a, B.dropWhile (== ' ') b) diff -r bf64f1bef1cc -r 941b5ab9e5a6 gameServer/HWProtoInRoomState.hs --- a/gameServer/HWProtoInRoomState.hs Tue Mar 31 22:50:12 2015 +0300 +++ b/gameServer/HWProtoInRoomState.hs Tue Mar 31 23:01:53 2015 +0300 @@ -473,11 +473,11 @@ return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "callvote hedgehogs: specify number from 1 to 8"]] -handleCmd_inRoom ["VOTE", m] = do +handleCmd_inRoom ("VOTE" : m : p) = do cl <- thisClient let b = if m == "YES" then Just True else if m == "NO" then Just False else Nothing if isJust b then - voted (fromJust b) + voted (p == ["FORCE"]) (fromJust b) else return [AnswerClients [sendChan cl] ["CHAT", "[server]", "vote: 'yes' or 'no'"]] diff -r bf64f1bef1cc -r 941b5ab9e5a6 gameServer/Votes.hs --- a/gameServer/Votes.hs Tue Mar 31 22:50:12 2015 +0300 +++ b/gameServer/Votes.hs Tue Mar 31 23:01:53 2015 +0300 @@ -34,8 +34,8 @@ import EngineInteraction -voted :: Bool -> Reader (ClientIndex, IRnC) [Action] -voted vote = do +voted :: Bool -> Bool -> Reader (ClientIndex, IRnC) [Action] +voted forced vote = do cl <- thisClient rm <- thisRoom uid <- liftM clUID thisClient @@ -44,10 +44,12 @@ Nothing -> return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "There's no voting going on"]] Just voting -> - if uid `L.notElem` entitledToVote voting then + if (not forced) && (uid `L.notElem` entitledToVote voting) then return [] - else if uid `L.elem` map fst (votes voting) then + else if (not forced) && (uid `L.elem` map fst (votes voting)) then return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "You already have voted"]] + else if forced && (not $ isAdministrator cl) then + return [] else ((:) (AnswerClients [sendChan cl] ["CHAT", "[server]", loc "Your vote counted"])) <$> (actOnVoting $ voting{votes = (uid, vote):votes voting}) @@ -59,9 +61,9 @@ let totalV = length $ entitledToVote vt let successV = totalV `div` 2 + 1 - if length contra > totalV - successV then + if (forced && not vote) || (length contra > totalV - successV) then closeVoting - else if length pro >= successV then do + else if (forced && vote) || (length pro >= successV) then do a <- act $ voteType vt c <- closeVoting return $ c ++ a