Freeciv21
Develop your civilization from humble roots to a global empire
packets.h File Reference
#include "shared.h"
#include "connection.h"
#include "diptreaty.h"
#include "effects.h"
#include "events.h"
#include "improvement.h"
#include "player.h"
#include "requirements.h"
#include "spaceship.h"
#include "team.h"
#include "tile.h"
#include "traderoutes.h"
#include "unittype.h"
#include "worklist.h"
#include "packets_gen.h"
+ Include dependency graph for packets.h:

Go to the source code of this file.

Classes

struct  packet_handlers
 

Macros

#define MAX_LEN_MSG   1536
 
#define MAX_LEN_ROUTE   2000 /* MAX_LEN_PACKET / 2 - header */
 
#define ATTRIBUTE_CHUNK_SIZE   (1400)
 
#define get_packet_from_connection(pc, ptype)    get_packet_from_connection_raw(pc, ptype)
 
#define SEND_PACKET_START(packet_type)
 
#define SEND_PACKET_END(packet_type)
 
#define RECEIVE_PACKET_START(packet_type, result)
 
#define RECEIVE_PACKET_END(result)
 
#define RECEIVE_PACKET_FIELD_ERROR(field, ...)
 

Enumerations

enum  report_type { REPORT_WONDERS_OF_THE_WORLD , REPORT_TOP_5_CITIES , REPORT_DEMOGRAPHIC , REPORT_ACHIEVEMENTS }
 
enum  unit_info_use { UNIT_INFO_IDENTITY , UNIT_INFO_CITY_SUPPORTED , UNIT_INFO_CITY_PRESENT }
 
enum  authentication_type { AUTH_LOGIN_FIRST , AUTH_NEWUSER_FIRST , AUTH_LOGIN_RETRY , AUTH_NEWUSER_RETRY }
 

Functions

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 send_attribute_block (const struct player *pplayer, struct connection *pconn)
 Split the attribute block into chunks and send them over pconn. 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 packet_handlers_fill_initial (struct packet_handlers *phandlers)
 
void packet_handlers_fill_capability (struct packet_handlers *phandlers, const char *capability)
 
const char * packet_name (enum packet_type type)
 
bool packet_has_game_info_flag (enum packet_type type)
 
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...
 
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...
 
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...
 
const struct packet_handlerspacket_handlers_initial ()
 Returns the packet handlers variant with no special capability. More...
 
const struct packet_handlerspacket_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...
 
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...
 
bool packet_check (struct data_in *din, struct connection *pc)
 Sanity check packet. 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 > *, char separator, const char *str)
 Build the string vector from a string until 'str_size' bytes are read. More...
 

Macro Definition Documentation

◆ ATTRIBUTE_CHUNK_SIZE

#define ATTRIBUTE_CHUNK_SIZE   (1400)

Definition at line 49 of file packets.h.

◆ get_packet_from_connection

#define get_packet_from_connection (   pc,
  ptype 
)     get_packet_from_connection_raw(pc, ptype)

Definition at line 90 of file packets.h.

◆ MAX_LEN_MSG

#define MAX_LEN_MSG   1536

Definition at line 37 of file packets.h.

◆ MAX_LEN_ROUTE

#define MAX_LEN_ROUTE   2000 /* MAX_LEN_PACKET / 2 - header */

Definition at line 38 of file packets.h.

◆ RECEIVE_PACKET_END

#define RECEIVE_PACKET_END (   result)
Value:
if (!packet_check(&din, pc)) { \
return nullptr; \
} \
remove_packet_from_buffer(pc->buffer); \
result = new std::remove_reference<decltype(*result)>::type; \
*result = packet_buf; \
return result;
bool packet_check(struct data_in *din, struct connection *pc)
Sanity check packet.
Definition: packets.cpp:617

Definition at line 158 of file packets.h.

◆ RECEIVE_PACKET_FIELD_ERROR

#define RECEIVE_PACKET_FIELD_ERROR (   field,
  ... 
)
Value:
log_packet("Error on field '" #field "'" __VA_ARGS__); \
return nullptr
#define log_packet
Definition: log.h:72

Definition at line 167 of file packets.h.

◆ RECEIVE_PACKET_START

#define RECEIVE_PACKET_START (   packet_type,
  result 
)
Value:
struct data_in din; \
struct packet_type packet_buf, *result = &packet_buf; \
&din, pc->buffer->data, \
data_type_size((enum data_type) pc->packet_header.length)); \
{ \
int size; \
dio_get_type_raw(&din, (enum data_type) pc->packet_header.length, \
&size); \
dio_input_init(&din, pc->buffer->data, MIN(size, pc->buffer->ndata)); \
} \
dio_input_skip( \
&din, (data_type_size((enum data_type) pc->packet_header.length) \
+ data_type_size((enum data_type) pc->packet_header.type)));
bool dio_get_type_raw(struct data_in *din, enum data_type type, int *dest)
Receive value using 'size' bits to dest.
Definition: dataio_raw.cpp:555
size_t data_type_size(enum data_type type)
Return the size of the data_type in bytes.
Definition: dataio_raw.cpp:193
void dio_input_init(struct data_in *din, const void *src, size_t src_size)
Initializes the input to the given input buffer and the given number of valid input bytes.
Definition: dataio_raw.cpp:169
data_type
Definition: dataio_raw.h:37
#define MIN(x, y)
Definition: shared.h:49
size_t size
Definition: specvec.h:64

Definition at line 140 of file packets.h.

◆ SEND_PACKET_END

#define SEND_PACKET_END (   packet_type)
Value:
{ \
size_t size = dio_output_used(&dout); \
dio_put_type_raw(&dout, (enum data_type) pc->packet_header.length, \
size); \
fc_assert(!dout.too_short); \
return send_packet_data(pc, buffer, size, packet_type); \
}
size_t dio_output_used(struct raw_data_out *dout)
Return the maximum number of bytes used.
Definition: dataio_raw.cpp:157
void dio_output_rewind(struct raw_data_out *dout)
Rewinds the stream so that the put-functions start from the beginning.
Definition: dataio_raw.cpp:163
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()).
Definition: packets.cpp:176

Definition at line 129 of file packets.h.

◆ SEND_PACKET_START

#define SEND_PACKET_START (   packet_type)
Value:
unsigned char buffer[MAX_LEN_PACKET]; \
struct raw_data_out dout; \
dio_output_init(&dout, buffer, sizeof(buffer)); \
dio_put_type_raw(&dout, (enum data_type) pc->packet_header.length, 0); \
dio_put_type_raw(&dout, (enum data_type) pc->packet_header.type, \
packet_type);
#define MAX_LEN_PACKET
Definition: connection.h:41
void dio_output_init(struct raw_data_out *dout, void *destination, size_t dest_size)
Initializes the output to the given output buffer and the given buffer size.
Definition: dataio_raw.cpp:144

Definition at line 120 of file packets.h.

Enumeration Type Documentation

◆ authentication_type

Enumerator
AUTH_LOGIN_FIRST 
AUTH_NEWUSER_FIRST 
AUTH_LOGIN_RETRY 
AUTH_NEWUSER_RETRY 

Definition at line 67 of file packets.h.

◆ report_type

Enumerator
REPORT_WONDERS_OF_THE_WORLD 
REPORT_TOP_5_CITIES 
REPORT_DEMOGRAPHIC 
REPORT_ACHIEVEMENTS 

Definition at line 52 of file packets.h.

◆ unit_info_use

Enumerator
UNIT_INFO_IDENTITY 
UNIT_INFO_CITY_SUPPORTED 
UNIT_INFO_CITY_PRESENT 

Definition at line 60 of file packets.h.

Function Documentation

◆ generic_handle_player_attribute_chunk()

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

◆ get_packet_from_connection_raw()

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.

◆ packet_check()

bool packet_check ( struct data_in din,
struct connection pc 
)

Sanity check packet.

Definition at line 617 of file packets.cpp.

◆ packet_handlers_fill_capability()

void packet_handlers_fill_capability ( struct packet_handlers phandlers,
const char *  capability 
)

Referenced by packet_handlers_get().

◆ packet_handlers_fill_initial()

void packet_handlers_fill_initial ( struct packet_handlers phandlers)

Referenced by packet_handlers_initial().

◆ packet_handlers_get()

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

◆ packet_handlers_initial()

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

◆ packet_has_game_info_flag()

bool packet_has_game_info_flag ( enum packet_type  type)

Referenced by conn_reset_delta_state().

◆ packet_header_init()

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

◆ packet_name()

const char* packet_name ( enum packet_type  type)

◆ packet_strvec_compute()

◆ packet_strvec_extract()

◆ packets_deinit()

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

◆ post_receive_packet_server_join_reply()

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.

◆ post_send_packet_server_join_reply()

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.

◆ pre_send_packet_player_attribute_chunk()

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.

◆ qstrvec_from_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.

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

◆ remove_packet_from_buffer()

void remove_packet_from_buffer ( struct socket_packet_buffer buffer)

Remove the packet from the buffer.

Definition at line 553 of file packets.cpp.

◆ send_attribute_block()

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

◆ send_packet_data()

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

Definition at line 176 of file packets.cpp.