branch | qmlfrontend |
changeset 11444 | 91f8c6ff5bab |
parent 11442 | 6b04a266feee |
child 11446 | 321d0ce43568 |
11443:5182d44fb733 | 11444:91f8c6ff5bab |
---|---|
6 procedure initModule; |
6 procedure initModule; |
7 procedure freeModule; |
7 procedure freeModule; |
8 procedure sendNet(s: shortstring); |
8 procedure sendNet(s: shortstring); |
9 procedure sendNetLn(s: shortstring); |
9 procedure sendNetLn(s: shortstring); |
10 |
10 |
11 var isConnected: boolean = false; |
|
12 |
|
11 implementation |
13 implementation |
12 uses SDLh, uFLIPC, uFLTypes, uFLUICallback, uFLNetTypes, uFLUtils; |
14 uses SDLh, uFLIPC, uFLTypes, uFLUICallback, uFLNetTypes, uFLUtils; |
13 |
15 |
14 const endCmd: shortstring = #10 + #10; |
16 const endCmd: shortstring = #10 + #10; |
15 |
17 |
16 function getNextChar: char; forward; |
18 function getNextChar: char; forward; |
17 function getCurrChar: char; forward; |
19 function getCurrChar: char; forward; |
18 |
20 |
19 type |
21 type |
20 TNetState = (netDisconnected, netConnecting); |
|
21 TParserState = record |
22 TParserState = record |
22 cmd: TCmdType; |
23 cmd: TCmdType; |
23 l: LongInt; |
24 l: LongInt; |
24 netState: TNetState; |
|
25 buf: shortstring; |
25 buf: shortstring; |
26 bufpos: byte; |
26 bufpos: byte; |
27 end; |
27 end; |
28 PHandler = procedure; |
28 PHandler = procedure; |
29 |
29 |
282 |
282 |
283 repeat |
283 repeat |
284 c:= getNextChar; |
284 c:= getNextChar; |
285 //writeln('>>>>> ', c, ' [', letters[state.l], '] ', commands[state.l], ' ', state.l); |
285 //writeln('>>>>> ', c, ' [', letters[state.l], '] ', commands[state.l], ' ', state.l); |
286 if c = #0 then |
286 if c = #0 then |
287 state.netState:= netDisconnected |
287 isConnected:= false |
288 else |
288 else |
289 begin |
289 begin |
290 while (letters[state.l] <> c) and (commands[state.l] > 0) do |
290 while (letters[state.l] <> c) and (commands[state.l] > 0) do |
291 inc(state.l, commands[state.l]); |
291 inc(state.l, commands[state.l]); |
292 |
292 |
303 else |
303 else |
304 begin |
304 begin |
305 handler__UNKNOWN_() |
305 handler__UNKNOWN_() |
306 end |
306 end |
307 end |
307 end |
308 until state.netState = netDisconnected; |
308 until not isConnected; |
309 |
309 |
310 SDLNet_TCP_Close(sock); |
310 SDLNet_TCP_Close(sock); |
311 sock:= nil; |
311 sock:= nil; |
312 |
312 |
313 writeln('[NET] netReader: disconnected'); |
313 writeln('[NET] netReader: disconnected'); |
381 |
381 |
382 state.bufpos:= 0; |
382 state.bufpos:= 0; |
383 state.buf:= ''; |
383 state.buf:= ''; |
384 |
384 |
385 state.l:= 0; |
385 state.l:= 0; |
386 state.netState:= netConnecting; |
386 isConnected:= true; |
387 |
387 |
388 netReaderThread:= SDL_CreateThread(@netReader, 'netReader', nil); |
388 netReaderThread:= SDL_CreateThread(@netReader, 'netReader', nil); |
389 SDL_DetachThread(netReaderThread) |
389 SDL_DetachThread(netReaderThread) |
390 end; |
390 end; |
391 |
391 |
392 procedure initModule; |
392 procedure initModule; |
393 begin |
393 begin |
394 sock:= nil; |
394 sock:= nil; |
395 isConnected:= false; |
|
395 |
396 |
396 SDLNet_Init; |
397 SDLNet_Init; |
397 |
398 |
398 registerNetCallback(nil, @netSendCallback); |
399 registerNetCallback(nil, @netSendCallback); |
399 end; |
400 end; |