"/force" command for server admin to force voting result
authorunc0rr
Tue, 31 Mar 2015 23:01:53 +0300
changeset 10881 941b5ab9e5a6
parent 10880 bf64f1bef1cc
child 10882 ed7717f659ae
"/force" command for server admin to force voting result
gameServer/HWProtoCore.hs
gameServer/HWProtoInRoomState.hs
gameServer/Votes.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)
--- 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'"]]
 
--- 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