author | unc0rr |
Mon, 11 May 2015 00:27:16 +0300 | |
branch | qmlfrontend |
changeset 10927 | 336f5ad638be |
parent 10900 | 6a805e822074 |
child 10929 | 8ebf01f75d9f |
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; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
8 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
9 |
implementation |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
10 |
uses SDLh; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
11 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
12 |
var sock: PTCPSocket; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
13 |
fds: PSDLNet_SocketSet; |
10900 | 14 |
netReaderThread: PSDL_Thread; |
15 |
sockbuf: shortstring; |
|
16 |
sockbufpos: byte; |
|
17 |
||
18 |
function getNextChar: char; |
|
19 |
var r: byte; |
|
20 |
begin |
|
21 |
if sockbufpos < byte(sockbuf[0]) then |
|
22 |
begin |
|
23 |
inc(sockbufpos); |
|
24 |
getNextChar:= sockbuf[sockbufpos]; |
|
25 |
end else |
|
26 |
begin |
|
27 |
r:= SDLNet_TCP_Recv(sock, @sockbuf[1], 255); |
|
28 |
if r > 0 then |
|
29 |
begin |
|
30 |
sockbufpos:= 1; |
|
31 |
sockbuf[0]:= char(i); |
|
32 |
getNextChar:= sockbuf[1]; |
|
33 |
end else |
|
34 |
begin |
|
35 |
sockbufpos:= 0; |
|
36 |
sockbuf[0]:= #0; |
|
37 |
getNextChar:= #0 |
|
38 |
end; |
|
39 |
end; |
|
10898 | 40 |
|
41 |
function netReader(data: pointer): LongInt; cdecl; export; |
|
42 |
begin |
|
43 |
end; |
|
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
44 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
45 |
procedure connectOfficialServer; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
46 |
var ipaddr: TIPAddress; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
47 |
begin |
10898 | 48 |
if sock <> nil then |
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
49 |
exit; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
50 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
51 |
if SDLNet_ResolveHost(ipaddr, PChar('netserver.hedgewars.org'), 46631) = 0 then |
10898 | 52 |
sock:= SDLNet_TCP_Open(ipaddr); |
53 |
||
10900 | 54 |
sockbufpos:= 0; |
55 |
sockbuf:= ''; |
|
56 |
netReaderThread:= SDL_CreateThread(@netReader{$IFDEF SDL2}, 'netReader'{$ENDIF}, nil); |
|
10896
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
57 |
end; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
58 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
59 |
procedure initModule; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
60 |
begin |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
61 |
sock:= nil; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
62 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
63 |
SDLNet_Init; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
64 |
fds:= SDLNet_AllocSocketSet(1); |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
65 |
end; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
66 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
67 |
procedure freeModule; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
68 |
begin |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
69 |
end; |
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
70 |
|
5a74923120d5
Start network support: only setting up a connection for now
unc0rr
parents:
diff
changeset
|
71 |
end. |