Make multiplayer ruleset default to iso topology, to match client default.
[freeciv.git] / client / ggzclient.c
blobe19f77dec0b9a216618cdd8dfa212eb761b18995
1 /**********************************************************************
2 Freeciv - Copyright (C) 2005 - Freeciv Development Team
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)
6 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.
12 ***********************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 /* utility */
19 #include "fciconv.h"
20 #include "fcintl.h"
21 #include "rand.h"
23 /* client/include */
24 #include "gui_main_g.h"
25 #include "ggz_g.h"
27 /* client */
28 #include "clinet.h"
30 #include "ggzclient.h"
32 #ifdef GGZ_CLIENT
33 # include <ggzmod.h>
34 #endif
36 bool with_ggz;
38 /****************************************************************************
39 Initializations for GGZ, including checks to see if we are being run from
40 inside GGZ.
41 ****************************************************************************/
42 void ggz_initialize(void)
44 #ifdef GGZ_CLIENT
45 with_ggz = ggzmod_is_ggz_mode();
47 if (with_ggz) {
48 ggz_begin();
50 #endif
52 gui_ggz_embed_ensure_server();
55 #ifdef GGZ_CLIENT
57 static GGZMod *ggzmod;
59 /****************************************************************************
60 A callback that GGZ calls when we are connected to the freeciv
61 server.
62 ****************************************************************************/
63 static void handle_ggzmod_server(GGZMod * ggzmod, GGZModEvent e,
64 const void *data)
66 const int *socket = data;
67 const char *username = ggzmod_get_player(ggzmod, NULL, NULL);
69 if (!username) {
70 username = "NONE";
72 make_connection(*socket, username);
75 /****************************************************************************
76 Callback for when the GGZ client tells us player stats.
77 ****************************************************************************/
78 static void handle_ggzmod_stats(GGZMod *ggzmod, GGZModEvent e,
79 const void *data)
81 conn_list_dialog_update();
84 /****************************************************************************
85 Connect to the GGZ client.
86 ****************************************************************************/
87 void ggz_begin(void)
89 int ggz_socket;
91 /* We're in GGZ mode */
92 ggzmod = ggzmod_new(GGZMOD_GAME);
93 ggzmod_set_handler(ggzmod, GGZMOD_EVENT_SERVER, &handle_ggzmod_server);
94 ggzmod_set_handler(ggzmod, GGZMOD_EVENT_STATS, &handle_ggzmod_stats);
95 if (ggzmod_connect(ggzmod) < 0) {
96 exit(EXIT_FAILURE);
98 ggz_socket = ggzmod_get_fd(ggzmod);
99 if (ggz_socket < 0) {
100 fc_fprintf(stderr, _("Only the GGZ client must call freeciv-client"
101 " in ggz mode!\n"));
102 exit(EXIT_FAILURE);
104 add_ggz_input(ggz_socket);
107 /****************************************************************************
108 Called when the ggz socket has data pending.
109 ****************************************************************************/
110 void input_from_ggz(int socket)
112 if (ggzmod_dispatch(ggzmod) < 0) {
113 disconnect_from_server();
117 /****************************************************************************
118 Find the seat for the given player (in the seat parameter), or returns
119 FALSE if no seat is found.
120 ****************************************************************************/
121 static bool user_get_seat(const char *name, GGZSeat *seat)
123 int i;
124 int num = ggzmod_get_num_seats(ggzmod);
126 for (i = 0; i < num; i++) {
127 *seat = ggzmod_get_seat(ggzmod, i);
129 if (seat->type == GGZ_SEAT_PLAYER
130 && strcasecmp(seat->name, name) == 0) {
131 return TRUE;
135 return FALSE;
138 /****************************************************************************
139 Find the player's rating, or return FALSE if there is no rating.
140 ****************************************************************************/
141 bool user_get_rating(const char *name, int *rating)
143 GGZSeat seat;
145 if (user_get_seat(name, &seat)) {
146 return ggzmod_player_get_rating(ggzmod, &seat, rating);
149 return FALSE;
152 /****************************************************************************
153 Find the player's record, or return FALSE if there is no record.
154 ****************************************************************************/
155 bool user_get_record(const char *name,
156 int *wins, int *losses, int *ties, int *forfeits)
158 GGZSeat seat;
160 if (user_get_seat(name, &seat)) {
161 return ggzmod_player_get_record(ggzmod, &seat,
162 wins, losses, ties, forfeits);
165 return FALSE;
169 #endif /* GGZ_CLIENT */