hedgewars/uFLNet.pas
branchqmlfrontend
changeset 11437 6e641b5453f9
parent 11434 23912c93935a
child 11441 908aed8525f9
equal deleted inserted replaced
11436:f7fa429e42ab 11437:6e641b5453f9
     9 procedure sendNetLn(s: shortstring);
     9 procedure sendNetLn(s: shortstring);
    10 
    10 
    11 implementation
    11 implementation
    12 uses SDLh, uFLIPC, uFLTypes, uFLUICallback, uFLNetTypes, uFLUtils;
    12 uses SDLh, uFLIPC, uFLTypes, uFLUICallback, uFLNetTypes, uFLUtils;
    13 
    13 
    14 const endCmd: string = #10 + #10;
    14 const endCmd: shortstring = #10 + #10;
    15 
    15 
    16 function getNextChar: char; forward;
    16 function getNextChar: char; forward;
    17 function getCurrChar: char; forward;
    17 function getCurrChar: char; forward;
    18 
    18 
    19 type
    19 type
    29 
    29 
    30 var state: TParserState;
    30 var state: TParserState;
    31 
    31 
    32 procedure handleTail; forward;
    32 procedure handleTail; forward;
    33 function getShortString: shortstring; forward;
    33 function getShortString: shortstring; forward;
       
    34 function getLongString: ansistring; forward;
    34 
    35 
    35 procedure handler_;
    36 procedure handler_;
    36 begin
    37 begin
    37     sendUI(mtNetData, @state.cmd, sizeof(state.cmd));
    38     sendUI(mtNetData, @state.cmd, sizeof(state.cmd));
    38     handleTail()
    39     handleTail()
    40 
    41 
    41 procedure handler_L;
    42 procedure handler_L;
    42 var cmd: TCmdParamL;
    43 var cmd: TCmdParamL;
    43 begin
    44 begin
    44     cmd.cmd:= state.cmd;
    45     cmd.cmd:= state.cmd;
    45     cmd.str1:= getShortString; // FIXME long line
    46     cmd.str1:= getLongString;
    46     if cmd.str1[0] = #0 then exit;
    47     if length(cmd.str1) = 0 then exit;
    47     sendUI(mtNetData, @cmd, sizeof(cmd));
    48     sendUI(mtNetData, @cmd, sizeof(cmd));
    48     handleTail()
    49     handleTail()
    49 end;
    50 end;
    50 
    51 
    51 procedure handler_ML;
    52 procedure handler_ML;
    55     writeln('handler_ML');
    56     writeln('handler_ML');
    56     sendUI(mtNetData, @state.cmd, sizeof(state.cmd));
    57     sendUI(mtNetData, @state.cmd, sizeof(state.cmd));
    57     cmd.cmd:= Succ(state.cmd);
    58     cmd.cmd:= Succ(state.cmd);
    58 
    59 
    59     repeat
    60     repeat
    60         cmd.str1:= getShortString; // FIXME long line
    61         cmd.str1:= getLongString;
    61         f:= cmd.str1[0] <> #0;
    62         f:= cmd.str1[0] <> #0;
    62         if f then
    63         if f then
    63             sendUI(mtNetData, @cmd, sizeof(cmd));
    64             sendUI(mtNetData, @cmd, sizeof(cmd));
    64     until not f;
    65     until not f;
    65     state.l:= 0
    66     state.l:= 0
    95 var cmd: TCmdParamSL;
    96 var cmd: TCmdParamSL;
    96 begin
    97 begin
    97     cmd.cmd:= state.cmd;
    98     cmd.cmd:= state.cmd;
    98     cmd.str1:= getShortString;
    99     cmd.str1:= getShortString;
    99     if cmd.str1[0] = #0 then exit;
   100     if cmd.str1[0] = #0 then exit;
   100     cmd.str2:= getShortString; // FIXME should be long string
   101     cmd.str2:= getLongString;
   101     if cmd.str2[0] = #0 then exit;
   102     if cmd.str2[0] = #0 then exit;
   102     sendUI(mtNetData, @cmd, sizeof(cmd));
   103     sendUI(mtNetData, @cmd, sizeof(cmd));
   103     handleTail()
   104     handleTail()
   104 end;
   105 end;
   105 
   106 
   329         repeat c:= getNextChar until (c = #0) or (c = #10);
   330         repeat c:= getNextChar until (c = #0) or (c = #10);
   330 
   331 
   331     getShortString:= s
   332     getShortString:= s
   332 end;
   333 end;
   333 
   334 
       
   335 function getLongString: ansistring;
       
   336 var s: shortstring;
       
   337     l: ansistring;
       
   338     c: char;
       
   339 begin
       
   340     l:= '';
       
   341 
       
   342     repeat
       
   343         s[0]:= #0;
       
   344             repeat
       
   345                 inc(s[0]);
       
   346                 c:= getNextChar;
       
   347                 s[byte(s[0])]:= c
       
   348             until (s[0] = #255) or (c = #10) or (c = #0);
       
   349 
       
   350         if s[byte(s[0])] = #10 then
       
   351             dec(s[0]);
       
   352 
       
   353         l:= l + s
       
   354     until (c = #10) or (c = #0);
       
   355 
       
   356     getLongString:= l
       
   357 end;
       
   358 
   334 procedure netSendCallback(p: pointer; msg: PChar; len: Longword);
   359 procedure netSendCallback(p: pointer; msg: PChar; len: Longword);
   335 begin
   360 begin
   336     // W A R N I N G: totally thread-unsafe due to use of sock variable
   361     // W A R N I N G: totally thread-unsafe due to use of sock variable
   337     SDLNet_TCP_Send(sock, msg, len);
   362     SDLNet_TCP_Send(sock, msg, len);
   338 end;
   363 end;