Freeciv-3.3
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions
packets.h File Reference
#include "shared.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"

Go to the source code of this file.

Data Structures

struct  packet_handlers
 

Macros

#define web_send_packet(packetname, pconn, ...)
 
#define web_lsend_packet(packetname, ...)
 
#define REQEST_PLAYER_INITIATED   (0)
 
#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 SEND_PACKET_DISCARD()    return 0
 
#define RECEIVE_PACKET_START(packet_type, result)
 
#define RECEIVE_PACKET_END(result)
 
#define RECEIVE_PACKET_FIELD_ERROR(field, ...)
 
#define PACKET_STRVEC_INSERT(dest, src)    dest = src
 
#define PACKET_STRVEC_EXTRACT(dest, src)
 

Enumerations

enum  unit_info_use { UNIT_INFO_IDENTITY , UNIT_INFO_CITY_SUPPORTED , UNIT_INFO_CITY_PRESENT }
 

Functions

voidget_packet_from_connection_raw (struct connection *pc, enum packet_type *ptype)
 
void remove_packet_from_buffer (struct socket_packet_buffer *buffer)
 
void send_attribute_block (const struct player *pplayer, struct connection *pconn)
 
void generic_handle_player_attribute_chunk (struct player *pplayer, const struct packet_player_attribute_chunk *chunk)
 
void packet_handlers_fill_initial (struct packet_handlers *phandlers)
 
void packet_handlers_fill_capability (struct packet_handlers *phandlers, const char *capability)
 
const charpacket_name (enum packet_type type)
 
bool packet_has_game_info_flag (enum packet_type type)
 
void packet_destroy (void *packet, enum packet_type type)
 
void packet_header_init (struct packet_header *packet_header)
 
void post_send_packet_server_join_reply (struct connection *pconn, const struct packet_server_join_reply *packet)
 
void post_receive_packet_server_join_reply (struct connection *pconn, const struct packet_server_join_reply *packet)
 
void pre_send_packet_player_attribute_chunk (struct connection *pc, struct packet_player_attribute_chunk *packet)
 
const struct packet_handlerspacket_handlers_initial (void)
 
const struct packet_handlerspacket_handlers_get (const char *capability)
 
void packets_deinit (void)
 
int send_packet_data (struct connection *pc, unsigned char *data, int len, enum packet_type packet_type)
 
bool packet_check (struct data_in *din, struct connection *pc)
 

Macro Definition Documentation

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

◆ PACKET_STRVEC_EXTRACT

#define PACKET_STRVEC_EXTRACT (   dest,
  src 
)
Value:
if (src != nullptr && strvec_size(src) > 0) { \
dest = strvec_new(); \
strvec_copy(dest, src); \
} else { \
dest = nullptr; \
}
char * incite_cost
Definition comments.c:76
struct strvec * strvec_new(void)
size_t strvec_size(const struct strvec *psv)

Definition at line 190 of file packets.h.

◆ PACKET_STRVEC_INSERT

#define PACKET_STRVEC_INSERT (   dest,
  src 
)     dest = src

Definition at line 188 of file packets.h.

◆ RECEIVE_PACKET_END

#define RECEIVE_PACKET_END (   result)
Value:
if (!packet_check(&din, pc)) { \
return NULL; \
} \
result = fc_malloc(sizeof(*result)); \
*result = packet_buf; \
return result;
#define fc_malloc(sz)
Definition mem.h:34
bool packet_check(struct data_in *din, struct connection *pc)
Definition packets.c:665

Definition at line 166 of file packets.h.

◆ RECEIVE_PACKET_FIELD_ERROR

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

Definition at line 176 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; \
\
dio_input_init(&din, pc->buffer->data, \
data_type_size(pc->packet_header.length)); \
{ \
int size; \
dio_get_type_raw(&din, pc->packet_header.length, &size); \
dio_input_init(&din, pc->buffer->data, MIN(size, pc->buffer->ndata)); \
} \
dio_input_skip(&din, (data_type_size(pc->packet_header.length) \
+ data_type_size(pc->packet_header.type)));
size_t data_type_size(enum data_type type)
Definition dataio_raw.c:229
packet_type
#define MIN(x, y)
Definition shared.h:55
size_t size
Definition specvec.h:72

Definition at line 150 of file packets.h.

◆ REQEST_PLAYER_INITIATED

#define REQEST_PLAYER_INITIATED   (0)

Definition at line 63 of file packets.h.

◆ SEND_PACKET_DISCARD

#define SEND_PACKET_DISCARD ( )     return 0

Definition at line 147 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, 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)
Definition dataio_raw.c:184
int send_packet_data(struct connection *pc, unsigned char *data, int len, enum packet_type packet_type)
Definition packets.c:213

Definition at line 137 of file packets.h.

◆ SEND_PACKET_START

#define SEND_PACKET_START (   packet_type)
Value:
unsigned char buffer[MAX_LEN_PACKET]; \
dio_output_init(&dout, buffer, sizeof(buffer)); \
dio_put_type_raw(&dout, pc->packet_header.length, 0); \
dio_put_type_raw(&dout, pc->packet_header.type, packet_type);
#define MAX_LEN_PACKET
Definition conn_types.h:29

Definition at line 129 of file packets.h.

◆ web_lsend_packet

#define web_lsend_packet (   packetname,
  ... 
)

Definition at line 57 of file packets.h.

◆ web_send_packet

#define web_send_packet (   packetname,
  pconn,
  ... 
)

Definition at line 56 of file packets.h.

Enumeration Type Documentation

◆ unit_info_use

Enumerator
UNIT_INFO_IDENTITY 
UNIT_INFO_CITY_SUPPORTED 
UNIT_INFO_CITY_PRESENT 

Definition at line 66 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 690 of file packets.c.

Referenced by handle_player_attribute_chunk(), and 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 NULL.

Definition at line 373 of file packets.c.

◆ packet_check()

bool packet_check ( struct data_in din,
struct connection pc 
)

Sanity check packet

Definition at line 665 of file packets.c.

◆ packet_destroy()

void packet_destroy ( void packet,
enum packet_type  type 
)

◆ packet_handlers_fill_capability()

void packet_handlers_fill_capability ( struct packet_handlers phandlers,
const char capability 
)

Definition at line 103989 of file packets_gen.c.

Referenced by packet_handlers_get().

◆ packet_handlers_fill_initial()

void packet_handlers_fill_initial ( struct packet_handlers phandlers)

Definition at line 103576 of file packets_gen.c.

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 840 of file packets.c.

Referenced by conn_set_capability().

◆ packet_handlers_initial()

const struct packet_handlers * packet_handlers_initial ( void  )

Returns the packet handlers variant with no special capability.

Definition at line 823 of file packets.c.

Referenced by init_packet_hashes(), and packet_handlers_get().

◆ packet_has_game_info_flag()

bool packet_has_game_info_flag ( enum packet_type  type)

Definition at line 574 of file packets_gen.c.

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 617 of file packets.c.

Referenced by connection_common_init().

◆ packet_name()

const char * packet_name ( enum packet_type  type)

◆ packets_deinit()

void packets_deinit ( void  )

Call when there is no longer a requirement for protocol processing. All connections must have been closed.

Definition at line 900 of file packets.c.

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 652 of file packets.c.

Referenced by receive_packet_server_join_reply_100().

◆ 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 640 of file packets.c.

Referenced by send_packet_server_join_reply_100().

◆ 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 793 of file packets.c.

Referenced by send_packet_player_attribute_chunk_100().

◆ remove_packet_from_buffer()

void remove_packet_from_buffer ( struct socket_packet_buffer buffer)

Remove the packet from the buffer

Definition at line 598 of file packets.c.

◆ 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 746 of file packets.c.

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 213 of file packets.c.