gameServer/HWProtoInRoomState.hs
branchsdl2transition
changeset 9798 f2b18754742f
parent 9787 0da6ba2f1f93
child 9950 2759212a27de
child 9995 8bf092ddc536
equal deleted inserted replaced
9711:7d0329f37181 9798:f2b18754742f
    29 handleCmd_inRoom ("CFG" : paramName : paramStrs)
    29 handleCmd_inRoom ("CFG" : paramName : paramStrs)
    30     | null paramStrs = return [ProtocolError $ loc "Empty config entry"]
    30     | null paramStrs = return [ProtocolError $ loc "Empty config entry"]
    31     | otherwise = do
    31     | otherwise = do
    32         chans <- roomOthersChans
    32         chans <- roomOthersChans
    33         cl <- thisClient
    33         cl <- thisClient
    34         if isMaster cl then
    34         rm <- thisRoom
       
    35 
       
    36         if isSpecial rm then
       
    37             return [Warning $ loc "Restricted"]
       
    38         else if isMaster cl then
    35            return [
    39            return [
    36                 ModifyRoom f,
    40                 ModifyRoom f,
    37                 AnswerClients chans ("CFG" : paramName : paramStrs)]
    41                 AnswerClients chans ("CFG" : paramName : paramStrs)]
    38             else
    42             else
    39             return [ProtocolError $ loc "Not room master"]
    43             return [ProtocolError $ loc "Not room master"]
    40     where
    44     where
    41         f r = if paramName `Map.member` (mapParams r) then
    45         f r = if paramName `Map.member` (mapParams r) then
    42                 r{mapParams = Map.insert paramName (head paramStrs) (mapParams r)}
    46                 r{mapParams = Map.insert paramName (head paramStrs) (mapParams r)}
    43                 else
    47                 else
    44                 r{params = Map.insert paramName paramStrs (params r)}
    48                 r{params = Map.insert paramName paramStrs (params r)}
       
    49 
    45 
    50 
    46 handleCmd_inRoom ("ADD_TEAM" : tName : color : grave : fort : voicepack : flag : difStr : hhsInfo)
    51 handleCmd_inRoom ("ADD_TEAM" : tName : color : grave : fort : voicepack : flag : difStr : hhsInfo)
    47     | length hhsInfo /= 16 = return [ProtocolError $ loc "Corrupted hedgehogs info"]
    52     | length hhsInfo /= 16 = return [ProtocolError $ loc "Corrupted hedgehogs info"]
    48     | otherwise = do
    53     | otherwise = do
    49         (ci, _) <- ask
    54         (ci, _) <- ask
   288             [ProtocolError $ loc "Not room master"]
   293             [ProtocolError $ loc "Not room master"]
   289         else
   294         else
   290         if illegalName newName then 
   295         if illegalName newName then 
   291             [Warning $ loc "Illegal room name"]
   296             [Warning $ loc "Illegal room name"]
   292         else
   297         else
       
   298         if isSpecial rm then
       
   299             [Warning $ loc "Restricted"]
       
   300         else
   293         if isJust $ find (\r -> newName == name r) rs then
   301         if isJust $ find (\r -> newName == name r) rs then
   294             [Warning $ loc "Room with such name already exists"]
   302             [Warning $ loc "Room with such name already exists"]
   295         else
   303         else
   296             [ModifyRoom roomUpdate,
   304             [ModifyRoom roomUpdate,
   297             AnswerClients chans ("ROOM" : "UPD" : name rm : roomInfo (nick cl) (roomUpdate rm))]
   305             AnswerClients chans ("ROOM" : "UPD" : name rm : roomInfo (clientProto cl) (nick cl) (roomUpdate rm))]
   298     where
   306     where
   299         roomUpdate r = r{name = newName}
   307         roomUpdate r = r{name = newName}
   300 
   308 
   301 
   309 
   302 handleCmd_inRoom ["KICK", kickNick] = do
   310 handleCmd_inRoom ["KICK", kickNick] = do
   321 handleCmd_inRoom ["DELEGATE", newAdmin] = do
   329 handleCmd_inRoom ["DELEGATE", newAdmin] = do
   322     (thisClientId, rnc) <- ask
   330     (thisClientId, rnc) <- ask
   323     maybeClientId <- clientByNick newAdmin
   331     maybeClientId <- clientByNick newAdmin
   324     master <- liftM isMaster thisClient
   332     master <- liftM isMaster thisClient
   325     serverAdmin <- liftM isAdministrator thisClient
   333     serverAdmin <- liftM isAdministrator thisClient
       
   334     thisRoomMasterId <- liftM masterID thisRoom
   326     let newAdminId = fromJust maybeClientId
   335     let newAdminId = fromJust maybeClientId
   327     let sameRoom = clientRoom rnc thisClientId == clientRoom rnc newAdminId
   336     let sameRoom = clientRoom rnc thisClientId == clientRoom rnc newAdminId
   328     return
   337     return
   329         [ChangeMaster (Just newAdminId) |
   338         [ChangeMaster (Just newAdminId) |
   330             (master || serverAdmin)
   339             (master || serverAdmin)
   331                 && isJust maybeClientId
   340                 && isJust maybeClientId
   332                 && ((newAdminId /= thisClientId) || (serverAdmin && not master))
   341                 && ((newAdminId /= thisClientId) || (serverAdmin && not master))
       
   342                 && (Just newAdminId /= thisRoomMasterId)
   333                 && sameRoom]
   343                 && sameRoom]
   334 
   344 
   335 
   345 
   336 handleCmd_inRoom ["TEAMCHAT", msg] = do
   346 handleCmd_inRoom ["TEAMCHAT", msg] = do
   337     cl <- thisClient
   347     cl <- thisClient
   358 handleCmd_inRoom ("RND":rs) = do
   368 handleCmd_inRoom ("RND":rs) = do
   359     n <- clientNick
   369     n <- clientNick
   360     s <- roomClientsChans
   370     s <- roomClientsChans
   361     return [AnswerClients s ["CHAT", n, B.unwords $ "/rnd" : rs], Random s rs]
   371     return [AnswerClients s ["CHAT", n, B.unwords $ "/rnd" : rs], Random s rs]
   362 
   372 
       
   373 handleCmd_inRoom ["FIX"] = do
       
   374     cl <- thisClient
       
   375     return [ModifyRoom (\r -> r{isSpecial = True}) | isAdministrator cl]
       
   376 
       
   377 handleCmd_inRoom ["UNFIX"] = do
       
   378     cl <- thisClient
       
   379     return [ModifyRoom (\r -> r{isSpecial = False}) | isAdministrator cl]
       
   380 
       
   381 handleCmd_inRoom ["GREETING", msg] = do
       
   382     cl <- thisClient
       
   383     rm <- thisRoom
       
   384     return [ModifyRoom (\r -> r{greeting = msg}) | isAdministrator cl || (isMaster cl && (not $ isSpecial rm))]
       
   385 
   363 handleCmd_inRoom ["LIST"] = return [] -- for old clients (<= 0.9.17)
   386 handleCmd_inRoom ["LIST"] = return [] -- for old clients (<= 0.9.17)
   364 
   387 
   365 handleCmd_inRoom (s:_) = return [ProtocolError $ "Incorrect command '" `B.append` s `B.append` "' (state: in room)"]
   388 handleCmd_inRoom (s:_) = return [ProtocolError $ "Incorrect command '" `B.append` s `B.append` "' (state: in room)"]
   366 
   389 
   367 handleCmd_inRoom [] = return [ProtocolError "Empty command (state: in room)"]
   390 handleCmd_inRoom [] = return [ProtocolError "Empty command (state: in room)"]