Freeciv21
Develop your civilization from humble roots to a global empire
srv_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 // utility
16 #include "log.h" // QtMsgType
17 #include "net_types.h" // announce_type
18 
19 // common
20 #include "fc_types.h"
21 #include "game.h"
22 
23 // Qt
24 #include <QHostAddress>
25 
26 struct conn_list;
27 
29  // metaserver information
31  QString metaserver_addr;
33  QString identity_name;
34  unsigned short int metaserver_port;
35  // Address in case a local socket is used
36  QString local_addr;
37  // address this server is to listen on
38  QHostAddress bind_addr;
39  // this server's listen port
40  int port;
42  // address to bind when connecting to the metaserver (nullptr => bind_addr)
43  QString bind_meta_addr;
44  // filenames
45  QString log_filename;
47  QString load_filename;
48  QString script_filename;
49  QString saves_pathname;
51  QString ruleset;
52  QString serverid;
53  // quit if there no players after a given time interval
54  int quitidle;
55  // exit the server on game ending
57  bool timetrack; // defaults to FALSE
58  // authentication options
59  bool fcdb_enabled; // defaults to FALSE
60  QString fcdb_conf; // freeciv database configuration file
61  bool auth_enabled; // defaults to FALSE
62  bool auth_allow_guests; // defaults to FALSE
63  bool auth_allow_newusers; // defaults to FALSE
65 };
66 
67 // used in savegame values
68 #define SPECENUM_NAME server_states
69 #define SPECENUM_VALUE0 S_S_INITIAL
70 #define SPECENUM_VALUE1 S_S_RUNNING
71 #define SPECENUM_VALUE2 S_S_OVER
72 #include "specenum_gen.h"
73 
74 /* Structure for holding global server data.
75  *
76  * TODO: Lots more variables could be added here. */
77 extern struct civserver {
80 
81  /* this counter creates all the city and unit numbers used.
82  * arbitrarily starts at 101, but at 65K wraps to 1.
83  * use identity_number()
84  */
85 #define IDENTITY_NUMBER_SKIP (100)
86  unsigned short identity_number;
87 
89 
90  struct unit_wait_list *unit_waits;
92 
93 void init_game_seed();
94 void srv_init();
95 void server_quit();
96 void save_game_auto(const char *save_reason, enum autosave_type type);
97 
98 enum server_states server_state();
99 void set_server_state(enum server_states newstate);
100 
102 bool check_for_game_over();
103 bool game_was_started();
104 
105 int server_plr_tile_city_id_get(const struct tile *ptile,
106  const struct player *pplayer);
107 
109 const char *server_ss_name_get(server_setting_id id);
110 enum sset_type server_ss_type_get(server_setting_id id);
114 
115 bool server_packet_input(struct connection *pconn, void *packet, int type);
116 void start_game();
117 const char *pick_random_player_name(const struct nation_type *pnation);
118 void player_nation_defaults(struct player *pplayer,
119  struct nation_type *pnation, bool set_name);
120 void send_all_info(struct conn_list *dest);
121 
122 void begin_turn(bool is_new_turn);
123 void begin_phase(bool is_new_phase);
124 void end_phase();
125 void end_turn();
126 
127 void identity_number_release(int id);
128 void identity_number_reserve(int id);
129 int identity_number();
130 
131 void srv_ready();
132 void srv_scores();
133 
134 void server_game_init(bool keep_ruleset_value);
135 void server_game_free();
136 const char *aifill(int amount);
137 
138 extern struct server_arguments srvarg;
139 
140 extern bool force_end_of_sniff;
141 
143 
144 known_type mapimg_server_tile_known(const struct tile *ptile,
145  const struct player *pplayer,
146  bool knowledge);
147 terrain *mapimg_server_tile_terrain(const struct tile *ptile,
148  const struct player *pplayer,
149  bool knowledge);
150 player *mapimg_server_tile_owner(const struct tile *ptile,
151  const struct player *pplayer,
152  bool knowledge);
153 player *mapimg_server_tile_city(const struct tile *ptile,
154  const struct player *pplayer,
155  bool knowledge);
156 player *mapimg_server_tile_unit(const struct tile *ptile,
157  const struct player *pplayer,
158  bool knowledge);
159 
int server_setting_id
Definition: fc_types.h:893
#define MAX_LEN_GAME_IDENTIFIER
Definition: fc_types.h:66
autosave_type
Definition: game.h:54
const char * name
Definition: inputfile.cpp:118
announce_type
Definition: net_types.h:19
void server_game_init(bool keep_ruleset_value)
Initialize game data for the server (corresponds to server_game_free).
Definition: srv_main.cpp:3179
void srv_scores()
Score calculation.
Definition: srv_main.cpp:2834
void srv_ready()
Set up one game.
Definition: srv_main.cpp:2888
const char * aifill(int amount)
Fill or remove players to meet the given aifill.
Definition: srv_main.cpp:2440
void check_for_full_turn_done()
Check if turn is really done.
Definition: srv_main.cpp:2179
int mapimg_server_plrcolor_count()
Helper function for the mapimg module - number of player colors.
Definition: srv_main.cpp:3446
void identity_number_release(int id)
Mark identity number free.
Definition: srv_main.cpp:1964
void end_phase()
End a phase of movement.
Definition: srv_main.cpp:1397
int server_plr_tile_city_id_get(const struct tile *ptile, const struct player *pplayer)
Returns the id of the city the player map of 'pplayer' has at 'ptile' or IDENTITY_NUMBER_ZERO if the ...
Definition: srv_main.cpp:3254
void player_nation_defaults(struct player *pplayer, struct nation_type *pnation, bool set_name)
Set nation for player with nation default values.
Definition: srv_main.cpp:2545
void server_game_free()
Free game data that we reinitialize as part of a server soft restart.
Definition: srv_main.cpp:3204
struct civserver server
player * mapimg_server_tile_owner(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Helper function for the mapimg module - tile owner.
Definition: srv_main.cpp:3385
bool force_end_of_sniff
Definition: srv_main.cpp:130
void save_game_auto(const char *save_reason, enum autosave_type type)
Save game with autosave filename.
Definition: srv_main.cpp:1788
const char * server_ss_name_get(server_setting_id id)
Returns the name of the server setting with the specified id.
Definition: srv_main.cpp:3281
bool check_for_game_over()
Returns TRUE if any one game end condition is fulfilled, FALSE otherwise.
Definition: srv_main.cpp:265
void start_game()
Start actual game.
Definition: srv_main.cpp:1830
player * mapimg_server_tile_unit(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Helper function for the mapimg module - unit owner.
Definition: srv_main.cpp:3426
void set_server_state(enum server_states newstate)
Set current server state.
Definition: srv_main.cpp:243
void end_turn()
Handle the end of each turn.
Definition: srv_main.cpp:1554
void identity_number_reserve(int id)
Mark identity number allocated.
Definition: srv_main.cpp:1969
void server_quit()
Quit the server and exit.
Definition: srv_main.cpp:1869
struct server_arguments srvarg
Definition: srv_main.cpp:118
void init_game_seed()
Initialize the game seed.
Definition: srv_main.cpp:147
known_type mapimg_server_tile_known(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Helper function for the mapimg module - tile knowledge.
Definition: srv_main.cpp:3356
bool game_was_started()
Returns iff the game was started once upon a time.
Definition: srv_main.cpp:251
bool server_ss_val_bool_get(server_setting_id id)
Returns the value of the boolean server setting with the specified id.
Definition: srv_main.cpp:3311
server_setting_id server_ss_by_name(const char *name)
Returns the id of the server setting with the specified name.
Definition: srv_main.cpp:3266
enum server_states server_state()
Return current server state.
Definition: srv_main.cpp:238
rgbcolor * mapimg_server_plrcolor_get(int i)
Helper function for the mapimg module - one player color.
Definition: srv_main.cpp:3451
void begin_phase(bool is_new_phase)
Begin a phase of movement.
Definition: srv_main.cpp:1213
bool server_packet_input(struct connection *pconn, void *packet, int type)
Returns FALSE if connection should be closed (because the clients was rejected).
Definition: srv_main.cpp:2024
void srv_init()
Initialize freeciv server.
Definition: srv_main.cpp:162
int server_ss_val_int_get(server_setting_id id)
Returns the value of the integer server setting with the specified id.
Definition: srv_main.cpp:3326
unsigned int server_ss_val_bitwise_get(server_setting_id id)
Returns the value of the bitwise server setting with the specified id.
Definition: srv_main.cpp:3341
void begin_turn(bool is_new_turn)
Handle the beginning of each turn.
Definition: srv_main.cpp:1083
void send_all_info(struct conn_list *dest)
Send all information for when game starts or client reconnects.
Definition: srv_main.cpp:607
const char * pick_random_player_name(const struct nation_type *pnation)
Returns a random ruler name picked from given nation's ruler names that is not already in use.
Definition: srv_main.cpp:2787
int identity_number()
Identity ids wrap at IDENTITY_NUMBER_SIZE, skipping IDENTITY_NUMBER_ZERO Setup in server_game_init()
Definition: srv_main.cpp:1993
enum sset_type server_ss_type_get(server_setting_id id)
Returns the type of the server setting with the specified id.
Definition: srv_main.cpp:3296
void update_nations_with_startpos()
Update information about which nations have start positions on the map.
Definition: srv_main.cpp:2239
terrain * mapimg_server_tile_terrain(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Helper function for the mapimg module - tile terrain.
Definition: srv_main.cpp:3370
player * mapimg_server_tile_city(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Helper function for the mapimg module - city owner.
Definition: srv_main.cpp:3401
struct unit_wait_list * unit_waits
Definition: srv_main.h:90
char game_identifier[MAX_LEN_GAME_IDENTIFIER]
Definition: srv_main.h:88
int nbarbarians
Definition: srv_main.h:79
int playable_nations
Definition: srv_main.h:78
unsigned short identity_number
Definition: srv_main.h:86
Definition: player.h:231
bool metaconnection_persistent
Definition: srv_main.h:32
QString log_filename
Definition: srv_main.h:45
bool exit_on_end
Definition: srv_main.h:56
enum announce_type announce
Definition: srv_main.h:64
QString bind_meta_addr
Definition: srv_main.h:43
QString local_addr
Definition: srv_main.h:36
QString script_filename
Definition: srv_main.h:48
bool user_specified_port
Definition: srv_main.h:41
bool auth_allow_guests
Definition: srv_main.h:62
bool fcdb_enabled
Definition: srv_main.h:59
QString identity_name
Definition: srv_main.h:33
QHostAddress bind_addr
Definition: srv_main.h:38
bool metaserver_no_send
Definition: srv_main.h:30
QString fcdb_conf
Definition: srv_main.h:60
QString saves_pathname
Definition: srv_main.h:49
QString serverid
Definition: srv_main.h:52
QString ruleset
Definition: srv_main.h:51
QString load_filename
Definition: srv_main.h:47
unsigned short int metaserver_port
Definition: srv_main.h:34
bool auth_enabled
Definition: srv_main.h:61
QString scenarios_pathname
Definition: srv_main.h:50
bool auth_allow_newusers
Definition: srv_main.h:63
QString metaserver_addr
Definition: srv_main.h:31
QString ranklog_filename
Definition: srv_main.h:46
Definition: tile.h:42
known_type
Definition: tile.h:28