Freeciv21
Develop your civilization from humble roots to a global empire
client_main.h
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 #pragma once
14 
15 #include "packets.h" // enum report_type
16 
17 // Forward declarations
18 class QString;
19 class QUrl;
20 
21 /*
22  * Every TIMER_INTERVAL milliseconds real_timer_callback is
23  * called. TIMER_INTERVAL has to stay 500 because real_timer_callback
24  * also updates the timeout info.
25  */
26 #define TIMER_INTERVAL (int) (real_timer_callback() * 1000)
27 
28 /* Client states (see also enum server_states in srv_main.h).
29  * Changing those values don't break the network compatibility.
30  *
31  * C_S_INITIAL: Client boot, only used once on program start.
32  * C_S_DISCONNECTED: The state when the client is not connected
33  * to a server. In this state, neither game nor ruleset
34  * is in effect.
35  * C_S_PREPARING: Connected in pregame. Game and ruleset are done.
36  * C_S_RUNNING: Connected ith game in progress.
37  * C_S_OVER: Connected with game over.
38  */
45 };
46 
47 int client_main(int argc, char *argv[]);
48 
49 void client_packet_input(void *packet, int type);
50 
51 void send_report_request(enum report_type type);
53 void send_turn_done();
54 
55 void user_ended_turn();
56 
57 void set_client_state(enum client_states newstate);
59 void set_server_busy(bool busy);
60 bool is_server_busy();
61 
62 void client_remove_cli_conn(struct connection *pconn);
64 
65 QUrl &client_url();
66 
67 extern QString logfile;
68 extern QString scriptfile;
69 extern QString savefile;
70 extern QString sound_plugin_name;
71 extern QString sound_set_name;
72 extern QString music_set_name;
73 extern QString cmd_metaserver;
74 extern bool auto_connect;
75 extern bool auto_spawn;
76 extern bool waiting_for_end_turn;
77 
78 #ifdef FREECIV_DEBUG
79 extern bool hackless;
80 #endif // FREECIV_DEBUG
81 
82 struct global_worklist_list; // Defined in global_worklist.[ch].
83 
84 /* Structure for holding global client data.
85  *
86  * TODO: Lots more variables could be added here. */
87 extern struct civclient {
88  // this is the client's connection to the server
89  struct connection conn;
90  struct global_worklist_list *worklists;
92 
93 bool client_is_observer();
96 bool client_has_player();
97 struct player *client_player();
98 bool client_map_is_known_and_seen(const struct tile *ptile,
99  const struct player *pplayer,
100  enum vision_layer vlayer);
101 void set_miliseconds_to_turndone(int miliseconds);
105 void stop_turn_change_wait();
107 double real_timer_callback();
108 bool can_client_control();
111 bool can_meet_with_player(const struct player *pplayer);
112 
113 void client_exit();
114 
115 bool is_client_quitting();
116 void start_quitting();
117 
118 // Set in GUI code.
119 extern const char *const gui_character_encoding;
120 extern const bool gui_use_transliteration;
QString savefile
int get_seconds_to_new_turn()
Return the number of seconds until turn-done.
enum client_states client_state()
Return current client state.
void start_turn_change_wait()
Start waiting of the server turn change activities.
QString logfile
void client_remove_cli_conn(struct connection *pconn)
Remove pconn from all connection lists in client, then free it.
QString cmd_metaserver
QUrl & client_url()
Returns the URL that this client connects to.
bool can_meet_with_player(const struct player *pplayer)
Returns TRUE iff the client can do diplomatic meetings with another given player.
void client_packet_input(void *packet, int type)
Handle packet received from server.
int client_player_number()
Returns number of player attached to client.
bool client_map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Return the vision of the player on a tile.
bool waiting_for_end_turn
bool is_server_busy()
Returns if server is considered busy at the moment.
int client_main(int argc, char *argv[])
Entry point for common client code.
QString sound_plugin_name
bool client_has_player()
Either controlling or observing.
void set_miliseconds_to_turndone(int miliseconds)
Reset the number of seconds to turndone from an "authentic" source.
void client_remove_all_cli_conn()
Remove (and free) all connections from all connection lists in client.
client_states
Definition: client_main.h:39
@ C_S_PREPARING
Definition: client_main.h:42
@ C_S_DISCONNECTED
Definition: client_main.h:41
@ C_S_INITIAL
Definition: client_main.h:40
@ C_S_RUNNING
Definition: client_main.h:43
@ C_S_OVER
Definition: client_main.h:44
bool client_is_global_observer()
Returns whether client is global observer.
double real_timer_callback()
This function should be called at least once per second.
void start_quitting()
Mark client as one going to quit as soon as possible,.
void set_server_busy(bool busy)
Sets if server is considered busy.
struct player * client_player()
Either controlling or observing.
int get_seconds_to_turndone()
Return the number of seconds until turn-done.
struct civclient client
bool can_client_issue_orders()
Returns TRUE iff the client can issue orders (such as giving unit commands).
bool auto_connect
void user_ended_turn()
Handle user ending his/her turn.
bool client_is_observer()
Returns whether client is observer.
void send_attribute_block_request()
Send attribute block.
QString scriptfile
bool auto_spawn
QString music_set_name
void send_report_request(enum report_type type)
Send request for some report to server.
bool is_client_quitting()
Is the client marked as one going down?
const char *const gui_character_encoding
Definition: gui_main.cpp:47
void send_turn_done()
Send information about player having finished his/her turn to server.
bool can_client_control()
Returns TRUE iff the client can control player.
bool is_waiting_turn_change()
Are we in turn-change wait state?
bool can_client_change_view()
Return TRUE if the client can change the view; i.e.
void stop_turn_change_wait()
Server is responsive again.
QString sound_set_name
void client_exit()
Main client execution stop function.
const bool gui_use_transliteration
Definition: gui_main.cpp:46
void set_client_state(enum client_states newstate)
Change client state.
report_type
Definition: packets.h:52
struct global_worklist_list * worklists
Definition: client_main.h:90
struct connection conn
Definition: client_main.h:89
Definition: player.h:231
Definition: tile.h:42