diff --git a/PlayerTracker b/PlayerTracker index 73b5a8c..96d9eca 100755 Binary files a/PlayerTracker and b/PlayerTracker differ diff --git a/include/parcer.c b/include/parcer.c index 43d7ef5..922693c 100644 --- a/include/parcer.c +++ b/include/parcer.c @@ -137,3 +137,5 @@ void read_string(const u_int8_t *buf, size_t recv_len, size_t *offset, char *out *offset += len; *ok = 1; } + + diff --git a/include/server_structs.h b/include/server_structs.h index 013539d..6c1344f 100644 --- a/include/server_structs.h +++ b/include/server_structs.h @@ -5,6 +5,7 @@ #include #include #include + struct handshake { // [not used in the current Remote Telemtry version by AC] // In future versions it will identify the platform type of the client. @@ -106,6 +107,7 @@ enum SessionType { struct trackAtributes { u_int8_t protocol_version; + u_int8_t session_index; u_int8_t current_session_index; u_int8_t session_count; diff --git a/source/main.cpp b/source/main.cpp index 20f0352..9b2b9ea 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,6 +1,8 @@ #include #include +#include #include +#include #include #include #include @@ -51,18 +53,16 @@ void init_carupdate(carAtributes *car) { car->lap_time = 0; car->cuts = 0; car->total_cuts = 0; - car->total_cuts_alltime = 0; // TODO: SQL querry to get total cuts of all time; - // TAG:1 - car->total_laps_completed = 0; - car->contacts = 0; - car->total_contacts = 0; // TODO: SQL querry to get total contacts of all time; - // TAG:2 + car->total_cuts_alltime = 0; // TODO: SQL querry to get total cuts of all time; TAG:1 + + car->total_laps_completed = 0; + car->contacts = 0; + car->total_contacts = 0; // TODO: SQL querry to get total contacts of all time; TAG:2 car->normalizedSplinePos = 0.0f; } int main(void) { - printf("[+] Starting server...\n"); printf("[+] Server listening on port %d\n", SERVER_IN_PORT); printf("[+] Server sending to %s:%d\n\n", SERVER_OUT_IP, SERVER_OUT_PORT); @@ -98,6 +98,7 @@ int main(void) { char message[124] = {0}; // just a place to put info messages from the server itself + printf("\n"); while (1) { offset = 0; @@ -120,7 +121,7 @@ int main(void) { case ACSP_SESSION_INFO: printf("[+] Message Type: ACSP_SESSION_INFO\n"); goto skip_message; - case ACSP_NEW_SESSION: // DONE + case ACSP_NEW_SESSION: // DONE: printf("[+] Message Type: ACSP_NEW_SESSION\n"); skip_message: offset = 1; // Reset offset to 1 to read after message types @@ -433,13 +434,12 @@ int main(void) { printf("Car ID: %d (%s) collided with Car ID: %d (%s)\n", update.carID, players[update.carID].driver_name, event_car_id, players[event_car_id].driver_name); - - players[update.carID].contacts++; - players[event_car_id].contacts++; + players[update.carID].contacts++; + players[event_car_id].contacts++; + + // TODO: Update total contacts for both players in the database + // TAG:2 Update total contacts for both players - // TODO: Update total contacts for both players in the database - // TAG:2 Update total contacts for both players - } break; case ACSP_CE_COLLISION_WITH_ENV: { @@ -447,15 +447,15 @@ int main(void) { printf("Car ID: %d (%s) collided with the environment\n", update.carID, players[update.carID].driver_name); - players[update.carID].contacts++; + players[update.carID].contacts++; - // TODO: Update total contacts for the player in the database - // TAG:2 Update total contacts for the player + // TODO: Update total contacts for the player in the database + // TAG:2 Update total contacts for the player } break; } - // TODO: possible iRacing style impact severity system - // With X velues and (e.g >5 m/s = 0x, >10 m/s = 2x, >15 m/s = 4x) && Blackflag limits (e.g x17 = DQ) + // TODO: possible iRacing style impact severity system + // With X velues and (e.g >5 m/s = 0x, >10 m/s = 2x, >15 m/s = 4x) && Blackflag limits (e.g x17 = DQ) float impact_speed = read_float((const u_int8_t *)buffer, recv_bytes, &offset, &ok); postion world_pos = {0}; @@ -463,15 +463,14 @@ int main(void) { world_pos.y = read_float((const u_int8_t *)buffer, recv_bytes, &offset, &ok); world_pos.z = read_float((const u_int8_t *)buffer, recv_bytes, &offset, &ok); - postion rel_pos = {0}; - rel_pos.x = read_float((const u_int8_t *)buffer, recv_bytes, &offset, &ok); - rel_pos.y = read_float((const u_int8_t *)buffer, recv_bytes, &offset, &ok); - rel_pos.z = read_float((const u_int8_t *)buffer, recv_bytes, &offset, &ok); - - printf("\tImpact Speed: %.2f m/s\n", impact_speed); - printf("\tWorld Position: X: %.2f Y: %.2f Z: %.2f\n", world_pos.x, world_pos.y, world_pos.z); - printf("\tRelative Position: X: %.2f Y: %.2f Z: %.2f\n\n", rel_pos.x, rel_pos.y, rel_pos.z); + postion rel_pos = {0}; + rel_pos.x = read_float((const u_int8_t *)buffer, recv_bytes, &offset, &ok); + rel_pos.y = read_float((const u_int8_t *)buffer, recv_bytes, &offset, &ok); + rel_pos.z = read_float((const u_int8_t *)buffer, recv_bytes, &offset, &ok); + printf("\tImpact Speed: %.2f m/s\n", impact_speed); + printf("\tWorld Position: X: %.2f Y: %.2f Z: %.2f\n", world_pos.x, world_pos.y, world_pos.z); + printf("\tRelative Position: X: %.2f Y: %.2f Z: %.2f\n\n", rel_pos.x, rel_pos.y, rel_pos.z); } break; @@ -480,6 +479,7 @@ int main(void) { // // ============================ // CLIENT → SERVER COMMANDS + // NOTE: These are not meant to be here, these are comands to SEND to the server // ============================ case ACSP_REALTIMEPOS_INTERVAL: printf("[+] Command: ACSP_REALTIMEPOS_INTERVAL\n"); @@ -517,9 +517,20 @@ int main(void) { printf("[+] Command: ACSP_RESTART_SESSION\n"); break; - case ACSP_ADMIN_COMMAND: + case ACSP_ADMIN_COMMAND: { // DONE: printf("[+] Command: ACSP_ADMIN_COMMAND\n"); - break; + char *buffer = (char *)malloc(256); + char command[256] = "/settime 19:00"; // TEST: + + buffer[0] = (char)ACSP_ADMIN_COMMAND; + for (int i = 1; i <= strlen(command); i++) { + buffer[i] = command[i - 1]; + } + + sendto(send_sock_fd, buffer, strlen(command) + 1, 0, NULL, 0); + printf("\tSent Admin Command: %s\n\n", command); + free(buffer); + } break; // ============================ // DEFAULT HANDLER @@ -534,6 +545,21 @@ int main(void) { close(send_sock_fd); close(recv_sock_fd); + // Free allocated memory + free(update.car_model); + free(update.driver_GUID); + free(update.car_skin); + free(update.driver_name); + free(update.driver_team); + + for (int i = 0; i < MAX_PLAYERS; i++) { + free(players[i].car_model); + free(players[i].driver_GUID); + free(players[i].car_skin); + free(players[i].driver_name); + free(players[i].driver_team); + } + free(trackInfo.server_name); free(trackInfo.track); free(trackInfo.track_config);