mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-02-16 10:41:01 +00:00
Merge TUDPServer and TTCPServer into TNetwork
this gets rid of a bunch of unclear cases which I mistakenly created while refactoring for this rewrite. One example is having to call into TTCPServer to do UDP sending in some cases.
This commit is contained in:
committed by
Anonymous275
parent
05c5fb047c
commit
40cae31885
@@ -4,7 +4,7 @@
|
||||
|
||||
class TConfig {
|
||||
public:
|
||||
TConfig(const std::string& ConfigFile);
|
||||
explicit TConfig(const std::string& ConfigFile);
|
||||
|
||||
private:
|
||||
static std::string RemoveComments(const std::string& Line);
|
||||
|
||||
@@ -4,15 +4,14 @@
|
||||
#include "IThreaded.h"
|
||||
#include "TLuaFile.h"
|
||||
#include "TServer.h"
|
||||
#include <optional>
|
||||
#include <lua.hpp>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
|
||||
class TLuaEngine : public IThreaded {
|
||||
public:
|
||||
explicit TLuaEngine(TServer& Server, TTCPServer& TCPServer, TUDPServer& UDPServer);
|
||||
//~TLuaEngine();
|
||||
explicit TLuaEngine(TServer& Server, TNetwork& Network);
|
||||
|
||||
using TSetOfLuaFile = std::set<std::unique_ptr<TLuaFile>>;
|
||||
|
||||
@@ -21,19 +20,17 @@ public:
|
||||
[[nodiscard]] const TSetOfLuaFile& LuaFiles() const { return mLuaFiles; }
|
||||
[[nodiscard]] TServer& Server() { return mServer; }
|
||||
[[nodiscard]] const TServer& Server() const { return mServer; }
|
||||
[[nodiscard]] TNetwork& Network() { return mNetwork; }
|
||||
[[nodiscard]] const TNetwork& Network() const { return mNetwork; }
|
||||
|
||||
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;
|
||||
TNetwork& mNetwork;
|
||||
TServer& mServer;
|
||||
std::string mPath;
|
||||
bool mShutdown { false };
|
||||
|
||||
@@ -1,20 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "Client.h"
|
||||
#include "Common.h"
|
||||
#include "Compat.h"
|
||||
#include "IThreaded.h"
|
||||
#include "TResourceManager.h"
|
||||
#include "TServer.h"
|
||||
#include <optional>
|
||||
|
||||
class TResourceManager;
|
||||
|
||||
class TTCPServer : public IThreaded {
|
||||
class TNetwork {
|
||||
public:
|
||||
explicit TTCPServer(TServer& Server, TPPSMonitor& PPSMonitor, TResourceManager& ResourceManager);
|
||||
//~TTCPServer();
|
||||
|
||||
void operator()() override;
|
||||
TNetwork(TServer& Server, TPPSMonitor& PPSMonitor, TResourceManager& ResourceManager);
|
||||
|
||||
bool TCPSend(TClient& c, const std::string& Data, bool IsSync = false);
|
||||
void SendLarge(TClient& c, std::string Data, bool isSync = false);
|
||||
@@ -22,26 +14,28 @@ public:
|
||||
std::shared_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(const 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 UDPSend(TClient& Client, std::string Data) const;
|
||||
void SendToAll(TClient* c, const std::string& Data, bool Self, bool Rel);
|
||||
void UpdatePlayer(TClient& Client);
|
||||
|
||||
private:
|
||||
std::optional<std::reference_wrapper<TUDPServer>> mUDPServer { std::nullopt };
|
||||
void UDPServerMain();
|
||||
void TCPServerMain();
|
||||
|
||||
TServer& mServer;
|
||||
TPPSMonitor& mPPSMonitor;
|
||||
TResourceManager& mResourceManager;
|
||||
SOCKET mUDPSock {};
|
||||
bool mShutdown { false };
|
||||
TResourceManager& mResourceManager;
|
||||
std::thread mUDPThread;
|
||||
std::thread mTCPThread;
|
||||
|
||||
std::string UDPRcvFromClient(sockaddr_in& client) const;
|
||||
void HandleDownload(SOCKET TCPSock);
|
||||
void OnConnect(const std::weak_ptr<TClient>& c);
|
||||
void TCPClient(const std::weak_ptr<TClient>& c);
|
||||
@@ -51,4 +45,4 @@ private:
|
||||
void SendFile(TClient& c, const std::string& Name);
|
||||
static bool TCPSendRaw(SOCKET C, char* Data, int32_t Size);
|
||||
static void SplitLoad(TClient& c, size_t Sent, size_t Size, bool D, const std::string& Name);
|
||||
};
|
||||
};
|
||||
@@ -3,6 +3,9 @@
|
||||
#include "Common.h"
|
||||
#include "TServer.h"
|
||||
#include <optional>
|
||||
|
||||
class TNetwork;
|
||||
|
||||
class TPPSMonitor : public IThreaded {
|
||||
public:
|
||||
explicit TPPSMonitor(TServer& Server);
|
||||
@@ -12,13 +15,13 @@ public:
|
||||
void SetInternalPPS(int NewPPS) { mInternalPPS = NewPPS; }
|
||||
void IncrementInternalPPS() { ++mInternalPPS; }
|
||||
[[nodiscard]] int InternalPPS() const { return mInternalPPS; }
|
||||
void SetTCPServer(TTCPServer& Server) { mTCPServer = std::ref(Server); }
|
||||
void SetNetwork(TNetwork& Server) { mNetwork = std::ref(Server); }
|
||||
|
||||
private:
|
||||
TTCPServer& TCPServer() { return mTCPServer->get(); }
|
||||
|
||||
TNetwork& Network() { return mNetwork->get(); }
|
||||
|
||||
TServer& mServer;
|
||||
std::optional<std::reference_wrapper<TTCPServer>> mTCPServer { std::nullopt };
|
||||
std::optional<std::reference_wrapper<TNetwork>> mNetwork { std::nullopt };
|
||||
bool mShutdown { false };
|
||||
int mInternalPPS { 0 };
|
||||
};
|
||||
@@ -8,8 +8,7 @@
|
||||
#include <unordered_set>
|
||||
|
||||
class TClient;
|
||||
class TUDPServer;
|
||||
class TTCPServer;
|
||||
class TNetwork;
|
||||
class TPPSMonitor;
|
||||
|
||||
class TServer final {
|
||||
@@ -25,12 +24,12 @@ public:
|
||||
void ForEachClient(const std::function<bool(std::weak_ptr<TClient>)>& Fn);
|
||||
size_t ClientCount() const;
|
||||
|
||||
static void GlobalParser(const std::weak_ptr<TClient>& Client, std::string Packet, TPPSMonitor& PPSMonitor, TUDPServer& UDPServer, TTCPServer& TCPServer);
|
||||
static void GlobalParser(const std::weak_ptr<TClient>& Client, std::string Packet, TPPSMonitor& PPSMonitor, TNetwork& Network);
|
||||
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 ParseVehicle(TClient& c, const std::string& Pckt, TNetwork& Network);
|
||||
static void Apply(TClient& c, int VID, const std::string& pckt);
|
||||
};
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Client.h"
|
||||
#include "Common.h"
|
||||
#include "Compat.h"
|
||||
#include "IThreaded.h"
|
||||
#include "TPPSMonitor.h"
|
||||
#include "TServer.h"
|
||||
|
||||
class TUDPServer : public IThreaded {
|
||||
public:
|
||||
explicit TUDPServer(TServer& Server, TPPSMonitor& PPSMonitor, TTCPServer& TCPServer);
|
||||
//~TUDPServer();
|
||||
|
||||
void operator()() override;
|
||||
|
||||
void UDPSend(TClient& Client, std::string Data) const;
|
||||
void SendToAll(TClient* c, const std::string& Data, bool Self, bool Rel);
|
||||
|
||||
private:
|
||||
TServer& mServer;
|
||||
TPPSMonitor& mPPSMonitor;
|
||||
TTCPServer& mTCPServer;
|
||||
SOCKET mUDPSock {};
|
||||
bool mShutdown { false };
|
||||
|
||||
std::string UDPRcvFromClient(sockaddr_in& client) const;
|
||||
};
|
||||
Reference in New Issue
Block a user