# HG changeset patch # User unc0rr # Date 1236631637 0 # Node ID bb114339eb4ed0b0eff1d87eb34533d74113abc6 # Parent b3b277d2b891c6ed8f3c313e8fe70ef4fed4b4ed Implement kick from room diff -r b3b277d2b891 -r bb114339eb4e QTfrontend/newnetclient.cpp --- a/QTfrontend/newnetclient.cpp Mon Mar 09 20:23:04 2009 +0000 +++ b/QTfrontend/newnetclient.cpp Mon Mar 09 20:47:17 2009 +0000 @@ -342,6 +342,13 @@ return; } + if(lst[0] == "KICKED") { + netClientState = 2; + emit showMessage(HWNewNet::tr("You got kicked")); + emit LeftRoom(); + return; + } + if(lst[0] == "JOINED") { if(lst.size() < 2) { diff -r b3b277d2b891 -r bb114339eb4e gameServer/Actions.hs --- a/gameServer/Actions.hs Mon Mar 09 20:23:04 2009 +0000 +++ b/gameServer/Actions.hs Mon Mar 09 20:47:17 2009 +0000 @@ -28,6 +28,8 @@ | Warning String | ByeClient String | KickClient Int -- clID + | KickRoomClient Int -- clID + | RemoveClientTeams Int -- clID | BanClient String -- nick | ModifyClient (ClientInfo -> ClientInfo) | ModifyRoom (RoomInfo -> RoomInfo) @@ -54,7 +56,8 @@ processAction (clID, serverInfo, clients, rooms) (AnswerAllOthers msg) = do - mapM_ (\id -> writeChan (sendChan $ clients ! id) msg) $ Prelude.filter (/= clID) (keys clients) + mapM_ (\id -> writeChan (sendChan $ clients ! id) msg) $ + Prelude.filter (\id' -> (id' /= clID) && (logonPassed $ clients ! id')) (keys clients) return (clID, serverInfo, clients, rooms) @@ -285,4 +288,19 @@ processAction (clID, serverInfo, clients, rooms) (KickClient kickID) = do - liftM2 replaceID (return clID) (processAction (kickID, serverInfo, clients, rooms) $ ByeClient "Kicked") \ No newline at end of file + liftM2 replaceID (return clID) (processAction (kickID, serverInfo, clients, rooms) $ ByeClient "Kicked") + + +processAction (clID, serverInfo, clients, rooms) (KickRoomClient kickID) = do + writeChan (sendChan $ clients ! kickID) ["KICKED"] + liftM2 replaceID (return clID) (processAction (kickID, serverInfo, clients, rooms) $ RoomRemoveThisClient) + + +processAction (clID, serverInfo, clients, rooms) (RemoveClientTeams teamsClID) = do + liftM2 replaceID (return clID) $ + foldM processAction (teamsClID, serverInfo, clients, rooms) $ removeTeamsActions + where + client = clients ! teamsClID + room = rooms ! (roomID client) + teamsToRemove = Prelude.filter (\t -> teamowner t == nick client) $ teams room + removeTeamsActions = Prelude.map (RemoveTeam . teamname) teamsToRemove diff -r b3b277d2b891 -r bb114339eb4e gameServer/HWProtoCore.hs --- a/gameServer/HWProtoCore.hs Mon Mar 09 20:23:04 2009 +0000 +++ b/gameServer/HWProtoCore.hs Mon Mar 09 20:47:17 2009 +0000 @@ -16,15 +16,12 @@ handleCmd clID _ _ ["PING"] = [AnswerThisClient ["PONG"]] handleCmd clID clients rooms ("QUIT" : xs) = - (if isMaster client then [RemoveRoom] else removeClientTeams) + (if isMaster client then [RemoveRoom] else [RemoveClientTeams clID]) ++ [ByeClient msg] where client = clients IntMap.! clID clientNick = nick client msg = if not $ null xs then head xs else "" - room = rooms IntMap.! (roomID client) - clientTeams = filter (\t -> teamowner t == nick client) $ teams room - removeClientTeams = map (RemoveTeam . teamname) clientTeams handleCmd clID clients rooms cmd = diff -r b3b277d2b891 -r bb114339eb4e gameServer/HWProtoInRoomState.hs --- a/gameServer/HWProtoInRoomState.hs Mon Mar 09 20:23:04 2009 +0000 +++ b/gameServer/HWProtoInRoomState.hs Mon Mar 09 20:47:17 2009 +0000 @@ -1,5 +1,6 @@ module HWProtoInRoomState where +import qualified Data.Foldable as Foldable import qualified Data.IntMap as IntMap import qualified Data.Map as Map import Data.Sequence(Seq, (|>), (><), fromList, empty) @@ -194,5 +195,24 @@ where client = clients IntMap.! clID +handleCmd_inRoom clID clients rooms ["KICK", kickNick] = + if not $ isMaster client then + [] + else + if noSuchClient then + [] + else + if (kickID == clID) || (roomID client /= roomID kickClient) then + [] + else + [RemoveClientTeams kickID, + KickRoomClient kickID] + where + client = clients IntMap.! clID + maybeClient = Foldable.find (\cl -> kickNick == nick cl) clients + noSuchClient = isNothing maybeClient + kickClient = fromJust maybeClient + kickID = clientUID kickClient + handleCmd_inRoom clID _ _ _ = [ProtocolError "Incorrect command (state: in room)"] diff -r b3b277d2b891 -r bb114339eb4e gameServer/HWProtoNEState.hs --- a/gameServer/HWProtoNEState.hs Mon Mar 09 20:23:04 2009 +0000 +++ b/gameServer/HWProtoNEState.hs Mon Mar 09 20:47:17 2009 +0000 @@ -41,6 +41,7 @@ parsedProto = fromMaybe 0 (maybeRead protoNum :: Maybe Word16) checkPassword = if (not . null) (nick client) then [CheckRegistered] else [] + handleCmd_NotEntered clID clients _ ["PASSWORD", passwd] = if passwd == webPassword client then [ModifyClient (\cl -> cl{logonPassed = True}),