comparison packets.c @ 3:5a977ccbc7a9 default tip

Empty changelog
author darius
date Sat, 06 Dec 1997 05:41:29 +0000
parents
children
comparison
equal deleted inserted replaced
2:fba0b6e6cdc7 3:5a977ccbc7a9
1 /* $Id: packets.c,v 1.1.1.1 1997/12/06 05:41:29 darius Exp $ */
2
3 #include <stddef.h>
4
5 #include "defs.h"
6 #include "packets.h"
7 #include "gppackets.h"
8 #include "wtext.h"
9
10 size_t client_packet_sizes[] = {
11 0,
12 sizeof(struct mesg_cpacket),
13 sizeof(struct speed_cpacket),
14 sizeof(struct dir_cpacket),
15 sizeof(struct phaser_cpacket),
16 sizeof(struct plasma_cpacket),
17 sizeof(struct torp_cpacket),
18 sizeof(struct quit_cpacket),
19 sizeof(struct login_cpacket),
20 sizeof(struct outfit_cpacket),
21 /* 10 v */
22 sizeof(struct war_cpacket),
23 sizeof(struct practr_cpacket),
24 sizeof(struct shield_cpacket),
25 sizeof(struct repair_cpacket),
26 sizeof(struct orbit_cpacket),
27 sizeof(struct planlock_cpacket),
28 sizeof(struct playlock_cpacket),
29 sizeof(struct bomb_cpacket),
30 sizeof(struct beam_cpacket),
31 sizeof(struct cloak_cpacket),
32 /* 20 v */
33 sizeof(struct det_torps_cpacket),
34 sizeof(struct det_mytorp_cpacket),
35 sizeof(struct copilot_cpacket),
36 sizeof(struct refit_cpacket),
37 sizeof(struct tractor_cpacket),
38 sizeof(struct repress_cpacket),
39 sizeof(struct coup_cpacket),
40 sizeof(struct socket_cpacket),
41 sizeof(struct options_cpacket),
42 sizeof(struct bye_cpacket),
43 /* 30 v */
44 sizeof(struct dockperm_cpacket),
45 sizeof(struct updates_cpacket),
46 sizeof(struct resetstats_cpacket),
47 sizeof(struct reserved_cpacket),
48 sizeof(struct scan_cpacket),
49 sizeof(struct udp_req_cpacket),
50 sizeof(struct sequence_cpacket),
51 sizeof(struct rsa_key_cpacket),
52 sizeof(struct obvious_packet),
53 0,
54 /* 40 v */
55 0,
56 0,
57 sizeof(struct ping_cpacket),/* 42 */
58 #ifdef SHORT_PACKETS
59 sizeof(struct shortreq_cpacket),
60 sizeof(struct threshold_cpacket),
61 0, /* CP_S_MESSAGE */
62 0, /* CP_S_RESERVED */
63 0, /* CP_S_DUMMY */
64 #else
65 0,
66 0,
67 0,
68 0,
69 0, /* 47 */
70 #endif
71 0, /* 48 */
72 0,
73 /* 50 v */
74 0,
75 0,
76 0,
77 0,
78 0,
79 0,
80 0,
81 0,
82 0,
83 0, /* 59 */
84 #ifdef FEATURE
85 sizeof(struct feature_cpacket) /* CP_FEATURE */
86 #else
87 0
88 #endif
89 };
90
91 #define num_cpacket_sizes sizeof(client_packet_sizes)/sizeof(*client_packet_sizes)
92
93 int
94 size_of_cpacket(pkt)
95 void *pkt;
96 {
97 CARD8 type;
98 CARD8 subtype;
99
100 type = ((CARD8 *) pkt)[0];
101 subtype = ((CARD8 *) pkt)[1];
102
103 if (type < num_cpacket_sizes && client_packet_sizes[type] > 0)
104 return client_packet_sizes[type];
105
106 switch (type) {
107 #ifdef CP_FIRE_WEAPON
108 case CP_FIRE_WEAPON:
109 {
110 struct fire_weapon_cpacket *fwp = pkt;
111 return (fwp->mech == TM_POSITION) ? 12 : 4;
112 }
113 #endif
114
115 #ifdef SHORT_PACKETS
116 case CP_S_MESSAGE:
117 return ((unsigned char *) pkt)[3];
118 case CP_S_RESERVED:
119 case CP_S_DUMMY:
120 /* hmm? good question */
121 return 0;
122 #endif /* SHORT_PACKETS */
123
124 default:
125 return 0;
126 }
127 }
128
129
130 int server_packet_sizes[] = {
131 0, /* record 0 */
132 sizeof(struct mesg_spacket),/* SP_MESSAGE */
133 sizeof(struct plyr_info_spacket), /* SP_PLAYER_INFO */
134 sizeof(struct kills_spacket), /* SP_KILLS */
135 sizeof(struct player_spacket), /* SP_PLAYER */
136 sizeof(struct torp_info_spacket), /* SP_TORP_INFO */
137 sizeof(struct torp_spacket),/* SP_TORP */
138 sizeof(struct phaser_spacket), /* SP_PHASER */
139 sizeof(struct plasma_info_spacket), /* SP_PLASMA_INFO */
140 sizeof(struct plasma_spacket), /* SP_PLASMA */
141 /* 10 v */
142 sizeof(struct warning_spacket), /* SP_WARNING */
143 sizeof(struct motd_spacket),/* SP_MOTD */
144 sizeof(struct you_spacket), /* SP_YOU */
145 sizeof(struct queue_spacket), /* SP_QUEUE */
146 sizeof(struct status_spacket), /* SP_STATUS */
147 sizeof(struct planet_spacket), /* SP_PLANET */
148 sizeof(struct pickok_spacket), /* SP_PICKOK */
149 sizeof(struct login_spacket), /* SP_LOGIN */
150 sizeof(struct flags_spacket), /* SP_FLAGS */
151 sizeof(struct mask_spacket),/* SP_MASK */
152 /* 20 v */
153 sizeof(struct pstatus_spacket), /* SP_PSTATUS */
154 sizeof(struct badversion_spacket), /* SP_BADVERSION */
155 sizeof(struct hostile_spacket), /* SP_HOSTILE */
156 sizeof(struct stats_spacket), /* SP_STATS */
157 sizeof(struct plyr_login_spacket), /* SP_PL_LOGIN */
158 sizeof(struct reserved_spacket), /* SP_RESERVED */
159 sizeof(struct planet_loc_spacket), /* SP_PLANET_LOC */
160 sizeof(struct scan_spacket),/* SP_SCAN (ATM) */
161 sizeof(struct udp_reply_spacket), /* SP_UDP_REPLY */
162 sizeof(struct sequence_spacket), /* SP_SEQUENCE */
163 /* 30 v */
164 sizeof(struct sc_sequence_spacket), /* SP_SC_SEQUENCE */
165 sizeof(struct rsa_key_spacket), /* SP_RSA_KEY */
166 sizeof(struct motd_pic_spacket), /* SP_MOTD_PIC */
167 sizeof(struct stats_spacket2), /* SP_STATS2 */
168 sizeof(struct status_spacket2), /* SP_STATUS2 */
169 sizeof(struct planet_spacket2), /* SP_PLANET2 */
170 sizeof(struct obvious_packet), /* SP_NEW_MOTD */
171 sizeof(struct thingy_spacket), /* SP_THINGY */
172 sizeof(struct thingy_info_spacket), /* SP_THINGY_INFO */
173 sizeof(struct ship_cap_spacket), /* SP_SHIP_CAP */
174 /* 40 v */
175 #ifdef SHORT_PACKETS
176 sizeof(struct shortreply_spacket), /* SP_S_REPLY */
177 -1, /* SP_S_MESSAGE */
178 -1, /* SP_S_WARNING */
179 sizeof(struct youshort_spacket), /* SP_S_YOU */
180 sizeof(struct youss_spacket), /* SP_S_YOU_SS */
181 -1, /* SP_S_PLAYER */
182 #else
183 -1,
184 -1,
185 -1,
186 -1,
187 -1,
188 -1,
189 #endif
190 sizeof(struct ping_spacket),/* SP_PING */
191 -1, /* SP_S_TORP */
192 -1, /* SP_S_TORP_INFO */
193 20, /* SP_S_8_TORP */
194 /* 50 v */
195 -1, /* SP_S_PLANET */
196 -1, /* SP_GPARAM */
197 -1, /* SP_PARADISE_EXT1 */
198 sizeof(struct terrain_packet2), /* SP_TERRAIN2 */
199 sizeof(struct terrain_info_packet2), /* SP_TERRAIN_INFO2 */
200 -1,
201 -1,
202 -1,
203 -1,
204 -1,
205 /* 60 v */
206 #ifdef FEATURE
207 sizeof(struct feature_spacket),
208 #else
209 -1,
210 #endif
211 -1
212 };
213
214 #define num_spacket_sizes (sizeof(server_packet_sizes) / sizeof(server_packet_sizes[0]) - 1)
215
216 #ifdef SHORT_PACKETS
217 unsigned char numofbits[256] =
218 {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1,
219 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1,
220 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2,
221 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1,
222 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2,
223 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2,
224 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3,
225 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1,
226 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2,
227 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2,
228 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3,
229 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2,
230 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3,
231 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3,
232 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4,
233 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8};
234
235 static int vtsize[9] =
236 {4, 8, 8, 12, 12, 16, 20, 20, 24}; /* How big is the torppacket */
237 int vtisize[9] =
238 {4, 7, 9, 11, 13, 16, 18, 20, 22}; /* 4 byte Header + torpdata */
239
240
241 static int
242 padto4(sz)
243 int sz;
244 {
245 return (sz % 4) ? (sz / 4 + 1) * 4 : sz;
246
247 }
248 #endif
249
250 int
251 size_of_spacket(pkt)
252 unsigned char *pkt;
253 {
254 switch (pkt[0]) {
255 case SP_GPARAM:
256 switch (pkt[1]) {
257 case 0:
258 return sizeof(struct gp_sizes_spacket);
259 case 1:
260 return sizeof(struct gp_team_spacket);
261 case 2:
262 return sizeof(struct gp_teamlogo_spacket);
263 case 3:
264 return sizeof(struct gp_shipshape_spacket);
265 case 4:
266 return sizeof(struct gp_shipbitmap_spacket);
267 case 5:
268 return sizeof(struct gp_rank_spacket);
269 case 6:
270 return sizeof(struct gp_royal_spacket);
271 case 7:
272 return sizeof(struct gp_teamplanet_spacket);
273 default:
274 return 0;
275 }
276 #ifdef SHORT_PACKETS
277 case SP_S_MESSAGE:
278 return padto4(pkt[4]); /* IMPORTANT Changed */
279 case SP_S_WARNING:
280 if (pkt[1] == STEXTE_STRING ||
281 pkt[1] == SHORT_WARNING) {
282 return padto4(pkt[3]);
283 } else
284 return 4; /* Normal Packet */
285 case SP_S_PLAYER:
286 if (pkt[1] & 128) { /* Small +extended Header */
287 return padto4(((pkt[1] & 0x3f) * 4) + 4);
288 } else if (pkt[1] & 64) { /* Small Header */
289 return padto4(((pkt[1] & 0x3f) * 4) + 4);
290 } else { /* Big Header */
291 return padto4((pkt[1] * 4 + 12));
292 }
293 case SP_S_TORP:
294 return padto4(vtsize[numofbits[pkt[1]]]);
295 case SP_S_TORP_INFO:
296 return padto4((vtisize[numofbits[pkt[1]]] + numofbits[pkt[3]]));
297 case SP_S_PLANET:
298 return padto4((pkt[1] * VPLANET_SIZE) + 2);
299 #endif
300 case SP_PARADISE_EXT1:
301 switch (pkt[1]) {
302 case SP_PE1_MISSING_BITMAP:
303 return sizeof(struct pe1_missing_bitmap_spacket);
304 case SP_PE1_NUM_MISSILES:
305 return sizeof(struct pe1_num_missiles_spacket);
306 default:
307 return 0;
308 }
309 #ifdef RECORDER
310 case REC_UPDATE:
311 {
312 extern int playback;
313 if (playback) /* if not, something's very wrong... */
314 return 4;
315 }
316 #endif
317 default:
318 return (*pkt < num_spacket_sizes && server_packet_sizes[*pkt] >= 0)
319 ? server_packet_sizes[*pkt] : 0;
320 }
321 }