hedgewars/uFLNet.pas
author unc0rr
Sat, 28 Nov 2015 00:18:04 +0300
branchqmlfrontend
changeset 11433 bca9afcc3a72
parent 11429 d96a37de1076
child 11434 23912c93935a
permissions -rw-r--r--
Handle some CFG parameters
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;
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
     8
procedure sendNet(s: shortstring);
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 11413
diff changeset
     9
procedure sendNetLn(s: shortstring);
10896
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
    10
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
    11
implementation
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
    12
uses SDLh, uFLIPC, uFLTypes, uFLUICallback, uFLNetTypes, uFLUtils;
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
    13
10935
3a65fcd7c335 Move SDLNet_TCP_Send to its own thread
unc0rr
parents: 10933
diff changeset
    14
const endCmd: string = #10 + #10;
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
    15
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
    16
function getNextChar: char; forward;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
    17
function getCurrChar: char; forward;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
    18
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    19
type
11424
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
    20
    TNetState = (netDisconnected, netConnecting);
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    21
    TParserState = record
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    22
                       cmd: TCmdType;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    23
                       l: LongInt;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    24
                       netState: TNetState;
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
    25
                       buf: shortstring;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
    26
                       bufpos: byte;
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    27
                   end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    28
    PHandler = procedure;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    29
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    30
var state: TParserState;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    31
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
    32
procedure handleTail; forward;
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
    33
function getShortString: shortstring; forward;
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    34
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
    35
procedure handler_;
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    36
begin
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
    37
    sendUI(mtNetData, @state.cmd, sizeof(state.cmd));
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
    38
    handleTail()
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    39
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    40
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
    41
procedure handler_L;
11423
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11421
diff changeset
    42
var cmd: TCmdParamL;
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    43
begin
11423
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11421
diff changeset
    44
    cmd.cmd:= state.cmd;
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11421
diff changeset
    45
    cmd.str1:= getShortString; // FIXME long line
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11421
diff changeset
    46
    if cmd.str1[0] = #0 then exit;
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11421
diff changeset
    47
    sendUI(mtNetData, @cmd, sizeof(cmd));
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
    48
    handleTail()
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    49
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    50
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
    51
procedure handler_ML;
11423
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11421
diff changeset
    52
var cmd: TCmdParamL;
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11421
diff changeset
    53
    f: boolean;
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    54
begin
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
    55
    writeln('handler_ML');
11423
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11421
diff changeset
    56
    sendUI(mtNetData, @state.cmd, sizeof(state.cmd));
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11421
diff changeset
    57
    cmd.cmd:= Succ(state.cmd);
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11421
diff changeset
    58
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11421
diff changeset
    59
    repeat
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11421
diff changeset
    60
        cmd.str1:= getShortString; // FIXME long line
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11421
diff changeset
    61
        f:= cmd.str1[0] <> #0;
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11421
diff changeset
    62
        if f then
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11421
diff changeset
    63
            sendUI(mtNetData, @cmd, sizeof(cmd));
11429
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
    64
    until not f;
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
    65
    state.l:= 0
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    66
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    67
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
    68
procedure handler_MS;
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
    69
var cmd: TCmdParamS;
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
    70
    f: boolean;
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    71
begin
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
    72
    sendUI(mtNetData, @state.cmd, sizeof(state.cmd));
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
    73
    cmd.cmd:= Succ(state.cmd);
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    74
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
    75
    repeat
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
    76
        cmd.str1:= getShortString;
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
    77
        f:= cmd.str1[0] <> #0;
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
    78
        if f then
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
    79
            sendUI(mtNetData, @cmd, sizeof(cmd));
11429
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
    80
    until not f;
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
    81
    state.l:= 0
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    82
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    83
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
    84
procedure handler_S;
11423
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11421
diff changeset
    85
var cmd: TCmdParamS;
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    86
begin
11423
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11421
diff changeset
    87
    cmd.cmd:= state.cmd;
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11421
diff changeset
    88
    cmd.str1:= getShortString;
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11421
diff changeset
    89
    if cmd.str1[0] = #0 then exit;
e045dc60c37e - Warnings/errors message box
unc0rr
parents: 11421
diff changeset
    90
    sendUI(mtNetData, @cmd, sizeof(cmd));
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
    91
    handleTail()
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    92
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    93
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
    94
procedure handler_SL;
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 11413
diff changeset
    95
var cmd: TCmdParamSL;
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
    96
begin
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 11413
diff changeset
    97
    cmd.cmd:= state.cmd;
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 11413
diff changeset
    98
    cmd.str1:= getShortString;
11420
ef7f8ac96dfa Small fixes
unc0rr
parents: 11419
diff changeset
    99
    if cmd.str1[0] = #0 then exit;
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 11413
diff changeset
   100
    cmd.str2:= getShortString; // FIXME should be long string
11420
ef7f8ac96dfa Small fixes
unc0rr
parents: 11419
diff changeset
   101
    if cmd.str2[0] = #0 then exit;
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 11413
diff changeset
   102
    sendUI(mtNetData, @cmd, sizeof(cmd));
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   103
    handleTail()
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   104
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   105
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   106
procedure handler_SMS;
11424
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   107
var cmd: TCmdParamS;
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   108
    f: boolean;
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   109
begin
11424
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   110
    cmd.cmd:= state.cmd;
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   111
    cmd.str1:= getShortString;
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   112
    if cmd.str1[0] = #0 then exit;
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   113
    sendUI(mtNetData, @cmd, sizeof(cmd));
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   114
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   115
    cmd.cmd:= Succ(state.cmd);
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   116
    repeat
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   117
        cmd.str1:= getShortString;
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   118
        f:= cmd.str1[0] <> #0;
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   119
        if f then
86c13e5662f1 - Some refactoring
unc0rr
parents: 11423
diff changeset
   120
            sendUI(mtNetData, @cmd, sizeof(cmd));
11429
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   121
    until not f;
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   122
    state.l:= 0
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   123
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   124
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   125
procedure handler__i;
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   126
var cmd: TCmdParami;
11420
ef7f8ac96dfa Small fixes
unc0rr
parents: 11419
diff changeset
   127
    s: shortstring;
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   128
begin
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   129
    writeln('handler__i');
11420
ef7f8ac96dfa Small fixes
unc0rr
parents: 11419
diff changeset
   130
    s:= getShortString();
ef7f8ac96dfa Small fixes
unc0rr
parents: 11419
diff changeset
   131
    if s[0] = #0 then exit;
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   132
    cmd.cmd:= state.cmd;
11420
ef7f8ac96dfa Small fixes
unc0rr
parents: 11419
diff changeset
   133
    s:= getShortString();
ef7f8ac96dfa Small fixes
unc0rr
parents: 11419
diff changeset
   134
    if s[0] = #0 then exit;
ef7f8ac96dfa Small fixes
unc0rr
parents: 11419
diff changeset
   135
    cmd.param1:= strToInt(s);
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   136
    sendUI(mtNetData, @cmd, sizeof(cmd));
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   137
    handleTail()
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   138
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   139
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   140
procedure handler_i;
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   141
begin
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   142
    writeln('handler_i');
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   143
    handleTail()
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   144
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   145
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   146
procedure handler__UNKNOWN_;
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   147
begin
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   148
    writeln('[NET] Unknown cmd');
11429
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   149
    handleTail();
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   150
    state.l:= 0
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   151
end;
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   152
11429
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   153
const net2cmd: array[0..46] of TCmdType = (cmd_WARNING, cmd_WARNING,
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   154
    cmd_TEAM_COLOR, cmd_TEAM_ACCEPTED, cmd_SERVER_VARS, cmd_SERVER_MESSAGE,
11425
2947f06e8533 Another approach to parsing two-lines protocol commands
unc0rr
parents: 11424
diff changeset
   155
    cmd_SERVER_AUTH, cmd_RUN_GAME, cmd_ROUND_FINISHED, cmd_ROOM_UPD, cmd_ROOM_DEL,
11429
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   156
    cmd_ROOM_ADD, cmd_ROOMS, cmd_REMOVE_TEAM, cmd_PROTO, cmd_PING, cmd_NOTICE,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   157
    cmd_NICK, cmd_LOBBY_LEFT, cmd_LOBBY_JOINED, cmd_LEFT, cmd_KICKED, cmd_JOINING,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   158
    cmd_JOINED, cmd_INFO, cmd_HH_NUM, cmd_ERROR, cmd_EM, cmd_CONNECTED,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   159
    cmd_CLIENT_FLAGS, cmd_CHAT, cmd_CFG_THEME, cmd_CFG_TEMPLATE, cmd_CFG_SEED,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   160
    cmd_CFG_SCRIPT, cmd_CFG_SCHEME, cmd_CFG_MAZE_SIZE, cmd_CFG_MAP, cmd_CFG_MAPGEN,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   161
    cmd_CFG_FULLMAPCONFIG, cmd_CFG_FEATURE_SIZE, cmd_CFG_DRAWNMAP, cmd_CFG_AMMO,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   162
    cmd_BYE, cmd_BANLIST, cmd_ASKPASSWORD, cmd_ADD_TEAM);
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   163
const letters: array[0..332] of char = ('A', 'D', 'D', '_', 'T', 'E', 'A', 'M',
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   164
    #10, 'S', 'K', 'P', 'A', 'S', 'S', 'W', 'O', 'R', 'D', #10, 'B', 'A', 'N', 'L',
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   165
    'I', 'S', 'T', #10, 'Y', 'E', #10, 'C', 'F', 'G', #10, 'A', 'M', 'M', 'O', #10,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   166
    'D', 'R', 'A', 'W', 'N', 'M', 'A', 'P', #10, 'F', 'E', 'A', 'T', 'U', 'R', 'E',
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   167
    '_', 'S', 'I', 'Z', 'E', #10, 'U', 'L', 'L', 'M', 'A', 'P', 'C', 'O', 'N', 'F',
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   168
    'I', 'G', #10, 'M', 'A', 'P', 'G', 'E', 'N', #10, #10, 'Z', 'E', '_', 'S', 'I',
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   169
    'Z', 'E', #10, 'S', 'C', 'H', 'E', 'M', 'E', #10, 'R', 'I', 'P', 'T', #10, 'E',
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   170
    'E', 'D', #10, 'T', 'E', 'M', 'P', 'L', 'A', 'T', 'E', #10, 'H', 'E', 'M', 'E',
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   171
    #10, 'H', 'A', 'T', #10, 'L', 'I', 'E', 'N', 'T', '_', 'F', 'L', 'A', 'G', 'S',
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   172
    #10, 'O', 'N', 'N', 'E', 'C', 'T', 'E', 'D', #10, 'E', 'M', #10, 'R', 'R', 'O',
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   173
    'R', #10, 'H', 'H', '_', 'N', 'U', 'M', #10, 'I', 'N', 'F', 'O', #10, 'J', 'O',
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   174
    'I', 'N', 'E', 'D', #10, 'I', 'N', 'G', #10, 'K', 'I', 'C', 'K', 'E', 'D', #10,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   175
    'L', 'E', 'F', 'T', #10, 'O', 'B', 'B', 'Y', ':', 'J', 'O', 'I', 'N', 'E', 'D',
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   176
    #10, 'L', 'E', 'F', 'T', #10, 'N', 'I', 'C', 'K', #10, 'O', 'T', 'I', 'C', 'E',
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   177
    #10, 'P', 'I', 'N', 'G', #10, 'R', 'O', 'T', 'O', #10, 'R', 'E', 'M', 'O', 'V',
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   178
    'E', '_', 'T', 'E', 'A', 'M', #10, 'O', 'O', 'M', 'S', #10, #10, 'A', 'D', 'D',
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   179
    #10, 'D', 'E', 'L', #10, 'U', 'P', 'D', #10, 'U', 'N', 'D', '_', 'F', 'I', 'N',
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   180
    'I', 'S', 'H', 'E', 'D', #10, 'U', 'N', '_', 'G', 'A', 'M', 'E', #10, 'S', 'E',
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   181
    'R', 'V', 'E', 'R', '_', 'A', 'U', 'T', 'H', #10, 'M', 'E', 'S', 'S', 'A', 'G',
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   182
    'E', #10, 'V', 'A', 'R', 'S', #10, 'T', 'E', 'A', 'M', '_', 'A', 'C', 'C', 'E',
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   183
    'P', 'T', 'E', 'D', #10, 'C', 'O', 'L', 'O', 'R', #10, 'W', 'A', 'R', 'N', 'I',
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   184
    'N', 'G', #10, #0, #10);
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   185
const commands: array[0..332] of integer = (20, 8, 0, 0, 0, 0, 0, 0, -56, 0, 0,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   186
    0, 0, 0, 0, 0, 0, 0, 0, -55, 11, 7, 0, 0, 0, 0, 0, -54, 0, 0, -53, 115, 89, 0,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   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,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   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,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   189
    0, 0, 0, 0, 0, 0, 0, -46, 16, 11, 5, 0, 0, 0, -45, 0, 0, 0, 0, -44, 0, 0, 0,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   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,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   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,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   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,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   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,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   194
    0, 0, 0, -28, 11, 4, 0, 0, -27, 0, 0, 0, 0, 0, -26, 10, 4, 0, 0, -25, 0, 0, 0,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   195
    0, -24, 51, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, -23, 31, 17, 0, 2, -22, 0, 4, 0, 0,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   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,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   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,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   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,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   199
    0, -12, 8, 0, 0, 0, 0, 0, 0, -11, 0, -10);
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   200
const handlers: array[0..46] of PHandler = (@handler__UNKNOWN_, @handler_L,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   201
    @handler_MS, @handler_S, @handler_SL, @handler_L, @handler_S, @handler_,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   202
    @handler_, @handler_MS, @handler_S, @handler_MS, @handler_MS, @handler_S,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   203
    @handler_i, @handler_MS, @handler_L, @handler_S, @handler_SL, @handler_MS,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   204
    @handler_SMS, @handler_, @handler_S, @handler_MS, @handler_MS, @handler_MS,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   205
    @handler_L, @handler_ML, @handler__i, @handler_SMS, @handler_SL, @handler_S,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   206
    @handler_i, @handler_S, @handler_S, @handler_MS, @handler_i, @handler_i,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   207
    @handler_S, @handler_ML, @handler_i, @handler_L, @handler_SL, @handler_SL,
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   208
    @handler_MS, @handler_S, @handler_MS);
11418
091149424aa4 Handle ROOMS and ROOM ADD protocol commands
unc0rr
parents: 11415
diff changeset
   209
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   210
procedure handleTail;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   211
var cnt: Longint;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   212
    c: char;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   213
begin
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   214
    c:= getCurrChar;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   215
    repeat
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   216
        if c = #10 then cnt:= 0 else cnt:= 1;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   217
        repeat
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   218
            c:= getNextChar;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   219
            inc(cnt)
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   220
        until (c = #0) or (c = #10);
11429
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   221
    until (c = #0) or (cnt = 1);
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   222
    state.l:= 0
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   223
end;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   224
10896
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   225
var sock: PTCPSocket;
10900
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   226
    netReaderThread: PSDL_Thread;
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   227
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   228
function getCurrChar: char;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   229
begin
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   230
    getCurrChar:= state.buf[state.bufpos]
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   231
end;
10900
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   232
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   233
function getNextChar: char;
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   234
var r: byte;
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   235
begin
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   236
    if state.bufpos < byte(state.buf[0]) then
10900
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   237
    begin
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   238
        inc(state.bufpos);
10900
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   239
    end else
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   240
    begin
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   241
        r:= SDLNet_TCP_Recv(sock, @state.buf[1], 255);
10900
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   242
        if r > 0 then
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   243
        begin
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   244
            state.bufpos:= 1;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   245
            state.buf[0]:= char(r);
10900
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   246
        end else
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   247
        begin
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   248
            state.bufpos:= 0;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   249
            state.buf[0]:= #0;
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   250
        end
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   251
    end;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   252
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   253
    getNextChar:= state.buf[state.bufpos];
10900
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
   254
end;
10898
f373838129c2 Some futher work on flib net client part
unc0rr
parents: 10896
diff changeset
   255
f373838129c2 Some futher work on flib net client part
unc0rr
parents: 10896
diff changeset
   256
function netReader(data: pointer): LongInt; cdecl; export;
10929
8ebf01f75d9f Mockup of protocol parser
unc0rr
parents: 10900
diff changeset
   257
var c: char;
10933
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   258
    ipaddr: TIPAddress;
10898
f373838129c2 Some futher work on flib net client part
unc0rr
parents: 10896
diff changeset
   259
begin
10933
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   260
    netReader:= 0;
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   261
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   262
    if SDLNet_ResolveHost(ipaddr, PChar('netserver.hedgewars.org'), 46631) = 0 then
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   263
        sock:= SDLNet_TCP_Open(ipaddr);
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   264
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   265
    repeat
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   266
        c:= getNextChar;
11429
d96a37de1076 Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents: 11425
diff changeset
   267
        //writeln('>>>>> ', c, ' [', letters[state.l], '] ', commands[state.l], ' ', state.l);
10933
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   268
        if c = #0 then
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   269
            state.netState:= netDisconnected
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   270
        else
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   271
        begin
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   272
            while (letters[state.l] <> c) and (commands[state.l] > 0) do
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   273
                inc(state.l, commands[state.l]);
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   274
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   275
            if c = letters[state.l] then
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   276
                if commands[state.l] < 0 then
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   277
                begin
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   278
                    state.cmd:= net2cmd[-10 - commands[state.l]];
10933
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   279
                    writeln('[NET] ', state.cmd);
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   280
                    handlers[-10 - commands[state.l]]();
11420
ef7f8ac96dfa Small fixes
unc0rr
parents: 11419
diff changeset
   281
                    state.l:= 0
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   282
                end
10933
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   283
                else
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   284
                    inc(state.l)
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   285
            else
10933
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   286
            begin
11419
8a5cc31483c6 - Handle ROOM DEL
unc0rr
parents: 11418
diff changeset
   287
                handler__UNKNOWN_()
10933
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   288
            end
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   289
        end
10933
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   290
    until state.netState = netDisconnected;
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   291
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 11413
diff changeset
   292
    SDLNet_TCP_Close(sock);
10933
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   293
    sock:= nil;
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   294
f1da4126a61c Some more work on flib network
unc0rr
parents: 10931
diff changeset
   295
    writeln('[NET] netReader: disconnected');
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   296
end;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   297
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   298
procedure sendNet(s: shortstring);
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   299
begin
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   300
    writeln('[NET] Send: ', s);
10935
3a65fcd7c335 Move SDLNet_TCP_Send to its own thread
unc0rr
parents: 10933
diff changeset
   301
    ipcToNet(s + endCmd);
3a65fcd7c335 Move SDLNet_TCP_Send to its own thread
unc0rr
parents: 10933
diff changeset
   302
end;
3a65fcd7c335 Move SDLNet_TCP_Send to its own thread
unc0rr
parents: 10933
diff changeset
   303
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 11413
diff changeset
   304
procedure sendNetLn(s: shortstring);
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 11413
diff changeset
   305
begin
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 11413
diff changeset
   306
    writeln('[NET] Send: ', s);
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 11413
diff changeset
   307
    ipcToNet(s + #10);
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 11413
diff changeset
   308
end;
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 11413
diff changeset
   309
11413
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   310
function getShortString: shortstring;
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   311
var s: shortstring;
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   312
    c: char;
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   313
begin
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   314
    s[0]:= #0;
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   315
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   316
    repeat
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   317
        inc(s[0]);
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   318
        s[byte(s[0])]:= getNextChar
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   319
    until (s[0] = #255) or (s[byte(s[0])] = #10) or (s[byte(s[0])] = #0);
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   320
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   321
    if s[byte(s[0])] = #10 then
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   322
        dec(s[0])
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   323
    else
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   324
        repeat c:= getNextChar until (c = #0) or (c = #10);
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   325
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   326
    getShortString:= s
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   327
end;
ffff8a0d1a76 Implement processing net commands in the main thread
unc0rr
parents: 11403
diff changeset
   328
10935
3a65fcd7c335 Move SDLNet_TCP_Send to its own thread
unc0rr
parents: 10933
diff changeset
   329
procedure netSendCallback(p: pointer; msg: PChar; len: Longword);
3a65fcd7c335 Move SDLNet_TCP_Send to its own thread
unc0rr
parents: 10933
diff changeset
   330
begin
3a65fcd7c335 Move SDLNet_TCP_Send to its own thread
unc0rr
parents: 10933
diff changeset
   331
    // W A R N I N G: totally thread-unsafe due to use of sock variable
3a65fcd7c335 Move SDLNet_TCP_Send to its own thread
unc0rr
parents: 10933
diff changeset
   332
    SDLNet_TCP_Send(sock, msg, len);
10898
f373838129c2 Some futher work on flib net client part
unc0rr
parents: 10896
diff changeset
   333
end;
10896
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   334
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   335
procedure connectOfficialServer;
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   336
begin
10898
f373838129c2 Some futher work on flib net client part
unc0rr
parents: 10896
diff changeset
   337
    if sock <> nil then
10896
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   338
        exit;
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   339
10931
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   340
    state.bufpos:= 0;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   341
    state.buf:= '';
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   342
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   343
    state.l:= 0;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   344
    state.netState:= netConnecting;
384765cd0caf Parse net commands, answer to pings
unc0rr
parents: 10929
diff changeset
   345
11403
b894922d58cc Merge default (add a bunch of FIXMEs)
unc0rr
parents: 10953
diff changeset
   346
    netReaderThread:= SDL_CreateThread(@netReader, 'netReader', nil);
11415
05cf35103206 Lobby page with chat widget(readonly)
unc0rr
parents: 11413
diff changeset
   347
    SDL_DetachThread(netReaderThread)
10896
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   348
end;
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   349
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   350
procedure initModule;
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   351
begin
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   352
    sock:= nil;
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   353
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   354
    SDLNet_Init;
10935
3a65fcd7c335 Move SDLNet_TCP_Send to its own thread
unc0rr
parents: 10933
diff changeset
   355
3a65fcd7c335 Move SDLNet_TCP_Send to its own thread
unc0rr
parents: 10933
diff changeset
   356
    registerNetCallback(nil, @netSendCallback);
10896
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   357
end;
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   358
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   359
procedure freeModule;
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   360
begin
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   361
end;
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   362
5a74923120d5 Start network support: only setting up a connection for now
unc0rr
parents:
diff changeset
   363
end.