mirror of
https://github.com/HarbourMasters/Shipwright
synced 2026-06-29 11:51:07 -04:00
Tweaks to ENABLE_REMOTE_CONTROL usage & sail hooks (#5928)
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
#ifdef ENABLE_REMOTE_CONTROL
|
||||
|
||||
#include "Network.h"
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <libultraship/libultraship.h>
|
||||
@@ -7,6 +5,7 @@
|
||||
// MARK: - Public
|
||||
|
||||
void Network::Enable(const char* host, uint16_t port) {
|
||||
#ifdef ENABLE_REMOTE_CONTROL
|
||||
if (isEnabled) {
|
||||
return;
|
||||
}
|
||||
@@ -23,6 +22,7 @@ void Network::Enable(const char* host, uint16_t port) {
|
||||
}
|
||||
|
||||
receiveThread = std::thread(&Network::ReceiveFromServer, this);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Network::Disable() {
|
||||
@@ -47,8 +47,10 @@ void Network::OnDisconnected() {
|
||||
}
|
||||
|
||||
void Network::SendDataToRemote(const char* payload) {
|
||||
#ifdef ENABLE_REMOTE_CONTROL
|
||||
SPDLOG_DEBUG("[Network] Sending data: {}", payload);
|
||||
SDLNet_TCP_Send(networkSocket, payload, strlen(payload) + 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Network::SendJsonToRemote(nlohmann::json payload) {
|
||||
@@ -58,6 +60,7 @@ void Network::SendJsonToRemote(nlohmann::json payload) {
|
||||
// MARK: - Private
|
||||
|
||||
void Network::ReceiveFromServer() {
|
||||
#ifdef ENABLE_REMOTE_CONTROL
|
||||
while (isEnabled) {
|
||||
while (!isConnected && isEnabled) {
|
||||
SPDLOG_TRACE("[Network] Attempting to make connection to server...");
|
||||
@@ -123,6 +126,7 @@ void Network::ReceiveFromServer() {
|
||||
SPDLOG_INFO("[Network] Ending receiving thread...");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Network::HandleRemoteData(char payload[512]) {
|
||||
@@ -141,5 +145,3 @@ void Network::HandleRemoteJson(std::string payload) {
|
||||
|
||||
OnIncomingJson(jsonPayload);
|
||||
}
|
||||
|
||||
#endif // ENABLE_REMOTE_CONTROL
|
||||
|
||||
Reference in New Issue
Block a user