271 lines
6.9 KiB
C

#ifndef SERVER_STRUCTS_H
#define SERVER_STRUCTS_H
#include <sys/cdefs.h>
#include <sys/types.h>
#define MAX_PLAYERS 64
const int MAX_TELEMETRY_CLIENTS = 128;
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))
int32_t identifier;
// [not used in the current Remote Telemtry version by AC]
// In future version this field will identify the AC Remote Telemetry version that the device expects to speak with.
int32_t version;
// This is the type of operation required by the client.
// The following operations are now available:
// ----------------------------------------------------------------
// HANDSHAKE = 0 :
// This operation identifier must be set when the client wants to start the comunication.
//
// SUBSCRIBE_UPDATE = 1 :
// This operation identifier must be set when the client wants to be updated from the specific ACServer.
//
// SUBSCRIBE_SPOT = 2 :
// This operation identifier must be set when the client wants to be updated from the specific ACServer just for SPOT Events (e.g.: the end of a lap).
//
// DISMISS = 3 :
// This operation identifier must be set when the client wants to leave the comunication with ACServer.
int32_t operationId;
} __attribute__((packed)) handshake;
typedef struct handshackerResponse {
// is the name of the car that the player is driving on the AC Server
char carName[50];
// is the name of the driver running on the AC Server
char driverName[50];
// for now is just 4242, this code will identify different status,
// as “NOT AVAILABLE” for connection
int32_t identifier;
// for now is set to 1, this will identify the version running on the AC Server
int32_t version;
// is the name of the track on the AC Server
char trackName[50];
// is the track configuration on the AC Server
char trackConfig[50];
} __attribute__((packed)) handshackerResponse;
typedef struct postion {
float x;
float y;
float z;
} __attribute__((packed)) postion;
typedef enum flag {
NO_FLAG = 0,
YELLOW_FLAG = 1,
BLUE_FLAG = 2,
BLACK_FLAG = 3,
CHECKERED_FLAG = 4,
} __attribute__((packed)) flag;
typedef struct carAtributes {
// Related to ACSP_CAR_INFO
u_char isConnected; // 1 = connected, 0 = disconnected
u_char isLoading; // 1 = loading, 0 = not isLoading
char *car_model;
char *car_skin;
char *driver_name;
char *driver_team;
char *driver_GUID;
// 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)) carAtributes;
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;
typedef struct trackAtributes {
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;
char *track;
char *track_config;
char *session_name;
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;
u_int32_t elapsed_ms;
} __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_char message_type; // ACSP_MessageType
u_int8_t tracker_id;
u_int8_t connected_players;
u_int8_t cars_colided[2]; // IDs of cars involved in a collision event IF [1] == 255, [0] is the only car involved (environment collision)
carAtributesAPI cars[64];
trackAtributesAPI track_info;
} __attribute__((packed)) api_packet;
// Telemetry packet structure (lightweight for streaming)
struct telemetry_packet {
u_int8_t server_id;
u_int8_t car_count;
struct car_telemetry {
u_int8_t carID;
char driver_name[64];
char driver_guid[64];
char car_model[64];
postion position;
float normalizedSplinePos;
float speed_kmh;
u_int8_t gear;
u_int16_t rpm;
u_int32_t last_lap_time;
u_int32_t best_lap_time;
u_int16_t current_lap;
u_int8_t position_rank; // RENAME: position -> position_rank to avoid conflict
} __attribute__((packed)) cars[64];
} __attribute__((packed));
enum ACSP_MessageType {
// ============================
// PROTOCOL VERSION
// ============================
PROTOCOL_VERSION = 4,
// ============================
// SERVER → CLIENT MESSAGES
// ============================
ACSP_NEW_SESSION = 50,
ACSP_NEW_CONNECTION = 51,
ACSP_CONNECTION_CLOSED = 52,
ACSP_CAR_UPDATE = 53,
ACSP_CAR_INFO = 54, // Response to ACSP_GET_CAR_INFO
ACSP_END_SESSION = 55,
ACSP_VERSION = 56,
ACSP_CHAT = 57,
ACSP_CLIENT_LOADED = 58,
ACSP_SESSION_INFO = 59,
ACSP_ERROR = 60,
ACSP_LAP_COMPLETED = 73,
// ============================
// EVENTS
// ============================
ACSP_CLIENT_EVENT = 130,
// ============================
// EVENT TYPES
// ============================
ACSP_CE_COLLISION_WITH_CAR = 10,
ACSP_CE_COLLISION_WITH_ENV = 11,
// ============================
// CLIENT → SERVER COMMANDS
// ============================
ACSP_REALTIMEPOS_INTERVAL = 200,
ACSP_GET_CAR_INFO = 201,
ACSP_SEND_CHAT = 202, // Sends chat to one car
ACSP_BROADCAST_CHAT = 203, // Sends chat to everybody
ACSP_GET_SESSION_INFO = 204,
ACSP_SET_SESSION_INFO = 205,
ACSP_KICK_USER = 206,
ACSP_NEXT_SESSION = 207,
ACSP_RESTART_SESSION = 208,
ACSP_ADMIN_COMMAND = 209 // Send message plus a string
};
#endif // SERVER_STRUCTS_H