1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
41 Players
, MaxPlayers
, LocalPl
, Bots
: Byte;
45 PingAddr
: ENetAddress
;
47 pTNetServer
= ^TNetServer
;
48 TNetServerRow
= record
49 Indices
: Array of Integer;
53 TNetServerList
= array of TNetServer
;
54 pTNetServerList
= ^TNetServerList
;
55 TNetServerTable
= array of TNetServerRow
;
58 NetMHost
: pENetHost
= nil;
59 NetMPeer
: pENetPeer
= nil;
61 slCurrent
: TNetServerList
= nil;
62 slTable
: TNetServerTable
= nil;
63 slWaitStr
: string = '';
64 slReturnPressed
: Boolean = True;
67 slUrgent
: string = '';
69 procedure g_Net_Slist_Set(IP
: string; Port
: Word);
70 function g_Net_Slist_Fetch(var SL
: TNetServerList
): Boolean;
71 procedure g_Net_Slist_Update();
72 procedure g_Net_Slist_Remove();
73 function g_Net_Slist_Connect(): Boolean;
74 procedure g_Net_Slist_Check();
75 procedure g_Net_Slist_Disconnect();
76 procedure g_Net_Slist_WriteInfo();
78 procedure g_Serverlist_GenerateTable(SL
: TNetServerList
; var ST
: TNetServerTable
);
79 procedure g_Serverlist_Draw(var SL
: TNetServerList
; var ST
: TNetServerTable
);
80 procedure g_Serverlist_Control(var SL
: TNetServerList
; var ST
: TNetServerTable
);
85 SysUtils
, e_msg
, e_input
, e_graphics
, e_log
, g_window
, g_net
, g_console
,
86 g_map
, g_game
, g_sound
, g_gui
, g_menu
, g_options
, g_language
, g_basic
,
91 slSelection
: Byte = 0;
92 slFetched
: Boolean = False;
93 slDirPressed
: Boolean = False;
94 slReadUrgent
: Boolean = False;
96 function GetTimerMS(): Int64;
98 Result
:= GetTimer() {div 1000};
101 procedure PingServer(var S
: TNetServer
; Sock
: ENetSocket
);
104 Ping
: array [0..9] of Byte;
107 ClTime
:= GetTimerMS();
109 Buf
.data
:= Addr(Ping
[0]);
110 Buf
.dataLength
:= 2+8;
114 Int64(Addr(Ping
[2])^) := ClTime
;
116 enet_socket_send(Sock
, Addr(S
.PingAddr
), @Buf
, 1);
119 procedure PingBcast(Sock
: ENetSocket
);
123 S
.IP
:= '255.255.255.255';
124 S
.Port
:= NET_PING_PORT
;
125 enet_address_set_host(Addr(S
.PingAddr
), PChar(Addr(S
.IP
[1])));
127 S
.PingAddr
.port
:= S
.Port
;
131 function g_Net_Slist_Fetch(var SL
: TNetServerList
): Boolean;
145 procedure ProcessLocal();
148 SetLength(SL
, I
+ 1);
151 IP
:= DecodeIPV4(SvAddr
.host
);
152 Port
:= InMsg
.ReadWord();
153 Ping
:= InMsg
.ReadInt64();
154 Ping
:= GetTimerMS() - Ping
;
155 Name
:= InMsg
.ReadString();
156 Map
:= InMsg
.ReadString();
157 GameMode
:= InMsg
.ReadByte();
158 Players
:= InMsg
.ReadByte();
159 MaxPlayers
:= InMsg
.ReadByte();
160 Protocol
:= InMsg
.ReadByte();
161 Password
:= InMsg
.ReadByte() = 1;
162 LocalPl
:= InMsg
.ReadByte();
163 Bots
:= InMsg
.ReadWord();
166 procedure CheckLocalServers();
170 Sock
:= enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM
);
171 if Sock
= ENET_SOCKET_NULL
then Exit
;
172 enet_socket_set_option(Sock
, ENET_SOCKOPT_NONBLOCK
, 1);
173 enet_socket_set_option(Sock
, ENET_SOCKOPT_BROADCAST
, 1);
178 InMsg
.Alloc(NET_BUFSIZE
);
179 Buf
.data
:= InMsg
.Data
;
180 Buf
.dataLength
:= InMsg
.MaxSize
;
181 while GetTimerMS() - T
<= 500 do
185 RX
:= enet_socket_receive(Sock
, @SvAddr
, @Buf
, 1);
186 if RX
<= 0 then continue
;
189 InMsg
.BeginReading();
191 if InMsg
.ReadChar() <> 'D' then continue
;
192 if InMsg
.ReadChar() <> 'F' then continue
;
198 enet_socket_destroy(Sock
);
200 if Length(SL
) = 0 then SL
:= nil;
206 if (NetMHost
<> nil) or (NetMPeer
<> nil) then
212 if not g_Net_Slist_Connect
then
218 e_WriteLog('Fetching serverlist...', TMsgType
.Notify
);
219 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_SLIST_FETCH
]);
222 NetOut
.Write(Byte(NET_MMSG_GET
));
224 // TODO: what should we identify the build with?
225 MyVer
:= GAME_VERSION
;
228 P
:= enet_packet_create(NetOut
.Data
, NetOut
.CurSize
, Cardinal(ENET_PACKET_FLAG_RELIABLE
));
229 enet_peer_send(NetMPeer
, NET_MCHAN_MAIN
, P
);
230 enet_host_flush(NetMHost
);
232 while enet_host_service(NetMHost
, @NetMEvent
, 5000) > 0 do
234 if NetMEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
then
236 if not InMsg
.Init(NetMEvent
.packet
^.data
, NetMEvent
.packet
^.dataLength
, True) then continue
;
238 MID
:= InMsg
.ReadByte();
240 if MID
<> NET_MMSG_GET
then continue
;
242 Cnt
:= InMsg
.ReadByte();
243 g_Console_Add(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_SLIST_RETRIEVED
], [Cnt
]), True);
249 for I
:= 0 to Cnt
- 1 do
252 SL
[I
].IP
:= InMsg
.ReadString();
253 SL
[I
].Port
:= InMsg
.ReadWord();
254 SL
[I
].Name
:= InMsg
.ReadString();
255 SL
[I
].Map
:= InMsg
.ReadString();
256 SL
[I
].GameMode
:= InMsg
.ReadByte();
257 SL
[I
].Players
:= InMsg
.ReadByte();
258 SL
[I
].MaxPlayers
:= InMsg
.ReadByte();
259 SL
[I
].Protocol
:= InMsg
.ReadByte();
260 SL
[I
].Password
:= InMsg
.ReadByte() = 1;
261 enet_address_set_host(Addr(SL
[I
].PingAddr
), PChar(Addr(SL
[I
].IP
[1])));
263 SL
[I
].PingAddr
.port
:= NET_PING_PORT
;
267 if InMsg
.ReadCount
< InMsg
.CurSize
then
269 // new master, supports version reports
270 Str
:= InMsg
.ReadString();
271 if (Str
<> MyVer
) then
274 g_Console_Add('!!! UpdVer = `' + Str
+ '`');
276 // even newer master, supports extra info
277 if InMsg
.ReadCount
< InMsg
.CurSize
then
279 slMOTD
:= b_Text_Format(InMsg
.ReadString());
280 Str
:= b_Text_Format(InMsg
.ReadString());
281 // check if the message has updated and the user has to read it again
282 if slUrgent
<> Str
then slReadUrgent
:= False;
292 g_Net_Slist_Disconnect
;
295 if Length(SL
) = 0 then
301 Sock
:= enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM
);
302 if Sock
= ENET_SOCKET_NULL
then Exit
;
303 enet_socket_set_option(Sock
, ENET_SOCKOPT_NONBLOCK
, 1);
305 for I
:= Low(SL
) to High(SL
) do
306 PingServer(SL
[I
], Sock
);
308 enet_socket_set_option(Sock
, ENET_SOCKOPT_BROADCAST
, 1);
313 InMsg
.Alloc(NET_BUFSIZE
);
314 Buf
.data
:= InMsg
.Data
;
315 Buf
.dataLength
:= InMsg
.MaxSize
;
317 while GetTimerMS() - T
<= 500 do
321 RX
:= enet_socket_receive(Sock
, @SvAddr
, @Buf
, 1);
322 if RX
<= 0 then continue
;
325 InMsg
.BeginReading();
327 if InMsg
.ReadChar() <> 'D' then continue
;
328 if InMsg
.ReadChar() <> 'F' then continue
;
331 for I
:= Low(SL
) to High(SL
) do
332 if (SL
[I
].PingAddr
.host
= SvAddr
.host
) and
333 (SL
[I
].PingAddr
.port
= SvAddr
.port
) then
337 Port
:= InMsg
.ReadWord();
338 Ping
:= InMsg
.ReadInt64();
339 Ping
:= GetTimerMS() - Ping
;
340 Name
:= InMsg
.ReadString();
341 Map
:= InMsg
.ReadString();
342 GameMode
:= InMsg
.ReadByte();
343 Players
:= InMsg
.ReadByte();
344 MaxPlayers
:= InMsg
.ReadByte();
345 Protocol
:= InMsg
.ReadByte();
346 Password
:= InMsg
.ReadByte() = 1;
347 LocalPl
:= InMsg
.ReadByte();
348 Bots
:= InMsg
.ReadWord();
359 enet_socket_destroy(Sock
);
362 procedure g_Net_Slist_WriteInfo();
367 Wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
368 Map
:= g_ExtractFileName(gMapInfo
.Map
);
370 NetOut
.Write(NetServerName
);
372 NetOut
.Write(Wad
+ ':\' + Map
);
373 NetOut
.Write(gGameSettings
.GameMode
);
375 Cli
:= NetClientCount
;
378 NetOut
.Write(NetMaxClients
);
380 NetOut
.Write(Byte(NET_PROTOCOL_VER
));
381 NetOut
.Write(Byte(NetPassword
<> ''));
384 procedure g_Net_Slist_Update
;
390 if (NetMHost
= nil) or (NetMPeer
= nil) then Exit
;
393 NetOut
.Write(Byte(NET_MMSG_UPD
));
394 NetOut
.Write(NetAddr
.port
);
396 g_Net_Slist_WriteInfo();
398 P
:= enet_packet_create(NetOut
.Data
, NetOut
.CurSize
, Cardinal(ENET_PACKET_FLAG_RELIABLE
));
399 enet_peer_send(NetMPeer
, NET_MCHAN_UPD
, P
);
401 enet_host_flush(NetMHost
);
405 procedure g_Net_Slist_Remove
;
409 if (NetMHost
= nil) or (NetMPeer
= nil) then Exit
;
411 NetOut
.Write(Byte(NET_MMSG_DEL
));
412 NetOut
.Write(NetAddr
.port
);
414 P
:= enet_packet_create(NetOut
.Data
, NetOut
.CurSize
, Cardinal(ENET_PACKET_FLAG_RELIABLE
));
415 enet_peer_send(NetMPeer
, NET_MCHAN_MAIN
, P
);
417 enet_host_flush(NetMHost
);
421 function g_Net_Slist_Connect
: Boolean;
425 NetMHost
:= enet_host_create(nil, 1, NET_MCHANS
, 0, 0);
426 if (NetMHost
= nil) then
428 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CLIENT
], True);
432 NetMPeer
:= enet_host_connect(NetMHost
, @NetSlistAddr
, NET_MCHANS
, 0);
433 if (NetMPeer
= nil) then
435 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CLIENT
], True);
436 enet_host_destroy(NetMHost
);
441 if (enet_host_service(NetMHost
, @NetMEvent
, 3000) > 0) then
442 if NetMEvent
.kind
= ENET_EVENT_TYPE_CONNECT
then
445 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_SLIST_CONN
]);
449 if NetMEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
then
450 enet_packet_destroy(NetMEvent
.packet
);
452 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
], True);
458 procedure g_Net_Slist_Disconnect
;
460 if (NetMHost
= nil) and (NetMPeer
= nil) then Exit
;
462 if NetMode
= NET_SERVER
then g_Net_Slist_Remove
;
464 enet_peer_disconnect(NetMPeer
, 0);
465 enet_host_flush(NetMHost
);
467 enet_peer_reset(NetMPeer
);
468 enet_host_destroy(NetMHost
);
473 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_SLIST_DISC
]);
476 procedure g_Net_Slist_Check
;
478 if (NetMHost
= nil) or (NetMPeer
= nil) then Exit
;
480 while (enet_host_service(NetMHost
, @NetMEvent
, 0) > 0) do
482 if NetMEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
then
484 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_SLIST_LOST
], True);
485 if NetMPeer
<> nil then enet_peer_reset(NetMPeer
);
486 if NetMHost
<> nil then enet_host_destroy(NetMHost
);
492 if NetMEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
then
493 enet_packet_destroy(NetMEvent
.packet
);
497 procedure g_Net_Slist_Set(IP
: string; Port
: Word);
501 enet_address_set_host(@NetSlistAddr
, PChar(Addr(IP
[1])));
502 NetSlistAddr
.Port
:= Port
;
503 e_WriteLog('Masterserver address set to ' + IP
+ ':' + IntToStr(Port
), TMsgType
.Notify
);
507 function GetServerFromTable(Index
: Integer; SL
: TNetServerList
; ST
: TNetServerTable
): TNetServer
;
510 Result
.Protocol
:= 0;
516 Result
.MaxPlayers
:= 0;
520 Result
.GameMode
:= 0;
521 Result
.Password
:= false;
522 FillChar(Result
.PingAddr
, SizeOf(ENetAddress
), 0);
525 if (Index
< 0) or (Index
>= Length(ST
)) then
527 Result
:= SL
[ST
[Index
].Indices
[ST
[Index
].Current
]];
530 procedure g_Serverlist_Draw(var SL
: TNetServerList
; var ST
: TNetServerTable
);
533 sy
, i
, y
, mw
, mx
, l
: Integer;
543 e_CharFont_GetSize(gMenuFont
, _lc
[I_NET_SLIST
], ww
, hh
);
544 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2) - (ww
div 2), 16, _lc
[I_NET_SLIST
]);
546 e_TextureFontGetSize(gStdFont
, cw
, ch
);
548 ip
:= _lc
[I_NET_SLIST_HELP
];
549 mw
:= (Length(ip
) * cw
) div 2;
551 e_DrawFillQuad(16, 64, gScreenWidth
-16, gScreenHeight
-84, 64, 64, 64, 110);
552 e_DrawQuad(16, 64, gScreenWidth
-16, gScreenHeight
-84, 255, 127, 0);
554 e_TextureFontPrintEx(gScreenWidth
div 2 - mw
, gScreenHeight
-24, ip
, gStdFont
, 225, 225, 225, 1);
559 e_DrawFillQuad(16, gScreenHeight
-84, gScreenWidth
-16, gScreenHeight
-44, 64, 64, 64, 110);
560 e_DrawQuad(16, gScreenHeight
-84, gScreenWidth
-16, gScreenHeight
-44, 255, 127, 0);
561 e_TextureFontPrintFmt(20, gScreenHeight
-81, slMOTD
, gStdFont
, False, True);
565 if not slReadUrgent
and (slUrgent
<> '') then
567 e_DrawFillQuad(17, 65, gScreenWidth
-17, gScreenHeight
-85, 64, 64, 64, 128);
568 e_DrawFillQuad(gScreenWidth
div 2 - 256, gScreenHeight
div 2 - 60,
569 gScreenWidth
div 2 + 256, gScreenHeight
div 2 + 60, 64, 64, 64, 128);
570 e_DrawQuad(gScreenWidth
div 2 - 256, gScreenHeight
div 2 - 60,
571 gScreenWidth
div 2 + 256, gScreenHeight
div 2 + 60, 255, 127, 0);
572 e_DrawLine(1, gScreenWidth
div 2 - 256, gScreenHeight
div 2 - 40,
573 gScreenWidth
div 2 + 256, gScreenHeight
div 2 - 40, 255, 127, 0);
574 l
:= Length(_lc
[I_NET_SLIST_URGENT
]) div 2;
575 e_TextureFontPrint(gScreenWidth
div 2 - cw
* l
, gScreenHeight
div 2 - 58,
576 _lc
[I_NET_SLIST_URGENT
], gStdFont
);
577 l
:= Length(slUrgent
) div 2;
578 e_TextureFontPrintFmt(gScreenWidth
div 2 - 253, gScreenHeight
div 2 - 38,
579 slUrgent
, gStdFont
, False, True);
580 l
:= Length(_lc
[I_NET_SLIST_URGENT_CONT
]) div 2;
581 e_TextureFontPrint(gScreenWidth
div 2 - cw
* l
, gScreenHeight
div 2 + 41,
582 _lc
[I_NET_SLIST_URGENT_CONT
], gStdFont
);
583 e_DrawLine(1, gScreenWidth
div 2 - 256, gScreenHeight
div 2 + 40,
584 gScreenWidth
div 2 + 256, gScreenHeight
div 2 + 40, 255, 127, 0);
590 l
:= Length(slWaitStr
) div 2;
591 e_DrawFillQuad(17, 65, gScreenWidth
-17, gScreenHeight
-85, 64, 64, 64, 128);
592 e_DrawQuad(gScreenWidth
div 2 - 192, gScreenHeight
div 2 - 10,
593 gScreenWidth
div 2 + 192, gScreenHeight
div 2 + 11, 255, 127, 0);
594 e_TextureFontPrint(gScreenWidth
div 2 - cw
* l
, gScreenHeight
div 2 - ch
div 2,
595 slWaitStr
, gStdFont
);
600 if (slSelection
< Length(ST
)) then
603 sy
:= y
+ 42 * I
- 4;
604 Srv
:= GetServerFromTable(I
, SL
, ST
);
605 ip
:= _lc
[I_NET_ADDRESS
] + ' ' + Srv
.IP
+ ':' + IntToStr(Srv
.Port
);
607 ip
:= ip
+ ' ' + _lc
[I_NET_SERVER_PASSWORD
] + ' ' + _lc
[I_MENU_YES
]
609 ip
:= ip
+ ' ' + _lc
[I_NET_SERVER_PASSWORD
] + ' ' + _lc
[I_MENU_NO
];
611 if Length(ST
) > 0 then
614 mw
:= (gScreenWidth
- 188);
617 e_DrawFillQuad(16 + 1, sy
, gScreenWidth
- 16 - 1, sy
+ 40, 64, 64, 64, 0);
618 e_DrawLine(1, 16 + 1, sy
, gScreenWidth
- 16 - 1, sy
, 205, 205, 205);
619 e_DrawLine(1, 16 + 1, sy
+ 41, gScreenWidth
- 16 - 1, sy
+ 41, 255, 255, 255);
621 e_DrawLine(1, 16, 85, gScreenWidth
- 16, 85, 255, 127, 0);
622 e_DrawLine(1, 16, gScreenHeight
-104, gScreenWidth
-16, gScreenHeight
-104, 255, 127, 0);
624 e_DrawLine(1, mx
- 70, 64, mx
- 70, gScreenHeight
-84, 255, 127, 0);
625 e_DrawLine(1, mx
, 64, mx
, gScreenHeight
-104, 255, 127, 0);
626 e_DrawLine(1, mx
+ 52, 64, mx
+ 52, gScreenHeight
-104, 255, 127, 0);
627 e_DrawLine(1, mx
+ 104, 64, mx
+ 104, gScreenHeight
-104, 255, 127, 0);
629 e_TextureFontPrintEx(18, 68, 'NAME/MAP', gStdFont
, 255, 127, 0, 1);
630 e_TextureFontPrintEx(mx
- 68, 68, 'PING', gStdFont
, 255, 127, 0, 1);
631 e_TextureFontPrintEx(mx
+ 2, 68, 'MODE', gStdFont
, 255, 127, 0, 1);
632 e_TextureFontPrintEx(mx
+ 54, 68, 'PLRS', gStdFont
, 255, 127, 0, 1);
633 e_TextureFontPrintEx(mx
+ 106, 68, 'VER', gStdFont
, 255, 127, 0, 1);
636 for I
:= 0 to High(ST
) do
638 Srv
:= GetServerFromTable(I
, SL
, ST
);
640 e_TextureFontPrintEx(18, y
, Srv
.Name
, gStdFont
, 255, 255, 255, 1);
641 e_TextureFontPrintEx(18, y
+ 16, Srv
.Map
, gStdFont
, 210, 210, 210, 1);
643 // Ping and similar count
644 if (Srv
.Ping
< 0) or (Srv
.Ping
> 999) then
645 e_TextureFontPrintEx(mx
- 68, y
, _lc
[I_NET_SLIST_NO_ACCESS
], gStdFont
, 255, 0, 0, 1)
648 e_TextureFontPrintEx(mx
- 68, y
, '<1' + _lc
[I_NET_SLIST_PING_MS
], gStdFont
, 255, 255, 255, 1)
650 e_TextureFontPrintEx(mx
- 68, y
, IntToStr(Srv
.Ping
) + _lc
[I_NET_SLIST_PING_MS
], gStdFont
, 255, 255, 255, 1);
652 if Length(ST
[I
].Indices
) > 1 then
653 e_TextureFontPrintEx(mx
- 68, y
+ 16, '< ' + IntToStr(Length(ST
[I
].Indices
)) + ' >', gStdFont
, 210, 210, 210, 1);
656 e_TextureFontPrintEx(mx
+ 2, y
, g_Game_ModeToText(Srv
.GameMode
), gStdFont
, 255, 255, 255, 1);
659 e_TextureFontPrintEx(mx
+ 54, y
, IntToStr(Srv
.Players
) + '/' + IntToStr(Srv
.MaxPlayers
), gStdFont
, 255, 255, 255, 1);
660 e_TextureFontPrintEx(mx
+ 54, y
+ 16, IntToStr(Srv
.LocalPl
) + '+' + IntToStr(Srv
.Bots
), gStdFont
, 210, 210, 210, 1);
663 e_TextureFontPrintEx(mx
+ 106, y
, IntToStr(Srv
.Protocol
), gStdFont
, 255, 255, 255, 1);
668 e_TextureFontPrintEx(20, gScreenHeight
-101, ip
, gStdFont
, 205, 205, 205, 1);
669 ip
:= IntToStr(Length(ST
)) + _lc
[I_NET_SLIST_SERVERS
];
670 e_TextureFontPrintEx(gScreenWidth
- 48 - (Length(ip
) + 1)*cw
,
671 gScreenHeight
-101, ip
, gStdFont
, 205, 205, 205, 1);
674 procedure g_Serverlist_GenerateTable(SL
: TNetServerList
; var ST
: TNetServerTable
);
678 function FindServerInTable(Name
: string): Integer;
685 for i
:= Low(ST
) to High(ST
) do
687 if Length(ST
[i
].Indices
) = 0 then
689 if SL
[ST
[i
].Indices
[0]].Name
= Name
then
696 function ComparePing(i1
, i2
: Integer): Boolean;
702 if (p1
< 0) then p1
:= 999;
703 if (p2
< 0) then p2
:= 999;
706 procedure SortIndices(var ind
: Array of Integer);
711 for I
:= High(ind
) downto Low(ind
) do
712 for J
:= Low(ind
) to High(ind
) - 1 do
713 if ComparePing(ind
[j
], ind
[j
+1]) then
720 procedure SortRows();
725 for I
:= High(ST
) downto Low(ST
) do
726 for J
:= Low(ST
) to High(ST
) - 1 do
727 if ComparePing(ST
[j
].Indices
[0], ST
[j
+1].Indices
[0]) then
738 for i
:= Low(SL
) to High(SL
) do
740 j
:= FindServerInTable(SL
[i
].Name
);
744 SetLength(ST
, j
+ 1);
746 SetLength(ST
[j
].Indices
, 1);
747 ST
[j
].Indices
[0] := i
;
751 SetLength(ST
[j
].Indices
, Length(ST
[j
].Indices
) + 1);
752 ST
[j
].Indices
[High(ST
[j
].Indices
)] := i
;
756 for i
:= Low(ST
) to High(ST
) do
757 SortIndices(ST
[i
].Indices
);
762 procedure g_Serverlist_Control(var SL
: TNetServerList
; var ST
: TNetServerTable
);
767 if gConsoleShow
or gChatShow
then
770 qm
:= g_ProcessMessages(); // this updates kbd
772 if qm
or e_KeyPressed(IK_ESCAPE
) or e_KeyPressed(VK_ESCAPE
) or
773 e_KeyPressed(JOY0_JUMP
) or e_KeyPressed(JOY1_JUMP
) or
774 e_KeyPressed(JOY2_JUMP
) or e_KeyPressed(JOY3_JUMP
) then
778 gState
:= STATE_MENU
;
779 g_GUI_ShowWindow('MainMenu');
780 g_GUI_ShowWindow('NetGameMenu');
781 g_GUI_ShowWindow('NetClientMenu');
782 g_Sound_PlayEx(WINDOW_CLOSESOUND
);
786 // if there's a message on the screen,
787 if not slReadUrgent
and (slUrgent
<> '') then
789 if e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
790 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
) then
791 slReadUrgent
:= True;
795 if e_KeyPressed(IK_SPACE
) or e_KeyPressed(VK_JUMP
) or
796 e_KeyPressed(JOY0_ACTIVATE
) or e_KeyPressed(JOY1_ACTIVATE
) or e_KeyPressed(JOY2_ACTIVATE
) or e_KeyPressed(JOY3_ACTIVATE
) then
798 if not slFetched
then
800 slWaitStr
:= _lc
[I_NET_SLIST_WAIT
];
803 g_window
.ReDrawWindow
;
805 if g_Net_Slist_Fetch(SL
) then
808 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
812 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
815 g_Serverlist_GenerateTable(SL
, ST
);
821 if SL
= nil then Exit
;
823 if e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
824 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
) then
826 if not slReturnPressed
then
828 Srv
:= GetServerFromTable(slSelection
, SL
, ST
);
832 PromptPort
:= Srv
.Port
;
833 gState
:= STATE_MENU
;
834 g_GUI_ShowWindow('ClientPasswordMenu');
837 slReturnPressed
:= True;
841 g_Game_StartClient(Srv
.IP
, Srv
.Port
, '');
844 slReturnPressed
:= True;
849 slReturnPressed
:= False;
851 if e_KeyPressed(IK_DOWN
) or e_KeyPressed(IK_KPDOWN
) or e_KeyPressed(VK_DOWN
) or
852 e_KeyPressed(JOY0_DOWN
) or e_KeyPressed(JOY1_DOWN
) or e_KeyPressed(JOY2_DOWN
) or e_KeyPressed(JOY3_DOWN
) then
854 if not slDirPressed
then
857 if slSelection
> High(ST
) then slSelection
:= 0;
858 slDirPressed
:= True;
862 if e_KeyPressed(IK_UP
) or e_KeyPressed(IK_KPUP
) or e_KeyPressed(VK_UP
) or
863 e_KeyPressed(JOY0_UP
) or e_KeyPressed(JOY1_UP
) or e_KeyPressed(JOY2_UP
) or e_KeyPressed(JOY3_UP
) then
865 if not slDirPressed
then
867 if slSelection
= 0 then slSelection
:= Length(ST
);
870 slDirPressed
:= True;
874 if e_KeyPressed(IK_RIGHT
) or e_KeyPressed(IK_KPRIGHT
) or e_KeyPressed(VK_RIGHT
) or
875 e_KeyPressed(JOY0_RIGHT
) or e_KeyPressed(JOY1_RIGHT
) or e_KeyPressed(JOY2_RIGHT
) or e_KeyPressed(JOY3_RIGHT
) then
877 if not slDirPressed
then
879 Inc(ST
[slSelection
].Current
);
880 if ST
[slSelection
].Current
> High(ST
[slSelection
].Indices
) then ST
[slSelection
].Current
:= 0;
881 slDirPressed
:= True;
885 if e_KeyPressed(IK_LEFT
) or e_KeyPressed(IK_KPLEFT
) or e_KeyPressed(VK_LEFT
) or
886 e_KeyPressed(JOY0_LEFT
) or e_KeyPressed(JOY1_LEFT
) or e_KeyPressed(JOY2_LEFT
) or e_KeyPressed(JOY3_LEFT
) then
888 if not slDirPressed
then
890 if ST
[slSelection
].Current
= 0 then ST
[slSelection
].Current
:= Length(ST
[slSelection
].Indices
);
891 Dec(ST
[slSelection
].Current
);
893 slDirPressed
:= True;
897 if (not e_KeyPressed(IK_DOWN
)) and
898 (not e_KeyPressed(IK_UP
)) and
899 (not e_KeyPressed(IK_RIGHT
)) and
900 (not e_KeyPressed(IK_LEFT
)) and
901 (not e_KeyPressed(IK_KPDOWN
)) and
902 (not e_KeyPressed(IK_KPUP
)) and
903 (not e_KeyPressed(IK_KPRIGHT
)) and
904 (not e_KeyPressed(IK_KPLEFT
)) and
905 (not e_KeyPressed(VK_DOWN
)) and
906 (not e_KeyPressed(VK_UP
)) and
907 (not e_KeyPressed(VK_RIGHT
)) and
908 (not e_KeyPressed(VK_LEFT
)) and
909 (not e_KeyPressed(JOY0_UP
)) and (not e_KeyPressed(JOY1_UP
)) and (not e_KeyPressed(JOY2_UP
)) and (not e_KeyPressed(JOY3_UP
)) and
910 (not e_KeyPressed(JOY0_DOWN
)) and (not e_KeyPressed(JOY1_DOWN
)) and (not e_KeyPressed(JOY2_DOWN
)) and (not e_KeyPressed(JOY3_DOWN
)) and
911 (not e_KeyPressed(JOY0_LEFT
)) and (not e_KeyPressed(JOY1_LEFT
)) and (not e_KeyPressed(JOY2_LEFT
)) and (not e_KeyPressed(JOY3_LEFT
)) and
912 (not e_KeyPressed(JOY0_RIGHT
)) and (not e_KeyPressed(JOY1_RIGHT
)) and (not e_KeyPressed(JOY2_RIGHT
)) and (not e_KeyPressed(JOY3_RIGHT
))
914 slDirPressed
:= False;