DEADSOFTWARE

Netmaster: Use DecodeIPV4 function
[d2df-sdl.git] / src / game / g_netmaster.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
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.
7 *
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.
12 *
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/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
17 unit g_netmaster;
19 interface
21 uses ENet;
23 const
24 NET_MCHANS = 2;
26 NET_MCHAN_MAIN = 0;
27 NET_MCHAN_UPD = 1;
29 NET_MMSG_UPD = 200;
30 NET_MMSG_DEL = 201;
31 NET_MMSG_GET = 202;
33 type
34 TNetServer = record
35 Number: Byte;
36 Protocol: Byte;
37 Name: string;
38 IP: string;
39 Port: Word;
40 Map: string;
41 Players, MaxPlayers, LocalPl, Bots: Byte;
42 Ping: Int64;
43 GameMode: Byte;
44 Password: Boolean;
45 PingAddr: ENetAddress;
46 end;
47 pTNetServer = ^TNetServer;
49 TNetServerList = array of TNetServer;
50 pTNetServerList = ^TNetServerList;
52 var
53 NetMHost: pENetHost = nil;
54 NetMPeer: pENetPeer = nil;
56 slCurrent: TNetServerList = nil;
57 slWaitStr: string = '';
58 slReturnPressed: Boolean = True;
60 procedure g_Net_Slist_Set(IP: string; Port: Word);
61 function g_Net_Slist_Fetch(var SL: TNetServerList): Boolean;
62 procedure g_Net_Slist_Update();
63 procedure g_Net_Slist_Remove();
64 function g_Net_Slist_Connect(): Boolean;
65 procedure g_Net_Slist_Check();
66 procedure g_Net_Slist_Disconnect();
67 procedure g_Net_Slist_WriteInfo();
69 procedure g_Serverlist_Draw(var SL: TNetServerList);
70 procedure g_Serverlist_Control(var SL: TNetServerList);
72 implementation
74 uses
75 SysUtils, e_msg, e_input, e_graphics, e_log, g_window, g_net, g_console,
76 g_map, g_game, g_sound, g_gui, g_menu, g_options, g_language, wadreader;
78 var
79 NetMEvent: ENetEvent;
80 slSelection: Byte = 0;
81 slFetched: Boolean = False;
82 slDirPressed: Boolean = False;
84 function GetTimerMS(): Int64;
85 begin
86 Result := GetTimer() {div 1000};
87 end;
89 procedure PingServer(var S: TNetServer; Sock: ENetSocket);
90 var
91 Buf: ENetBuffer;
92 Ping: array [0..9] of Byte;
93 ClTime: Int64;
94 begin
95 ClTime := GetTimerMS();
97 Buf.data := Addr(Ping[0]);
98 Buf.dataLength := 2+8;
100 Ping[0] := Ord('D');
101 Ping[1] := Ord('F');
102 Int64(Addr(Ping[2])^) := ClTime;
104 enet_socket_send(Sock, Addr(S.PingAddr), @Buf, 1);
105 end;
107 procedure PingBcast(Sock: ENetSocket);
108 var
109 S: TNetServer;
110 begin
111 S.IP := '255.255.255.255';
112 S.Port := NET_PING_PORT;
113 enet_address_set_host(Addr(S.PingAddr), PChar(Addr(S.IP[1])));
114 S.Ping := -1;
115 S.PingAddr.port := S.Port;
116 PingServer(S, Sock);
117 end;
119 function g_Net_Slist_Fetch(var SL: TNetServerList): Boolean;
120 var
121 Cnt: Byte;
122 P: pENetPacket;
123 MID: Byte;
124 I, RX: Integer;
125 T: Int64;
126 Sock: ENetSocket;
127 Buf: ENetBuffer;
128 InMsg: TMsg;
129 SvAddr: ENetAddress;
130 FromSL: Boolean;
132 procedure ProcessLocal();
133 begin
134 I := Length(SL);
135 SetLength(SL, I + 1);
136 with SL[I] do
137 begin
138 IP := DecodeIPV4(SvAddr.host);
139 Port := InMsg.ReadWord();
140 Ping := InMsg.ReadInt64();
141 Ping := GetTimerMS() - Ping;
142 Name := InMsg.ReadString();
143 Map := InMsg.ReadString();
144 GameMode := InMsg.ReadByte();
145 Players := InMsg.ReadByte();
146 MaxPlayers := InMsg.ReadByte();
147 Protocol := InMsg.ReadByte();
148 Password := InMsg.ReadByte() = 1;
149 LocalPl := InMsg.ReadByte();
150 Bots := InMsg.ReadWord();
151 end;
152 end;
153 procedure CheckLocalServers();
154 begin
155 SetLength(SL, 0);
157 Sock := enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM);
158 if Sock = ENET_SOCKET_NULL then Exit;
159 enet_socket_set_option(Sock, ENET_SOCKOPT_NONBLOCK, 1);
160 enet_socket_set_option(Sock, ENET_SOCKOPT_BROADCAST, 1);
161 PingBcast(Sock);
163 T := GetTimerMS();
165 InMsg.Alloc(NET_BUFSIZE);
166 Buf.data := InMsg.Data;
167 Buf.dataLength := InMsg.MaxSize;
168 while GetTimerMS() - T <= 500 do
169 begin
170 InMsg.Clear();
172 RX := enet_socket_receive(Sock, @SvAddr, @Buf, 1);
173 if RX <= 0 then continue;
174 InMsg.CurSize := RX;
176 InMsg.BeginReading();
178 if InMsg.ReadChar() <> 'D' then continue;
179 if InMsg.ReadChar() <> 'F' then continue;
181 ProcessLocal();
182 end;
184 InMsg.Free();
185 enet_socket_destroy(Sock);
187 if Length(SL) = 0 then SL := nil;
188 end;
189 begin
190 Result := False;
191 SL := nil;
193 if (NetMHost <> nil) or (NetMPeer <> nil) then
194 begin
195 CheckLocalServers();
196 Exit;
197 end;
199 if not g_Net_Slist_Connect then
200 begin
201 CheckLocalServers();
202 Exit;
203 end;
205 e_WriteLog('Fetching serverlist...', TMsgType.Notify);
206 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_SLIST_FETCH]);
208 NetOut.Clear();
209 NetOut.Write(Byte(NET_MMSG_GET));
211 P := enet_packet_create(NetOut.Data, NetOut.CurSize, Cardinal(ENET_PACKET_FLAG_RELIABLE));
212 enet_peer_send(NetMPeer, NET_MCHAN_MAIN, P);
213 enet_host_flush(NetMHost);
215 while enet_host_service(NetMHost, @NetMEvent, 5000) > 0 do
216 begin
217 if NetMEvent.kind = ENET_EVENT_TYPE_RECEIVE then
218 begin
219 if not InMsg.Init(NetMEvent.packet^.data, NetMEvent.packet^.dataLength, True) then continue;
221 MID := InMsg.ReadByte();
223 if MID <> NET_MMSG_GET then continue;
225 Cnt := InMsg.ReadByte();
226 g_Console_Add(_lc[I_NET_MSG] + Format(_lc[I_NET_SLIST_RETRIEVED], [Cnt]), True);
228 if Cnt > 0 then
229 begin
230 SetLength(SL, Cnt);
232 for I := 0 to Cnt - 1 do
233 begin
234 SL[I].Number := I;
235 SL[I].IP := InMsg.ReadString();
236 SL[I].Port := InMsg.ReadWord();
237 SL[I].Name := InMsg.ReadString();
238 SL[I].Map := InMsg.ReadString();
239 SL[I].GameMode := InMsg.ReadByte();
240 SL[I].Players := InMsg.ReadByte();
241 SL[I].MaxPlayers := InMsg.ReadByte();
242 SL[I].Protocol := InMsg.ReadByte();
243 SL[I].Password := InMsg.ReadByte() = 1;
244 enet_address_set_host(Addr(SL[I].PingAddr), PChar(Addr(SL[I].IP[1])));
245 SL[I].Ping := -1;
246 SL[I].PingAddr.port := NET_PING_PORT;
247 end;
248 end;
250 Result := True;
251 break;
252 end;
253 end;
255 g_Net_Slist_Disconnect;
256 NetOut.Clear();
258 if Length(SL) = 0 then
259 begin
260 CheckLocalServers();
261 Exit;
262 end;
264 Sock := enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM);
265 if Sock = ENET_SOCKET_NULL then Exit;
266 enet_socket_set_option(Sock, ENET_SOCKOPT_NONBLOCK, 1);
268 for I := Low(SL) to High(SL) do
269 PingServer(SL[I], Sock);
271 enet_socket_set_option(Sock, ENET_SOCKOPT_BROADCAST, 1);
272 PingBcast(Sock);
274 T := GetTimerMS();
276 InMsg.Alloc(NET_BUFSIZE);
277 Buf.data := InMsg.Data;
278 Buf.dataLength := InMsg.MaxSize;
279 Cnt := 0;
280 while GetTimerMS() - T <= 500 do
281 begin
282 InMsg.Clear();
284 RX := enet_socket_receive(Sock, @SvAddr, @Buf, 1);
285 if RX <= 0 then continue;
286 InMsg.CurSize := RX;
288 InMsg.BeginReading();
290 if InMsg.ReadChar() <> 'D' then continue;
291 if InMsg.ReadChar() <> 'F' then continue;
293 FromSL := False;
294 for I := Low(SL) to High(SL) do
295 if (SL[I].PingAddr.host = SvAddr.host) and
296 (SL[I].PingAddr.port = SvAddr.port) then
297 begin
298 with SL[I] do
299 begin
300 Port := InMsg.ReadWord();
301 Ping := InMsg.ReadInt64();
302 Ping := GetTimerMS() - Ping;
303 Name := InMsg.ReadString();
304 Map := InMsg.ReadString();
305 GameMode := InMsg.ReadByte();
306 Players := InMsg.ReadByte();
307 MaxPlayers := InMsg.ReadByte();
308 Protocol := InMsg.ReadByte();
309 Password := InMsg.ReadByte() = 1;
310 LocalPl := InMsg.ReadByte();
311 Bots := InMsg.ReadWord();
312 end;
313 FromSL := True;
314 Inc(Cnt);
315 break;
316 end;
317 if not FromSL then
318 ProcessLocal();
319 end;
321 InMsg.Free();
322 enet_socket_destroy(Sock);
323 end;
325 procedure g_Net_Slist_WriteInfo();
326 var
327 Wad, Map: string;
328 Cli: Byte;
329 begin
330 Wad := g_ExtractWadNameNoPath(gMapInfo.Map);
331 Map := g_ExtractFileName(gMapInfo.Map);
333 NetOut.Write(NetServerName);
335 NetOut.Write(Wad + ':\' + Map);
336 NetOut.Write(gGameSettings.GameMode);
338 Cli := NetClientCount;
339 NetOut.Write(Cli);
341 NetOut.Write(NetMaxClients);
343 NetOut.Write(Byte(NET_PROTOCOL_VER));
344 NetOut.Write(Byte(NetPassword <> ''));
345 end;
347 procedure g_Net_Slist_Update;
348 var
350 P: pENetPacket;
352 begin
353 if (NetMHost = nil) or (NetMPeer = nil) then Exit;
355 NetOut.Clear();
356 NetOut.Write(Byte(NET_MMSG_UPD));
357 NetOut.Write(NetAddr.port);
359 g_Net_Slist_WriteInfo();
361 P := enet_packet_create(NetOut.Data, NetOut.CurSize, Cardinal(ENET_PACKET_FLAG_RELIABLE));
362 enet_peer_send(NetMPeer, NET_MCHAN_UPD, P);
364 enet_host_flush(NetMHost);
365 NetOut.Clear();
366 end;
368 procedure g_Net_Slist_Remove;
369 var
370 P: pENetPacket;
371 begin
372 if (NetMHost = nil) or (NetMPeer = nil) then Exit;
373 NetOut.Clear();
374 NetOut.Write(Byte(NET_MMSG_DEL));
375 NetOut.Write(NetAddr.port);
377 P := enet_packet_create(NetOut.Data, NetOut.CurSize, Cardinal(ENET_PACKET_FLAG_RELIABLE));
378 enet_peer_send(NetMPeer, NET_MCHAN_MAIN, P);
380 enet_host_flush(NetMHost);
381 NetOut.Clear();
382 end;
384 function g_Net_Slist_Connect: Boolean;
385 begin
386 Result := False;
388 NetMHost := enet_host_create(nil, 1, NET_MCHANS, 0, 0);
389 if (NetMHost = nil) then
390 begin
391 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CLIENT], True);
392 Exit;
393 end;
395 NetMPeer := enet_host_connect(NetMHost, @NetSlistAddr, NET_MCHANS, 0);
396 if (NetMPeer = nil) then
397 begin
398 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CLIENT], True);
399 enet_host_destroy(NetMHost);
400 NetMHost := nil;
401 Exit;
402 end;
404 if (enet_host_service(NetMHost, @NetMEvent, 3000) > 0) then
405 if NetMEvent.kind = ENET_EVENT_TYPE_CONNECT then
406 begin
407 Result := True;
408 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_SLIST_CONN]);
409 Exit;
410 end
411 else
412 if NetMEvent.kind = ENET_EVENT_TYPE_RECEIVE then
413 enet_packet_destroy(NetMEvent.packet);
415 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_SLIST_ERROR], True);
417 NetMHost := nil;
418 NetMPeer := nil;
419 end;
421 procedure g_Net_Slist_Disconnect;
422 begin
423 if (NetMHost = nil) and (NetMPeer = nil) then Exit;
425 if NetMode = NET_SERVER then g_Net_Slist_Remove;
427 enet_peer_disconnect(NetMPeer, 0);
428 enet_host_flush(NetMHost);
430 enet_peer_reset(NetMPeer);
431 enet_host_destroy(NetMHost);
433 NetMPeer := nil;
434 NetMHost := nil;
436 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_SLIST_DISC]);
437 end;
439 procedure g_Net_Slist_Check;
440 begin
441 if (NetMHost = nil) or (NetMPeer = nil) then Exit;
443 while (enet_host_service(NetMHost, @NetMEvent, 0) > 0) do
444 begin
445 if NetMEvent.kind = ENET_EVENT_TYPE_DISCONNECT then
446 begin
447 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_SLIST_LOST], True);
448 if NetMPeer <> nil then enet_peer_reset(NetMPeer);
449 if NetMHost <> nil then enet_host_destroy(NetMHost);
450 NetMPeer := nil;
451 NetMHost := nil;
452 Break;
453 end
454 else
455 if NetMEvent.kind = ENET_EVENT_TYPE_RECEIVE then
456 enet_packet_destroy(NetMEvent.packet);
457 end;
458 end;
460 procedure g_Net_Slist_Set(IP: string; Port: Word);
461 begin
462 if NetInitDone then
463 begin
464 enet_address_set_host(@NetSlistAddr, PChar(Addr(IP[1])));
465 NetSlistAddr.Port := Port;
466 e_WriteLog('Masterserver address set to ' + IP + ':' + IntToStr(Port), TMsgType.Notify);
467 end;
468 end;
470 procedure g_Serverlist_Draw(var SL: TNetServerList);
471 var
472 sy, i, y, mw, mx, l: Integer;
473 cw: Byte = 0;
474 ch: Byte = 0;
475 ww: Word = 0;
476 hh: Word = 0;
477 ip: string;
478 begin
479 ip := '';
480 sy := 0;
482 e_CharFont_GetSize(gMenuFont, _lc[I_NET_SLIST], ww, hh);
483 e_CharFont_Print(gMenuFont, (gScreenWidth div 2) - (ww div 2), 16, _lc[I_NET_SLIST]);
485 e_TextureFontGetSize(gStdFont, cw, ch);
487 ip := _lc[I_NET_SLIST_HELP];
488 mw := (Length(ip) * cw) div 2;
490 e_DrawFillQuad(16, 64, gScreenWidth-16, gScreenHeight-44, 64, 64, 64, 110);
491 e_DrawQuad(16, 64, gScreenWidth-16, gScreenHeight-44, 255, 127, 0);
493 e_TextureFontPrintEx(gScreenWidth div 2 - mw, gScreenHeight-24, ip, gStdFont, 225, 225, 225, 1);
495 if SL = nil then
496 begin
497 l := Length(slWaitStr) div 2;
498 e_DrawFillQuad(16, 64, gScreenWidth-16, gScreenHeight-44, 64, 64, 64, 128);
499 e_DrawQuad(gScreenWidth div 2 - 192, gScreenHeight div 2 - 10,
500 gScreenWidth div 2 + 192, gScreenHeight div 2 + 11, 255, 127, 0);
501 e_TextureFontPrint(gScreenWidth div 2 - cw * l, gScreenHeight div 2 - ch div 2,
502 slWaitStr, gStdFont);
503 Exit;
504 end;
506 y := 90;
507 if (slSelection < Length(SL)) then
508 begin
509 I := slSelection;
510 sy := y + 42 * I - 4;
511 ip := _lc[I_NET_ADDRESS] + ' ' + SL[I].IP + ':' + IntToStr(SL[I].Port);
512 if SL[I].Password then
513 ip := ip + ' ' + _lc[I_NET_SERVER_PASSWORD] + ' ' + _lc[I_MENU_YES]
514 else
515 ip := ip + ' ' + _lc[I_NET_SERVER_PASSWORD] + ' ' + _lc[I_MENU_NO];
516 end else
517 if Length(SL) > 0 then
518 slSelection := 0;
520 mw := (gScreenWidth - 188);
521 mx := 16 + mw;
523 e_DrawFillQuad(16 + 1, sy, gScreenWidth - 16 - 1, sy + 40, 64, 64, 64, 0);
524 e_DrawLine(1, 16 + 1, sy, gScreenWidth - 16 - 1, sy, 205, 205, 205);
525 e_DrawLine(1, 16 + 1, sy + 41, gScreenWidth - 16 - 1, sy + 41, 255, 255, 255);
527 e_DrawLine(1, 16, 85, gScreenWidth - 16, 85, 255, 127, 0);
528 e_DrawLine(1, 16, gScreenHeight-64, gScreenWidth-16, gScreenHeight-64, 255, 127, 0);
530 e_DrawLine(1, mx - 70, 64, mx - 70, gScreenHeight-44, 255, 127, 0);
531 e_DrawLine(1, mx, 64, mx, gScreenHeight-64, 255, 127, 0);
532 e_DrawLine(1, mx + 52, 64, mx + 52, gScreenHeight-64, 255, 127, 0);
533 e_DrawLine(1, mx + 104, 64, mx + 104, gScreenHeight-64, 255, 127, 0);
535 e_TextureFontPrintEx(18, 68, 'NAME/MAP', gStdFont, 255, 127, 0, 1);
537 y := 90;
538 for I := 0 to High(SL) do
539 begin
540 e_TextureFontPrintEx(18, y, SL[I].Name, gStdFont, 255, 255, 255, 1);
541 e_TextureFontPrintEx(18, y + 16, SL[I].Map, gStdFont, 210, 210, 210, 1);
543 y := y + 42;
544 end;
546 e_TextureFontPrintEx(mx - 68, 68, 'PING', gStdFont, 255, 127, 0, 1);
547 y := 90;
548 for I := 0 to High(SL) do
549 begin
550 if (SL[I].Ping < 0) or (SL[I].Ping > 999) then
551 e_TextureFontPrintEx(mx - 68, y, _lc[I_NET_SLIST_NO_ACCESS], gStdFont, 255, 0, 0, 1)
552 else
553 if SL[I].Ping = 0 then
554 e_TextureFontPrintEx(mx - 68, y, '<1' + _lc[I_NET_SLIST_PING_MS], gStdFont, 255, 255, 255, 1)
555 else
556 e_TextureFontPrintEx(mx - 68, y, IntToStr(SL[I].Ping) + _lc[I_NET_SLIST_PING_MS], gStdFont, 255, 255, 255, 1);
558 y := y + 42;
559 end;
561 e_TextureFontPrintEx(mx + 2, 68, 'MODE', gStdFont, 255, 127, 0, 1);
562 y := 90;
563 for I := 0 to High(SL) do
564 begin
565 e_TextureFontPrintEx(mx + 2, y, g_Game_ModeToText(SL[I].GameMode), gStdFont, 255, 255, 255, 1);
567 y := y + 42;
568 end;
570 e_TextureFontPrintEx(mx + 54, 68, 'PLRS', gStdFont, 255, 127, 0, 1);
571 y := 90;
572 for I := 0 to High(SL) do
573 begin
574 e_TextureFontPrintEx(mx + 54, y, IntToStr(SL[I].Players) + '/' + IntToStr(SL[I].MaxPlayers), gStdFont, 255, 255, 255, 1);
575 e_TextureFontPrintEx(mx + 54, y + 16, IntToStr(SL[I].LocalPl) + '+' + IntToStr(SL[I].Bots), gStdFont, 210, 210, 210, 1);
576 y := y + 42;
577 end;
579 e_TextureFontPrintEx(mx + 106, 68, 'VER', gStdFont, 255, 127, 0, 1);
580 y := 90;
581 for I := 0 to High(SL) do
582 begin
583 e_TextureFontPrintEx(mx + 106, y, IntToStr(SL[I].Protocol), gStdFont, 255, 255, 255, 1);
585 y := y + 42;
586 end;
588 e_TextureFontPrintEx(20, gScreenHeight-61, ip, gStdFont, 205, 205, 205, 1);
589 ip := IntToStr(Length(SL)) + _lc[I_NET_SLIST_SERVERS];
590 e_TextureFontPrintEx(gScreenWidth - 48 - (Length(ip) + 1)*cw,
591 gScreenHeight-61, ip, gStdFont, 205, 205, 205, 1);
592 end;
594 procedure g_Serverlist_Control(var SL: TNetServerList);
595 var
596 qm: Boolean;
597 begin
598 if gConsoleShow or gChatShow then
599 Exit;
601 qm := g_ProcessMessages(); // this updates kbd
603 if qm or e_KeyPressed(IK_ESCAPE) or e_KeyPressed(VK_ESCAPE) then
604 begin
605 SL := nil;
606 gState := STATE_MENU;
607 g_GUI_ShowWindow('MainMenu');
608 g_GUI_ShowWindow('NetGameMenu');
609 g_GUI_ShowWindow('NetClientMenu');
610 g_Sound_PlayEx(WINDOW_CLOSESOUND);
611 Exit;
612 end;
614 if e_KeyPressed(IK_SPACE) or e_KeyPressed(VK_JUMP) then
615 begin
616 if not slFetched then
617 begin
618 slWaitStr := _lc[I_NET_SLIST_WAIT];
620 g_Game_Draw;
621 g_window.ReDrawWindow;
623 if g_Net_Slist_Fetch(SL) then
624 begin
625 if SL = nil then
626 slWaitStr := _lc[I_NET_SLIST_NOSERVERS];
627 end
628 else
629 if SL = nil then
630 slWaitStr := _lc[I_NET_SLIST_ERROR];
631 slFetched := True;
632 slSelection := 0;
633 end;
634 end
635 else
636 slFetched := False;
638 if SL = nil then Exit;
640 if e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) then
641 begin
642 if not slReturnPressed then
643 begin
644 if SL[slSelection].Password then
645 begin
646 PromptIP := SL[slSelection].IP;
647 PromptPort := SL[slSelection].Port;
648 gState := STATE_MENU;
649 g_GUI_ShowWindow('ClientPasswordMenu');
650 SL := nil;
651 slReturnPressed := True;
652 Exit;
653 end
654 else
655 g_Game_StartClient(SL[slSelection].IP, SL[slSelection].Port, '');
656 SL := nil;
657 slReturnPressed := True;
658 Exit;
659 end;
660 end
661 else
662 slReturnPressed := False;
664 if e_KeyPressed(IK_DOWN) or e_KeyPressed(IK_KPDOWN) or e_KeyPressed(VK_DOWN) then
665 begin
666 if not slDirPressed then
667 begin
668 Inc(slSelection);
669 if slSelection > High(SL) then slSelection := 0;
670 slDirPressed := True;
671 end;
672 end;
674 if e_KeyPressed(IK_UP) or e_KeyPressed(IK_KPUP) or e_KeyPressed(VK_UP) then
675 begin
676 if not slDirPressed then
677 begin
678 if slSelection = 0 then slSelection := Length(SL);
679 Dec(slSelection);
681 slDirPressed := True;
682 end;
683 end;
685 if (not e_KeyPressed(IK_DOWN)) and (not e_KeyPressed(IK_UP)) and (not e_KeyPressed(IK_KPDOWN)) and (not e_KeyPressed(IK_KPUP)) and (not e_KeyPressed(VK_DOWN)) and (not e_KeyPressed(VK_UP)) then
686 slDirPressed := False;
687 end;
689 end.