gameServer/HWProtoCore.hs
changeset 4568 f85243bf890e
parent 4337 85e02b1a8e8f
child 4904 0eab727d4717
--- a/gameServer/HWProtoCore.hs	Sun Dec 19 20:45:15 2010 +0300
+++ b/gameServer/HWProtoCore.hs	Sun Dec 19 13:31:55 2010 -0500
@@ -1,10 +1,8 @@
-{-# LANGUAGE OverloadedStrings #-}
 module HWProtoCore where
 
 import qualified Data.IntMap as IntMap
 import Data.Foldable
 import Data.Maybe
-import Control.Monad.Reader
 --------------------------------------
 import CoreTypes
 import Actions
@@ -12,37 +10,35 @@
 import HWProtoNEState
 import HWProtoLobbyState
 import HWProtoInRoomState
-import HandlerUtils
-import RoomsAndClients
 
 handleCmd, handleCmd_loggedin :: CmdHandler
 
-
-handleCmd ["PING"] = answerClient ["PONG"]
+handleCmd clID _ _ ["PING"] = [AnswerThisClient ["PONG"]]
 
-
-handleCmd ("QUIT" : xs) = return [ByeClient msg]
+handleCmd clID clients rooms ("QUIT" : xs) =
+    [ByeClient msg]
     where
         msg = if not $ null xs then head xs else ""
 
-{-
-handleCmd ["PONG"] =
+
+handleCmd clID clients _ ["PONG"] =
     if pingsQueue client == 0 then
         [ProtocolError "Protocol violation"]
     else
         [ModifyClient (\cl -> cl{pingsQueue = pingsQueue cl - 1})]
     where
         client = clients IntMap.! clID
--}
+
 
-handleCmd cmd = do
-    (ci, irnc) <- ask
-    if logonPassed (irnc `client` ci) then
-        handleCmd_loggedin cmd
-        else
-        handleCmd_NotEntered cmd
+handleCmd clID clients rooms cmd =
+    if not $ logonPassed client then
+        handleCmd_NotEntered clID clients rooms cmd
+    else
+        handleCmd_loggedin clID clients rooms cmd
+    where
+        client = clients IntMap.! clID
 
-{-
+
 handleCmd_loggedin clID clients rooms ["INFO", asknick] =
     if noSuchClient then
         []
@@ -66,12 +62,11 @@
             then if teamsInGame client > 0 then "(playing)" else "(spectating)"
             else ""
 
--}
 
-
-handleCmd_loggedin cmd = do
-    (ci, rnc) <- ask
-    if clientRoom rnc ci == lobbyId then
-        handleCmd_lobby cmd
-        else
-        handleCmd_inRoom cmd
+handleCmd_loggedin clID clients rooms cmd =
+    if roomID client == 0 then
+        handleCmd_lobby clID clients rooms cmd
+    else
+        handleCmd_inRoom clID clients rooms cmd
+    where
+        client = clients IntMap.! clID