1 /**********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
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 2, or (at your option)
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 ***********************************************************************/
15 #include <fc_config.h>
22 #include <X11/Intrinsic.h>
23 #include <X11/StringDefs.h>
24 #include <X11/Xaw/Form.h>
25 #include <X11/Xaw/Label.h>
26 #include <X11/Xaw/SimpleMenu.h>
27 #include <X11/Xaw/Command.h>
28 #include <X11/Xaw/AsciiText.h>
29 #include <X11/Xaw/List.h>
30 #include <X11/Xaw/Viewport.h>
32 /* common & utility */
35 #include "mem.h" /* fc_strdup() */
40 #include "client_main.h"
41 #include "clinet.h" /* connect_to_server() */
47 #include "gui_stuff.h"
50 #include "connectdlg_common.h"
51 #include "connectdlg.h"
54 enum connection_state
{
61 static enum connection_state connection_status
;
64 static Widget connectdlg_shell
;
65 static Widget connectdlg_form
;
67 static Widget connectdlg_beta_label
;
69 static Widget connectdlg_select_label
;
70 static Widget connectdlg_host_label
;
71 static Widget connectdlg_host_text
;
72 static Widget connectdlg_port_label
;
73 static Widget connectdlg_port_text
;
74 static Widget connectdlg_login_label
;
75 static Widget connectdlg_login_text
;
76 static Widget connectdlg_password_label
;
77 static Widget connectdlg_password_text
;
78 static Widget connectdlg_verify_label
;
79 static Widget connectdlg_verify_text
;
80 static Widget connectdlg_message_label
;
81 static Widget connectdlg_connect_button
;
82 static Widget connectdlg_lan_button
;
83 static Widget connectdlg_meta_button
;
84 static Widget connectdlg_quit_button
;
86 void connectdlg_connect_callback(Widget w
, XtPointer client_data
,
88 void connectdlg_lan_callback(Widget w
, XtPointer client_data
,
90 void connectdlg_meta_callback(Widget w
, XtPointer client_data
,
92 void connectdlg_quit_callback(Widget w
, XtPointer client_data
,
95 /****************************************************************/
98 static Widget connectdlg_serverlist_shell
;
100 static Widget connectdlg_serverlist_form
;
101 static Widget connectdlg_serverlist_legend_label
;
102 static Widget connectdlg_serverlist_viewport
;
103 static Widget connectdlg_serverlist_list
;
104 static Widget connectdlg_serverlist_update_button
;
105 static Widget connectdlg_serverlist_close_button
;
107 static struct server_scan
*lan_scan
, *meta_scan
;
109 void connectdlg_serverlist_popup(void);
110 void server_scan_error(struct server_scan
*scan
, const char *message
);
111 void connectdlg_serverlist_update_callback(Widget w
, XtPointer client_data
,
112 XtPointer call_data
);
113 void connectdlg_serverlist_close_callback(Widget w
, XtPointer client_data
,
114 XtPointer call_data
);
115 void connectdlg_serverlist_list_callback(Widget w
, XtPointer client_data
,
116 XtPointer call_data
);
118 /* FIXME: Replace magic 64 with proper constant. */
119 static char *servers_list
[64]={NULL
};
121 static void server_list_timer(XtPointer client_data
, XtIntervalId
* id
);
122 static int get_server_list(char **list
, char *errbuf
, int n_errbuf
);
124 static bool lan_mode
; /* true for LAN mode, false when Meta mode */
125 static int num_lanservers_timer
= 0;
128 /****************************************************************************
129 Aligns widths of connect dialog labels and texts.
130 ****************************************************************************/
131 static void connectdlg_align_labels(void)
133 Dimension width
, s_width
, t_width
, max_width
= 0;
136 XtVaGetValues(connectdlg_beta_label
, XtNwidth
, &width
, NULL
);
140 XtVaGetValues(connectdlg_select_label
, XtNwidth
, &width
, NULL
);
141 if (width
> max_width
) {
144 XtVaGetValues(connectdlg_message_label
, XtNwidth
, &width
, NULL
);
145 if (width
> max_width
) {
149 /* FIXME: Replace 7 with proper XtN* variable value */
150 XtVaGetValues(connectdlg_host_label
, XtNwidth
, &width
, NULL
);
151 XtVaGetValues(connectdlg_host_text
, XtNwidth
, &t_width
, NULL
);
153 if (width
+ 7 + t_width
> max_width
) {
154 max_width
= width
+ 7 + t_width
;
156 XtVaGetValues(connectdlg_port_label
, XtNwidth
, &width
, NULL
);
157 XtVaGetValues(connectdlg_port_text
, XtNwidth
, &t_width
, NULL
);
158 if (width
> s_width
) {
161 if (width
+ 7 + t_width
> max_width
) {
162 max_width
= width
+ 7 + t_width
;
164 XtVaGetValues(connectdlg_login_label
, XtNwidth
, &width
, NULL
);
165 XtVaGetValues(connectdlg_login_text
, XtNwidth
, &t_width
, NULL
);
166 if (width
> s_width
) {
169 if (width
+ 7 + t_width
> max_width
) {
170 max_width
= width
+ 7 + t_width
;
172 XtVaGetValues(connectdlg_password_label
, XtNwidth
, &width
, NULL
);
173 XtVaGetValues(connectdlg_password_text
, XtNwidth
, &t_width
, NULL
);
174 if (width
> s_width
) {
177 if (width
+ 7 + t_width
> max_width
) {
178 max_width
= width
+ 7 + t_width
;
180 XtVaGetValues(connectdlg_verify_label
, XtNwidth
, &width
, NULL
);
181 XtVaGetValues(connectdlg_verify_text
, XtNwidth
, &t_width
, NULL
);
182 if (width
> s_width
) {
185 if (width
+ 7 + t_width
> max_width
) {
186 max_width
= width
+ 7 + t_width
;
190 XtVaSetValues(connectdlg_beta_label
, XtNwidth
, max_width
, NULL
);
192 XtVaSetValues(connectdlg_select_label
, XtNwidth
, max_width
, NULL
);
193 XtVaSetValues(connectdlg_message_label
, XtNwidth
, max_width
, NULL
);
194 XtVaSetValues(connectdlg_message_label
, XtNresizable
, False
, NULL
);
196 XtVaSetValues(connectdlg_host_label
, XtNwidth
, s_width
, NULL
);
197 XtVaSetValues(connectdlg_port_label
, XtNwidth
, s_width
, NULL
);
198 XtVaSetValues(connectdlg_login_label
, XtNwidth
, s_width
, NULL
);
199 XtVaSetValues(connectdlg_password_label
, XtNwidth
, s_width
, NULL
);
200 XtVaSetValues(connectdlg_verify_label
, XtNwidth
, s_width
, NULL
);
202 XtVaSetValues(connectdlg_host_text
, XtNresizable
, True
, NULL
);
203 XtVaSetValues(connectdlg_host_text
, XtNwidth
, max_width
- s_width
- 7,
205 XtVaSetValues(connectdlg_host_text
, XtNresizable
, False
, NULL
);
206 XtVaSetValues(connectdlg_port_text
, XtNresizable
, True
, NULL
);
207 XtVaSetValues(connectdlg_port_text
, XtNwidth
, max_width
- s_width
- 7,
209 XtVaSetValues(connectdlg_port_text
, XtNresizable
, False
, NULL
);
210 XtVaSetValues(connectdlg_login_text
, XtNresizable
, True
, NULL
);
211 XtVaSetValues(connectdlg_login_text
, XtNwidth
, max_width
- s_width
- 7,
213 XtVaSetValues(connectdlg_login_text
, XtNresizable
, False
, NULL
);
214 XtVaSetValues(connectdlg_password_text
, XtNresizable
, True
, NULL
);
215 XtVaSetValues(connectdlg_password_text
, XtNwidth
, max_width
- s_width
- 7,
217 XtVaSetValues(connectdlg_password_text
, XtNresizable
, False
, NULL
);
218 XtVaSetValues(connectdlg_verify_text
, XtNresizable
, True
, NULL
);
219 XtVaSetValues(connectdlg_verify_text
, XtNwidth
, max_width
- s_width
- 7,
221 XtVaSetValues(connectdlg_verify_text
, XtNresizable
, False
, NULL
);
224 /**************************************************************************
225 Creates connect dialog.
226 **************************************************************************/
227 static void connectdlg_create(void)
231 if (connectdlg_shell
) {
236 I_IN(I_T(XtCreatePopupShell("connectdialog", topLevelShellWidgetClass
,
237 toplevel
, NULL
, 0)));
239 XtVaCreateManagedWidget("connectform", formWidgetClass
,
240 connectdlg_shell
, NULL
);
243 connectdlg_beta_label
=
244 I_L(XtVaCreateManagedWidget("connbetalabel", labelWidgetClass
,
247 XtNjustify
, XtJustifyCenter
,
248 XtNlabel
, beta_message(),
252 connectdlg_select_label
=
253 I_L(XtVaCreateManagedWidget("connselectlabel", labelWidgetClass
,
257 XtNfromVert
, connectdlg_beta_label
,
261 connectdlg_host_label
=
262 I_L(XtVaCreateManagedWidget("connhostlabel", labelWidgetClass
,
266 connectdlg_host_text
=
267 XtVaCreateManagedWidget("connhosttext", asciiTextWidgetClass
,
269 XtNeditType
, XawtextEdit
,
270 XtNstring
, server_host
,
272 connectdlg_port_label
=
273 I_L(XtVaCreateManagedWidget("connportlabel", labelWidgetClass
,
277 fc_snprintf(buf
, sizeof(buf
), "%d", server_port
);
278 connectdlg_port_text
=
279 XtVaCreateManagedWidget("connporttext", asciiTextWidgetClass
,
281 XtNeditType
, XawtextEdit
,
284 connectdlg_login_label
=
285 I_L(XtVaCreateManagedWidget("connloginlabel", labelWidgetClass
,
289 connectdlg_login_text
=
290 XtVaCreateManagedWidget("connlogintext", asciiTextWidgetClass
,
292 XtNeditType
, XawtextEdit
,
293 XtNstring
, user_name
,
295 connectdlg_password_label
=
296 I_L(XtVaCreateManagedWidget("connpasswordlabel", labelWidgetClass
,
300 connectdlg_password_text
=
301 XtVaCreateManagedWidget("connpasswordtext", asciiTextWidgetClass
,
306 connectdlg_verify_label
=
307 I_L(XtVaCreateManagedWidget("connverifylabel", labelWidgetClass
,
311 connectdlg_verify_text
=
312 XtVaCreateManagedWidget("connverifytext", asciiTextWidgetClass
,
317 connectdlg_message_label
=
318 I_L(XtVaCreateManagedWidget("connmessagelabel", labelWidgetClass
,
323 connectdlg_connect_button
=
324 I_L(XtVaCreateManagedWidget("connconnectbutton", commandWidgetClass
,
326 XtNlabel
, _("Connect"),
328 connectdlg_lan_button
=
329 I_L(XtVaCreateManagedWidget("connlanbutton", commandWidgetClass
,
331 XtNlabel
, _("LAN Servers"),
333 connectdlg_meta_button
=
334 I_L(XtVaCreateManagedWidget("connmetabutton", commandWidgetClass
,
336 XtNlabel
, _("Metaserver"),
338 connectdlg_quit_button
=
339 I_L(XtVaCreateManagedWidget("connquitbutton", commandWidgetClass
,
344 XtAddCallback(connectdlg_connect_button
, XtNcallback
,
345 connectdlg_connect_callback
, NULL
);
346 XtAddCallback(connectdlg_lan_button
, XtNcallback
,
347 connectdlg_lan_callback
, NULL
);
348 XtAddCallback(connectdlg_meta_button
, XtNcallback
,
349 connectdlg_meta_callback
, NULL
);
350 XtAddCallback(connectdlg_quit_button
, XtNcallback
,
351 connectdlg_quit_callback
, NULL
);
353 XtRealizeWidget(connectdlg_shell
);
356 /**************************************************************************
357 Popdowns connect dialog.
358 **************************************************************************/
359 static void connectdlg_popdown(void)
362 server_scan_finish(lan_scan
);
366 server_scan_finish(meta_scan
);
369 if (connectdlg_shell
) {
370 XtPopdown(connectdlg_shell
);
374 /**************************************************************************
375 Destroys connect dialog.
376 **************************************************************************/
377 static void connectdlg_destroy(void)
379 if (connectdlg_shell
) {
380 connectdlg_popdown();
381 XtDestroyWidget(connectdlg_shell
);
382 connectdlg_shell
= NULL
;
386 /**************************************************************************
387 Popups connect dialog.
388 **************************************************************************/
389 static void connectdlg_popup(void)
391 if (!connectdlg_shell
) {
395 connectdlg_align_labels();
396 xaw_set_relative_position(toplevel
, connectdlg_shell
, 20, 20);
397 XtPopup(connectdlg_shell
, XtGrabNone
);
400 /****************************************************************************
401 Callback for Connect button.
402 ****************************************************************************/
403 void connectdlg_connect_callback(Widget w
, XtPointer client_data
,
408 struct packet_authentication_reply reply
;
410 switch (connection_status
) {
412 XtVaGetValues(connectdlg_host_text
, XtNstring
, &pxp
, NULL
);
413 sz_strlcpy(server_host
, (char *)pxp
);
414 XtVaGetValues(connectdlg_port_text
, XtNstring
, &pxp
, NULL
);
415 sscanf((char *)pxp
, "%d", &server_port
);
416 XtVaGetValues(connectdlg_login_text
, XtNstring
, &pxp
, NULL
);
417 sz_strlcpy(user_name
, (char *)pxp
);
418 if (connect_to_server(user_name
, server_host
, server_port
,
419 errbuf
, sizeof(errbuf
)) != -1) {
421 connectdlg_destroy();
422 XtSetSensitive(toplevel
, True
);
425 XtVaSetValues(connectdlg_message_label
, XtNlabel
, errbuf
, NULL
);
426 output_window_append(ftc_client
, errbuf
);
429 case NEW_PASSWORD_TYPE
:
430 XtVaGetValues(connectdlg_password_text
, XtNstring
, &pxp
, NULL
);
431 sz_strlcpy(password
, (char *)pxp
);
432 XtVaGetValues(connectdlg_verify_text
, XtNstring
, &pxp
, NULL
);
433 sz_strlcpy(reply
.password
, (char *)pxp
);
434 if (strncmp(reply
.password
, password
, MAX_LEN_NAME
) == 0) {
436 send_packet_authentication_reply(&client
.conn
, &reply
);
437 XtVaSetValues(connectdlg_message_label
, XtNlabel
, "", NULL
);
438 XtVaSetValues(connectdlg_password_text
, XtNsensitive
, False
, NULL
);
439 XtVaSetValues(connectdlg_verify_text
, XtNsensitive
, False
, NULL
);
441 XtVaSetValues(connectdlg_password_text
, XtNstring
, "", NULL
);
442 XtVaSetValues(connectdlg_verify_text
, XtNstring
, "", NULL
);
443 XtVaSetValues(connectdlg_message_label
, XtNlabel
,
444 _("Passwords don't match, enter password."), NULL
);
445 output_window_append(ftc_client
,
446 _("Passwords don't match, enter password."));
449 case ENTER_PASSWORD_TYPE
:
450 XtVaGetValues(connectdlg_verify_text
, XtNstring
, &pxp
, NULL
);
451 sz_strlcpy(reply
.password
, (char *)pxp
);
452 send_packet_authentication_reply(&client
.conn
, &reply
);
454 XtVaSetValues(connectdlg_message_label
, XtNlabel
, "", NULL
);
455 XtVaSetValues(connectdlg_password_text
, XtNsensitive
, False
, NULL
);
456 XtVaSetValues(connectdlg_verify_text
, XtNsensitive
, False
, NULL
);
463 /****************************************************************************
464 Callback fir LAN Servers button.
465 ****************************************************************************/
466 void connectdlg_lan_callback(Widget w
, XtPointer client_data
,
471 lan_scan
= server_scan_begin(SERVER_SCAN_LOCAL
, server_scan_error
);
473 connectdlg_serverlist_popup();
476 /****************************************************************************
477 Callback for Metaserver button.
478 ****************************************************************************/
479 void connectdlg_meta_callback(Widget w
, XtPointer client_data
,
484 meta_scan
= server_scan_begin(SERVER_SCAN_GLOBAL
, server_scan_error
);
486 connectdlg_serverlist_popup();
489 /****************************************************************************
490 Callback for Quit button.
491 ****************************************************************************/
492 void connectdlg_quit_callback(Widget w
, XtPointer client_data
,
495 connectdlg_destroy();
499 /**************************************************************************
500 configure the dialog depending on what type of authentication request the
502 **************************************************************************/
503 void handle_authentication_req(enum authentication_type type
,
506 XtVaSetValues(connectdlg_message_label
, XtNlabel
, message
, NULL
);
509 case AUTH_NEWUSER_FIRST
:
510 case AUTH_NEWUSER_RETRY
:
511 XtVaSetValues(connectdlg_password_text
, XtNsensitive
, True
, NULL
);
512 XtVaSetValues(connectdlg_verify_text
, XtNsensitive
, True
, NULL
);
513 connection_status
= NEW_PASSWORD_TYPE
;
515 case AUTH_LOGIN_FIRST
:
516 /* if we magically have a password already present in 'password'
517 * then, use that and skip the password entry dialog */
518 if (password
[0] != '\0') {
519 struct packet_authentication_reply reply
;
521 sz_strlcpy(reply
.password
, password
);
522 send_packet_authentication_reply(&client
.conn
, &reply
);
525 XtVaSetValues(connectdlg_password_text
, XtNsensitive
, True
, NULL
);
526 XtVaSetValues(connectdlg_verify_text
, XtNsensitive
, False
, NULL
);
527 connection_status
= ENTER_PASSWORD_TYPE
;
530 case AUTH_LOGIN_RETRY
:
531 XtVaSetValues(connectdlg_password_text
, XtNsensitive
, True
, NULL
);
532 XtVaSetValues(connectdlg_verify_text
, XtNsensitive
, False
, NULL
);
533 connection_status
= ENTER_PASSWORD_TYPE
;
536 log_error("Unsupported authentication type %d: %s.", type
, message
);
541 /****************************************************************
542 Provide an interface for connecting to a Freeciv server.
543 *****************************************************************/
544 void server_connect(void)
546 connection_status
= LOGIN_TYPE
;
548 XtSetSensitive(turn_done_button
, FALSE
);
549 /* XtSetSensitive(toplevel, FALSE);*/
556 XtPopup(connectdlg_shell, XtGrabNone);
557 XtSetKeyboardFocus(toplevel, connectdlg_shell);
562 /**************************************************************************
563 this regenerates the player information from a loaded game on the server.
564 currently a stub. TODO
565 **************************************************************************/
566 void handle_game_load(bool load_successful
, const char *filename
)
571 /****************************************************************
573 *****************************************************************/
574 void connectdlg_key_connect(Widget w
)
576 x_simulate_button_click(connectdlg_connect_button
);
579 /****************************************************************************
581 ****************************************************************************/
583 /****************************************************************************
584 Callback function for when there's an error in the server scan.
585 ****************************************************************************/
586 void server_scan_error(struct server_scan
*scan
, const char *message
)
588 output_window_append(ftc_client
, message
);
589 log_normal("%s", message
);
590 switch (server_scan_get_type(scan
)) {
591 case SERVER_SCAN_LOCAL
:
592 server_scan_finish(lan_scan
);
595 case SERVER_SCAN_GLOBAL
:
596 server_scan_finish(meta_scan
);
599 case SERVER_SCAN_LAST
:
604 /****************************************************************************
605 This function updates the list of servers after the server dialog has been
606 displayed. LAN servers updated every 250 ms for 5 seconds, metaserver
607 updated every 500 ms for 2 seconds.
608 ****************************************************************************/
609 static void server_list_timer(XtPointer meta_list
, XtIntervalId
* id
)
613 if (!connectdlg_serverlist_shell
) {
617 if (get_server_list(servers_list
, errbuf
, sizeof(errbuf
)) != -1) {
618 XawListChange(meta_list
, servers_list
, 0, 0, True
);
621 else if (!lan_mode) {
622 output_window_append(ftc_client, errbuf);
625 num_lanservers_timer
++;
628 if (num_lanservers_timer
== 20) {
629 server_scan_finish(lan_scan
);
631 num_lanservers_timer
= 0;
634 (void)XtAppAddTimeOut(app_context
, 250, server_list_timer
,
635 (XtPointer
)meta_list
);
637 if (num_lanservers_timer
== 4) {
638 server_scan_finish(meta_scan
);
640 num_lanservers_timer
= 0;
643 (void)XtAppAddTimeOut(app_context
, 500, server_list_timer
,
644 (XtPointer
)meta_list
);
648 /****************************************************************************
649 Creates Servers List dialog.
650 ****************************************************************************/
651 static void connectdlg_serverlist_create(void)
653 connectdlg_serverlist_shell
=
654 I_IN(I_T(XtCreatePopupShell("serverlistdialog",
655 topLevelShellWidgetClass
,
656 toplevel
, NULL
, 0)));
658 connectdlg_serverlist_form
=
659 XtVaCreateManagedWidget("serverlistform", formWidgetClass
,
660 connectdlg_serverlist_shell
, NULL
);
661 connectdlg_serverlist_legend_label
=
662 I_L(XtVaCreateManagedWidget("legendlabel", labelWidgetClass
,
663 connectdlg_serverlist_form
,
666 connectdlg_serverlist_viewport
=
667 XtVaCreateManagedWidget("viewport", viewportWidgetClass
,
668 connectdlg_serverlist_form
, NULL
);
669 connectdlg_serverlist_list
=
670 XtVaCreateManagedWidget("serverlist", listWidgetClass
,
671 connectdlg_serverlist_viewport
, NULL
);
672 connectdlg_serverlist_update_button
=
673 XtVaCreateManagedWidget("updatebutton", commandWidgetClass
,
674 connectdlg_serverlist_form
,
675 XtNlabel
, _("Update"),
677 connectdlg_serverlist_close_button
=
678 XtVaCreateManagedWidget("closebutton", commandWidgetClass
,
679 connectdlg_serverlist_form
,
680 XtNlabel
, _("Close"),
683 XtAddCallback(connectdlg_serverlist_update_button
, XtNcallback
,
684 connectdlg_serverlist_update_callback
, NULL
);
685 XtAddCallback(connectdlg_serverlist_close_button
, XtNcallback
,
686 connectdlg_serverlist_close_callback
, NULL
);
687 XtAddCallback(connectdlg_serverlist_list
, XtNcallback
,
688 connectdlg_serverlist_list_callback
, NULL
);
690 (void)XtAppAddTimeOut(app_context
, 1, server_list_timer
,
691 (XtPointer
)connectdlg_serverlist_list
);
693 XtRealizeWidget(connectdlg_serverlist_shell
);
696 /****************************************************************************
697 Popups Servers List dialog.
698 ****************************************************************************/
699 void connectdlg_serverlist_popup(void)
701 if (!connectdlg_serverlist_shell
) {
702 connectdlg_serverlist_create();
705 xaw_set_relative_position(toplevel
, connectdlg_serverlist_shell
, 15, 15);
706 XtPopup(connectdlg_serverlist_shell
, XtGrabNone
);
709 /****************************************************************************
710 Destroys Servers List dialog.
711 ****************************************************************************/
712 static void connectdlg_serverlist_destroy(void)
717 server_scan_finish(lan_scan
);
721 server_scan_finish(meta_scan
);
724 /* FIXME: Replace magic 64 with proper constant. */
725 for (i
= 0; i
< 64; i
++) {
726 if (servers_list
[i
]) {
727 free(servers_list
[i
]);
728 servers_list
[i
] = NULL
;
731 if (connectdlg_serverlist_shell
) {
732 XtDestroyWidget(connectdlg_serverlist_shell
);
733 connectdlg_serverlist_shell
= NULL
;
737 /****************************************************************************
738 Callback for Update button.
739 ****************************************************************************/
740 void connectdlg_serverlist_update_callback(Widget w
, XtPointer client_data
,
745 lan_scan
= server_scan_begin(SERVER_SCAN_LOCAL
, server_scan_error
);
747 if (num_lanservers_timer
== 0) {
748 server_list_timer(connectdlg_serverlist_list
, NULL
);
752 meta_scan
= server_scan_begin(SERVER_SCAN_GLOBAL
, server_scan_error
);
754 if (num_lanservers_timer
== 0) {
755 server_list_timer(connectdlg_serverlist_list
, NULL
);
760 /****************************************************************************
761 Callback for Close button.
762 ****************************************************************************/
763 void connectdlg_serverlist_close_callback(Widget w
, XtPointer client_data
,
766 connectdlg_serverlist_destroy();
769 /****************************************************************************
770 Callback for choosing server from serverlist.
771 ****************************************************************************/
772 void connectdlg_serverlist_list_callback(Widget w
, XtPointer client_data
,
775 XawListReturnStruct
*ret
= XawListShowCurrent(w
);
776 char name
[64], port
[16];
778 sscanf(ret
->string
, "%s %s\n", name
, port
);
779 XtVaSetValues(connectdlg_host_text
, XtNstring
, name
, NULL
);
780 XtVaSetValues(connectdlg_port_text
, XtNstring
, port
, NULL
);
783 /**************************************************************************
784 Get the list of servers from the metaserver or LAN servers
785 depending on lan_mode.
786 **************************************************************************/
787 static int get_server_list(char **list
, char *errbuf
, int n_errbuf
)
790 struct srv_list
*srvrs
= NULL
;
791 enum server_scan_status scan_stat
;
795 server_scan_poll(lan_scan
);
796 srvrs
= server_scan_get_list(lan_scan
);
797 fc_allocate_mutex(&srvrs
->mutex
);
798 if (srvrs
->servers
== NULL
) {
801 if (num_lanservers_timer
== 0) {
805 *list
= fc_strdup(" ");
810 fc_release_mutex(&srvrs
->mutex
);
819 scan_stat
= server_scan_poll(meta_scan
);
820 if (scan_stat
>= SCAN_STATUS_PARTIAL
) {
821 srvrs
= server_scan_get_list(meta_scan
);
822 fc_allocate_mutex(&srvrs
->mutex
);
823 if (!srvrs
->servers
) {
824 fc_release_mutex(&srvrs
->mutex
);
825 if (num_lanservers_timer
== 0) {
829 *list
= fc_strdup(" ");
843 server_list_iterate(srvrs
->servers
, pserver
) {
844 if (pserver
== NULL
) {
847 fc_snprintf(line
, sizeof(line
), "%-35s %-5d %-11s %-11s %2d %s",
848 pserver
->host
, pserver
->port
, pserver
->version
,
849 _(pserver
->state
), pserver
->nplayers
, pserver
->message
);
853 *list
= fc_strdup(line
);
855 } server_list_iterate_end
;
857 fc_release_mutex(&srvrs
->mutex
);
861 delete_server_list(server_list);
869 /**************************************************************************
870 Really closes and destroys the dialog.
871 **************************************************************************/
872 void really_close_connection_dialog(void)
877 /**************************************************************************
878 Closes and destroys the dialog.
879 **************************************************************************/
880 void close_connection_dialog()
882 connectdlg_serverlist_destroy();
883 connectdlg_destroy();