Freeciv-3.2
Loading...
Searching...
No Matches
Functions
connecthand.c File Reference
#include <string.h>
#include "capability.h"
#include "fcintl.h"
#include "log.h"
#include "mem.h"
#include "rand.h"
#include "support.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 "sernet.h"
#include "settings.h"
#include "srv_main.h"
#include "stdinhand.h"
#include "voting.h"
#include "script_fcdb.h"
#include "connecthand.h"

Go to the source code of this file.

Functions

static bool connection_attach_real (struct connection *pconn, struct player *pplayer, bool observing, bool connecting)
 
void conn_set_access (struct connection *pconn, enum cmdlevel new_level, bool granted)
 
static void restore_access_level (struct connection *pconn)
 
void establish_new_connection (struct connection *pconn)
 
void reject_new_connection (const char *msg, struct connection *pconn)
 
bool handle_login_request (struct connection *pconn, struct packet_server_join_req *req)
 
void lost_connection_to_client (struct connection *pconn)
 
static void package_conn_info (struct connection *pconn, struct packet_conn_info *packet)
 
static void send_conn_info_arg (struct conn_list *src, struct conn_list *dest, bool remove_conn)
 
void send_conn_info (struct conn_list *src, struct conn_list *dest)
 
void send_conn_info_remove (struct conn_list *src, struct conn_list *dest)
 
struct playerfind_uncontrolled_player (void)
 
bool connection_attach (struct connection *pconn, struct player *pplayer, bool observing)
 
void connection_detach (struct connection *pconn, bool remove_unused_player)
 
bool connection_delegate_take (struct connection *pconn, struct player *dplayer)
 
bool connection_delegate_restore (struct connection *pconn)
 
void connection_close_server (struct connection *pconn, const char *reason)
 
void handle_sync_serial (struct connection *conn, int serial)
 

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 72 of file connecthand.c.

Referenced by api_auth_set_cmdlevel(), 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 793 of file connecthand.c.

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 NULL and observing is FALSE: take the next available player that is not connected.
  • If pplayer is NULL and observing is TRUE: attach this connection to the game as global observer.
  • If pplayer is not NULL and observing is FALSE: take this player.
  • If pplayer is not NULL 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 645 of file connecthand.c.

Referenced by connection_attach(), and establish_new_connection().

◆ connection_close_server()

void connection_close_server ( struct connection pconn,
const char 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 1006 of file connecthand.c.

Referenced by auth_process_status(), cut_client_connection(), cut_lagging_connection(), flush_packets(), incoming_client_packets(), kick_command(), and server_sniff_all_input().

◆ 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 945 of file connecthand.c.

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 884 of file connecthand.c.

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 809 of file connecthand.c.

Referenced by connection_delegate_restore(), connection_delegate_take(), connection_detach(), detach_command(), handle_edit_player_remove(), load_command(), lost_connection_to_client(), observe_command(), server_remove_player(), 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 NULL, is an AI, else a client.

N.B. this only attaches 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 additional packets if the game already started.

Definition at line 130 of file connecthand.c.

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

◆ find_uncontrolled_player()

struct player * find_uncontrolled_player ( void  )

Search for first uncontrolled player

Definition at line 618 of file connecthand.c.

Referenced by connection_attach_real(), create_command_pregame(), 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 396 of file connecthand.c.

Referenced by server_packet_input().

◆ handle_sync_serial()

void handle_sync_serial ( struct connection conn,
int  serial 
)

Handle client's request to sync via packet serial number.

Definition at line 1016 of file connecthand.c.

Referenced by server_handle_packet().

◆ 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 530 of file connecthand.c.

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 553 of file connecthand.c.

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 375 of file connecthand.c.

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 97 of file connecthand.c.

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 601 of file connecthand.c.

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 579 of file connecthand.c.

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 610 of file connecthand.c.

Referenced by lost_connection_to_client().