gameServer/HWProtoInRoomState.hs
changeset 10194 7025bd3c3131
parent 10095 003fc694c0c3
child 10195 d1c23bb73346
equal deleted inserted replaced
10193:d7cd5b43588f 10194:7025bd3c3131
   223                 else
   223                 else
   224                 ["CLIENT_FLAGS", if isReady cl then "-r" else "+r", nick cl])
   224                 ["CLIENT_FLAGS", if isReady cl then "-r" else "+r", nick cl])
   225         : gs
   225         : gs
   226 
   226 
   227 
   227 
   228 handleCmd_inRoom ["START_GAME"] = do
   228 handleCmd_inRoom ["START_GAME"] = roomAdminOnly startGame
   229     cl <- thisClient
       
   230     if isMaster cl then startGame else return []
       
   231 
   229 
   232 handleCmd_inRoom ["EM", msg] = do
   230 handleCmd_inRoom ["EM", msg] = do
   233     cl <- thisClient
   231     cl <- thisClient
   234     rm <- thisRoom
   232     rm <- thisRoom
   235     chans <- roomOthersChans
   233     chans <- roomOthersChans
   267 
   265 
   268 -- compatibility with clients with protocol < 38
   266 -- compatibility with clients with protocol < 38
   269 handleCmd_inRoom ["ROUNDFINISHED"] =
   267 handleCmd_inRoom ["ROUNDFINISHED"] =
   270     handleCmd_inRoom ["ROUNDFINISHED", "1"]
   268     handleCmd_inRoom ["ROUNDFINISHED", "1"]
   271 
   269 
   272 handleCmd_inRoom ["TOGGLE_RESTRICT_JOINS"] = do
   270 handleCmd_inRoom ["TOGGLE_RESTRICT_JOINS"] = roomAdminOnly $
   273     cl <- thisClient
   271     return [ModifyRoom (\r -> r{isRestrictedJoins = not $ isRestrictedJoins r})]
       
   272 
       
   273 
       
   274 handleCmd_inRoom ["TOGGLE_RESTRICT_TEAMS"] = roomAdminOnly $
       
   275     return [ModifyRoom (\r -> r{isRestrictedTeams = not $ isRestrictedTeams r})]
       
   276 
       
   277 
       
   278 handleCmd_inRoom ["TOGGLE_REGISTERED_ONLY"] = roomAdminOnly $
       
   279     return [ModifyRoom (\r -> r{isRegisteredOnly = not $ isRegisteredOnly r})]
       
   280 
       
   281 
       
   282 handleCmd_inRoom ["ROOM_NAME", newName] = roomAdminOnly $ do
       
   283     cl <- thisClient
       
   284     rs <- allRoomInfos
       
   285     rm <- thisRoom
       
   286     chans <- sameProtoChans
       
   287 
   274     return $
   288     return $
   275         if not $ isMaster cl then
       
   276             [ProtocolError $ loc "Not room master"]
       
   277         else
       
   278             [ModifyRoom (\r -> r{isRestrictedJoins = not $ isRestrictedJoins r})]
       
   279 
       
   280 
       
   281 handleCmd_inRoom ["TOGGLE_RESTRICT_TEAMS"] = do
       
   282     cl <- thisClient
       
   283     return $
       
   284         if not $ isMaster cl then
       
   285             [ProtocolError $ loc "Not room master"]
       
   286         else
       
   287             [ModifyRoom (\r -> r{isRestrictedTeams = not $ isRestrictedTeams r})]
       
   288 
       
   289 
       
   290 handleCmd_inRoom ["TOGGLE_REGISTERED_ONLY"] = do
       
   291     cl <- thisClient
       
   292     return $
       
   293         if not $ isMaster cl then
       
   294             [ProtocolError $ loc "Not room master"]
       
   295         else
       
   296             [ModifyRoom (\r -> r{isRegisteredOnly = not $ isRegisteredOnly r})]
       
   297 
       
   298 
       
   299 handleCmd_inRoom ["ROOM_NAME", newName] = do
       
   300     cl <- thisClient
       
   301     rs <- allRoomInfos
       
   302     rm <- thisRoom
       
   303     chans <- sameProtoChans
       
   304 
       
   305     return $
       
   306         if not $ isMaster cl then
       
   307             [ProtocolError $ loc "Not room master"]
       
   308         else
       
   309         if illegalName newName then
   289         if illegalName newName then
   310             [Warning $ loc "Illegal room name"]
   290             [Warning $ loc "Illegal room name"]
   311         else
   291         else
   312         if isSpecial rm then
   292         if isSpecial rm then
   313             [Warning $ loc "Restricted"]
   293             [Warning $ loc "Restricted"]
   319             AnswerClients chans ("ROOM" : "UPD" : name rm : roomInfo (clientProto cl) (nick cl) (roomUpdate rm))]
   299             AnswerClients chans ("ROOM" : "UPD" : name rm : roomInfo (clientProto cl) (nick cl) (roomUpdate rm))]
   320     where
   300     where
   321         roomUpdate r = r{name = newName}
   301         roomUpdate r = r{name = newName}
   322 
   302 
   323 
   303 
   324 handleCmd_inRoom ["KICK", kickNick] = do
   304 handleCmd_inRoom ["KICK", kickNick] = roomAdminOnly $ do
   325     (thisClientId, rnc) <- ask
   305     (thisClientId, rnc) <- ask
   326     maybeClientId <- clientByNick kickNick
   306     maybeClientId <- clientByNick kickNick
   327     master <- liftM isMaster thisClient
       
   328     rm <- thisRoom
   307     rm <- thisRoom
   329     let kickId = fromJust maybeClientId
   308     let kickId = fromJust maybeClientId
   330     let kickCl = rnc `client` kickId
   309     let kickCl = rnc `client` kickId
   331     let sameRoom = clientRoom rnc thisClientId == clientRoom rnc kickId
   310     let sameRoom = clientRoom rnc thisClientId == clientRoom rnc kickId
   332     let notOnly2Players = (length . group . sort . map teamowner . teams $ rm) > 2
   311     let notOnly2Players = (length . group . sort . map teamowner . teams $ rm) > 2
   333     return
   312     return
   334         [KickRoomClient kickId |
   313         [KickRoomClient kickId |
   335             master
   314             isJust maybeClientId
   336             && isJust maybeClientId
       
   337             && (kickId /= thisClientId)
   315             && (kickId /= thisClientId)
   338             && sameRoom
   316             && sameRoom
   339             && ((isNothing $ gameInfo rm) || notOnly2Players || teamsInGame kickCl == 0)
   317             && ((isNothing $ gameInfo rm) || notOnly2Players || teamsInGame kickCl == 0)
   340         ]
   318         ]
   341 
   319 
   381 handleCmd_inRoom ("RND":rs) = do
   359 handleCmd_inRoom ("RND":rs) = do
   382     n <- clientNick
   360     n <- clientNick
   383     s <- roomClientsChans
   361     s <- roomClientsChans
   384     return [AnswerClients s ["CHAT", n, B.unwords $ "/rnd" : rs], Random s rs]
   362     return [AnswerClients s ["CHAT", n, B.unwords $ "/rnd" : rs], Random s rs]
   385 
   363 
   386 handleCmd_inRoom ["FIX"] = do
   364 handleCmd_inRoom ["FIX"] = serverAdminOnly $
   387     cl <- thisClient
   365     return [ModifyRoom (\r -> r{isSpecial = True})]
   388     return [ModifyRoom (\r -> r{isSpecial = True}) | isAdministrator cl]
   366 
   389 
   367 handleCmd_inRoom ["UNFIX"] = serverAdminOnly $
   390 handleCmd_inRoom ["UNFIX"] = do
   368     return [ModifyRoom (\r -> r{isSpecial = False})]
   391     cl <- thisClient
       
   392     return [ModifyRoom (\r -> r{isSpecial = False}) | isAdministrator cl]
       
   393 
   369 
   394 handleCmd_inRoom ["GREETING", msg] = do
   370 handleCmd_inRoom ["GREETING", msg] = do
   395     cl <- thisClient
   371     cl <- thisClient
   396     rm <- thisRoom
   372     rm <- thisRoom
   397     return [ModifyRoom (\r -> r{greeting = msg}) | isAdministrator cl || (isMaster cl && (not $ isSpecial rm))]
   373     return [ModifyRoom (\r -> r{greeting = msg}) | isAdministrator cl || (isMaster cl && (not $ isSpecial rm))]
   427     if isJust b then
   403     if isJust b then
   428         voted (fromJust b)
   404         voted (fromJust b)
   429         else
   405         else
   430         return [AnswerClients [sendChan cl] ["CHAT", "[server]", "vote: 'yes' or 'no'"]]
   406         return [AnswerClients [sendChan cl] ["CHAT", "[server]", "vote: 'yes' or 'no'"]]
   431 
   407 
       
   408 
       
   409 handleCmd_inRoom ["SAVE", stateName] = serverAdminOnly $ do
       
   410     return [ModifyRoom $ \r -> r{roomSaves = Map.insert stateName (mapParams r, params r) (roomSaves r)}]
       
   411 
       
   412 handleCmd_inRoom ["DELETE", stateName] = serverAdminOnly $ do
       
   413     return [ModifyRoom $ \r -> r{roomSaves = Map.delete stateName (roomSaves r)}]
       
   414 
       
   415 
   432 handleCmd_inRoom ["LIST"] = return [] -- for old clients (<= 0.9.17)
   416 handleCmd_inRoom ["LIST"] = return [] -- for old clients (<= 0.9.17)
   433 
   417 
   434 handleCmd_inRoom (s:_) = return [ProtocolError $ "Incorrect command '" `B.append` s `B.append` "' (state: in room)"]
   418 handleCmd_inRoom (s:_) = return [ProtocolError $ "Incorrect command '" `B.append` s `B.append` "' (state: in room)"]
   435 
   419 
   436 handleCmd_inRoom [] = return [ProtocolError "Empty command (state: in room)"]
   420 handleCmd_inRoom [] = return [ProtocolError "Empty command (state: in room)"]