Make in-game chat work qmlfrontend
authorunc0rr
Thu, 11 Aug 2016 23:05:14 +0300
branchqmlfrontend
changeset 11843 01f88c3b7b66
parent 11842 93e6c401cc3d
child 12855 1b2b84315d27
Make in-game chat work
hedgewars/hwLibrary.pas
hedgewars/uFLNet.pas
hedgewars/uFLNetProtocol.pas
hedgewars/uFLUICallback.pas
hedgewars/uIO.pas
--- a/hedgewars/hwLibrary.pas	Tue Aug 02 23:08:17 2016 +0300
+++ b/hedgewars/hwLibrary.pas	Thu Aug 11 23:05:14 2016 +0300
@@ -181,6 +181,7 @@
     // network
     connectOfficialServer,
     passNetData,
+    passToNet,
     passFlibEvent,
     sendChatLine,
     joinRoom,
--- a/hedgewars/uFLNet.pas	Tue Aug 02 23:08:17 2016 +0300
+++ b/hedgewars/uFLNet.pas	Thu Aug 11 23:05:14 2016 +0300
@@ -11,6 +11,7 @@
 procedure passToNet(data: PByteArray; len: Longword);
 
 var isConnected: boolean = false;
+    myNickname: shortstring = 'qmlfrontend';
 
 implementation
 uses uFLIPC, uFLUICallback, uFLNetTypes, uFLUtils, uFLTypes;
@@ -402,6 +403,8 @@
 
 procedure passToNet(data: PByteArray; len: Longword);
 var i: Longword;
+    l: ansistring;
+    s: shortstring;
 begin
     i:= 0;
 
@@ -409,8 +412,15 @@
     begin
         if data^[i + 1] = ord('s') then
         begin
-            sendUI(mtRoomChatLine, @(data^[i + 2]), data^[i]);
-            //sendChatLine()
+            s[0]:= char(data^[i] - 1);
+            Move(data^[i + 2], s[1], data^[i] - 1);
+
+            l:= myNickname + #10;
+            l:= l + s;
+
+            sendUI(mtRoomChatLine, @l[1], length(l));
+            sendNetLn('CHAT');
+            sendNet(s);
         end;
 
         inc(i, data^[i] + 1);
--- a/hedgewars/uFLNetProtocol.pas	Tue Aug 02 23:08:17 2016 +0300
+++ b/hedgewars/uFLNetProtocol.pas	Thu Aug 11 23:05:14 2016 +0300
@@ -16,7 +16,6 @@
     PHandler = procedure (var t: TCmdData);
 
 var isInRoom: boolean;
-    myNickname: shortstring;
 
 procedure onRoomLeaving();
 begin
@@ -310,8 +309,8 @@
 begin
     sendUI(mtConnected, nil, 0);
     //writeln('Server features version ', p.param1);
-    sendNet('PROTO' + #10 + '51');
-    sendNet('NICK' + #10 + 'qmlfrontend');
+    sendNet('PROTO' + #10 + '52');
+    sendNet('NICK' + #10 + myNickname);
 end;
 
 procedure handler_EM(var p: TCmdParam);
--- a/hedgewars/uFLUICallback.pas	Tue Aug 02 23:08:17 2016 +0300
+++ b/hedgewars/uFLUICallback.pas	Thu Aug 11 23:05:14 2016 +0300
@@ -14,10 +14,9 @@
 
 procedure engineMessageCallback(p: pointer; msg: PChar; len: Longword);
 begin
-    if msg^ = 'T' then
+    if (len >= 3) and (msg[1] = 'T') then
     begin
-        inc(msg);
-        isGame:= msg^ = 'G';
+        isGame:= msg[2] = 'G';
         exit;
     end;
 
--- a/hedgewars/uIO.pas	Tue Aug 02 23:08:17 2016 +0300
+++ b/hedgewars/uIO.pas	Thu Aug 11 23:05:14 2016 +0300
@@ -256,7 +256,9 @@
 
 procedure flushBuffer();
 begin
+    ipcToFrontendRaw(@sendBuffer.buf, sendBuffer.count);
     flushDelayTicks:= 0;
+    sendBuffer.count:= 0;
 end;
 
 procedure SendIPC(s: shortstring);
@@ -269,7 +271,20 @@
     AddFileLog('[IPC out] '+ sanitizeCharForLog(s[1]));
     inc(s[0], 2);
 
-    ipcToFrontend(s)
+    if isSyncedCommand(s[1]) then
+        begin
+        if sendBuffer.count + byte(s[0]) >= cSendBufferSize then
+            flushBuffer();
+
+        Move(s, sendBuffer.buf[sendBuffer.count], byte(s[0]) + 1);
+        inc(sendBuffer.count, byte(s[0]) + 1);
+
+        if (s[1] = 'N') or (s[1] = '#') then
+            flushBuffer();
+        end
+    else
+        ipcToFrontendRaw(@s, Succ(byte(s[0])))
+
 end;
 
 procedure SendIPCRaw(p: pointer; len: Longword);