Stabe: V1.0 - First Stable Release AND API connection (See https://git.fernandovideira.com/AfonsoCMSousa/ACPlayer_database_api)

This commit is contained in:
2025-10-20 22:04:28 +01:00
parent e94afdfd9b
commit 9449749b9b
5 changed files with 247 additions and 42 deletions
+20 -20
View File
@@ -1,4 +1,5 @@
#include "parcer.h"
#include "server_structs.h"
#include <sys/types.h>
int ensure(size_t recv_len, size_t offset, size_t need) {
@@ -39,28 +40,28 @@ u_int32_t read_uint32(const u_int8_t *buf, size_t recv_len, size_t *offset, int
}
int32_t read_int32(const u_int8_t *buf, size_t recv_len, size_t *offset, int *ok) {
if (!ensure(recv_len, *offset, sizeof(int32_t))) {
*ok = 0;
return 0;
}
int32_t v;
memcpy(&v, buf + *offset, sizeof(v));
*offset += sizeof(v);
return (int32_t)ntohl(v);
if (!ensure(recv_len, *offset, sizeof(int32_t))) {
*ok = 0;
return 0;
}
int32_t v;
memcpy(&v, buf + *offset, sizeof(v));
*offset += sizeof(v);
return (int32_t)ntohl(v);
}
float read_float(const u_int8_t *buf, size_t recv_len, size_t *offset, int *ok) {
if (!ensure(recv_len, *offset, sizeof(float))) {
*ok = 0;
return 0.0f;
}
u_int32_t v_int;
memcpy(&v_int, buf + *offset, sizeof(v_int));
*offset += sizeof(v_int);
v_int = ntohl(v_int);
float v_float;
memcpy(&v_float, &v_int, sizeof(v_float));
return v_float;
if (!ensure(recv_len, *offset, sizeof(float))) {
*ok = 0;
return 0.0f;
}
u_int32_t v_int;
memcpy(&v_int, buf + *offset, sizeof(v_int));
*offset += sizeof(v_int);
v_int = ntohl(v_int);
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) {
@@ -138,4 +139,3 @@ void read_string(const u_int8_t *buf, size_t recv_len, size_t *offset, char *out
*ok = 1;
}
+2
View File
@@ -13,6 +13,8 @@ extern "C" {
#include <sys/types.h>
#include <unistd.h>
#include "server_structs.h"
// Ensures that there are at least 'need' bytes available in the buffer
// starting from 'offset'. Returns 1 if enough bytes are available, 0 otherwise.
int ensure(size_t recv_len, size_t offset, size_t need);
+80 -17
View File
@@ -1,12 +1,10 @@
#ifndef SERVER_STRUCTS_H
#define SERVER_STRUCTS_H
#include <cmath>
#include <cstdint>
#include <sys/cdefs.h>
#include <sys/types.h>
struct handshake {
typedef struct handshake {
// [not used in the current Remote Telemtry version by AC]
// In future versions it will identify the platform type of the client.
// This will be used to adjust a specific behaviour for each platform. (eIPadDevice for now (1))
@@ -31,9 +29,9 @@ struct handshake {
// DISMISS = 3 :
// This operation identifier must be set when the client wants to leave the comunication with ACServer.
int32_t operationId;
} __attribute__((packed));
} __attribute__((packed)) handshake;
struct handshackerResponse {
typedef struct handshackerResponse {
// is the name of the car that the player is driving on the AC Server
char carName[50];
@@ -52,23 +50,23 @@ struct handshackerResponse {
// is the track configuration on the AC Server
char trackConfig[50];
} __attribute__((packed));
} __attribute__((packed)) handshackerResponse;
struct postion {
typedef struct postion {
float x;
float y;
float z;
} __attribute__((packed));
} __attribute__((packed)) postion;
enum flag {
typedef enum flag {
NO_FLAG = 0,
YELLOW_FLAG = 1,
BLUE_FLAG = 2,
BLACK_FLAG = 3,
CHECKERED_FLAG = 4,
} __attribute__((packed));
} __attribute__((packed)) flag;
struct carAtributes {
typedef struct carAtributes {
// Related to ACSP_CAR_INFO
u_char isConnected; // 1 = connected, 0 = disconnected
u_char isLoading; // 1 = loading, 0 = not isLoading
@@ -96,16 +94,48 @@ struct carAtributes {
flag current_flag; // TODO: implement flag status updates
// TAG:3
float_t normalizedSplinePos;
} __attribute__((packed));
float normalizedSplinePos;
} __attribute__((packed)) carAtributes;
enum SessionType {
typedef struct carAtributesAPI {
// Related to ACSP_CAR_INFO
u_char isConnected; // 1 = connected, 0 = disconnected
u_char isLoading; // 1 = loading, 0 = not isLoading
char car_model[64];
char car_skin[64];
char driver_name[64];
char driver_team[64];
char driver_GUID[64];
// Related to ACSP_CAR_UPDATE
u_int8_t carID;
postion position;
postion velocity;
u_int8_t carGear;
u_int16_t carRPM;
u_int32_t lap_time;
u_int32_t cuts;
u_int32_t total_cuts;
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 normalizedSplinePos;
} __attribute__((packed)) carAtributesAPI;
typedef enum SessionType {
PRACTICE = 0,
RACE = 1,
QUALIFYING = 2,
};
} __attribute__((packed)) SessionType;
struct trackAtributes {
typedef struct trackAtributes {
u_int8_t protocol_version;
u_int8_t session_index;
@@ -127,7 +157,40 @@ struct trackAtributes {
char *weather_graphics;
u_int32_t elapsed_ms;
} __attribute__((packed));
} __attribute__((packed)) trackAtributes;
typedef struct trackAtributesAPI {
u_int8_t protocol_version;
u_int8_t session_index;
u_int8_t current_session_index;
u_int8_t session_count;
SessionType session_type;
char server_name[128];
char track[64];
char track_config[64];
char session_name[64];
u_int8_t typ;
u_int16_t time;
u_int16_t laps;
u_int16_t wait_time;
u_int8_t ambient_temp;
u_int8_t road_temp;
char weather_graphics[64];
u_int32_t elapsed_ms;
} __attribute__((packed)) trackAtributesAPI;
typedef struct api_packet {
u_int8_t tracker_id;
u_int8_t last_updated_carid;
carAtributesAPI cars[64];
trackAtributesAPI track_info;
} __attribute__((packed)) api_packet;
enum ACSP_MessageType {
// ============================