42#define web_send_packet(packetname, pconn, ...) \
44 if (conn_is_webclient(pconn)) { \
45 send_packet_web_ ##packetname(pconn, __VA_ARGS__ ); \
48#define web_lsend_packet(packetname, pconn, pack, ...) \
50 const struct packet_web_ ##packetname *_pptr_ = pack; \
51 if (_pptr_ != NULL) { \
52 lsend_packet_web_ ##packetname(pconn, _pptr_, ##__VA_ARGS__ ); \
56#define web_send_packet(packetname, pconn, ...)
57#define web_lsend_packet(packetname, ...)
63#define REQEST_PLAYER_INITIATED (0)
87#ifdef FREECIV_JSON_CONNECTION
88#define get_packet_from_connection(pc, ptype) get_packet_from_connection_json(pc, ptype)
90#define get_packet_from_connection(pc, ptype) get_packet_from_connection_raw(pc, ptype)
125#ifdef FREECIV_JSON_CONNECTION
129#define SEND_PACKET_START(packet_type) \
130 unsigned char buffer[MAX_LEN_PACKET]; \
131 struct raw_data_out dout; \
133 dio_output_init(&dout, buffer, sizeof(buffer)); \
134 dio_put_type_raw(&dout, pc->packet_header.length, 0); \
135 dio_put_type_raw(&dout, pc->packet_header.type, packet_type);
137#define SEND_PACKET_END(packet_type) \
139 size_t size = dio_output_used(&dout); \
141 dio_output_rewind(&dout); \
142 dio_put_type_raw(&dout, pc->packet_header.length, size); \
143 fc_assert(!dout.too_short); \
144 return send_packet_data(pc, buffer, size, packet_type); \
147#define SEND_PACKET_DISCARD() \
150#define RECEIVE_PACKET_START(packet_type, result) \
151 struct data_in din; \
152 struct packet_type packet_buf, *result = &packet_buf; \
154 init_ ##packet_type (&packet_buf); \
155 dio_input_init(&din, pc->buffer->data, \
156 data_type_size(pc->packet_header.length)); \
160 dio_get_type_raw(&din, pc->packet_header.length, &size); \
161 dio_input_init(&din, pc->buffer->data, MIN(size, pc->buffer->ndata)); \
163 dio_input_skip(&din, (data_type_size(pc->packet_header.length) \
164 + data_type_size(pc->packet_header.type)));
166#define RECEIVE_PACKET_END(result) \
167 if (!packet_check(&din, pc)) { \
168 FREE_PACKET_STRUCT(&packet_buf); \
171 remove_packet_from_buffer(pc->buffer); \
172 result = fc_malloc(sizeof(*result)); \
173 *result = packet_buf; \
176#define RECEIVE_PACKET_FIELD_ERROR(field, ...) \
177 log_packet("Error on field '" #field "'" __VA_ARGS__); \
178 FREE_PACKET_STRUCT(&packet_buf); \
188#define PACKET_STRVEC_INSERT(dest, src) \
190#define PACKET_STRVEC_EXTRACT(dest, src) \
191 if (src != nullptr && strvec_size(src) > 0) { \
192 dest = strvec_new(); \
193 strvec_copy(dest, src); \
void post_receive_packet_server_join_reply(struct connection *pconn, const struct packet_server_join_reply *packet)
void * get_packet_from_connection_raw(struct connection *pc, enum packet_type *ptype)
bool packet_has_game_info_flag(enum packet_type type)
bool packet_check(struct data_in *din, struct connection *pc)
void packet_header_init(struct packet_header *packet_header)
void packet_handlers_fill_capability(struct packet_handlers *phandlers, const char *capability)
const struct packet_handlers * packet_handlers_initial(void)
void packets_deinit(void)
void pre_send_packet_player_attribute_chunk(struct connection *pc, struct packet_player_attribute_chunk *packet)
void remove_packet_from_buffer(struct socket_packet_buffer *buffer)
const char * packet_name(enum packet_type type)
void post_send_packet_server_join_reply(struct connection *pconn, const struct packet_server_join_reply *packet)
int send_packet_data(struct connection *pc, unsigned char *data, int len, enum packet_type packet_type)
void packet_destroy(void *packet, enum packet_type type)
void generic_handle_player_attribute_chunk(struct player *pplayer, const struct packet_player_attribute_chunk *chunk)
void send_attribute_block(const struct player *pplayer, struct connection *pconn)
@ UNIT_INFO_CITY_SUPPORTED
const struct packet_handlers * packet_handlers_get(const char *capability)
void packet_handlers_fill_initial(struct packet_handlers *phandlers)
char capability[MAX_LEN_CAPSTR]
struct socket_packet_buffer * buffer
union packet_handlers::@71 send[PACKET_LAST]
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)
void *(* receive[PACKET_LAST])(struct connection *pconn)