mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-02-16 10:41:01 +00:00
fix various issues
This commit is contained in:
committed by
Anonymous275
parent
8e4006fc38
commit
4edd1ac100
@@ -13,13 +13,18 @@ class TServer;
|
||||
|
||||
class TClient final {
|
||||
public:
|
||||
using TSetOfVehicleData = std::unordered_set<std::unique_ptr<TVehicleData>>;
|
||||
using TSetOfVehicleData = std::unordered_set<TVehicleData>;
|
||||
|
||||
struct TVehicleDataLockPair {
|
||||
TSetOfVehicleData& VehicleData;
|
||||
std::unique_lock<std::mutex> Lock;
|
||||
};
|
||||
|
||||
explicit TClient(TServer& Server);
|
||||
|
||||
void AddNewCar(int Ident, const std::string& Data);
|
||||
void SetCarData(int Ident, const std::string& Data);
|
||||
TSetOfVehicleData& GetAllCars();
|
||||
TVehicleDataLockPair GetAllCars();
|
||||
void SetName(const std::string& Name) { mName = Name; }
|
||||
void SetRoles(const std::string& Role) { mRole = Role; }
|
||||
std::string GetCarData(int Ident);
|
||||
@@ -54,6 +59,7 @@ private:
|
||||
bool mIsConnected = false;
|
||||
bool mIsSynced = false;
|
||||
bool mIsGuest = false;
|
||||
std::mutex mVehicleDataMutex;
|
||||
TSetOfVehicleData mVehicleData;
|
||||
std::string mName = "Unknown Client";
|
||||
SOCKET mSocket[2] { SOCKET(-1) };
|
||||
|
||||
@@ -56,6 +56,9 @@ private:
|
||||
static inline std::deque<TShutdownHandler> mShutdownHandlers {};
|
||||
};
|
||||
|
||||
#define KB 1024
|
||||
#define MB (KB * 1024)
|
||||
|
||||
#ifndef DEBUG
|
||||
static inline void warn(const std::string& str) {
|
||||
Application::Console().Write(std::string("[WARN] ") + str);
|
||||
|
||||
@@ -7,13 +7,24 @@ public:
|
||||
TVehicleData(int ID, const std::string& Data);
|
||||
~TVehicleData();
|
||||
|
||||
bool IsInvalid() const { return _ID == -1; }
|
||||
int ID() const { return _ID; }
|
||||
[[nodiscard]] bool IsInvalid() const { return mID == -1; }
|
||||
[[nodiscard]] int ID() const { return mID; }
|
||||
|
||||
std::string Data() const { return _Data; }
|
||||
void SetData(const std::string& Data) { _Data = Data; }
|
||||
[[nodiscard]] std::string Data() const { return mData; }
|
||||
void SetData(const std::string& Data) { mData = Data; }
|
||||
|
||||
bool operator==(const TVehicleData& v) const { return mID == v.mID; }
|
||||
|
||||
private:
|
||||
int _ID { -1 };
|
||||
std::string _Data;
|
||||
int mID { -1 };
|
||||
std::string mData;
|
||||
};
|
||||
|
||||
namespace std {
|
||||
template <>
|
||||
struct hash<TVehicleData> {
|
||||
std::size_t operator()(const TVehicleData& s) const noexcept {
|
||||
return s.ID();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user