generated from AfonsoCMSousa/CPP-Template
Feature: parce Contacs and laying ground for a iRacing Contact system
This commit is contained in:
+73
-20
@@ -52,6 +52,12 @@ void init_carupdate(carAtributes *car) {
|
||||
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->normalizedSplinePos = 0.0f;
|
||||
}
|
||||
|
||||
@@ -148,8 +154,9 @@ int main(void) {
|
||||
str_len_8 = read_uint8((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
||||
read_string((const u_int8_t *)buffer, recv_bytes, &offset, trackInfo.weather_graphics, str_len_8, &ok);
|
||||
|
||||
// FIX: elapsed_ms was/is incorrectly read
|
||||
trackInfo.elapsed_ms = read_uint32((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
||||
// FIX: elapsed_ms was/is incorrectly read
|
||||
// TEST: Verify with actual server
|
||||
trackInfo.elapsed_ms = read_uint32((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
||||
|
||||
if (!ok) {
|
||||
fprintf(stderr, "[-] Error parsing NEW_SESSION packet (offset=%zu)\n", offset);
|
||||
@@ -384,14 +391,14 @@ int main(void) {
|
||||
printf("\tServer Message: \"%s\"\n\n", message);
|
||||
break;
|
||||
|
||||
case ACSP_LAP_COMPLETED: // TODO: Handle lap completed events
|
||||
case ACSP_LAP_COMPLETED: // DONE: Handle lap completed events
|
||||
printf("[+] Message Type: ACSP_LAP_COMPLETED\n");
|
||||
offset = 1; // Reset offset to 1 to read after message types
|
||||
|
||||
update.carID = read_uint8((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
||||
|
||||
// TEST: Possiblity of lap_time not behing correct
|
||||
// TODO: Verify with actual server
|
||||
|
||||
// TEST: Possiblity of lap_time not behing correct
|
||||
// TODO: Verify with actual server
|
||||
update.lap_time = read_uint32((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
||||
update.cuts = read_uint32((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
||||
|
||||
@@ -407,24 +414,70 @@ int main(void) {
|
||||
// ============================
|
||||
// EVENTS
|
||||
// ============================
|
||||
case ACSP_CLIENT_EVENT:
|
||||
case ACSP_CLIENT_EVENT: {
|
||||
printf("[+] Message Type: ACSP_CLIENT_EVENT\n");
|
||||
break;
|
||||
offset = 1; // Reset offset to 1 to read after message types
|
||||
|
||||
// ============================
|
||||
// EVENT TYPES
|
||||
// ============================
|
||||
case ACSP_CE_COLLISION_WITH_CAR:
|
||||
printf("[+] Event Type: ACSP_CE_COLLISION_WITH_CAR\n");
|
||||
break;
|
||||
u_int8_t event_type = read_uint8((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
||||
|
||||
case ACSP_CE_COLLISION_WITH_ENV:
|
||||
printf("[+] Event Type: ACSP_CE_COLLISION_WITH_ENV\n");
|
||||
break;
|
||||
update.carID = read_uint8((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
||||
u_int8_t event_car_id = 255; // If event doesnt involve another car, set to 255
|
||||
|
||||
// TODO: Add for ranking system
|
||||
// OPTIMIZE: Make sure DB queries are optimized for speed has there can be more that 30 players querying at the same time
|
||||
//
|
||||
switch (event_type) {
|
||||
// ============================
|
||||
// EVENT TYPES
|
||||
// ============================
|
||||
case ACSP_CE_COLLISION_WITH_CAR: {
|
||||
printf("[+] Event Type: ACSP_CE_COLLISION_WITH_CAR\n");
|
||||
event_car_id = read_uint8((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
||||
|
||||
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].collisions++;
|
||||
players[event_car_id].collisions++;
|
||||
|
||||
// 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: {
|
||||
printf("[+] Event Type: ACSP_CE_COLLISION_WITH_ENV\n");
|
||||
|
||||
printf("Car ID: %d (%s) collided with the environment\n", update.carID, players[update.carID].driver_name);
|
||||
|
||||
players[update.carID].contacts++;
|
||||
|
||||
// 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)
|
||||
|
||||
float impact_speed = read_float((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
||||
postion world_pos = {0};
|
||||
world_pos.x = read_float((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
||||
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);
|
||||
|
||||
|
||||
} break;
|
||||
|
||||
// TODO: Add for ranking system
|
||||
// OPTIMIZE: Make sure DB queries are optimized for speed has there can be more that 30 players querying at the same time
|
||||
//
|
||||
// ============================
|
||||
// CLIENT → SERVER COMMANDS
|
||||
// ============================
|
||||
|
||||
Reference in New Issue
Block a user