annotate packets.c @ 3:5a977ccbc7a9 default tip

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