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