Convert READY and NOT_READY messages to CLIENT_FLAGS message
authorunc0rr
Sat, 05 Feb 2011 11:05:16 +0300
changeset 4917 8ff92bdc9f98
parent 4916 33c1e9bc68ad
child 4918 c6d3aec73f93
Convert READY and NOT_READY messages to CLIENT_FLAGS message
QTfrontend/chatwidget.cpp
QTfrontend/newnetclient.cpp
gameServer/Actions.hs
gameServer/HWProtoInRoomState.hs
gameServer/HWProtoLobbyState.hs
--- a/QTfrontend/chatwidget.cpp	Fri Feb 04 20:41:46 2011 +0100
+++ b/QTfrontend/chatwidget.cpp	Sat Feb 05 11:05:16 2011 +0300
@@ -502,6 +502,8 @@
 
 void HWChatWidget::chatNickDoubleClicked(QListWidgetItem * item)
 {
+    Q_UNUSED(item);
+
     QList<QAction *> actions = chatNicks->actions();
     actions.first()->activate(QAction::Trigger);
 }
--- a/QTfrontend/newnetclient.cpp	Fri Feb 04 20:41:46 2011 +0100
+++ b/QTfrontend/newnetclient.cpp	Sat Feb 05 11:05:16 2011 +0300
@@ -312,33 +312,36 @@
         return;
     }
 
-    if (lst[0] == "READY") {
-        if(lst.size() < 2)
+    if (lst[0] == "CLIENT_FLAGS")
+    {
+        if(lst.size() < 3 || lst[1].size() < 2)
         {
-            qWarning("Net: Malformed READY message");
+            qWarning("Net: Malformed CLIENT_FLAGS message");
             return;
         }
-        for(int i = 1; i < lst.size(); ++i)
+
+        QString flags = lst[1];
+        bool setFlag = flags[0] == '+';
+
+        while(flags.size() > 1)
         {
-            if (lst[i] == mynick)
-                emit setMyReadyStatus(true);
-            emit setReadyStatus(lst[i], true);
-        }
-        return;
-    }
+            flags.remove(0, 1);
+            char c = flags[0].toAscii();
 
-    if (lst[0] == "NOT_READY") {
-        if(lst.size() < 2)
-        {
-            qWarning("Net: Malformed NOT_READY message");
-            return;
+            switch(c)
+            {
+            case 'r':
+                {
+                    for(int i = 2; i < lst.size(); ++i)
+                    {
+                        if (lst[i] == mynick)
+                            emit setMyReadyStatus(setFlag);
+                        emit setReadyStatus(lst[i], setFlag);
+                    }
+                }
+            }
         }
-        for(int i = 1; i < lst.size(); ++i)
-        {
-            if (lst[i] == mynick)
-                emit setMyReadyStatus(false);
-            emit setReadyStatus(lst[i], false);
-        }
+
         return;
     }
 
--- a/gameServer/Actions.hs	Fri Feb 04 20:41:46 2011 +0100
+++ b/gameServer/Actions.hs	Sat Feb 05 11:05:16 2011 +0300
@@ -262,7 +262,7 @@
     ri <- clientRoomA
     roomPlayers <- roomClientsS ri
     roomClIDs <- io $ roomClientsIndicesM rnc ri
-    processAction $ AnswerClients (map sendChan roomPlayers) ("NOT_READY" : map nick roomPlayers)
+    processAction $ AnswerClients (map sendChan roomPlayers) ("CLIENT_FLAGS" : "-r" : map nick roomPlayers)
     io $ mapM_ (modifyClient rnc (\cl -> cl{isReady = False})) roomClIDs
     processAction $ ModifyRoom (\r -> r{readyPlayers = 0})
 
--- a/gameServer/HWProtoInRoomState.hs	Fri Feb 04 20:41:46 2011 +0100
+++ b/gameServer/HWProtoInRoomState.hs	Sat Feb 05 11:05:16 2011 +0300
@@ -154,7 +154,7 @@
     return [
         ModifyClient (\c -> c{isReady = not $ isReady cl}),
         ModifyRoom (\r -> r{readyPlayers = readyPlayers r + (if isReady cl then -1 else 1)}),
-        AnswerClients chans [if isReady cl then "NOT_READY" else "READY", nick cl]
+        AnswerClients chans ["CLIENT_FLAGS", if isReady cl then "-r" else "+r", nick cl]
         ]
 
 handleCmd_inRoom ["START_GAME"] = do
--- a/gameServer/HWProtoLobbyState.hs	Fri Feb 04 20:41:46 2011 +0100
+++ b/gameServer/HWProtoLobbyState.hs	Sat Feb 05 11:05:16 2011 +0300
@@ -62,7 +62,7 @@
             else
             [
                 AddRoom newRoom roomPassword,
-                AnswerClients [sendChan cl] ["NOT_READY", nick cl]
+                AnswerClients [sendChan cl] ["CLIENT_FLAGS", "-r", nick cl]
             ]
 
 
@@ -91,7 +91,7 @@
             [
                 MoveToRoom jRI,
                 AnswerClients [sendChan cl] $ "JOINED" : nicks,
-                AnswerClients chans ["NOT_READY", nick cl]
+                AnswerClients chans ["CLIENT_FLAGS", "-r", nick cl]
             ]
             ++ (map (readynessMessage cl) jRoomClients)
             ++ (answerFullConfig cl $ params jRoom)
@@ -99,7 +99,7 @@
             ++ (watchRound cl jRoom)
 
         where
-        readynessMessage cl c = AnswerClients [sendChan cl] [if isReady c then "READY" else "NOT_READY", nick c]
+        readynessMessage cl c = AnswerClients [sendChan cl] ["CLIENT_FLAGS", if isReady c then "+r" else "-r", nick c]
 
         toAnswer cl (paramName, paramStrs) = AnswerClients [sendChan cl] $ "CFG" : paramName : paramStrs