Introduce numbered server notice messages server_refactor
authorunc0rr
Sat, 29 Jan 2011 13:43:07 +0300
branchserver_refactor
changeset 4610 9541b2a76067
parent 4608 d0f758d0ff91
child 4612 e82758d6f924
Introduce numbered server notice messages
gameServer/Actions.hs
gameServer/CoreTypes.hs
gameServer/HWProtoNEState.hs
--- a/gameServer/Actions.hs	Fri Jan 28 22:34:07 2011 +0300
+++ b/gameServer/Actions.hs	Sat Jan 29 13:43:07 2011 +0300
@@ -32,6 +32,7 @@
     | JoinLobby
     | ProtocolError B.ByteString
     | Warning B.ByteString
+    | NoticeMessage Notice
     | ByeClient B.ByteString
     | KickClient ClientIndex
     | KickRoomClient ClientIndex
@@ -103,6 +104,10 @@
     chan <- client's sendChan
     processAction $ AnswerClients [chan] ["WARNING", msg]
 
+processAction (NoticeMessage n) = do
+    chan <- client's sendChan
+    processAction $ AnswerClients [chan] ["NOTICE", B.pack . show . fromEnum $ n]
+
 processAction (ByeClient msg) = do
     (Just ci) <- gets clientIndex
     rnc <- gets roomsClients
--- a/gameServer/CoreTypes.hs	Fri Jan 28 22:34:07 2011 +0300
+++ b/gameServer/CoreTypes.hs	Sat Jan 29 13:43:07 2011 +0300
@@ -179,7 +179,9 @@
     show (ClientAccountInfo _) = "ClientAccountInfo"
     show (TimerAction _) = "TimerAction"
     show (Remove _) = "Remove"
-    
+
 type MRnC = MRoomsAndClients RoomInfo ClientInfo
 type IRnC = IRoomsAndClients RoomInfo ClientInfo
 
+data Notice = NickAlreadyInUse
+    deriving Enum
\ No newline at end of file
--- a/gameServer/HWProtoNEState.hs	Fri Jan 28 22:34:07 2011 +0300
+++ b/gameServer/HWProtoNEState.hs	Sat Jan 29 13:43:07 2011 +0300
@@ -20,7 +20,7 @@
     let cl = irnc `client` ci
     if not . B.null $ nick cl then return [ProtocolError "Nickname already chosen"]
         else
-        if haveSameNick irnc then return [{-AnswerClients [sendChan cl] ["WARNING", "Nickname already in use"], -}ByeClient "Nickname already in use"]
+        if haveSameNick irnc then return [NoticeMessage NickAlreadyInUse]
             else
             if illegalName newNick then return [ByeClient "Illegal nickname"]
                 else
@@ -57,10 +57,5 @@
         else
         return [ByeClient "Authentication failed"]
 
-{-
-
-handleCmd_NotEntered clID clients _ ["DUMP"] =
-    if isAdministrator (clients IntMap.! clID) then [Dump] else []
--}
 
 handleCmd_NotEntered _ = return [ProtocolError "Incorrect command (state: not entered)"]