generated from AfonsoCMSousa/CPP-Template
Feature: parce Contacs and laying ground for a iRacing Contact system
This commit is contained in:
parent
1fe0452ad6
commit
2df0838be8
BIN
PlayerTracker
BIN
PlayerTracker
Binary file not shown.
@ -49,16 +49,18 @@ int32_t read_int32(const u_int8_t *buf, size_t recv_len, size_t *offset, int *ok
|
|||||||
return (int32_t)ntohl(v);
|
return (int32_t)ntohl(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_float(const u_int8_t *buf, size_t recv_len, size_t *offset, float *out, int *ok) {
|
float read_float(const u_int8_t *buf, size_t recv_len, size_t *offset, int *ok) {
|
||||||
if (!ensure(recv_len, *offset, sizeof(float))) {
|
if (!ensure(recv_len, *offset, sizeof(float))) {
|
||||||
*ok = 0;
|
*ok = 0;
|
||||||
return;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
uint32_t v;
|
u_int32_t v_int;
|
||||||
memcpy(&v, buf + *offset, sizeof(v));
|
memcpy(&v_int, buf + *offset, sizeof(v_int));
|
||||||
*offset += sizeof(v);
|
*offset += sizeof(v_int);
|
||||||
v = ntohl(v);
|
v_int = ntohl(v_int);
|
||||||
memcpy(out, &v, sizeof(float));
|
float v_float;
|
||||||
|
memcpy(&v_float, &v_int, sizeof(v_float));
|
||||||
|
return v_float;
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_bytes(const u_int8_t *buf, size_t recv_len, size_t *offset, u_int8_t *out, size_t len, int *ok) {
|
void read_bytes(const u_int8_t *buf, size_t recv_len, size_t *offset, u_int8_t *out, size_t len, int *ok) {
|
||||||
|
|||||||
@ -35,7 +35,7 @@ int32_t read_int32(const u_int8_t *buf, size_t recv_len, size_t *offset, int *ok
|
|||||||
|
|
||||||
// Reads a 32-bit float from the buffer in network byte order.
|
// Reads a 32-bit float from the buffer in network byte order.
|
||||||
// Advances the offset by 4 bytes.
|
// Advances the offset by 4 bytes.
|
||||||
void read_float(const u_int8_t *buf, size_t recv_len, size_t *offset, float *out, int *ok);
|
float read_float(const u_int8_t *buf, size_t recv_len, size_t *offset, int *ok);
|
||||||
|
|
||||||
// Reads a fixed number of bytes into the output buffer.
|
// Reads a fixed number of bytes into the output buffer.
|
||||||
// The output buffer must be at least 'len' bytes long.
|
// The output buffer must be at least 'len' bytes long.
|
||||||
|
|||||||
@ -59,10 +59,18 @@ struct postion {
|
|||||||
float z;
|
float z;
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
|
enum flag {
|
||||||
|
NO_FLAG = 0,
|
||||||
|
YELLOW_FLAG = 1,
|
||||||
|
BLUE_FLAG = 2,
|
||||||
|
BLACK_FLAG = 3,
|
||||||
|
CHECKERED_FLAG = 4,
|
||||||
|
}
|
||||||
|
|
||||||
struct carAtributes {
|
struct carAtributes {
|
||||||
// Related to ACSP_CAR_INFO
|
// Related to ACSP_CAR_INFO
|
||||||
u_char isConnected; // 1 = connected, 0 = disconnected
|
u_char isConnected; // 1 = connected, 0 = disconnected
|
||||||
u_char isLoading; // 1 = loading, 0 = not loading
|
u_char isLoading; // 1 = loading, 0 = not isLoading
|
||||||
|
|
||||||
char *car_model;
|
char *car_model;
|
||||||
char *car_skin;
|
char *car_skin;
|
||||||
@ -80,6 +88,13 @@ struct carAtributes {
|
|||||||
u_int32_t cuts;
|
u_int32_t cuts;
|
||||||
u_int32_t total_cuts;
|
u_int32_t total_cuts;
|
||||||
u_int32_t total_cuts_alltime;
|
u_int32_t total_cuts_alltime;
|
||||||
|
u_int16_t total_laps_completed;
|
||||||
|
u_int16_t contacts;
|
||||||
|
u_int16_t total_contacts;
|
||||||
|
|
||||||
|
flag current_flag; // TODO: implement flag status updates
|
||||||
|
// TAG:3
|
||||||
|
|
||||||
float_t normalizedSplinePos;
|
float_t normalizedSplinePos;
|
||||||
|
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|||||||
@ -52,6 +52,12 @@ void init_carupdate(carAtributes *car) {
|
|||||||
car->cuts = 0;
|
car->cuts = 0;
|
||||||
car->total_cuts = 0;
|
car->total_cuts = 0;
|
||||||
car->total_cuts_alltime = 0; // TODO: SQL querry to get total cuts of all time;
|
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;
|
car->normalizedSplinePos = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,6 +155,7 @@ int main(void) {
|
|||||||
read_string((const u_int8_t *)buffer, recv_bytes, &offset, trackInfo.weather_graphics, str_len_8, &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
|
// 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);
|
trackInfo.elapsed_ms = read_uint32((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
||||||
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
@ -384,7 +391,7 @@ int main(void) {
|
|||||||
printf("\tServer Message: \"%s\"\n\n", message);
|
printf("\tServer Message: \"%s\"\n\n", message);
|
||||||
break;
|
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");
|
printf("[+] Message Type: ACSP_LAP_COMPLETED\n");
|
||||||
offset = 1; // Reset offset to 1 to read after message types
|
offset = 1; // Reset offset to 1 to read after message types
|
||||||
|
|
||||||
@ -407,20 +414,66 @@ int main(void) {
|
|||||||
// ============================
|
// ============================
|
||||||
// EVENTS
|
// EVENTS
|
||||||
// ============================
|
// ============================
|
||||||
case ACSP_CLIENT_EVENT:
|
case ACSP_CLIENT_EVENT: {
|
||||||
printf("[+] Message Type: ACSP_CLIENT_EVENT\n");
|
printf("[+] Message Type: ACSP_CLIENT_EVENT\n");
|
||||||
break;
|
offset = 1; // Reset offset to 1 to read after message types
|
||||||
|
|
||||||
|
u_int8_t event_type = read_uint8((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
switch (event_type) {
|
||||||
// ============================
|
// ============================
|
||||||
// EVENT TYPES
|
// EVENT TYPES
|
||||||
// ============================
|
// ============================
|
||||||
case ACSP_CE_COLLISION_WITH_CAR:
|
case ACSP_CE_COLLISION_WITH_CAR: {
|
||||||
printf("[+] Event Type: ACSP_CE_COLLISION_WITH_CAR\n");
|
printf("[+] Event Type: ACSP_CE_COLLISION_WITH_CAR\n");
|
||||||
break;
|
event_car_id = read_uint8((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
||||||
|
|
||||||
case ACSP_CE_COLLISION_WITH_ENV:
|
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("[+] Event Type: ACSP_CE_COLLISION_WITH_ENV\n");
|
||||||
break;
|
|
||||||
|
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
|
// 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
|
// OPTIMIZE: Make sure DB queries are optimized for speed has there can be more that 30 players querying at the same time
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user