mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-02-16 10:41:01 +00:00
add socketio, http post & get
This commit is contained in:
committed by
Anonymous275
parent
4cda6e8bc3
commit
ef5db013b3
9
include/Http.h
Normal file
9
include/Http.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Http {
|
||||
std::string GET(const std::string& host, int port, const std::string& target);
|
||||
std::string POST(const std::string& host, const std::string& target, const std::unordered_map<std::string, std::string>& fields, const std::string& body, bool json);
|
||||
}
|
||||
69
include/SocketIO.h
Normal file
69
include/SocketIO.h
Normal file
@@ -0,0 +1,69 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
#include <sio_client.h>
|
||||
#include <thread>
|
||||
|
||||
/*
|
||||
* 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(SocketIORoom Room, SocketIOEvent Event, const std::string& Data);
|
||||
|
||||
~SocketIO();
|
||||
|
||||
void SetAuthenticated(bool auth) { _Authenticated = auth; }
|
||||
|
||||
private:
|
||||
SocketIO();
|
||||
|
||||
void ThreadMain();
|
||||
|
||||
struct Event {
|
||||
std::string Room;
|
||||
std::string Name;
|
||||
std::string Data;
|
||||
};
|
||||
|
||||
bool _Authenticated { false };
|
||||
sio::client _Client;
|
||||
std::thread _Thread;
|
||||
std::atomic_bool _CloseThread { false };
|
||||
std::mutex _QueueMutex;
|
||||
std::deque<Event> _Queue;
|
||||
|
||||
friend std::unique_ptr<SocketIO> std::make_unique<SocketIO>();
|
||||
};
|
||||
|
||||
10
include/THeartbeatThread.h
Normal file
10
include/THeartbeatThread.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "IThreaded.h"
|
||||
#include "Common.h"
|
||||
|
||||
class THeartbeatThread : public IThreaded {
|
||||
public:
|
||||
THeartbeatThread();
|
||||
void operator()() override;
|
||||
};
|
||||
19
include/TResourceManager.h
Normal file
19
include/TResourceManager.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
class TResourceManager {
|
||||
public:
|
||||
TResourceManager();
|
||||
|
||||
[[nodiscard]] uint64_t MaxModSize() const { return mMaxModSize; }
|
||||
[[nodiscard]] std::string FileList() const { return mFileList; }
|
||||
[[nodiscard]] std::string FileSizes() const { return mFileSizes; }
|
||||
[[nodiscard]] int ModsLoaded() const { return mModsLoaded; }
|
||||
|
||||
private:
|
||||
uint64_t mMaxModSize = 0;
|
||||
std::string mFileSizes;
|
||||
std::string mFileList;
|
||||
int mModsLoaded = 0;
|
||||
};
|
||||
Reference in New Issue
Block a user