37 #define MAX_LEN_MSG 1536
38 #define MAX_LEN_ROUTE 2000
49 #define ATTRIBUTE_CHUNK_SIZE (1400)
75 #include "packets_gen.h"
88 enum packet_type *ptype);
90 #define get_packet_from_connection(pc, ptype) \
91 get_packet_from_connection_raw(pc, ptype)
99 const struct packet_player_attribute_chunk *chunk);
108 struct connection *pconn,
const struct packet_server_join_reply *packet);
110 struct connection *pconn,
const struct packet_server_join_reply *packet);
113 struct connection *pc,
struct packet_player_attribute_chunk *packet);
120 #define SEND_PACKET_START(packet_type) \
121 unsigned char buffer[MAX_LEN_PACKET]; \
122 struct raw_data_out dout; \
124 dio_output_init(&dout, buffer, sizeof(buffer)); \
125 dio_put_type_raw(&dout, (enum data_type) pc->packet_header.length, 0); \
126 dio_put_type_raw(&dout, (enum data_type) pc->packet_header.type, \
129 #define SEND_PACKET_END(packet_type) \
131 size_t size = dio_output_used(&dout); \
133 dio_output_rewind(&dout); \
134 dio_put_type_raw(&dout, (enum data_type) pc->packet_header.length, \
136 fc_assert(!dout.too_short); \
137 return send_packet_data(pc, buffer, size, packet_type); \
140 #define RECEIVE_PACKET_START(packet_type, result) \
141 struct data_in din; \
142 struct packet_type packet_buf, *result = &packet_buf; \
145 &din, pc->buffer->data, \
146 data_type_size((enum data_type) pc->packet_header.length)); \
150 dio_get_type_raw(&din, (enum data_type) pc->packet_header.length, \
152 dio_input_init(&din, pc->buffer->data, MIN(size, pc->buffer->ndata)); \
155 &din, (data_type_size((enum data_type) pc->packet_header.length) \
156 + data_type_size((enum data_type) pc->packet_header.type)));
158 #define RECEIVE_PACKET_END(result) \
159 if (!packet_check(&din, pc)) { \
162 remove_packet_from_buffer(pc->buffer); \
163 result = new std::remove_reference<decltype(*result)>::type; \
164 *result = packet_buf; \
167 #define RECEIVE_PACKET_FIELD_ERROR(field, ...) \
168 log_packet("Error on field '" #field "'" __VA_ARGS__); \
172 enum packet_type packet_type);
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.
bool packet_has_game_info_flag(enum packet_type type)
void packets_deinit()
Call when there is no longer a requirement for protocol processing.
void packet_strvec_compute(char str[MAX_LEN_PACKET], QVector< QString > *qstrvec)
const struct packet_handlers * packet_handlers_get(const char *capability)
Returns the packet handlers variant for 'capability'.
bool packet_check(struct data_in *din, struct connection *pc)
Sanity check packet.
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 connect...
void * get_packet_from_connection_raw(struct connection *pc, enum packet_type *ptype)
Read and return a packet from the connection 'pc'.
const struct packet_handlers * packet_handlers_initial()
Returns the packet handlers variant with no special capability.
void packet_handlers_fill_capability(struct packet_handlers *phandlers, const char *capability)
const char * packet_name(enum packet_type type)
@ REPORT_WONDERS_OF_THE_WORLD
void pre_send_packet_player_attribute_chunk(struct connection *pc, struct packet_player_attribute_chunk *packet)
Test and log for sending player attribute_block.
void remove_packet_from_buffer(struct socket_packet_buffer *buffer)
Remove the packet from the buffer.
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.
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()).
void qstrvec_from_str(QVector< QString > *, char separator, const char *str)
Build the string vector from a string until 'str_size' bytes are read.
QVector< QString > * packet_strvec_extract(const char *str)
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.
void send_attribute_block(const struct player *pplayer, struct connection *pconn)
Split the attribute block into chunks and send them over pconn.
@ UNIT_INFO_CITY_SUPPORTED
void packet_handlers_fill_initial(struct packet_handlers *phandlers)
char capability[MAX_LEN_CAPSTR]
struct socket_packet_buffer * buffer
void *(* receive[PACKET_LAST])(struct connection *pconn)
int(* force_to_send)(struct connection *pconn, const void *packet, bool force_to_send)
int(* no_packet)(struct connection *pconn)
int(* packet)(struct connection *pconn, const void *packet)
union packet_handlers::@63 send[PACKET_LAST]