mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-02-16 10:41:01 +00:00
add udpserver, tcpserver
This commit is contained in:
committed by
Anonymous275
parent
f19a012509
commit
bf74b1ae32
@@ -8,46 +8,52 @@
|
||||
#include "Compat.h"
|
||||
#include "VehicleData.h"
|
||||
|
||||
class TServer;
|
||||
|
||||
class TClient final {
|
||||
public:
|
||||
using TSetOfVehicleData = std::unordered_set<std::unique_ptr<TVehicleData>>;
|
||||
|
||||
explicit TClient(TServer& Server);
|
||||
|
||||
void AddNewCar(int Ident, const std::string& Data);
|
||||
void SetCarData(int Ident, const std::string& Data);
|
||||
TSetOfVehicleData& GetAllCars();
|
||||
void SetName(const std::string& Name) { _Name = Name; }
|
||||
void SetRoles(const std::string& Role) { _Role = Role; }
|
||||
void SetName(const std::string& Name) { mName = Name; }
|
||||
void SetRoles(const std::string& Role) { mRole = Role; }
|
||||
std::string GetCarData(int Ident);
|
||||
void SetUDPAddr(sockaddr_in Addr) { _UDPAddress = Addr; }
|
||||
void SetDownSock(SOCKET CSock) { _Socket[1] = CSock; }
|
||||
void SetTCPSock(SOCKET CSock) { _Socket[0] = CSock; }
|
||||
void SetStatus(int Status) { _Status = Status; }
|
||||
void SetUDPAddr(sockaddr_in Addr) { mUDPAddress = Addr; }
|
||||
void SetDownSock(SOCKET CSock) { mSocket[1] = CSock; }
|
||||
void SetTCPSock(SOCKET CSock) { mSocket[0] = CSock; }
|
||||
void SetStatus(int Status) { mStatus = Status; }
|
||||
void DeleteCar(int Ident);
|
||||
sockaddr_in GetUDPAddr() { return _UDPAddress; }
|
||||
std::string GetRoles() { return _Role; }
|
||||
std::string GetName() { return _Name; }
|
||||
SOCKET GetDownSock() { return _Socket[1]; }
|
||||
SOCKET GetTCPSock() { return _Socket[0]; }
|
||||
void SetID(int ID) { _ID = ID; }
|
||||
int GetOpenCarID();
|
||||
int GetCarCount();
|
||||
sockaddr_in GetUDPAddr() const { return mUDPAddress; }
|
||||
std::string GetRoles() const { return mRole; }
|
||||
std::string GetName() const { return mName; }
|
||||
SOCKET GetDownSock() const { return mSocket[1]; }
|
||||
SOCKET GetTCPSock() const { return mSocket[0]; }
|
||||
void SetID(int ID) { mID = ID; }
|
||||
int GetOpenCarID() const;
|
||||
int GetCarCount() const;
|
||||
void ClearCars();
|
||||
int GetStatus() { return _Status; }
|
||||
int GetID() { return _ID; }
|
||||
bool IsConnected() const { return _IsConnected; }
|
||||
bool IsSynced() const { return _IsSynced; }
|
||||
bool IsGuest() const { return _IsGuest; }
|
||||
int GetStatus() const { return mStatus; }
|
||||
int GetID() const { return mID; }
|
||||
bool IsConnected() const { return mIsConnected; }
|
||||
bool IsSynced() const { return mIsSynced; }
|
||||
bool IsGuest() const { return mIsGuest; }
|
||||
TServer& Server() const;
|
||||
|
||||
private:
|
||||
bool _IsConnected = false;
|
||||
bool _IsSynced = false;
|
||||
bool _IsGuest = false;
|
||||
TSetOfVehicleData _VehicleData;
|
||||
std::string _Name = "Unknown Client";
|
||||
SOCKET _Socket[2] { SOCKET(-1) };
|
||||
sockaddr_in _UDPAddress;
|
||||
std::string _Role;
|
||||
std::string _DID;
|
||||
int _Status = 0;
|
||||
int _ID = -1;
|
||||
TServer& mServer;
|
||||
bool mIsConnected = false;
|
||||
bool mIsSynced = false;
|
||||
bool mIsGuest = false;
|
||||
TSetOfVehicleData mVehicleData;
|
||||
std::string mName = "Unknown Client";
|
||||
SOCKET mSocket[2] { SOCKET(-1) };
|
||||
sockaddr_in mUDPAddress {}; // is this initialization OK?
|
||||
std::string mRole;
|
||||
std::string mDID;
|
||||
int mStatus = 0;
|
||||
int mID = -1;
|
||||
};
|
||||
|
||||
@@ -76,3 +76,8 @@ static inline void debug(const std::string& str) {
|
||||
static inline void luaprint(const std::string& str) {
|
||||
Application::Console().Write(std::string("[LUA] ") + str);
|
||||
}
|
||||
|
||||
#define Biggest 30000
|
||||
std::string Comp(std::string Data);
|
||||
std::string DeComp(std::string Compressed);
|
||||
|
||||
|
||||
@@ -4,13 +4,18 @@
|
||||
|
||||
#ifdef __unix
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
using SOCKET = int;
|
||||
using DWORD = unsigned long;
|
||||
using PDWORD = unsigned long*;
|
||||
using LPDWORD = unsigned long*;
|
||||
char _getch(void);
|
||||
char _getch();
|
||||
inline void CloseSocketProper(int socket) {
|
||||
shutdown(socket, SHUT_RDWR);
|
||||
close(socket);
|
||||
}
|
||||
#endif // unix
|
||||
|
||||
// ======================= WIN32 =======================
|
||||
@@ -18,6 +23,10 @@ char _getch(void);
|
||||
#ifdef WIN32
|
||||
#include <conio.h>
|
||||
#include <windows.h>
|
||||
inline void CloseSocketProper(int socket) {
|
||||
shutdown(socket, SHUT_RDWR);
|
||||
close(socket);
|
||||
}
|
||||
#endif // WIN32
|
||||
|
||||
// ======================= OTHER =======================
|
||||
@@ -25,4 +34,3 @@ char _getch(void);
|
||||
#if !defined(WIN32) && !defined(__unix)
|
||||
#error "OS not supported"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -10,8 +10,11 @@ public:
|
||||
|
||||
void operator()() override;
|
||||
|
||||
private:
|
||||
void SetInternalPPS(int NewPPS) { mInternalPPS = NewPPS; }
|
||||
void IncrementInternalPPS() { ++mInternalPPS; }
|
||||
[[nodiscard]] int InternalPPS() const { return mInternalPPS; }
|
||||
|
||||
private:
|
||||
TServer& mServer;
|
||||
bool mShutdown { false };
|
||||
int mInternalPPS { 0 };
|
||||
|
||||
14
include/TTCPServer.h
Normal file
14
include/TTCPServer.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "Common.h"
|
||||
#include "Compat.h"
|
||||
#include "IThreaded.h"
|
||||
#include "TServer.h"
|
||||
|
||||
class TTCPServer : public IThreaded {
|
||||
public:
|
||||
explicit TTCPServer(TServer& Server);
|
||||
|
||||
private:
|
||||
TServer& mServer;
|
||||
};
|
||||
26
include/TUDPServer.h
Normal file
26
include/TUDPServer.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#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);
|
||||
|
||||
void operator()() override;
|
||||
|
||||
void UDPSend(TClient& Client, std::string Data) const;
|
||||
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;
|
||||
std::string UDPRcvFromClient(sockaddr_in& client) const;
|
||||
};
|
||||
Reference in New Issue
Block a user