Preparation to sending engine messages to net. qmlfrontend
authorunc0rr
Tue, 02 Aug 2016 23:08:17 +0300
branchqmlfrontend
changeset 11842 93e6c401cc3d
parent 11841 6adf27e85cae
child 11843 01f88c3b7b66
Preparation to sending engine messages to net.
hedgewars/uFLNet.pas
hedgewars/uFLTypes.pas
hedgewars/uFLUICallback.pas
qmlFrontend/flib.h
qmlFrontend/hwengine.cpp
--- a/hedgewars/uFLNet.pas	Fri Jul 15 22:39:07 2016 +0300
+++ b/hedgewars/uFLNet.pas	Tue Aug 02 23:08:17 2016 +0300
@@ -1,5 +1,6 @@
 unit uFLNet;
 interface
+uses SDLh;
 
 procedure connectOfficialServer;
 
@@ -7,11 +8,12 @@
 procedure freeModule;
 procedure sendNet(s: shortstring);
 procedure sendNetLn(s: shortstring);
+procedure passToNet(data: PByteArray; len: Longword);
 
 var isConnected: boolean = false;
 
 implementation
-uses SDLh, uFLIPC, uFLTypes, uFLUICallback, uFLNetTypes, uFLUtils;
+uses uFLIPC, uFLUICallback, uFLNetTypes, uFLUtils, uFLTypes;
 
 const endCmd: shortstring = #10 + #10;
 
@@ -378,7 +380,7 @@
 
 procedure netSendCallback(p: pointer; msg: PChar; len: Longword);
 begin
-    // W A R N I N G: totally thread-unsafe due to use of sock variable
+    // FIXME W A R N I N G: totally thread-unsafe due to use of sock variable
     SDLNet_TCP_Send(sock, msg, len);
 end;
 
@@ -397,6 +399,24 @@
     SDL_DetachThread(netReaderThread)
 end;
 
+
+procedure passToNet(data: PByteArray; len: Longword);
+var i: Longword;
+begin
+    i:= 0;
+
+    while(i < len) do
+    begin
+        if data^[i + 1] = ord('s') then
+        begin
+            sendUI(mtRoomChatLine, @(data^[i + 2]), data^[i]);
+            //sendChatLine()
+        end;
+
+        inc(i, data^[i] + 1);
+    end;
+end;
+
 procedure initModule;
 begin
     sock:= nil;
--- a/hedgewars/uFLTypes.pas	Fri Jul 15 22:39:07 2016 +0300
+++ b/hedgewars/uFLTypes.pas	Tue Aug 02 23:08:17 2016 +0300
@@ -9,7 +9,7 @@
     TMessageType = (mtRenderingPreview, mtPreview, mtPreviewHogCount
                     , mtAddPlayingTeam, mtRemovePlayingTeam
                     , mtAddTeam, mtRemoveTeam, mtTeamColor, mtHedgehogsNumber
-                    , mtNetData
+                    , mtNetData, mtToNet
                     , mtFlibEvent, mtConnected, mtDisconnected, mtAddLobbyClient
                     , mtRemoveLobbyClient, mtLobbyChatLine, mtAddRoomClient
                     , mtRemoveRoomClient, mtRoomChatLine, mtAddRoom, mtUpdateRoom
--- a/hedgewars/uFLUICallback.pas	Fri Jul 15 22:39:07 2016 +0300
+++ b/hedgewars/uFLUICallback.pas	Tue Aug 02 23:08:17 2016 +0300
@@ -23,6 +23,7 @@
 
     if isGame then
     begin
+        uiCallbackFunction(uiCallbackPointer, mtToNet, msg, len)
     end
     else begin
         if len = 128 * 256 then
--- a/qmlFrontend/flib.h	Fri Jul 15 22:39:07 2016 +0300
+++ b/qmlFrontend/flib.h	Tue Aug 02 23:08:17 2016 +0300
@@ -18,6 +18,7 @@
     , MSG_TEAMCOLOR
     , MSG_HEDGEHOGSNUMBER
     , MSG_NETDATA
+    , MSG_TONET
     , MSG_FLIBEVENT
     , MSG_CONNECTED
     , MSG_DISCONNECTED
@@ -73,6 +74,7 @@
 typedef void flibInit_t(const char * localPrefix, const char * userPrefix);
 typedef void flibFree_t();
 typedef void passNetData_t(const char * data);
+typedef void passToNet_t(const char * data, uint32_t size);
 typedef void passFlibEvent_t(const char * data);
 typedef void sendChatLine_t(const char * msg);
 typedef void joinRoom_t(const char * roomName);
--- a/qmlFrontend/hwengine.cpp	Fri Jul 15 22:39:07 2016 +0300
+++ b/qmlFrontend/hwengine.cpp	Tue Aug 02 23:08:17 2016 +0300
@@ -36,6 +36,7 @@
 
     connectOfficialServer_t * flibConnectOfficialServer;
     passNetData_t * flibPassNetData;
+    passToNet_t * flibPassToNet;
     passFlibEvent_t * flibPassFlibEvent;
     sendChatLine_t * flibSendChatLine;
     joinRoom_t * flibJoinRoom;
@@ -90,6 +91,7 @@
 
     flibConnectOfficialServer = (connectOfficialServer_t*) hwlib.resolve("connectOfficialServer");
     flibPassNetData = (passNetData_t*) hwlib.resolve("passNetData");
+    flibPassToNet = (passToNet_t*) hwlib.resolve("passToNet");
     flibPassFlibEvent = (passFlibEvent_t*) hwlib.resolve("passFlibEvent");
     flibSendChatLine = (sendChatLine_t*) hwlib.resolve("sendChatLine");
     flibJoinRoom = (joinRoom_t*) hwlib.resolve("joinRoom");
@@ -201,6 +203,10 @@
         flibPassNetData(msg.constData());
         break;
     }
+    case MSG_TONET: {
+        flibPassToNet(msg.constData(), msg.size());
+        break;
+    }
     case MSG_FLIBEVENT: {
         flibPassFlibEvent(msg.constData());
         break;