author | unc0rr |
Sat, 21 Nov 2015 09:56:00 +0300 | |
branch | qmlfrontend |
changeset 11425 | ef7f8ac96dfa |
parent 11424 | 8a5cc31483c6 |
child 11426 | 25e0f427f57e |
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 |
10931 | 20 |
TNetState = (netDisconnected, netConnecting, netLoggedIn); |
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, |
|
11425 | 56 |
-21, 28, 19, 5, 3, 1, -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 |
writeln('handler_'); |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
65 |
handleTail() |
10929 | 66 |
end; |
67 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
68 |
procedure handler_L; |
10929 | 69 |
begin |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
70 |
writeln('handler_L'); |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
71 |
handleTail() |
10929 | 72 |
end; |
73 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
74 |
procedure handler_ML; |
10929 | 75 |
begin |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
76 |
writeln('handler_ML'); |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
77 |
handleTail() |
10929 | 78 |
end; |
79 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
80 |
procedure handler_MS; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
81 |
var cmd: TCmdParamS; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
82 |
f: boolean; |
10929 | 83 |
begin |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
84 |
sendUI(mtNetData, @state.cmd, sizeof(state.cmd)); |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
85 |
cmd.cmd:= Succ(state.cmd); |
10929 | 86 |
|
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
87 |
repeat |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
88 |
cmd.str1:= getShortString; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
89 |
f:= cmd.str1[0] <> #0; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
90 |
if f then |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
91 |
sendUI(mtNetData, @cmd, sizeof(cmd)); |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
92 |
until not f |
10929 | 93 |
end; |
94 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
95 |
procedure handler_S; |
10929 | 96 |
begin |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
97 |
writeln('handler_S'); |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
98 |
handleTail() |
10929 | 99 |
end; |
100 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
101 |
procedure handler_SL; |
11420 | 102 |
var cmd: TCmdParamSL; |
10929 | 103 |
begin |
11420 | 104 |
cmd.cmd:= state.cmd; |
105 |
cmd.str1:= getShortString; |
|
11425 | 106 |
if cmd.str1[0] = #0 then exit; |
11420 | 107 |
cmd.str2:= getShortString; // FIXME should be long string |
11425 | 108 |
if cmd.str2[0] = #0 then exit; |
11420 | 109 |
sendUI(mtNetData, @cmd, sizeof(cmd)); |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
110 |
handleTail() |
10929 | 111 |
end; |
112 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
113 |
procedure handler_SMS; |
10929 | 114 |
begin |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
115 |
writeln('handler_SMS'); |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
116 |
handleTail() |
10929 | 117 |
end; |
118 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
119 |
procedure handler__i; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
120 |
var cmd: TCmdParami; |
11425 | 121 |
s: shortstring; |
10929 | 122 |
begin |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
123 |
writeln('handler__i'); |
11425 | 124 |
s:= getShortString(); |
125 |
if s[0] = #0 then exit; |
|
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
126 |
cmd.cmd:= state.cmd; |
11425 | 127 |
s:= getShortString(); |
128 |
if s[0] = #0 then exit; |
|
129 |
cmd.param1:= strToInt(s); |
|
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
130 |
sendUI(mtNetData, @cmd, sizeof(cmd)); |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
131 |
handleTail() |
10929 | 132 |
end; |
133 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
134 |
procedure handler_i; |
10929 | 135 |
begin |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
136 |
writeln('handler_i'); |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
137 |
handleTail() |
10929 | 138 |
end; |
139 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
140 |
procedure handler__UNKNOWN_; |
10929 | 141 |
begin |
10931 | 142 |
writeln('[NET] Unknown cmd'); |
11424 | 143 |
handleTail() |
10929 | 144 |
end; |
145 |
||
11423 | 146 |
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
|
147 |
@handler_SL, @handler_L, @handler_S, @handler_, @handler_, @handler_MS, |
11423 | 148 |
@handler_MS, @handler_i, @handler_MS, @handler_L, @handler_S, @handler_SL, |
149 |
@handler_MS, @handler_SMS, @handler_, @handler_S, @handler_MS, @handler_MS, |
|
150 |
@handler_MS, @handler_L, @handler_ML, @handler__i, @handler_SMS, @handler_SL, |
|
151 |
@handler_SL, @handler_MS, @handler_S); |
|
152 |
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
|
153 |
cmd_TEAM_COLOR, cmd_TEAM_ACCEPTED, cmd_SERVER_VARS, cmd_SERVER_MESSAGE, |
11423 | 154 |
cmd_SERVER_AUTH, cmd_RUN_GAME, cmd_ROUND_FINISHED, cmd_ROOMS, cmd_ROOM, |
155 |
cmd_PROTO, cmd_PING, cmd_NOTICE, cmd_NICK, cmd_LOBBY_LEFT, cmd_LOBBY_JOINED, |
|
156 |
cmd_LEFT, cmd_KICKED, cmd_JOINING, cmd_JOINED, cmd_INFO, cmd_HH_NUM, cmd_ERROR, |
|
157 |
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
|
158 |
cmd_ASKPASSWORD); |
10929 | 159 |
|
160 |
||
11423 | 161 |
|
10929 | 162 |
// end of generated stuff |
10931 | 163 |
procedure handleTail; |
164 |
var cnt: Longint; |
|
165 |
c: char; |
|
166 |
begin |
|
167 |
c:= getCurrChar; |
|
168 |
repeat |
|
169 |
if c = #10 then cnt:= 0 else cnt:= 1; |
|
170 |
repeat |
|
171 |
c:= getNextChar; |
|
172 |
inc(cnt) |
|
173 |
until (c = #0) or (c = #10); |
|
174 |
until (c = #0) or (cnt = 1) |
|
175 |
end; |
|
176 |
||
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
177 |
var sock: PTCPSocket; |
10900 | 178 |
netReaderThread: PSDL_Thread; |
10931 | 179 |
|
180 |
function getCurrChar: char; |
|
181 |
begin |
|
182 |
getCurrChar:= state.buf[state.bufpos] |
|
183 |
end; |
|
10900 | 184 |
|
185 |
function getNextChar: char; |
|
186 |
var r: byte; |
|
187 |
begin |
|
10931 | 188 |
if state.bufpos < byte(state.buf[0]) then |
10900 | 189 |
begin |
10931 | 190 |
inc(state.bufpos); |
10900 | 191 |
end else |
192 |
begin |
|
10931 | 193 |
r:= SDLNet_TCP_Recv(sock, @state.buf[1], 255); |
10900 | 194 |
if r > 0 then |
195 |
begin |
|
10931 | 196 |
state.bufpos:= 1; |
197 |
state.buf[0]:= char(r); |
|
10900 | 198 |
end else |
199 |
begin |
|
10931 | 200 |
state.bufpos:= 0; |
201 |
state.buf[0]:= #0; |
|
10929 | 202 |
end |
10931 | 203 |
end; |
204 |
||
205 |
getNextChar:= state.buf[state.bufpos]; |
|
10900 | 206 |
end; |
10898 | 207 |
|
208 |
function netReader(data: pointer): LongInt; cdecl; export; |
|
10929 | 209 |
var c: char; |
10933 | 210 |
ipaddr: TIPAddress; |
10898 | 211 |
begin |
10933 | 212 |
netReader:= 0; |
213 |
||
214 |
if SDLNet_ResolveHost(ipaddr, PChar('netserver.hedgewars.org'), 46631) = 0 then |
|
215 |
sock:= SDLNet_TCP_Open(ipaddr); |
|
216 |
||
217 |
repeat |
|
218 |
c:= getNextChar; |
|
219 |
//writeln('>>>>> ', c, ' [', letters[state.l], '] ', commands[state.l]); |
|
220 |
if c = #0 then |
|
221 |
state.netState:= netDisconnected |
|
222 |
else |
|
223 |
begin |
|
224 |
while (letters[state.l] <> c) and (commands[state.l] > 0) do |
|
225 |
inc(state.l, commands[state.l]); |
|
226 |
||
227 |
if c = letters[state.l] then |
|
228 |
if commands[state.l] < 0 then |
|
10931 | 229 |
begin |
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
230 |
state.cmd:= net2cmd[-10 - commands[state.l]]; |
10933 | 231 |
writeln('[NET] ', state.cmd); |
10931 | 232 |
handlers[-10 - commands[state.l]](); |
11425 | 233 |
state.l:= 0 |
10931 | 234 |
end |
10933 | 235 |
else |
236 |
inc(state.l) |
|
10931 | 237 |
else |
10933 | 238 |
begin |
11424 | 239 |
handler__UNKNOWN_() |
10933 | 240 |
end |
10931 | 241 |
end |
10933 | 242 |
until state.netState = netDisconnected; |
10931 | 243 |
|
11420 | 244 |
SDLNet_TCP_Close(sock); |
10933 | 245 |
sock:= nil; |
246 |
||
247 |
writeln('[NET] netReader: disconnected'); |
|
10931 | 248 |
end; |
249 |
||
250 |
procedure sendNet(s: shortstring); |
|
251 |
begin |
|
252 |
writeln('[NET] Send: ', s); |
|
10935 | 253 |
ipcToNet(s + endCmd); |
254 |
end; |
|
255 |
||
11420 | 256 |
procedure sendNetLn(s: shortstring); |
257 |
begin |
|
258 |
writeln('[NET] Send: ', s); |
|
259 |
ipcToNet(s + #10); |
|
260 |
end; |
|
261 |
||
11418
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
262 |
function getShortString: shortstring; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
263 |
var s: shortstring; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
264 |
c: char; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
265 |
begin |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
266 |
s[0]:= #0; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
267 |
|
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
268 |
repeat |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
269 |
inc(s[0]); |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
270 |
s[byte(s[0])]:= getNextChar |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
271 |
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
|
272 |
|
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
273 |
if s[byte(s[0])] = #10 then |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
274 |
dec(s[0]) |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
275 |
else |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
276 |
repeat c:= getNextChar until (c = #0) or (c = #10); |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
277 |
|
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
278 |
getShortString:= s |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
279 |
end; |
ffff8a0d1a76
Implement processing net commands in the main thread
unc0rr
parents:
11408
diff
changeset
|
280 |
|
10935 | 281 |
procedure netSendCallback(p: pointer; msg: PChar; len: Longword); |
282 |
begin |
|
283 |
// W A R N I N G: totally thread-unsafe due to use of sock variable |
|
284 |
SDLNet_TCP_Send(sock, msg, len); |
|
10898 | 285 |
end; |
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
286 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
287 |
procedure connectOfficialServer; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
288 |
begin |
10898 | 289 |
if sock <> nil then |
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
290 |
exit; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
291 |
|
10931 | 292 |
state.bufpos:= 0; |
293 |
state.buf:= ''; |
|
294 |
||
295 |
state.l:= 0; |
|
296 |
state.netState:= netConnecting; |
|
297 |
||
11408 | 298 |
netReaderThread:= SDL_CreateThread(@netReader, 'netReader', nil); |
11420 | 299 |
SDL_DetachThread(netReaderThread) |
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
300 |
end; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
301 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
302 |
procedure initModule; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
303 |
begin |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
304 |
sock:= nil; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
305 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
306 |
SDLNet_Init; |
10935 | 307 |
|
308 |
registerNetCallback(nil, @netSendCallback); |
|
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
309 |
end; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
310 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
311 |
procedure freeModule; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
312 |
begin |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
313 |
end; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
314 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
315 |
end. |