gameServer/Actions.hs
changeset 7710 fd5bcbd698a5
parent 7682 f6bfbe829008
child 7735 4c7e282b5732
equal deleted inserted replaced
7709:631852904cee 7710:fd5bcbd698a5
   235                 playersIn = playersIn r - 1,
   235                 playersIn = playersIn r - 1,
   236                 readyPlayers = if ready then readyPlayers r - 1 else readyPlayers r
   236                 readyPlayers = if ready then readyPlayers r - 1 else readyPlayers r
   237                 }) ri
   237                 }) ri
   238         moveClientToLobby rnc ci
   238         moveClientToLobby rnc ci
   239 
   239 
       
   240 
   240 processAction ChangeMaster = do
   241 processAction ChangeMaster = do
   241     (Just ci) <- gets clientIndex
   242     (Just ci) <- gets clientIndex
       
   243     proto <- client's clientProto
   242     ri <- clientRoomA
   244     ri <- clientRoomA
   243     rnc <- gets roomsClients
   245     rnc <- gets roomsClients
   244     newMasterId <- liftM (head . filter (/= ci)) . io $ roomClientsIndicesM rnc ri
   246     newMasterId <- liftM (head . filter (/= ci)) . io $ roomClientsIndicesM rnc ri
   245     newMaster <- io $ client'sM rnc id newMasterId
   247     newMaster <- io $ client'sM rnc id newMasterId
   246     oldRoomName <- io $ room'sM rnc name ri
   248     oldRoomName <- io $ room'sM rnc name ri
   247     oldMaster <- client's nick
   249     oldMaster <- client's nick
   248     thisRoomChans <- liftM (map sendChan) $ roomClientsS ri
   250     thisRoomChans <- liftM (map sendChan) $ roomClientsS ri
   249     let newRoomName = nick newMaster
   251     let newRoomName = if proto < 42 then nick newMaster else oldRoomName
   250     mapM_ processAction [
   252     mapM_ processAction [
   251         ModifyRoom (\r -> r{masterID = newMasterId, name = newRoomName, isRestrictedJoins = False, isRestrictedTeams = False})
   253         ModifyRoom (\r -> r{masterID = newMasterId, name = newRoomName, isRestrictedJoins = False, isRestrictedTeams = False})
   252         , ModifyClient2 newMasterId (\c -> c{isMaster = True})
   254         , ModifyClient2 newMasterId (\c -> c{isMaster = True})
   253         , AnswerClients [sendChan newMaster] ["ROOM_CONTROL_ACCESS", "1"]
   255         , AnswerClients [sendChan newMaster] ["ROOM_CONTROL_ACCESS", "1"]
   254         , AnswerClients thisRoomChans ["WARNING", "New room admin is " `B.append` nick newMaster]
   256         , AnswerClients thisRoomChans ["WARNING", "New room admin is " `B.append` nick newMaster]
   257         ]
   259         ]
   258 
   260 
   259     proto <- client's clientProto
   261     proto <- client's clientProto
   260     newRoom <- io $ room'sM rnc id ri
   262     newRoom <- io $ room'sM rnc id ri
   261     chans <- liftM (map sendChan) $! sameProtoClientsS proto
   263     chans <- liftM (map sendChan) $! sameProtoClientsS proto
   262     processAction $ AnswerClients chans ("ROOM" : "UPD" : oldRoomName : roomInfo (nick newMaster) newRoom)
   264     processAction $ AnswerClients chans ("ROOM" : "UPD" : oldRoomName : roomInfo newRoomName newRoom)
   263 
   265 
   264 
   266 
   265 processAction (AddRoom roomName roomPassword) = do
   267 processAction (AddRoom roomName roomPassword) = do
   266     Just clId <- gets clientIndex
   268     Just clId <- gets clientIndex
   267     rnc <- gets roomsClients
   269     rnc <- gets roomsClients