gameServer/HandlerUtils.hs
branchserver_refactor
changeset 4614 26661bf28dd5
parent 3568 ae89cf0735dc
child 4932 f11d80bac7ed
--- a/gameServer/HandlerUtils.hs	Sat Jan 29 21:33:24 2011 +0300
+++ b/gameServer/HandlerUtils.hs	Sun Jan 30 20:32:23 2011 +0300
@@ -2,6 +2,7 @@
 
 import Control.Monad.Reader
 import qualified Data.ByteString.Char8 as B
+import Data.List
 
 import RoomsAndClients
 import CoreTypes
@@ -27,6 +28,18 @@
     let ri = clientRoom rnc ci
     return $ map (sendChan . client rnc) $ filter (/= ci) (roomClients rnc ri)
 
+roomSameClanChans :: Reader (ClientIndex, IRnC) [ClientChan]
+roomSameClanChans = do
+    (ci, rnc) <- ask
+    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
+
 roomClientsChans :: Reader (ClientIndex, IRnC) [ClientChan]
 roomClientsChans = do
     (ci, rnc) <- ask
@@ -43,3 +56,10 @@
 
 allRoomInfos :: Reader (a, IRnC) [RoomInfo]
 allRoomInfos = liftM ((\irnc -> map (room irnc) $ allRooms irnc) . snd) ask
+
+clientByNick :: B.ByteString -> Reader (ClientIndex, IRnC) (Maybe ClientIndex)
+clientByNick n = do
+    (_, rnc) <- ask
+    let allClientIDs = allClients rnc
+    return $ find (\clId -> n == nick (client rnc clId)) allClientIDs
+