hedgewars/uFLNet.pas
branchqmlfrontend
changeset 11420 05cf35103206
parent 11418 ffff8a0d1a76
child 11423 091149424aa4
--- a/hedgewars/uFLNet.pas	Wed Nov 18 22:18:39 2015 +0300
+++ b/hedgewars/uFLNet.pas	Thu Nov 19 23:04:53 2015 +0300
@@ -6,6 +6,7 @@
 procedure initModule;
 procedure freeModule;
 procedure sendNet(s: shortstring);
+procedure sendNetLn(s: shortstring);
 
 implementation
 uses SDLh, uFLIPC, uFLTypes, uFLUICallback, uFLNetTypes, uFLUtils;
@@ -81,7 +82,6 @@
     f: boolean;
 begin
     sendUI(mtNetData, @state.cmd, sizeof(state.cmd));
-    writeln('handler_MS');
     cmd.cmd:= Succ(state.cmd);
 
     repeat
@@ -99,8 +99,12 @@
 end;
 
 procedure handler_SL;
+var cmd: TCmdParamSL;
 begin
-    writeln('handler_SL');
+    cmd.cmd:= state.cmd;
+    cmd.str1:= getShortString;
+    cmd.str2:= getShortString; // FIXME should be long string
+    sendUI(mtNetData, @cmd, sizeof(cmd));
     handleTail()
 end;
 
@@ -195,11 +199,6 @@
     getNextChar:= state.buf[state.bufpos];
 end;
 
-function netWriter(sock: PTCPSocket): LongInt; cdecl; export;
-begin
-    netWriter:= 0;
-end;
-
 function netReader(data: pointer): LongInt; cdecl; export;
 var c: char;
     ipaddr: TIPAddress;
@@ -209,8 +208,6 @@
     if SDLNet_ResolveHost(ipaddr, PChar('netserver.hedgewars.org'), 46631) = 0 then
         sock:= SDLNet_TCP_Open(ipaddr);
 
-    SDL_CreateThread(@netWriter, 'netWriter', sock);
-
     repeat
         c:= getNextChar;
         //writeln('>>>>> ', c, ' [', letters[state.l], '] ', commands[state.l]);
@@ -238,6 +235,7 @@
         end
     until state.netState = netDisconnected;
 
+    SDLNet_TCP_Close(sock);
     sock:= nil;
 
     writeln('[NET] netReader: disconnected');
@@ -249,6 +247,12 @@
     ipcToNet(s + endCmd);
 end;
 
+procedure sendNetLn(s: shortstring);
+begin
+    writeln('[NET] Send: ', s);
+    ipcToNet(s + #10);
+end;
+
 function getShortString: shortstring;
 var s: shortstring;
     c: char;
@@ -286,6 +290,7 @@
     state.netState:= netConnecting;
 
     netReaderThread:= SDL_CreateThread(@netReader, 'netReader', nil);
+    SDL_DetachThread(netReaderThread)
 end;
 
 procedure initModule;