hedgewars/uFLNet.pas
branchqmlfrontend
changeset 10935 3a65fcd7c335
parent 10933 f1da4126a61c
child 10951 89a7f617e091
equal deleted inserted replaced
10933:f1da4126a61c 10935:3a65fcd7c335
     5 
     5 
     6 procedure initModule;
     6 procedure initModule;
     7 procedure freeModule;
     7 procedure freeModule;
     8 
     8 
     9 implementation
     9 implementation
    10 uses SDLh;
    10 uses SDLh, uFLIPC;
    11 
    11 
    12 const endCmd: array[0..1] of char = (#10, #10);
    12 const endCmd: string = #10 + #10;
    13 
    13 
    14 function getNextChar: char; forward;
    14 function getNextChar: char; forward;
    15 function getCurrChar: char; forward;
    15 function getCurrChar: char; forward;
    16 procedure sendNet(s: shortstring); forward;
    16 procedure sendNet(s: shortstring); forward;
    17 
    17 
   254 end;
   254 end;
   255 
   255 
   256 procedure sendNet(s: shortstring);
   256 procedure sendNet(s: shortstring);
   257 begin
   257 begin
   258     writeln('[NET] Send: ', s);
   258     writeln('[NET] Send: ', s);
   259     SDLNet_TCP_Send(sock, @s[1], byte(s[0]));
   259     ipcToNet(s + endCmd);
   260     SDLNet_TCP_Send(sock, @endCmd, 2);
   260 end;
       
   261 
       
   262 procedure netSendCallback(p: pointer; msg: PChar; len: Longword);
       
   263 begin
       
   264     // W A R N I N G: totally thread-unsafe due to use of sock variable
       
   265     SDLNet_TCP_Send(sock, msg, len);
   261 end;
   266 end;
   262 
   267 
   263 procedure connectOfficialServer;
   268 procedure connectOfficialServer;
   264 begin
   269 begin
   265     if sock <> nil then
   270     if sock <> nil then
   277 procedure initModule;
   282 procedure initModule;
   278 begin
   283 begin
   279     sock:= nil;
   284     sock:= nil;
   280 
   285 
   281     SDLNet_Init;
   286     SDLNet_Init;
       
   287 
       
   288     registerNetCallback(nil, @netSendCallback);
   282 end;
   289 end;
   283 
   290 
   284 procedure freeModule;
   291 procedure freeModule;
   285 begin
   292 begin
   286 end;
   293 end;