gameServer/Actions.hs
branchwebgl
changeset 9127 e350500c4edb
parent 8833 c13ebed437cb
parent 9062 a65492ca1587
child 9160 fc46e75f6b72
equal deleted inserted replaced
8860:bde641cf53c8 9127:e350500c4edb
    18 import Data.Unique
    18 import Data.Unique
    19 import Control.Arrow
    19 import Control.Arrow
    20 import Control.Exception
    20 import Control.Exception
    21 import System.Process
    21 import System.Process
    22 import Network.Socket
    22 import Network.Socket
       
    23 import System.Random
    23 -----------------------------
    24 -----------------------------
    24 #if defined(OFFICIAL_SERVER)
    25 #if defined(OFFICIAL_SERVER)
    25 import OfficialServer.GameReplayStore
    26 import OfficialServer.GameReplayStore
    26 #endif
    27 #endif
    27 import CoreTypes
    28 import CoreTypes
   204     proto <- client's clientProto
   205     proto <- client's clientProto
   205     ri <- clientRoomA
   206     ri <- clientRoomA
   206     rnc <- gets roomsClients
   207     rnc <- gets roomsClients
   207     newMasterId <- liftM (\ids -> fromMaybe (last . filter (/= ci) $ ids) delegateId) . io $ roomClientsIndicesM rnc ri
   208     newMasterId <- liftM (\ids -> fromMaybe (last . filter (/= ci) $ ids) delegateId) . io $ roomClientsIndicesM rnc ri
   208     newMaster <- io $ client'sM rnc id newMasterId
   209     newMaster <- io $ client'sM rnc id newMasterId
       
   210     oldMasterId <- io $ room'sM rnc masterID ri
       
   211     oldMaster <- io $ client'sM rnc id oldMasterId
   209     oldRoomName <- io $ room'sM rnc name ri
   212     oldRoomName <- io $ room'sM rnc name ri
   210     oldMaster <- client's nick
       
   211     kicked <- client's isKickedFromServer
   213     kicked <- client's isKickedFromServer
   212     thisRoomChans <- liftM (map sendChan) $ roomClientsS ri
   214     thisRoomChans <- liftM (map sendChan) $ roomClientsS ri
   213     let newRoomName = if (proto < 42) || kicked then nick newMaster else oldRoomName
   215     let newRoomName = if (proto < 42) || kicked then nick newMaster else oldRoomName
   214     mapM_ processAction [
   216     mapM_ processAction [
   215         ModifyRoom (\r -> r{masterID = newMasterId
   217         ModifyRoom (\r -> r{masterID = newMasterId
   216                 , name = newRoomName
   218                 , name = newRoomName
   217                 , isRestrictedJoins = False
   219                 , isRestrictedJoins = False
   218                 , isRestrictedTeams = False
   220                 , isRestrictedTeams = False
   219                 , isRegisteredOnly = False
   221                 , isRegisteredOnly = False}
   220                 , readyPlayers = if isReady newMaster then readyPlayers r else readyPlayers r + 1})
   222                 )
   221         , ModifyClient2 newMasterId (\c -> c{isMaster = True, isReady = True})
   223         , ModifyClient2 newMasterId (\c -> c{isMaster = True})
       
   224         , ModifyClient2 oldMasterId (\c -> c{isMaster = False})
   222         , AnswerClients [sendChan newMaster] ["ROOM_CONTROL_ACCESS", "1"]
   225         , AnswerClients [sendChan newMaster] ["ROOM_CONTROL_ACCESS", "1"]
   223         , AnswerClients thisRoomChans ["CLIENT_FLAGS", "-h", oldMaster]
   226         , AnswerClients thisRoomChans ["CLIENT_FLAGS", "-h", nick oldMaster]
   224         , AnswerClients thisRoomChans ["CLIENT_FLAGS", "+hr", nick newMaster]
   227         , AnswerClients thisRoomChans ["CLIENT_FLAGS", "+h", nick newMaster]
   225         ]
   228         ]
   226 
   229 
   227     newRoom' <- io $ room'sM rnc id ri
   230     newRoom' <- io $ room'sM rnc id ri
   228     chans <- liftM (map sendChan) $! sameProtoClientsS proto
   231     chans <- liftM (map sendChan) $! sameProtoClientsS proto
   229     processAction $ AnswerClients chans ("ROOM" : "UPD" : oldRoomName : roomInfo (nick newMaster) newRoom')
   232     processAction $ AnswerClients chans ("ROOM" : "UPD" : oldRoomName : roomInfo (nick newMaster) newRoom')
   379     haveSameNick <- liftM (not . null . tail . filter (\c -> (not $ isChecker c) && caseInsensitiveCompare (nick c) n)) allClientsS
   382     haveSameNick <- liftM (not . null . tail . filter (\c -> (not $ isChecker c) && caseInsensitiveCompare (nick c) n)) allClientsS
   380     if (not checker) && haveSameNick then
   383     if (not checker) && haveSameNick then
   381         if p < 38 then
   384         if p < 38 then
   382             processAction $ ByeClient $ loc "Nickname is already in use"
   385             processAction $ ByeClient $ loc "Nickname is already in use"
   383             else
   386             else
   384             processAction $ NoticeMessage NickAlreadyInUse
   387             mapM_ processAction [NoticeMessage NickAlreadyInUse, ModifyClient $ \c -> c{nick = B.empty}]
   385         else
   388         else
   386         do
   389         do
   387         db <- gets (dbQueries . serverInfo)
   390         db <- gets (dbQueries . serverInfo)
   388         io $ writeChan db $ CheckAccount ci (hashUnique uid) n h
   391         io $ writeChan db $ CheckAccount ci (hashUnique uid) n h
   389         return ()
   392         return ()
   613                     , "</td></tr>"])
   616                     , "</td></tr>"])
   614             . Set.toList $ keys
   617             . Set.toList $ keys
   615     processAction $ Warning versionsStats
   618     processAction $ Warning versionsStats
   616 
   619 
   617 
   620 
       
   621 processAction (Random chans items) = do
       
   622     let i = if null items then ["heads", "tails"] else items
       
   623     n <- io $ randomRIO (0, length i - 1)
       
   624     processAction $ AnswerClients chans ["CHAT", "[random]", i !! n]
       
   625 
       
   626 
   618 #if defined(OFFICIAL_SERVER)
   627 #if defined(OFFICIAL_SERVER)
   619 processAction SaveReplay = do
   628 processAction SaveReplay = do
   620     ri <- clientRoomA
   629     ri <- clientRoomA
   621     rnc <- gets roomsClients
   630     rnc <- gets roomsClients
   622 
   631