author | unc0rr |
Sat, 21 Nov 2015 23:56:41 +0300 | |
branch | qmlfrontend |
changeset 11429 | 86c13e5662f1 |
parent 11428 | e045dc60c37e |
child 11430 | 2947f06e8533 |
permissions | -rw-r--r-- |
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
1 |
unit uFLNet; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
2 |
interface |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
3 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
4 |
procedure connectOfficialServer; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
5 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
6 |
procedure initModule; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
7 |
procedure freeModule; |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
8 |
procedure sendNet(s: shortstring); |
11420 | 9 |
procedure sendNetLn(s: shortstring); |
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
10 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
11 |
implementation |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
12 |
uses SDLh, uFLIPC, uFLTypes, uFLUICallback, uFLNetTypes, uFLUtils; |
10931 | 13 |
|
10935 | 14 |
const endCmd: string = #10 + #10; |
10931 | 15 |
|
16 |
function getNextChar: char; forward; |
|
17 |
function getCurrChar: char; forward; |
|
18 |
||
10929 | 19 |
type |
11429 | 20 |
TNetState = (netDisconnected, netConnecting); |
10929 | 21 |
TParserState = record |
22 |
cmd: TCmdType; |
|
23 |
l: LongInt; |
|
24 |
netState: TNetState; |
|
10931 | 25 |
buf: shortstring; |
26 |
bufpos: byte; |
|
10929 | 27 |
end; |
28 |
PHandler = procedure; |
|
29 |
||
30 |
var state: TParserState; |
|
31 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
32 |
procedure handleTail; forward; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
33 |
function getShortString: shortstring; forward; |
10929 | 34 |
|
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
35 |
// generated stuff here |
11423 | 36 |
const letters: array[0..212] of char = ('A', 'S', 'K', 'P', 'A', 'S', 'S', 'W', |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
37 |
'O', 'R', 'D', #10, 'B', 'A', 'N', 'L', 'I', 'S', 'T', #10, 'Y', 'E', #10, 'C', |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
38 |
'H', 'A', 'T', #10, 'L', 'I', 'E', 'N', 'T', '_', 'F', 'L', 'A', 'G', 'S', #10, |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
39 |
'O', 'N', 'N', 'E', 'C', 'T', 'E', 'D', #10, 'E', 'M', #10, 'R', 'R', 'O', 'R', |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
40 |
#10, 'H', 'H', '_', 'N', 'U', 'M', #10, 'I', 'N', 'F', 'O', #10, 'J', 'O', 'I', |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
41 |
'N', 'E', 'D', #10, 'I', 'N', 'G', #10, 'K', 'I', 'C', 'K', 'E', 'D', #10, 'L', |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
42 |
'E', 'F', 'T', #10, 'O', 'B', 'B', 'Y', ':', 'J', 'O', 'I', 'N', 'E', 'D', #10, |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
43 |
'L', 'E', 'F', 'T', #10, 'N', 'I', 'C', 'K', #10, 'O', 'T', 'I', 'C', 'E', #10, |
11424 | 44 |
'P', 'I', 'N', 'G', #10, 'R', 'O', 'T', 'O', #10, 'R', 'O', 'O', 'M', 'S', #10, |
11423 | 45 |
#10, 'U', 'N', 'D', '_', 'F', 'I', 'N', 'I', 'S', 'H', 'E', 'D', #10, 'U', 'N', |
46 |
'_', 'G', 'A', 'M', 'E', #10, 'S', 'E', 'R', 'V', 'E', 'R', '_', 'A', 'U', 'T', |
|
47 |
'H', #10, 'M', 'E', 'S', 'S', 'A', 'G', 'E', #10, 'V', 'A', 'R', 'S', #10, 'T', |
|
48 |
'E', 'A', 'M', '_', 'A', 'C', 'C', 'E', 'P', 'T', 'E', 'D', #10, 'C', 'O', 'L', |
|
49 |
'O', 'R', #10, 'W', 'A', 'R', 'N', 'I', 'N', 'G', #10, #0, #10); |
|
50 |
const commands: array[0..212] of integer = (12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
|
51 |
-40, 11, 7, 0, 0, 0, 0, 0, -39, 0, 0, -38, 26, 4, 0, 0, -37, 12, 0, 0, 0, 0, 0, |
|
52 |
0, 0, 0, 0, 0, -36, 0, 0, 0, 0, 0, 0, 0, 0, -35, 8, 2, -34, 0, 0, 0, 0, -33, 7, |
|
53 |
0, 0, 0, 0, 0, -32, 5, 0, 0, 0, -31, 11, 0, 0, 0, 3, 0, -30, 0, 0, 0, -29, 7, 0, |
|
54 |
0, 0, 0, 0, -28, 22, 4, 0, 0, -27, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, -26, 0, 0, |
|
55 |
0, 0, -25, 11, 4, 0, 0, -24, 0, 0, 0, 0, 0, -23, 10, 4, 0, 0, -22, 0, 0, 0, 0, |
|
11426 | 56 |
-21, 28, 19, 5, 3, 2, -19, -20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -18, 0, 0, 0, |
11424 | 57 |
0, 0, 0, 0, -17, 25, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, -16, 8, 0, 0, 0, 0, 0, 0, |
11423 | 58 |
-15, 0, 0, 0, 0, -14, 20, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, -13, 0, 0, 0, 0, |
59 |
0, -12, 8, 0, 0, 0, 0, 0, 0, -11, 0, -10); |
|
10929 | 60 |
|
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
61 |
procedure handler_; |
10929 | 62 |
begin |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
63 |
sendUI(mtNetData, @state.cmd, sizeof(state.cmd)); |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
64 |
handleTail() |
10929 | 65 |
end; |
66 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
67 |
procedure handler_L; |
11428 | 68 |
var cmd: TCmdParamL; |
10929 | 69 |
begin |
11428 | 70 |
cmd.cmd:= state.cmd; |
71 |
cmd.str1:= getShortString; // FIXME long line |
|
72 |
if cmd.str1[0] = #0 then exit; |
|
73 |
sendUI(mtNetData, @cmd, sizeof(cmd)); |
|
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
74 |
handleTail() |
10929 | 75 |
end; |
76 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
77 |
procedure handler_ML; |
11428 | 78 |
var cmd: TCmdParamL; |
79 |
f: boolean; |
|
10929 | 80 |
begin |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
81 |
writeln('handler_ML'); |
11428 | 82 |
sendUI(mtNetData, @state.cmd, sizeof(state.cmd)); |
83 |
cmd.cmd:= Succ(state.cmd); |
|
84 |
||
85 |
repeat |
|
86 |
cmd.str1:= getShortString; // FIXME long line |
|
87 |
f:= cmd.str1[0] <> #0; |
|
88 |
if f then |
|
89 |
sendUI(mtNetData, @cmd, sizeof(cmd)); |
|
90 |
until not f |
|
10929 | 91 |
end; |
92 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
93 |
procedure handler_MS; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
94 |
var cmd: TCmdParamS; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
95 |
f: boolean; |
10929 | 96 |
begin |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
97 |
sendUI(mtNetData, @state.cmd, sizeof(state.cmd)); |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
98 |
cmd.cmd:= Succ(state.cmd); |
10929 | 99 |
|
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
100 |
repeat |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
101 |
cmd.str1:= getShortString; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
102 |
f:= cmd.str1[0] <> #0; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
103 |
if f then |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
104 |
sendUI(mtNetData, @cmd, sizeof(cmd)); |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
105 |
until not f |
10929 | 106 |
end; |
107 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
108 |
procedure handler_S; |
11428 | 109 |
var cmd: TCmdParamS; |
10929 | 110 |
begin |
11428 | 111 |
cmd.cmd:= state.cmd; |
112 |
cmd.str1:= getShortString; |
|
113 |
if cmd.str1[0] = #0 then exit; |
|
114 |
sendUI(mtNetData, @cmd, sizeof(cmd)); |
|
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
115 |
handleTail() |
10929 | 116 |
end; |
117 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
118 |
procedure handler_SL; |
11420 | 119 |
var cmd: TCmdParamSL; |
10929 | 120 |
begin |
11420 | 121 |
cmd.cmd:= state.cmd; |
122 |
cmd.str1:= getShortString; |
|
11425 | 123 |
if cmd.str1[0] = #0 then exit; |
11420 | 124 |
cmd.str2:= getShortString; // FIXME should be long string |
11425 | 125 |
if cmd.str2[0] = #0 then exit; |
11420 | 126 |
sendUI(mtNetData, @cmd, sizeof(cmd)); |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
127 |
handleTail() |
10929 | 128 |
end; |
129 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
130 |
procedure handler_SMS; |
11429 | 131 |
var cmd: TCmdParamS; |
132 |
f: boolean; |
|
10929 | 133 |
begin |
11429 | 134 |
cmd.cmd:= state.cmd; |
135 |
cmd.str1:= getShortString; |
|
136 |
if cmd.str1[0] = #0 then exit; |
|
137 |
sendUI(mtNetData, @cmd, sizeof(cmd)); |
|
138 |
||
139 |
cmd.cmd:= Succ(state.cmd); |
|
140 |
repeat |
|
141 |
cmd.str1:= getShortString; |
|
142 |
f:= cmd.str1[0] <> #0; |
|
143 |
if f then |
|
144 |
sendUI(mtNetData, @cmd, sizeof(cmd)); |
|
145 |
until not f |
|
10929 | 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 |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
152 |
writeln('handler__i'); |
11425 | 153 |
s:= getShortString(); |
154 |
if s[0] = #0 then exit; |
|
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
155 |
cmd.cmd:= state.cmd; |
11425 | 156 |
s:= getShortString(); |
157 |
if s[0] = #0 then exit; |
|
158 |
cmd.param1:= strToInt(s); |
|
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
159 |
sendUI(mtNetData, @cmd, sizeof(cmd)); |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
160 |
handleTail() |
10929 | 161 |
end; |
162 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
163 |
procedure handler_i; |
10929 | 164 |
begin |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
165 |
writeln('handler_i'); |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
166 |
handleTail() |
10929 | 167 |
end; |
168 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
169 |
procedure handler__UNKNOWN_; |
10929 | 170 |
begin |
10931 | 171 |
writeln('[NET] Unknown cmd'); |
11424 | 172 |
handleTail() |
10929 | 173 |
end; |
174 |
||
11423 | 175 |
const handlers: array[0..30] of PHandler = (@handler__UNKNOWN_, @handler_L, @handler_MS, @handler_S, |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
176 |
@handler_SL, @handler_L, @handler_S, @handler_, @handler_, @handler_MS, |
11423 | 177 |
@handler_MS, @handler_i, @handler_MS, @handler_L, @handler_S, @handler_SL, |
178 |
@handler_MS, @handler_SMS, @handler_, @handler_S, @handler_MS, @handler_MS, |
|
179 |
@handler_MS, @handler_L, @handler_ML, @handler__i, @handler_SMS, @handler_SL, |
|
180 |
@handler_SL, @handler_MS, @handler_S); |
|
181 |
const net2cmd: array[0..30] 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, |
11423 | 183 |
cmd_SERVER_AUTH, cmd_RUN_GAME, cmd_ROUND_FINISHED, cmd_ROOMS, cmd_ROOM, |
184 |
cmd_PROTO, cmd_PING, cmd_NOTICE, cmd_NICK, cmd_LOBBY_LEFT, cmd_LOBBY_JOINED, |
|
185 |
cmd_LEFT, cmd_KICKED, cmd_JOINING, cmd_JOINED, cmd_INFO, cmd_HH_NUM, cmd_ERROR, |
|
186 |
cmd_EM, cmd_CONNECTED, cmd_CLIENT_FLAGS, cmd_CHAT, cmd_BYE, cmd_BANLIST, |
|
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
187 |
cmd_ASKPASSWORD); |
10929 | 188 |
|
189 |
||
11423 | 190 |
|
10929 | 191 |
// end of generated stuff |
10931 | 192 |
procedure handleTail; |
193 |
var cnt: Longint; |
|
194 |
c: char; |
|
195 |
begin |
|
196 |
c:= getCurrChar; |
|
197 |
repeat |
|
198 |
if c = #10 then cnt:= 0 else cnt:= 1; |
|
199 |
repeat |
|
200 |
c:= getNextChar; |
|
201 |
inc(cnt) |
|
202 |
until (c = #0) or (c = #10); |
|
203 |
until (c = #0) or (cnt = 1) |
|
204 |
end; |
|
205 |
||
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
206 |
var sock: PTCPSocket; |
10900 | 207 |
netReaderThread: PSDL_Thread; |
10931 | 208 |
|
209 |
function getCurrChar: char; |
|
210 |
begin |
|
211 |
getCurrChar:= state.buf[state.bufpos] |
|
212 |
end; |
|
10900 | 213 |
|
214 |
function getNextChar: char; |
|
215 |
var r: byte; |
|
216 |
begin |
|
10931 | 217 |
if state.bufpos < byte(state.buf[0]) then |
10900 | 218 |
begin |
10931 | 219 |
inc(state.bufpos); |
10900 | 220 |
end else |
221 |
begin |
|
10931 | 222 |
r:= SDLNet_TCP_Recv(sock, @state.buf[1], 255); |
10900 | 223 |
if r > 0 then |
224 |
begin |
|
10931 | 225 |
state.bufpos:= 1; |
226 |
state.buf[0]:= char(r); |
|
10900 | 227 |
end else |
228 |
begin |
|
10931 | 229 |
state.bufpos:= 0; |
230 |
state.buf[0]:= #0; |
|
10929 | 231 |
end |
10931 | 232 |
end; |
233 |
||
234 |
getNextChar:= state.buf[state.bufpos]; |
|
10900 | 235 |
end; |
10898 | 236 |
|
237 |
function netReader(data: pointer): LongInt; cdecl; export; |
|
10929 | 238 |
var c: char; |
10933 | 239 |
ipaddr: TIPAddress; |
10898 | 240 |
begin |
10933 | 241 |
netReader:= 0; |
242 |
||
243 |
if SDLNet_ResolveHost(ipaddr, PChar('netserver.hedgewars.org'), 46631) = 0 then |
|
244 |
sock:= SDLNet_TCP_Open(ipaddr); |
|
245 |
||
246 |
repeat |
|
247 |
c:= getNextChar; |
|
248 |
//writeln('>>>>> ', c, ' [', letters[state.l], '] ', commands[state.l]); |
|
249 |
if c = #0 then |
|
250 |
state.netState:= netDisconnected |
|
251 |
else |
|
252 |
begin |
|
253 |
while (letters[state.l] <> c) and (commands[state.l] > 0) do |
|
254 |
inc(state.l, commands[state.l]); |
|
255 |
||
256 |
if c = letters[state.l] then |
|
257 |
if commands[state.l] < 0 then |
|
10931 | 258 |
begin |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
259 |
state.cmd:= net2cmd[-10 - commands[state.l]]; |
10933 | 260 |
writeln('[NET] ', state.cmd); |
10931 | 261 |
handlers[-10 - commands[state.l]](); |
11425 | 262 |
state.l:= 0 |
10931 | 263 |
end |
10933 | 264 |
else |
265 |
inc(state.l) |
|
10931 | 266 |
else |
10933 | 267 |
begin |
11424 | 268 |
handler__UNKNOWN_() |
10933 | 269 |
end |
10931 | 270 |
end |
10933 | 271 |
until state.netState = netDisconnected; |
10931 | 272 |
|
11420 | 273 |
SDLNet_TCP_Close(sock); |
10933 | 274 |
sock:= nil; |
275 |
||
276 |
writeln('[NET] netReader: disconnected'); |
|
10931 | 277 |
end; |
278 |
||
279 |
procedure sendNet(s: shortstring); |
|
280 |
begin |
|
281 |
writeln('[NET] Send: ', s); |
|
10935 | 282 |
ipcToNet(s + endCmd); |
283 |
end; |
|
284 |
||
11420 | 285 |
procedure sendNetLn(s: shortstring); |
286 |
begin |
|
287 |
writeln('[NET] Send: ', s); |
|
288 |
ipcToNet(s + #10); |
|
289 |
end; |
|
290 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
291 |
function getShortString: shortstring; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
292 |
var s: shortstring; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
293 |
c: char; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
294 |
begin |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
295 |
s[0]:= #0; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
296 |
|
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
297 |
repeat |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
298 |
inc(s[0]); |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
299 |
s[byte(s[0])]:= getNextChar |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
300 |
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
|
301 |
|
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
302 |
if s[byte(s[0])] = #10 then |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
303 |
dec(s[0]) |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
304 |
else |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
305 |
repeat c:= getNextChar until (c = #0) or (c = #10); |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
306 |
|
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
307 |
getShortString:= s |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
308 |
end; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
309 |
|
10935 | 310 |
procedure netSendCallback(p: pointer; msg: PChar; len: Longword); |
311 |
begin |
|
312 |
// W A R N I N G: totally thread-unsafe due to use of sock variable |
|
313 |
SDLNet_TCP_Send(sock, msg, len); |
|
10898 | 314 |
end; |
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
315 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
316 |
procedure connectOfficialServer; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
317 |
begin |
10898 | 318 |
if sock <> nil then |
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
319 |
exit; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
320 |
|
10931 | 321 |
state.bufpos:= 0; |
322 |
state.buf:= ''; |
|
323 |
||
324 |
state.l:= 0; |
|
325 |
state.netState:= netConnecting; |
|
326 |
||
11408 | 327 |
netReaderThread:= SDL_CreateThread(@netReader, 'netReader', nil); |
11420 | 328 |
SDL_DetachThread(netReaderThread) |
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
329 |
end; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
330 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
331 |
procedure initModule; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
332 |
begin |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
333 |
sock:= nil; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
334 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
335 |
SDLNet_Init; |
10935 | 336 |
|
337 |
registerNetCallback(nil, @netSendCallback); |
|
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
338 |
end; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
339 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
340 |
procedure freeModule; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
341 |
begin |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
342 |
end; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
343 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
344 |
end. |