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