14 #include <fc_config.h>
26 #include "fc_version.h"
56 struct player *pplayer,
bool observing,
74 pconn->
server.granted_access_level = new_level;
77 if (old_level != new_level) {
92 enum cmdlevel
level = pconn->
server.granted_access_level;
124 struct conn_list *dest = pconn->
self;
126 struct packet_server_join_reply packet;
127 struct packet_chat_msg connect_info;
129 bool delegation_error =
false;
130 struct packet_set_topology topo_packet;
133 memset(pconn->
server.password, 0,
sizeof(pconn->
server.password));
136 packet.you_can_join =
true;
138 fc_snprintf(packet.message,
sizeof(packet.message),
_(
"%s Welcome"),
141 packet.conn_id = pconn->
id;
142 send_packet_server_join_reply(pconn, &packet);
148 pconn->
server.delegation.status =
false;
149 pconn->
server.delegation.playing =
nullptr;
150 pconn->
server.delegation.observer =
false;
163 _(
"Welcome to the %s Server running at %s port %d."),
167 _(
"Welcome to the %s Server at port %d."),
175 qInfo(
_(
"%s has connected from %s."), pconn->
username,
176 qUtf8Printable(pconn->
addr));
186 send_packet_set_topology(pconn, &topo_packet);
199 _(
"Your delegate %s was controlling your player '%s'; "
203 _(
"%s reconnected, ending your delegated control of "
209 qCritical(
"Failed to revoke delegate %s's control of %s, so owner %s "
210 "can't regain control.",
213 _(
"Couldn't get control of '%s' from delegation to %s."),
215 delegation_error =
true;
220 if (!delegation_error) {
235 _(
"Couldn't attach your connection to new player."));
236 qDebug(
"%s is not attached to a player", pconn->
username);
245 if (
nullptr == pplayer) {
253 _(
"You are logged in as '%s' connected to no player."),
257 _(
"You are logged in as '%s' connected to %s."),
270 _(
"%s has connected (player %s)."), pconn->
username,
274 _(
"%s has connected."), pconn->
username);
278 if (aconn != pconn) {
279 send_packet_chat_msg(aconn, &connect_info);
290 if (
is_human(cplayer) && !cplayer->phase_done
291 && cplayer != pconn->
playing) {
293 _(
"Turn-blocking game play: "
294 "waiting on %s to finish turn..."),
303 _(
" *** Server is in edit mode. *** "));
306 if (
nullptr != pplayer) {
322 struct packet_server_join_reply packet;
325 memset(pconn->
server.password, 0,
sizeof(pconn->
server.password));
327 packet.you_can_join =
false;
330 packet.challenge_file[0] =
'\0';
332 send_packet_server_join_reply(pconn, &packet);
342 struct packet_server_join_req *req)
345 int kick_time_remaining;
353 qInfo(
_(
"Connection request from %s from %s"), req->username,
354 qUtf8Printable(pconn->
addr));
357 qInfo(
_(
"%s has client version %d.%d.%d%s"), pconn->
username,
358 req->major_version, req->minor_version, req->patch_version,
360 qDebug(
"Client caps: %s", req->capability);
368 _(
"The client is missing a capability that this server needs.\n"
369 "Server version: %d.%d.%d%s Client version: %d.%d.%d%s."
370 " Upgrading may help!"),
371 MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION, VERSION_LABEL,
372 req->major_version, req->minor_version, req->patch_version,
375 qInfo(
_(
"%s was rejected: Mismatched capabilities."), req->username);
383 _(
"The server is missing a capability that the client needs.\n"
384 "Server version: %d.%d.%d%s Client version: %d.%d.%d%s."
385 " Upgrading may help!"),
386 MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION, VERSION_LABEL,
387 req->major_version, req->minor_version, req->patch_version,
390 qInfo(
_(
"%s was rejected: Mismatched capabilities."), req->username);
397 struct packet_server_info info;
399 info.major_version = MAJOR_VERSION;
400 info.minor_version = MINOR_VERSION;
401 info.patch_version = PATCH_VERSION;
403 sz_strlcpy(info.version_label, VERSION_LABEL);
404 send_packet_server_info(pconn, &info);
411 fc_snprintf(msg,
sizeof(msg),
_(
"Invalid username '%s'"), req->username);
413 qInfo(
_(
"%s was rejected: Invalid name [%s]."), req->username,
414 qUtf8Printable(pconn->
addr));
420 _(
"You have been kicked from this server "
421 "and cannot reconnect for %d seconds."),
422 kick_time_remaining);
424 qInfo(
_(
"%s was rejected: Connection kicked "
425 "(%d seconds remaining)."),
426 req->username, kick_time_remaining);
434 fc_snprintf(msg,
sizeof(msg),
_(
"'%s' already connected."),
437 qInfo(
_(
"%s was rejected: Duplicate login name [%s]."), req->username,
438 qUtf8Printable(pconn->
addr));
446 "Ping timer list size %d, should be 1. Have we sent "
447 "a ping to unestablished connection %s?",
455 dsend_packet_connect_msg(pconn,
game.
server.connectmsg);
497 struct packet_conn_info *packet)
499 packet->id = pconn->
id;
500 packet->used = pconn->
used;
502 packet->player_num = (
nullptr != pconn->
playing)
521 struct packet_conn_info packet;
533 lsend_packet_conn_info(dest, &packet);
563 if (!played->is_connected && !played->was_created) {
589 struct player *pplayer,
bool observing,
594 "connections must be detached with "
595 "connection_detach() before calling this!");
598 if (
nullptr == pplayer) {
602 if (
nullptr == pplayer) {
648 }
else if (pplayer ==
nullptr) {
650 bool already =
false;
656 if (pconn2 == pconn) {
671 if (aplayer != pplayer
674 aplayer->unassigned_user =
true;
708 dsend_packet_start_phase(pconn,
game.
info.phase);
762 if (
nullptr != (pplayer = pconn->
playing)) {
779 if (!aconn->observer) {
818 qDebug(
"connection_detach() calls send_player_info_c()");
845 pconn->
server.delegation.status =
true;
869 pconn->
server.delegation.observer);
873 pconn->
server.delegation.status =
false;
874 pconn->
server.delegation.playing =
nullptr;
875 pconn->
server.delegation.observer =
false;
878 oplayer->
server.orig_username[0] =
'\0';
880 dplayer->
server.orig_username[0] =
'\0';
898 if (!pconn->
server.delegation.status) {
902 if (pconn->
server.delegation.playing
903 && !pconn->
server.delegation.observer) {
907 strcmp(pconn->
server.delegation.playing->server.orig_username,
925 if ((
nullptr != pconn->
server.delegation.playing
926 || pconn->
server.delegation.observer)
928 pconn->
server.delegation.observer)) {
933 pconn->
server.delegation.status =
false;
934 pconn->
server.delegation.playing =
nullptr;
935 pconn->
server.delegation.observer =
false;
940 oplayer->
server.orig_username[0] =
'\0';
946 dplayer->
server.orig_username[0] =
'\0';
const char * default_ai_type_name()
Return name of default ai type.
bool auth_user(struct connection *pconn, char *username)
Handle authentication of a user; called by handle_login_request() if authentication is enabled.
bool has_capabilities(const char *us, const char *them)
This routine returns true if all the mandatory capabilities in us appear in them.
const char *const our_capability
static bool connection_attach_real(struct connection *pconn, struct player *pplayer, bool observing, bool connecting)
Setup pconn as a client connected to pplayer or observer: Updates pconn->playing, pplayer->connection...
void send_conn_info(struct conn_list *src, struct conn_list *dest)
Send conn_info packets to tell 'dest' connections all about 'src' connections.
bool connection_attach(struct connection *pconn, struct player *pplayer, bool observing)
Setup pconn as a client connected to pplayer or observer.
static void package_conn_info(struct connection *pconn, struct packet_conn_info *packet)
Fill in packet_conn_info from full connection struct.
void reject_new_connection(const char *msg, struct connection *pconn)
send the rejection packet to the client.
static void send_conn_info_arg(struct conn_list *src, struct conn_list *dest, bool remove_conn)
Handle both send_conn_info() and send_conn_info_removed(), depending on 'remove' arg.
bool connection_delegate_take(struct connection *pconn, struct player *dplayer)
Use a delegation to get control over another player.
bool handle_login_request(struct connection *pconn, struct packet_server_join_req *req)
Returns FALSE if the clients gets rejected and the connection should be closed.
static void restore_access_level(struct connection *pconn)
Restore access level for the given connection (user).
void lost_connection_to_client(struct connection *pconn)
High-level server stuff when connection to client is closed or lost.
struct player * find_uncontrolled_player()
Search for first uncontrolled player.
void connection_close_server(struct connection *pconn, const QString &reason)
Close a connection.
void connection_detach(struct connection *pconn, bool remove_unused_player)
Remove pconn as a client connected to pplayer: Updates pconn->playing, pconn->playing->connections,...
void conn_set_access(struct connection *pconn, enum cmdlevel new_level, bool granted)
Set the access level of a connection, and re-send some needed info.
bool connection_delegate_restore(struct connection *pconn)
Restore the original status of a delegate connection pconn after potentially using a delegation.
void send_conn_info_remove(struct conn_list *src, struct conn_list *dest)
Like send_conn_info(), but turn off the 'used' bits to tell clients to remove info about these connec...
void establish_new_connection(struct connection *pconn)
This is used when a new player joins a server, before the game has started.
bool can_conn_edit(const struct connection *pconn)
Return TRUE iff the connection is currently allowed to edit.
void flush_connection_send_buffer_all(struct connection *pc)
Flush'em.
struct player * conn_get_player(const struct connection *pconn)
Returns the player that this connection is attached to, or nullptr.
const char * conn_description(const struct connection *pconn, bool is_private)
° Return pointer to static string containing a description for this ° connection, based on pconn->nam...
void conn_set_capability(struct connection *pconn, const char *capability)
Set the network capability string for 'pconn'.
void conn_reset_delta_state(struct connection *pc)
Remove all is-game-info cached packets from the connection.
bool conn_controls_player(const struct connection *pconn)
Returns TRUE if the given connection is attached to a player which it also controls (i....
void connection_close(struct connection *pconn, const QString &reason)
Call the conn_close_callback.
void conn_compression_freeze(struct connection *pconn)
Freeze the connection.
struct connection * conn_by_user(const char *user_name)
Find connection by exact user name, from game.all_connections, case-insensitve.
enum cmdlevel conn_get_access(const struct connection *pconn)
Returns the current access level of the given connection.
bool conn_compression_thaw(struct connection *pconn)
Thaw the connection.
#define conn_list_iterate(connlist, pconn)
#define conn_list_iterate_end
void send_diplomatic_meetings(struct connection *dest)
Send information on any on-going diplomatic meetings for connection's player.
void edithand_send_initial_packets(struct conn_list *dest)
Send the needed packets for connections entering in the editing mode.
#define MAX_NUM_PLAYER_SLOTS
const struct ft_color ftc_player_lost
const struct ft_color ftc_server
const struct ft_color ftc_editor
const struct ft_color ftc_any
const char * new_challenge_filename(struct connection *pc)
Find a file that we can write too, and return it's name.
void send_scenario_description(struct conn_list *dest)
Send description of the current scenario.
void send_scenario_info(struct conn_list *dest)
Send current scenario info.
void send_game_info(struct conn_list *dest)
Send game_info packet; some server options and various stuff...
#define fc_assert_msg(condition, message,...)
#define fc_assert_ret(condition)
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
#define fc_assert_action(condition, action)
#define log_debug(message,...)
#define fc_assert_ret_val_msg(condition, val, message,...)
void send_pending_events(struct connection *pconn, bool include_public)
Send all available events.
void notify_conn(struct conn_list *dest, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
See notify_conn_packet - this is just the "non-v" version, with varargs.
void package_event(struct packet_chat_msg *packet, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Fill a packet_chat_msg structure for common server event.
void event_cache_add_for_all(const struct packet_chat_msg *packet)
Add an event to the cache for all connections.
bool is_valid_username(const char *name)
Returns whether this is a valid username.
int player_number(const struct player *pplayer)
Return the player index/number/id.
int player_count()
Return the number of players.
const char * player_name(const struct player *pplayer)
Return the leader name of the player.
struct player * player_by_user(const char *name)
Find player by its user name (not player/leader name)
#define players_iterate_end
#define players_iterate(_pplayer)
#define set_as_human(plr)
#define players_iterate_alive_end
#define players_iterate_alive(_pplayer)
void server_player_set_name(struct player *pplayer, const char *name)
Try to set the player name to 'name'.
struct player * server_create_player(int player_id, const char *ai_tname, struct rgbcolor *prgbcolor, bool allow_ai_type_fallbacking)
Creates a new, uninitialized, used player slot.
struct player * player_by_user_delegated(const char *name)
For a given user, if there is some player that the user originally controlled but is currently delega...
void send_player_info_c(struct player *src, struct conn_list *dest)
Send information about player slot 'src', or all valid (i.e.
void send_delegation_info(const struct connection *pconn)
Send information about delegations to reconnecting users.
void server_remove_player(struct player *pplayer)
This function does not close any connections attached to this player.
void server_player_init(struct player *pplayer, bool initmap, bool needs_team)
Initialize ANY newly-created player on the server.
int normal_player_count()
Return the number of non-barbarian players.
const char * player_delegation_get(const struct player *pplayer)
Returns the username that control of the player is delegated to, if any.
void reset_all_start_commands(bool plrchange)
Called when something is changed; this resets everyone's readiness.
void report_final_scores(struct conn_list *dest)
Inform clients about player scores and statistics when the game ends.
void send_current_history_report(struct conn_list *dest)
Send history report of this turn.
void send_rulesets(struct conn_list *dest)
Send all ruleset information to the specified connections.
struct setting_list * level[OLEVELS_NUM]
void send_server_setting_control(struct connection *pconn)
Tell the client about all server settings.
void send_server_settings(struct conn_list *dest)
Tell the client about all server settings.
void send_server_access_level_settings(struct conn_list *dest, enum cmdlevel old_level, enum cmdlevel new_level)
Send the server settings that got a different visibility or changability after a connection access le...
void remove_leading_trailing_spaces(char *s)
Removes leading and trailing spaces in string pointed to by 's'.
const char * aifill(int amount)
Fill or remove players to meet the given aifill.
void check_for_full_turn_done()
Check if turn is really done.
struct server_arguments srvarg
bool game_was_started()
Returns iff the game was started once upon a time.
enum server_states server_state()
Return current server state.
void send_all_info(struct conn_list *dest)
Send all information for when game starts or client reconnects.
void notify_if_first_access_level_is_available()
Check if first access level is available and if it is, notify connections about it.
bool conn_is_kicked(struct connection *pconn, int *time_remaining)
Returns FALSE if the connection isn't kicked and can connect the server normally.
void toggle_ai_player_direct(struct connection *caller, struct player *pplayer)
Handle ai player ai toggling.
struct civ_game::@28::@32 server
struct conn_list * glob_observers
struct conn_list * est_connections
struct packet_game_info info
struct conn_list * all_connections
enum cmdlevel access_level
struct connection::@55::@61 server
char username[MAX_LEN_NAME]
char capability[MAX_LEN_CAPSTR]
char username[MAX_LEN_NAME]
struct player::@65::@67 server
struct conn_list * connections
struct nation_type * nation
int fc_snprintf(char *str, size_t n, const char *format,...)
See also fc_utf8_snprintf_trunc(), fc_utf8_snprintf_rep().
int fc_gethostname(char *buf, size_t len)
Call gethostname() if supported, else just returns -1.
int fc_strcasecmp(const char *str0, const char *str1)
Compare strings like strcmp(), but ignoring case.
#define sz_strlcpy(dest, src)
void team_remove_player(struct player *pplayer)
Remove the player from the team.
void timer_destroy(civtimer *t)
Deletes timer.
const char * freeciv_name_version()
Return string containing both name of Freeciv21 and version.
void send_running_votes(struct connection *pconn, bool only_team_votes)
Sends a packet_vote_new to pconn for every currently running votes.
void send_remove_team_votes(struct connection *pconn)
Sends a packet_vote_remove to pconn for every currently running team vote 'pconn' can see.
void cancel_connection_votes(struct connection *pconn)
Cancel the votes of a lost or a detached connection.
void send_updated_vote_totals(struct conn_list *dest)
Sends a packet_vote_update to every conn in dest.