mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-03 00:05:34 +00:00
Remove Socket.io for now
it is being built every time and we dont need it
This commit is contained in:
parent
2a96546c8c
commit
2727f90430
@ -62,7 +62,6 @@ message(STATUS "Adding local source dependencies")
|
||||
include_directories("asio/asio/include")
|
||||
include_directories("rapidjson/include")
|
||||
include_directories("websocketpp")
|
||||
add_subdirectory("socket.io-client-cpp")
|
||||
add_subdirectory("include/commandline")
|
||||
|
||||
|
||||
@ -104,7 +103,6 @@ target_include_directories(BeamMP-Server PUBLIC
|
||||
${Boost_INCLUDE_DIRS}
|
||||
${LUA_INCLUDE_DIR}
|
||||
${CURL_INCLUDE_DIRS}
|
||||
"socket.io-client-cpp/src"
|
||||
"include/tomlplusplus"
|
||||
"include/sentry-native/include"
|
||||
"include/curl/include")
|
||||
@ -142,4 +140,4 @@ elseif (WIN32)
|
||||
commandline
|
||||
sioclient_tls
|
||||
sentry)
|
||||
endif ()
|
||||
endif ()
|
||||
|
@ -91,7 +91,7 @@ private:
|
||||
static inline std::mutex mShutdownHandlersMutex {};
|
||||
static inline std::deque<TShutdownHandler> mShutdownHandlers {};
|
||||
|
||||
static inline Version mVersion { 2, 3, 0 };
|
||||
static inline Version mVersion { 2, 4, 0 };
|
||||
};
|
||||
|
||||
std::string ThreadName(bool DebugModeOverride = false);
|
||||
|
@ -1,69 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
#include <sio_client.h>
|
||||
#include <thread>
|
||||
#include <memory>
|
||||
|
||||
/*
|
||||
* We send relevant server events over socket.io to the backend.
|
||||
*
|
||||
* We send all events to `backend.beammp.com`, to the room `/key`
|
||||
* where `key` is the currently active auth-key.
|
||||
*/
|
||||
|
||||
enum class SocketIOEvent {
|
||||
ConsoleOut,
|
||||
CPUUsage,
|
||||
MemoryUsage,
|
||||
NetworkUsage,
|
||||
PlayerList,
|
||||
};
|
||||
|
||||
enum class SocketIORoom {
|
||||
None,
|
||||
Stats,
|
||||
Player,
|
||||
Info,
|
||||
Console,
|
||||
};
|
||||
|
||||
class SocketIO final {
|
||||
private:
|
||||
struct Event;
|
||||
|
||||
public:
|
||||
enum class EventType {
|
||||
};
|
||||
|
||||
// Singleton pattern
|
||||
static SocketIO& Get();
|
||||
|
||||
void Emit(SocketIOEvent Event, const std::string& Data);
|
||||
|
||||
~SocketIO();
|
||||
|
||||
void SetAuthenticated(bool auth) { mAuthenticated = auth; }
|
||||
|
||||
private:
|
||||
SocketIO() noexcept;
|
||||
|
||||
void ThreadMain();
|
||||
|
||||
struct Event {
|
||||
std::string Name;
|
||||
std::string Data;
|
||||
};
|
||||
|
||||
bool mAuthenticated { false };
|
||||
sio::client mClient;
|
||||
std::thread mThread;
|
||||
std::atomic_bool mCloseThread { false };
|
||||
std::mutex mQueueMutex;
|
||||
std::deque<Event> mQueue;
|
||||
|
||||
friend std::unique_ptr<SocketIO> std::make_unique<SocketIO>();
|
||||
};
|
||||
|
@ -1,98 +0,0 @@
|
||||
#include "SocketIO.h"
|
||||
#include "Common.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
//TODO Default disabled with config option
|
||||
static std::unique_ptr<SocketIO> SocketIOInstance = std::make_unique<SocketIO>();
|
||||
|
||||
SocketIO& SocketIO::Get() {
|
||||
return *SocketIOInstance;
|
||||
}
|
||||
|
||||
SocketIO::SocketIO() noexcept
|
||||
: mThread([this] { ThreadMain(); }) {
|
||||
|
||||
mClient.socket()->on("network", [&](sio::event&e) {
|
||||
if(e.get_message()->get_string() == "Welcome"){
|
||||
info("SocketIO Authenticated!");
|
||||
mAuthenticated = true;
|
||||
}
|
||||
});
|
||||
|
||||
mClient.socket()->on("welcome", [&](sio::event&) {
|
||||
info("Got welcome from backend! Authenticating SocketIO...");
|
||||
mClient.socket()->emit("onInitConnection", Application::Settings.Key);
|
||||
});
|
||||
|
||||
mClient.set_logs_quiet();
|
||||
mClient.set_reconnect_delay(10000);
|
||||
mClient.connect(Application::GetBackendUrlForSocketIO());
|
||||
}
|
||||
|
||||
SocketIO::~SocketIO() {
|
||||
mCloseThread.store(true);
|
||||
mThread.join();
|
||||
}
|
||||
|
||||
|
||||
static constexpr auto EventNameFromEnum(SocketIOEvent Event) {
|
||||
switch (Event) {
|
||||
case SocketIOEvent::CPUUsage:
|
||||
return "cpu usage";
|
||||
case SocketIOEvent::MemoryUsage:
|
||||
return "memory usage";
|
||||
case SocketIOEvent::ConsoleOut:
|
||||
return "console out";
|
||||
case SocketIOEvent::NetworkUsage:
|
||||
return "network usage";
|
||||
case SocketIOEvent::PlayerList:
|
||||
return "player list";
|
||||
default:
|
||||
error("unreachable code reached (developer error)");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
void SocketIO::Emit(SocketIOEvent Event, const std::string& Data) {
|
||||
if (!mAuthenticated) {
|
||||
debug("trying to emit a socket.io event when not yet authenticated");
|
||||
return;
|
||||
}
|
||||
std::string EventName = EventNameFromEnum(Event);
|
||||
debug("emitting event \"" + EventName + "\" with data: \"" + Data);
|
||||
std::unique_lock Lock(mQueueMutex);
|
||||
mQueue.push_back({EventName, Data });
|
||||
debug("queue now has " + std::to_string(mQueue.size()) + " events");
|
||||
}
|
||||
|
||||
void SocketIO::ThreadMain() {
|
||||
while (!mCloseThread.load()) {
|
||||
bool empty;
|
||||
{ // queue lock scope
|
||||
std::unique_lock Lock(mQueueMutex);
|
||||
empty = mQueue.empty();
|
||||
} // end queue lock scope
|
||||
if (empty || !mClient.opened()) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
continue;
|
||||
} else {
|
||||
Event TheEvent;
|
||||
{ // queue lock scope
|
||||
std::unique_lock Lock(mQueueMutex);
|
||||
TheEvent = mQueue.front();
|
||||
mQueue.pop_front();
|
||||
} // end queue lock scope
|
||||
debug("sending \"" + TheEvent.Name + "\" event");
|
||||
mClient.socket()->emit(TheEvent.Name, TheEvent.Data);
|
||||
debug("sent \"" + TheEvent.Name + "\" event");
|
||||
}
|
||||
}
|
||||
// using std::cout as this happens during static destruction and the logger might be dead already
|
||||
std::cout << "closing " + std::string(__func__) << std::endl;
|
||||
|
||||
mClient.sync_close();
|
||||
mClient.clear_con_listeners();
|
||||
|
||||
std::cout << "closed" << std::endl;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user