hedgewars/uFLNet.pas
branchqmlfrontend
changeset 10935 3a65fcd7c335
parent 10933 f1da4126a61c
child 10951 89a7f617e091
--- a/hedgewars/uFLNet.pas	Sun May 17 00:14:30 2015 +0300
+++ b/hedgewars/uFLNet.pas	Mon May 18 00:07:52 2015 +0300
@@ -7,9 +7,9 @@
 procedure freeModule;
 
 implementation
-uses SDLh;
+uses SDLh, uFLIPC;
 
-const endCmd: array[0..1] of char = (#10, #10);
+const endCmd: string = #10 + #10;
 
 function getNextChar: char; forward;
 function getCurrChar: char; forward;
@@ -256,8 +256,13 @@
 procedure sendNet(s: shortstring);
 begin
     writeln('[NET] Send: ', s);
-    SDLNet_TCP_Send(sock, @s[1], byte(s[0]));
-    SDLNet_TCP_Send(sock, @endCmd, 2);
+    ipcToNet(s + endCmd);
+end;
+
+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
+    SDLNet_TCP_Send(sock, msg, len);
 end;
 
 procedure connectOfficialServer;
@@ -279,6 +284,8 @@
     sock:= nil;
 
     SDLNet_Init;
+
+    registerNetCallback(nil, @netSendCallback);
 end;
 
 procedure freeModule;