2 * Copyright (C) Volition, Inc. 2005. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on the
10 #ifndef _pilot_track_header
11 #define _pilot_track_header
13 #include "scoring.h" // for medals count
15 //Pilot tracker client header
18 #elif defined(FS2_DEMO)
24 #define MAX_NET_RETRIES 30
25 #define NET_ACK_TIMEOUT 2500
27 #define MAX_PXO_FILENAME_LEN 32
31 #define UNT_NEW_ID_REQUEST 1
32 #define UNT_VALIDAT_ID_REQUEST 2
33 #define UNT_LOOKUP_ID_REQUEST 3
34 #define UNT_UPDATE_ID_REQUEST 4
35 #define UNT_MOTD_REQUEST 5
36 #define UNT_MOTD_RESPONSE 6
37 #define UNT_PILOT_DATA_READ 7 // Request from the game for pilot info
38 #define UNT_PILOT_DATA_RESPONSE 8 // Mastertracker's response to a read request (has pilot data in this packet)
39 #define UNT_PILOT_DATA_WRITE 9 // Request from the server to write a user record
40 #define UNT_PILOT_WRITE_FAILED 10 // Server didn't update the pilots record for some reason
41 #define UNT_PILOT_WRITE_SUCCESS 11 // Server updated the pilots record
42 #define UNT_PILOT_READ_FAILED 12 // Couldn't find the record
43 #define UNT_LOGIN_AUTH_REQUEST 13 // Request login authentication by login/password only (returns tracker id)
44 #define UNT_LOGIN_NO_AUTH 14 // Couldn't login this user (code has reason)
45 #define UNT_LOGIN_AUTHENTICATED 15 // User was authenticated (data has sz string with tracker id)
46 #define UNT_VALID_FS_MSN_REQ 18 // Client asking if this is a valid mission
47 #define UNT_VALID_FS_MSN_RSP 19 // Server Response (code has the answer)
49 #define UNT_PILOT_DATA_READ_NEW 20 // New packet for requesting reads (tracker will get new security field when receiving this)
50 #define UNT_PILOT_DATA_WRITE_NEW 21 // New packet for requesting writes (tracker will compare security fields if this packet is used)
52 // 22 through 45 are D3 specific codes
53 #define UNT_VALID_FS2_MSN_REQ 46 // validated mission request to PXO for FS2
54 #define UNT_VALID_FS2_MSN_RSP 47 // validated mission response from PXO for FS2
56 // validate a squad war mission
57 #define UNT_VALID_SW_MSN_REQ 48 // send info about a squad war mission, wait for tracker response
58 #define UNT_VALID_SW_MSN_RSP 49 // response from the tracker
59 #define UNT_SW_RESULT_WRITE 50 // report on a finished squad war mission to the tracker
60 #define UNT_SW_RESULT_RESPONSE 51 // response on a squad war mission write request
62 #define UNT_CONTROL_VALIDATION 70 // UNT_CONTROL for validation packets
65 #define CMD_NEW_USER_ACK 1
66 #define CMD_NEW_USER_NAK 2
67 #define CMD_VALIDATED_USER_ACK 3
68 #define CMD_UPDATED_USER_ACK 4
69 #define CMD_CLIENT_RECEIVED 5
70 #define CMD_FIND_USER_NAK 6
71 #define CMD_FIND_USER_ACK 7
72 #define CMD_UPDATED_USER_NAK 8
73 #define CMD_VALIDATED_USER_NAK 9
74 //Game designators for UNT_PILOT_DATA_REQUEST and UNT_PILOT_DATA_RESPONSE
75 #define CMD_GAME_FREESPACE 10
76 #define CMD_GAME_DESCENT3 11
77 #define CMD_GAME_FREESPACE2 12
80 #define REG_NAK_EMAIL 0 // failed to register the guy because of an invalid email address
81 #define REG_NAK_LOGIN 1 // failed to register the guy because an existing login exists
82 #define REG_NAK_ERROR 2 // failed to register because of an error on the tracker
83 #define REG_NAK_STRINGS 3 // failed to validate because of invalid password/login match
84 #define REG_NAK_UNKNOWN 4 // failed to validate because the player is unknown
85 #define REG_NAK_UPDATE_PL 5 // update info failed because login/passwd were not correct
86 #define REG_NAK_UPDATE_GEN 6 // update info failed in general (tracker problem)
87 #define REG_NAK_UPDATE_LOG 7 // update failed because login not found
88 #define REG_ACK_NEW_ID 8 // New id created, just used for return code, not net packets.
90 #define MAX_UDP_DATA_LENGH 480
92 #define PACKED_HEADER_ONLY_SIZE (sizeof(udp_packet_header)-MAX_UDP_DATA_LENGH)
94 // FS1 doesn't pack header so add 3 bytes to size for padding
95 #define PACKED_HEADER_ONLY_SIZE (sizeof(udp_packet_header)-MAX_UDP_DATA_LENGH+3)
97 //sizeof(update_id_request) //The largest packet
100 #define REAL_NAME_LEN 66
101 #define PASSWORD_LEN 17
102 #define EMAIL_LEN 100
103 #define TRACKER_ID_LEN 10
104 #define PILOT_NAME_LEN 20
105 #define MATCH_CODE_LEN 34
107 #define MAX_SQUAD_PLAYERS 4
108 #define MAX_SQUAD_RESPONSE_LEN 255
110 // data could be one of the following:
112 // type == UNT_NEW_ID_REQUEST
115 char first_name[REAL_NAME_LEN]; // Real Name
116 char last_name[REAL_NAME_LEN]; // Real Name
117 char login[LOGIN_LEN]; // Login id
118 char password[PASSWORD_LEN]; // password
119 char email[EMAIL_LEN]; // Email Address
120 unsigned char showemail; // 0==don't show 1 == show
121 unsigned char showname; // 0==don't show 1 == show
125 // type == UNT_VALIDAT_ID_REQUEST or UNT_LOOKUP_ID_REQUEST
127 char login[LOGIN_LEN]; // Login id
128 char password[PASSWORD_LEN]; // password
129 char tracker_id[TRACKER_ID_LEN]; // Tracker ID
130 } validate_id_request;
132 // type == UNT_UPDATE_ID_REQUEST
134 char old_login[LOGIN_LEN]; // Login before it's changed.
135 char old_password[PASSWORD_LEN]; // Password before it's changed
136 char tracker_id[TRACKER_ID_LEN]; // Tracker ID (not sure if we need it for updating, but maybe)
137 char first_name[REAL_NAME_LEN]; // Real Name
138 char last_name[REAL_NAME_LEN]; // Real Name
139 char login[LOGIN_LEN]; // Login id (new)
140 char password[PASSWORD_LEN]; // password (new)
141 char email[EMAIL_LEN]; // Email Address (new)
142 unsigned char showemail; // 0==don't show 1 == show
143 unsigned char showname; // 0==don't show 1 == show
147 char pilot_name[PILOT_NAME_LEN]; // Login id
148 char tracker_id[TRACKER_ID_LEN]; // Tracker ID
149 char pad[2]; // 2-bytes padding
152 // type == UNT_VALID_SW_MSN_REQ
153 typedef struct squad_war_request {
154 int squad_plr1[MAX_SQUAD_PLAYERS]; // id #'s for all squad members in the match
155 int squad_plr2[MAX_SQUAD_PLAYERS]; // id #'s for all squad memebrs in the match
157 ubyte squad_count1; // # of players present in squad 1
158 ubyte squad_count2; // # of players present in squad 2
160 char match_code[MATCH_CODE_LEN]; // code for the match
162 char mission_filename[MAX_PXO_FILENAME_LEN]; // filename of mission
163 int mission_checksum; // mission checksum
166 // type == UNT_SW_RESULT_WRITE
167 typedef struct squad_war_result {
168 char match_code[MATCH_CODE_LEN]; // code for the match
169 ubyte result; // result of the match, 0 == tie, 1 == one team won
170 ubyte squad_count1; // # of players in winning squad
171 ubyte squad_count2; // # of players in the losing squad
172 char pad[3]; // 3-bytes padding
173 int squad_winners[MAX_SQUAD_PLAYERS]; // list of players on the winning team
174 int squad_losers[MAX_SQUAD_PLAYERS]; // list of players on the losing team
177 // type == UNT_VALID_SW_MSN_RSP and UNT_SW_RESULT_RESPONSE
178 typedef struct squad_war_response {
179 char reason[MAX_SQUAD_RESPONSE_LEN];
180 unsigned char accepted;
181 } squad_war_response;
183 #pragma pack(push, 1)
185 unsigned char type; // type
186 unsigned short len; // Length of total packet, including this header
187 unsigned int code; // For control messages
188 unsigned short xcode; // For control/NAK messages and for sigs.
189 unsigned int sig; // To identify unique return ACKs
190 unsigned int security; // Just a random value, we store the last value used in the user record
191 // So we don't process the same request twice.
192 unsigned char data[MAX_UDP_DATA_LENGH];
197 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
198 // GAME SPECIFIC structures
202 // ------------------------------------------------------------------------------------------------------------
204 // NOTE : this is obsolete for FS2 - we use our own FS2 struct
205 #define MAX_FS_MEDALS 16 // these should correspond directly to those defined inside of freespace.
206 #define MAX_FS_SHIP_TYPES 75 // this one will be scaled down to be the correct # eventually
207 typedef struct vmt_freespace_struct {
208 char tracker_id[TRACKER_ID_LEN];
209 char pilot_name[PILOT_NAME_LEN];
211 char pad_a[2]; // 2-bytes padding
215 int medals[MAX_FS_MEDALS];
217 int kills[MAX_FS_SHIP_TYPES]; // only valid kills (i.e. not on friendlies).
219 int kill_count; // total alltime kills
220 int kill_count_ok; // total valid alltime kills (no friendlies)
221 unsigned int p_shots_fired; // primary weapon
222 unsigned int s_shots_fired; // secondary weapon
224 unsigned int p_shots_hit; // primary
225 unsigned int s_shots_hit; // secondary
227 unsigned int p_bonehead_hits; // hits/kills on the players own team
228 unsigned int s_bonehead_hits;
232 unsigned char virgin_pilot; //This pilot was just created if TRUE
234 char pad_b[3]; // 3-bytes padding
236 unsigned int checksum; //This value needs to be equal to whatever the checksum is once the packet is decoded
238 unsigned int missions_flown; // # of missions flown to completion
239 unsigned int flight_time; // total hours of flight time
240 unsigned int last_flown; // data/time of last mission flown
241 } vmt_freespace_struct;
242 #define FREESPACE_BLOCK_SIZE (sizeof(vmt_freespace_struct))
244 #define vmt_stats_struct vmt_freespace_struct
248 // ------------------------------------------------------------------------------------------------------------
251 #define MAX_FS2_MEDALS 16 // these should correspond directly to those defined inside of freespace.
252 #define MAX_FS2_SHIP_TYPES 120 // this one will be scaled down to be the correct # eventually
253 typedef struct vmt_freespace2_struct {
254 char tracker_id[TRACKER_ID_LEN];
255 char pilot_name[PILOT_NAME_LEN];
257 char pad_a[2]; // 2-bytes padding (size/alignment)
261 int medals[MAX_FS2_MEDALS];
263 ushort kills[MAX_FS2_SHIP_TYPES]; // only valid kills (i.e. not on friendlies).
265 int kill_count; // total alltime kills
266 int kill_count_ok; // total valid alltime kills (no friendlies)
267 unsigned int p_shots_fired; // primary weapon
268 unsigned int s_shots_fired; // secondary weapon
270 unsigned int p_shots_hit; // primary
271 unsigned int s_shots_hit; // secondary
273 unsigned int p_bonehead_hits; // hits/kills on the players own team
274 unsigned int s_bonehead_hits;
278 unsigned char virgin_pilot; //This pilot was just created if TRUE
280 char pad_b[3]; // 3-bytes padding (size/alignment)
282 unsigned int checksum; //This value needs to be equal to whatever the checksum is once the packet is decoded
284 unsigned int missions_flown; // # of missions flown to completion
285 unsigned int flight_time; // total hours of flight time
286 unsigned int last_flown; // data/time of last mission flown
287 } vmt_freespace2_struct;
289 #define MAX_FS2_MEDALS NUM_MEDALS // these should correspond directly to those defined inside of freespace.
290 #define MAX_FS2_SHIP_TYPES MAX_SHIP_TYPES // this one will be scaled down to be the correct # eventually
291 typedef struct vmt_freespace2_struct {
292 char tracker_id[TRACKER_ID_LEN];
293 char pilot_name[PILOT_NAME_LEN];
295 char pad_a[2]; // 2-bytes padding
300 int kill_count; // total alltime kills
301 int kill_count_ok; // total valid alltime kills (no friendlies)
302 unsigned int p_shots_fired; // primary weapon
303 unsigned int s_shots_fired; // secondary weapon
305 unsigned int p_shots_hit; // primary
306 unsigned int s_shots_hit; // secondary
308 unsigned int p_bonehead_hits; // hits/kills on the players own team
309 unsigned int s_bonehead_hits;
313 unsigned char virgin_pilot; //This pilot was just created if TRUE
315 char pad_b[3]; // 3-bytes padding
317 unsigned int checksum; //This value needs to be equal to whatever the checksum is once the packet is decoded
319 unsigned int missions_flown; // # of missions flown to completion
320 unsigned int flight_time; // total hours of flight time
321 unsigned int last_flown; // data/time of last mission flown
323 unsigned short num_medals;
324 unsigned short num_ship_types;
326 int medals[MAX_FS2_MEDALS];
327 unsigned short kills[MAX_FS2_SHIP_TYPES]; // only valid kills (i.e. not on friendlies).
328 } vmt_freespace2_struct;
330 #define FREESPACE2_BLOCK_SIZE (sizeof(vmt_freespace2_struct))
332 #define vmt_stats_struct vmt_freespace2_struct
336 //Function prototypes
337 int InitPilotTrackerClient();
338 void AckServer(unsigned int sig);
340 int SendFSPilotData(vmt_stats_struct *fs_pilot);
341 int GetFSPilotData(vmt_stats_struct *fs_pilot, const char *pilot_name, const char *tracker_id, int update_security);
342 int SendSWData(squad_war_result *sw_res, squad_war_response *sw_resp);
343 void PollPTrackNet();
347 #define STATE_SENDING_PILOT 1
348 #define STATE_READING_PILOT 2
349 #define STATE_RECEIVED_PILOT 3
350 #define STATE_WROTE_PILOT 4
351 #define STATE_TIMED_OUT 5
352 #define STATE_PILOT_NOT_FOUND 6
353 #define STATE_WRITE_PILOT_FAILED 7
355 #define PILOT_REQ_TIMEOUT 30000
356 #define PILOT_REQ_RESEND_TIME 3500
359 #define PXO_ADD_DATA(d) do { memcpy(data+packet_size, &d, sizeof(d) ); packet_size += sizeof(d); } while (0)
360 #define PXO_ADD_SHORT(d) do { short swap = INTEL_SHORT(d); memcpy(data+packet_size, &swap, sizeof(d) ); packet_size += sizeof(d); } while (0)
361 #define PXO_ADD_USHORT(d) do { ushort swap = INTEL_SHORT(d); memcpy(data+packet_size, &swap, sizeof(d) ); packet_size += sizeof(d); } while (0)
362 #define PXO_ADD_INT(d) do { int swap = INTEL_INT(d); memcpy(data+packet_size, &swap, sizeof(d) ); packet_size += sizeof(d); } while (0)
363 #define PXO_ADD_UINT(d) do { uint swap = INTEL_INT(d); memcpy(data+packet_size, &swap, sizeof(d) ); packet_size += sizeof(d); } while (0)
365 #define PXO_GET_DATA(d) do { memcpy(&d, data+offset, sizeof(d) ); offset += sizeof(d); } while(0)
366 #define PXO_GET_SHORT(d) do { short swap; memcpy(&swap, data+offset, sizeof(d) ); d = INTEL_SHORT(swap); offset += sizeof(d); } while(0)
367 #define PXO_GET_USHORT(d) do { ushort swap; memcpy(&swap, data+offset, sizeof(d) ); d = INTEL_SHORT(swap); offset += sizeof(d); } while(0)
368 #define PXO_GET_INT(d) do { int swap; memcpy(&swap, data+offset, sizeof(d) ); d = INTEL_INT(swap); offset += sizeof(d); } while(0)
369 #define PXO_GET_UINT(d) do { uint swap; memcpy(&swap, data+offset, sizeof(d) ); d = INTEL_INT(swap); offset += sizeof(d); } while(0)
373 #define PXO_SELECT(a, b, c, d, e, f) SELECT(a, b, c, d, e, f)
374 #define PXO_RECVFROM(a, b, c, d, e, f, g) RECVFROM(a, b, c, d, e, f, g)
375 #define PXO_SENDTO(a, b, c, d, e, f, g) SENDTO(a, b, c, d, e, f, g)
377 #define PXO_SELECT(a, b, c, d, e, f) select(a, b, c, d, e)
379 #define PXO_RECVFROM(a, b, c, d, e, f, g) recvfrom(a, b, c, d, e, (socklen_t*)f)
381 #define PXO_RECVFROM(a, b, c, d, e, f, g) recvfrom(a, b, c, d, e, f)
383 #define PXO_SENDTO(a, b, c, d, e, f, g) sendto(a , b, c, d, e, f)