hedgewars/uIO.pas
branchqmlfrontend
changeset 11454 3c5d99013baf
parent 11403 b894922d58cc
child 11544 b69f5f22a3ba
--- 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;