1 /**********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 ***********************************************************************/
18 #endif /* __cplusplus */
23 #include "connection.h" /* struct connection, MAX_LEN_* */
24 #include "diptreaty.h"
27 #include "improvement.h" /* bv_imprs */
30 #include "requirements.h"
31 #include "shared.h" /* MAX_LEN_ADDR */
32 #include "spaceship.h"
34 #include "traderoutes.h"
39 /* Used in network protocol. */
40 #define MAX_LEN_MSG 1536
41 #define MAX_LEN_ROUTE 2000 /* MAX_LEN_PACKET/2 - header */
43 /* The size of opaque (void *) data sent in the network packet. To avoid
44 * fragmentation issues, this SHOULD NOT be larger than the standard
45 * ethernet or PPP 1500 byte frame size (with room for headers).
47 * Do not spend much time optimizing, you have no idea of the actual dynamic
48 * path characteristics between systems, such as VPNs and tunnels.
50 * Used in network protocol.
52 #define ATTRIBUTE_CHUNK_SIZE (1400)
54 /* Used in network protocol. */
56 REPORT_WONDERS_OF_THE_WORLD
,
61 /* Used in network protocol. */
62 enum spaceship_place_type
{
63 SSHIP_PLACE_STRUCTURAL
,
65 SSHIP_PLACE_PROPULSION
,
66 SSHIP_PLACE_HABITATION
,
67 SSHIP_PLACE_LIFE_SUPPORT
,
68 SSHIP_PLACE_SOLAR_PANELS
71 /* Used in network protocol. */
74 UNIT_INFO_CITY_SUPPORTED
,
75 UNIT_INFO_CITY_PRESENT
78 /* Used in network protocol. */
79 enum authentication_type
{
80 AUTH_LOGIN_FIRST
, /* request a password for a returning user */
81 AUTH_NEWUSER_FIRST
, /* request a password for a new user */
82 AUTH_LOGIN_RETRY
, /* inform the client to try a different password */
83 AUTH_NEWUSER_RETRY
/* inform the client to try a different [new] password */
86 #include "packets_gen.h"
88 void *get_packet_from_connection(struct connection
*pc
,
89 enum packet_type
*ptype
);
90 void remove_packet_from_buffer(struct socket_packet_buffer
*buffer
);
92 void send_attribute_block(const struct player
*pplayer
,
93 struct connection
*pconn
);
94 void generic_handle_player_attribute_chunk(struct player
*pplayer
,
96 packet_player_attribute_chunk
98 const char *packet_name(enum packet_type type
);
99 bool packet_has_game_info_flag(enum packet_type type
);
101 void packet_header_init(struct packet_header
*packet_header
);
102 void post_send_packet_server_join_reply(struct connection
*pconn
,
103 const struct packet_server_join_reply
105 void post_receive_packet_server_join_reply(struct connection
*pconn
,
107 packet_server_join_reply
*packet
);
109 void pre_send_packet_player_attribute_chunk(struct connection
*pc
,
110 struct packet_player_attribute_chunk
113 #define SEND_PACKET_START(packet_type) \
114 unsigned char buffer[MAX_LEN_PACKET]; \
115 struct data_out dout; \
117 dio_output_init(&dout, buffer, sizeof(buffer)); \
118 dio_put_type(&dout, pc->packet_header.length, 0); \
119 dio_put_type(&dout, pc->packet_header.type, packet_type);
121 #define SEND_PACKET_END(packet_type) \
123 size_t size = dio_output_used(&dout); \
125 dio_output_rewind(&dout); \
126 dio_put_type(&dout, pc->packet_header.length, size); \
127 fc_assert(!dout.too_short); \
128 return send_packet_data(pc, buffer, size, packet_type); \
131 #define RECEIVE_PACKET_START(packet_type, result) \
132 struct data_in din; \
133 struct packet_type packet_buf, *result = &packet_buf; \
135 dio_input_init(&din, pc->buffer->data, \
136 data_type_size(pc->packet_header.length)); \
140 dio_get_type(&din, pc->packet_header.length, &size); \
141 dio_input_init(&din, pc->buffer->data, MIN(size, pc->buffer->ndata)); \
143 dio_input_skip(&din, (data_type_size(pc->packet_header.length) \
144 + data_type_size(pc->packet_header.type)));
146 #define RECEIVE_PACKET_END(result) \
147 if (!packet_check(&din, pc)) { \
150 remove_packet_from_buffer(pc->buffer); \
151 result = fc_malloc(sizeof(*result)); \
152 *result = packet_buf; \
155 #define RECEIVE_PACKET_FIELD_ERROR(field, ...) \
156 log_packet("Error on field '" #field "'" __VA_ARGS__); \
159 int send_packet_data(struct connection
*pc
, unsigned char *data
, int len
,
160 enum packet_type packet_type
);
161 bool packet_check(struct data_in
*din
, struct connection
*pc
);
163 /* Utilities to exchange strings and string vectors. */
164 #define PACKET_STRVEC_SEPARATOR '\3'
165 #define PACKET_STRVEC_COMPUTE(str, strvec) \
166 if (NULL != strvec) { \
167 strvec_to_str(strvec, PACKET_STRVEC_SEPARATOR, str, sizeof(str)); \
171 #define PACKET_STRVEC_EXTRACT(strvec, str) \
172 if ('\0' != str[0]) { \
173 strvec = strvec_new(); \
174 strvec_from_str(strvec, PACKET_STRVEC_SEPARATOR, str); \
181 #endif /* __cplusplus */
183 #endif /* FC__PACKETS_H */