author | unc0rr |
Thu, 03 Dec 2015 23:59:06 +0300 | |
branch | qmlfrontend |
changeset 11447 | 6b04a266feee |
parent 11446 | 908aed8525f9 |
child 11449 | 91f8c6ff5bab |
permissions | -rw-r--r-- |
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; |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
8 |
procedure sendNet(s: shortstring); |
11420 | 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 |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
12 |
uses SDLh, uFLIPC, uFLTypes, uFLUICallback, uFLNetTypes, uFLUtils; |
10931 | 13 |
|
11442 | 14 |
const endCmd: shortstring = #10 + #10; |
10931 | 15 |
|
16 |
function getNextChar: char; forward; |
|
17 |
function getCurrChar: char; forward; |
|
18 |
||
10929 | 19 |
type |
11429 | 20 |
TNetState = (netDisconnected, netConnecting); |
10929 | 21 |
TParserState = record |
22 |
cmd: TCmdType; |
|
23 |
l: LongInt; |
|
24 |
netState: TNetState; |
|
10931 | 25 |
buf: shortstring; |
26 |
bufpos: byte; |
|
10929 | 27 |
end; |
28 |
PHandler = procedure; |
|
29 |
||
30 |
var state: TParserState; |
|
31 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
32 |
procedure handleTail; forward; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
33 |
function getShortString: shortstring; forward; |
11442 | 34 |
function getLongString: ansistring; forward; |
10929 | 35 |
|
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
36 |
procedure handler_; |
10929 | 37 |
begin |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
38 |
sendUI(mtNetData, @state.cmd, sizeof(state.cmd)); |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
39 |
handleTail() |
10929 | 40 |
end; |
41 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
42 |
procedure handler_L; |
11428 | 43 |
var cmd: TCmdParamL; |
10929 | 44 |
begin |
11428 | 45 |
cmd.cmd:= state.cmd; |
11442 | 46 |
cmd.str1:= getLongString; |
47 |
if length(cmd.str1) = 0 then exit; |
|
11428 | 48 |
sendUI(mtNetData, @cmd, sizeof(cmd)); |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
49 |
handleTail() |
10929 | 50 |
end; |
51 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
52 |
procedure handler_ML; |
11428 | 53 |
var cmd: TCmdParamL; |
54 |
f: boolean; |
|
10929 | 55 |
begin |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
56 |
writeln('handler_ML'); |
11428 | 57 |
sendUI(mtNetData, @state.cmd, sizeof(state.cmd)); |
58 |
cmd.cmd:= Succ(state.cmd); |
|
59 |
||
60 |
repeat |
|
11442 | 61 |
cmd.str1:= getLongString; |
11428 | 62 |
f:= cmd.str1[0] <> #0; |
63 |
if f then |
|
64 |
sendUI(mtNetData, @cmd, sizeof(cmd)); |
|
11434
d96a37de1076
Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents:
11430
diff
changeset
|
65 |
until not f; |
d96a37de1076
Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents:
11430
diff
changeset
|
66 |
state.l:= 0 |
10929 | 67 |
end; |
68 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
69 |
procedure handler_MS; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
70 |
var cmd: TCmdParamS; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
71 |
f: boolean; |
10929 | 72 |
begin |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
73 |
sendUI(mtNetData, @state.cmd, sizeof(state.cmd)); |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
74 |
cmd.cmd:= Succ(state.cmd); |
10929 | 75 |
|
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
76 |
repeat |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
77 |
cmd.str1:= getShortString; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
78 |
f:= cmd.str1[0] <> #0; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
79 |
if f then |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
80 |
sendUI(mtNetData, @cmd, sizeof(cmd)); |
11434
d96a37de1076
Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents:
11430
diff
changeset
|
81 |
until not f; |
d96a37de1076
Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents:
11430
diff
changeset
|
82 |
state.l:= 0 |
10929 | 83 |
end; |
84 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
85 |
procedure handler_S; |
11428 | 86 |
var cmd: TCmdParamS; |
10929 | 87 |
begin |
11428 | 88 |
cmd.cmd:= state.cmd; |
89 |
cmd.str1:= getShortString; |
|
90 |
if cmd.str1[0] = #0 then exit; |
|
91 |
sendUI(mtNetData, @cmd, sizeof(cmd)); |
|
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
92 |
handleTail() |
10929 | 93 |
end; |
94 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
95 |
procedure handler_SL; |
11420 | 96 |
var cmd: TCmdParamSL; |
10929 | 97 |
begin |
11420 | 98 |
cmd.cmd:= state.cmd; |
99 |
cmd.str1:= getShortString; |
|
11425 | 100 |
if cmd.str1[0] = #0 then exit; |
11442 | 101 |
cmd.str2:= getLongString; |
11425 | 102 |
if cmd.str2[0] = #0 then exit; |
11420 | 103 |
sendUI(mtNetData, @cmd, sizeof(cmd)); |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
104 |
handleTail() |
10929 | 105 |
end; |
106 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
107 |
procedure handler_SMS; |
11429 | 108 |
var cmd: TCmdParamS; |
109 |
f: boolean; |
|
10929 | 110 |
begin |
11429 | 111 |
cmd.cmd:= state.cmd; |
112 |
cmd.str1:= getShortString; |
|
113 |
if cmd.str1[0] = #0 then exit; |
|
114 |
sendUI(mtNetData, @cmd, sizeof(cmd)); |
|
115 |
||
116 |
cmd.cmd:= Succ(state.cmd); |
|
117 |
repeat |
|
118 |
cmd.str1:= getShortString; |
|
119 |
f:= cmd.str1[0] <> #0; |
|
120 |
if f then |
|
121 |
sendUI(mtNetData, @cmd, sizeof(cmd)); |
|
11434
d96a37de1076
Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents:
11430
diff
changeset
|
122 |
until not f; |
d96a37de1076
Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents:
11430
diff
changeset
|
123 |
state.l:= 0 |
10929 | 124 |
end; |
125 |
||
11447 | 126 |
procedure handler_SS; |
127 |
var cmd: TCmdParamSS; |
|
128 |
begin |
|
129 |
cmd.cmd:= state.cmd; |
|
130 |
cmd.str1:= getShortString; |
|
131 |
if cmd.str1[0] = #0 then exit; |
|
132 |
cmd.str2:= getShortString; |
|
133 |
if cmd.str2[0] = #0 then exit; |
|
134 |
sendUI(mtNetData, @cmd, sizeof(cmd)); |
|
135 |
handleTail() |
|
136 |
end; |
|
137 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
138 |
procedure handler__i; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
139 |
var cmd: TCmdParami; |
11425 | 140 |
s: shortstring; |
10929 | 141 |
begin |
11425 | 142 |
s:= getShortString(); |
143 |
if s[0] = #0 then exit; |
|
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
144 |
cmd.cmd:= state.cmd; |
11425 | 145 |
s:= getShortString(); |
146 |
if s[0] = #0 then exit; |
|
147 |
cmd.param1:= strToInt(s); |
|
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
148 |
sendUI(mtNetData, @cmd, sizeof(cmd)); |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
149 |
handleTail() |
10929 | 150 |
end; |
151 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
152 |
procedure handler_i; |
11439 | 153 |
var cmd: TCmdParami; |
154 |
s: shortstring; |
|
10929 | 155 |
begin |
11439 | 156 |
s:= getShortString(); |
157 |
if s[0] = #0 then exit; |
|
158 |
cmd.cmd:= state.cmd; |
|
159 |
cmd.param1:= strToInt(s); |
|
160 |
sendUI(mtNetData, @cmd, sizeof(cmd)); |
|
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
161 |
handleTail() |
10929 | 162 |
end; |
163 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
164 |
procedure handler__UNKNOWN_; |
10929 | 165 |
begin |
10931 | 166 |
writeln('[NET] Unknown cmd'); |
11434
d96a37de1076
Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents:
11430
diff
changeset
|
167 |
handleTail(); |
d96a37de1076
Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents:
11430
diff
changeset
|
168 |
state.l:= 0 |
10929 | 169 |
end; |
170 |
||
11434
d96a37de1076
Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents:
11430
diff
changeset
|
171 |
const net2cmd: array[0..46] of TCmdType = (cmd_WARNING, cmd_WARNING, |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
172 |
cmd_TEAM_COLOR, cmd_TEAM_ACCEPTED, cmd_SERVER_VARS, cmd_SERVER_MESSAGE, |
11430
2947f06e8533
Another approach to parsing two-lines protocol commands
unc0rr
parents:
11429
diff
changeset
|
173 |
cmd_SERVER_AUTH, cmd_RUN_GAME, cmd_ROUND_FINISHED, cmd_ROOM_UPD, cmd_ROOM_DEL, |
11434
d96a37de1076
Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents:
11430
diff
changeset
|
174 |
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:
11430
diff
changeset
|
175 |
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:
11430
diff
changeset
|
176 |
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:
11430
diff
changeset
|
177 |
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:
11430
diff
changeset
|
178 |
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:
11430
diff
changeset
|
179 |
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:
11430
diff
changeset
|
180 |
cmd_BYE, cmd_BANLIST, cmd_ASKPASSWORD, cmd_ADD_TEAM); |
d96a37de1076
Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents:
11430
diff
changeset
|
181 |
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:
11430
diff
changeset
|
182 |
#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:
11430
diff
changeset
|
183 |
'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:
11430
diff
changeset
|
184 |
'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:
11430
diff
changeset
|
185 |
'_', '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:
11430
diff
changeset
|
186 |
'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:
11430
diff
changeset
|
187 |
'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:
11430
diff
changeset
|
188 |
'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:
11430
diff
changeset
|
189 |
#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:
11430
diff
changeset
|
190 |
#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:
11430
diff
changeset
|
191 |
'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:
11430
diff
changeset
|
192 |
'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:
11430
diff
changeset
|
193 |
'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:
11430
diff
changeset
|
194 |
#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:
11430
diff
changeset
|
195 |
#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:
11430
diff
changeset
|
196 |
'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:
11430
diff
changeset
|
197 |
#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:
11430
diff
changeset
|
198 |
'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:
11430
diff
changeset
|
199 |
'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:
11430
diff
changeset
|
200 |
'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:
11430
diff
changeset
|
201 |
'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:
11430
diff
changeset
|
202 |
'N', 'G', #10, #0, #10); |
d96a37de1076
Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents:
11430
diff
changeset
|
203 |
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:
11430
diff
changeset
|
204 |
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:
11430
diff
changeset
|
205 |
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:
11430
diff
changeset
|
206 |
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:
11430
diff
changeset
|
207 |
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:
11430
diff
changeset
|
208 |
-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:
11430
diff
changeset
|
209 |
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:
11430
diff
changeset
|
210 |
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:
11430
diff
changeset
|
211 |
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:
11430
diff
changeset
|
212 |
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:
11430
diff
changeset
|
213 |
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:
11430
diff
changeset
|
214 |
-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:
11430
diff
changeset
|
215 |
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:
11430
diff
changeset
|
216 |
-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:
11430
diff
changeset
|
217 |
0, -12, 8, 0, 0, 0, 0, 0, 0, -11, 0, -10); |
d96a37de1076
Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents:
11430
diff
changeset
|
218 |
const handlers: array[0..46] of PHandler = (@handler__UNKNOWN_, @handler_L, |
11447 | 219 |
@handler_SS, @handler_S, @handler_SL, @handler_L, @handler_S, @handler_, |
11434
d96a37de1076
Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents:
11430
diff
changeset
|
220 |
@handler_, @handler_MS, @handler_S, @handler_MS, @handler_MS, @handler_S, |
d96a37de1076
Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents:
11430
diff
changeset
|
221 |
@handler_i, @handler_MS, @handler_L, @handler_S, @handler_SL, @handler_MS, |
11447 | 222 |
@handler_SL, @handler_, @handler_S, @handler_MS, @handler_MS, @handler_SS, |
11434
d96a37de1076
Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents:
11430
diff
changeset
|
223 |
@handler_L, @handler_ML, @handler__i, @handler_SMS, @handler_SL, @handler_S, |
d96a37de1076
Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents:
11430
diff
changeset
|
224 |
@handler_i, @handler_S, @handler_S, @handler_MS, @handler_i, @handler_i, |
d96a37de1076
Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents:
11430
diff
changeset
|
225 |
@handler_S, @handler_ML, @handler_i, @handler_L, @handler_SL, @handler_SL, |
d96a37de1076
Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents:
11430
diff
changeset
|
226 |
@handler_MS, @handler_S, @handler_MS); |
11423 | 227 |
|
10931 | 228 |
procedure handleTail; |
229 |
var cnt: Longint; |
|
230 |
c: char; |
|
231 |
begin |
|
232 |
c:= getCurrChar; |
|
233 |
repeat |
|
234 |
if c = #10 then cnt:= 0 else cnt:= 1; |
|
235 |
repeat |
|
236 |
c:= getNextChar; |
|
237 |
inc(cnt) |
|
238 |
until (c = #0) or (c = #10); |
|
11434
d96a37de1076
Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents:
11430
diff
changeset
|
239 |
until (c = #0) or (cnt = 1); |
d96a37de1076
Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents:
11430
diff
changeset
|
240 |
state.l:= 0 |
10931 | 241 |
end; |
242 |
||
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
243 |
var sock: PTCPSocket; |
10900 | 244 |
netReaderThread: PSDL_Thread; |
10931 | 245 |
|
246 |
function getCurrChar: char; |
|
247 |
begin |
|
248 |
getCurrChar:= state.buf[state.bufpos] |
|
249 |
end; |
|
10900 | 250 |
|
251 |
function getNextChar: char; |
|
252 |
var r: byte; |
|
253 |
begin |
|
10931 | 254 |
if state.bufpos < byte(state.buf[0]) then |
10900 | 255 |
begin |
10931 | 256 |
inc(state.bufpos); |
10900 | 257 |
end else |
258 |
begin |
|
10931 | 259 |
r:= SDLNet_TCP_Recv(sock, @state.buf[1], 255); |
10900 | 260 |
if r > 0 then |
261 |
begin |
|
10931 | 262 |
state.bufpos:= 1; |
263 |
state.buf[0]:= char(r); |
|
10900 | 264 |
end else |
265 |
begin |
|
10931 | 266 |
state.bufpos:= 0; |
267 |
state.buf[0]:= #0; |
|
10929 | 268 |
end |
10931 | 269 |
end; |
270 |
||
271 |
getNextChar:= state.buf[state.bufpos]; |
|
10900 | 272 |
end; |
10898 | 273 |
|
274 |
function netReader(data: pointer): LongInt; cdecl; export; |
|
10929 | 275 |
var c: char; |
10933 | 276 |
ipaddr: TIPAddress; |
10898 | 277 |
begin |
10933 | 278 |
netReader:= 0; |
279 |
||
280 |
if SDLNet_ResolveHost(ipaddr, PChar('netserver.hedgewars.org'), 46631) = 0 then |
|
281 |
sock:= SDLNet_TCP_Open(ipaddr); |
|
282 |
||
283 |
repeat |
|
284 |
c:= getNextChar; |
|
11434
d96a37de1076
Apply generated code to .pas files, fix FULLMAPCONFIG handling
unc0rr
parents:
11430
diff
changeset
|
285 |
//writeln('>>>>> ', c, ' [', letters[state.l], '] ', commands[state.l], ' ', state.l); |
10933 | 286 |
if c = #0 then |
287 |
state.netState:= netDisconnected |
|
288 |
else |
|
289 |
begin |
|
290 |
while (letters[state.l] <> c) and (commands[state.l] > 0) do |
|
291 |
inc(state.l, commands[state.l]); |
|
292 |
||
293 |
if c = letters[state.l] then |
|
294 |
if commands[state.l] < 0 then |
|
10931 | 295 |
begin |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
296 |
state.cmd:= net2cmd[-10 - commands[state.l]]; |
10933 | 297 |
writeln('[NET] ', state.cmd); |
10931 | 298 |
handlers[-10 - commands[state.l]](); |
11425 | 299 |
state.l:= 0 |
10931 | 300 |
end |
10933 | 301 |
else |
302 |
inc(state.l) |
|
10931 | 303 |
else |
10933 | 304 |
begin |
11424 | 305 |
handler__UNKNOWN_() |
10933 | 306 |
end |
10931 | 307 |
end |
10933 | 308 |
until state.netState = netDisconnected; |
10931 | 309 |
|
11420 | 310 |
SDLNet_TCP_Close(sock); |
10933 | 311 |
sock:= nil; |
312 |
||
313 |
writeln('[NET] netReader: disconnected'); |
|
10931 | 314 |
end; |
315 |
||
316 |
procedure sendNet(s: shortstring); |
|
317 |
begin |
|
318 |
writeln('[NET] Send: ', s); |
|
10935 | 319 |
ipcToNet(s + endCmd); |
320 |
end; |
|
321 |
||
11420 | 322 |
procedure sendNetLn(s: shortstring); |
323 |
begin |
|
324 |
writeln('[NET] Send: ', s); |
|
325 |
ipcToNet(s + #10); |
|
326 |
end; |
|
327 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
328 |
function getShortString: shortstring; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
329 |
var s: shortstring; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
330 |
c: char; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
331 |
begin |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
332 |
s[0]:= #0; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
333 |
|
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
334 |
repeat |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
335 |
inc(s[0]); |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
336 |
s[byte(s[0])]:= getNextChar |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
337 |
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:
11408
diff
changeset
|
338 |
|
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
339 |
if s[byte(s[0])] = #10 then |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
340 |
dec(s[0]) |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
341 |
else |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
342 |
repeat c:= getNextChar until (c = #0) or (c = #10); |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
343 |
|
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
344 |
getShortString:= s |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
345 |
end; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
346 |
|
11442 | 347 |
function getLongString: ansistring; |
348 |
var s: shortstring; |
|
349 |
l: ansistring; |
|
350 |
c: char; |
|
351 |
begin |
|
352 |
l:= ''; |
|
353 |
||
354 |
repeat |
|
355 |
s[0]:= #0; |
|
356 |
repeat |
|
357 |
inc(s[0]); |
|
358 |
c:= getNextChar; |
|
359 |
s[byte(s[0])]:= c |
|
360 |
until (s[0] = #255) or (c = #10) or (c = #0); |
|
361 |
||
362 |
if s[byte(s[0])] = #10 then |
|
363 |
dec(s[0]); |
|
364 |
||
365 |
l:= l + s |
|
366 |
until (c = #10) or (c = #0); |
|
367 |
||
368 |
getLongString:= l |
|
369 |
end; |
|
370 |
||
10935 | 371 |
procedure netSendCallback(p: pointer; msg: PChar; len: Longword); |
372 |
begin |
|
373 |
// W A R N I N G: totally thread-unsafe due to use of sock variable |
|
374 |
SDLNet_TCP_Send(sock, msg, len); |
|
10898 | 375 |
end; |
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
376 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
377 |
procedure connectOfficialServer; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
378 |
begin |
10898 | 379 |
if sock <> nil then |
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
380 |
exit; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
381 |
|
10931 | 382 |
state.bufpos:= 0; |
383 |
state.buf:= ''; |
|
384 |
||
385 |
state.l:= 0; |
|
386 |
state.netState:= netConnecting; |
|
387 |
||
11408 | 388 |
netReaderThread:= SDL_CreateThread(@netReader, 'netReader', nil); |
11420 | 389 |
SDL_DetachThread(netReaderThread) |
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
390 |
end; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
391 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
392 |
procedure initModule; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
393 |
begin |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
394 |
sock:= nil; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
395 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
396 |
SDLNet_Init; |
10935 | 397 |
|
398 |
registerNetCallback(nil, @netSendCallback); |
|
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
399 |
end; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
400 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
401 |
procedure freeModule; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
402 |
begin |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
403 |
end; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
404 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
405 |
end. |