]> icculus.org git repositories - taylor/freespace2.git/blob - include/ptrack.h
re-add PXO sources to project files
[taylor/freespace2.git] / include / ptrack.h
1 /*
2  * Copyright (C) Volition, Inc. 2005.  All rights reserved.
3  * 
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 
6  * source.
7  *
8 */
9
10 #ifndef _pilot_track_header
11 #define _pilot_track_header
12
13 #include "scoring.h"                                    // for medals count
14
15 //Pilot tracker client header
16 #ifdef FS2_DEMO
17         #define REGPORT                                         7802
18 #else
19         #define REGPORT                                         8811
20 #endif
21
22 #define MAX_NET_RETRIES                         30
23 #define NET_ACK_TIMEOUT                         2500
24
25 #define MAX_PXO_FILENAME_LEN            32
26
27 //This is for type 
28 #define UNT_CONTROL                                     0
29 #define UNT_NEW_ID_REQUEST                      1
30 #define UNT_VALIDAT_ID_REQUEST  2
31 #define UNT_LOOKUP_ID_REQUEST           3
32 #define UNT_UPDATE_ID_REQUEST           4
33 #define UNT_MOTD_REQUEST                        5
34 #define UNT_MOTD_RESPONSE                       6
35 #define UNT_PILOT_DATA_READ             7               // Request from the game for pilot info
36 #define UNT_PILOT_DATA_RESPONSE 8               // Mastertracker's response to a read request (has pilot data in this packet)
37 #define UNT_PILOT_DATA_WRITE            9               // Request from the server to write a user record
38 #define UNT_PILOT_WRITE_FAILED  10              // Server didn't update the pilots record for some reason
39 #define UNT_PILOT_WRITE_SUCCESS 11              // Server updated the pilots record
40 #define UNT_PILOT_READ_FAILED           12              // Couldn't find the record
41 #define UNT_LOGIN_AUTH_REQUEST  13              // Request login authentication by login/password only (returns tracker id)
42 #define UNT_LOGIN_NO_AUTH                       14              // Couldn't login this user (code has reason)
43 #define UNT_LOGIN_AUTHENTICATED 15              // User was authenticated (data has sz string with tracker id)
44 #define UNT_VALID_FS_MSN_REQ            18              // Client asking if this is a valid mission
45 #define UNT_VALID_FS_MSN_RSP            19              // Server Response (code has the answer)
46
47 #define UNT_PILOT_DATA_READ_NEW 20              // New packet for requesting reads (tracker will get new security field when receiving this)
48 #define UNT_PILOT_DATA_WRITE_NEW        21              // New packet for requesting writes (tracker will compare security fields if this packet is used)
49
50 // 22 through 45 are D3 specific codes
51 #define UNT_VALID_FS2_MSN_REQ           46              // validated mission request to PXO for FS2
52 #define UNT_VALID_FS2_MSN_RSP           47              // validated mission response from PXO for FS2
53
54 // validate a squad war mission
55 #define UNT_VALID_SW_MSN_REQ            48              // send info about a squad war mission, wait for tracker response
56 #define UNT_VALID_SW_MSN_RSP            49              // response from the tracker
57 #define UNT_SW_RESULT_WRITE             50              // report on a finished squad war mission to the tracker
58 #define UNT_SW_RESULT_RESPONSE  51              // response on a squad war mission write request
59
60 #define UNT_CONTROL_VALIDATION  70              // UNT_CONTROL for validation packets
61
62 //This is for code
63 #define CMD_NEW_USER_ACK                        1
64 #define CMD_NEW_USER_NAK                        2
65 #define CMD_VALIDATED_USER_ACK  3
66 #define CMD_UPDATED_USER_ACK            4
67 #define CMD_CLIENT_RECEIVED             5
68 #define CMD_FIND_USER_NAK                       6
69 #define CMD_FIND_USER_ACK                       7
70 #define CMD_UPDATED_USER_NAK            8
71 #define CMD_VALIDATED_USER_NAK  9
72         //Game designators for UNT_PILOT_DATA_REQUEST and UNT_PILOT_DATA_RESPONSE
73 #define CMD_GAME_FREESPACE                      10                                              
74 #define CMD_GAME_DESCENT3                       11
75 #define CMD_GAME_FREESPACE2             12
76
77 //This is for xcode
78 #define REG_NAK_EMAIL                           0                                                               // failed to register the guy because of an invalid email address
79 #define REG_NAK_LOGIN                           1                                                               // failed to register the guy because an existing login exists
80 #define REG_NAK_ERROR                           2                                                               // failed to register because of an error on the tracker
81 #define REG_NAK_STRINGS                         3                                                               // failed to validate because of invalid password/login match
82 #define REG_NAK_UNKNOWN                         4                                                               // failed to validate because the player is unknown
83 #define REG_NAK_UPDATE_PL                       5                                                               // update info failed because login/passwd were not correct
84 #define REG_NAK_UPDATE_GEN                      6                                                               // update info failed in general (tracker problem)
85 #define REG_NAK_UPDATE_LOG                      7                                                               // update failed because login not found
86 #define REG_ACK_NEW_ID                          8                                                               // New id created, just used for return code, not net packets.
87
88 #define MAX_UDP_DATA_LENGH                      480
89 #define PACKED_HEADER_ONLY_SIZE (sizeof(udp_packet_header)-MAX_UDP_DATA_LENGH)
90 //sizeof(update_id_request)     //The largest packet
91
92 #define LOGIN_LEN                                               33
93 #define REAL_NAME_LEN                           66
94 #define PASSWORD_LEN                                    17
95 #define EMAIL_LEN                                               100
96 #define TRACKER_ID_LEN                          10
97 #define PILOT_NAME_LEN                          20
98 #define MATCH_CODE_LEN                          34
99
100 #define MAX_SQUAD_PLAYERS                       4
101 #define MAX_SQUAD_RESPONSE_LEN  255
102
103 // data could be one of the following:
104
105 // type == UNT_NEW_ID_REQUEST
106 // Respond with ACK
107 typedef struct {
108         char first_name[REAL_NAME_LEN];         // Real Name
109         char last_name[REAL_NAME_LEN];          // Real Name
110         char login[LOGIN_LEN];                                  // Login id
111         char password[PASSWORD_LEN];                    // password
112         char email[EMAIL_LEN];                                  // Email Address
113         unsigned char showemail;                                // 0==don't show 1 == show
114         unsigned char showname;                                 // 0==don't show 1 == show
115 } new_id_request;
116
117
118 // type == UNT_VALIDAT_ID_REQUEST or UNT_LOOKUP_ID_REQUEST
119 typedef struct {
120         char login[LOGIN_LEN];                                  // Login id
121         char password[PASSWORD_LEN];                    // password
122         char tracker_id[TRACKER_ID_LEN];                // Tracker ID
123 } validate_id_request;
124
125 // type == UNT_UPDATE_ID_REQUEST
126 typedef struct {
127         char old_login[LOGIN_LEN];                              // Login before it's changed.
128         char old_password[PASSWORD_LEN];                // Password before it's changed
129         char tracker_id[TRACKER_ID_LEN];                // Tracker ID (not sure if we need it for updating, but maybe)
130         char first_name[REAL_NAME_LEN];         // Real Name
131         char last_name[REAL_NAME_LEN];          // Real Name
132         char login[LOGIN_LEN];                                  // Login id (new)
133         char password[PASSWORD_LEN];                    // password (new)
134         char email[EMAIL_LEN];                                  // Email Address (new)
135         unsigned char showemail;                                // 0==don't show 1 == show
136         unsigned char showname;                                 // 0==don't show 1 == show
137 } update_id_request;
138
139 typedef struct {
140         char pilot_name[PILOT_NAME_LEN];                // Login id
141         char tracker_id[TRACKER_ID_LEN];                // Tracker ID
142         char pad[2];                                                    // 2-bytes padding
143 } pilot_request;
144
145 // type == UNT_VALID_SW_MSN_REQ
146 typedef struct squad_war_request {              
147         int squad_plr1[MAX_SQUAD_PLAYERS];      // id #'s for all squad members in the match
148         int squad_plr2[MAX_SQUAD_PLAYERS];      // id #'s for all squad memebrs in the match
149
150         ubyte squad_count1;                                             // # of players present in squad 1
151         ubyte squad_count2;                                             // # of players present in squad 2      
152
153         char match_code[MATCH_CODE_LEN];                // code for the match   
154
155         char mission_filename[MAX_PXO_FILENAME_LEN];            // filename of mission
156         int mission_checksum;                                                                   // mission checksum
157 } squad_war_request;
158
159 // type == UNT_SW_RESULT_WRITE
160 typedef struct squad_war_result {
161         char match_code[MATCH_CODE_LEN];                        // code for the match
162         ubyte result;                                                                   // result of the match, 0 == tie, 1 == one team won
163         ubyte squad_count1;                                                     // # of players in winning squad
164         ubyte squad_count2;                                                     // # of players in the losing squad
165         char pad[3];                                                    // 3-bytes padding
166         int squad_winners[MAX_SQUAD_PLAYERS];   // list of players on the winning team
167         int squad_losers[MAX_SQUAD_PLAYERS];    // list of players on the losing team
168 } squad_war_result;
169
170 // type == UNT_VALID_SW_MSN_RSP and UNT_SW_RESULT_RESPONSE
171 typedef struct squad_war_response {
172         char reason[MAX_SQUAD_RESPONSE_LEN];
173         unsigned char accepted;
174 } squad_war_response;
175
176 #pragma pack(push, 1)
177         typedef struct {        
178                 unsigned char type;                                             // type
179                 unsigned short len;                                             //      Length of total packet, including this header
180                 unsigned int code;                                              // For control messages
181                 unsigned short xcode;                                   // For control/NAK messages and for sigs.
182                 unsigned int sig;                                               // To identify unique return ACKs
183                 unsigned int security;                                  // Just a random value, we store the last value used in the user record
184                                                                                                                 // So we don't process the same request twice.          
185                 unsigned char data[MAX_UDP_DATA_LENGH];
186         } udp_packet_header;
187 #pragma pack(pop)
188
189
190 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
191 // GAME SPECIFIC structures
192
193
194 #ifdef MAKE_FS1
195 // ------------------------------------------------------------------------------------------------------------
196 // FREESPACE
197 // NOTE : this is obsolete for FS2  -  we use our own FS2 struct
198 #define MAX_FS_MEDALS           16                      // these should correspond directly to those defined inside of freespace.
199 #define MAX_FS_SHIP_TYPES       75                      // this one will be scaled down to be the correct # eventually
200 typedef struct vmt_freespace_struct {
201         char tracker_id[TRACKER_ID_LEN];
202         char pilot_name[PILOT_NAME_LEN];
203
204         int score;
205         int rank;
206         int medals[MAX_FS_MEDALS];
207    
208         int kills[MAX_FS_SHIP_TYPES];            // only valid kills (i.e. not on friendlies).
209         int assists;
210         int kill_count;                // total alltime kills
211         int kill_count_ok;                          // total valid alltime kills (no friendlies)
212         unsigned int p_shots_fired;      // primary weapon
213         unsigned int s_shots_fired;    // secondary weapon
214
215         unsigned int p_shots_hit;      // primary
216         unsigned int s_shots_hit;      // secondary
217
218         unsigned int p_bonehead_hits;  // hits/kills on the players own team
219         unsigned int s_bonehead_hits;
220    int          bonehead_kills;
221
222         int                      security;                              
223         unsigned char virgin_pilot;     //This pilot was just created if TRUE
224         unsigned int checksum;                  //This value needs to be equal to whatever the checksum is once the packet is decoded
225                 
226         unsigned int missions_flown;                    // # of missions flown to completion
227         unsigned int flight_time;                               // total hours of flight time
228         unsigned int last_flown;                                // data/time of last mission flown
229 } vmt_freespace_struct;
230 #define FREESPACE_BLOCK_SIZE (sizeof(vmt_freespace_struct))
231
232 #else
233
234 // ------------------------------------------------------------------------------------------------------------
235 // FREESPACE2
236 #ifdef FS2_DEMO
237         #define MAX_FS2_MEDALS                                  16                                              // these should correspond directly to those defined inside of freespace.
238         #define MAX_FS2_SHIP_TYPES                              120                                     // this one will be scaled down to be the correct # eventually
239         typedef struct vmt_freespace2_struct {
240                 char                            tracker_id[TRACKER_ID_LEN];
241                 char                            pilot_name[PILOT_NAME_LEN];
242
243                 int                             score;
244                 int                             rank;
245                 int                             medals[MAX_FS2_MEDALS];
246    
247                 ushort                  kills[MAX_FS2_SHIP_TYPES];               // only valid kills (i.e. not on friendlies).
248                 int                             assists;
249                 int                             kill_count;                // total alltime kills
250                 int                             kill_count_ok;                      // total valid alltime kills (no friendlies)
251                 unsigned int    p_shots_fired;   // primary weapon
252                 unsigned int    s_shots_fired;    // secondary weapon
253
254                 unsigned int    p_shots_hit;      // primary
255                 unsigned int    s_shots_hit;      // secondary
256
257                 unsigned int    p_bonehead_hits;  // hits/kills on the players own team
258                 unsigned int    s_bonehead_hits;
259                 int                             bonehead_kills;
260
261                 int                             security;                               
262                 unsigned char   virgin_pilot;   //This pilot was just created if TRUE
263                 unsigned int    checksum;                       //This value needs to be equal to whatever the checksum is once the packet is decoded
264                         
265                 unsigned int    missions_flown;                 // # of missions flown to completion
266                 unsigned int    flight_time;                            // total hours of flight time
267                 unsigned int    last_flown;                             // data/time of last mission flown
268         } vmt_freespace2_struct;
269 #else 
270         #define MAX_FS2_MEDALS                  NUM_MEDALS                      // these should correspond directly to those defined inside of freespace.
271         #define MAX_FS2_SHIP_TYPES              MAX_SHIP_TYPES          // this one will be scaled down to be the correct # eventually  
272         typedef struct vmt_freespace2_struct {
273                 char                            tracker_id[TRACKER_ID_LEN];
274                 char                            pilot_name[PILOT_NAME_LEN];
275
276                 char                    pad_a[2];                       // 2-bytes padding
277
278                 int                             score;
279                 int                             rank;           
280                 int                             assists;
281                 int                             kill_count;                // total alltime kills
282                 int                             kill_count_ok;                      // total valid alltime kills (no friendlies)
283                 unsigned int    p_shots_fired;   // primary weapon
284                 unsigned int    s_shots_fired;    // secondary weapon
285
286                 unsigned int    p_shots_hit;      // primary
287                 unsigned int    s_shots_hit;      // secondary
288
289                 unsigned int    p_bonehead_hits;  // hits/kills on the players own team
290                 unsigned int    s_bonehead_hits;
291                 int                             bonehead_kills;
292
293                 int                             security;                               
294                 unsigned char   virgin_pilot;   //This pilot was just created if TRUE
295
296                 char                    pad_b[3];                       // 3-bytes padding
297
298                 unsigned int    checksum;                       //This value needs to be equal to whatever the checksum is once the packet is decoded
299                         
300                 unsigned int    missions_flown;                 // # of missions flown to completion
301                 unsigned int    flight_time;                            // total hours of flight time
302                 unsigned int    last_flown;                             // data/time of last mission flown
303                 
304                 unsigned short num_medals;
305                 unsigned short num_ship_types;
306
307                 int                             medals[MAX_FS2_MEDALS];   
308                 unsigned short kills[MAX_FS2_SHIP_TYPES];                // only valid kills (i.e. not on friendlies).
309         } vmt_freespace2_struct;
310 #endif
311 #define FREESPACE2_BLOCK_SIZE (sizeof(vmt_freespace2_struct))
312
313 #endif // MAKE_FS1
314
315 //Function prototypes
316 int InitPilotTrackerClient();
317 void AckServer(unsigned int sig);
318
319 #ifdef MAKE_FS1
320 int SendFSPilotData(vmt_freespace2_struct *fs_pilot);
321 int GetFSPilotData(vmt_freespace2_struct *fs_pilot, const char *pilot_name, const char *tracker_id, int update_security);
322 #else
323 int SendFSPilotData(vmt_freespace2_struct *fs_pilot);
324 int GetFSPilotData(vmt_freespace2_struct *fs_pilot, const char *pilot_name, const char *tracker_id, int update_security);
325 #endif
326 int SendSWData(squad_war_result *sw_res, squad_war_response *sw_resp);
327 void PollPTrackNet();
328
329 //Definitions
330 #define STATE_IDLE                                              0
331 #define STATE_SENDING_PILOT                     1
332 #define STATE_READING_PILOT                     2
333 #define STATE_RECEIVED_PILOT                    3
334 #define STATE_WROTE_PILOT                               4
335 #define STATE_TIMED_OUT                                 5
336 #define STATE_PILOT_NOT_FOUND                   6
337 #define STATE_WRITE_PILOT_FAILED                7
338
339 #define PILOT_REQ_TIMEOUT                       30000
340 #define PILOT_REQ_RESEND_TIME           3500
341
342
343 #define PXO_ADD_DATA(d) do { memcpy(data+packet_size, &d, sizeof(d) ); packet_size += sizeof(d); } while (0)
344 #define PXO_ADD_SHORT(d) do { short swap = INTEL_SHORT(d); memcpy(data+packet_size, &swap, sizeof(d) ); packet_size += sizeof(d); } while (0)
345 #define PXO_ADD_USHORT(d) do { ushort swap = INTEL_SHORT(d); memcpy(data+packet_size, &swap, sizeof(d) ); packet_size += sizeof(d); } while (0)
346 #define PXO_ADD_INT(d) do { int swap = INTEL_INT(d); memcpy(data+packet_size, &swap, sizeof(d) ); packet_size += sizeof(d); } while (0)
347 #define PXO_ADD_UINT(d) do { uint swap = INTEL_INT(d); memcpy(data+packet_size, &swap, sizeof(d) ); packet_size += sizeof(d); } while (0)
348
349 #define PXO_GET_DATA(d) do { memcpy(&d, data+offset, sizeof(d) ); offset += sizeof(d); } while(0)
350 #define PXO_GET_SHORT(d) do { short swap; memcpy(&swap, data+offset, sizeof(d) ); d = INTEL_SHORT(swap); offset += sizeof(d); } while(0)
351 #define PXO_GET_USHORT(d) do { ushort swap; memcpy(&swap, data+offset, sizeof(d) ); d = INTEL_SHORT(swap); offset += sizeof(d); } while(0)
352 #define PXO_GET_INT(d) do { int swap; memcpy(&swap, data+offset, sizeof(d) ); d = INTEL_INT(swap); offset += sizeof(d); } while(0)
353 #define PXO_GET_UINT(d) do { uint swap; memcpy(&swap, data+offset, sizeof(d) ); d = INTEL_INT(swap); offset += sizeof(d); } while(0)
354
355 #endif
356
357