hedgewars/uFLNet.pas
author unc0rr
Fri, 15 May 2015 23:28:31 +0300
branchqmlfrontend
changeset 10931 384765cd0caf
parent 10929 8ebf01f75d9f
child 10933 f1da4126a61c
permissions -rw-r--r--
Parse net commands, answer to pings
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10896
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
     1
unit uFLNet;
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
     2
interface
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
     3
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
     4
procedure connectOfficialServer;
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
     5
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
     6
procedure initModule;
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
     7
procedure freeModule;
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
     8
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
     9
implementation
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
    10
uses SDLh;
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
    11
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
    12
const endCmd: array[0..1] of char = (#10, #10);
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
    13
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
    14
function getNextChar: char; forward;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
    15
function getCurrChar: char; forward;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
    16
procedure sendNet(s: shortstring); forward;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
    17
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    18
type TCmdType = (cmd_ASKPASSWORD, cmd_BANLIST, cmd_BYE, cmd_CHAT, cmd_CLIENT_FLAGS, cmd_CONNECTED, cmd_EM, cmd_HH_NUM, cmd_INFO, cmd_JOINED, cmd_JOINING, cmd_KICKED, cmd_LEFT, cmd_LOBBY_JOINED, cmd_LOBBY_LEFT, cmd_NICK, cmd_NOTICE, cmd_PING, cmd_PROTO, cmd_ROOMS, cmd_ROUND_FINISHED, cmd_RUN_GAME, cmd_SERVER_AUTH, cmd_SERVER_MESSAGE, cmd_SERVER_VARS, cmd_TEAM_ACCEPTED, cmd_TEAM_COLOR, cmd_WARNING, cmd___UNKNOWN__);
10896
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
    19
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    20
type
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
    21
    TNetState = (netDisconnected, netConnecting, netLoggedIn);
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    22
    TParserState = record
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    23
                       cmd: TCmdType;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    24
                       l: LongInt;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    25
                       netState: TNetState;
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
    26
                       buf: shortstring;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
    27
                       bufpos: byte;
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    28
                   end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    29
    PHandler = procedure;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    30
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    31
var state: TParserState;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    32
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    33
// generated stuff here
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
    34
const letters: array[0..206] of char = ('A', 'S', 'K', 'P', 'A', 'S', 'S', 'W', 'O', 'R', 'D', #10, 'B', 'A', 'N', 'L', 'I', 'S', 'T', #10, 'Y', 'E', #10, 'C', 'H', 'A', 'T', #10, 'L', 'I', 'E', 'N', 'T', '_', 'F', 'L', 'A', 'G', 'S', #10, 'O', 'N', 'N', 'E', 'C', 'T', 'E', 'D', #10, 'E', 'M', #10, 'H', 'H', '_', 'N', 'U', 'M', #10, 'I', 'N', 'F', 'O', #10, 'J', 'O', 'I', 'N', 'E', 'D', #10, 'I', 'N', 'G', #10, 'K', 'I', 'C', 'K', 'E', 'D', #10, 'L', 'E', 'F', 'T', #10, 'O', 'B', 'B', 'Y', ':', 'J', 'O', 'I', 'N', 'E', 'D', #10, 'L', 'E', 'F', 'T', #10, 'N', 'I', 'C', 'K', #10, 'O', 'T', 'I', 'C', 'E', #10, 'P', 'I', 'N', 'G', #10, 'R', 'O', 'T', 'O', #10, 'R', 'O', 'O', 'M', 'S', #10, 'U', 'N', 'D', '_', 'F', 'I', 'N', 'I', 'S', 'H', 'E', 'D', #10, 'U', 'N', '_', 'G', 'A', 'M', 'E', #10, 'S', 'E', 'R', 'V', 'E', 'R', '_', 'A', 'U', 'T', 'H', #10, 'M', 'E', 'S', 'S', 'A', 'G', 'E', #10, 'V', 'A', 'R', 'S', #10, 'T', 'E', 'A', 'M', '_', 'A', 'C', 'C', 'E', 'P', 'T', 'E', 'D', #10, 'C', 'O', 'L', 'O', 'R', #10, 'W', 'A', 'R', 'N', 'I', 'N', 'G', #10, #0, #10);
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    35
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
    36
const commands: array[0..206] of integer = (12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -38, 11, 7, 0, 0, 0, 0, 0, -37, 0, 0, -36, 26, 4, 0, 0, -35, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -34, 0, 0, 0, 0, 0, 0, 0, 0, -33, 3, 0, -32, 7, 0, 0, 0, 0, 0, -31, 5, 0, 0, 0, -30, 11, 0, 0, 0, 3, 0, -29, 0, 0, 0, -28, 7, 0, 0, 0, 0, 0, -27, 22, 4, 0, 0, -26, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, -25, 0, 0, 0, 0, -24, 11, 4, 0, 0, -23, 0, 0, 0, 0, 0, -22, 10, 4, 0, 0, -21, 0, 0, 0, 0, -20, 27, 18, 4, 0, 0, -19, 0, 0, 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, 0, 5, 0, 0, 0, -16, 8, 0, 0, 0, 0, 0, 0, -15, 0, 0, 0, 0, -14, 20, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, -13, 0, 0, 0, 0, 0, -12, 8, 0, 0, 0, 0, 0, 0, -11, 0, -10);
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    37
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    38
procedure handler_ASKPASSWORD;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    39
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    40
    state.cmd:= cmd_ASKPASSWORD;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    41
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    42
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    43
procedure handler_BANLIST;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    44
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    45
    state.cmd:= cmd_BANLIST;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    46
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    47
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    48
procedure handler_BYE;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    49
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    50
    state.cmd:= cmd_BYE;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    51
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    52
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    53
procedure handler_CHAT;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    54
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    55
    state.cmd:= cmd_CHAT;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    56
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    57
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    58
procedure handler_CLIENT_FLAGS;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    59
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    60
    state.cmd:= cmd_CLIENT_FLAGS;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    61
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    62
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    63
procedure handler_CONNECTED;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    64
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    65
    state.cmd:= cmd_CONNECTED;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    66
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    67
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    68
procedure handler_EM;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    69
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    70
    state.cmd:= cmd_EM;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    71
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    72
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    73
procedure handler_HH_NUM;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    74
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    75
    state.cmd:= cmd_HH_NUM;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    76
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    77
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    78
procedure handler_INFO;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    79
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    80
    state.cmd:= cmd_INFO;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    81
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    82
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    83
procedure handler_JOINED;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    84
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    85
    state.cmd:= cmd_JOINED;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    86
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    87
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    88
procedure handler_JOINING;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    89
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    90
    state.cmd:= cmd_JOINING;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    91
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    92
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    93
procedure handler_KICKED;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    94
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    95
    state.cmd:= cmd_KICKED;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    96
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    97
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    98
procedure handler_LEFT;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    99
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   100
    state.cmd:= cmd_LEFT;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   101
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   102
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   103
procedure handler_LOBBY_JOINED;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   104
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   105
    state.cmd:= cmd_LOBBY_JOINED;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   106
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   107
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   108
procedure handler_LOBBY_LEFT;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   109
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   110
    state.cmd:= cmd_LOBBY_LEFT;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   111
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   112
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   113
procedure handler_NICK;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   114
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   115
    state.cmd:= cmd_NICK;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   116
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   117
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   118
procedure handler_NOTICE;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   119
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   120
    state.cmd:= cmd_NOTICE;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   121
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   122
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   123
procedure handler_PING;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   124
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   125
    state.cmd:= cmd_PING;
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   126
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   127
    sendNet('PONG');
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   128
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   129
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   130
procedure handler_PROTO;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   131
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   132
    state.cmd:= cmd_PROTO;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   133
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   134
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   135
procedure handler_ROOMS;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   136
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   137
    state.cmd:= cmd_ROOMS;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   138
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   139
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   140
procedure handler_ROUND_FINISHED;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   141
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   142
    state.cmd:= cmd_ROUND_FINISHED;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   143
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   144
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   145
procedure handler_RUN_GAME;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   146
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   147
    state.cmd:= cmd_RUN_GAME;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   148
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   149
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   150
procedure handler_SERVER_AUTH;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   151
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   152
    state.cmd:= cmd_SERVER_AUTH;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   153
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   154
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   155
procedure handler_SERVER_MESSAGE;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   156
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   157
    state.cmd:= cmd_SERVER_MESSAGE;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   158
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   159
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   160
procedure handler_SERVER_VARS;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   161
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   162
    state.cmd:= cmd_SERVER_VARS;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   163
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   164
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   165
procedure handler_TEAM_ACCEPTED;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   166
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   167
    state.cmd:= cmd_TEAM_ACCEPTED;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   168
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   169
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   170
procedure handler_TEAM_COLOR;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   171
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   172
    state.cmd:= cmd_TEAM_COLOR;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   173
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   174
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   175
procedure handler_WARNING;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   176
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   177
    state.cmd:= cmd_WARNING;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   178
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   179
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   180
procedure handler___UNKNOWN__;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   181
begin
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   182
    state.cmd:= cmd___UNKNOWN__;
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   183
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   184
    writeln('[NET] Unknown cmd');
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   185
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   186
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   187
const handlers: array[0..28] of PHandler = (@handler___UNKNOWN__, @handler_WARNING, @handler_TEAM_COLOR, @handler_TEAM_ACCEPTED, @handler_SERVER_VARS, @handler_SERVER_MESSAGE, @handler_SERVER_AUTH, @handler_RUN_GAME, @handler_ROUND_FINISHED, @handler_ROOMS, @handler_PROTO, @handler_PING, @handler_NOTICE, @handler_NICK, @handler_LOBBY_LEFT, @handler_LOBBY_JOINED, @handler_LEFT, @handler_KICKED, @handler_JOINING, @handler_JOINED, @handler_INFO, @handler_HH_NUM, @handler_EM, @handler_CONNECTED, @handler_CLIENT_FLAGS, @handler_CHAT, @handler_BYE, @handler_BANLIST, @handler_ASKPASSWORD);
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   188
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   189
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   190
// end of generated stuff
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   191
procedure handleTail;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   192
var cnt: Longint;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   193
    c: char;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   194
begin
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   195
    state.l:= 0;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   196
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   197
    c:= getCurrChar;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   198
    repeat
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   199
        if c = #10 then cnt:= 0 else cnt:= 1;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   200
        repeat
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   201
            c:= getNextChar;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   202
            inc(cnt)
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   203
        until (c = #0) or (c = #10);
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   204
    until (c = #0) or (cnt = 1)
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   205
end;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   206
10896
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   207
var sock: PTCPSocket;
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   208
    fds: PSDLNet_SocketSet;
10900
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   209
    netReaderThread: PSDL_Thread;
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   210
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   211
function getCurrChar: char;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   212
begin
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   213
    getCurrChar:= state.buf[state.bufpos]
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   214
end;
10900
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   215
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   216
function getNextChar: char;
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   217
var r: byte;
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   218
begin
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   219
    if state.bufpos < byte(state.buf[0]) then
10900
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   220
    begin
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   221
        inc(state.bufpos);
10900
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   222
    end else
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   223
    begin
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   224
        r:= SDLNet_TCP_Recv(sock, @state.buf[1], 255);
10900
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   225
        if r > 0 then
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   226
        begin
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   227
            state.bufpos:= 1;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   228
            state.buf[0]:= char(r);
10900
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   229
        end else
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   230
        begin
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   231
            state.bufpos:= 0;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   232
            state.buf[0]:= #0;
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   233
        end
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   234
    end;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   235
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   236
    getNextChar:= state.buf[state.bufpos];
10900
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   237
end;
10898
f373838129c2 Some futher work on flib net client part
unc0rr
parents: 10896
diff changeset
   238
f373838129c2 Some futher work on flib net client part
unc0rr
parents: 10896
diff changeset
   239
function netReader(data: pointer): LongInt; cdecl; export;
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   240
var c: char;
10898
f373838129c2 Some futher work on flib net client part
unc0rr
parents: 10896
diff changeset
   241
begin
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   242
repeat
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   243
    c:= getNextChar;
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   244
    writeln('>>>>> ', c, ' [', letters[state.l], '] ', commands[state.l]);
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   245
    if c = #0 then
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   246
        state.netState:= netDisconnected
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   247
    else
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   248
    begin
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   249
        while (letters[state.l] <> c) and (commands[state.l] > 0) do
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   250
            inc(state.l, commands[state.l]);
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   251
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   252
        if c = letters[state.l] then
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   253
            if commands[state.l] < 0 then
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   254
                begin
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   255
                    handlers[-10 - commands[state.l]]();
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   256
                    handleTail()
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   257
                end
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   258
            else
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   259
                inc(state.l)
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   260
        else
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   261
        begin
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   262
            handler___UNKNOWN__();
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   263
            handleTail()
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   264
        end
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   265
    end
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   266
until state.netState = netDisconnected;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   267
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   268
writeln('[NET] netReader: disconnected');
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   269
end;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   270
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   271
procedure sendNet(s: shortstring);
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   272
begin
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   273
    writeln('[NET] Send: ', s);
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   274
    SDLNet_TCP_Send(sock, @s[1], byte(s[0]));
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   275
    SDLNet_TCP_Send(sock, @endCmd, 2);
10898
f373838129c2 Some futher work on flib net client part
unc0rr
parents: 10896
diff changeset
   276
end;
10896
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   277
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   278
procedure connectOfficialServer;
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   279
var ipaddr: TIPAddress;
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   280
begin
10898
f373838129c2 Some futher work on flib net client part
unc0rr
parents: 10896
diff changeset
   281
    if sock <> nil then
10896
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   282
        exit;
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   283
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   284
    if SDLNet_ResolveHost(ipaddr, PChar('netserver.hedgewars.org'), 46631) = 0 then
10898
f373838129c2 Some futher work on flib net client part
unc0rr
parents: 10896
diff changeset
   285
        sock:= SDLNet_TCP_Open(ipaddr);
f373838129c2 Some futher work on flib net client part
unc0rr
parents: 10896
diff changeset
   286
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   287
    state.bufpos:= 0;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   288
    state.buf:= '';
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   289
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   290
    state.l:= 0;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   291
    state.netState:= netConnecting;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   292
10900
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   293
    netReaderThread:= SDL_CreateThread(@netReader{$IFDEF SDL2}, 'netReader'{$ENDIF}, nil);
10896
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   294
end;
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   295
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   296
procedure initModule;
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   297
begin
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   298
    sock:= nil;
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   299
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   300
    SDLNet_Init;
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   301
    fds:= SDLNet_AllocSocketSet(1);
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   302
end;
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   303
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   304
procedure freeModule;
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   305
begin
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   306
end;
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   307
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   308
end.