]> icculus.org git repositories - taylor/freespace2.git/blob - include/ptrack.h
first pass at PXO reintegration
[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 } pilot_request;
143
144 // type == UNT_VALID_SW_MSN_REQ
145 typedef struct squad_war_request {              
146         int squad_plr1[MAX_SQUAD_PLAYERS];      // id #'s for all squad members in the match
147         int squad_plr2[MAX_SQUAD_PLAYERS];      // id #'s for all squad memebrs in the match
148
149         ubyte squad_count1;                                             // # of players present in squad 1
150         ubyte squad_count2;                                             // # of players present in squad 2      
151
152         char match_code[MATCH_CODE_LEN];                // code for the match   
153
154         char mission_filename[MAX_PXO_FILENAME_LEN];            // filename of mission
155         int mission_checksum;                                                                   // mission checksum
156 } squad_war_request;
157
158 // type == UNT_SW_RESULT_WRITE
159 typedef struct squad_war_result {
160         char match_code[MATCH_CODE_LEN];                        // code for the match
161         ubyte result;                                                                   // result of the match, 0 == tie, 1 == one team won
162         ubyte squad_count1;                                                     // # of players in winning squad
163         ubyte squad_count2;                                                     // # of players in the losing squad
164         int squad_winners[MAX_SQUAD_PLAYERS];   // list of players on the winning team
165         int squad_losers[MAX_SQUAD_PLAYERS];    // list of players on the losing team
166 } squad_war_result;
167
168 // type == UNT_VALID_SW_MSN_RSP and UNT_SW_RESULT_RESPONSE
169 typedef struct squad_war_response {
170         char reason[MAX_SQUAD_RESPONSE_LEN];
171         unsigned char accepted;
172 } squad_war_response;
173
174 #pragma pack(push, 1)
175         typedef struct {        
176                 unsigned char type;                                             // type
177                 unsigned short len;                                             //      Length of total packet, including this header
178                 unsigned int code;                                              // For control messages
179                 unsigned short xcode;                                   // For control/NAK messages and for sigs.
180                 unsigned int sig;                                               // To identify unique return ACKs
181                 unsigned int security;                                  // Just a random value, we store the last value used in the user record
182                                                                                                                 // So we don't process the same request twice.          
183                 unsigned char data[MAX_UDP_DATA_LENGH];
184         } udp_packet_header;
185 #pragma pack(pop)
186
187
188 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
189 // GAME SPECIFIC structures
190
191
192 #ifdef MAKE_FS1
193 // ------------------------------------------------------------------------------------------------------------
194 // FREESPACE
195 // NOTE : this is obsolete for FS2  -  we use our own FS2 struct
196 #define MAX_FS_MEDALS           16                      // these should correspond directly to those defined inside of freespace.
197 #define MAX_FS_SHIP_TYPES       75                      // this one will be scaled down to be the correct # eventually
198 typedef struct vmt_freespace_struct {
199         char tracker_id[TRACKER_ID_LEN];
200         char pilot_name[PILOT_NAME_LEN];
201
202         int score;
203         int rank;
204         int medals[MAX_FS_MEDALS];
205    
206         int kills[MAX_FS_SHIP_TYPES];            // only valid kills (i.e. not on friendlies).
207         int assists;
208         int kill_count;                // total alltime kills
209         int kill_count_ok;                          // total valid alltime kills (no friendlies)
210         unsigned int p_shots_fired;      // primary weapon
211         unsigned int s_shots_fired;    // secondary weapon
212
213         unsigned int p_shots_hit;      // primary
214         unsigned int s_shots_hit;      // secondary
215
216         unsigned int p_bonehead_hits;  // hits/kills on the players own team
217         unsigned int s_bonehead_hits;
218    int          bonehead_kills;
219
220         int                      security;                              
221         unsigned char virgin_pilot;     //This pilot was just created if TRUE
222         unsigned int checksum;                  //This value needs to be equal to whatever the checksum is once the packet is decoded
223                 
224         unsigned int missions_flown;                    // # of missions flown to completion
225         unsigned int flight_time;                               // total hours of flight time
226         unsigned int last_flown;                                // data/time of last mission flown
227 } vmt_freespace_struct;
228 #define FREESPACE_BLOCK_SIZE (sizeof(vmt_freespace_struct))
229
230 #else
231
232 // ------------------------------------------------------------------------------------------------------------
233 // FREESPACE2
234 #ifdef FS2_DEMO
235         #define MAX_FS2_MEDALS                                  16                                              // these should correspond directly to those defined inside of freespace.
236         #define MAX_FS2_SHIP_TYPES                              120                                     // this one will be scaled down to be the correct # eventually
237         typedef struct vmt_freespace2_struct {
238                 char                            tracker_id[TRACKER_ID_LEN];
239                 char                            pilot_name[PILOT_NAME_LEN];
240
241                 int                             score;
242                 int                             rank;
243                 int                             medals[MAX_FS2_MEDALS];
244    
245                 ushort                  kills[MAX_FS2_SHIP_TYPES];               // only valid kills (i.e. not on friendlies).
246                 int                             assists;
247                 int                             kill_count;                // total alltime kills
248                 int                             kill_count_ok;                      // total valid alltime kills (no friendlies)
249                 unsigned int    p_shots_fired;   // primary weapon
250                 unsigned int    s_shots_fired;    // secondary weapon
251
252                 unsigned int    p_shots_hit;      // primary
253                 unsigned int    s_shots_hit;      // secondary
254
255                 unsigned int    p_bonehead_hits;  // hits/kills on the players own team
256                 unsigned int    s_bonehead_hits;
257                 int                             bonehead_kills;
258
259                 int                             security;                               
260                 unsigned char   virgin_pilot;   //This pilot was just created if TRUE
261                 unsigned int    checksum;                       //This value needs to be equal to whatever the checksum is once the packet is decoded
262                         
263                 unsigned int    missions_flown;                 // # of missions flown to completion
264                 unsigned int    flight_time;                            // total hours of flight time
265                 unsigned int    last_flown;                             // data/time of last mission flown
266         } vmt_freespace2_struct;
267 #else 
268         #define MAX_FS2_MEDALS                  NUM_MEDALS                      // these should correspond directly to those defined inside of freespace.
269         #define MAX_FS2_SHIP_TYPES              MAX_SHIP_TYPES          // this one will be scaled down to be the correct # eventually  
270         typedef struct vmt_freespace2_struct {
271                 char                            tracker_id[TRACKER_ID_LEN];
272                 char                            pilot_name[PILOT_NAME_LEN];
273
274                 int                             score;
275                 int                             rank;           
276                 int                             assists;
277                 int                             kill_count;                // total alltime kills
278                 int                             kill_count_ok;                      // total valid alltime kills (no friendlies)
279                 unsigned int    p_shots_fired;   // primary weapon
280                 unsigned int    s_shots_fired;    // secondary weapon
281
282                 unsigned int    p_shots_hit;      // primary
283                 unsigned int    s_shots_hit;      // secondary
284
285                 unsigned int    p_bonehead_hits;  // hits/kills on the players own team
286                 unsigned int    s_bonehead_hits;
287                 int                             bonehead_kills;
288
289                 int                             security;                               
290                 unsigned char   virgin_pilot;   //This pilot was just created if TRUE
291                 unsigned int    checksum;                       //This value needs to be equal to whatever the checksum is once the packet is decoded
292                         
293                 unsigned int    missions_flown;                 // # of missions flown to completion
294                 unsigned int    flight_time;                            // total hours of flight time
295                 unsigned int    last_flown;                             // data/time of last mission flown
296                 
297                 unsigned short num_medals;
298                 unsigned short num_ship_types;
299
300                 int                             medals[MAX_FS2_MEDALS];   
301                 unsigned short kills[MAX_FS2_SHIP_TYPES];                // only valid kills (i.e. not on friendlies).
302         } vmt_freespace2_struct;
303 #endif
304 #define FREESPACE2_BLOCK_SIZE (sizeof(vmt_freespace2_struct))
305
306 #endif // MAKE_FS1
307
308 //Function prototypes
309 int InitPilotTrackerClient();
310 void AckServer(unsigned int sig);
311
312 #ifdef MAKE_FS1
313 int SendFSPilotData(vmt_freespace2_struct *fs_pilot);
314 int GetFSPilotData(vmt_freespace2_struct *fs_pilot, const char *pilot_name, const char *tracker_id, int update_security);
315 #else
316 int SendFSPilotData(vmt_freespace2_struct *fs_pilot);
317 int GetFSPilotData(vmt_freespace2_struct *fs_pilot, const char *pilot_name, const char *tracker_id, int update_security);
318 #endif
319 int SendSWData(squad_war_result *sw_res, squad_war_response *sw_resp);
320 void PollPTrackNet();
321
322 //Definitions
323 #define STATE_IDLE                                              0
324 #define STATE_SENDING_PILOT                     1
325 #define STATE_READING_PILOT                     2
326 #define STATE_RECEIVED_PILOT                    3
327 #define STATE_WROTE_PILOT                               4
328 #define STATE_TIMED_OUT                                 5
329 #define STATE_PILOT_NOT_FOUND                   6
330 #define STATE_WRITE_PILOT_FAILED                7
331
332 #define PILOT_REQ_TIMEOUT                       30000
333 #define PILOT_REQ_RESEND_TIME           3500
334
335
336 #endif
337
338