DEADSOFTWARE

Net: Allow to discover LAN servers
[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 var
134 IPBuf: Array[0..19] of Byte;
135 begin
136 I := Length(SL);
137 SetLength(SL, I + 1);
138 with SL[I] do
139 begin
140 FillChar(IPBuf, Length(IPBuf), 0);
141 enet_address_get_host_ip(Addr(SvAddr.host), PChar(Addr(IPBuf)), Length(IPBuf));
142 IP := PChar(Addr(IPBuf));
143 Port := InMsg.ReadWord();
144 Ping := InMsg.ReadInt64();
145 Ping := GetTimerMS() - Ping;
146 Name := InMsg.ReadString();
147 Map := InMsg.ReadString();
148 GameMode := InMsg.ReadByte();
149 Players := InMsg.ReadByte();
150 MaxPlayers := InMsg.ReadByte();
151 Protocol := InMsg.ReadByte();
152 Password := InMsg.ReadByte() = 1;
153 LocalPl := InMsg.ReadByte();
154 Bots := InMsg.ReadWord();
155 end;
156 end;
157 procedure CheckLocalServers();
158 begin
159 SetLength(SL, 0);
161 Sock := enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM);
162 if Sock = ENET_SOCKET_NULL then Exit;
163 enet_socket_set_option(Sock, ENET_SOCKOPT_NONBLOCK, 1);
164 enet_socket_set_option(Sock, ENET_SOCKOPT_BROADCAST, 1);
165 PingBcast(Sock);
167 T := GetTimerMS();
169 InMsg.Alloc(NET_BUFSIZE);
170 Buf.data := InMsg.Data;
171 Buf.dataLength := InMsg.MaxSize;
172 while GetTimerMS() - T <= 500 do
173 begin
174 InMsg.Clear();
176 RX := enet_socket_receive(Sock, @SvAddr, @Buf, 1);
177 if RX <= 0 then continue;
178 InMsg.CurSize := RX;
180 InMsg.BeginReading();
182 if InMsg.ReadChar() <> 'D' then continue;
183 if InMsg.ReadChar() <> 'F' then continue;
185 ProcessLocal();
186 end;
188 InMsg.Free();
189 enet_socket_destroy(Sock);
191 if Length(SL) = 0 then SL := nil;
192 end;
193 begin
194 Result := False;
195 SL := nil;
197 if (NetMHost <> nil) or (NetMPeer <> nil) then
198 begin
199 CheckLocalServers();
200 Exit;
201 end;
203 if not g_Net_Slist_Connect then
204 begin
205 CheckLocalServers();
206 Exit;
207 end;
209 e_WriteLog('Fetching serverlist...', TMsgType.Notify);
210 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_SLIST_FETCH]);
212 NetOut.Clear();
213 NetOut.Write(Byte(NET_MMSG_GET));
215 P := enet_packet_create(NetOut.Data, NetOut.CurSize, Cardinal(ENET_PACKET_FLAG_RELIABLE));
216 enet_peer_send(NetMPeer, NET_MCHAN_MAIN, P);
217 enet_host_flush(NetMHost);
219 while enet_host_service(NetMHost, @NetMEvent, 5000) > 0 do
220 begin
221 if NetMEvent.kind = ENET_EVENT_TYPE_RECEIVE then
222 begin
223 if not InMsg.Init(NetMEvent.packet^.data, NetMEvent.packet^.dataLength, True) then continue;
225 MID := InMsg.ReadByte();
227 if MID <> NET_MMSG_GET then continue;
229 Cnt := InMsg.ReadByte();
230 g_Console_Add(_lc[I_NET_MSG] + Format(_lc[I_NET_SLIST_RETRIEVED], [Cnt]), True);
232 if Cnt > 0 then
233 begin
234 SetLength(SL, Cnt);
236 for I := 0 to Cnt - 1 do
237 begin
238 SL[I].Number := I;
239 SL[I].IP := InMsg.ReadString();
240 SL[I].Port := InMsg.ReadWord();
241 SL[I].Name := InMsg.ReadString();
242 SL[I].Map := InMsg.ReadString();
243 SL[I].GameMode := InMsg.ReadByte();
244 SL[I].Players := InMsg.ReadByte();
245 SL[I].MaxPlayers := InMsg.ReadByte();
246 SL[I].Protocol := InMsg.ReadByte();
247 SL[I].Password := InMsg.ReadByte() = 1;
248 enet_address_set_host(Addr(SL[I].PingAddr), PChar(Addr(SL[I].IP[1])));
249 SL[I].Ping := -1;
250 SL[I].PingAddr.port := NET_PING_PORT;
251 end;
252 end;
254 Result := True;
255 break;
256 end;
257 end;
259 g_Net_Slist_Disconnect;
260 NetOut.Clear();
262 if Length(SL) = 0 then
263 begin
264 CheckLocalServers();
265 Exit;
266 end;
268 Sock := enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM);
269 if Sock = ENET_SOCKET_NULL then Exit;
270 enet_socket_set_option(Sock, ENET_SOCKOPT_NONBLOCK, 1);
272 for I := Low(SL) to High(SL) do
273 PingServer(SL[I], Sock);
275 enet_socket_set_option(Sock, ENET_SOCKOPT_BROADCAST, 1);
276 PingBcast(Sock);
278 T := GetTimerMS();
280 InMsg.Alloc(NET_BUFSIZE);
281 Buf.data := InMsg.Data;
282 Buf.dataLength := InMsg.MaxSize;
283 Cnt := 0;
284 while GetTimerMS() - T <= 500 do
285 begin
286 InMsg.Clear();
288 RX := enet_socket_receive(Sock, @SvAddr, @Buf, 1);
289 if RX <= 0 then continue;
290 InMsg.CurSize := RX;
292 InMsg.BeginReading();
294 if InMsg.ReadChar() <> 'D' then continue;
295 if InMsg.ReadChar() <> 'F' then continue;
297 FromSL := False;
298 for I := Low(SL) to High(SL) do
299 if (SL[I].PingAddr.host = SvAddr.host) and
300 (SL[I].PingAddr.port = SvAddr.port) then
301 begin
302 with SL[I] do
303 begin
304 Port := InMsg.ReadWord();
305 Ping := InMsg.ReadInt64();
306 Ping := GetTimerMS() - Ping;
307 Name := InMsg.ReadString();
308 Map := InMsg.ReadString();
309 GameMode := InMsg.ReadByte();
310 Players := InMsg.ReadByte();
311 MaxPlayers := InMsg.ReadByte();
312 Protocol := InMsg.ReadByte();
313 Password := InMsg.ReadByte() = 1;
314 LocalPl := InMsg.ReadByte();
315 Bots := InMsg.ReadWord();
316 end;
317 FromSL := True;
318 Inc(Cnt);
319 break;
320 end;
321 if not FromSL then
322 ProcessLocal();
323 end;
325 InMsg.Free();
326 enet_socket_destroy(Sock);
327 end;
329 procedure g_Net_Slist_WriteInfo();
330 var
331 Wad, Map: string;
332 Cli: Byte;
333 begin
334 Wad := g_ExtractWadNameNoPath(gMapInfo.Map);
335 Map := g_ExtractFileName(gMapInfo.Map);
337 NetOut.Write(NetServerName);
339 NetOut.Write(Wad + ':\' + Map);
340 NetOut.Write(gGameSettings.GameMode);
342 Cli := NetClientCount;
343 NetOut.Write(Cli);
345 NetOut.Write(NetMaxClients);
347 NetOut.Write(Byte(NET_PROTOCOL_VER));
348 NetOut.Write(Byte(NetPassword <> ''));
349 end;
351 procedure g_Net_Slist_Update;
352 var
354 P: pENetPacket;
356 begin
357 if (NetMHost = nil) or (NetMPeer = nil) then Exit;
359 NetOut.Clear();
360 NetOut.Write(Byte(NET_MMSG_UPD));
361 NetOut.Write(NetAddr.port);
363 g_Net_Slist_WriteInfo();
365 P := enet_packet_create(NetOut.Data, NetOut.CurSize, Cardinal(ENET_PACKET_FLAG_RELIABLE));
366 enet_peer_send(NetMPeer, NET_MCHAN_UPD, P);
368 enet_host_flush(NetMHost);
369 NetOut.Clear();
370 end;
372 procedure g_Net_Slist_Remove;
373 var
374 P: pENetPacket;
375 begin
376 if (NetMHost = nil) or (NetMPeer = nil) then Exit;
377 NetOut.Clear();
378 NetOut.Write(Byte(NET_MMSG_DEL));
379 NetOut.Write(NetAddr.port);
381 P := enet_packet_create(NetOut.Data, NetOut.CurSize, Cardinal(ENET_PACKET_FLAG_RELIABLE));
382 enet_peer_send(NetMPeer, NET_MCHAN_MAIN, P);
384 enet_host_flush(NetMHost);
385 NetOut.Clear();
386 end;
388 function g_Net_Slist_Connect: Boolean;
389 begin
390 Result := False;
392 NetMHost := enet_host_create(nil, 1, NET_MCHANS, 0, 0);
393 if (NetMHost = nil) then
394 begin
395 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CLIENT], True);
396 Exit;
397 end;
399 NetMPeer := enet_host_connect(NetMHost, @NetSlistAddr, NET_MCHANS, 0);
400 if (NetMPeer = nil) then
401 begin
402 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CLIENT], True);
403 enet_host_destroy(NetMHost);
404 NetMHost := nil;
405 Exit;
406 end;
408 if (enet_host_service(NetMHost, @NetMEvent, 3000) > 0) then
409 if NetMEvent.kind = ENET_EVENT_TYPE_CONNECT then
410 begin
411 Result := True;
412 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_SLIST_CONN]);
413 Exit;
414 end
415 else
416 if NetMEvent.kind = ENET_EVENT_TYPE_RECEIVE then
417 enet_packet_destroy(NetMEvent.packet);
419 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_SLIST_ERROR], True);
421 NetMHost := nil;
422 NetMPeer := nil;
423 end;
425 procedure g_Net_Slist_Disconnect;
426 begin
427 if (NetMHost = nil) and (NetMPeer = nil) then Exit;
429 if NetMode = NET_SERVER then g_Net_Slist_Remove;
431 enet_peer_disconnect(NetMPeer, 0);
432 enet_host_flush(NetMHost);
434 enet_peer_reset(NetMPeer);
435 enet_host_destroy(NetMHost);
437 NetMPeer := nil;
438 NetMHost := nil;
440 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_SLIST_DISC]);
441 end;
443 procedure g_Net_Slist_Check;
444 begin
445 if (NetMHost = nil) or (NetMPeer = nil) then Exit;
447 while (enet_host_service(NetMHost, @NetMEvent, 0) > 0) do
448 begin
449 if NetMEvent.kind = ENET_EVENT_TYPE_DISCONNECT then
450 begin
451 g_Console_Add(_lc[I_NET_MSG] + _lc[I_NET_SLIST_LOST], True);
452 if NetMPeer <> nil then enet_peer_reset(NetMPeer);
453 if NetMHost <> nil then enet_host_destroy(NetMHost);
454 NetMPeer := nil;
455 NetMHost := nil;
456 Break;
457 end
458 else
459 if NetMEvent.kind = ENET_EVENT_TYPE_RECEIVE then
460 enet_packet_destroy(NetMEvent.packet);
461 end;
462 end;
464 procedure g_Net_Slist_Set(IP: string; Port: Word);
465 begin
466 if NetInitDone then
467 begin
468 enet_address_set_host(@NetSlistAddr, PChar(Addr(IP[1])));
469 NetSlistAddr.Port := Port;
470 e_WriteLog('Masterserver address set to ' + IP + ':' + IntToStr(Port), TMsgType.Notify);
471 end;
472 end;
474 procedure g_Serverlist_Draw(var SL: TNetServerList);
475 var
476 sy, i, y, mw, mx, l: Integer;
477 cw: Byte = 0;
478 ch: Byte = 0;
479 ww: Word = 0;
480 hh: Word = 0;
481 ip: string;
482 begin
483 ip := '';
484 sy := 0;
486 e_CharFont_GetSize(gMenuFont, _lc[I_NET_SLIST], ww, hh);
487 e_CharFont_Print(gMenuFont, (gScreenWidth div 2) - (ww div 2), 16, _lc[I_NET_SLIST]);
489 e_TextureFontGetSize(gStdFont, cw, ch);
491 ip := _lc[I_NET_SLIST_HELP];
492 mw := (Length(ip) * cw) div 2;
494 e_DrawFillQuad(16, 64, gScreenWidth-16, gScreenHeight-44, 64, 64, 64, 110);
495 e_DrawQuad(16, 64, gScreenWidth-16, gScreenHeight-44, 255, 127, 0);
497 e_TextureFontPrintEx(gScreenWidth div 2 - mw, gScreenHeight-24, ip, gStdFont, 225, 225, 225, 1);
499 if SL = nil then
500 begin
501 l := Length(slWaitStr) div 2;
502 e_DrawFillQuad(16, 64, gScreenWidth-16, gScreenHeight-44, 64, 64, 64, 128);
503 e_DrawQuad(gScreenWidth div 2 - 192, gScreenHeight div 2 - 10,
504 gScreenWidth div 2 + 192, gScreenHeight div 2 + 11, 255, 127, 0);
505 e_TextureFontPrint(gScreenWidth div 2 - cw * l, gScreenHeight div 2 - ch div 2,
506 slWaitStr, gStdFont);
507 Exit;
508 end;
510 y := 90;
511 if (slSelection < Length(SL)) then
512 begin
513 I := slSelection;
514 sy := y + 42 * I - 4;
515 ip := _lc[I_NET_ADDRESS] + ' ' + SL[I].IP + ':' + IntToStr(SL[I].Port);
516 if SL[I].Password then
517 ip := ip + ' ' + _lc[I_NET_SERVER_PASSWORD] + ' ' + _lc[I_MENU_YES]
518 else
519 ip := ip + ' ' + _lc[I_NET_SERVER_PASSWORD] + ' ' + _lc[I_MENU_NO];
520 end else
521 if Length(SL) > 0 then
522 slSelection := 0;
524 mw := (gScreenWidth - 188);
525 mx := 16 + mw;
527 e_DrawFillQuad(16 + 1, sy, gScreenWidth - 16 - 1, sy + 40, 64, 64, 64, 0);
528 e_DrawLine(1, 16 + 1, sy, gScreenWidth - 16 - 1, sy, 205, 205, 205);
529 e_DrawLine(1, 16 + 1, sy + 41, gScreenWidth - 16 - 1, sy + 41, 255, 255, 255);
531 e_DrawLine(1, 16, 85, gScreenWidth - 16, 85, 255, 127, 0);
532 e_DrawLine(1, 16, gScreenHeight-64, gScreenWidth-16, gScreenHeight-64, 255, 127, 0);
534 e_DrawLine(1, mx - 70, 64, mx - 70, gScreenHeight-44, 255, 127, 0);
535 e_DrawLine(1, mx, 64, mx, gScreenHeight-64, 255, 127, 0);
536 e_DrawLine(1, mx + 52, 64, mx + 52, gScreenHeight-64, 255, 127, 0);
537 e_DrawLine(1, mx + 104, 64, mx + 104, gScreenHeight-64, 255, 127, 0);
539 e_TextureFontPrintEx(18, 68, 'NAME/MAP', gStdFont, 255, 127, 0, 1);
541 y := 90;
542 for I := 0 to High(SL) do
543 begin
544 e_TextureFontPrintEx(18, y, SL[I].Name, gStdFont, 255, 255, 255, 1);
545 e_TextureFontPrintEx(18, y + 16, SL[I].Map, gStdFont, 210, 210, 210, 1);
547 y := y + 42;
548 end;
550 e_TextureFontPrintEx(mx - 68, 68, 'PING', gStdFont, 255, 127, 0, 1);
551 y := 90;
552 for I := 0 to High(SL) do
553 begin
554 if (SL[I].Ping < 0) or (SL[I].Ping > 999) then
555 e_TextureFontPrintEx(mx - 68, y, _lc[I_NET_SLIST_NO_ACCESS], gStdFont, 255, 0, 0, 1)
556 else
557 if SL[I].Ping = 0 then
558 e_TextureFontPrintEx(mx - 68, y, '<1' + _lc[I_NET_SLIST_PING_MS], gStdFont, 255, 255, 255, 1)
559 else
560 e_TextureFontPrintEx(mx - 68, y, IntToStr(SL[I].Ping) + _lc[I_NET_SLIST_PING_MS], gStdFont, 255, 255, 255, 1);
562 y := y + 42;
563 end;
565 e_TextureFontPrintEx(mx + 2, 68, 'MODE', gStdFont, 255, 127, 0, 1);
566 y := 90;
567 for I := 0 to High(SL) do
568 begin
569 e_TextureFontPrintEx(mx + 2, y, g_Game_ModeToText(SL[I].GameMode), gStdFont, 255, 255, 255, 1);
571 y := y + 42;
572 end;
574 e_TextureFontPrintEx(mx + 54, 68, 'PLRS', gStdFont, 255, 127, 0, 1);
575 y := 90;
576 for I := 0 to High(SL) do
577 begin
578 e_TextureFontPrintEx(mx + 54, y, IntToStr(SL[I].Players) + '/' + IntToStr(SL[I].MaxPlayers), gStdFont, 255, 255, 255, 1);
579 e_TextureFontPrintEx(mx + 54, y + 16, IntToStr(SL[I].LocalPl) + '+' + IntToStr(SL[I].Bots), gStdFont, 210, 210, 210, 1);
580 y := y + 42;
581 end;
583 e_TextureFontPrintEx(mx + 106, 68, 'VER', gStdFont, 255, 127, 0, 1);
584 y := 90;
585 for I := 0 to High(SL) do
586 begin
587 e_TextureFontPrintEx(mx + 106, y, IntToStr(SL[I].Protocol), gStdFont, 255, 255, 255, 1);
589 y := y + 42;
590 end;
592 e_TextureFontPrintEx(20, gScreenHeight-61, ip, gStdFont, 205, 205, 205, 1);
593 ip := IntToStr(Length(SL)) + _lc[I_NET_SLIST_SERVERS];
594 e_TextureFontPrintEx(gScreenWidth - 48 - (Length(ip) + 1)*cw,
595 gScreenHeight-61, ip, gStdFont, 205, 205, 205, 1);
596 end;
598 procedure g_Serverlist_Control(var SL: TNetServerList);
599 var
600 qm: Boolean;
601 begin
602 if gConsoleShow or gChatShow then
603 Exit;
605 qm := g_ProcessMessages(); // this updates kbd
607 if qm or e_KeyPressed(IK_ESCAPE) or e_KeyPressed(VK_ESCAPE) then
608 begin
609 SL := nil;
610 gState := STATE_MENU;
611 g_GUI_ShowWindow('MainMenu');
612 g_GUI_ShowWindow('NetGameMenu');
613 g_GUI_ShowWindow('NetClientMenu');
614 g_Sound_PlayEx(WINDOW_CLOSESOUND);
615 Exit;
616 end;
618 if e_KeyPressed(IK_SPACE) or e_KeyPressed(VK_JUMP) then
619 begin
620 if not slFetched then
621 begin
622 slWaitStr := _lc[I_NET_SLIST_WAIT];
624 g_Game_Draw;
625 g_window.ReDrawWindow;
627 if g_Net_Slist_Fetch(SL) then
628 begin
629 if SL = nil then
630 slWaitStr := _lc[I_NET_SLIST_NOSERVERS];
631 end
632 else
633 if SL = nil then
634 slWaitStr := _lc[I_NET_SLIST_ERROR];
635 slFetched := True;
636 slSelection := 0;
637 end;
638 end
639 else
640 slFetched := False;
642 if SL = nil then Exit;
644 if e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) then
645 begin
646 if not slReturnPressed then
647 begin
648 if SL[slSelection].Password then
649 begin
650 PromptIP := SL[slSelection].IP;
651 PromptPort := SL[slSelection].Port;
652 gState := STATE_MENU;
653 g_GUI_ShowWindow('ClientPasswordMenu');
654 SL := nil;
655 slReturnPressed := True;
656 Exit;
657 end
658 else
659 g_Game_StartClient(SL[slSelection].IP, SL[slSelection].Port, '');
660 SL := nil;
661 slReturnPressed := True;
662 Exit;
663 end;
664 end
665 else
666 slReturnPressed := False;
668 if e_KeyPressed(IK_DOWN) or e_KeyPressed(IK_KPDOWN) or e_KeyPressed(VK_DOWN) then
669 begin
670 if not slDirPressed then
671 begin
672 Inc(slSelection);
673 if slSelection > High(SL) then slSelection := 0;
674 slDirPressed := True;
675 end;
676 end;
678 if e_KeyPressed(IK_UP) or e_KeyPressed(IK_KPUP) or e_KeyPressed(VK_UP) then
679 begin
680 if not slDirPressed then
681 begin
682 if slSelection = 0 then slSelection := Length(SL);
683 Dec(slSelection);
685 slDirPressed := True;
686 end;
687 end;
689 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
690 slDirPressed := False;
691 end;
693 end.