# HG changeset patch # User unc0rr # Date 1277230904 -14400 # Node ID 7d99655130ffc7c12be837fe2a7d075b776dc6b0 # Parent 51521238724fedc7cb6b42a47002e6017848eb09 Partially reimplement joining rooms diff -r 51521238724f -r 7d99655130ff gameServer/HWProtoLobbyState.hs --- a/gameServer/HWProtoLobbyState.hs Tue Jun 22 18:06:55 2010 +0200 +++ b/gameServer/HWProtoLobbyState.hs Tue Jun 22 22:21:44 2010 +0400 @@ -74,6 +74,35 @@ handleCmd_lobby ["CREATE_ROOM", newRoom] = handleCmd_lobby ["CREATE_ROOM", newRoom, ""] + +handleCmd_lobby ["JOIN_ROOM", roomName, roomPassword] = do + (ci, irnc) <- ask + let ris = allRooms irnc + let cl = irnc `client` ci + let maybeRI = find (\ri -> roomName == name (irnc `room` ri)) ris + let jRI = fromJust maybeRI + let jRoom = irnc `room` jRI + let jRoomClients = map (client irnc) $! roomClients irnc jRI -- no lazyness here! + return $ + if isNothing maybeRI then + [Warning "No such rooms"] + else if isRestrictedJoins jRoom then + [Warning "Joining restricted"] + else if roomPassword /= password jRoom then + [Warning "Wrong password"] + else + [ + MoveToRoom jRI, + AnswerClients (map sendChan $ cl : jRoomClients) ["NOT_READY", nick cl] + ] + ++ [ AnswerClients [sendChan cl] $ "JOINED" : map nick jRoomClients | playersIn jRoom /= 0] + ++ (map (readynessMessage cl) jRoomClients) + + where + readynessMessage cl c = AnswerClients [sendChan cl] [if isReady c then "READY" else "NOT_READY", nick c] + + + {- handleCmd_lobby clID clients rooms ["JOIN_ROOM", roomName, roomPassword] @@ -90,12 +119,6 @@ ++ answerTeams ++ watchRound where - noSuchRoom = isNothing mbRoom - mbRoom = find (\r -> roomName == name r && roomProto r == clientProto client) $ IntMap.elems rooms - jRoom = fromJust mbRoom - rID = roomUID jRoom - client = clients IntMap.! clID - roomClientsIDs = IntSet.elems $ playersIDs jRoom answerNicks = [AnswerThisClient $ "JOINED" : map (\clID -> nick $ clients IntMap.! clID) roomClientsIDs | playersIn jRoom /= 0] @@ -121,12 +144,12 @@ answerAllTeams (clientProto client) (teamsAtStart jRoom) else answerAllTeams (clientProto client) (teams jRoom) - +-} -handleCmd_lobby clID clients rooms ["JOIN_ROOM", roomName] = - handleCmd_lobby clID clients rooms ["JOIN_ROOM", roomName, ""] +handleCmd_lobby ["JOIN_ROOM", roomName] = + handleCmd_lobby ["JOIN_ROOM", roomName, ""] - +{- handleCmd_lobby clID clients rooms ["FOLLOW", asknick] = if noSuchClient || roomID followClient == 0 then [] diff -r 51521238724f -r 7d99655130ff gameServer/HWProtoNEState.hs --- a/gameServer/HWProtoNEState.hs Tue Jun 22 18:06:55 2010 +0200 +++ b/gameServer/HWProtoNEState.hs Tue Jun 22 22:21:44 2010 +0400 @@ -31,6 +31,7 @@ where haveSameNick irnc = False --isJust $ find (\cl -> newNick == nick cl) $ IntMap.elems clients + handleCmd_NotEntered ["PROTO", protoNum] = do (ci, irnc) <- ask let cl = irnc `client` ci @@ -47,18 +48,17 @@ Just (i, t) | B.null t -> fromIntegral i otherwise -> 0 -{- + +handleCmd_NotEntered ["PASSWORD", passwd] = do + (ci, irnc) <- ask + let cl = irnc `client` ci -handleCmd_NotEntered clID clients _ ["PASSWORD", passwd] = - if passwd == webPassword client then - [ModifyClient (\cl -> cl{logonPassed = True}), - MoveToLobby] ++ adminNotice - else - [ByeClient "Authentication failed"] - where - client = clients IntMap.! clID - adminNotice = [AnswerThisClient ["ADMIN_ACCESS"] | isAdministrator client] + if passwd == webPassword cl then + return $ JoinLobby : [AnswerClients [sendChan cl] ["ADMIN_ACCESS"] | isAdministrator cl] + else + return [ByeClient "Authentication failed"] +{- handleCmd_NotEntered clID clients _ ["DUMP"] = if isAdministrator (clients IntMap.! clID) then [Dump] else []