| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | /* |
| 20 | * $Logfile: /DescentIII/Main/mtclient/mtpilottrack.h $ |
| 21 | * $Revision: 1.1.1.1 $ |
| 22 | * $Date: 2003-08-26 03:58:40 $ |
| 23 | * $Author: kevinb $ |
| 24 | * |
| 25 | * Pilot tracker client header |
| 26 | * |
| 27 | * $Log: not supported by cvs2svn $ |
| 28 | * |
| 29 | * 13 4/20/99 8:57p Jeff |
| 30 | * compile for Linux |
| 31 | * |
| 32 | * 12 4/17/99 3:44p Kevin |
| 33 | * Demo2 changes & fixes |
| 34 | * |
| 35 | * 11 4/07/99 9:15a Kevin |
| 36 | * Changed PXO server addresses for release builds |
| 37 | * |
| 38 | * 10 3/02/99 5:50p Kevin |
| 39 | * Ouch. Duplicate structures existed and were conflicting. |
| 40 | * |
| 41 | * 9 2/16/99 12:36a Kevin |
| 42 | * Fixes for release builds of OEM V3 and KAtmai |
| 43 | * |
| 44 | * 8 2/03/99 6:14p Kevin |
| 45 | * OEM changes |
| 46 | * |
| 47 | * 7 12/23/98 6:38p Kevin |
| 48 | * All UDP data (except gamespy) now uses one (registered) port number |
| 49 | * |
| 50 | * 6 10/30/98 11:25a Kevin |
| 51 | * Message of the day for PXO |
| 52 | * |
| 53 | * 5 10/09/98 2:56p Kevin |
| 54 | * Changed IP addresses for PXO demo |
| 55 | * |
| 56 | * 4 10/01/98 11:37a Kevin |
| 57 | * UI fixes and stuff |
| 58 | * |
| 59 | * 3 9/03/98 11:12a Kevin |
| 60 | * Fixed bug in #define |
| 61 | * |
| 62 | * 2 6/01/98 10:10a Kevin |
| 63 | * Added DLL connection interface and auto update DLL |
| 64 | * |
| 65 | * 1 5/25/98 4:12p Kevin |
| 66 | * |
| 67 | * 11 5/14/98 6:08p Kevin |
| 68 | * fixed encryption bug |
| 69 | * |
| 70 | * 10 5/14/98 5:19p Kevin |
| 71 | * Encrypted pilot data |
| 72 | * |
| 73 | * 9 5/13/98 4:06p Kevin |
| 74 | * Added more mastertracker info |
| 75 | * |
| 76 | * 8 5/12/98 5:12p Kevin |
| 77 | * added virgin_pilot field |
| 78 | * |
| 79 | * 7 5/12/98 5:10p Kevin |
| 80 | * added lateral and rotational thrust |
| 81 | * |
| 82 | * 6 5/07/98 9:47a Kevin |
| 83 | * Made pilot reading more robust |
| 84 | * |
| 85 | * 5 5/04/98 12:53p Kevin |
| 86 | * Fixed mastertracker resend stuff |
| 87 | * |
| 88 | * 4 5/04/98 10:56a Kevin |
| 89 | * Mastertracker fixes/enhancements |
| 90 | * |
| 91 | * 3 4/30/98 3:50p Kevin |
| 92 | * Mastertracker pilot stats |
| 93 | * |
| 94 | * 2 4/27/98 7:12p Kevin |
| 95 | * Mastertracker pilot tracker |
| 96 | * |
| 97 | * 1 4/27/98 5:27p Kevin |
| 98 | * Initial version |
| 99 | * |
| 100 | * $NoKeywords: $ |
| 101 | */ |
| 102 | |
| 103 | #ifndef _PILOT_TRACKER_HEADER |
| 104 | #define _PILOT_TRACKER_HEADER |
| 105 | // Pilot tracker client header |
| 106 | |
| 107 | #ifdef WIN32 |
| 108 | #pragma pack(push, r_udp) |
| 109 | #endif |
| 110 | #pragma pack(1) |
| 111 | |
| 112 | // Definitions |
| 113 | #define STATE_IDLE 0 |
| 114 | #define STATE_SENDING_PILOT 1 |
| 115 | #define STATE_READING_PILOT 2 |
| 116 | #define STATE_RECEIVED_PILOT 3 |
| 117 | #define STATE_WROTE_PILOT 4 |
| 118 | #define STATE_TIMED_OUT 5 |
| 119 | #define STATE_PILOT_NOT_FOUND 6 |
| 120 | #define STATE_WRITE_PILOT_FAILED 7 |
| 121 | |
| 122 | #define REGPORT 2092 // The UDP port |
| 123 | #define PILOTTRACKERNAME "tracker.pxo.nottheeye.com" |
| 124 | |
| 125 | #define PILOT_REQ_TIMEOUT 30.000 |
| 126 | #define PILOT_REQ_RESEND_TIME 2.0 |
| 127 | |
| 128 | #define MAX_NET_RETRIES 30 |
| 129 | #define NET_ACK_TIMEOUT 1.5 |
| 130 | |
| 131 | // This is for type |
| 132 | #define UNT_CONTROL 0 |
| 133 | #define UNT_NEW_ID_REQUEST 1 |
| 134 | #define UNT_VALIDAT_ID_REQUEST 2 |
| 135 | #define UNT_LOOKUP_ID_REQUEST 3 |
| 136 | #define UNT_UPDATE_ID_REQUEST 4 |
| 137 | #define UNT_MOTD_REQUEST 5 |
| 138 | #define UNT_MOTD_RESPONSE 6 |
| 139 | #define UNT_PILOT_DATA_READ 7 // Request from the game for pilot info |
| 140 | #define UNT_PILOT_DATA_RESPONSE 8 // Mastertracker's response to a read request (has pilot data in this packet) |
| 141 | #define UNT_PILOT_DATA_WRITE 9 // Request from the server to write a user record |
| 142 | #define UNT_PILOT_WRITE_FAILED 10 // Server didn't update the pilots record for some reason |
| 143 | #define UNT_PILOT_WRITE_SUCCESS 11 // Server updated the pilots record |
| 144 | #define UNT_PILOT_READ_FAILED 12 // Couldn't find the record |
| 145 | #define UNT_LOGIN_AUTH_REQUEST 13 // Request login authentication by login/password only (returns tracker id) |
| 146 | #define UNT_LOGIN_NO_AUTH 14 // Couldn't login this user (code has reason) |
| 147 | #define UNT_LOGIN_AUTHENTICATED 15 // User was authenticated (data has sz string with tracker id) |
| 148 | #define UNT_TRACKER_VERSION_REQ 16 // Request the latest MT version (xcode has game type) code has present version |
| 149 | #define UNT_TRACKER_VERSION_RSP \ |
| 150 | 17 // Response for the latest MT version (xcode has game type) code has version data has null term string with url for |
| 151 | // dll to download |
| 152 | |
| 153 | // This is for code |
| 154 | #define CMD_NEW_USER_ACK 1 |
| 155 | #define CMD_NEW_USER_NAK 2 |
| 156 | #define CMD_VALIDATED_USER_ACK 3 |
| 157 | #define CMD_UPDATED_USER_ACK 4 |
| 158 | #define CMD_CLIENT_RECEIVED 5 |
| 159 | #define CMD_FIND_USER_NAK 6 |
| 160 | #define CMD_FIND_USER_ACK 7 |
| 161 | #define CMD_UPDATED_USER_NAK 8 |
| 162 | #define CMD_VALIDATED_USER_NAK 9 |
| 163 | // Game designators for UNT_PILOT_DATA_REQUEST and UNT_PILOT_DATA_RESPONSE |
| 164 | #define CMD_GAME_FREESPACE 10 |
| 165 | #define CMD_GAME_DESCENT3 11 |
| 166 | |
| 167 | // This is for xcode |
| 168 | #define REG_NAK_EMAIL 0 // failed to register the guy because of an invalid email address |
| 169 | #define REG_NAK_LOGIN 1 // failed to register the guy because an existing login exists |
| 170 | #define REG_NAK_ERROR 2 // failed to register because of an error on the tracker |
| 171 | #define REG_NAK_STRINGS 3 // failed to validate because of invalid password/login match |
| 172 | #define REG_NAK_UNKNOWN 4 // failed to validate because the player is unknown |
| 173 | #define REG_NAK_UPDATE_PL 5 // update info failed because login/passwd were not correct |
| 174 | #define REG_NAK_UPDATE_GEN 6 // update info failed in general (tracker problem) |
| 175 | #define REG_NAK_UPDATE_LOG 7 // update failed because login not found |
| 176 | #define REG_ACK_NEW_ID 8 // New id created, just used for return code, not net packets. |
| 177 | |
| 178 | #define MAX_UDP_DATA_LENGH 500 |
| 179 | #define PACKED_HEADER_ONLY_SIZE (sizeof(udp_packet_header) - MAX_UDP_DATA_LENGH) |
| 180 | // sizeof(update_id_request) //The largest packet |
| 181 | |
| 182 | // data could be one of the following: |
| 183 | |
| 184 | // type == UNT_NEW_ID_REQUEST |
| 185 | // Respond with ACK |
| 186 | struct new_id_request { |
| 187 | char first_name[REAL_NAME_LEN]; // Real Name |
| 188 | char last_name[REAL_NAME_LEN]; // Real Name |
| 189 | char login[LOGIN_LEN]; // Login id |
| 190 | char password[PASSWORD_LEN]; // password |
| 191 | char email[EMAIL_LEN]; // Email Address |
| 192 | uint8_t showemail; // 0==don't show 1 == show |
| 193 | uint8_t showname; // 0==don't show 1 == show |
| 194 | }; |
| 195 | |
| 196 | // type == UNT_VALIDAT_ID_REQUEST or UNT_LOOKUP_ID_REQUEST |
| 197 | struct validate_id_request { |
| 198 | char login[LOGIN_LEN]; // Login id |
| 199 | char password[PASSWORD_LEN]; // password |
| 200 | char tracker_id[TRACKER_ID_LEN]; // Tracker ID |
| 201 | }; |
| 202 | |
| 203 | // type == UNT_UPDATE_ID_REQUEST |
| 204 | struct update_id_request { |
| 205 | char old_login[LOGIN_LEN]; // Login before it's changed. |
| 206 | char old_password[PASSWORD_LEN]; // Password before it's changed |
| 207 | char tracker_id[TRACKER_ID_LEN]; // Tracker ID (not sure if we need it for updating, but maybe) |
| 208 | char first_name[REAL_NAME_LEN]; // Real Name |
| 209 | char last_name[REAL_NAME_LEN]; // Real Name |
| 210 | char login[LOGIN_LEN]; // Login id (new) |
| 211 | char password[PASSWORD_LEN]; // password (new) |
| 212 | char email[EMAIL_LEN]; // Email Address (new) |
| 213 | uint8_t showemail; // 0==don't show 1 == show |
| 214 | uint8_t showname; // 0==don't show 1 == show |
| 215 | }; |
| 216 | |
| 217 | struct pilot_request { |
| 218 | char pilot_name[PILOT_NAME_LEN]; // Login id |
| 219 | char tracker_id[TRACKER_ID_LEN]; // Tracker ID |
| 220 | }; |
| 221 | |
| 222 | struct udp_packet_header { |
| 223 | uint8_t type; // Type of request |
| 224 | uint16_t len; // Length of total packet, including this header |
| 225 | uint32_t code; // For control messages |
| 226 | uint16_t xcode; // For control/NAK messages and for sigs. |
| 227 | uint32_t sig; // To identify unique return ACKs |
| 228 | uint32_t security; // Just a random value, we store the last value used in the user record |
| 229 | // So we don't process the same request twice. |
| 230 | uint8_t data[MAX_UDP_DATA_LENGH]; |
| 231 | }; |
| 232 | |
| 233 | #ifdef WIN32 |
| 234 | // Queue -- We need a queue to put responses in, so after a certain amount of time |
| 235 | // If we don't get an ACK back from the client, we resend the packet, until eventually |
| 236 | // We give up. |
| 237 | |
| 238 | struct net_reg_queue { |
| 239 | char login[LOGIN_LEN]; // Login id |
| 240 | uint32_t time_last_sent; // Time in milliseconds since we last sent this packet |
| 241 | int retries; // Number of times this has been sent |
| 242 | udp_packet_header packet; // Packet containing the actual data to resend, etc. |
| 243 | struct net_reg_queue *next; // Pointer to next item in the list |
| 244 | SOCKADDR netaddr; |
| 245 | uint32_t sig; // Signature to be used by the client to ACK our response. |
| 246 | }; |
| 247 | #endif |
| 248 | |
| 249 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 250 | // GAME SPECIFIC structures |
| 251 | |
| 252 | /* |
| 253 | #pragma pack(1) |
| 254 | struct vmt_descent3_struct { |
| 255 | char tracker_id[TRACKER_ID_LEN]; |
| 256 | char pilot_name[PILOT_NAME_LEN]; |
| 257 | int rank; |
| 258 | |
| 259 | int kills; |
| 260 | int deaths; |
| 261 | int suicides; |
| 262 | int online_time; |
| 263 | int games_played; |
| 264 | uint32_t security; |
| 265 | uint8_t virgin_pilot; //This pilot was just created if TRUE |
| 266 | uint32_t lateral_thrust; |
| 267 | uint32_t rotational_thrust; |
| 268 | uint32_t sliding_pct; //Percentage of the time you were sliding |
| 269 | uint32_t checksum; //This value needs to be equal to whatever the checksum is once the |
| 270 | packet is decoded uint32_t pad; //just to provide room for out 4 byte encryption boundry only needed on |
| 271 | the client side for now |
| 272 | }; |
| 273 | */ |
| 274 | |
| 275 | // |
| 276 | // ------------------------------------------------------------------------------------------------------------- |
| 277 | |
| 278 | /** |
| 279 | * Get MOTD from remote. Call with NULL to poll. Call with valid pointer and maxlen to get the message of the day. |
| 280 | * @param szmotd |
| 281 | * @param maxlen |
| 282 | * @return |
| 283 | * -3 - Error, called with NULL, but no request is waiting; |
| 284 | * -2 - Error, already waiting on message of the day (hasn't timed out yet); |
| 285 | * -1 - Timeout waiting for message of the day; |
| 286 | * 0 - Waiting for data; |
| 287 | * 1 - Data received. |
| 288 | */ |
| 289 | int GetD3MOTD(char *szmotd, int maxlen); |
| 290 | |
| 291 | /** |
| 292 | * Cancel previous MOTD request |
| 293 | * @return |
| 294 | * -3 Error, called with NULL, but no request is waiting |
| 295 | * 2 Request successfully cancelled |
| 296 | */ |
| 297 | int GetD3MOTDCancel(); |
| 298 | |
| 299 | // Function prototypes |
| 300 | int InitPilotTrackerClient(); |
| 301 | void AckServer(uint32_t sig); |
| 302 | |
| 303 | int SendD3PilotData(vmt_descent3_struct *d3_pilot); |
| 304 | int GetD3PilotData(vmt_descent3_struct *d3_pilot, char *pilot_name, char *tracker_id); |
| 305 | |
| 306 | /** |
| 307 | * Cancel previous GetD3PilotData() wait |
| 308 | * @return |
| 309 | * -3: Error - Called GetD3PilotData with NULL, but no request is waiting; |
| 310 | * 2: Request successfully canceled; |
| 311 | */ |
| 312 | int GetD3PilotDataCancel(); |
| 313 | void PollPTrackNet(); |
| 314 | void ValidIdle(); |
| 315 | // int ValidateUser(validate_id_request *valid_id); |
| 316 | int ValidateUser(validate_id_request *valid_id, char *trackerid); |
| 317 | void xorcode(void *data, uint32_t len, uint32_t hash); |
| 318 | extern int MTAVersionCheck(uint32_t oldver, char *URL); |
| 319 | void VersionIdle(); |
| 320 | void HandlePilotData(uint8_t *data, int len, network_address *from); |
| 321 | |
| 322 | #ifdef WIN32 |
| 323 | #pragma pack(pop, r_udp) |
| 324 | #else |
| 325 | #pragma pack() |
| 326 | #endif |
| 327 | #endif |