Keep room admin ready status always set
authorunc0rr
Sun, 21 Oct 2012 17:00:35 +0400
changeset 7775 835ad028fb66
parent 7773 3d460e57d4e6
child 7777 e0be9fbc21b4
Keep room admin ready status always set
QTfrontend/net/newnetclient.cpp
gameServer/Actions.hs
gameServer/HWProtoInRoomState.hs
gameServer/HWProtoLobbyState.hs
--- a/QTfrontend/net/newnetclient.cpp	Sun Oct 21 16:38:54 2012 +0400
+++ b/QTfrontend/net/newnetclient.cpp	Sun Oct 21 17:00:35 2012 +0400
@@ -102,9 +102,6 @@
 
     RawSendNet(QString("CREATE_ROOM%1%2").arg(delimeter).arg(room));
     isChief = true;
-
-    //set our ready status to be true
-    RawSendNet(QString("TOGGLE_READY"));
 }
 
 void HWNewNet::JoinRoom(const QString & room)
--- a/gameServer/Actions.hs	Sun Oct 21 16:38:54 2012 +0400
+++ b/gameServer/Actions.hs	Sun Oct 21 17:00:35 2012 +0400
@@ -261,12 +261,16 @@
     thisRoomChans <- liftM (map sendChan) $ roomClientsS ri
     let newRoomName = if proto < 42 then nick newMaster else oldRoomName
     mapM_ processAction [
-        ModifyRoom (\r -> r{masterID = newMasterId, name = newRoomName, isRestrictedJoins = False, isRestrictedTeams = False})
-        , ModifyClient2 newMasterId (\c -> c{isMaster = True})
+        ModifyRoom (\r -> r{masterID = newMasterId
+                , name = newRoomName
+                , isRestrictedJoins = False
+                , isRestrictedTeams = False
+                , readyPlayers = if isReady newMaster then readyPlayers r else readyPlayers r + 1})
+        , ModifyClient2 newMasterId (\c -> c{isMaster = True, isReady = True})
         , AnswerClients [sendChan newMaster] ["ROOM_CONTROL_ACCESS", "1"]
         , AnswerClients thisRoomChans ["WARNING", "New room admin is " `B.append` nick newMaster]
         , AnswerClients thisRoomChans ["CLIENT_FLAGS", "-h", oldMaster]
-        , AnswerClients thisRoomChans ["CLIENT_FLAGS", "+h", nick newMaster]
+        , AnswerClients thisRoomChans ["CLIENT_FLAGS", "+hr", nick newMaster]
         ]
 
     newRoom' <- io $ room'sM rnc id ri
@@ -279,7 +283,6 @@
     rnc <- gets roomsClients
     proto <- client's clientProto
     n <- client's nick
-    chan <- client's sendChan
 
     let rm = newRoom{
             masterID = clId,
@@ -296,8 +299,6 @@
 
     mapM_ processAction [
         AnswerClients chans ("ROOM" : "ADD" : roomInfo n rm)
-        , AnswerClients [chan] ["CLIENT_FLAGS", "+h", n]
-        , ModifyClient (\cl -> cl{isMaster = True})
         ]
 
 
@@ -323,9 +324,9 @@
     roomPlayers <- roomClientsS ri
     pr <- client's clientProto
     mapM_ processAction [
-        AnswerClients (map sendChan roomPlayers) $ notReadyMessage pr (map nick roomPlayers)
-        , ModifyRoomClients (\cl -> cl{isReady = False})
-        , ModifyRoom (\r -> r{readyPlayers = 0})
+        AnswerClients (map sendChan roomPlayers) $ notReadyMessage pr . map nick . filter (not . isMaster) $ roomPlayers
+        , ModifyRoomClients (\cl -> cl{isReady = isMaster cl})
+        , ModifyRoom (\r -> r{readyPlayers = 1})
         ]
     where
         notReadyMessage p nicks = if p < 38 then "NOT_READY" : nicks else "CLIENT_FLAGS" : "-r" : nicks
--- a/gameServer/HWProtoInRoomState.hs	Sun Oct 21 16:38:54 2012 +0400
+++ b/gameServer/HWProtoInRoomState.hs	Sun Oct 21 17:00:35 2012 +0400
@@ -157,14 +157,17 @@
 handleCmd_inRoom ["TOGGLE_READY"] = do
     cl <- thisClient
     chans <- roomClientsChans
-    return [
-        ModifyRoom (\r -> r{readyPlayers = readyPlayers r + (if isReady cl then -1 else 1)}),
-        ModifyClient (\c -> c{isReady = not $ isReady cl}),
-        AnswerClients chans $ if clientProto cl < 38 then
-                [if isReady cl then "NOT_READY" else "READY", nick cl]
-                else
-                ["CLIENT_FLAGS", if isReady cl then "-r" else "+r", nick cl]
-        ]
+    if isMaster cl then
+        return []
+        else
+        return [
+            ModifyRoom (\r -> r{readyPlayers = readyPlayers r + (if isReady cl then -1 else 1)}),
+            ModifyClient (\c -> c{isReady = not $ isReady cl}),
+            AnswerClients chans $ if clientProto cl < 38 then
+                    [if isReady cl then "NOT_READY" else "READY", nick cl]
+                    else
+                    ["CLIENT_FLAGS", if isReady cl then "-r" else "+r", nick cl]
+            ]
 
 handleCmd_inRoom ["START_GAME"] = do
     (ci, rnc) <- ask
--- a/gameServer/HWProtoLobbyState.hs	Sun Oct 21 16:38:54 2012 +0400
+++ b/gameServer/HWProtoLobbyState.hs	Sun Oct 21 17:00:35 2012 +0400
@@ -51,8 +51,10 @@
             [Warning "Room exists"]
             else
             [
-                AddRoom rName roomPassword,
-                AnswerClients [sendChan cl] ["CLIENT_FLAGS", "-r", nick cl]
+                AddRoom rName roomPassword
+                , AnswerClients [sendChan cl] ["CLIENT_FLAGS", "+hr", nick cl]
+                , ModifyClient (\cl -> cl{isMaster = True, isReady = True})
+                , ModifyRoom (\r -> r{readyPlayers = 1})
             ]