gameServer/Actions.hs
changeset 7775 835ad028fb66
parent 7766 98edc0724a28
child 7898 ba735701ce7f
equal deleted inserted replaced
7773:3d460e57d4e6 7775:835ad028fb66
   259     oldRoomName <- io $ room'sM rnc name ri
   259     oldRoomName <- io $ room'sM rnc name ri
   260     oldMaster <- client's nick
   260     oldMaster <- client's nick
   261     thisRoomChans <- liftM (map sendChan) $ roomClientsS ri
   261     thisRoomChans <- liftM (map sendChan) $ roomClientsS ri
   262     let newRoomName = if proto < 42 then nick newMaster else oldRoomName
   262     let newRoomName = if proto < 42 then nick newMaster else oldRoomName
   263     mapM_ processAction [
   263     mapM_ processAction [
   264         ModifyRoom (\r -> r{masterID = newMasterId, name = newRoomName, isRestrictedJoins = False, isRestrictedTeams = False})
   264         ModifyRoom (\r -> r{masterID = newMasterId
   265         , ModifyClient2 newMasterId (\c -> c{isMaster = True})
   265                 , name = newRoomName
       
   266                 , isRestrictedJoins = False
       
   267                 , isRestrictedTeams = False
       
   268                 , readyPlayers = if isReady newMaster then readyPlayers r else readyPlayers r + 1})
       
   269         , ModifyClient2 newMasterId (\c -> c{isMaster = True, isReady = True})
   266         , AnswerClients [sendChan newMaster] ["ROOM_CONTROL_ACCESS", "1"]
   270         , AnswerClients [sendChan newMaster] ["ROOM_CONTROL_ACCESS", "1"]
   267         , AnswerClients thisRoomChans ["WARNING", "New room admin is " `B.append` nick newMaster]
   271         , AnswerClients thisRoomChans ["WARNING", "New room admin is " `B.append` nick newMaster]
   268         , AnswerClients thisRoomChans ["CLIENT_FLAGS", "-h", oldMaster]
   272         , AnswerClients thisRoomChans ["CLIENT_FLAGS", "-h", oldMaster]
   269         , AnswerClients thisRoomChans ["CLIENT_FLAGS", "+h", nick newMaster]
   273         , AnswerClients thisRoomChans ["CLIENT_FLAGS", "+hr", nick newMaster]
   270         ]
   274         ]
   271 
   275 
   272     newRoom' <- io $ room'sM rnc id ri
   276     newRoom' <- io $ room'sM rnc id ri
   273     chans <- liftM (map sendChan) $! sameProtoClientsS proto
   277     chans <- liftM (map sendChan) $! sameProtoClientsS proto
   274     processAction $ AnswerClients chans ("ROOM" : "UPD" : oldRoomName : roomInfo newRoomName newRoom')
   278     processAction $ AnswerClients chans ("ROOM" : "UPD" : oldRoomName : roomInfo newRoomName newRoom')
   277 processAction (AddRoom roomName roomPassword) = do
   281 processAction (AddRoom roomName roomPassword) = do
   278     Just clId <- gets clientIndex
   282     Just clId <- gets clientIndex
   279     rnc <- gets roomsClients
   283     rnc <- gets roomsClients
   280     proto <- client's clientProto
   284     proto <- client's clientProto
   281     n <- client's nick
   285     n <- client's nick
   282     chan <- client's sendChan
       
   283 
   286 
   284     let rm = newRoom{
   287     let rm = newRoom{
   285             masterID = clId,
   288             masterID = clId,
   286             name = roomName,
   289             name = roomName,
   287             password = roomPassword,
   290             password = roomPassword,
   294 
   297 
   295     chans <- liftM (map sendChan) $! sameProtoClientsS proto
   298     chans <- liftM (map sendChan) $! sameProtoClientsS proto
   296 
   299 
   297     mapM_ processAction [
   300     mapM_ processAction [
   298         AnswerClients chans ("ROOM" : "ADD" : roomInfo n rm)
   301         AnswerClients chans ("ROOM" : "ADD" : roomInfo n rm)
   299         , AnswerClients [chan] ["CLIENT_FLAGS", "+h", n]
       
   300         , ModifyClient (\cl -> cl{isMaster = True})
       
   301         ]
   302         ]
   302 
   303 
   303 
   304 
   304 processAction RemoveRoom = do
   305 processAction RemoveRoom = do
   305     Just clId <- gets clientIndex
   306     Just clId <- gets clientIndex
   321 processAction UnreadyRoomClients = do
   322 processAction UnreadyRoomClients = do
   322     ri <- clientRoomA
   323     ri <- clientRoomA
   323     roomPlayers <- roomClientsS ri
   324     roomPlayers <- roomClientsS ri
   324     pr <- client's clientProto
   325     pr <- client's clientProto
   325     mapM_ processAction [
   326     mapM_ processAction [
   326         AnswerClients (map sendChan roomPlayers) $ notReadyMessage pr (map nick roomPlayers)
   327         AnswerClients (map sendChan roomPlayers) $ notReadyMessage pr . map nick . filter (not . isMaster) $ roomPlayers
   327         , ModifyRoomClients (\cl -> cl{isReady = False})
   328         , ModifyRoomClients (\cl -> cl{isReady = isMaster cl})
   328         , ModifyRoom (\r -> r{readyPlayers = 0})
   329         , ModifyRoom (\r -> r{readyPlayers = 1})
   329         ]
   330         ]
   330     where
   331     where
   331         notReadyMessage p nicks = if p < 38 then "NOT_READY" : nicks else "CLIENT_FLAGS" : "-r" : nicks
   332         notReadyMessage p nicks = if p < 38 then "NOT_READY" : nicks else "CLIENT_FLAGS" : "-r" : nicks
   332 
   333 
   333 
   334