- Try sending remove message in 'finally' as a last resort
authorunc0rr
Thu, 28 Jun 2012 22:45:06 +0400
changeset 7321 57bd4f201401
parent 7319 c4705bca9f21
child 7323 8490a4f439a5
- Try sending remove message in 'finally' as a last resort - Some sources maintainance
QTfrontend/drawmapscene.cpp
gameServer/Actions.hs
gameServer/ClientIO.hs
gameServer/CoreTypes.hs
gameServer/HWProtoInRoomState.hs
gameServer/HWProtoLobbyState.hs
--- a/QTfrontend/drawmapscene.cpp	Wed Jun 27 16:40:36 2012 -0400
+++ b/QTfrontend/drawmapscene.cpp	Thu Jun 28 22:45:06 2012 +0400
@@ -136,7 +136,6 @@
 
 void DrawMapScene::showCursor()
 {
-    qDebug() << "show cursor";
     if(!m_isCursorShown)
         addItem(m_cursor);
 
@@ -145,7 +144,6 @@
 
 void DrawMapScene::hideCursor()
 {
-    qDebug() << "hide cursor";
     if(m_isCursorShown)
         removeItem(m_cursor);
 
--- a/gameServer/Actions.hs	Wed Jun 27 16:40:36 2012 -0400
+++ b/gameServer/Actions.hs	Thu Jun 28 22:45:06 2012 +0400
@@ -160,7 +160,7 @@
 
     s <- get
     put $! s{removedClients = ci `Set.delete` removedClients s}
-    
+
     sp <- gets (shutdownPending . serverInfo)
     cls <- allClientsS
     io $ when (sp && null cls) $ throwIO ShutdownException
@@ -251,7 +251,7 @@
     chans <- liftM (map sendChan) $! sameProtoClientsS proto
     processAction $ AnswerClients chans ("ROOM" : "UPD" : oldRoomName : roomInfo (nick newMaster) newRoom)
 
-    
+
 processAction (AddRoom roomName roomPassword) = do
     Just clId <- gets clientIndex
     rnc <- gets roomsClients
@@ -306,16 +306,16 @@
     where
         notReadyMessage p nicks = if p < 38 then "NOT_READY" : nicks else "CLIENT_FLAGS" : "-r" : nicks
 
-        
+
 processAction FinishGame = do
     rnc <- gets roomsClients
     ri <- clientRoomA
     thisRoomChans <- liftM (map sendChan) $ roomClientsS ri
     clNick <- client's nick
-    answerRemovedTeams <- io $ 
+    answerRemovedTeams <- io $
          room'sM rnc (map (\t -> AnswerClients thisRoomChans ["REMOVE_TEAM", t]) . leftTeams . fromJust . gameInfo) ri
-         
-    mapM_ processAction $ 
+
+    mapM_ processAction $
         SaveReplay
         : ModifyRoom
             (\r -> r{
@@ -326,7 +326,7 @@
         : UnreadyRoomClients
         : answerRemovedTeams
 
-        
+
 processAction (SendTeamRemovalMessage teamName) = do
     chans <- othersChans
     mapM_ processAction [
@@ -338,22 +338,22 @@
                 }) $ gameInfo r
             })
         ]
-        
+
     rnc <- gets roomsClients
     ri <- clientRoomA
     gi <- io $ room'sM rnc gameInfo ri
     when (isJust gi && 0 == teamsInGameNumber (fromJust gi)) $
-        processAction FinishGame        
+        processAction FinishGame
     where
         rmTeamMsg = toEngineMsg $ 'F' `B.cons` teamName
-    
-    
+
+
 processAction (RemoveTeam teamName) = do
     rnc <- gets roomsClients
     ri <- clientRoomA
     inGame <- io $ room'sM rnc (isJust . gameInfo) ri
     chans <- othersChans
-    mapM_ processAction $ 
+    mapM_ processAction $
         ModifyRoom (\r -> r{
             teams = Prelude.filter (\t -> teamName /= teamname t) $ teams r
             , gameInfo = liftM (\g -> g{leftTeams = teamName : leftTeams g}) $ gameInfo r
@@ -456,7 +456,7 @@
     bans <- gets (bans . serverInfo)
     processAction $
         AnswerClients [ch] ["BANLIST", B.pack $ show bans]
-    
+
 
 
 processAction (KickRoomClient kickId) = do
@@ -536,7 +536,7 @@
     where
           st irnc = (length $ allRooms irnc, length $ allClients irnc)
 
-processAction RestartServer = do 
+processAction RestartServer = do
     sp <- gets (shutdownPending . serverInfo)
     when (not sp) $ do
         sock <- gets (fromJust . serverSocket . serverInfo)
--- a/gameServer/ClientIO.hs	Wed Jun 27 16:40:36 2012 -0400
+++ b/gameServer/ClientIO.hs	Thu Jun 28 22:45:06 2012 +0400
@@ -43,16 +43,18 @@
 
 clientRecvLoop :: Socket -> Chan CoreMessage -> Chan [B.ByteString] -> ClientIndex -> (forall a. IO a -> IO a) -> IO ()
 clientRecvLoop s chan clChan ci restore =
-    myThreadId >>=
+    (myThreadId >>=
     \t -> (restore $ forkIO (clientSendLoop s t clChan ci) >>
         listenLoop s chan ci >> return "Connection closed")
+        `Exception.catch` (\(e :: ShutdownThreadException) -> return . B.pack . show $ e)
         `Exception.catch` (\(e :: Exception.IOException) -> return . B.pack . show $ e)
-        `Exception.catch` (\(e :: ShutdownThreadException) -> return . B.pack . show $ e)
         `Exception.catch` (\(e :: Exception.SomeException) -> return . B.pack . show $ e)
-        >>= clientOff >> remove
+        >>= clientOff) `Exception.finally` remove
     where
         clientOff msg = writeChan chan $ ClientMessage (ci, ["QUIT", msg])
-        remove = writeChan chan $ Remove ci
+        remove = do
+            clientOff "Client is in some weird state"
+            writeChan chan $ Remove ci
 
 
 
--- a/gameServer/CoreTypes.hs	Wed Jun 27 16:40:36 2012 -0400
+++ b/gameServer/CoreTypes.hs	Thu Jun 28 22:45:06 2012 +0400
@@ -62,7 +62,7 @@
         hedgehogs :: [HedgehogInfo]
     }
     deriving (Show, Read)
-    
+
 data GameInfo =
     GameInfo
     {
@@ -74,9 +74,9 @@
         giMapParams :: Map.Map B.ByteString B.ByteString,
         giParams :: Map.Map B.ByteString [B.ByteString]
     } deriving (Show, Read)
-    
---newGameInfo ::  -> GameInfo 
-newGameInfo = 
+
+--newGameInfo ::  -> GameInfo
+newGameInfo =
     GameInfo
         Data.Sequence.empty
         []
--- a/gameServer/HWProtoInRoomState.hs	Wed Jun 27 16:40:36 2012 -0400
+++ b/gameServer/HWProtoInRoomState.hs	Thu Jun 28 22:45:06 2012 +0400
@@ -79,10 +79,10 @@
         hhsList [_] = error "Hedgehogs list with odd elements number"
         hhsList (n:h:hhs) = HedgehogInfo n h : hhsList hhs
         newTeamHHNum r = min 4 (canAddNumber r)
-        maxTeams r 
+        maxTeams r
             | roomProto r < 38 = 6
             | otherwise = 8
-                
+
 
 handleCmd_inRoom ["REMOVE_TEAM", tName] = do
         (ci, _) <- ask
@@ -171,7 +171,7 @@
     cl <- thisClient
     rm <- thisRoom
     chans <- roomClientsChans
-    
+
     let allPlayersRegistered = all ((<) 0 . B.length . webPassword . client rnc . teamownerId) $ teams rm
 
     if isMaster cl && playersIn rm == readyPlayers rm && not (isJust $ gameInfo rm) then
@@ -247,7 +247,7 @@
     rs <- allRoomInfos
     rm <- thisRoom
     chans <- sameProtoChans
-    
+
     return $
         if not $ isMaster cl then
             [ProtocolError "Not room master"]
--- a/gameServer/HWProtoLobbyState.hs	Wed Jun 27 16:40:36 2012 -0400
+++ b/gameServer/HWProtoLobbyState.hs	Thu Jun 28 22:45:06 2012 +0400
@@ -71,7 +71,7 @@
     let nicks = map nick jRoomClients
     let chans = map sendChan (cl : jRoomClients)
     return $
-        if isNothing maybeRI || not sameProto then 
+        if isNothing maybeRI || not sameProto then
             [Warning "No such room"]
             else if isRestrictedJoins jRoom then
             [Warning "Joining restricted"]
@@ -147,12 +147,12 @@
     cl <- thisClient
     banId <- clientByNick banNick
     return [BanClient 60 reason (fromJust banId) | isAdministrator cl && isJust banId && fromJust banId /= ci]
-    
+
 handleCmd_lobby ["BANIP", ip, reason, duration] = do
     (ci, _) <- ask
     cl <- thisClient
     return [BanIP ip (readInt_ duration) reason | isAdministrator cl]
-    
+
 handleCmd_lobby ["BANLIST"] = do
     (ci, _) <- ask
     cl <- thisClient
@@ -172,7 +172,7 @@
     return [ModifyServerInfo (\si -> si{latestReleaseVersion = readNum}) | isAdministrator cl && readNum > 0]
     where
         readNum = readInt_ protoNum
- 
+
 handleCmd_lobby ["GET_SERVER_VAR"] = do
     cl <- thisClient
     return [SendServerVars | isAdministrator cl]