Files
Shipwright/soh/soh/Network/Network.h
T
Philip Dubé 940e3c5696 More pragma once (#7081)
libultraship uses pragma once, we were already using it in many headers
2026-08-16 14:49:44 +00:00

49 lines
1.4 KiB
C++

#pragma once
#ifdef __cplusplus
#include <thread>
#include <SDL2/SDL_net.h>
#include <nlohmann/json.hpp>
class Network {
private:
IPaddress networkAddress;
TCPsocket networkSocket;
std::thread receiveThread;
std::string receivedData;
void ReceiveFromServer();
void HandleRemoteData(char payload[512]);
void HandleRemoteJson(std::string payload);
public:
bool isEnabled;
bool isConnected;
void Enable(const char* host, uint16_t port);
void Disable();
/**
* Raw data handler
*
* If you are developing a new remote, you should probably use the json methods instead. This
* method requires you to parse the data and ensure packets are complete manually, we cannot
* gaurentee that the data will be complete, or that it will only contain one packet with this
*/
virtual void OnIncomingData(char payload[512]);
/**
* Json handler
*
* This method will be called when a complete json packet is received. All json packets must
* be delimited by a null terminator (\0).
*/
virtual void OnIncomingJson(nlohmann::json payload);
virtual void OnConnected();
virtual void OnDisconnected();
virtual void ProcessOutgoingPackets();
void SendDataToRemote(const char* payload);
virtual void SendJsonToRemote(nlohmann::json packet);
};
#endif // __cplusplus