![]() |
Freeciv21
Develop your civilization from humble roots to a global empire
|
#include <QLocalSocket>#include <QTcpSocket>#include "fcintl.h"#include "genhash.h"#include "log.h"#include "support.h"#include "game.h"#include "packets.h"#include "connection.h"
Include dependency graph for connection.cpp:Go to the source code of this file.
Classes | |
| struct | conn_pattern |
| Connection patterns. More... | |
Functions | |
| static void | default_conn_close_callback (struct connection *pconn) |
| Default 'conn_close_fn_t' to close a connection. More... | |
| void | connections_set_close_callback (conn_close_fn_t func) |
| Register the close_callback. More... | |
| void | connection_close (struct connection *pconn, const QString &reason) |
| Call the conn_close_callback. More... | |
| static bool | buffer_ensure_free_extra_space (struct socket_packet_buffer *buf, int extra_space) |
| Make sure that there is at least extra_space bytes free space in buffer, allocating more memory if needed. More... | |
| int | read_socket_data (QIODevice *sock, struct socket_packet_buffer *buffer) |
| Read data from socket, and check if a packet is ready. More... | |
| static int | write_socket_data (struct connection *pc, struct socket_packet_buffer *buf, int limit) |
| Write wrapper function -vasc. More... | |
| void | flush_connection_send_buffer_all (struct connection *pc) |
| Flush'em. More... | |
| static void | flush_connection_send_buffer_packets (struct connection *pc) |
| Flush'em. More... | |
| static bool | add_connection_data (struct connection *pconn, const unsigned char *data, int len) |
| Add data to send to the connection. More... | |
| bool | connection_send_data (struct connection *pconn, const unsigned char *data, int len) |
| Write data to socket. More... | |
| void | connection_do_buffer (struct connection *pc) |
| Turn on buffering, using a counter so that calls may be nested. More... | |
| void | connection_do_unbuffer (struct connection *pc) |
| Turn off buffering if internal counter of number of times buffering was turned on falls to zero, to handle nested buffer/unbuffer pairs. More... | |
| void | conn_list_do_buffer (struct conn_list *dest) |
| Convenience functions to buffer a list of connections. More... | |
| void | conn_list_do_unbuffer (struct conn_list *dest) |
| Convenience functions to unbuffer a list of connections. More... | |
| struct connection * | conn_by_user (const char *user_name) |
| Find connection by exact user name, from game.all_connections, case-insensitve. More... | |
| static const char * | connection_accessor (int i) |
| Like conn_by_username(), but allow unambigous prefix (i.e. More... | |
| struct connection * | conn_by_user_prefix (const char *user_name, enum m_pre_result *result) |
| struct connection * | conn_by_number (int id) |
| Find connection by id, from game.all_connections. More... | |
| struct socket_packet_buffer * | new_socket_packet_buffer () |
| Return malloced struct, appropriately initialized. More... | |
| static void | free_socket_packet_buffer (struct socket_packet_buffer *buf) |
| Free malloced struct. More... | |
| 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->name, pconn->addr, and (if applicable) ° pconn->playing->name. More... | |
| bool | can_conn_edit (const struct connection *pconn) |
| Return TRUE iff the connection is currently allowed to edit. More... | |
| bool | can_conn_enable_editing (const struct connection *pconn) |
| Return TRUE iff the connection is allowed to start editing. More... | |
| int | get_next_request_id (int old_request_id) |
| Get next request id. More... | |
| void | free_compression_queue (struct connection *pc) |
| Free compression queue for given connection. More... | |
| static void | init_packet_hashs (struct connection *pc) |
| Allocate and initialize packet hashs for given connection. More... | |
| static void | free_packet_hashes (struct connection *pc) |
| Free packet hash resources from given connection. More... | |
| void | connection_common_init (struct connection *pconn) |
| Initialize common part of connection structure. More... | |
| void | connection_common_close (struct connection *pconn) |
| Connection closing part common to server and client. More... | |
| void | conn_set_capability (struct connection *pconn, const char *capability) |
| Set the network capability string for 'pconn'. More... | |
| void | conn_reset_delta_state (struct connection *pc) |
| Remove all is-game-info cached packets from the connection. More... | |
| void | conn_compression_freeze (struct connection *pconn) |
| Freeze the connection. More... | |
| bool | conn_compression_frozen (const struct connection *pconn) |
| Returns TRUE if the connection is frozen. More... | |
| void | conn_list_compression_freeze (const struct conn_list *pconn_list) |
| Freeze a connection list. More... | |
| void | conn_list_compression_thaw (const struct conn_list *pconn_list) |
| Thaw a connection list. More... | |
| bool | conn_controls_player (const struct connection *pconn) |
| Returns TRUE if the given connection is attached to a player which it also controls (i.e. More... | |
| bool | conn_is_global_observer (const struct connection *pconn) |
| Returns TRUE if the given connection is a global observer. More... | |
| struct player * | conn_get_player (const struct connection *pconn) |
| Returns the player that this connection is attached to, or nullptr. More... | |
| enum cmdlevel | conn_get_access (const struct connection *pconn) |
| Returns the current access level of the given connection. More... | |
| struct conn_pattern * | conn_pattern_new (enum conn_pattern_type type, const char *wildcard) |
| Creates a new connection pattern. More... | |
| void | conn_pattern_destroy (struct conn_pattern *ppattern) |
| Free a connection pattern. More... | |
| bool | conn_pattern_match (const struct conn_pattern *ppattern, const struct connection *pconn) |
| Returns TRUE whether the connection fits the connection pattern. More... | |
| bool | conn_pattern_list_match (const struct conn_pattern_list *plist, const struct connection *pconn) |
| Returns TRUE whether the connection fits one of the connection patterns. More... | |
| size_t | conn_pattern_to_string (const struct conn_pattern *ppattern, char *buf, size_t buf_len) |
| Put a string reprentation of the pattern in 'buf'. More... | |
| struct conn_pattern * | conn_pattern_from_string (const char *pattern, enum conn_pattern_type prefer, char *error_buf, size_t error_buf_len) |
| Creates a new connection pattern from the string. More... | |
| bool | conn_is_valid (const struct connection *pconn) |
| Returns TRUE if the connection is valid, i.e. More... | |
Variables | |
| const char | blank_addr_str [] = "---.---.---.---" |
| static conn_close_fn_t | conn_close_callback = default_conn_close_callback |
| This callback is used when an error occurs trying to write to the connection. More... | |
|
static |
Add data to send to the connection.
Definition at line 219 of file connection.cpp.
Referenced by connection_send_data().
|
static |
Make sure that there is at least extra_space bytes free space in buffer, allocating more memory if needed.
Definition at line 85 of file connection.cpp.
Referenced by add_connection_data(), and read_socket_data().
| bool can_conn_edit | ( | const struct connection * | pconn | ) |
Return TRUE iff the connection is currently allowed to edit.
Definition at line 472 of file connection.cpp.
Referenced by can_conn_edit_players_nation(), connection_attach_real(), edithand_send_initial_packets(), editor_is_active(), handle_edit_startpos(), handle_edit_startpos_full(), and server_packet_input().
| bool can_conn_enable_editing | ( | const struct connection * | pconn | ) |
Return TRUE iff the connection is allowed to start editing.
Definition at line 481 of file connection.cpp.
Referenced by can_conn_edit(), and handle_edit_mode().
| struct connection* conn_by_number | ( | int | id | ) |
Find connection by id, from game.all_connections.
Returns nullptr if not found. Number of connections will always be relatively small given current implementation, so linear search should be fine.
Definition at line 376 of file connection.cpp.
Referenced by check_vote(), handle_conn_info(), lsend_vote_new(), lsend_vote_update(), makeup_connection_name(), and vote_get_caller().
| struct connection* conn_by_user | ( | const char * | user_name | ) |
Find connection by exact user name, from game.all_connections, case-insensitve.
Returns nullptr if not found.
Definition at line 329 of file connection.cpp.
Referenced by delegate_command(), establish_new_connection(), get_unique_guest_name(), is_allowed_city_name(), makeup_connection_name(), and send_to_metaserver().
| struct connection* conn_by_user_prefix | ( | const char * | user_name, |
| enum m_pre_result * | result | ||
| ) |
Definition at line 353 of file connection.cpp.
Referenced by cmdlevel_command(), cut_client_connection(), detach_command(), handle_chat_msg_req(), kick_command(), observe_command(), and take_command().
| void conn_compression_freeze | ( | struct connection * | pconn | ) |
Freeze the connection.
Then the packets sent to it won't be sent immediatly, but later, using a compression method. See futher details in common/packets.[ch].
Definition at line 636 of file connection.cpp.
Referenced by conn_list_compression_freeze(), connection_attach_real(), establish_new_connection(), and start_processing_request().
| bool conn_compression_frozen | ( | const struct connection * | pconn | ) |
Returns TRUE if the connection is frozen.
See also conn_compression_freeze().
Definition at line 648 of file connection.cpp.
Referenced by send_packet_data().
| bool conn_controls_player | ( | const struct connection * | pconn | ) |
Returns TRUE if the given connection is attached to a player which it also controls (i.e.
not a player observer).
Definition at line 675 of file connection.cpp.
Referenced by away_command(), conn_can_vote(), connection_delegate_restore(), connection_delegate_take(), cut_client_connection(), delegate_command(), establish_new_connection(), kick_command(), lost_connection_to_client(), send_all_info(), and surrender_command().
| 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->name, pconn->addr, and (if applicable) ° pconn->playing->name.
(Also pconn->established and pconn->observer.) ° ° Note that when pconn is client.conn (connection to server), ° pconn->name and pconn->addr contain empty string, and pconn->playing ° is nullptr: in this case return string "server".
If is_private is true, show the actual hostname, otherwise mask it.
Definition at line 431 of file connection.cpp.
Referenced by conn_compression_thaw(), connection_ping(), connection_send_data(), default_conn_close_callback(), flush_packets(), handle_conn_pong(), handle_edit_mode(), handle_login_request(), handle_vote_submit(), lost_connection_to_client(), packet_check(), reject_new_connection(), freeciv::server::send_pings(), send_remove_team_votes(), send_running_votes(), server_packet_input(), and show_connections().
| enum cmdlevel conn_get_access | ( | const struct connection * | pconn | ) |
Returns the current access level of the given connection.
NB: If 'pconn' is nullptr, this function will return ALLOW_NONE.
Definition at line 693 of file connection.cpp.
Referenced by cancelvote_command(), cmdlevel_command(), conn_can_vote(), conn_set_access(), delegate_command(), handle_stdin_input_real(), kick_command(), and may_use_nothing().
| struct player* conn_get_player | ( | const struct connection * | pconn | ) |
Returns the player that this connection is attached to, or nullptr.
Note that this will return the observed player for connections that are observing players.
Definition at line 693 of file connection.cpp.
Referenced by away_command(), cancelvote_command(), check_vote(), conn_can_see_vote(), conn_can_vote(), connection_delegate_restore(), connection_delegate_take(), delegate_command(), establish_new_connection(), handle_stdin_input_real(), really_close_connections(), send_city_turn_notifications(), send_pending_events(), send_remove_team_votes(), send_research_info(), send_running_votes(), send_unit_info(), surrender_command(), and unit_move().
| bool conn_is_global_observer | ( | const struct connection * | pconn | ) |
Returns TRUE if the given connection is a global observer.
Definition at line 683 of file connection.cpp.
Referenced by broadcast_city_info(), chat_msg_to_global_observers(), conn_can_see_vote(), send_city_info_at_tile(), send_pending_events(), and server_remove_unit_full().
| bool conn_is_valid | ( | const struct connection * | pconn | ) |
Returns TRUE if the connection is valid, i.e.
not nullptr, not closed, not closing, etc.
Definition at line 864 of file connection.cpp.
Referenced by auth_get_ipaddr(), and auth_get_username().
| void conn_list_compression_freeze | ( | const struct conn_list * | pconn_list | ) |
Freeze a connection list.
Definition at line 656 of file connection.cpp.
Referenced by buffer_shared_vision(), load_command(), send_rulesets(), and srv_ready().
| void conn_list_compression_thaw | ( | const struct conn_list * | pconn_list | ) |
Thaw a connection list.
Definition at line 665 of file connection.cpp.
Referenced by load_command(), send_rulesets(), srv_ready(), and unbuffer_shared_vision().
| void conn_list_do_buffer | ( | struct conn_list * | dest | ) |
Convenience functions to buffer a list of connections.
Definition at line 310 of file connection.cpp.
Referenced by begin_phase(), buffer_shared_vision(), check_leaving_edit_mode(), city_refresh_for_player(), do_unit_establish_trade(), freeciv::server::end_phase(), handle_edit_city(), handle_edit_city_create(), handle_edit_player_vision(), handle_edit_tile_extra(), handle_edit_tile_terrain(), handle_edit_toggle_fogofwar(), handle_edit_unit_create(), handle_unit_type_upgrade(), really_handle_city_buy(), remove_player_from_maps(), send_all_known_cities(), send_all_known_tiles(), send_all_known_units(), send_updated_vote_totals(), transform_unit(), unit_do_help_build(), unit_move(), and upgrade_all_city_extras().
| void conn_list_do_unbuffer | ( | struct conn_list * | dest | ) |
Convenience functions to unbuffer a list of connections.
Definition at line 319 of file connection.cpp.
Referenced by begin_phase(), check_leaving_edit_mode(), city_refresh_for_player(), do_unit_establish_trade(), freeciv::server::end_phase(), handle_edit_city(), handle_edit_city_create(), handle_edit_player_vision(), handle_edit_tile_extra(), handle_edit_tile_terrain(), handle_edit_toggle_fogofwar(), handle_edit_unit_create(), handle_unit_type_upgrade(), really_handle_city_buy(), remove_player_from_maps(), send_all_known_cities(), send_all_known_tiles(), send_all_known_units(), send_updated_vote_totals(), transform_unit(), unbuffer_shared_vision(), unit_do_help_build(), unit_move(), and upgrade_all_city_extras().
| void conn_pattern_destroy | ( | struct conn_pattern * | ppattern | ) |
Free a connection pattern.
Definition at line 738 of file connection.cpp.
Referenced by ignore_command(), and server_make_connection().
| struct conn_pattern* conn_pattern_from_string | ( | const char * | pattern, |
| enum conn_pattern_type | prefer, | ||
| char * | error_buf, | ||
| size_t | error_buf_len | ||
| ) |
Creates a new connection pattern from the string.
If the type is not specified in 'pattern', then 'prefer' type will be used. If the type is needed, then pass conn_pattern_type_invalid() for 'prefer'.
Definition at line 809 of file connection.cpp.
Referenced by ignore_command().
| bool conn_pattern_list_match | ( | const struct conn_pattern_list * | plist, |
| const struct connection * | pconn | ||
| ) |
Returns TRUE whether the connection fits one of the connection patterns.
Definition at line 779 of file connection.cpp.
Referenced by conn_is_ignored().
| bool conn_pattern_match | ( | const struct conn_pattern * | ppattern, |
| const struct connection * | pconn | ||
| ) |
Returns TRUE whether the connection fits the connection pattern.
Definition at line 748 of file connection.cpp.
Referenced by conn_pattern_list_match().
| struct conn_pattern* conn_pattern_new | ( | enum conn_pattern_type | type, |
| const char * | wildcard | ||
| ) |
Creates a new connection pattern.
Definition at line 724 of file connection.cpp.
Referenced by conn_pattern_from_string().
| size_t conn_pattern_to_string | ( | const struct conn_pattern * | ppattern, |
| char * | buf, | ||
| size_t | buf_len | ||
| ) |
Put a string reprentation of the pattern in 'buf'.
Definition at line 796 of file connection.cpp.
Referenced by ignore_command(), show_ignore(), and unignore_command().
| void conn_reset_delta_state | ( | struct connection * | pc | ) |
Remove all is-game-info cached packets from the connection.
This resets the delta-state partially.
Definition at line 615 of file connection.cpp.
Referenced by client_state(), and connection_attach_real().
| void conn_set_capability | ( | struct connection * | pconn, |
| const char * | capability | ||
| ) |
Set the network capability string for 'pconn'.
Definition at line 603 of file connection.cpp.
Referenced by handle_login_request(), and handle_server_join_reply().
|
static |
Like conn_by_username(), but allow unambigous prefix (i.e.
abbreviation). Returns nullptr if could not match, or if ambiguous or other problem, and fills *result with characterisation of match/non-match (see "utility/shared.[ch]").
Definition at line 348 of file connection.cpp.
Referenced by conn_by_user_prefix().
| void connection_close | ( | struct connection * | pconn, |
| const QString & | reason | ||
| ) |
Call the conn_close_callback.
Definition at line 69 of file connection.cpp.
Referenced by add_connection_data(), connection_close_server(), get_packet_from_connection_raw(), input_from_server(), and write_socket_data().
| void connection_common_close | ( | struct connection * | pconn | ) |
Connection closing part common to server and client.
Definition at line 574 of file connection.cpp.
Referenced by close_connection(), and close_socket_nomessage().
| void connection_common_init | ( | struct connection * | pconn | ) |
Initialize common part of connection structure.
This is used by both server and client.
Definition at line 555 of file connection.cpp.
Referenced by make_connection(), manual_command(), and server_make_connection().
| void connection_do_buffer | ( | struct connection * | pc | ) |
Turn on buffering, using a counter so that calls may be nested.
Definition at line 278 of file connection.cpp.
Referenced by cma_yoloswag::apply_result_on_server(), conn_list_do_buffer(), edit_buffer_paste(), editor_apply_tool_to_selection(), incoming_client_packets(), send_attribute_block(), send_remove_team_votes(), and send_running_votes().
| void connection_do_unbuffer | ( | struct connection * | pc | ) |
Turn off buffering if internal counter of number of times buffering was turned on falls to zero, to handle nested buffer/unbuffer pairs.
When counter is zero, flush any pending data.
Definition at line 290 of file connection.cpp.
Referenced by cma_yoloswag::apply_result_on_server(), conn_list_do_unbuffer(), edit_buffer_paste(), editor_apply_tool_to_selection(), incoming_client_packets(), send_attribute_block(), send_remove_team_votes(), and send_running_votes().
| bool connection_send_data | ( | struct connection * | pconn, |
| const unsigned char * | data, | ||
| int | len | ||
| ) |
Write data to socket.
Return TRUE on success.
Definition at line 245 of file connection.cpp.
Referenced by conn_compression_flush(), send_packet_data(), and server_packet_input().
| void connections_set_close_callback | ( | conn_close_fn_t | func | ) |
Register the close_callback.
Definition at line 61 of file connection.cpp.
Referenced by server_open_socket(), and try_to_connect().
|
static |
Default 'conn_close_fn_t' to close a connection.
Definition at line 50 of file connection.cpp.
| void flush_connection_send_buffer_all | ( | struct connection * | pc | ) |
Flush'em.
Definition at line 177 of file connection.cpp.
Referenced by connection_do_unbuffer(), connection_send_data(), flush_packets(), read_from_connection(), and reject_new_connection().
|
static |
| void free_compression_queue | ( | struct connection * | pc | ) |
Free compression queue for given connection.
Definition at line 508 of file connection.cpp.
Referenced by connection_common_close().
|
static |
Free packet hash resources from given connection.
Definition at line 526 of file connection.cpp.
Referenced by connection_common_close().
|
static |
Free malloced struct.
Definition at line 409 of file connection.cpp.
Referenced by connection_common_close().
| int get_next_request_id | ( | int | old_request_id | ) |
Get next request id.
Takes wrapping of the 16 bit wide unsigned int into account.
Definition at line 490 of file connection.cpp.
Referenced by handle_processing_started(), incoming_client_packets(), and send_packet_data().
|
static |
Allocate and initialize packet hashs for given connection.
Definition at line 516 of file connection.cpp.
Referenced by connection_common_init().
| struct socket_packet_buffer* new_socket_packet_buffer | ( | ) |
Return malloced struct, appropriately initialized.
Definition at line 395 of file connection.cpp.
Referenced by connection_common_init().
| int read_socket_data | ( | QIODevice * | sock, |
| struct socket_packet_buffer * | buffer | ||
| ) |
Read data from socket, and check if a packet is ready.
Returns: -1 : an error occurred - you should close the socket -2 : the connection was closed >0 : number of bytes read =0 : non-blocking sockets only; no data read, would block
Definition at line 110 of file connection.cpp.
Referenced by freeciv::server::input_on_socket(), and read_from_connection().
|
static |
Write wrapper function -vasc.
Definition at line 138 of file connection.cpp.
Referenced by flush_connection_send_buffer_all(), and flush_connection_send_buffer_packets().
| const char blank_addr_str[] = "---.---.---.---" |
Definition at line 35 of file connection.cpp.
|
static |
This callback is used when an error occurs trying to write to the connection.
The effect of the callback should be to close the connection. This is here so that the server and client can take appropriate (different) actions: server lost a client, client lost connection to server. Never attempt to call this function directly, call connection_close() instead.
Definition at line 45 of file connection.cpp.
Referenced by connections_set_close_callback(), and default_conn_close_callback().