generated from AfonsoCMSousa/CPP-Template
Compare commits
No commits in common. "master" and "v1.0" have entirely different histories.
Binary file not shown.
BIN
PlayerTracker
BIN
PlayerTracker
Binary file not shown.
14
build.sh
14
build.sh
@ -18,20 +18,6 @@ if [ $? -ne 0 ]; then
|
|||||||
echo "Error: Build failed"
|
echo "Error: Build failed"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cp ./bin/$1 ../
|
cp ./bin/$1 ../
|
||||||
cd ..
|
|
||||||
|
|
||||||
echo ">>> Copying PlayerTracker to AC Servers <<<"
|
|
||||||
for server in ../servers/*; do
|
|
||||||
if [ -d "$server/utils" ]; then
|
|
||||||
target="$server/utils/ACPlayer_tracker"
|
|
||||||
mkdir -p "$target"
|
|
||||||
cp ./PlayerTracker "$target/"
|
|
||||||
echo "Installed PlayerTracker to: $target"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
echo ">>> Build Complete <<<"
|
echo ">>> Build Complete <<<"
|
||||||
echo ">>> Executable: $1 <<<"
|
echo ">>> Executable: $1 <<<"
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
#include "parcer.h"
|
#include "parcer.h"
|
||||||
#include "server_structs.h"
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
int ensure(size_t recv_len, size_t offset, size_t need) {
|
int ensure(size_t recv_len, size_t offset, size_t need) {
|
||||||
@ -40,28 +39,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) {
|
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))) {
|
if (!ensure(recv_len, *offset, sizeof(int32_t))) {
|
||||||
*ok = 0;
|
*ok = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int32_t v;
|
int32_t v;
|
||||||
memcpy(&v, buf + *offset, sizeof(v));
|
memcpy(&v, buf + *offset, sizeof(v));
|
||||||
*offset += sizeof(v);
|
*offset += sizeof(v);
|
||||||
return (int32_t)ntohl(v);
|
return (int32_t)ntohl(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
float read_float(const u_int8_t *buf, size_t recv_len, size_t *offset, 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 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
u_int32_t v_int;
|
u_int32_t v_int;
|
||||||
memcpy(&v_int, buf + *offset, sizeof(v_int));
|
memcpy(&v_int, buf + *offset, sizeof(v_int));
|
||||||
*offset += sizeof(v_int);
|
*offset += sizeof(v_int);
|
||||||
v_int = ntohl(v_int);
|
v_int = ntohl(v_int);
|
||||||
float v_float;
|
float v_float;
|
||||||
memcpy(&v_float, &v_int, sizeof(v_float));
|
memcpy(&v_float, &v_int, sizeof(v_float));
|
||||||
return 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) {
|
||||||
@ -139,3 +138,4 @@ void read_string(const u_int8_t *buf, size_t recv_len, size_t *offset, char *out
|
|||||||
*ok = 1;
|
*ok = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -13,8 +13,6 @@ extern "C" {
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "server_structs.h"
|
|
||||||
|
|
||||||
// Ensures that there are at least 'need' bytes available in the buffer
|
// Ensures that there are at least 'need' bytes available in the buffer
|
||||||
// starting from 'offset'. Returns 1 if enough bytes are available, 0 otherwise.
|
// starting from 'offset'. Returns 1 if enough bytes are available, 0 otherwise.
|
||||||
int ensure(size_t recv_len, size_t offset, size_t need);
|
int ensure(size_t recv_len, size_t offset, size_t need);
|
||||||
|
|||||||
@ -1,13 +1,12 @@
|
|||||||
#ifndef SERVER_STRUCTS_H
|
#ifndef SERVER_STRUCTS_H
|
||||||
#define SERVER_STRUCTS_H
|
#define SERVER_STRUCTS_H
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstdint>
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#define MAX_PLAYERS 64
|
struct handshake {
|
||||||
const int MAX_TELEMETRY_CLIENTS = 128;
|
|
||||||
|
|
||||||
typedef struct handshake {
|
|
||||||
// [not used in the current Remote Telemtry version by AC]
|
// [not used in the current Remote Telemtry version by AC]
|
||||||
// In future versions it will identify the platform type of the client.
|
// 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))
|
// This will be used to adjust a specific behaviour for each platform. (eIPadDevice for now (1))
|
||||||
@ -32,9 +31,9 @@ typedef struct handshake {
|
|||||||
// DISMISS = 3 :
|
// DISMISS = 3 :
|
||||||
// This operation identifier must be set when the client wants to leave the comunication with ACServer.
|
// This operation identifier must be set when the client wants to leave the comunication with ACServer.
|
||||||
int32_t operationId;
|
int32_t operationId;
|
||||||
} __attribute__((packed)) handshake;
|
} __attribute__((packed));
|
||||||
|
|
||||||
typedef struct handshackerResponse {
|
struct handshackerResponse {
|
||||||
// is the name of the car that the player is driving on the AC Server
|
// is the name of the car that the player is driving on the AC Server
|
||||||
char carName[50];
|
char carName[50];
|
||||||
|
|
||||||
@ -53,26 +52,26 @@ typedef struct handshackerResponse {
|
|||||||
|
|
||||||
// is the track configuration on the AC Server
|
// is the track configuration on the AC Server
|
||||||
char trackConfig[50];
|
char trackConfig[50];
|
||||||
} __attribute__((packed)) handshackerResponse;
|
} __attribute__((packed));
|
||||||
|
|
||||||
typedef struct postion {
|
struct postion {
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
float z;
|
float z;
|
||||||
} __attribute__((packed)) postion;
|
} __attribute__((packed));
|
||||||
|
|
||||||
typedef enum flag {
|
enum flag {
|
||||||
NO_FLAG = 0,
|
NO_FLAG = 0,
|
||||||
YELLOW_FLAG = 1,
|
YELLOW_FLAG = 1,
|
||||||
BLUE_FLAG = 2,
|
BLUE_FLAG = 2,
|
||||||
BLACK_FLAG = 3,
|
BLACK_FLAG = 3,
|
||||||
CHECKERED_FLAG = 4,
|
CHECKERED_FLAG = 4,
|
||||||
} __attribute__((packed)) flag;
|
} __attribute__((packed));
|
||||||
|
|
||||||
typedef 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 isLoading
|
u_char isLoading; // 1 = loading, 0 = not isLoading
|
||||||
|
|
||||||
char *car_model;
|
char *car_model;
|
||||||
char *car_skin;
|
char *car_skin;
|
||||||
@ -86,58 +85,27 @@ typedef struct carAtributes {
|
|||||||
postion velocity;
|
postion velocity;
|
||||||
u_int8_t carGear;
|
u_int8_t carGear;
|
||||||
u_int16_t carRPM;
|
u_int16_t carRPM;
|
||||||
u_int32_t lap_time;
|
u_int32_t lap_time;
|
||||||
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 total_laps_completed;
|
||||||
u_int16_t contacts;
|
u_int16_t contacts;
|
||||||
u_int16_t total_contacts;
|
u_int16_t total_contacts;
|
||||||
|
|
||||||
flag current_flag; // TODO: implement flag status updates
|
flag current_flag; // TODO: implement flag status updates
|
||||||
// TAG:3
|
// TAG:3
|
||||||
|
|
||||||
float normalizedSplinePos;
|
float_t normalizedSplinePos;
|
||||||
} __attribute__((packed)) carAtributes;
|
} __attribute__((packed));
|
||||||
|
|
||||||
typedef struct carAtributesAPI {
|
enum SessionType {
|
||||||
// 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,
|
PRACTICE = 0,
|
||||||
RACE = 1,
|
RACE = 1,
|
||||||
QUALIFYING = 2,
|
QUALIFYING = 2,
|
||||||
} __attribute__((packed)) SessionType;
|
};
|
||||||
|
|
||||||
typedef struct trackAtributes {
|
struct trackAtributes {
|
||||||
u_int8_t protocol_version;
|
u_int8_t protocol_version;
|
||||||
|
|
||||||
u_int8_t session_index;
|
u_int8_t session_index;
|
||||||
@ -159,64 +127,6 @@ typedef struct trackAtributes {
|
|||||||
|
|
||||||
char *weather_graphics;
|
char *weather_graphics;
|
||||||
u_int32_t elapsed_ms;
|
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));
|
} __attribute__((packed));
|
||||||
|
|
||||||
enum ACSP_MessageType {
|
enum ACSP_MessageType {
|
||||||
|
|||||||
313
source/main.cpp
313
source/main.cpp
@ -1,162 +1,26 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <exception>
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <pthread.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/un.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "parcer.h"
|
#include "parcer.h"
|
||||||
#include "server_structs.h"
|
#include "server_structs.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
|
||||||
#define DEBUG_CAR_INFO 1
|
#define DEBUG_CAR_INFO 0
|
||||||
|
|
||||||
const char *API_SOCKET_PATH = "/tmp/ACplayer_socket";
|
|
||||||
|
|
||||||
|
const int SERVER_OUT_PORT = 12000;
|
||||||
|
const int SERVER_IN_PORT = 11000;
|
||||||
const char *SERVER_OUT_IP = "127.0.0.1";
|
const char *SERVER_OUT_IP = "127.0.0.1";
|
||||||
|
|
||||||
u_int8_t SERVER_ID;
|
const int MAX_PLAYERS = 64;
|
||||||
api_packet current_packet;
|
|
||||||
u_int8_t apiSent = 0;
|
|
||||||
|
|
||||||
// INFO: This assumes Players pointer to be the same size of MAX_PLAYERS
|
|
||||||
void update_api_packet(trackAtributes trackInfo, carAtributes *players) {
|
|
||||||
current_packet.tracker_id = SERVER_ID;
|
|
||||||
|
|
||||||
// Update track info
|
|
||||||
current_packet.track_info.protocol_version = trackInfo.protocol_version;
|
|
||||||
current_packet.track_info.session_index = trackInfo.session_index;
|
|
||||||
current_packet.track_info.current_session_index = trackInfo.current_session_index;
|
|
||||||
current_packet.track_info.session_count = trackInfo.session_count;
|
|
||||||
current_packet.track_info.session_type = trackInfo.session_type;
|
|
||||||
strncpy(current_packet.track_info.server_name, trackInfo.server_name, sizeof(current_packet.track_info.server_name) - 1);
|
|
||||||
strncpy(current_packet.track_info.track, trackInfo.track, sizeof(current_packet.track_info.track) - 1);
|
|
||||||
strncpy(current_packet.track_info.track_config, trackInfo.track_config, sizeof(current_packet.track_info.track_config) - 1);
|
|
||||||
strncpy(current_packet.track_info.session_name, trackInfo.session_name, sizeof(current_packet.track_info.session_name) - 1);
|
|
||||||
current_packet.track_info.typ = trackInfo.typ;
|
|
||||||
current_packet.track_info.time = trackInfo.time;
|
|
||||||
current_packet.track_info.laps = trackInfo.laps;
|
|
||||||
current_packet.track_info.wait_time = trackInfo.wait_time;
|
|
||||||
current_packet.track_info.ambient_temp = trackInfo.ambient_temp;
|
|
||||||
current_packet.track_info.road_temp = trackInfo.road_temp;
|
|
||||||
strncpy(current_packet.track_info.weather_graphics, trackInfo.weather_graphics, sizeof(current_packet.track_info.weather_graphics) - 1);
|
|
||||||
current_packet.track_info.elapsed_ms = trackInfo.elapsed_ms;
|
|
||||||
|
|
||||||
// Update car INFO
|
|
||||||
for (int i = 0; i < MAX_PLAYERS; i++) {
|
|
||||||
current_packet.cars[i].isConnected = players[i].isConnected;
|
|
||||||
current_packet.cars[i].isLoading = players[i].isLoading;
|
|
||||||
|
|
||||||
strncpy(current_packet.cars[i].car_model, players[i].car_model, sizeof(current_packet.cars[i].car_model) - 1);
|
|
||||||
strncpy(current_packet.cars[i].driver_GUID, players[i].driver_GUID, sizeof(current_packet.cars[i].driver_GUID) - 1);
|
|
||||||
strncpy(current_packet.cars[i].car_skin, players[i].car_skin, sizeof(current_packet.cars[i].car_skin) - 1);
|
|
||||||
strncpy(current_packet.cars[i].driver_name, players[i].driver_name, sizeof(current_packet.cars[i].driver_name) - 1);
|
|
||||||
strncpy(current_packet.cars[i].driver_team, players[i].driver_team, sizeof(current_packet.cars[i].driver_team) - 1);
|
|
||||||
|
|
||||||
current_packet.cars[i].carID = players[i].carID;
|
|
||||||
|
|
||||||
current_packet.cars[i].position = players[i].position;
|
|
||||||
current_packet.cars[i].velocity = players[i].velocity;
|
|
||||||
|
|
||||||
current_packet.cars[i].carGear = players[i].carGear;
|
|
||||||
current_packet.cars[i].carRPM = players[i].carRPM;
|
|
||||||
current_packet.cars[i].lap_time = players[i].lap_time;
|
|
||||||
current_packet.cars[i].cuts = players[i].cuts;
|
|
||||||
current_packet.cars[i].total_cuts = players[i].total_cuts;
|
|
||||||
current_packet.cars[i].total_cuts_alltime = players[i].total_cuts_alltime;
|
|
||||||
|
|
||||||
current_packet.cars[i].total_laps_completed = players[i].total_laps_completed;
|
|
||||||
current_packet.cars[i].contacts = players[i].contacts;
|
|
||||||
current_packet.cars[i].total_contacts = players[i].total_contacts;
|
|
||||||
|
|
||||||
current_packet.cars[i].normalizedSplinePos = players[i].normalizedSplinePos;
|
|
||||||
}
|
|
||||||
|
|
||||||
apiSent = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *send_to_api_socket(void *arg) {
|
|
||||||
int sock_fd;
|
|
||||||
struct sockaddr_un addr;
|
|
||||||
|
|
||||||
addr.sun_family = AF_UNIX;
|
|
||||||
strcpy(addr.sun_path, API_SOCKET_PATH);
|
|
||||||
|
|
||||||
// --- Connect loop ---
|
|
||||||
while (1) {
|
|
||||||
sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
||||||
if (sock_fd < 0) {
|
|
||||||
usleep(500000);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connect(sock_fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
|
||||||
close(sock_fd);
|
|
||||||
usleep(500000);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
break; // connected
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("[+] Connected to API socket at %s\n", API_SOCKET_PATH);
|
|
||||||
|
|
||||||
// Handshake
|
|
||||||
api_packet handshake;
|
|
||||||
|
|
||||||
handshake.tracker_id = 65;
|
|
||||||
send(sock_fd, &handshake, sizeof(api_packet), MSG_NOSIGNAL);
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
if (current_packet.tracker_id == (u_int8_t)-1) {
|
|
||||||
usleep(10000);
|
|
||||||
apiSent = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (apiSent) {
|
|
||||||
usleep(10000);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ssize_t sent_bytes = send(sock_fd, ¤t_packet, sizeof(api_packet), MSG_NOSIGNAL);
|
|
||||||
if (sent_bytes < 0) {
|
|
||||||
fprintf(stderr, "[!] Failed to send data to API socket, reconnecting...\n");
|
|
||||||
close(sock_fd);
|
|
||||||
|
|
||||||
// Reconnect loop
|
|
||||||
while (1) {
|
|
||||||
sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
||||||
if (sock_fd < 0) {
|
|
||||||
usleep(500000);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connect(sock_fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
|
||||||
close(sock_fd);
|
|
||||||
usleep(500000);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
break; // connected
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("[+] Reconnected to API socket at %s\n", API_SOCKET_PATH);
|
|
||||||
}
|
|
||||||
|
|
||||||
apiSent = 1;
|
|
||||||
|
|
||||||
usleep(10000); // 10ms
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void init_carupdate(carAtributes *car) {
|
void init_carupdate(carAtributes *car) {
|
||||||
car->isConnected = 0;
|
car->isConnected = 0;
|
||||||
@ -193,32 +57,18 @@ void init_carupdate(carAtributes *car) {
|
|||||||
|
|
||||||
car->total_laps_completed = 0;
|
car->total_laps_completed = 0;
|
||||||
car->contacts = 0;
|
car->contacts = 0;
|
||||||
car->total_contacts = 0; // TODO: SQL querry to get total contacts of all time; TAG:2
|
car->total_contacts = 0; // TODO: SQL querry to get total contacts of all time; TAG:2
|
||||||
|
|
||||||
car->normalizedSplinePos = 0.0f;
|
car->normalizedSplinePos = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(void) {
|
||||||
|
|
||||||
// Parse command-line arguments
|
|
||||||
if (argc != 4) {
|
|
||||||
fprintf(stderr, "Usage: %s <server_id> <in_port> <out_port>\n", argv[0]);
|
|
||||||
fprintf(stderr, "Example: %s 131 11001 12001\n", argv[0]);
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
SERVER_ID = (u_int8_t)atoi(argv[1]);
|
|
||||||
u_int16_t SERVER_IN_PORT = (u_int16_t)atoi(argv[2]);
|
|
||||||
u_int16_t SERVER_OUT_PORT = (u_int16_t)atoi(argv[3]);
|
|
||||||
|
|
||||||
printf("[+] Starting server...\n");
|
printf("[+] Starting server...\n");
|
||||||
printf("[+] Server listening on port %d\n", SERVER_IN_PORT);
|
printf("[+] Server listening on port %d\n", SERVER_IN_PORT);
|
||||||
printf("[+] Server sending to %s:%d\n\n", SERVER_OUT_IP, SERVER_OUT_PORT);
|
printf("[+] Server sending to %s:%d\n\n", SERVER_OUT_IP, SERVER_OUT_PORT);
|
||||||
|
|
||||||
current_packet.tracker_id = (u_int8_t)-1; // Mark as uninitialized
|
int send_sock_fd = connect_udp_socket("127.0.0.1", 11000); // SEND requests to Server
|
||||||
|
int recv_sock_fd = create_bound_udp_socket("0.0.0.0", 12000); // LISTEN to server updates
|
||||||
int send_sock_fd = connect_udp_socket(SERVER_OUT_IP, SERVER_IN_PORT); // SEND requests to Server
|
|
||||||
int recv_sock_fd = create_bound_udp_socket("0.0.0.0", SERVER_OUT_PORT); // LISTEN to server updates
|
|
||||||
|
|
||||||
if (send_sock_fd < 0 || recv_sock_fd < 0) {
|
if (send_sock_fd < 0 || recv_sock_fd < 0) {
|
||||||
fprintf(stderr, "[!] Failed to create sockets (%d)(%d)\n", send_sock_fd, recv_sock_fd);
|
fprintf(stderr, "[!] Failed to create sockets (%d)(%d)\n", send_sock_fd, recv_sock_fd);
|
||||||
@ -229,26 +79,15 @@ int main(int argc, char *argv[]) {
|
|||||||
int ok = 1;
|
int ok = 1;
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
|
|
||||||
// Start thread to send data to API socket
|
|
||||||
pthread_t api_thread;
|
|
||||||
if (pthread_create(&api_thread, NULL, send_to_api_socket, NULL) != 0) {
|
|
||||||
fprintf(stderr, "[!] Failed to create API socket thread\n");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_detach(api_thread);
|
|
||||||
|
|
||||||
trackAtributes trackInfo;
|
trackAtributes trackInfo;
|
||||||
carAtributes players[MAX_PLAYERS];
|
carAtributes players[MAX_PLAYERS];
|
||||||
|
|
||||||
current_packet.connected_players = 0;
|
|
||||||
carAtributes update;
|
carAtributes update;
|
||||||
|
|
||||||
// Basically a contrutor for carAtributes (because all strings in carAtributes are pointers)
|
// Basically a contrutor for carAtributes (because all strings in carAtributes are pointers)
|
||||||
for (int i = 0; i < MAX_PLAYERS; i++) {
|
for (int i = 0; i < MAX_PLAYERS; i++) {
|
||||||
init_carupdate(&players[i]);
|
init_carupdate(&players[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
init_carupdate(&update);
|
init_carupdate(&update);
|
||||||
|
|
||||||
trackInfo.server_name = (char *)malloc(128);
|
trackInfo.server_name = (char *)malloc(128);
|
||||||
@ -258,12 +97,7 @@ int main(int argc, char *argv[]) {
|
|||||||
trackInfo.session_name = (char *)malloc(64);
|
trackInfo.session_name = (char *)malloc(64);
|
||||||
|
|
||||||
char message[124] = {0}; // just a place to put info messages from the server itself
|
char message[124] = {0}; // just a place to put info messages from the server itself
|
||||||
u_char update_rate_message[2] = {0};
|
|
||||||
|
|
||||||
// EXPERIMENTAL: Send a message to the server to increase update rate - USING ACSP_REALTIMEPOS_INTERVAL
|
|
||||||
update_rate_message[0] = (u_char)ACSP_REALTIMEPOS_INTERVAL;
|
|
||||||
update_rate_message[1] = 255; // ms
|
|
||||||
u_char updateSent = 0;
|
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -272,22 +106,15 @@ int main(int argc, char *argv[]) {
|
|||||||
memset(buffer, 0, sizeof(buffer));
|
memset(buffer, 0, sizeof(buffer));
|
||||||
|
|
||||||
// FIX: Its not garanted to receive a full packet in one recvfrom call, but the error -1 is not handled by a unsigned size_t
|
// FIX: Its not garanted to receive a full packet in one recvfrom call, but the error -1 is not handled by a unsigned size_t
|
||||||
size_t recv_bytes = (size_t)recvfrom(recv_sock_fd, buffer, sizeof(buffer), 0, NULL, NULL);
|
size_t recv_bytes = (size_t)recvfrom(recv_sock_fd, buffer, sizeof(buffer), 0, NULL, NULL);
|
||||||
|
|
||||||
// Send update rate message to server ONCE
|
|
||||||
if (updateSent != 1) {
|
|
||||||
sendto(send_sock_fd, update_rate_message, sizeof(update_rate_message), 0, NULL, 0);
|
|
||||||
updateSent = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert buffer to utf-8 string and print it
|
// Convert buffer to utf-8 string and print it
|
||||||
#if DEBUG_CAR_INFO
|
#if DEBUG_CAR_INFO
|
||||||
printf("[+] Received %zd bytes from client\n", recv_bytes);
|
printf("[+] Received %zd bytes from client\n", recv_bytes);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
current_packet.message_type = (u_char)buffer[0];
|
|
||||||
// The first byte of the messages is always an ACSP_MessageType
|
// The first byte of the messages is always an ACSP_MessageType
|
||||||
switch ((u_char)buffer[0]) {
|
switch ((int)buffer[0]) {
|
||||||
// ============================
|
// ============================
|
||||||
// SERVER → CLIENT MESSAGES
|
// SERVER → CLIENT MESSAGES
|
||||||
// ============================
|
// ============================
|
||||||
@ -351,7 +178,6 @@ int main(int argc, char *argv[]) {
|
|||||||
printf("\tElapsed Time: %d ms (%2d:%2d:%2d)\n\n", trackInfo.elapsed_ms, trackInfo.elapsed_ms / 60000, (trackInfo.elapsed_ms % 60000) / 1000,
|
printf("\tElapsed Time: %d ms (%2d:%2d:%2d)\n\n", trackInfo.elapsed_ms, trackInfo.elapsed_ms / 60000, (trackInfo.elapsed_ms % 60000) / 1000,
|
||||||
(trackInfo.elapsed_ms % 60000) % 1000);
|
(trackInfo.elapsed_ms % 60000) % 1000);
|
||||||
|
|
||||||
update_api_packet(trackInfo, players);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACSP_NEW_CONNECTION: // DONE:
|
case ACSP_NEW_CONNECTION: // DONE:
|
||||||
@ -378,8 +204,7 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update.isConnected = 1; // Mark as connected
|
update.isConnected = 1; // Mark as connected
|
||||||
update.isLoading = 1; // Mark as Loading
|
update.isLoading = 1; // Mark as loading
|
||||||
current_packet.connected_players++;
|
|
||||||
|
|
||||||
printf("\tDriver Name: \"%s\"\n", update.driver_name);
|
printf("\tDriver Name: \"%s\"\n", update.driver_name);
|
||||||
printf("\tDriver GUID: \"%s\"\n", update.driver_GUID);
|
printf("\tDriver GUID: \"%s\"\n", update.driver_GUID);
|
||||||
@ -389,23 +214,9 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
// Store player player into the respective Index
|
// Store player player into the respective Index
|
||||||
if (update.carID < MAX_PLAYERS) {
|
if (update.carID < MAX_PLAYERS) {
|
||||||
players[update.carID].isConnected = update.isConnected;
|
memcpy(&players[update.carID], &update, sizeof(carAtributes));
|
||||||
players[update.carID].isLoading = update.isLoading;
|
|
||||||
players[update.carID].carID = update.carID;
|
|
||||||
|
|
||||||
strncpy(players[update.carID].driver_GUID, update.driver_GUID, 63);
|
|
||||||
strncpy(players[update.carID].driver_name, update.driver_name, 63);
|
|
||||||
strncpy(players[update.carID].driver_team, update.driver_team, 63);
|
|
||||||
strncpy(players[update.carID].car_model, update.car_model, 63);
|
|
||||||
strncpy(players[update.carID].car_skin, update.car_skin, 63);
|
|
||||||
|
|
||||||
players[update.carID].driver_GUID[63] = '\0';
|
|
||||||
players[update.carID].driver_name[63] = '\0';
|
|
||||||
players[update.carID].driver_team[63] = '\0';
|
|
||||||
players[update.carID].car_model[63] = '\0';
|
|
||||||
players[update.carID].car_skin[63] = '\0';
|
|
||||||
}
|
}
|
||||||
update_api_packet(trackInfo, players);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACSP_CONNECTION_CLOSED: // DONE:
|
case ACSP_CONNECTION_CLOSED: // DONE:
|
||||||
@ -432,10 +243,6 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update.isConnected = 0; // Mark as disconnected
|
update.isConnected = 0; // Mark as disconnected
|
||||||
current_packet.connected_players--;
|
|
||||||
if (current_packet.connected_players > MAX_PLAYERS) {
|
|
||||||
current_packet.connected_players = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("\tDriver Name: \"%s\"\n", update.driver_name);
|
printf("\tDriver Name: \"%s\"\n", update.driver_name);
|
||||||
printf("\tDriver GUID: \"%s\"\n", update.driver_GUID);
|
printf("\tDriver GUID: \"%s\"\n", update.driver_GUID);
|
||||||
@ -445,10 +252,9 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
// Store player player into the respective Index
|
// Store player player into the respective Index
|
||||||
if (update.carID < MAX_PLAYERS) {
|
if (update.carID < MAX_PLAYERS) {
|
||||||
players[update.carID].isConnected = 0; // Mark disconnected
|
memcpy(&players[update.carID], &update, sizeof(carAtributes));
|
||||||
players[update.carID].isLoading = 0;
|
|
||||||
}
|
}
|
||||||
update_api_packet(trackInfo, players);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACSP_CAR_UPDATE: // DONE:
|
case ACSP_CAR_UPDATE: // DONE:
|
||||||
@ -457,7 +263,7 @@ int main(int argc, char *argv[]) {
|
|||||||
#endif
|
#endif
|
||||||
offset = 1;
|
offset = 1;
|
||||||
|
|
||||||
memcpy(&update.carID, buffer + offset, sizeof(uint8_t));
|
memcpy(&update.carID, buffer, sizeof(uint8_t));
|
||||||
offset = 1 + sizeof(uint8_t);
|
offset = 1 + sizeof(uint8_t);
|
||||||
memcpy(&update.position, buffer + offset, sizeof(postion));
|
memcpy(&update.position, buffer + offset, sizeof(postion));
|
||||||
offset += sizeof(postion);
|
offset += sizeof(postion);
|
||||||
@ -475,20 +281,15 @@ int main(int argc, char *argv[]) {
|
|||||||
printf("Gear: %d RPM: %d\n", update.carGear, update.carRPM);
|
printf("Gear: %d RPM: %d\n", update.carGear, update.carRPM);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Store player player into the respective Index
|
// Store player player into the respective index
|
||||||
if (update.carID < MAX_PLAYERS) {
|
if (update.carID < MAX_PLAYERS) {
|
||||||
players[update.carID].position = update.position;
|
memcpy(&players[update.carID].position, &update.position, sizeof(postion));
|
||||||
players[update.carID].velocity = update.velocity;
|
memcpy(&players[update.carID].velocity, &update.velocity, sizeof(postion));
|
||||||
players[update.carID].carGear = update.carGear;
|
players[update.carID].carGear = update.carGear;
|
||||||
players[update.carID].carRPM = update.carRPM;
|
players[update.carID].carRPM = update.carRPM;
|
||||||
players[update.carID].normalizedSplinePos = update.normalizedSplinePos;
|
players[update.carID].normalizedSplinePos = update.normalizedSplinePos;
|
||||||
|
|
||||||
players[update.carID].isConnected = update.isConnected;
|
|
||||||
players[update.carID].isLoading = update.isLoading;
|
|
||||||
players[update.carID].carID = update.carID;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
update_api_packet(trackInfo, players);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACSP_CAR_INFO: // DONE:
|
case ACSP_CAR_INFO: // DONE:
|
||||||
@ -523,25 +324,9 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
// Store player player into the respective Index
|
// Store player player into the respective Index
|
||||||
if (update.carID < MAX_PLAYERS) {
|
if (update.carID < MAX_PLAYERS) {
|
||||||
|
memcpy(&players[update.carID], &update, sizeof(carAtributes));
|
||||||
players[update.carID].isConnected = update.isConnected;
|
|
||||||
players[update.carID].isLoading = update.isLoading;
|
|
||||||
players[update.carID].carID = update.carID;
|
|
||||||
|
|
||||||
strncpy(players[update.carID].driver_GUID, update.driver_GUID, 63);
|
|
||||||
strncpy(players[update.carID].driver_name, update.driver_name, 63);
|
|
||||||
strncpy(players[update.carID].driver_team, update.driver_team, 63);
|
|
||||||
strncpy(players[update.carID].car_model, update.car_model, 63);
|
|
||||||
strncpy(players[update.carID].car_skin, update.car_skin, 63);
|
|
||||||
|
|
||||||
players[update.carID].driver_GUID[63] = '\0';
|
|
||||||
players[update.carID].driver_name[63] = '\0';
|
|
||||||
players[update.carID].driver_team[63] = '\0';
|
|
||||||
players[update.carID].car_model[63] = '\0';
|
|
||||||
players[update.carID].car_skin[63] = '\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
update_api_packet(trackInfo, players);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACSP_END_SESSION: // DONE: (only session type cycling)
|
case ACSP_END_SESSION: // DONE: (only session type cycling)
|
||||||
@ -561,7 +346,6 @@ int main(int argc, char *argv[]) {
|
|||||||
printf("\tNext Session Name: %s\n", trackInfo.session_name);
|
printf("\tNext Session Name: %s\n", trackInfo.session_name);
|
||||||
printf("\tNext Session Type: %d\n\n", trackInfo.session_type);
|
printf("\tNext Session Type: %d\n\n", trackInfo.session_type);
|
||||||
|
|
||||||
update_api_packet(trackInfo, players);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACSP_VERSION: // DONE:
|
case ACSP_VERSION: // DONE:
|
||||||
@ -571,7 +355,6 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
printf("\tProtocol Version: %d\n\n", trackInfo.protocol_version);
|
printf("\tProtocol Version: %d\n\n", trackInfo.protocol_version);
|
||||||
|
|
||||||
update_api_packet(trackInfo, players);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACSP_CHAT: // DONE: Receive chat messages
|
case ACSP_CHAT: // DONE: Receive chat messages
|
||||||
@ -586,7 +369,6 @@ int main(int argc, char *argv[]) {
|
|||||||
printf("\tCar ID: %d (%s)\n", update.carID, players[update.carID].driver_name);
|
printf("\tCar ID: %d (%s)\n", update.carID, players[update.carID].driver_name);
|
||||||
printf("\tMessage: \"%s\"\n\n", message);
|
printf("\tMessage: \"%s\"\n\n", message);
|
||||||
|
|
||||||
update_api_packet(trackInfo, players);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACSP_CLIENT_LOADED: // DONE: Check for client loaded status
|
case ACSP_CLIENT_LOADED: // DONE: Check for client loaded status
|
||||||
@ -598,7 +380,6 @@ int main(int argc, char *argv[]) {
|
|||||||
players[update.carID].isLoading = 0;
|
players[update.carID].isLoading = 0;
|
||||||
printf("\tCar ID: %d (%s) Finished Loading into the session\n\n", update.carID, players[update.carID].driver_name);
|
printf("\tCar ID: %d (%s) Finished Loading into the session\n\n", update.carID, players[update.carID].driver_name);
|
||||||
|
|
||||||
update_api_packet(trackInfo, players);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACSP_ERROR: // DONE: Simple error message from server
|
case ACSP_ERROR: // DONE: Simple error message from server
|
||||||
@ -618,24 +399,17 @@ int main(int argc, char *argv[]) {
|
|||||||
update.carID = read_uint8((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
update.carID = read_uint8((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
||||||
|
|
||||||
// TEST: Possiblity of lap_time not behing correct
|
// TEST: Possiblity of lap_time not behing correct
|
||||||
// TODO: Verify with actual serve
|
// TODO: Verify with actual server
|
||||||
// SOLUTION: Server sends all times, lap_times and lap counts in big-endian format
|
|
||||||
update.lap_time = read_uint32((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
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);
|
update.cuts = read_uint32((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
||||||
|
|
||||||
update.total_cuts = read_uint32((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
update.total_cuts = read_uint32((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
||||||
|
|
||||||
current_packet.message_type = ACSP_LAP_COMPLETED;
|
|
||||||
|
|
||||||
printf("\tCar ID: %d (%s)\n", update.carID, players[update.carID].driver_name);
|
printf("\tCar ID: %d (%s)\n", update.carID, players[update.carID].driver_name);
|
||||||
printf("\tLap Time: %5d ms\n", update.lap_time);
|
printf("\tLap Time: %5d ms\n", update.lap_time);
|
||||||
printf("\tCuts this lap: %d\n", update.cuts);
|
printf("\tCuts this lap: %d\n", update.cuts);
|
||||||
printf("\tTotal Cuts (this session): %d\n\n", update.total_cuts);
|
printf("\tTotal Cuts (this session): %d\n\n", update.total_cuts);
|
||||||
|
|
||||||
current_packet.cars_colided[0] = update.carID;
|
|
||||||
players[update.carID].total_laps_completed++;
|
|
||||||
|
|
||||||
update_api_packet(trackInfo, players);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// ============================
|
// ============================
|
||||||
@ -666,11 +440,6 @@ int main(int argc, char *argv[]) {
|
|||||||
// TODO: Update total contacts for both players in the database
|
// TODO: Update total contacts for both players in the database
|
||||||
// TAG:2 Update total contacts for both players
|
// TAG:2 Update total contacts for both players
|
||||||
|
|
||||||
current_packet.message_type = ACSP_CE_COLLISION_WITH_CAR;
|
|
||||||
current_packet.cars_colided[0] = update.carID;
|
|
||||||
current_packet.cars_colided[1] = event_car_id;
|
|
||||||
|
|
||||||
update_api_packet(trackInfo, players);
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case ACSP_CE_COLLISION_WITH_ENV: {
|
case ACSP_CE_COLLISION_WITH_ENV: {
|
||||||
@ -682,45 +451,22 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
// TODO: Update total contacts for the player in the database
|
// TODO: Update total contacts for the player in the database
|
||||||
// TAG:2 Update total contacts for the player
|
// TAG:2 Update total contacts for the player
|
||||||
|
|
||||||
current_packet.message_type = ACSP_CE_COLLISION_WITH_ENV;
|
|
||||||
current_packet.cars_colided[0] = update.carID;
|
|
||||||
|
|
||||||
update_api_packet(trackInfo, players);
|
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: possible iRacing style impact severity system
|
// 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)
|
// With X velues and (e.g >5 m/s = 0x, >10 m/s = 2x, >15 m/s = 4x) && Blackflag limits (e.g x17 = DQ)
|
||||||
|
|
||||||
// FIX: read_float doesnt work, but memcpy does... weird...
|
|
||||||
float impact_speed = read_float((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
float impact_speed = read_float((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
||||||
postion world_pos = {0, 0, 0};
|
postion world_pos = {0};
|
||||||
/* world_pos.x = read_float((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
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.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);
|
world_pos.z = read_float((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
||||||
*/
|
|
||||||
|
|
||||||
memcpy(&world_pos.x, buffer + offset, sizeof(float));
|
postion rel_pos = {0};
|
||||||
offset += sizeof(float);
|
|
||||||
memcpy(&world_pos.y, buffer + offset, sizeof(float));
|
|
||||||
offset += sizeof(float);
|
|
||||||
memcpy(&world_pos.z, buffer + offset, sizeof(float));
|
|
||||||
offset += sizeof(float);
|
|
||||||
|
|
||||||
postion rel_pos = {0, 0, 0};
|
|
||||||
/*
|
|
||||||
rel_pos.x = read_float((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
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.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);
|
rel_pos.z = read_float((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
|
||||||
*/
|
|
||||||
|
|
||||||
memcpy(&rel_pos.x, buffer + offset, sizeof(float));
|
|
||||||
offset += sizeof(float);
|
|
||||||
memcpy(&rel_pos.y, buffer + offset, sizeof(float));
|
|
||||||
offset += sizeof(float);
|
|
||||||
memcpy(&rel_pos.z, buffer + offset, sizeof(float));
|
|
||||||
offset += sizeof(float);
|
|
||||||
|
|
||||||
printf("\tImpact Speed: %.2f m/s\n", impact_speed);
|
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("\tWorld Position: X: %.2f Y: %.2f Z: %.2f\n", world_pos.x, world_pos.y, world_pos.z);
|
||||||
@ -733,7 +479,7 @@ int main(int argc, char *argv[]) {
|
|||||||
//
|
//
|
||||||
// ============================
|
// ============================
|
||||||
// CLIENT → SERVER COMMANDS
|
// CLIENT → SERVER COMMANDS
|
||||||
// NOTE: These are not meant to be here, these are comands to SEND to the server
|
// NOTE: These are not meant to be here, these are comands to SEND to the server
|
||||||
// ============================
|
// ============================
|
||||||
case ACSP_REALTIMEPOS_INTERVAL:
|
case ACSP_REALTIMEPOS_INTERVAL:
|
||||||
printf("[+] Command: ACSP_REALTIMEPOS_INTERVAL\n");
|
printf("[+] Command: ACSP_REALTIMEPOS_INTERVAL\n");
|
||||||
@ -771,19 +517,19 @@ int main(int argc, char *argv[]) {
|
|||||||
printf("[+] Command: ACSP_RESTART_SESSION\n");
|
printf("[+] Command: ACSP_RESTART_SESSION\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACSP_ADMIN_COMMAND: { // DONE:
|
case ACSP_ADMIN_COMMAND: { // DONE:
|
||||||
printf("[+] Command: ACSP_ADMIN_COMMAND\n");
|
printf("[+] Command: ACSP_ADMIN_COMMAND\n");
|
||||||
char *__buffer = (char *)malloc(256);
|
char *buffer = (char *)malloc(256);
|
||||||
char command[256] = "/settime 19:00"; // TEST:
|
char command[256] = "/settime 19:00"; // TEST:
|
||||||
|
|
||||||
__buffer[0] = (char)ACSP_ADMIN_COMMAND;
|
buffer[0] = (char)ACSP_ADMIN_COMMAND;
|
||||||
for (int i = 1; i <= strlen(command); i++) {
|
for (int i = 1; i <= strlen(command); i++) {
|
||||||
buffer[i] = command[i - 1];
|
buffer[i] = command[i - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
sendto(send_sock_fd, buffer, strlen(command) + 1, 0, NULL, 0);
|
sendto(send_sock_fd, buffer, strlen(command) + 1, 0, NULL, 0);
|
||||||
printf("\tSent Admin Command: %s\n\n", command);
|
printf("\tSent Admin Command: %s\n\n", command);
|
||||||
free(__buffer);
|
free(buffer);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
// ============================
|
// ============================
|
||||||
@ -794,7 +540,6 @@ int main(int argc, char *argv[]) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// OPTIMIZE: This should be done inside each case where data is updated otherwise we lose performance
|
|
||||||
usleep(10000); // Sleep for 10ms
|
usleep(10000); // Sleep for 10ms
|
||||||
}
|
}
|
||||||
close(send_sock_fd);
|
close(send_sock_fd);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user