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)
124#ifdef FREECIV_JSON_CONNECTION
128#define SEND_PACKET_START(packet_type) \
129 unsigned char buffer[MAX_LEN_PACKET]; \
130 struct raw_data_out dout; \
132 dio_output_init(&dout, buffer, sizeof(buffer)); \
133 dio_put_type_raw(&dout, pc->packet_header.length, 0); \
134 dio_put_type_raw(&dout, pc->packet_header.type, packet_type);
136#define SEND_PACKET_END(packet_type) \
138 size_t size = dio_output_used(&dout); \
140 dio_output_rewind(&dout); \
141 dio_put_type_raw(&dout, pc->packet_header.length, size); \
142 fc_assert(!dout.too_short); \
143 return send_packet_data(pc, buffer, size, packet_type); \
146#define SEND_PACKET_DISCARD() \
149#define RECEIVE_PACKET_START(packet_type, result) \
150 struct data_in din; \
151 struct packet_type packet_buf, *result = &packet_buf; \
153 dio_input_init(&din, pc->buffer->data, \
154 data_type_size(pc->packet_header.length)); \
158 dio_get_type_raw(&din, pc->packet_header.length, &size); \
159 dio_input_init(&din, pc->buffer->data, MIN(size, pc->buffer->ndata)); \
161 dio_input_skip(&din, (data_type_size(pc->packet_header.length) \
162 + data_type_size(pc->packet_header.type)));
164#define RECEIVE_PACKET_END(result) \
165 if (!packet_check(&din, pc)) { \
168 remove_packet_from_buffer(pc->buffer); \
169 result = fc_malloc(sizeof(*result)); \
170 *result = packet_buf; \
173#define RECEIVE_PACKET_FIELD_ERROR(field, ...) \
174 log_packet("Error on field '" #field "'" __VA_ARGS__); \
184#define PACKET_STRVEC_SEPARATOR '\3'
185#define PACKET_STRVEC_COMPUTE(str, strvec) \
186 if (NULL != strvec) { \
187 strvec_to_str(strvec, PACKET_STRVEC_SEPARATOR, str, sizeof(str)); \
191#define PACKET_STRVEC_EXTRACT(strvec, str) \
192 if ('\0' != str[0]) { \
193 strvec = strvec_new(); \
194 strvec_from_str(strvec, PACKET_STRVEC_SEPARATOR, str); \
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 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::@68 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)