Use Maybe for storing client's clan, allows less error-prone spectator checks
authorunc0rr
Sat, 05 Mar 2011 22:16:29 +0300
changeset 4986 33fe91b2bcbf
parent 4985 304d149bb3dd
child 4987 cf9470964dba
Use Maybe for storing client's clan, allows less error-prone spectator checks
gameServer/CoreTypes.hs
gameServer/HWProtoInRoomState.hs
gameServer/HandlerUtils.hs
gameServer/NetRoutines.hs
--- a/gameServer/CoreTypes.hs	Sat Mar 05 13:07:02 2011 +0100
+++ b/gameServer/CoreTypes.hs	Sat Mar 05 22:16:29 2011 +0300
@@ -34,7 +34,7 @@
         isMaster :: Bool,
         isReady :: !Bool,
         isAdministrator :: Bool,
-        clientClan :: B.ByteString,
+        clientClan :: Maybe B.ByteString,
         teamsInGame :: Word
     }
 
--- a/gameServer/HWProtoInRoomState.hs	Sat Mar 05 13:07:02 2011 +0100
+++ b/gameServer/HWProtoInRoomState.hs	Sat Mar 05 22:16:29 2011 +0300
@@ -64,7 +64,7 @@
                 [Warning "restricted"]
             else
                 [ModifyRoom (\r -> r{teams = teams r ++ [newTeam ci clNick r]}),
-                ModifyClient (\c -> c{teamsInGame = teamsInGame c + 1, clientClan = color}),
+                ModifyClient (\c -> c{teamsInGame = teamsInGame c + 1, clientClan = Just color}),
                 AnswerClients clChan ["TEAM_ACCEPTED", tName],
                 AnswerClients othChans $ teamToNet $ newTeam ci clNick rm,
                 AnswerClients othChans ["TEAM_COLOR", tName, color]
@@ -99,7 +99,7 @@
                 ModifyClient
                     (\c -> c{
                         teamsInGame = teamsInGame c - 1,
-                        clientClan = if teamsInGame c == 1 then undefined else anotherTeamClan ci r
+                            clientClan = if teamsInGame c == 1 then Nothing else Just $ anotherTeamClan ci r
                         })
                 ]
     where
@@ -148,7 +148,7 @@
         else
             [ModifyRoom $ modifyTeam team{teamcolor = newColor},
             AnswerClients others ["TEAM_COLOR", teamName, newColor],
-            ModifyClient2 (teamownerId team) (\c -> c{clientClan = newColor})]
+            ModifyClient2 (teamownerId team) (\c -> c{clientClan = Just newColor})]
     where
         findTeam = find (\t -> teamName == teamname t) . teams
 
--- a/gameServer/HandlerUtils.hs	Sat Mar 05 13:07:02 2011 +0100
+++ b/gameServer/HandlerUtils.hs	Sat Mar 05 22:16:29 2011 +0300
@@ -34,11 +34,8 @@
     let ri = clientRoom rnc ci
     let otherRoomClients = map (client rnc) . filter (/= ci) $ roomClients rnc ri
     let cl = rnc `client` ci
-    let thisClan = clientClan cl
-    let sameClanClients = Prelude.filter (\c -> teamsInGame cl > 0 && clientClan c == thisClan) otherRoomClients
-    let spectators = Prelude.filter (\c -> teamsInGame c == 0) otherRoomClients
-    let sameClanOrSpec = if teamsInGame cl > 0 then sameClanClients else spectators
-    return $ map sendChan sameClanOrSpec
+    let sameClanClients = Prelude.filter (\c -> clientClan c == clientClan cl) otherRoomClients
+    return $ map sendChan sameClanClients
 
 roomClientsChans :: Reader (ClientIndex, IRnC) [ClientChan]
 roomClientsChans = do
--- a/gameServer/NetRoutines.hs	Sat Mar 05 13:07:02 2011 +0100
+++ b/gameServer/NetRoutines.hs	Sat Mar 05 22:16:29 2011 +0300
@@ -43,7 +43,7 @@
                     False
                     False
                     False
-                    undefined
+                    Nothing
                     undefined
                     )