Restore teams in teams list on rejoin, should fix issues with second rejoin.
authorunc0rr
Sat, 05 Jul 2014 15:28:32 +0400
changeset 10351 0eff41e9f63f
parent 10350 4e919f7b9d92
child 10352 2af2309207b0
Restore teams in teams list on rejoin, should fix issues with second rejoin.
gameServer/HWProtoLobbyState.hs
gameServer/Utils.hs
--- a/gameServer/HWProtoLobbyState.hs	Fri Jul 04 22:45:59 2014 +0400
+++ b/gameServer/HWProtoLobbyState.hs	Sat Jul 05 15:28:32 2014 +0400
@@ -63,7 +63,7 @@
     let chans = map sendChan (cl : jRoomClients)
     let isBanned = host cl `elem` roomBansList jRoom
     let clTeams =
-            if (isJust $ gameInfo jRoom) then
+            if (clientProto cl >= 48) && (isJust $ gameInfo jRoom) then
                 map teamname . filter (\t -> teamowner t == nick cl) . teamsAtStart . fromJust $ gameInfo jRoom 
                 else
                 []
@@ -87,6 +87,7 @@
                 : AnswerClients chans ["CLIENT_FLAGS", "-r", nick cl]
                 : [(AnswerClients [sendChan cl] $ "JOINED" : nicks) | not $ null nicks]
             )
+                ++ [ModifyRoom (\r -> let (t', g') = moveTeams clTeams . fromJust $ gameInfo r in r{gameInfo = Just g', teams = t'}) | not $ null clTeams]
             ++ [AnswerClients [sendChan cl] ["CLIENT_FLAGS", "+h", nick $ fromJust owner] | isJust owner]
             ++ [sendStateFlags cl jRoomClients | not $ null jRoomClients]
             ++ answerFullConfig cl jRoom
@@ -96,6 +97,9 @@
             ++ map (\t -> AnswerClients chans ["EM", toEngineMsg $ 'G' `B.cons` t]) clTeams
 
         where
+        moveTeams :: [B.ByteString] -> GameInfo -> ([TeamInfo], GameInfo)
+        moveTeams cts g = (deleteFirstsBy2 (\a b -> teamname a == b) (teamsAtStart g) (leftTeams g \\ cts)
+            , g{leftTeams = leftTeams g \\ cts, teamsInGameNumber = teamsInGameNumber g + length cts})
         sendStateFlags cl clients = AnswerClients [sendChan cl] . concat . intersperse [""] . filter (not . null) . concat $
                 [f "+r" ready, f "-r" unready, f "+g" ingame, f "-g" inroomlobby]
             where
--- a/gameServer/Utils.hs	Fri Jul 04 22:45:59 2014 +0400
+++ b/gameServer/Utils.hs	Sat Jul 05 15:28:32 2014 +0400
@@ -185,4 +185,13 @@
 loc = id
 
 maybeNick :: Maybe ClientInfo -> B.ByteString
-maybeNick = fromMaybe "[empty]" . liftM nick
+maybeNick = fromMaybe "[]" . liftM nick
+
+-- borrowed from Data.List, just more general in types
+deleteBy2                :: (a -> b -> Bool) -> a -> [b] -> [b]
+deleteBy2 _  _ []        = []
+deleteBy2 eq x (y:ys)    = if x `eq` y then ys else y : deleteBy2 eq x ys
+
+deleteFirstsBy2          :: (a -> b -> Bool) -> [a] -> [b] -> [a]
+deleteFirstsBy2 eq       =  foldl (flip (deleteBy2 (flip eq)))
+