feat: initial idea for paresing

This commit is contained in:
AfonsoCMSousa 2026-01-08 00:43:12 +00:00
parent 7072f17842
commit ef0da72123

View File

@ -5,14 +5,24 @@
#include <string> #include <string>
#include <sys/types.h> #include <sys/types.h>
#include <vector> #include <vector>
#include <unistd.h>
#include <signal.h>
#include "app.hpp" // for app_info struct #include "app.hpp" // for app_info struct
#include "file.hpp" // for parce_args #include "file.hpp" // for parce_args
#include "net.hpp" // for socket operations #include "net.hpp" // for socket operations
#include "server_structs.h" #include "server_structs.h" // for api_packet and ACSP_MessageType
#include "session.hpp" // for SessionManager
using namespace std; using namespace std;
volatile bool STOP_PROGRAM = false;
void signal_handler(int signum) {
if (signum == SIGINT || signum == SIGTERM) {
STOP_PROGRAM = true;
}
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
app_info app = parce_args(argc, argv); app_info app = parce_args(argc, argv);
@ -20,6 +30,8 @@ int main(int argc, char *argv[]) {
Socket sock; Socket sock;
SessionManager session_manager(app.app_id); // Server ID 1 for now
char buffer[2048]; char buffer[2048];
try { try {
@ -58,6 +70,40 @@ int main(int argc, char *argv[]) {
// TAG: Because sometimes the parser doesnt have the name of the server because it started after the server init // TAG: Because sometimes the parser doesnt have the name of the server because it started after the server init
// we can cache it and reuse it to avoid NULL names in the DB // we can cache it and reuse it to avoid NULL names in the DB
while (STOP_PROGRAM == false) {
// Receive data from server
ssize_t received = sock.receive_server(buffer, sizeof(buffer));
if (received > 0) {
switch (buffer[0]) {
case ACSP_VERSION: {
cout << "[?] Received Version Packet?\nResending Update Rate Request..." << endl;
char request[516] = {0};
request[0] = ACSP_REALTIMEPOS_INTERVAL;
request[1] = 120;
sock.send_server(request, sizeof(request));
break;
}
case ACSP_CAR_UPDATE: {
cout << "[+] Received Car Update Packet with " << (int)packet.connected_players << " connected players." << endl;
break;
}
case ACSP_NEW_SESSION: {
cout << "[+] New Session Started: " << packet.track_info.session_name << endl;
break;
}
default: {
cout << "[!] Unknown packet type received: " << (int)buffer[0] << endl;
break;
}
}
}
}
return 0; return 0;
} }