Freeciv21
Develop your civilization from humble roots to a global empire
connecthand.cpp File Reference
#include <fc_config.h>
#include <cstring>
#include "capability.h"
#include "fcintl.h"
#include "log.h"
#include "registry_ini.h"
#include "support.h"
#include "fc_version.h"
#include "capstr.h"
#include "events.h"
#include "game.h"
#include "packets.h"
#include "player.h"
#include "version.h"
#include "aiiface.h"
#include "auth.h"
#include "diplhand.h"
#include "edithand.h"
#include "gamehand.h"
#include "maphand.h"
#include "meta.h"
#include "notify.h"
#include "plrhand.h"
#include "report.h"
#include "ruleset.h"
#include "settings.h"
#include "srv_main.h"
#include "stdinhand.h"
#include "voting.h"
#include "connecthand.h"
+ Include dependency graph for connecthand.cpp:

Go to the source code of this file.

Functions

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->connections, pplayer->is_connected and pconn->observer. More...
 
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. More...
 
static void restore_access_level (struct connection *pconn)
 Restore access level for the given connection (user). More...
 
void establish_new_connection (struct connection *pconn)
 This is used when a new player joins a server, before the game has started. More...
 
void reject_new_connection (const char *msg, struct connection *pconn)
 send the rejection packet to the client. More...
 
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. More...
 
void lost_connection_to_client (struct connection *pconn)
 High-level server stuff when connection to client is closed or lost. More...
 
static void package_conn_info (struct connection *pconn, struct packet_conn_info *packet)
 Fill in packet_conn_info from full connection struct. More...
 
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. More...
 
void send_conn_info (struct conn_list *src, struct conn_list *dest)
 Send conn_info packets to tell 'dest' connections all about 'src' connections. More...
 
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 connections instead of adding it. More...
 
struct playerfind_uncontrolled_player ()
 Search for first uncontrolled player. More...
 
bool connection_attach (struct connection *pconn, struct player *pplayer, bool observing)
 Setup pconn as a client connected to pplayer or observer. More...
 
void connection_detach (struct connection *pconn, bool remove_unused_player)
 Remove pconn as a client connected to pplayer: Updates pconn->playing, pconn->playing->connections, pconn->playing->is_connected and pconn->observer. More...
 
bool connection_delegate_take (struct connection *pconn, struct player *dplayer)
 Use a delegation to get control over another player. More...
 
bool connection_delegate_restore (struct connection *pconn)
 Restore the original status of a delegate connection pconn after potentially using a delegation. More...
 
void connection_close_server (struct connection *pconn, const QString &reason)
 Close a connection. More...
 

Function Documentation

◆ conn_set_access()

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.

If granted is TRUE, then it will overwrite the granted_access_level too. Else, it will affect only the current access level.

NB: This function does not send updated connection information to other clients, you need to do that yourself afterwards.

Definition at line 67 of file connecthand.cpp.

Referenced by firstlevel_command(), handle_single_want_hack_req(), restore_access_level(), set_cmdlevel(), and start_game().

◆ connection_attach()

bool connection_attach ( struct connection pconn,
struct player pplayer,
bool  observing 
)

Setup pconn as a client connected to pplayer or observer.

Definition at line 740 of file connecthand.cpp.

Referenced by connection_delegate_restore(), connection_delegate_take(), load_command(), observe_command(), and take_command().

◆ connection_attach_real()

static bool connection_attach_real ( struct connection pconn,
struct player pplayer,
bool  observing,
bool  connecting 
)
static

Setup pconn as a client connected to pplayer or observer: Updates pconn->playing, pplayer->connections, pplayer->is_connected and pconn->observer.

  • If pplayer is nullptr and observing is FALSE: take the next available player that is not connected.
  • If pplayer is nullptr and observing is TRUE: attach this connection to the game as global observer.
  • If pplayer is not nullptr and observing is FALSE: take this player.
  • If pplayer is not nullptr and observing is TRUE: observe this player.

Note take_command() needs to know if this function will success before it's time to call this. Keep take_command() checks in sync when modifying this.

Definition at line 588 of file connecthand.cpp.

Referenced by connection_attach(), and establish_new_connection().

◆ connection_close_server()

void connection_close_server ( struct connection pconn,
const QString &  reason 
)

Close a connection.

Use this in the server to take care of delegation stuff (reset the username of the controlled connection).

Definition at line 957 of file connecthand.cpp.

Referenced by auth_process_status(), cut_client_connection(), freeciv::server::error_on_socket(), flush_packets(), incoming_client_packets(), freeciv::server::input_on_socket(), kick_command(), and freeciv::server::send_pings().

◆ connection_delegate_restore()

bool connection_delegate_restore ( struct connection pconn)

Restore the original status of a delegate connection pconn after potentially using a delegation.

pconn is detached from the delegated player, and reattached to its previous view (e.g. observer), if any. (Reattaching the original user to the delegated player is not handled here.)

Definition at line 894 of file connecthand.cpp.

Referenced by connection_close_server(), delegate_command(), and establish_new_connection().

◆ connection_delegate_take()

bool connection_delegate_take ( struct connection pconn,
struct player dplayer 
)

Use a delegation to get control over another player.

Definition at line 838 of file connecthand.cpp.

Referenced by delegate_command().

◆ connection_detach()

void connection_detach ( struct connection pconn,
bool  remove_unused_player 
)

Remove pconn as a client connected to pplayer: Updates pconn->playing, pconn->playing->connections, pconn->playing->is_connected and pconn->observer.

pconn remains a member of game.est_connections.

If remove_unused_player is TRUE, may remove a player left with no controlling connection (only in pregame, and not if explicitly /created).

Definition at line 756 of file connecthand.cpp.

Referenced by connection_delegate_restore(), connection_delegate_take(), detach_command(), handle_edit_player_remove(), load_command(), lost_connection_to_client(), observe_command(), player_limit_to_max_rates(), and take_command().

◆ establish_new_connection()

void establish_new_connection ( struct connection pconn)

This is used when a new player joins a server, before the game has started.

If pconn is nullptr, is an AI, else a client.

N.B. this only attachs a connection to a player if pconn->username == player->username

Here we send initial packets:

  • ruleset datas.
  • server settings.
  • scenario info.
  • game info.
  • players infos (note it's resent in srv_main.c::send_all_info(), see comment there).
  • connections infos.
  • running vote infos. ... and additionnal packets if the game already started.

Definition at line 122 of file connecthand.cpp.

Referenced by auth_handle_reply(), auth_user(), and handle_login_request().

◆ find_uncontrolled_player()

struct player* find_uncontrolled_player ( )

Search for first uncontrolled player.

Definition at line 559 of file connecthand.cpp.

Referenced by connection_attach_real(), and take_command().

◆ handle_login_request()

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.

Returns TRUE if the client get accepted.

Definition at line 341 of file connecthand.cpp.

Referenced by server_packet_input().

◆ lost_connection_to_client()

void lost_connection_to_client ( struct connection pconn)

High-level server stuff when connection to client is closed or lost.

Reports loss to log, and to other players if the connection was a player. Also removes player in pregame, applies auto_toggle, and does check for turn done (since can depend on connection/ai status). Note you shouldn't this function directly. You should use server_break_connection() if you want to close the connection.

Definition at line 475 of file connecthand.cpp.

Referenced by really_close_connections().

◆ package_conn_info()

static void package_conn_info ( struct connection pconn,
struct packet_conn_info *  packet 
)
static

Fill in packet_conn_info from full connection struct.

Definition at line 496 of file connecthand.cpp.

Referenced by send_conn_info_arg().

◆ reject_new_connection()

void reject_new_connection ( const char *  msg,
struct connection pconn 
)

send the rejection packet to the client.

Definition at line 320 of file connecthand.cpp.

Referenced by auth_handle_reply(), auth_process_status(), auth_user(), and handle_login_request().

◆ restore_access_level()

static void restore_access_level ( struct connection pconn)
static

Restore access level for the given connection (user).

Used when taking a player, observing, or detaching.

NB: This function does not send updated connection information to other clients, you need to do that yourself afterwards.

Definition at line 89 of file connecthand.cpp.

Referenced by connection_attach_real(), connection_detach(), and establish_new_connection().

◆ send_conn_info()

void send_conn_info ( struct conn_list *  src,
struct conn_list *  dest 
)

Send conn_info packets to tell 'dest' connections all about 'src' connections.

Definition at line 542 of file connecthand.cpp.

Referenced by connection_attach_real(), connection_detach(), establish_new_connection(), and handle_single_want_hack_req().

◆ send_conn_info_arg()

static void send_conn_info_arg ( struct conn_list *  src,
struct conn_list *  dest,
bool  remove_conn 
)
static

Handle both send_conn_info() and send_conn_info_removed(), depending on 'remove' arg.

Sends conn_info packets for 'src' to 'dest', turning off 'used' if 'remove' is specified.

Definition at line 518 of file connecthand.cpp.

Referenced by send_conn_info(), and send_conn_info_remove().

◆ send_conn_info_remove()

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 connections instead of adding it.

Definition at line 551 of file connecthand.cpp.

Referenced by lost_connection_to_client().