mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-23 00:17:00 +00:00
SocketIO work
This commit is contained in:
committed by
Anonymous275
parent
57fc0ea74d
commit
aadcd1abe5
@@ -11,15 +11,14 @@ SocketIO& SocketIO::Get() {
|
|||||||
SocketIO::SocketIO() noexcept
|
SocketIO::SocketIO() noexcept
|
||||||
: mThread([this] { ThreadMain(); }) {
|
: mThread([this] { ThreadMain(); }) {
|
||||||
|
|
||||||
mClient.socket("/" + Application::TSettings().Key)->on("Hello", [&](sio::event&) {
|
mClient.socket()->on("welcome", [&](sio::event&) {
|
||||||
info("Got 'Hello' from backend socket-io!");
|
info("Got welcome from backend! Authenticating SocketIO...");
|
||||||
|
mClient.socket()->emit("onInitConnection", Application::Settings.Key);
|
||||||
});
|
});
|
||||||
|
|
||||||
mClient.set_logs_quiet();
|
mClient.set_logs_quiet();
|
||||||
mClient.set_reconnect_delay(10000);
|
mClient.set_reconnect_delay(10000);
|
||||||
mClient.connect("https://backend.beammp.com");
|
mClient.connect("https://backend.beammp.com");
|
||||||
|
|
||||||
//mClient.socket()->emit("initConnection", Application::TSettings().Key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SocketIO::~SocketIO() {
|
SocketIO::~SocketIO() {
|
||||||
@@ -77,18 +76,14 @@ void SocketIO::Emit(SocketIORoom Room, SocketIOEvent Event, const std::string& D
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SocketIO::ThreadMain() {
|
void SocketIO::ThreadMain() {
|
||||||
bool FirstTime = true;
|
|
||||||
while (!mCloseThread.load()) {
|
while (!mCloseThread.load()) {
|
||||||
if (mAuthenticated && FirstTime) {
|
bool empty;
|
||||||
FirstTime = false;
|
|
||||||
}
|
|
||||||
bool empty = false;
|
|
||||||
{ // queue lock scope
|
{ // queue lock scope
|
||||||
std::unique_lock Lock(mQueueMutex);
|
std::unique_lock Lock(mQueueMutex);
|
||||||
empty = mQueue.empty();
|
empty = mQueue.empty();
|
||||||
} // end queue lock scope
|
} // end queue lock scope
|
||||||
if (empty) {
|
if (empty || !mClient.opened()) {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
Event TheEvent;
|
Event TheEvent;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "rapidjson/document.h"
|
#include "rapidjson/document.h"
|
||||||
#include "rapidjson/stringbuffer.h"
|
#include "rapidjson/stringbuffer.h"
|
||||||
#include "rapidjson/writer.h"
|
#include "rapidjson/writer.h"
|
||||||
|
|
||||||
namespace json = rapidjson;
|
namespace json = rapidjson;
|
||||||
|
|
||||||
TServer::TServer(int argc, char** argv) {
|
TServer::TServer(int argc, char** argv) {
|
||||||
@@ -234,6 +235,7 @@ void TServer::ParseVehicle(TClient& c, const std::string& Pckt, TTCPServer& TCPS
|
|||||||
PID = stoi(pid);
|
PID = stoi(pid);
|
||||||
VID = stoi(vid);
|
VID = stoi(vid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PID != -1 && VID != -1 && PID == c.GetID()) {
|
if (PID != -1 && VID != -1 && PID == c.GetID()) {
|
||||||
Data = Data.substr(Data.find('{'));
|
Data = Data.substr(Data.find('{'));
|
||||||
TriggerLuaEvent("onVehicleReset", false, nullptr,
|
TriggerLuaEvent("onVehicleReset", false, nullptr,
|
||||||
|
|||||||
Reference in New Issue
Block a user