![]() |
Freeciv21
Develop your civilization from humble roots to a global empire
|
#include <cstring>#include "capability.h"#include "connection.h"#include "fcintl.h"#include "log.h"#include "support.h"#include "dataio.h"#include "game.h"#include "packets.h"#include <QRegularExpression>#include <zlib.h>
Include dependency graph for packets.cpp:Go to the source code of this file.
Macros | |
| #define | JUMBO_SIZE 0xffff |
| #define | COMPRESSION_BORDER (16 * 1024 + 1) |
| #define | PACKET_STRVEC_SEPARATOR '\3' |
| #define | JUMBO_BORDER (64 * 1024 - COMPRESSION_BORDER - 1) |
| #define | log_compress log_debug |
| #define | log_compress2 log_debug |
| #define | MAX_DECOMPRESSION 400 |
| #define | PACKET_SIZE_STATISTICS 0 |
| #define | MAX_LEN_COMPRESS_QUEUE (MAX_LEN_BUFFER / 2) |
Typedefs | |
| typedef QHash< QString, struct packet_handlers * > | packetsHash |
Functions | |
| static int | get_compression_level () |
| Returns the compression level. More... | |
| static bool | conn_compression_flush (struct connection *pconn) |
| Send all waiting data. More... | |
| bool | conn_compression_thaw (struct connection *pconn) |
| Thaw the connection. More... | |
| int | send_packet_data (struct connection *pc, unsigned char *data, int len, enum packet_type packet_type) |
| It returns the request id of the outgoing packet (or 0 if is_server()). More... | |
| void * | get_packet_from_connection_raw (struct connection *pc, enum packet_type *ptype) |
| Read and return a packet from the connection 'pc'. More... | |
| void | remove_packet_from_buffer (struct socket_packet_buffer *buffer) |
| Remove the packet from the buffer. More... | |
| void | packet_header_init (struct packet_header *packet_header) |
| Set the packet header field lengths used for the login protocol, before the capability of the connection could be checked. More... | |
| static void | packet_header_set (struct packet_header *packet_header) |
| Set the packet header field lengths used after the login protocol, after the capability of the connection could be checked. More... | |
| void | post_send_packet_server_join_reply (struct connection *pconn, const struct packet_server_join_reply *packet) |
| Modify if needed the packet header field lengths. More... | |
| void | post_receive_packet_server_join_reply (struct connection *pconn, const struct packet_server_join_reply *packet) |
| Modify if needed the packet header field lengths. More... | |
| bool | packet_check (struct data_in *din, struct connection *pc) |
| Sanity check packet. More... | |
| void | generic_handle_player_attribute_chunk (struct player *pplayer, const struct packet_player_attribute_chunk *chunk) |
| Updates pplayer->attribute_block according to the given packet. More... | |
| void | send_attribute_block (const struct player *pplayer, struct connection *pconn) |
| Split the attribute block into chunks and send them over pconn. More... | |
| void | pre_send_packet_player_attribute_chunk (struct connection *pc, struct packet_player_attribute_chunk *packet) |
| Test and log for sending player attribute_block. More... | |
| static void | packet_handlers_free () |
| Destroy the packet handler hash table. More... | |
| const struct packet_handlers * | packet_handlers_initial () |
| Returns the packet handlers variant with no special capability. More... | |
| const struct packet_handlers * | packet_handlers_get (const char *capability) |
| Returns the packet handlers variant for 'capability'. More... | |
| void | packets_deinit () |
| Call when there is no longer a requirement for protocol processing. More... | |
| void | packet_strvec_compute (char str[MAX_LEN_PACKET], QVector< QString > *qstrvec) |
| QVector< QString > * | packet_strvec_extract (const char *str) |
| void | qstrvec_from_str (QVector< QString > *psv, char separator, const char *str) |
| Build the string vector from a string until 'str_size' bytes are read. More... | |
Variables | |
| const char *const | packet_functional_capability |
| static int | stat_size_alone = 0 |
| static int | stat_size_uncompressed = 0 |
| static int | stat_size_compressed = 0 |
| static int | stat_size_no_compression = 0 |
| #define COMPRESSION_BORDER (16 * 1024 + 1) |
Definition at line 39 of file packets.cpp.
| #define JUMBO_BORDER (64 * 1024 - COMPRESSION_BORDER - 1) |
Definition at line 44 of file packets.cpp.
| #define JUMBO_SIZE 0xffff |
Definition at line 34 of file packets.cpp.
| #define log_compress log_debug |
Definition at line 46 of file packets.cpp.
| #define log_compress2 log_debug |
Definition at line 47 of file packets.cpp.
| #define MAX_DECOMPRESSION 400 |
Definition at line 49 of file packets.cpp.
| #define MAX_LEN_COMPRESS_QUEUE (MAX_LEN_BUFFER / 2) |
| #define PACKET_SIZE_STATISTICS 0 |
Definition at line 55 of file packets.cpp.
| #define PACKET_STRVEC_SEPARATOR '\3' |
Definition at line 40 of file packets.cpp.
| typedef QHash<QString, struct packet_handlers *> packetsHash |
Definition at line 59 of file packets.cpp.
|
static |
Send all waiting data.
Return TRUE on success.
Definition at line 88 of file packets.cpp.
Referenced by conn_compression_thaw(), and send_packet_data().
| bool conn_compression_thaw | ( | struct connection * | pconn | ) |
Thaw the connection.
Then maybe compress the data waiting to send them to the connection. Returns TRUE on success. See also conn_compression_freeze().
Definition at line 160 of file packets.cpp.
Referenced by conn_list_compression_thaw(), connection_attach_real(), establish_new_connection(), and finish_processing_request().
| void generic_handle_player_attribute_chunk | ( | struct player * | pplayer, |
| const struct packet_player_attribute_chunk * | chunk | ||
| ) |
Updates pplayer->attribute_block according to the given packet.
Definition at line 639 of file packets.cpp.
Referenced by handle_player_attribute_chunk().
|
inlinestatic |
Returns the compression level.
Initilialize it if needed.
Definition at line 70 of file packets.cpp.
Referenced by conn_compression_flush().
| void* get_packet_from_connection_raw | ( | struct connection * | pc, |
| enum packet_type * | ptype | ||
| ) |
Read and return a packet from the connection 'pc'.
The type of the packet is written in 'ptype'. On error, the connection is closed and the function returns nullptr.
Definition at line 329 of file packets.cpp.
| bool packet_check | ( | struct data_in * | din, |
| struct connection * | pc | ||
| ) |
Sanity check packet.
Definition at line 617 of file packets.cpp.
|
static |
Destroy the packet handler hash table.
Definition at line 744 of file packets.cpp.
Referenced by packets_deinit().
| const struct packet_handlers* packet_handlers_get | ( | const char * | capability | ) |
Returns the packet handlers variant for 'capability'.
Definition at line 766 of file packets.cpp.
Referenced by conn_set_capability().
| const struct packet_handlers* packet_handlers_initial | ( | ) |
Returns the packet handlers variant with no special capability.
Definition at line 749 of file packets.cpp.
Referenced by init_packet_hashs(), and packet_handlers_get().
| void packet_header_init | ( | struct packet_header * | packet_header | ) |
Set the packet header field lengths used for the login protocol, before the capability of the connection could be checked.
NB: These values cannot be changed for backward compatibility reasons.
Definition at line 572 of file packets.cpp.
Referenced by connection_common_init().
|
inlinestatic |
Set the packet header field lengths used after the login protocol, after the capability of the connection could be checked.
Definition at line 582 of file packets.cpp.
Referenced by post_receive_packet_server_join_reply(), and post_send_packet_server_join_reply().
| void packet_strvec_compute | ( | char | str[MAX_LEN_PACKET], |
| QVector< QString > * | qstrvec | ||
| ) |
Definition at line 806 of file packets.cpp.
Referenced by send_ruleset_buildings(), send_ruleset_extras(), send_ruleset_goods(), send_ruleset_governments(), send_ruleset_multipliers(), send_ruleset_specialists(), send_ruleset_techs(), send_ruleset_terrain(), send_ruleset_unit_classes(), and send_ruleset_units().
| QVector<QString>* packet_strvec_extract | ( | const char * | str | ) |
Definition at line 819 of file packets.cpp.
Referenced by handle_ruleset_building(), handle_ruleset_extra(), handle_ruleset_goods(), handle_ruleset_government(), handle_ruleset_multiplier(), handle_ruleset_specialist(), handle_ruleset_tech(), handle_ruleset_terrain(), handle_ruleset_unit(), and handle_ruleset_unit_class().
| void packets_deinit | ( | ) |
Call when there is no longer a requirement for protocol processing.
All connections must have been closed.
Definition at line 804 of file packets.cpp.
Referenced by at_exit(), and close_connections_and_socket().
| void post_receive_packet_server_join_reply | ( | struct connection * | pconn, |
| const struct packet_server_join_reply * | packet | ||
| ) |
Modify if needed the packet header field lengths.
Definition at line 606 of file packets.cpp.
| void post_send_packet_server_join_reply | ( | struct connection * | pconn, |
| const struct packet_server_join_reply * | packet | ||
| ) |
Modify if needed the packet header field lengths.
Definition at line 595 of file packets.cpp.
| void pre_send_packet_player_attribute_chunk | ( | struct connection * | pc, |
| struct packet_player_attribute_chunk * | packet | ||
| ) |
Test and log for sending player attribute_block.
Definition at line 725 of file packets.cpp.
| void qstrvec_from_str | ( | QVector< QString > * | psv, |
| char | separator, | ||
| const char * | str | ||
| ) |
Build the string vector from a string until 'str_size' bytes are read.
Passing -1 for 'str_size' will assume 'str' as the expected format. Note it's a bit dangerous.
This string format is a list of strings separated by 'separator'.
See also strvec_to_str().
Definition at line 838 of file packets.cpp.
Referenced by packet_strvec_extract().
| void remove_packet_from_buffer | ( | struct socket_packet_buffer * | buffer | ) |
Remove the packet from the buffer.
Definition at line 553 of file packets.cpp.
| void send_attribute_block | ( | const struct player * | pplayer, |
| struct connection * | pconn | ||
| ) |
Split the attribute block into chunks and send them over pconn.
Definition at line 681 of file packets.cpp.
Referenced by attribute_flush(), handle_player_attribute_block(), and send_all_info().
| int send_packet_data | ( | struct connection * | pc, |
| unsigned char * | data, | ||
| int | len, | ||
| enum packet_type packet_type packet_type | |||
| ) |
It returns the request id of the outgoing packet (or 0 if is_server()).
Definition at line 176 of file packets.cpp.
| const char* const packet_functional_capability |
Definition at line 57 of file packets.cpp.
Referenced by packet_handlers_get().
|
static |
Definition at line 62 of file packets.cpp.
Referenced by send_packet_data().
|
static |
Definition at line 64 of file packets.cpp.
Referenced by conn_compression_flush(), and send_packet_data().
|
static |
Definition at line 65 of file packets.cpp.
Referenced by conn_compression_flush(), and send_packet_data().
|
static |
Definition at line 63 of file packets.cpp.
Referenced by conn_compression_flush(), and send_packet_data().