Reimplement TOGGLE_READY command
authorunc0rr
Wed, 23 Jun 2010 22:21:13 +0400
changeset 3543 d84a93b985c1
parent 3542 f216b24aeb7f
child 3544 aad64e15ca03
Reimplement TOGGLE_READY command
gameServer/HWProtoInRoomState.hs
gameServer/HandlerUtils.hs
--- a/gameServer/HWProtoInRoomState.hs	Wed Jun 23 22:17:27 2010 +0400
+++ b/gameServer/HWProtoInRoomState.hs	Wed Jun 23 22:21:13 2010 +0400
@@ -108,16 +108,18 @@
         findTeam = find (\t -> teamName == teamname t) $ teams room
         client = clients IntMap.! clID
         room = rooms IntMap.! (roomID client)
-
+-}
 
-handleCmd_inRoom clID clients rooms ["TOGGLE_READY"] =
-    [ModifyClient (\c -> c{isReady = not $ isReady client}),
-    ModifyRoom (\r -> r{readyPlayers = readyPlayers r + (if isReady client then -1 else 1)}),
-    AnswerThisRoom [if isReady client then "NOT_READY" else "READY", nick client]]
-    where
-        client = clients IntMap.! clID
+handleCmd_inRoom ["TOGGLE_READY"] = do
+    cl <- thisClient
+    chans <- roomClientsChans
+    return [
+        ModifyClient (\c -> c{isReady = not $ isReady cl}),
+        ModifyRoom (\r -> r{readyPlayers = readyPlayers r + (if isReady cl then -1 else 1)}),
+        AnswerClients chans [if isReady cl then "NOT_READY" else "READY", nick cl]
+        ]
 
-
+{-
 handleCmd_inRoom clID clients rooms ["START_GAME"] =
     if isMaster client && (playersIn room == readyPlayers room) && (not . gameinprogress) room then
         if enoughClans then
--- a/gameServer/HandlerUtils.hs	Wed Jun 23 22:17:27 2010 +0400
+++ b/gameServer/HandlerUtils.hs	Wed Jun 23 22:21:13 2010 +0400
@@ -21,6 +21,12 @@
     let ri = clientRoom rnc ci
     return $ map (sendChan . client rnc) $ filter (/= ci) (roomClients rnc ri)
 
+roomClientsChans :: Reader (ClientIndex, IRnC) [ClientChan]
+roomClientsChans = do
+    (ci, rnc) <- ask
+    let ri = clientRoom rnc ci
+    return $ map (sendChan . client rnc) (roomClients rnc ri)
+
 thisClientChans :: Reader (ClientIndex, IRnC) [ClientChan]
 thisClientChans = do
     (ci, rnc) <- ask