]> icculus.org git repositories - taylor/freespace2.git/blob - include/ptrack.h
embed standalone web in executable
[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 #if defined(MAKE_FS1)
17         #define REGPORT                                         3493
18 #elif defined(FS2_DEMO)
19         #define REGPORT                                         7802
20 #else
21         #define REGPORT                                         8811
22 #endif
23
24 #define MAX_NET_RETRIES                         30
25 #define NET_ACK_TIMEOUT                         2500
26
27 #define MAX_PXO_FILENAME_LEN            32
28
29 //This is for type 
30 #define UNT_CONTROL                                     0
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)
48
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)
51
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
55
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
61
62 #define UNT_CONTROL_VALIDATION  70              // UNT_CONTROL for validation packets
63
64 //This is for code
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
78
79 //This is for xcode
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.
89
90 #define MAX_UDP_DATA_LENGH                      480
91 #ifndef MAKE_FS1
92 #define PACKED_HEADER_ONLY_SIZE (sizeof(udp_packet_header)-MAX_UDP_DATA_LENGH)
93 #else
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)
96 #endif
97 //sizeof(update_id_request)     //The largest packet
98
99 #define LOGIN_LEN                                               33
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
106
107 #define MAX_SQUAD_PLAYERS                       4
108 #define MAX_SQUAD_RESPONSE_LEN  255
109
110 // data could be one of the following:
111
112 // type == UNT_NEW_ID_REQUEST
113 // Respond with ACK
114 typedef struct {
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
122 } new_id_request;
123
124
125 // type == UNT_VALIDAT_ID_REQUEST or UNT_LOOKUP_ID_REQUEST
126 typedef struct {
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;
131
132 // type == UNT_UPDATE_ID_REQUEST
133 typedef struct {
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
144 } update_id_request;
145
146 typedef struct {
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
150 } pilot_request;
151
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
156
157         ubyte squad_count1;                                             // # of players present in squad 1
158         ubyte squad_count2;                                             // # of players present in squad 2      
159
160         char match_code[MATCH_CODE_LEN];                // code for the match   
161
162         char mission_filename[MAX_PXO_FILENAME_LEN];            // filename of mission
163         int mission_checksum;                                                                   // mission checksum
164 } squad_war_request;
165
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
175 } squad_war_result;
176
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;
182
183 #pragma pack(push, 1)
184         typedef struct {        
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];
193         } udp_packet_header;
194 #pragma pack(pop)
195
196
197 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
198 // GAME SPECIFIC structures
199
200
201 #ifdef MAKE_FS1
202 // ------------------------------------------------------------------------------------------------------------
203 // FREESPACE
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];
210
211         char pad_a[2];                  // 2-bytes padding
212
213         int score;
214         int rank;
215         int medals[MAX_FS_MEDALS];
216    
217         int kills[MAX_FS_SHIP_TYPES];            // only valid kills (i.e. not on friendlies).
218         int assists;
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
223
224         unsigned int p_shots_hit;      // primary
225         unsigned int s_shots_hit;      // secondary
226
227         unsigned int p_bonehead_hits;  // hits/kills on the players own team
228         unsigned int s_bonehead_hits;
229    int          bonehead_kills;
230
231         int                      security;                              
232         unsigned char virgin_pilot;     //This pilot was just created if TRUE
233
234         char             pad_b[3];                      // 3-bytes padding
235
236         unsigned int checksum;                  //This value needs to be equal to whatever the checksum is once the packet is decoded
237                 
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))
243
244 #define vmt_stats_struct vmt_freespace_struct
245
246 #else
247
248 // ------------------------------------------------------------------------------------------------------------
249 // FREESPACE2
250 #ifdef FS2_DEMO
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];
256
257                 int                             score;
258                 int                             rank;
259                 int                             medals[MAX_FS2_MEDALS];
260    
261                 ushort                  kills[MAX_FS2_SHIP_TYPES];               // only valid kills (i.e. not on friendlies).
262                 int                             assists;
263                 int                             kill_count;                // total alltime kills
264                 int                             kill_count_ok;                      // total valid alltime kills (no friendlies)
265                 unsigned int    p_shots_fired;   // primary weapon
266                 unsigned int    s_shots_fired;    // secondary weapon
267
268                 unsigned int    p_shots_hit;      // primary
269                 unsigned int    s_shots_hit;      // secondary
270
271                 unsigned int    p_bonehead_hits;  // hits/kills on the players own team
272                 unsigned int    s_bonehead_hits;
273                 int                             bonehead_kills;
274
275                 int                             security;                               
276                 unsigned char   virgin_pilot;   //This pilot was just created if TRUE
277                 unsigned int    checksum;                       //This value needs to be equal to whatever the checksum is once the packet is decoded
278                         
279                 unsigned int    missions_flown;                 // # of missions flown to completion
280                 unsigned int    flight_time;                            // total hours of flight time
281                 unsigned int    last_flown;                             // data/time of last mission flown
282         } vmt_freespace2_struct;
283 #else 
284         #define MAX_FS2_MEDALS                  NUM_MEDALS                      // these should correspond directly to those defined inside of freespace.
285         #define MAX_FS2_SHIP_TYPES              MAX_SHIP_TYPES          // this one will be scaled down to be the correct # eventually  
286         typedef struct vmt_freespace2_struct {
287                 char                            tracker_id[TRACKER_ID_LEN];
288                 char                            pilot_name[PILOT_NAME_LEN];
289
290                 char                    pad_a[2];                       // 2-bytes padding
291
292                 int                             score;
293                 int                             rank;           
294                 int                             assists;
295                 int                             kill_count;                // total alltime kills
296                 int                             kill_count_ok;                      // total valid alltime kills (no friendlies)
297                 unsigned int    p_shots_fired;   // primary weapon
298                 unsigned int    s_shots_fired;    // secondary weapon
299
300                 unsigned int    p_shots_hit;      // primary
301                 unsigned int    s_shots_hit;      // secondary
302
303                 unsigned int    p_bonehead_hits;  // hits/kills on the players own team
304                 unsigned int    s_bonehead_hits;
305                 int                             bonehead_kills;
306
307                 int                             security;                               
308                 unsigned char   virgin_pilot;   //This pilot was just created if TRUE
309
310                 char                    pad_b[3];                       // 3-bytes padding
311
312                 unsigned int    checksum;                       //This value needs to be equal to whatever the checksum is once the packet is decoded
313                         
314                 unsigned int    missions_flown;                 // # of missions flown to completion
315                 unsigned int    flight_time;                            // total hours of flight time
316                 unsigned int    last_flown;                             // data/time of last mission flown
317                 
318                 unsigned short num_medals;
319                 unsigned short num_ship_types;
320
321                 int                             medals[MAX_FS2_MEDALS];   
322                 unsigned short kills[MAX_FS2_SHIP_TYPES];                // only valid kills (i.e. not on friendlies).
323         } vmt_freespace2_struct;
324 #endif
325 #define FREESPACE2_BLOCK_SIZE (sizeof(vmt_freespace2_struct))
326
327 #define vmt_stats_struct vmt_freespace2_struct
328
329 #endif // MAKE_FS1
330
331 //Function prototypes
332 int InitPilotTrackerClient();
333 void AckServer(unsigned int sig);
334
335 int SendFSPilotData(vmt_stats_struct *fs_pilot);
336 int GetFSPilotData(vmt_stats_struct *fs_pilot, const char *pilot_name, const char *tracker_id, int update_security);
337 int SendSWData(squad_war_result *sw_res, squad_war_response *sw_resp);
338 void PollPTrackNet();
339
340 //Definitions
341 #define STATE_IDLE                                              0
342 #define STATE_SENDING_PILOT                     1
343 #define STATE_READING_PILOT                     2
344 #define STATE_RECEIVED_PILOT                    3
345 #define STATE_WROTE_PILOT                               4
346 #define STATE_TIMED_OUT                                 5
347 #define STATE_PILOT_NOT_FOUND                   6
348 #define STATE_WRITE_PILOT_FAILED                7
349
350 #define PILOT_REQ_TIMEOUT                       30000
351 #define PILOT_REQ_RESEND_TIME           3500
352
353
354 #define PXO_ADD_DATA(d) do { memcpy(data+packet_size, &d, sizeof(d) ); packet_size += sizeof(d); } while (0)
355 #define PXO_ADD_SHORT(d) do { short swap = INTEL_SHORT(d); memcpy(data+packet_size, &swap, sizeof(d) ); packet_size += sizeof(d); } while (0)
356 #define PXO_ADD_USHORT(d) do { ushort swap = INTEL_SHORT(d); memcpy(data+packet_size, &swap, sizeof(d) ); packet_size += sizeof(d); } while (0)
357 #define PXO_ADD_INT(d) do { int swap = INTEL_INT(d); memcpy(data+packet_size, &swap, sizeof(d) ); packet_size += sizeof(d); } while (0)
358 #define PXO_ADD_UINT(d) do { uint swap = INTEL_INT(d); memcpy(data+packet_size, &swap, sizeof(d) ); packet_size += sizeof(d); } while (0)
359
360 #define PXO_GET_DATA(d) do { memcpy(&d, data+offset, sizeof(d) ); offset += sizeof(d); } while(0)
361 #define PXO_GET_SHORT(d) do { short swap; memcpy(&swap, data+offset, sizeof(d) ); d = INTEL_SHORT(swap); offset += sizeof(d); } while(0)
362 #define PXO_GET_USHORT(d) do { ushort swap; memcpy(&swap, data+offset, sizeof(d) ); d = INTEL_SHORT(swap); offset += sizeof(d); } while(0)
363 #define PXO_GET_INT(d) do { int swap; memcpy(&swap, data+offset, sizeof(d) ); d = INTEL_INT(swap); offset += sizeof(d); } while(0)
364 #define PXO_GET_UINT(d) do { uint swap; memcpy(&swap, data+offset, sizeof(d) ); d = INTEL_INT(swap); offset += sizeof(d); } while(0)
365
366
367 #ifndef MAKE_FS1
368 #define PXO_SELECT(a, b, c, d, e, f) SELECT(a, b, c, d, e, f)
369 #define PXO_RECVFROM(a, b, c, d, e, f, g) RECVFROM(a, b, c, d, e, f, g)
370 #define PXO_SENDTO(a, b, c, d, e, f, g) SENDTO(a, b, c, d, e, f, g)
371 #else
372 #define PXO_SELECT(a, b, c, d, e, f) select(a, b, c, d, e)
373 #ifdef PLAT_UNIX
374 #define PXO_RECVFROM(a, b, c, d, e, f, g) recvfrom(a, b, c, d, e, (socklen_t*)f)
375 #else
376 #define PXO_RECVFROM(a, b, c, d, e, f, g) recvfrom(a, b, c, d, e, f)
377 #endif
378 #define PXO_SENDTO(a, b, c, d, e, f, g) sendto(a , b, c, d, e, f)
379 #endif
380
381 #endif
382
383