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, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
40 Players
, MaxPlayers
, LocalPl
, Bots
: Byte;
44 PingAddr
: ENetAddress
;
46 pTNetServer
= ^TNetServer
;
47 TNetServerRow
= record
48 Indices
: Array of Integer;
52 TNetServerList
= array of TNetServer
;
53 pTNetServerList
= ^TNetServerList
;
54 TNetServerTable
= array of TNetServerRow
;
57 NetMHost
: pENetHost
= nil;
58 NetMPeer
: pENetPeer
= nil;
60 slCurrent
: TNetServerList
= nil;
61 slTable
: TNetServerTable
= nil;
62 slWaitStr
: string = '';
63 slReturnPressed
: Boolean = True;
66 slUrgent
: string = '';
68 procedure g_Net_Slist_Set(IP
: string; Port
: Word);
69 function g_Net_Slist_Fetch(var SL
: TNetServerList
): Boolean;
70 procedure g_Net_Slist_Update();
71 procedure g_Net_Slist_Remove();
72 function g_Net_Slist_Connect(): Boolean;
73 procedure g_Net_Slist_Check();
74 procedure g_Net_Slist_Disconnect();
75 procedure g_Net_Slist_WriteInfo();
77 procedure g_Serverlist_GenerateTable(SL
: TNetServerList
; var ST
: TNetServerTable
);
78 procedure g_Serverlist_Draw(var SL
: TNetServerList
; var ST
: TNetServerTable
);
79 procedure g_Serverlist_Control(var SL
: TNetServerList
; var ST
: TNetServerTable
);
84 SysUtils
, e_msg
, e_input
, e_graphics
, e_log
, g_window
, g_net
, g_console
,
85 g_map
, g_game
, g_sound
, g_gui
, g_menu
, g_options
, g_language
, g_basic
,
90 slSelection
: Byte = 0;
91 slFetched
: Boolean = False;
92 slDirPressed
: Boolean = False;
93 slReadUrgent
: Boolean = False;
95 function GetTimerMS(): Int64;
97 Result
:= GetTimer() {div 1000};
100 procedure PingServer(var S
: TNetServer
; Sock
: ENetSocket
);
103 Ping
: array [0..9] of Byte;
106 ClTime
:= GetTimerMS();
108 Buf
.data
:= Addr(Ping
[0]);
109 Buf
.dataLength
:= 2+8;
113 Int64(Addr(Ping
[2])^) := ClTime
;
115 enet_socket_send(Sock
, Addr(S
.PingAddr
), @Buf
, 1);
118 procedure PingBcast(Sock
: ENetSocket
);
122 S
.IP
:= '255.255.255.255';
123 S
.Port
:= NET_PING_PORT
;
124 enet_address_set_host(Addr(S
.PingAddr
), PChar(Addr(S
.IP
[1])));
126 S
.PingAddr
.port
:= S
.Port
;
130 function g_Net_Slist_Fetch(var SL
: TNetServerList
): Boolean;
144 procedure ProcessLocal();
147 SetLength(SL
, I
+ 1);
150 IP
:= DecodeIPV4(SvAddr
.host
);
151 Port
:= InMsg
.ReadWord();
152 Ping
:= InMsg
.ReadInt64();
153 Ping
:= GetTimerMS() - Ping
;
154 Name
:= InMsg
.ReadString();
155 Map
:= InMsg
.ReadString();
156 GameMode
:= InMsg
.ReadByte();
157 Players
:= InMsg
.ReadByte();
158 MaxPlayers
:= InMsg
.ReadByte();
159 Protocol
:= InMsg
.ReadByte();
160 Password
:= InMsg
.ReadByte() = 1;
161 LocalPl
:= InMsg
.ReadByte();
162 Bots
:= InMsg
.ReadWord();
165 procedure CheckLocalServers();
169 Sock
:= enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM
);
170 if Sock
= ENET_SOCKET_NULL
then Exit
;
171 enet_socket_set_option(Sock
, ENET_SOCKOPT_NONBLOCK
, 1);
172 enet_socket_set_option(Sock
, ENET_SOCKOPT_BROADCAST
, 1);
177 InMsg
.Alloc(NET_BUFSIZE
);
178 Buf
.data
:= InMsg
.Data
;
179 Buf
.dataLength
:= InMsg
.MaxSize
;
180 while GetTimerMS() - T
<= 500 do
184 RX
:= enet_socket_receive(Sock
, @SvAddr
, @Buf
, 1);
185 if RX
<= 0 then continue
;
188 InMsg
.BeginReading();
190 if InMsg
.ReadChar() <> 'D' then continue
;
191 if InMsg
.ReadChar() <> 'F' then continue
;
197 enet_socket_destroy(Sock
);
199 if Length(SL
) = 0 then SL
:= nil;
205 if (NetMHost
<> nil) or (NetMPeer
<> nil) then
211 if not g_Net_Slist_Connect
then
217 e_WriteLog('Fetching serverlist...', TMsgType
.Notify
);
218 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_SLIST_FETCH
]);
221 NetOut
.Write(Byte(NET_MMSG_GET
));
223 // TODO: what should we identify the build with?
224 MyVer
:= GAME_VERSION
;
227 P
:= enet_packet_create(NetOut
.Data
, NetOut
.CurSize
, Cardinal(ENET_PACKET_FLAG_RELIABLE
));
228 enet_peer_send(NetMPeer
, NET_MCHAN_MAIN
, P
);
229 enet_host_flush(NetMHost
);
231 while enet_host_service(NetMHost
, @NetMEvent
, 5000) > 0 do
233 if NetMEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
then
235 if not InMsg
.Init(NetMEvent
.packet
^.data
, NetMEvent
.packet
^.dataLength
, True) then continue
;
237 MID
:= InMsg
.ReadByte();
239 if MID
<> NET_MMSG_GET
then continue
;
241 Cnt
:= InMsg
.ReadByte();
242 g_Console_Add(_lc
[I_NET_MSG
] + Format(_lc
[I_NET_SLIST_RETRIEVED
], [Cnt
]), True);
248 for I
:= 0 to Cnt
- 1 do
251 SL
[I
].IP
:= InMsg
.ReadString();
252 SL
[I
].Port
:= InMsg
.ReadWord();
253 SL
[I
].Name
:= InMsg
.ReadString();
254 SL
[I
].Map
:= InMsg
.ReadString();
255 SL
[I
].GameMode
:= InMsg
.ReadByte();
256 SL
[I
].Players
:= InMsg
.ReadByte();
257 SL
[I
].MaxPlayers
:= InMsg
.ReadByte();
258 SL
[I
].Protocol
:= InMsg
.ReadByte();
259 SL
[I
].Password
:= InMsg
.ReadByte() = 1;
260 enet_address_set_host(Addr(SL
[I
].PingAddr
), PChar(Addr(SL
[I
].IP
[1])));
262 SL
[I
].PingAddr
.port
:= NET_PING_PORT
;
266 if InMsg
.ReadCount
< InMsg
.CurSize
then
268 // new master, supports version reports
269 Str
:= InMsg
.ReadString();
270 if (Str
<> MyVer
) then
273 g_Console_Add('!!! UpdVer = `' + Str
+ '`');
275 // even newer master, supports extra info
276 if InMsg
.ReadCount
< InMsg
.CurSize
then
278 slMOTD
:= b_Text_Format(InMsg
.ReadString());
279 Str
:= b_Text_Format(InMsg
.ReadString());
280 // check if the message has updated and the user has to read it again
281 if slUrgent
<> Str
then slReadUrgent
:= False;
291 g_Net_Slist_Disconnect
;
294 if Length(SL
) = 0 then
300 Sock
:= enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM
);
301 if Sock
= ENET_SOCKET_NULL
then Exit
;
302 enet_socket_set_option(Sock
, ENET_SOCKOPT_NONBLOCK
, 1);
304 for I
:= Low(SL
) to High(SL
) do
305 PingServer(SL
[I
], Sock
);
307 enet_socket_set_option(Sock
, ENET_SOCKOPT_BROADCAST
, 1);
312 InMsg
.Alloc(NET_BUFSIZE
);
313 Buf
.data
:= InMsg
.Data
;
314 Buf
.dataLength
:= InMsg
.MaxSize
;
316 while GetTimerMS() - T
<= 500 do
320 RX
:= enet_socket_receive(Sock
, @SvAddr
, @Buf
, 1);
321 if RX
<= 0 then continue
;
324 InMsg
.BeginReading();
326 if InMsg
.ReadChar() <> 'D' then continue
;
327 if InMsg
.ReadChar() <> 'F' then continue
;
330 for I
:= Low(SL
) to High(SL
) do
331 if (SL
[I
].PingAddr
.host
= SvAddr
.host
) and
332 (SL
[I
].PingAddr
.port
= SvAddr
.port
) then
336 Port
:= InMsg
.ReadWord();
337 Ping
:= InMsg
.ReadInt64();
338 Ping
:= GetTimerMS() - Ping
;
339 Name
:= InMsg
.ReadString();
340 Map
:= InMsg
.ReadString();
341 GameMode
:= InMsg
.ReadByte();
342 Players
:= InMsg
.ReadByte();
343 MaxPlayers
:= InMsg
.ReadByte();
344 Protocol
:= InMsg
.ReadByte();
345 Password
:= InMsg
.ReadByte() = 1;
346 LocalPl
:= InMsg
.ReadByte();
347 Bots
:= InMsg
.ReadWord();
358 enet_socket_destroy(Sock
);
361 procedure g_Net_Slist_WriteInfo();
366 Wad
:= g_ExtractWadNameNoPath(gMapInfo
.Map
);
367 Map
:= g_ExtractFileName(gMapInfo
.Map
);
369 NetOut
.Write(NetServerName
);
371 NetOut
.Write(Wad
+ ':\' + Map
);
372 NetOut
.Write(gGameSettings
.GameMode
);
374 Cli
:= NetClientCount
;
377 NetOut
.Write(NetMaxClients
);
379 NetOut
.Write(Byte(NET_PROTOCOL_VER
));
380 NetOut
.Write(Byte(NetPassword
<> ''));
383 procedure g_Net_Slist_Update
;
389 if (NetMHost
= nil) or (NetMPeer
= nil) then Exit
;
392 NetOut
.Write(Byte(NET_MMSG_UPD
));
393 NetOut
.Write(NetAddr
.port
);
395 g_Net_Slist_WriteInfo();
397 P
:= enet_packet_create(NetOut
.Data
, NetOut
.CurSize
, Cardinal(ENET_PACKET_FLAG_RELIABLE
));
398 enet_peer_send(NetMPeer
, NET_MCHAN_UPD
, P
);
400 enet_host_flush(NetMHost
);
404 procedure g_Net_Slist_Remove
;
408 if (NetMHost
= nil) or (NetMPeer
= nil) then Exit
;
410 NetOut
.Write(Byte(NET_MMSG_DEL
));
411 NetOut
.Write(NetAddr
.port
);
413 P
:= enet_packet_create(NetOut
.Data
, NetOut
.CurSize
, Cardinal(ENET_PACKET_FLAG_RELIABLE
));
414 enet_peer_send(NetMPeer
, NET_MCHAN_MAIN
, P
);
416 enet_host_flush(NetMHost
);
420 function g_Net_Slist_Connect
: Boolean;
424 NetMHost
:= enet_host_create(nil, 1, NET_MCHANS
, 0, 0);
425 if (NetMHost
= nil) then
427 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CLIENT
], True);
431 NetMPeer
:= enet_host_connect(NetMHost
, @NetSlistAddr
, NET_MCHANS
, 0);
432 if (NetMPeer
= nil) then
434 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_ERR_CLIENT
], True);
435 enet_host_destroy(NetMHost
);
440 if (enet_host_service(NetMHost
, @NetMEvent
, 3000) > 0) then
441 if NetMEvent
.kind
= ENET_EVENT_TYPE_CONNECT
then
444 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_SLIST_CONN
]);
448 if NetMEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
then
449 enet_packet_destroy(NetMEvent
.packet
);
451 g_Console_Add(_lc
[I_NET_MSG_ERROR
] + _lc
[I_NET_SLIST_ERROR
], True);
457 procedure g_Net_Slist_Disconnect
;
459 if (NetMHost
= nil) and (NetMPeer
= nil) then Exit
;
461 if NetMode
= NET_SERVER
then g_Net_Slist_Remove
;
463 enet_peer_disconnect(NetMPeer
, 0);
464 enet_host_flush(NetMHost
);
466 enet_peer_reset(NetMPeer
);
467 enet_host_destroy(NetMHost
);
472 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_SLIST_DISC
]);
475 procedure g_Net_Slist_Check
;
477 if (NetMHost
= nil) or (NetMPeer
= nil) then Exit
;
479 while (enet_host_service(NetMHost
, @NetMEvent
, 0) > 0) do
481 if NetMEvent
.kind
= ENET_EVENT_TYPE_DISCONNECT
then
483 g_Console_Add(_lc
[I_NET_MSG
] + _lc
[I_NET_SLIST_LOST
], True);
484 if NetMPeer
<> nil then enet_peer_reset(NetMPeer
);
485 if NetMHost
<> nil then enet_host_destroy(NetMHost
);
491 if NetMEvent
.kind
= ENET_EVENT_TYPE_RECEIVE
then
492 enet_packet_destroy(NetMEvent
.packet
);
496 procedure g_Net_Slist_Set(IP
: string; Port
: Word);
500 enet_address_set_host(@NetSlistAddr
, PChar(Addr(IP
[1])));
501 NetSlistAddr
.Port
:= Port
;
502 e_WriteLog('Masterserver address set to ' + IP
+ ':' + IntToStr(Port
), TMsgType
.Notify
);
506 function GetServerFromTable(Index
: Integer; SL
: TNetServerList
; ST
: TNetServerTable
): TNetServer
;
509 Result
.Protocol
:= 0;
515 Result
.MaxPlayers
:= 0;
519 Result
.GameMode
:= 0;
520 Result
.Password
:= false;
521 FillChar(Result
.PingAddr
, SizeOf(ENetAddress
), 0);
524 if (Index
< 0) or (Index
>= Length(ST
)) then
526 Result
:= SL
[ST
[Index
].Indices
[ST
[Index
].Current
]];
529 procedure g_Serverlist_Draw(var SL
: TNetServerList
; var ST
: TNetServerTable
);
532 sy
, i
, y
, mw
, mx
, l
, motdh
: Integer;
542 e_CharFont_GetSize(gMenuFont
, _lc
[I_NET_SLIST
], ww
, hh
);
543 e_CharFont_Print(gMenuFont
, (gScreenWidth
div 2) - (ww
div 2), 16, _lc
[I_NET_SLIST
]);
545 e_TextureFontGetSize(gStdFont
, cw
, ch
);
547 ip
:= _lc
[I_NET_SLIST_HELP
];
548 mw
:= (Length(ip
) * cw
) div 2;
550 motdh
:= gScreenHeight
- 49 - ch
* b_Text_LineCount(slMOTD
);
552 e_DrawFillQuad(16, 64, gScreenWidth
-16, motdh
, 64, 64, 64, 110);
553 e_DrawQuad(16, 64, gScreenWidth
-16, motdh
, 255, 127, 0);
555 e_TextureFontPrintEx(gScreenWidth
div 2 - mw
, gScreenHeight
-24, ip
, gStdFont
, 225, 225, 225, 1);
560 e_DrawFillQuad(16, motdh
, gScreenWidth
-16, gScreenHeight
-44, 64, 64, 64, 110);
561 e_DrawQuad(16, motdh
, gScreenWidth
-16, gScreenHeight
-44, 255, 127, 0);
562 e_TextureFontPrintFmt(20, motdh
+ 3, slMOTD
, gStdFont
, False, True);
566 if not slReadUrgent
and (slUrgent
<> '') then
568 e_DrawFillQuad(17, 65, gScreenWidth
-17, motdh
-1, 64, 64, 64, 128);
569 e_DrawFillQuad(gScreenWidth
div 2 - 256, gScreenHeight
div 2 - 60,
570 gScreenWidth
div 2 + 256, gScreenHeight
div 2 + 60, 64, 64, 64, 128);
571 e_DrawQuad(gScreenWidth
div 2 - 256, gScreenHeight
div 2 - 60,
572 gScreenWidth
div 2 + 256, gScreenHeight
div 2 + 60, 255, 127, 0);
573 e_DrawLine(1, gScreenWidth
div 2 - 256, gScreenHeight
div 2 - 40,
574 gScreenWidth
div 2 + 256, gScreenHeight
div 2 - 40, 255, 127, 0);
575 l
:= Length(_lc
[I_NET_SLIST_URGENT
]) div 2;
576 e_TextureFontPrint(gScreenWidth
div 2 - cw
* l
, gScreenHeight
div 2 - 58,
577 _lc
[I_NET_SLIST_URGENT
], gStdFont
);
578 l
:= Length(slUrgent
) div 2;
579 e_TextureFontPrintFmt(gScreenWidth
div 2 - 253, gScreenHeight
div 2 - 38,
580 slUrgent
, gStdFont
, False, True);
581 l
:= Length(_lc
[I_NET_SLIST_URGENT_CONT
]) div 2;
582 e_TextureFontPrint(gScreenWidth
div 2 - cw
* l
, gScreenHeight
div 2 + 41,
583 _lc
[I_NET_SLIST_URGENT_CONT
], gStdFont
);
584 e_DrawLine(1, gScreenWidth
div 2 - 256, gScreenHeight
div 2 + 40,
585 gScreenWidth
div 2 + 256, gScreenHeight
div 2 + 40, 255, 127, 0);
591 l
:= Length(slWaitStr
) div 2;
592 e_DrawFillQuad(17, 65, gScreenWidth
-17, motdh
-1, 64, 64, 64, 128);
593 e_DrawQuad(gScreenWidth
div 2 - 192, gScreenHeight
div 2 - 10,
594 gScreenWidth
div 2 + 192, gScreenHeight
div 2 + 11, 255, 127, 0);
595 e_TextureFontPrint(gScreenWidth
div 2 - cw
* l
, gScreenHeight
div 2 - ch
div 2,
596 slWaitStr
, gStdFont
);
601 if (slSelection
< Length(ST
)) then
604 sy
:= y
+ 42 * I
- 4;
605 Srv
:= GetServerFromTable(I
, SL
, ST
);
606 ip
:= _lc
[I_NET_ADDRESS
] + ' ' + Srv
.IP
+ ':' + IntToStr(Srv
.Port
);
608 ip
:= ip
+ ' ' + _lc
[I_NET_SERVER_PASSWORD
] + ' ' + _lc
[I_MENU_YES
]
610 ip
:= ip
+ ' ' + _lc
[I_NET_SERVER_PASSWORD
] + ' ' + _lc
[I_MENU_NO
];
612 if Length(ST
) > 0 then
615 mw
:= (gScreenWidth
- 188);
618 e_DrawFillQuad(16 + 1, sy
, gScreenWidth
- 16 - 1, sy
+ 40, 64, 64, 64, 0);
619 e_DrawLine(1, 16 + 1, sy
, gScreenWidth
- 16 - 1, sy
, 205, 205, 205);
620 e_DrawLine(1, 16 + 1, sy
+ 41, gScreenWidth
- 16 - 1, sy
+ 41, 255, 255, 255);
622 e_DrawLine(1, 16, 85, gScreenWidth
- 16, 85, 255, 127, 0);
623 e_DrawLine(1, 16, motdh
-20, gScreenWidth
-16, motdh
-20, 255, 127, 0);
625 e_DrawLine(1, mx
- 70, 64, mx
- 70, motdh
, 255, 127, 0);
626 e_DrawLine(1, mx
, 64, mx
, motdh
-20, 255, 127, 0);
627 e_DrawLine(1, mx
+ 52, 64, mx
+ 52, motdh
-20, 255, 127, 0);
628 e_DrawLine(1, mx
+ 104, 64, mx
+ 104, motdh
-20, 255, 127, 0);
630 e_TextureFontPrintEx(18, 68, 'NAME/MAP', gStdFont
, 255, 127, 0, 1);
631 e_TextureFontPrintEx(mx
- 68, 68, 'PING', gStdFont
, 255, 127, 0, 1);
632 e_TextureFontPrintEx(mx
+ 2, 68, 'MODE', gStdFont
, 255, 127, 0, 1);
633 e_TextureFontPrintEx(mx
+ 54, 68, 'PLRS', gStdFont
, 255, 127, 0, 1);
634 e_TextureFontPrintEx(mx
+ 106, 68, 'VER', gStdFont
, 255, 127, 0, 1);
637 for I
:= 0 to High(ST
) do
639 Srv
:= GetServerFromTable(I
, SL
, ST
);
641 e_TextureFontPrintEx(18, y
, Srv
.Name
, gStdFont
, 255, 255, 255, 1);
642 e_TextureFontPrintEx(18, y
+ 16, Srv
.Map
, gStdFont
, 210, 210, 210, 1);
644 // Ping and similar count
645 if (Srv
.Ping
< 0) or (Srv
.Ping
> 999) then
646 e_TextureFontPrintEx(mx
- 68, y
, _lc
[I_NET_SLIST_NO_ACCESS
], gStdFont
, 255, 0, 0, 1)
649 e_TextureFontPrintEx(mx
- 68, y
, '<1' + _lc
[I_NET_SLIST_PING_MS
], gStdFont
, 255, 255, 255, 1)
651 e_TextureFontPrintEx(mx
- 68, y
, IntToStr(Srv
.Ping
) + _lc
[I_NET_SLIST_PING_MS
], gStdFont
, 255, 255, 255, 1);
653 if Length(ST
[I
].Indices
) > 1 then
654 e_TextureFontPrintEx(mx
- 68, y
+ 16, '< ' + IntToStr(Length(ST
[I
].Indices
)) + ' >', gStdFont
, 210, 210, 210, 1);
657 e_TextureFontPrintEx(mx
+ 2, y
, g_Game_ModeToText(Srv
.GameMode
), gStdFont
, 255, 255, 255, 1);
660 e_TextureFontPrintEx(mx
+ 54, y
, IntToStr(Srv
.Players
) + '/' + IntToStr(Srv
.MaxPlayers
), gStdFont
, 255, 255, 255, 1);
661 e_TextureFontPrintEx(mx
+ 54, y
+ 16, IntToStr(Srv
.LocalPl
) + '+' + IntToStr(Srv
.Bots
), gStdFont
, 210, 210, 210, 1);
664 e_TextureFontPrintEx(mx
+ 106, y
, IntToStr(Srv
.Protocol
), gStdFont
, 255, 255, 255, 1);
669 e_TextureFontPrintEx(20, motdh
-20+3, ip
, gStdFont
, 205, 205, 205, 1);
670 ip
:= IntToStr(Length(ST
)) + _lc
[I_NET_SLIST_SERVERS
];
671 e_TextureFontPrintEx(gScreenWidth
- 48 - (Length(ip
) + 1)*cw
,
672 motdh
-20+3, ip
, gStdFont
, 205, 205, 205, 1);
675 procedure g_Serverlist_GenerateTable(SL
: TNetServerList
; var ST
: TNetServerTable
);
679 function FindServerInTable(Name
: string): Integer;
686 for i
:= Low(ST
) to High(ST
) do
688 if Length(ST
[i
].Indices
) = 0 then
690 if SL
[ST
[i
].Indices
[0]].Name
= Name
then
697 function ComparePing(i1
, i2
: Integer): Boolean;
703 if (p1
< 0) then p1
:= 999;
704 if (p2
< 0) then p2
:= 999;
707 procedure SortIndices(var ind
: Array of Integer);
712 for I
:= High(ind
) downto Low(ind
) do
713 for J
:= Low(ind
) to High(ind
) - 1 do
714 if ComparePing(ind
[j
], ind
[j
+1]) then
721 procedure SortRows();
726 for I
:= High(ST
) downto Low(ST
) do
727 for J
:= Low(ST
) to High(ST
) - 1 do
728 if ComparePing(ST
[j
].Indices
[0], ST
[j
+1].Indices
[0]) then
739 for i
:= Low(SL
) to High(SL
) do
741 j
:= FindServerInTable(SL
[i
].Name
);
745 SetLength(ST
, j
+ 1);
747 SetLength(ST
[j
].Indices
, 1);
748 ST
[j
].Indices
[0] := i
;
752 SetLength(ST
[j
].Indices
, Length(ST
[j
].Indices
) + 1);
753 ST
[j
].Indices
[High(ST
[j
].Indices
)] := i
;
757 for i
:= Low(ST
) to High(ST
) do
758 SortIndices(ST
[i
].Indices
);
763 procedure g_Serverlist_Control(var SL
: TNetServerList
; var ST
: TNetServerTable
);
768 if gConsoleShow
or gChatShow
then
771 qm
:= g_ProcessMessages(); // this updates kbd
773 if qm
or e_KeyPressed(IK_ESCAPE
) or e_KeyPressed(VK_ESCAPE
) or
774 e_KeyPressed(JOY0_JUMP
) or e_KeyPressed(JOY1_JUMP
) or
775 e_KeyPressed(JOY2_JUMP
) or e_KeyPressed(JOY3_JUMP
) then
779 gState
:= STATE_MENU
;
780 g_GUI_ShowWindow('MainMenu');
781 g_GUI_ShowWindow('NetGameMenu');
782 g_GUI_ShowWindow('NetClientMenu');
783 g_Sound_PlayEx(WINDOW_CLOSESOUND
);
787 // if there's a message on the screen,
788 if not slReadUrgent
and (slUrgent
<> '') then
790 if e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
791 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
) then
792 slReadUrgent
:= True;
796 if e_KeyPressed(IK_SPACE
) or e_KeyPressed(VK_JUMP
) or
797 e_KeyPressed(JOY0_ACTIVATE
) or e_KeyPressed(JOY1_ACTIVATE
) or e_KeyPressed(JOY2_ACTIVATE
) or e_KeyPressed(JOY3_ACTIVATE
) then
799 if not slFetched
then
801 slWaitStr
:= _lc
[I_NET_SLIST_WAIT
];
804 g_window
.ReDrawWindow
;
806 if g_Net_Slist_Fetch(SL
) then
809 slWaitStr
:= _lc
[I_NET_SLIST_NOSERVERS
];
813 slWaitStr
:= _lc
[I_NET_SLIST_ERROR
];
816 g_Serverlist_GenerateTable(SL
, ST
);
822 if SL
= nil then Exit
;
824 if e_KeyPressed(IK_RETURN
) or e_KeyPressed(IK_KPRETURN
) or e_KeyPressed(VK_FIRE
) or e_KeyPressed(VK_OPEN
) or
825 e_KeyPressed(JOY0_ATTACK
) or e_KeyPressed(JOY1_ATTACK
) or e_KeyPressed(JOY2_ATTACK
) or e_KeyPressed(JOY3_ATTACK
) then
827 if not slReturnPressed
then
829 Srv
:= GetServerFromTable(slSelection
, SL
, ST
);
833 PromptPort
:= Srv
.Port
;
834 gState
:= STATE_MENU
;
835 g_GUI_ShowWindow('ClientPasswordMenu');
838 slReturnPressed
:= True;
842 g_Game_StartClient(Srv
.IP
, Srv
.Port
, '');
845 slReturnPressed
:= True;
850 slReturnPressed
:= False;
852 if e_KeyPressed(IK_DOWN
) or e_KeyPressed(IK_KPDOWN
) or e_KeyPressed(VK_DOWN
) or
853 e_KeyPressed(JOY0_DOWN
) or e_KeyPressed(JOY1_DOWN
) or e_KeyPressed(JOY2_DOWN
) or e_KeyPressed(JOY3_DOWN
) then
855 if not slDirPressed
then
858 if slSelection
> High(ST
) then slSelection
:= 0;
859 slDirPressed
:= True;
863 if e_KeyPressed(IK_UP
) or e_KeyPressed(IK_KPUP
) or e_KeyPressed(VK_UP
) or
864 e_KeyPressed(JOY0_UP
) or e_KeyPressed(JOY1_UP
) or e_KeyPressed(JOY2_UP
) or e_KeyPressed(JOY3_UP
) then
866 if not slDirPressed
then
868 if slSelection
= 0 then slSelection
:= Length(ST
);
871 slDirPressed
:= True;
875 if e_KeyPressed(IK_RIGHT
) or e_KeyPressed(IK_KPRIGHT
) or e_KeyPressed(VK_RIGHT
) or
876 e_KeyPressed(JOY0_RIGHT
) or e_KeyPressed(JOY1_RIGHT
) or e_KeyPressed(JOY2_RIGHT
) or e_KeyPressed(JOY3_RIGHT
) then
878 if not slDirPressed
then
880 Inc(ST
[slSelection
].Current
);
881 if ST
[slSelection
].Current
> High(ST
[slSelection
].Indices
) then ST
[slSelection
].Current
:= 0;
882 slDirPressed
:= True;
886 if e_KeyPressed(IK_LEFT
) or e_KeyPressed(IK_KPLEFT
) or e_KeyPressed(VK_LEFT
) or
887 e_KeyPressed(JOY0_LEFT
) or e_KeyPressed(JOY1_LEFT
) or e_KeyPressed(JOY2_LEFT
) or e_KeyPressed(JOY3_LEFT
) then
889 if not slDirPressed
then
891 if ST
[slSelection
].Current
= 0 then ST
[slSelection
].Current
:= Length(ST
[slSelection
].Indices
);
892 Dec(ST
[slSelection
].Current
);
894 slDirPressed
:= True;
898 if (not e_KeyPressed(IK_DOWN
)) and
899 (not e_KeyPressed(IK_UP
)) and
900 (not e_KeyPressed(IK_RIGHT
)) and
901 (not e_KeyPressed(IK_LEFT
)) and
902 (not e_KeyPressed(IK_KPDOWN
)) and
903 (not e_KeyPressed(IK_KPUP
)) and
904 (not e_KeyPressed(IK_KPRIGHT
)) and
905 (not e_KeyPressed(IK_KPLEFT
)) and
906 (not e_KeyPressed(VK_DOWN
)) and
907 (not e_KeyPressed(VK_UP
)) and
908 (not e_KeyPressed(VK_RIGHT
)) and
909 (not e_KeyPressed(VK_LEFT
)) and
910 (not e_KeyPressed(JOY0_UP
)) and (not e_KeyPressed(JOY1_UP
)) and (not e_KeyPressed(JOY2_UP
)) and (not e_KeyPressed(JOY3_UP
)) and
911 (not e_KeyPressed(JOY0_DOWN
)) and (not e_KeyPressed(JOY1_DOWN
)) and (not e_KeyPressed(JOY2_DOWN
)) and (not e_KeyPressed(JOY3_DOWN
)) and
912 (not e_KeyPressed(JOY0_LEFT
)) and (not e_KeyPressed(JOY1_LEFT
)) and (not e_KeyPressed(JOY2_LEFT
)) and (not e_KeyPressed(JOY3_LEFT
)) and
913 (not e_KeyPressed(JOY0_RIGHT
)) and (not e_KeyPressed(JOY1_RIGHT
)) and (not e_KeyPressed(JOY2_RIGHT
)) and (not e_KeyPressed(JOY3_RIGHT
))
915 slDirPressed
:= False;