Freeciv-3.3: /fast/freeciv/nightly/main/server/sernet.c File Reference

Freeciv-3.3

Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables
sernet.c File Reference
`#include "fc_prehdrs.h"`
`#include <errno.h>`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include <time.h>`
`#include "capability.h"`
`#include "fciconv.h"`
`#include "fcintl.h"`
`#include "log.h"`
`#include "mem.h"`
`#include "netintf.h"`
`#include "shared.h"`
`#include "support.h"`
`#include "timing.h"`
`#include "dataio.h"`
`#include "events.h"`
`#include "game.h"`
`#include "packets.h"`
`#include "script_server.h"`
`#include "aiiface.h"`
`#include "auth.h"`
`#include "connecthand.h"`
`#include "console.h"`
`#include "meta.h"`
`#include "plrhand.h"`
`#include "srv_main.h"`
`#include "stdinhand.h"`
`#include "voting.h"`
`#include "sernet.h"`

Go to the source code of this file.

## Data Structures

struct | packet_to_handle

## Macros

#define | PROCESSING_TIME_STATISTICS 0

## Functions

static int | server_accept_connection (int sockfd)
static void | start_processing_request (struct connection *pconn, int request_id)
static void | finish_processing_request (struct connection *pconn)
static void | connection_ping (struct connection *pconn)
static void | send_ping_times_to_all (void)
static void | get_lanserver_announcement (void)
static void | send_lanserver_response (void)
static void | handle_stdin_close (void)
void | readline_atexit (void)
static void | close_connection (struct connection *pconn)
void | close_connections_and_socket (void)
static void | really_close_connections (void)
static void | server_conn_close_callback (struct connection *pconn)
static void | cut_lagging_connection (struct connection *pconn)
void | flush_packets (void)
static bool | get_packet (struct connection *pconn, struct packet_to_handle *ppacket)
static void | incoming_client_packets (struct connection *pconn)
enum server_events | server_sniff_all_input (void)
static const char * | makeup_connection_name (int *id)
int | server_make_connection (int new_sock, const char *client_addr, const char *client_ip)
int | server_open_socket (void)
void | init_connections (void)
void | handle_conn_pong (struct connection *pconn)
void | handle_client_heartbeat (struct connection *pconn)

## Variables

static struct connection | connections [MAX_NUM_CONNECTIONS]
static int * | listen_socks
static int | listen_count
static int | socklan
static bool | no_input = FALSE
static char * | current_internal = NULL

## Macro Definition Documentation

## ◆ PROCESSING_TIME_STATISTICS

#define PROCESSING_TIME_STATISTICS 0

Definition at line 118 of file sernet.c.

## 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 223 of file sernet.c.

Referenced by close_connections_and_socket(), and really_close_connections().

## ◆ close_connections_and_socket()

void close_connections_and_socket | ( | void |  | ) |

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

Definition at line 255 of file sernet.c.

Referenced by server_quit().

## ◆ connection_ping()

static void connection_ping | ( | struct connection * | pconn | ) |

static

Ping a connection.

Definition at line 1427 of file sernet.c.

Referenced by server_sniff_all_input().

## ◆ cut_lagging_connection()

static void cut_lagging_connection | ( | struct connection * | pconn | ) |

static

If a connection lags too much this function is called and we try to cut it.

Definition at line 351 of file sernet.c.

Referenced by flush_packets(), and server_sniff_all_input().

## ◆ finish_processing_request()

static void finish_processing_request | ( | struct connection * | pconn | ) |

static

Finish processing of request packet from client.

Definition at line 1409 of file sernet.c.

Referenced by incoming_client_packets().

## ◆ flush_packets()

void flush_packets | ( | void |  | ) |

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

Definition at line 376 of file sernet.c.

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()

static void get_lanserver_announcement | ( | void |  | ) |

static

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

Definition at line 1493 of file sernet.c.

Referenced by server_sniff_all_input().

## ◆ 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 451 of file sernet.c.

Referenced by incoming_client_packets().

## ◆ handle_client_heartbeat()

void handle_client_heartbeat | ( | struct connection * | pconn | ) |

Handle client's regular hearbeat

Definition at line 1461 of file sernet.c.

Referenced by server_handle_packet().

## ◆ handle_conn_pong()

void handle_conn_pong | ( | struct connection * | pconn | ) |

Handle response to ping.

Definition at line 1441 of file sernet.c.

Referenced by server_handle_packet(), and server_packet_input().

## ◆ handle_stdin_close()

static void handle_stdin_close | ( | void |  | ) |

static

This happens if you type an EOF character with nothing on the current line.

Definition at line 139 of file sernet.c.

Referenced by server_sniff_all_input().

## ◆ incoming_client_packets()

static void incoming_client_packets | ( | struct connection * | pconn | ) |

static

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 464 of file sernet.c.

Referenced by server_sniff_all_input().

## ◆ init_connections()

void init_connections | ( | void |  | ) |

Initialize connection related stuff. Attention: Logging is not available within this functions!

Definition at line 1362 of file sernet.c.

Referenced by main(), and srv_prepare().

## ◆ 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 959 of file sernet.c.

Referenced by server_make_connection().

## ◆ readline_atexit()

void readline_atexit | ( | void |  | ) |

Clear readline stuff at exit. To cater for as many different cases as possible, we call this both like any function call from server_quit() before exit(), and as a atexit handler. Former is to get everything cleared already before exit(), before any other atexit handler comes to play. Latter is to make sure that the function gets called also when in those rare cases where we exit some other way than server_quit() - that's important for always restoring terminal to a working state.

That means that in usual case this function gets called twice. Make sure that it doesn't try double frees or similar when that happens.

Definition at line 204 of file sernet.c.

Referenced by server_quit(), and server_sniff_all_input().

## ◆ really_close_connections()

static void really_close_connections | ( | void |  | ) |

static

Now really close connections marked as 'is_closing'. Do this here to avoid recursive sending.

Definition at line 304 of file sernet.c.

Referenced by server_sniff_all_input().

## ◆ send_lanserver_response()

static void send_lanserver_response | ( | void |  | ) |

static

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

Definition at line 1542 of file sernet.c.

Referenced by get_lanserver_announcement().

## ◆ send_ping_times_to_all()

static void send_ping_times_to_all | ( | void |  | ) |

static

Send ping time info about all connections to all connections.

Definition at line 1469 of file sernet.c.

Referenced by server_sniff_all_input().

## ◆ server_accept_connection()

static int server_accept_connection | ( | int | sockfd | ) |

static

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 986 of file sernet.c.

Referenced by server_sniff_all_input().

## ◆ 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 342 of file sernet.c.

Referenced by server_open_socket().

## ◆ server_make_connection()

int server_make_connection | ( | int | new_sock,
|  | const char * | client_addr,
|  | const char * | client_ip
| ) |  |

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 1071 of file sernet.c.

Referenced by server_accept_connection().

## ◆ server_open_socket()

int server_open_socket | ( | void |  | ) |

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

Definition at line 1133 of file sernet.c.

Referenced by srv_prepare().

## ◆ server_sniff_all_input()

enum server_events server_sniff_all_input | ( | void |  | ) |

Get and handle:

- new connections,
- input from connections,
- input from server operator in stdin

This function also handles prompt printing, via the con_prompt_* functions. That is, other functions should not need to do so. –dwp

Definition at line 522 of file sernet.c.

Referenced by srv_main(), and srv_running().

## ◆ 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 1394 of file sernet.c.

Referenced by incoming_client_packets().

## Variable Documentation

## ◆ connections

struct connection connections[MAX_NUM_CONNECTIONS]

static

Definition at line 94 of file sernet.c.

Referenced by clear_worker_task(), client_handle_packet(), close_connections_and_socket(), flush_packets(), handle_conn_ping_info(), init_connections(), package_and_send_worker_tasks(), really_close_connections(), receive_packet_conn_ping_info_100(), server_make_connection(), and server_sniff_all_input().

## ◆ current_internal

char* current_internal = NULL

static

Definition at line 152 of file sernet.c.

Referenced by readline_atexit(), and server_sniff_all_input().

## ◆ listen_count

int listen_count

static

Definition at line 97 of file sernet.c.

Referenced by close_connections_and_socket(), server_open_socket(), and server_sniff_all_input().

## ◆ listen_socks

int* listen_socks

static

Definition at line 96 of file sernet.c.

Referenced by close_connections_and_socket(), server_open_socket(), and server_sniff_all_input().

## ◆ no_input

bool no_input = FALSE

static

Definition at line 130 of file sernet.c.

Referenced by handle_stdin_close(), and server_sniff_all_input().

## ◆ socklan

int socklan

static

Definition at line 98 of file sernet.c.

Referenced by close_connections_and_socket(), get_lanserver_announcement(), and server_open_socket().