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