Freeciv21
Develop your civilization from humble roots to a global empire
sernet.cpp File Reference
#include <fc_config.h>
#include <cstring>
#include <QCoreApplication>
#include <QHostInfo>
#include <QLocalServer>
#include <QNetworkDatagram>
#include <QTcpServer>
#include <QTcpSocket>
#include <QUdpSocket>
#include "log.h"
#include "shared.h"
#include "support.h"
#include "timing.h"
#include "fc_version.h"
#include "dataio.h"
#include "events.h"
#include "game.h"
#include "packets.h"
#include "script_server.h"
#include "aiiface.h"
#include "connecthand.h"
#include "meta.h"
#include "plrhand.h"
#include "srv_main.h"
#include "stdinhand.h"
#include "unittools.h"
#include "voting.h"
#include "sernet.h"
+ Include dependency graph for sernet.cpp:

Go to the source code of this file.

Classes

struct  packet_to_handle
 

Macros

#define PROCESSING_TIME_STATISTICS   0
 

Functions

static void start_processing_request (struct connection *pconn, int request_id)
 Starts processing of request packet from client. More...
 
static void finish_processing_request (struct connection *pconn)
 Finish processing of request packet from client. More...
 
static void send_lanserver_response ()
 This function broadcasts an UDP packet to clients with that requests information about the server state. More...
 
static void close_connection (struct connection *pconn)
 Close the connection (very low-level). More...
 
void close_connections_and_socket ()
 Close all network stuff: connections, listening sockets, metaserver connection... More...
 
void really_close_connections ()
 Now really close connections marked as 'is_closing'. More...
 
static void server_conn_close_callback (struct connection *pconn)
 Break a client connection. More...
 
void flush_packets ()
 Attempt to flush all information in the send buffers for upto 'netwait' seconds. More...
 
static bool get_packet (struct connection *pconn, struct packet_to_handle *ppacket)
 Simplify a loop by wrapping get_packet_from_connection. More...
 
void incoming_client_packets (struct connection *pconn)
 Handle all incoming packets on a client connection. More...
 
static const char * makeup_connection_name (int *id)
 Make up a name for the connection, before we get any data from it to use as a sensible name. More...
 
int server_make_connection (QIODevice *new_sock, const QString &client_addr, const QString &ip_addr)
 Server accepts connection from client: Low level socket stuff, and basic-initialize the connection struct. More...
 
std::optional< socket_serverserver_open_socket ()
 Open server socket to be used to accept client connections and open a server socket for server LAN announcements. More...
 
void init_connections ()
 Initialize connection related stuff. More...
 
void finish_unit_waits ()
 Process all unit waits that are expired. More...
 
void connection_ping (struct connection *pconn)
 Ping a connection. More...
 
void handle_conn_pong (struct connection *pconn)
 Handle response to ping. More...
 
void handle_client_heartbeat (struct connection *pconn)
 Handle client's regular hearbeat. More...
 
void get_lanserver_announcement ()
 Listen for UDP packets multicasted from clients requesting announcement of servers on the LAN. More...
 

Variables

static struct connection connections [MAX_NUM_CONNECTIONS]
 
static QUdpSocket * udp_socket = nullptr
 

Macro Definition Documentation

◆ PROCESSING_TIME_STATISTICS

#define PROCESSING_TIME_STATISTICS   0

Definition at line 61 of file sernet.cpp.

Function Documentation

◆ close_connection()

static void close_connection ( struct connection pconn)
static

Close the connection (very low-level).

See also server_conn_close_callback().

Definition at line 73 of file sernet.cpp.

Referenced by close_connections_and_socket(), and really_close_connections().

◆ close_connections_and_socket()

void close_connections_and_socket ( )

Close all network stuff: connections, listening sockets, metaserver connection...

Definition at line 106 of file sernet.cpp.

Referenced by server_quit().

◆ connection_ping()

void connection_ping ( struct connection pconn)

Ping a connection.

Definition at line 527 of file sernet.cpp.

Referenced by freeciv::server::send_pings().

◆ finish_processing_request()

static void finish_processing_request ( struct connection pconn)
static

Finish processing of request packet from client.

Definition at line 487 of file sernet.cpp.

Referenced by incoming_client_packets().

◆ finish_unit_waits()

void finish_unit_waits ( )

Process all unit waits that are expired.

Definition at line 503 of file sernet.cpp.

Referenced by freeciv::server::pulse().

◆ flush_packets()

void flush_packets ( )

Attempt to flush all information in the send buffers for upto 'netwait' seconds.

Definition at line 187 of file sernet.cpp.

Referenced by begin_phase(), dai_do_first_activities(), end_phase(), send_all_known_cities(), send_all_known_tiles(), and send_all_known_units().

◆ get_lanserver_announcement()

void get_lanserver_announcement ( )

Listen for UDP packets multicasted from clients requesting announcement of servers on the LAN.

Definition at line 572 of file sernet.cpp.

Referenced by freeciv::server::pulse().

◆ get_packet()

static bool get_packet ( struct connection pconn,
struct packet_to_handle ppacket 
)
static

Simplify a loop by wrapping get_packet_from_connection.

Definition at line 216 of file sernet.cpp.

Referenced by incoming_client_packets().

◆ handle_client_heartbeat()

void handle_client_heartbeat ( struct connection pconn)

Handle client's regular hearbeat.

Definition at line 563 of file sernet.cpp.

◆ handle_conn_pong()

void handle_conn_pong ( struct connection pconn)

Handle response to ping.

Definition at line 541 of file sernet.cpp.

Referenced by server_packet_input().

◆ incoming_client_packets()

void incoming_client_packets ( struct connection pconn)

Handle all incoming packets on a client connection.

Precondition - we have read_socket_data. Postcondition - there are no more packets to handle on this connection.

Definition at line 229 of file sernet.cpp.

Referenced by freeciv::server::input_on_socket().

◆ init_connections()

void init_connections ( )

Initialize connection related stuff.

Attention: Logging is not available within this functions!

Definition at line 452 of file sernet.cpp.

Referenced by main().

◆ makeup_connection_name()

static const char* makeup_connection_name ( int *  id)
static

Make up a name for the connection, before we get any data from it to use as a sensible name.

Name will be 'c' + integer, guaranteed not to be the same as any other connection name, nor player name nor user name, nor connection id (avoid possible confusions). Returns pointer to static buffer, and fills in (*id) with chosen value.

Definition at line 285 of file sernet.cpp.

Referenced by server_make_connection().

◆ really_close_connections()

void really_close_connections ( )

Now really close connections marked as 'is_closing'.

Do this here to avoid recursive sending.

Definition at line 140 of file sernet.cpp.

Referenced by freeciv::server::error_on_socket(), and freeciv::server::input_on_socket().

◆ send_lanserver_response()

static void send_lanserver_response ( )
static

This function broadcasts an UDP packet to clients with that requests information about the server state.

Definition at line 600 of file sernet.cpp.

Referenced by get_lanserver_announcement().

◆ server_conn_close_callback()

static void server_conn_close_callback ( struct connection pconn)
static

Break a client connection.

You should almost always use connection_close_server() instead of calling this function directly.

Definition at line 177 of file sernet.cpp.

Referenced by server_open_socket().

◆ server_make_connection()

int server_make_connection ( QIODevice *  new_sock,
const QString &  client_addr,
const QString &  ip_addr 
)

Server accepts connection from client: Low level socket stuff, and basic-initialize the connection struct.

Returns 0 on success, -1 on failure (bad accept(), or too many connections).

Definition at line 310 of file sernet.cpp.

Referenced by freeciv::server::accept_local_connections(), and freeciv::server::accept_tcp_connections().

◆ server_open_socket()

std::optional<socket_server> server_open_socket ( )

Open server socket to be used to accept client connections and open a server socket for server LAN announcements.

Definition at line 370 of file sernet.cpp.

◆ start_processing_request()

static void start_processing_request ( struct connection pconn,
int  request_id 
)
static

Starts processing of request packet from client.

Definition at line 472 of file sernet.cpp.

Referenced by incoming_client_packets().

Variable Documentation

◆ connections

◆ udp_socket

QUdpSocket* udp_socket = nullptr
static