mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-01 23:35:41 +00:00
Added lua GetIdentifiers
This commit is contained in:
parent
7410e31230
commit
f0abfcc0ef
@ -28,34 +28,36 @@ public:
|
||||
TVehicleDataLockPair GetAllCars();
|
||||
void SetName(const std::string& Name) { mName = Name; }
|
||||
void SetRoles(const std::string& Role) { mRole = Role; }
|
||||
void AddIdentifier(const std::string& ID) { mIdentifiers.insert(ID); };
|
||||
std::string GetCarData(int Ident);
|
||||
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() 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]; }
|
||||
[[nodiscard]] std::set<std::string> GetIdentifiers() const { return mIdentifiers; }
|
||||
[[nodiscard]] sockaddr_in GetUDPAddr() const { return mUDPAddress; }
|
||||
[[nodiscard]] SOCKET GetDownSock() const { return mSocket[1]; }
|
||||
[[nodiscard]] SOCKET GetTCPSock() const { return mSocket[0]; }
|
||||
[[nodiscard]] std::string GetRoles() const { return mRole; }
|
||||
[[nodiscard]] std::string GetName() const { return mName; }
|
||||
void SetID(int ID) { mID = ID; }
|
||||
int GetOpenCarID() const;
|
||||
int GetCarCount() const;
|
||||
[[nodiscard]] int GetOpenCarID() const;
|
||||
[[nodiscard]] int GetCarCount() const;
|
||||
void ClearCars();
|
||||
int GetStatus() const { return mStatus; }
|
||||
int GetID() const { return mID; }
|
||||
bool IsConnected() const { return mIsConnected; }
|
||||
bool IsSynced() const { return mIsSynced; }
|
||||
bool IsSyncing() const { return mIsSyncing; }
|
||||
bool IsGuest() const { return mIsGuest; }
|
||||
[[nodiscard]] int GetStatus() const { return mStatus; }
|
||||
[[nodiscard]] int GetID() const { return mID; }
|
||||
[[nodiscard]] bool IsConnected() const { return mIsConnected; }
|
||||
[[nodiscard]] bool IsSynced() const { return mIsSynced; }
|
||||
[[nodiscard]] bool IsSyncing() const { return mIsSyncing; }
|
||||
[[nodiscard]] bool IsGuest() const { return mIsGuest; }
|
||||
void SetIsGuest(bool NewIsGuest) { mIsGuest = NewIsGuest; }
|
||||
void SetIsSynced(bool NewIsSynced) { mIsSynced = NewIsSynced; }
|
||||
void SetIsSyncing(bool NewIsSyncing) { mIsSyncing = NewIsSyncing; }
|
||||
void EnqueueMissedPacketDuringSyncing(const std::string& Packet) { mMissedPacketsDuringSyncing.push(Packet); }
|
||||
size_t MissedPacketQueueSize() const { return mMissedPacketsDuringSyncing.size(); }
|
||||
[[nodiscard]] size_t MissedPacketQueueSize() const { return mMissedPacketsDuringSyncing.size(); }
|
||||
void SetIsConnected(bool NewIsConnected) { mIsConnected = NewIsConnected; }
|
||||
TServer& Server() const;
|
||||
[[nodiscard]] TServer& Server() const;
|
||||
void UpdatePingTime();
|
||||
int SecondsSinceLastPing();
|
||||
|
||||
@ -65,6 +67,7 @@ private:
|
||||
bool mIsSynced = false;
|
||||
bool mIsSyncing = false;
|
||||
std::queue<std::string> mMissedPacketsDuringSyncing;
|
||||
std::set<std::string> mIdentifiers;
|
||||
bool mIsGuest = false;
|
||||
std::mutex mVehicleDataMutex;
|
||||
TSetOfVehicleData mVehicleData;
|
||||
|
@ -60,9 +60,11 @@ void TClient::SetCarData(int Ident, const std::string& Data) {
|
||||
}
|
||||
DeleteCar(Ident);
|
||||
}
|
||||
|
||||
int TClient::GetCarCount() const {
|
||||
return int(mVehicleData.size());
|
||||
}
|
||||
|
||||
TServer& TClient::Server() const {
|
||||
return mServer;
|
||||
}
|
||||
|
@ -321,9 +321,30 @@ int lua_GetAllPlayers(lua_State* L) {
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
int lua_GetIdentifiers(lua_State* L){
|
||||
if(lua_isnumber(L,1)){
|
||||
auto MaybeClient = GetClient(Engine().Server(), int(lua_tonumber(L, 1)));
|
||||
if (MaybeClient && !MaybeClient.value().expired()) {
|
||||
auto IDs = MaybeClient.value().lock()->GetIdentifiers();
|
||||
if(IDs.empty())
|
||||
return 0;
|
||||
lua_newtable(L);
|
||||
for(const std::string& ID : IDs){
|
||||
lua_pushstring(L, ID.substr(0,ID.find(':')).c_str());
|
||||
lua_pushstring(L, ID.c_str());
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
}else
|
||||
return 0;
|
||||
}else{
|
||||
SendError(Engine(), L, "lua_GetIdentifiers wrong arguments");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lua_GetCars(lua_State* L) {
|
||||
int Args = lua_gettop(L);
|
||||
if (Args > 0 && lua_isnumber(L, 1)) {
|
||||
if (lua_isnumber(L, 1)) {
|
||||
int ID = int(lua_tonumber(L, 1));
|
||||
auto MaybeClient = GetClient(Engine().Server(), ID);
|
||||
if (MaybeClient && !MaybeClient.value().expired()) {
|
||||
@ -344,7 +365,7 @@ int lua_GetCars(lua_State* L) {
|
||||
} else
|
||||
return 0;
|
||||
} else {
|
||||
SendError(Engine(), L, ("GetPlayerVehicles not enough arguments"));
|
||||
SendError(Engine(), L, ("GetPlayerVehicles wrong arguments"));
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
@ -638,9 +659,11 @@ std::any CallFunction(TLuaFile* lua, const std::string& FuncName, std::shared_pt
|
||||
ClearStack(luaState);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void TLuaFile::SetPluginName(const std::string& Name) {
|
||||
mPluginName = Name;
|
||||
}
|
||||
|
||||
void TLuaFile::SetFileName(const std::string& Name) {
|
||||
mFileName = Name;
|
||||
}
|
||||
@ -648,6 +671,7 @@ void TLuaFile::SetFileName(const std::string& Name) {
|
||||
void TLuaFile::Load() {
|
||||
Assert(mLuaState);
|
||||
luaL_openlibs(mLuaState);
|
||||
lua_register(mLuaState, "GetPlayerIdentifiers", lua_GetIdentifiers);
|
||||
lua_register(mLuaState, "TriggerGlobalEvent", lua_TriggerEventG);
|
||||
lua_register(mLuaState, "TriggerLocalEvent", lua_TriggerEventL);
|
||||
lua_register(mLuaState, "TriggerClientEvent", lua_RemoteEvent);
|
||||
|
@ -8,10 +8,14 @@
|
||||
#include <any>
|
||||
#include <sstream>
|
||||
|
||||
#undef GetObject //Fixes Windows
|
||||
|
||||
#include "rapidjson/document.h"
|
||||
#include "rapidjson/stringbuffer.h"
|
||||
#include "rapidjson/writer.h"
|
||||
|
||||
|
||||
|
||||
namespace json = rapidjson;
|
||||
|
||||
TServer::TServer(int argc, char** argv) {
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include <Http.h>
|
||||
#include <cstring>
|
||||
|
||||
#undef GetObject //Fixes Windows
|
||||
|
||||
#include "rapidjson/document.h"
|
||||
#include "rapidjson/stringbuffer.h"
|
||||
#include "rapidjson/writer.h"
|
||||
@ -102,10 +104,15 @@ void TTCPServer::Authentication(SOCKET TCPSock) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (AuthResponse["username"].IsString() && AuthResponse["roles"].IsString() && AuthResponse["guest"].IsBool()) {
|
||||
if (AuthResponse["username"].IsString() && AuthResponse["roles"].IsString()
|
||||
&& AuthResponse["guest"].IsBool() && AuthResponse["identifiers"].IsArray()) {
|
||||
|
||||
Client->SetName(AuthResponse["username"].GetString());
|
||||
Client->SetRoles(AuthResponse["roles"].GetString());
|
||||
Client->SetIsGuest(AuthResponse["guest"].GetBool());
|
||||
for(const auto& ID : AuthResponse["identifiers"].GetArray()){
|
||||
Client->AddIdentifier(ID.GetString());
|
||||
}
|
||||
} else {
|
||||
ClientKick(*Client, "Invalid authentication data!");
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user