- Improve IPC handling in engine qmlfrontend
authorunc0rr
Mon, 14 Dec 2015 00:24:03 +0300
branchqmlfrontend
changeset 11459 3c5d99013baf
parent 11458 e7c7ca0c1556
child 11460 96decedd9400
- Improve IPC handling in engine - Handle EM protocol command - Some fixes for net game
hedgewars/uFLGameConfig.pas
hedgewars/uFLIPC.pas
hedgewars/uFLNet.pas
hedgewars/uFLNetProtocol.pas
hedgewars/uFLTeams.pas
hedgewars/uIO.pas
qmlFrontend/qml/qmlFrontend/Lobby.qml
tools/protocolParser.hs
--- a/hedgewars/uFLGameConfig.pas	Sat Dec 12 23:42:40 2015 +0300
+++ b/hedgewars/uFLGameConfig.pas	Mon Dec 14 00:24:03 2015 +0300
@@ -68,7 +68,9 @@
                 ipcToEngine('e$template_filter ' + intToStr(template));
             ipcToEngine('e$feature_size ' + intToStr(featureSize));
         end;
-    gtLocal, gtNet: begin
+gtLocal, gtNet: begin
+            if gameType = gtNet then
+                ipcToEngine('TN');
             if script <> 'Normal' then
                 ipcToEngine('escript ' + getScriptPath(script));
             ipcToEngine('eseed ' + seed);
@@ -235,6 +237,7 @@
         c:= getUnusedColor;
 
         teams[i]:= team^;
+        teams[i].extDriven:= false;
 
         if i = 0 then hn:= 4 else hn:= teams[i - 1].hogsNumber;
         if hn > 48 - hedgehogsNumber then hn:= 48 - hedgehogsNumber;
--- a/hedgewars/uFLIPC.pas	Sat Dec 12 23:42:40 2015 +0300
+++ b/hedgewars/uFLIPC.pas	Mon Dec 14 00:24:03 2015 +0300
@@ -17,7 +17,7 @@
 
 procedure ipcToFrontend(s: shortstring);
 procedure ipcToFrontendRaw(p: pointer; len: Longword);
-function ipcReadFromFrontend: shortstring;
+function ipcReadFromFrontend: TIPCMessage;
 function ipcCheckFromFrontend: boolean;
 
 procedure registerIPCCallback(p: pointer; f: TIPCCallback);
@@ -212,9 +212,9 @@
     ipcReadFromEngine:= ipcRead(queueFrontend)
 end;
 
-function ipcReadFromFrontend: shortstring;
+function ipcReadFromFrontend: TIPCMessage;
 begin
-    ipcReadFromFrontend:= ipcRead(queueEngine).str
+    ipcReadFromFrontend:= ipcRead(queueEngine)
 end;
 
 function ipcReadToNet: TIPCMessage;
--- a/hedgewars/uFLNet.pas	Sat Dec 12 23:42:40 2015 +0300
+++ b/hedgewars/uFLNet.pas	Mon Dec 14 00:24:03 2015 +0300
@@ -221,7 +221,7 @@
     @handler_SL, @handler_, @handler_S, @handler_MS, @handler_MS, @handler_SS,
     @handler_L, @handler_ML, @handler__i, @handler_SMS, @handler_SL, @handler_S,
     @handler_i, @handler_S, @handler_S, @handler_MS, @handler_i, @handler_i,
-    @handler_S, @handler_ML, @handler_i, @handler_L, @handler_SL, @handler_SL,
+    @handler_S, @handler_MS, @handler_i, @handler_L, @handler_SL, @handler_SL,
     @handler_MS, @handler_S, @handler_MS);
 
 procedure handleTail;
--- a/hedgewars/uFLNetProtocol.pas	Sat Dec 12 23:42:40 2015 +0300
+++ b/hedgewars/uFLNetProtocol.pas	Mon Dec 14 00:24:03 2015 +0300
@@ -10,7 +10,7 @@
 procedure ResetNetState;
 
 implementation
-uses uFLNetTypes, uFLTypes, uFLUICallback, uFLNet, uFLGameConfig, uFLUtils;
+uses uFLNetTypes, uFLTypes, uFLUICallback, uFLNet, uFLGameConfig, uFLUtils, uFLIPC, uUtils;
 
 type
     PHandler = procedure (var t: TCmdData);
@@ -53,10 +53,10 @@
     , @tmpTeam.hedgehogs[7].name
     , @tmpTeam.hedgehogs[7].hat
     );
+
 procedure handler_ADD_TEAM(var p: TCmdParam);
 begin
     teamIndex:= 0;
-    tmpTeam.extDriven:= true;
     tmpTeam.color:= 0
 end;
 
@@ -317,8 +317,19 @@
 begin
 end;
 
-procedure handler_EM_s(var s: TCmdParamS);
+procedure handler_EM_s(var p: TCmdParamL);
+var i, l: Longword;
+    s: shortstring;
 begin
+    i:= 1;
+    l:= length(p.str1);
+
+    while i < l do
+    begin
+        s:= DecodeBase64(copy(p.str1, i, 240));
+        ipcToEngineRaw(@s[0], byte(s[0]));
+        inc(i, 160)
+    end;
 end;
 
 procedure handler_ERROR(var p: TCmdParamL);
@@ -411,7 +422,7 @@
 
 procedure handler_PROTO(var p: TCmdParami);
 begin
-    writeln('Protocol ', p.param1)
+    //writeln('Protocol ', p.param1)
 end;
 
 procedure handler_REMOVE_TEAM(var p: TCmdParamS);
--- a/hedgewars/uFLTeams.pas	Sat Dec 12 23:42:40 2015 +0300
+++ b/hedgewars/uFLTeams.pas	Mon Dec 14 00:24:03 2015 +0300
@@ -51,10 +51,12 @@
     with team do
     begin
         ipcToEngine('eaddteam <hash> ' + colorsSet[color] + ' ' + teamName);
+        if extDriven then
+            ipcToEngine('rdriven');
         for i:= 0 to Pred(hogsNumber) do
         begin
-            ipcToEngine('eaddhh ' + inttostr(botLevel) + ' 100 hog');// + hedgehogs[i].name);
-            //ipcToEngine('ehat ' + hedgehogs[i].hat);
+            ipcToEngine('eaddhh ' + inttostr(botLevel) + ' 100 ' + hedgehogs[i].name);
+            ipcToEngine('ehat ' + hedgehogs[i].hat);
         end;
     end
 end;
--- a/hedgewars/uIO.pas	Sat Dec 12 23:42:40 2015 +0300
+++ b/hedgewars/uIO.pas	Mon Dec 14 00:24:03 2015 +0300
@@ -38,7 +38,7 @@
 procedure doPut(putX, putY: LongInt; fromAI: boolean);
 
 implementation
-uses uConsole, uConsts, uVariables, uCommands, uUtils, uDebug, uFLIPC;
+uses uFLIPC, uFLTypes, uConsole, uConsts, uVariables, uCommands, uUtils, uDebug;
 
 const
     cSendEmptyPacketTime = 1000;
@@ -56,11 +56,12 @@
 
 var
     isPonged: boolean;
-    
+
     headcmd: PCmd;
     lastcmd: PCmd;
 
     flushDelayTicks: LongWord;
+    SocketString: shortstring;
     sendBuffer: record
                 buf: array[0..Pred(cSendBufferSize)] of byte;
                 count: Word;
@@ -156,9 +157,37 @@
 end;
 
 procedure IPCCheckSock;
+var i, t: LongInt;
+    msg: TIPCMessage;
 begin
     while ipcCheckFromFrontend() do
-        ParseIPCCommand(ipcReadFromFrontend())
+    begin
+        msg:= ipcReadFromFrontend();
+        if msg.str[0] > #0 then
+            ParseIPCCommand(msg.str)
+        else begin
+            i:= 0;
+            while (i < msg.len) do
+            begin
+                if LongInt(SocketString[0]) + msg.len - i > 255 then
+                    t:= 255 - byte(SocketString[0])
+                else
+                    t:= msg.len - i;
+
+                Move(PByteArray(msg.buf)^[i], SocketString[byte(SocketString[0]) + 1], t);
+                inc(byte(SocketString[0]), t);
+                inc(i, t);
+
+                while byte(SocketString[0]) > byte(SocketString[1]) do
+                begin
+                    ParseIPCCommand(copy(SocketString, 2, byte(SocketString[1])));
+                    Delete(SocketString, 1, Succ(byte(SocketString[1])))
+                end;
+            end;
+
+            FreeMem(msg.buf, msg.len)
+        end
+    end
 end;
 
 procedure LoadRecordFromFile(fileName: shortstring);
@@ -441,6 +470,7 @@
     headcmd:= nil;
     lastcmd:= nil;
     isPonged:= false;
+    SocketString:= '';
 
     hiTicks:= 0;
     flushDelayTicks:= 0;
--- a/qmlFrontend/qml/qmlFrontend/Lobby.qml	Sat Dec 12 23:42:40 2015 +0300
+++ b/qmlFrontend/qml/qmlFrontend/Lobby.qml	Mon Dec 14 00:24:03 2015 +0300
@@ -4,10 +4,10 @@
 Rectangle {
     ListView {
         id: roomsList
-        x: 20
-        y: 0
-        width: parent.width
-        height: parent.height - x
+        anchors.top: parent.top
+        anchors.left: parent.left
+        anchors.right: parent.right
+        anchors.bottom: lobbyChat.top
         focus: true
         clip: true
 
@@ -93,10 +93,11 @@
 
     Chat {
         id: lobbyChat;
-        x: 0;
-        y: 300;
-        width: parent.width;
-        height: parent.height - y;
+        height: 300
+        anchors.top: undefined
+        anchors.left: parent.left
+        anchors.right: parent.right
+        anchors.bottom: parent.bottom
 
         Connections {
             target: HWEngine
--- a/tools/protocolParser.hs	Sat Dec 12 23:42:40 2015 +0300
+++ b/tools/protocolParser.hs	Mon Dec 14 00:24:03 2015 +0300
@@ -109,7 +109,7 @@
         , cmd1 "CFG~SCRIPT" SS
         , cmd1 "CFG~DRAWNMAP" LS
         , cmd2 "CFG~AMMO" SS LS
-        , cmd1 "CFG~FULLMAPCONFIG" $ Many [LS]
+        , cmd1 "CFG~FULLMAPCONFIG" $ Many [SS]
     ]
 
 hasMany = any isMany