--- a/hedgewars/uFLNet.pas Wed Apr 22 23:33:16 2015 +0300
+++ b/hedgewars/uFLNet.pas Sat Apr 25 23:46:09 2015 +0300
@@ -11,7 +11,32 @@
var sock: PTCPSocket;
fds: PSDLNet_SocketSet;
- buf: shortstring;
+ netReaderThread: PSDL_Thread;
+ sockbuf: shortstring;
+ sockbufpos: byte;
+
+function getNextChar: char;
+var r: byte;
+begin
+ if sockbufpos < byte(sockbuf[0]) then
+ begin
+ inc(sockbufpos);
+ getNextChar:= sockbuf[sockbufpos];
+ end else
+ begin
+ r:= SDLNet_TCP_Recv(sock, @sockbuf[1], 255);
+ if r > 0 then
+ begin
+ sockbufpos:= 1;
+ sockbuf[0]:= char(i);
+ getNextChar:= sockbuf[1];
+ end else
+ begin
+ sockbufpos:= 0;
+ sockbuf[0]:= #0;
+ getNextChar:= #0
+ end;
+end;
function netReader(data: pointer): LongInt; cdecl; export;
begin
@@ -26,7 +51,9 @@
if SDLNet_ResolveHost(ipaddr, PChar('netserver.hedgewars.org'), 46631) = 0 then
sock:= SDLNet_TCP_Open(ipaddr);
- callbackListenerThread:= SDL_CreateThread(@listener{$IFDEF SDL2}, 'ipcListener'{$ENDIF}, nil);
+ sockbufpos:= 0;
+ sockbuf:= '';
+ netReaderThread:= SDL_CreateThread(@netReader{$IFDEF SDL2}, 'netReader'{$ENDIF}, nil);
end;
procedure initModule;