mirror of
https://github.com/SantaSpeen/BeamMP-Server.git
synced 2026-02-16 11:50:39 +00:00
finish rewrite, builds fully
This commit is contained in:
committed by
Anonymous275
parent
bf74b1ae32
commit
d360403c56
@@ -41,6 +41,9 @@ public:
|
||||
bool IsConnected() const { return mIsConnected; }
|
||||
bool IsSynced() const { return mIsSynced; }
|
||||
bool IsGuest() const { return mIsGuest; }
|
||||
void SetIsGuest(bool NewIsGuest) { mIsGuest = NewIsGuest; }
|
||||
void SetIsSynced(bool NewIsSynced) { mIsSynced = NewIsSynced; }
|
||||
void SetIsConnected(bool NewIsConnected) { mIsConnected = NewIsConnected; }
|
||||
TServer& Server() const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
|
||||
#include "TConsole.h"
|
||||
|
||||
@@ -56,7 +56,7 @@ private:
|
||||
static inline std::string mPPS;
|
||||
static std::unique_ptr<TConsole> mConsole;
|
||||
static inline std::mutex mShutdownHandlersMutex {};
|
||||
static inline std::vector<TShutdownHandler> mShutdownHandlers {};
|
||||
static inline std::deque<TShutdownHandler> mShutdownHandlers {};
|
||||
};
|
||||
|
||||
static inline void warn(const std::string& str) {
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
class TLuaEngine : public IThreaded {
|
||||
public:
|
||||
explicit TLuaEngine(TServer& Server);
|
||||
explicit TLuaEngine(TServer& Server, TTCPServer& TCPServer, TUDPServer& UDPServer);
|
||||
|
||||
using TSetOfLuaFile = std::set<std::unique_ptr<TLuaFile>>;
|
||||
|
||||
@@ -23,11 +23,16 @@ public:
|
||||
|
||||
std::optional<std::reference_wrapper<TLuaFile>> GetScript(lua_State* L);
|
||||
|
||||
TTCPServer& TCPServer() { return mTCPServer; }
|
||||
TUDPServer& UDPServer() { return mUDPServer; }
|
||||
|
||||
private:
|
||||
void FolderList(const std::string& Path, bool HotSwap);
|
||||
void RegisterFiles(const std::string& Path, bool HotSwap);
|
||||
bool NewFile(const std::string& Path);
|
||||
|
||||
TTCPServer& mTCPServer;
|
||||
TUDPServer& mUDPServer;
|
||||
TServer& mServer;
|
||||
TSetOfLuaFile mLuaFiles;
|
||||
};
|
||||
|
||||
@@ -56,4 +56,6 @@ private:
|
||||
bool mConsole = false;
|
||||
};
|
||||
|
||||
std::any TriggerLuaEvent(const std::string& Event, bool local, TLuaFile* Caller, std::shared_ptr<TLuaArg> arg, bool Wait);
|
||||
|
||||
#endif // TLUAFILE_H
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "Common.h"
|
||||
#include "IThreaded.h"
|
||||
#include "TServer.h"
|
||||
|
||||
class TPPSMonitor : public IThreaded {
|
||||
public:
|
||||
TPPSMonitor(TServer& Server);
|
||||
explicit TPPSMonitor(TServer& Server);
|
||||
|
||||
void operator()() override;
|
||||
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "IThreaded.h"
|
||||
#include "RWMutex.h"
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "RWMutex.h"
|
||||
|
||||
class TClient;
|
||||
class TUDPServer;
|
||||
class TTCPServer;
|
||||
class TPPSMonitor;
|
||||
|
||||
class TServer final {
|
||||
public:
|
||||
@@ -17,10 +20,16 @@ public:
|
||||
|
||||
std::weak_ptr<TClient> InsertNewClient();
|
||||
void RemoveClient(std::weak_ptr<TClient>);
|
||||
// in Fn, return true to continue, return false to break
|
||||
void ForEachClient(const std::function<bool(std::weak_ptr<TClient>)>& Fn);
|
||||
size_t ClientCount() const;
|
||||
|
||||
static void GlobalParser(std::weak_ptr<TClient> Client, std::string Packet, TPPSMonitor& PPSMonitor, TUDPServer& UDPServer, TTCPServer& TCPServer);
|
||||
static void HandleEvent(TClient& c, const std::string& Data);
|
||||
|
||||
private:
|
||||
TClientSet mClients;
|
||||
mutable RWMutex mClientsMutex;
|
||||
static void ParseVehicle(TClient& c, const std::string& Pckt, TTCPServer& TCPServer, TUDPServer& UDPServer);
|
||||
static void Apply(TClient& c, int VID, const std::string& pckt);
|
||||
};
|
||||
|
||||
@@ -1,14 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "Client.h"
|
||||
#include "Common.h"
|
||||
#include "Compat.h"
|
||||
#include "IThreaded.h"
|
||||
#include "TServer.h"
|
||||
|
||||
class TResourceManager;
|
||||
|
||||
class TTCPServer : public IThreaded {
|
||||
public:
|
||||
explicit TTCPServer(TServer& Server);
|
||||
explicit TTCPServer(TServer& Server, TPPSMonitor& PPSMonitor, TResourceManager& ResourceManager);
|
||||
|
||||
void operator()() override;
|
||||
|
||||
bool TCPSend(TClient& c, const std::string& Data);
|
||||
void SendLarge(TClient& c, std::string Data);
|
||||
void Respond(TClient& c, const std::string& MSG, bool Rel);
|
||||
std::weak_ptr<TClient> CreateClient(SOCKET TCPSock);
|
||||
std::string TCPRcv(TClient& c);
|
||||
void ClientKick(TClient& c, const std::string& R);
|
||||
|
||||
void SetUDPServer(TUDPServer& UDPServer);
|
||||
|
||||
TUDPServer& UDPServer() { return mUDPServer->get(); }
|
||||
|
||||
void SyncClient(std::weak_ptr<TClient> c);
|
||||
void Identify(SOCKET TCPSock);
|
||||
void Authentication(SOCKET TCPSock);
|
||||
bool CheckBytes(TClient& c, int32_t BytesRcv);
|
||||
void SyncResources(TClient& c);
|
||||
|
||||
void UpdatePlayers();
|
||||
private:
|
||||
std::optional<std::reference_wrapper<TUDPServer>> mUDPServer { std::nullopt };
|
||||
TServer& mServer;
|
||||
TPPSMonitor& mPPSMonitor;
|
||||
TResourceManager& mResourceManager;
|
||||
bool mShutdown { false };
|
||||
|
||||
void HandleDownload(SOCKET TCPSock);
|
||||
void OnConnect(std::weak_ptr<TClient> c);
|
||||
void TCPClient(std::weak_ptr<TClient> c);
|
||||
int OpenID();
|
||||
void OnDisconnect(std::weak_ptr<TClient> ClientPtr, bool kicked);
|
||||
void Parse(TClient& c, const std::string& Packet);
|
||||
void SendFile(TClient& c, const std::string& Name);
|
||||
static bool TCPSendRaw(SOCKET C, char* Data, int32_t Size);
|
||||
static void SplitLoad(TClient& c, int64_t Sent, int64_t Size, bool D, const std::string& Name);
|
||||
};
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
class TUDPServer : public IThreaded {
|
||||
public:
|
||||
explicit TUDPServer(TServer& Server, TPPSMonitor& PPSMonitor);
|
||||
explicit TUDPServer(TServer& Server, TPPSMonitor& PPSMonitor, TTCPServer& TCPServer);
|
||||
|
||||
void operator()() override;
|
||||
|
||||
@@ -17,10 +17,10 @@ public:
|
||||
void SendToAll(TClient* c, const std::string& Data, bool Self, bool Rel);
|
||||
|
||||
private:
|
||||
void UDPParser(TClient& Client, std::string Packet);
|
||||
|
||||
TServer& mServer;
|
||||
TPPSMonitor& mPPSMonitor;
|
||||
SOCKET mUDPSock;
|
||||
TTCPServer& mTCPServer;
|
||||
SOCKET mUDPSock {};
|
||||
|
||||
std::string UDPRcvFromClient(sockaddr_in& client) const;
|
||||
};
|
||||
Reference in New Issue
Block a user