hedgewars/uFLNet.pas
branchqmlfrontend
changeset 11434 d96a37de1076
parent 11430 2947f06e8533
child 11439 23912c93935a
equal deleted inserted replaced
11433:cc12bba5b2a2 11434:d96a37de1076
    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 
    34 
    35 const letters: array[0..224] of char = ('A', 'S', 'K', 'P', 'A', 'S', 'S', 'W',
       
    36     'O', 'R', 'D', #10, 'B', 'A', 'N', 'L', 'I', 'S', 'T', #10, 'Y', 'E', #10, 'C',
       
    37     'H', 'A', 'T', #10, 'L', 'I', 'E', 'N', 'T', '_', 'F', 'L', 'A', 'G', 'S', #10,
       
    38     'O', 'N', 'N', 'E', 'C', 'T', 'E', 'D', #10, 'E', 'M', #10, 'R', 'R', 'O', 'R',
       
    39     #10, 'H', 'H', '_', 'N', 'U', 'M', #10, 'I', 'N', 'F', 'O', #10, 'J', 'O', 'I',
       
    40     'N', 'E', 'D', #10, 'I', 'N', 'G', #10, 'K', 'I', 'C', 'K', 'E', 'D', #10, 'L',
       
    41     'E', 'F', 'T', #10, 'O', 'B', 'B', 'Y', ':', 'J', 'O', 'I', 'N', 'E', 'D', #10,
       
    42     'L', 'E', 'F', 'T', #10, 'N', 'I', 'C', 'K', #10, 'O', 'T', 'I', 'C', 'E', #10,
       
    43     'P', 'I', 'N', 'G', #10, 'R', 'O', 'T', 'O', #10, 'R', 'O', 'O', 'M', 'S', #10,
       
    44     #10, 'A', 'D', 'D', #10, 'D', 'E', 'L', #10, 'U', 'P', 'D', #10, 'U', 'N', 'D',
       
    45     '_', 'F', 'I', 'N', 'I', 'S', 'H', 'E', 'D', #10, 'U', 'N', '_', 'G', 'A', 'M',
       
    46     'E', #10, 'S', 'E', 'R', 'V', 'E', 'R', '_', 'A', 'U', 'T', 'H', #10, 'M', 'E',
       
    47     'S', 'S', 'A', 'G', 'E', #10, 'V', 'A', 'R', 'S', #10, 'T', 'E', 'A', 'M', '_',
       
    48     'A', 'C', 'C', 'E', 'P', 'T', 'E', 'D', #10, 'C', 'O', 'L', 'O', 'R', #10, 'W',
       
    49     'A', 'R', 'N', 'I', 'N', 'G', #10, #0, #10);
       
    50 const commands: array[0..224] of integer = (12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       
    51     -42, 11, 7, 0, 0, 0, 0, 0, -41, 0, 0, -40, 26, 4, 0, 0, -39, 12, 0, 0, 0, 0, 0,
       
    52     0, 0, 0, 0, 0, -38, 0, 0, 0, 0, 0, 0, 0, 0, -37, 8, 2, -36, 0, 0, 0, 0, -35, 7,
       
    53     0, 0, 0, 0, 0, -34, 5, 0, 0, 0, -33, 11, 0, 0, 0, 3, 0, -32, 0, 0, 0, -31, 7, 0,
       
    54     0, 0, 0, 0, -30, 22, 4, 0, 0, -29, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, -28, 0, 0,
       
    55     0, 0, -27, 11, 4, 0, 0, -26, 0, 0, 0, 0, 0, -25, 10, 4, 0, 0, -24, 0, 0, 0, 0,
       
    56     -23, 40, 31, 17, 0, 2, -22, 0, 4, 0, 0, -21, 4, 0, 0, -20, 0, 0, 0, -19, 0, 0,
       
    57     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -18, 0, 0, 0, 0, 0, 0, 0, -17, 25, 0, 0, 0, 0, 0,
       
    58     0, 5, 0, 0, 0, -16, 8, 0, 0, 0, 0, 0, 0, -15, 0, 0, 0, 0, -14, 20, 0, 0, 0, 0,
       
    59     9, 0, 0, 0, 0, 0, 0, 0, -13, 0, 0, 0, 0, 0, -12, 8, 0, 0, 0, 0, 0, 0, -11, 0,
       
    60     -10);
       
    61 
       
    62 
       
    63 procedure handler_;
    35 procedure handler_;
    64 begin
    36 begin
    65     sendUI(mtNetData, @state.cmd, sizeof(state.cmd));
    37     sendUI(mtNetData, @state.cmd, sizeof(state.cmd));
    66     handleTail()
    38     handleTail()
    67 end;
    39 end;
    87     repeat
    59     repeat
    88         cmd.str1:= getShortString; // FIXME long line
    60         cmd.str1:= getShortString; // FIXME long line
    89         f:= cmd.str1[0] <> #0;
    61         f:= cmd.str1[0] <> #0;
    90         if f then
    62         if f then
    91             sendUI(mtNetData, @cmd, sizeof(cmd));
    63             sendUI(mtNetData, @cmd, sizeof(cmd));
    92     until not f
    64     until not f;
       
    65     state.l:= 0
    93 end;
    66 end;
    94 
    67 
    95 procedure handler_MS;
    68 procedure handler_MS;
    96 var cmd: TCmdParamS;
    69 var cmd: TCmdParamS;
    97     f: boolean;
    70     f: boolean;
   102     repeat
    75     repeat
   103         cmd.str1:= getShortString;
    76         cmd.str1:= getShortString;
   104         f:= cmd.str1[0] <> #0;
    77         f:= cmd.str1[0] <> #0;
   105         if f then
    78         if f then
   106             sendUI(mtNetData, @cmd, sizeof(cmd));
    79             sendUI(mtNetData, @cmd, sizeof(cmd));
   107     until not f
    80     until not f;
       
    81     state.l:= 0
   108 end;
    82 end;
   109 
    83 
   110 procedure handler_S;
    84 procedure handler_S;
   111 var cmd: TCmdParamS;
    85 var cmd: TCmdParamS;
   112 begin
    86 begin
   142     repeat
   116     repeat
   143         cmd.str1:= getShortString;
   117         cmd.str1:= getShortString;
   144         f:= cmd.str1[0] <> #0;
   118         f:= cmd.str1[0] <> #0;
   145         if f then
   119         if f then
   146             sendUI(mtNetData, @cmd, sizeof(cmd));
   120             sendUI(mtNetData, @cmd, sizeof(cmd));
   147     until not f
   121     until not f;
       
   122     state.l:= 0
   148 end;
   123 end;
   149 
   124 
   150 procedure handler__i;
   125 procedure handler__i;
   151 var cmd: TCmdParami;
   126 var cmd: TCmdParami;
   152     s: shortstring;
   127     s: shortstring;
   169 end;
   144 end;
   170 
   145 
   171 procedure handler__UNKNOWN_;
   146 procedure handler__UNKNOWN_;
   172 begin
   147 begin
   173     writeln('[NET] Unknown cmd');
   148     writeln('[NET] Unknown cmd');
   174     handleTail()
   149     handleTail();
   175 end;
   150     state.l:= 0
   176 
   151 end;
   177 const handlers: array[0..32] of PHandler = (@handler__UNKNOWN_, @handler_L,
   152 
   178     @handler_MS, @handler_S, @handler_SL, @handler_L, @handler_S, @handler_,
   153 const net2cmd: array[0..46] of TCmdType = (cmd_WARNING, cmd_WARNING,
   179     @handler_, @handler_MS, @handler_S, @handler_MS, @handler_MS, @handler_i,
       
   180     @handler_MS, @handler_L, @handler_S, @handler_SL, @handler_MS, @handler_SMS,
       
   181     @handler_, @handler_S, @handler_MS, @handler_MS, @handler_MS, @handler_L,
       
   182     @handler_ML, @handler__i, @handler_SMS, @handler_SL, @handler_SL, @handler_MS,
       
   183     @handler_S);
       
   184 const net2cmd: array[0..32] of TCmdType = (cmd_WARNING, cmd_WARNING,
       
   185     cmd_TEAM_COLOR, cmd_TEAM_ACCEPTED, cmd_SERVER_VARS, cmd_SERVER_MESSAGE,
   154     cmd_TEAM_COLOR, cmd_TEAM_ACCEPTED, cmd_SERVER_VARS, cmd_SERVER_MESSAGE,
   186     cmd_SERVER_AUTH, cmd_RUN_GAME, cmd_ROUND_FINISHED, cmd_ROOM_UPD, cmd_ROOM_DEL,
   155     cmd_SERVER_AUTH, cmd_RUN_GAME, cmd_ROUND_FINISHED, cmd_ROOM_UPD, cmd_ROOM_DEL,
   187     cmd_ROOM_ADD, cmd_ROOMS, cmd_PROTO, cmd_PING, cmd_NOTICE, cmd_NICK,
   156     cmd_ROOM_ADD, cmd_ROOMS, cmd_REMOVE_TEAM, cmd_PROTO, cmd_PING, cmd_NOTICE,
   188     cmd_LOBBY_LEFT, cmd_LOBBY_JOINED, cmd_LEFT, cmd_KICKED, cmd_JOINING, cmd_JOINED,
   157     cmd_NICK, cmd_LOBBY_LEFT, cmd_LOBBY_JOINED, cmd_LEFT, cmd_KICKED, cmd_JOINING,
   189     cmd_INFO, cmd_HH_NUM, cmd_ERROR, cmd_EM, cmd_CONNECTED, cmd_CLIENT_FLAGS,
   158     cmd_JOINED, cmd_INFO, cmd_HH_NUM, cmd_ERROR, cmd_EM, cmd_CONNECTED,
   190     cmd_CHAT, cmd_BYE, cmd_BANLIST, cmd_ASKPASSWORD);
   159     cmd_CLIENT_FLAGS, cmd_CHAT, cmd_CFG_THEME, cmd_CFG_TEMPLATE, cmd_CFG_SEED,
   191 
   160     cmd_CFG_SCRIPT, cmd_CFG_SCHEME, cmd_CFG_MAZE_SIZE, cmd_CFG_MAP, cmd_CFG_MAPGEN,
   192 // end of generated stuff
   161     cmd_CFG_FULLMAPCONFIG, cmd_CFG_FEATURE_SIZE, cmd_CFG_DRAWNMAP, cmd_CFG_AMMO,
       
   162     cmd_BYE, cmd_BANLIST, cmd_ASKPASSWORD, cmd_ADD_TEAM);
       
   163 const letters: array[0..332] of char = ('A', 'D', 'D', '_', 'T', 'E', 'A', 'M',
       
   164     #10, 'S', 'K', 'P', 'A', 'S', 'S', 'W', 'O', 'R', 'D', #10, 'B', 'A', 'N', 'L',
       
   165     'I', 'S', 'T', #10, 'Y', 'E', #10, 'C', 'F', 'G', #10, 'A', 'M', 'M', 'O', #10,
       
   166     'D', 'R', 'A', 'W', 'N', 'M', 'A', 'P', #10, 'F', 'E', 'A', 'T', 'U', 'R', 'E',
       
   167     '_', 'S', 'I', 'Z', 'E', #10, 'U', 'L', 'L', 'M', 'A', 'P', 'C', 'O', 'N', 'F',
       
   168     'I', 'G', #10, 'M', 'A', 'P', 'G', 'E', 'N', #10, #10, 'Z', 'E', '_', 'S', 'I',
       
   169     'Z', 'E', #10, 'S', 'C', 'H', 'E', 'M', 'E', #10, 'R', 'I', 'P', 'T', #10, 'E',
       
   170     'E', 'D', #10, 'T', 'E', 'M', 'P', 'L', 'A', 'T', 'E', #10, 'H', 'E', 'M', 'E',
       
   171     #10, 'H', 'A', 'T', #10, 'L', 'I', 'E', 'N', 'T', '_', 'F', 'L', 'A', 'G', 'S',
       
   172     #10, 'O', 'N', 'N', 'E', 'C', 'T', 'E', 'D', #10, 'E', 'M', #10, 'R', 'R', 'O',
       
   173     'R', #10, 'H', 'H', '_', 'N', 'U', 'M', #10, 'I', 'N', 'F', 'O', #10, 'J', 'O',
       
   174     'I', 'N', 'E', 'D', #10, 'I', 'N', 'G', #10, 'K', 'I', 'C', 'K', 'E', 'D', #10,
       
   175     'L', 'E', 'F', 'T', #10, 'O', 'B', 'B', 'Y', ':', 'J', 'O', 'I', 'N', 'E', 'D',
       
   176     #10, 'L', 'E', 'F', 'T', #10, 'N', 'I', 'C', 'K', #10, 'O', 'T', 'I', 'C', 'E',
       
   177     #10, 'P', 'I', 'N', 'G', #10, 'R', 'O', 'T', 'O', #10, 'R', 'E', 'M', 'O', 'V',
       
   178     'E', '_', 'T', 'E', 'A', 'M', #10, 'O', 'O', 'M', 'S', #10, #10, 'A', 'D', 'D',
       
   179     #10, 'D', 'E', 'L', #10, 'U', 'P', 'D', #10, 'U', 'N', 'D', '_', 'F', 'I', 'N',
       
   180     'I', 'S', 'H', 'E', 'D', #10, 'U', 'N', '_', 'G', 'A', 'M', 'E', #10, 'S', 'E',
       
   181     'R', 'V', 'E', 'R', '_', 'A', 'U', 'T', 'H', #10, 'M', 'E', 'S', 'S', 'A', 'G',
       
   182     'E', #10, 'V', 'A', 'R', 'S', #10, 'T', 'E', 'A', 'M', '_', 'A', 'C', 'C', 'E',
       
   183     'P', 'T', 'E', 'D', #10, 'C', 'O', 'L', 'O', 'R', #10, 'W', 'A', 'R', 'N', 'I',
       
   184     'N', 'G', #10, #0, #10);
       
   185 const commands: array[0..332] of integer = (20, 8, 0, 0, 0, 0, 0, 0, -56, 0, 0,
       
   186     0, 0, 0, 0, 0, 0, 0, 0, -55, 11, 7, 0, 0, 0, 0, 0, -54, 0, 0, -53, 115, 89, 0,
       
   187     0, 5, 0, 0, 0, -52, 9, 0, 0, 0, 0, 0, 0, 0, -51, 26, 12, 0, 0, 0, 0, 0, 0, 0, 0,
       
   188     0, 0, -50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -49, 16, 0, 6, 4, 0, 0, -48, -47,
       
   189     0, 0, 0, 0, 0, 0, 0, -46, 16, 11, 5, 0, 0, 0, -45, 0, 0, 0, 0, -44, 0, 0, 0,
       
   190     -43, 0, 8, 0, 0, 0, 0, 0, 0, -42, 0, 0, 0, 0, -41, 4, 0, 0, -40, 12, 0, 0, 0, 0,
       
   191     0, 0, 0, 0, 0, 0, -39, 0, 0, 0, 0, 0, 0, 0, 0, -38, 8, 2, -37, 0, 0, 0, 0, -36,
       
   192     7, 0, 0, 0, 0, 0, -35, 5, 0, 0, 0, -34, 11, 0, 0, 0, 3, 0, -33, 0, 0, 0, -32, 7,
       
   193     0, 0, 0, 0, 0, -31, 22, 4, 0, 0, -30, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, -29, 0,
       
   194     0, 0, 0, -28, 11, 4, 0, 0, -27, 0, 0, 0, 0, 0, -26, 10, 4, 0, 0, -25, 0, 0, 0,
       
   195     0, -24, 51, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, -23, 31, 17, 0, 2, -22, 0, 4, 0, 0,
       
   196     -21, 4, 0, 0, -20, 0, 0, 0, -19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -18, 0, 0,
       
   197     0, 0, 0, 0, 0, -17, 25, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, -16, 8, 0, 0, 0, 0, 0, 0,
       
   198     -15, 0, 0, 0, 0, -14, 20, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, -13, 0, 0, 0, 0,
       
   199     0, -12, 8, 0, 0, 0, 0, 0, 0, -11, 0, -10);
       
   200 const handlers: array[0..46] of PHandler = (@handler__UNKNOWN_, @handler_L,
       
   201     @handler_MS, @handler_S, @handler_SL, @handler_L, @handler_S, @handler_,
       
   202     @handler_, @handler_MS, @handler_S, @handler_MS, @handler_MS, @handler_S,
       
   203     @handler_i, @handler_MS, @handler_L, @handler_S, @handler_SL, @handler_MS,
       
   204     @handler_SMS, @handler_, @handler_S, @handler_MS, @handler_MS, @handler_MS,
       
   205     @handler_L, @handler_ML, @handler__i, @handler_SMS, @handler_SL, @handler_S,
       
   206     @handler_i, @handler_S, @handler_S, @handler_MS, @handler_i, @handler_i,
       
   207     @handler_S, @handler_ML, @handler_i, @handler_L, @handler_SL, @handler_SL,
       
   208     @handler_MS, @handler_S, @handler_MS);
       
   209 
   193 procedure handleTail;
   210 procedure handleTail;
   194 var cnt: Longint;
   211 var cnt: Longint;
   195     c: char;
   212     c: char;
   196 begin
   213 begin
   197     c:= getCurrChar;
   214     c:= getCurrChar;
   199         if c = #10 then cnt:= 0 else cnt:= 1;
   216         if c = #10 then cnt:= 0 else cnt:= 1;
   200         repeat
   217         repeat
   201             c:= getNextChar;
   218             c:= getNextChar;
   202             inc(cnt)
   219             inc(cnt)
   203         until (c = #0) or (c = #10);
   220         until (c = #0) or (c = #10);
   204     until (c = #0) or (cnt = 1)
   221     until (c = #0) or (cnt = 1);
       
   222     state.l:= 0
   205 end;
   223 end;
   206 
   224 
   207 var sock: PTCPSocket;
   225 var sock: PTCPSocket;
   208     netReaderThread: PSDL_Thread;
   226     netReaderThread: PSDL_Thread;
   209 
   227 
   244     if SDLNet_ResolveHost(ipaddr, PChar('netserver.hedgewars.org'), 46631) = 0 then
   262     if SDLNet_ResolveHost(ipaddr, PChar('netserver.hedgewars.org'), 46631) = 0 then
   245         sock:= SDLNet_TCP_Open(ipaddr);
   263         sock:= SDLNet_TCP_Open(ipaddr);
   246 
   264 
   247     repeat
   265     repeat
   248         c:= getNextChar;
   266         c:= getNextChar;
   249         //writeln('>>>>> ', c, ' [', letters[state.l], '] ', commands[state.l]);
   267         //writeln('>>>>> ', c, ' [', letters[state.l], '] ', commands[state.l], ' ', state.l);
   250         if c = #0 then
   268         if c = #0 then
   251             state.netState:= netDisconnected
   269             state.netState:= netDisconnected
   252         else
   270         else
   253         begin
   271         begin
   254             while (letters[state.l] <> c) and (commands[state.l] > 0) do
   272             while (letters[state.l] <> c) and (commands[state.l] > 0) do