gameServer/Votes.hs
changeset 10881 941b5ab9e5a6
parent 10880 bf64f1bef1cc
child 11046 47a8c19ecb60
--- 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