feat: Migrating features from newer implementation

This commit is contained in:
2025-03-29 10:50:16 +01:00
parent 171a48eb71
commit 810264aa71
15 changed files with 982 additions and 538 deletions
+40 -20
View File
@@ -21,6 +21,7 @@
#include "SPITObject.h"
#include "SPITPlayer.h"
#include <memory>
#include <vector>
using namespace std;
@@ -30,9 +31,15 @@ public:
/** Maximal length of a SPITMessage*/
static const int MAXSPITMESSAGEBYTECOUNT = 512;
enum ServerEvent {
Detect,
Lost,
Changed,
};
struct Callbacks {
void(*onServerDetect)(const SAD_DetectedServer &p_DetectedServer);
void(*onServerLost)(const SAD_DetectedServer &p_DetectedServer);
void(*onServerEvent)(ServerEvent event, const SAD_DetectedServer &p_DetectedServer);
void(*onConnectionStatus)(string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime, int p_ConnectionStatus, int p_OldConnectionStatus);
void(*onStartProjectTransfer)();
void(*onEndProjectTransfer)();
void(*onProjectClosed)(string);
@@ -46,8 +53,10 @@ public:
void(*onSpitObjectRemoved)(const SPITType &p_SPITType, const SPITObject &p_SPITObject);
void(*onSpitObjectRemoteRemoved)(const SPITType &p_SPITType, const SPITObject &p_SPITObject);
void(*onPlay)(string p_PlayerID, string p_PlayerName, char p_PlayerType, bool p_PlayerIsRunning, long long p_TimeFrames);
void(*onPlayObject)(string p_PlayerID, bool p_Started, bool p_Stopped, const SPITType &p_SPITType, const SPITObject &p_SPITObject, const SPITPlayer::PlayObject &p_PlayObject);
void(*onPlaySpitType)(string p_PlayerID, string p_SPITTypeID, bool p_PlayerIsRunning, bool p_Started, bool p_Ended, double p_Value);
void(*onPlayRemoteObjectStatus)(const SPITType &p_SPITType, const SPITObject &p_SPITObject, long long p_FrameInsideObject, int p_Value);
bool(*onCheckSpitTypeVeto)(SPIT_Message::ReportSPITType* p_ReportSPITType);
bool(*onCheckSpitObjectVeto)(SPIT_Message::ReportSPITObject* p_ReportSPITObject);
};
//----- Connection Status -----
@@ -86,6 +95,7 @@ public:
public:
SPIT_Client(string name, string projName, Callbacks calls);
virtual ~SPIT_Client();
static int s_MAX_OVERTAKING_SPIT_MESSAGES;
private:
Callbacks mCallbacks;
@@ -99,15 +109,18 @@ private:
string m_ProjName;
string m_ComputerName;
string m_ClientProjectName;
unsigned char m_MessageNumber_Send;
int m_MessageNumber_Received;
vector<SPIT_Message*> m_OvertakingSPIT_Messages;
//Server's info filled by parseConnectAnswer
string m_ServerID{};
string m_ServerName{};
string m_ServerComputerName{};
int m_ServerStepTime{-1};
unsigned char m_MessageNumber_Send;
int m_MessageNumber_Received;
//--- Server Project ---
string m_ServerProjectID;
string m_ServerProjectName;
@@ -115,25 +128,28 @@ private:
public:
/** The ID of the client.<br>Every client instance should set an unique id*/
string getID();
string getID() { return m_ID; }
/** The name of the client, should be set by the user app*/
string getName();
string getName() { return m_Name; }
//----- Computer Params -----
/** The name of the client's host computer*/
string getComputerName();
string getComputerName() { return m_ComputerName; }
void setClientProjectName(string p_ClientProjectName) { m_ClientProjectName = p_ClientProjectName; }
string getClientProjectName() { return m_ClientProjectName; }
//connected Server Infos
/** The ID of the connected SPITServer*/
string getServerID();
string getServerID() { return m_ServerID; }
/** The host computername of the connected SPITServer*/
string getServerComputerName();
string getServerComputerName() { return m_ServerComputerName; }
/** The name of the connected SPITServer*/
string getServerName();
string getServerName() { return m_ServerName; }
/** Expected Refreah Rate of the connectd SPITServer.<br>
* When the server plays objects, it will do so at discrete time steps.<br>
* Play events will take place in these time steps..
*/
int getServerStepTime();
int getServerStepTime() { return m_ServerStepTime; }
/** Should be called when the client wants to close his project*/
void clientProjectClose();
@@ -155,11 +171,11 @@ private:
bool startReceiveSPITMessages();
void stopReceiveSPITMessages();
static void receiveSPITMessage(SPIT_Client& rM);
int sendSPITMessage(SPIT_Message::OPPart& p_SPITMessageOPPart);
void fillHeader(SPIT_Message::Header* p_Header);
// Reconnect to the server when connection is lost see eventConnectionStatus and eventServerDetected
bool _doReconnect{}; // true = on eventServerDetected connect to the server identified by m_ServerID
public:
void fillHeader(SPIT_Message::Header* p_Header);
int sendSPITMessage(SPIT_Message::OPPart& p_SPITMessageOPPart);
//--------------- ServerAutoDetection SAD ---------------
public:
@@ -168,10 +184,10 @@ public:
/** Stops the autodetection of SPITServers in the local network*/
void stopServerAutoDetect();
/** Called every time a new SPITServer is detetced in the local network */
void eventServerDetected(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ClientIP, bool p_IsIP4);
void eventServerDetected(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ProjectName, string p_ClientIP, bool p_IsIP4);
/** Called every time a prior detected SPITServer is is no longer found.*/
void eventServerLost(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ClientIP, bool p_IsIP4);
void eventServerLost(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ProjectName, string p_ClientIP, bool p_IsIP4);
void eventServerChanged(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ProjectName, string p_ClientIP, bool p_IsIP4);
//--------------- Connection ---------------
public:
@@ -194,7 +210,10 @@ public:
private:
void disconnectInternal(int p_Cause);
void resetMessageNumberReceived();
void parseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage);
void checkParseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage);
void addOvertakingSPIT_Message(SPIT_Message* p_SPIT_Message);
void parseConnectAnswer(SPIT_Message::ConnectAnswer* p_ConnectAnswer);
void parseDisconnect(SPIT_Message::Disconnect* p_Disconnect);
void parseWatchdog(SPIT_Message::Watchdog* p_Watchdog);
@@ -220,7 +239,8 @@ private:
void parseRequestProjectTransfer(SPIT_Message::RequestProjectTransfer* p_RequestProjectTransfer);
void parseStartProjectTransfer(SPIT_Message::StartProjectTransfer* p_StartProjectTransfer);
void parseEndProjectTransfer(SPIT_Message::EndProjectTransfer* p_EndProjectTransfer);
public:
static void sendProject(SPIT_Client* p_PtrSPIT_Client);
// --------------- SPIT Types ---------------
public: