mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-02-16 10:41:01 +00:00
Lua: Implement most API functions
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
@@ -98,3 +99,5 @@ private:
|
||||
int mID = -1;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> mLastPingTime;
|
||||
};
|
||||
|
||||
std::optional<std::weak_ptr<TClient>> GetClient(class TServer& Server, int ID);
|
||||
|
||||
@@ -10,5 +10,14 @@ namespace MP {
|
||||
|
||||
std::string GetOSName();
|
||||
std::tuple<int, int, int> GetServerVersion();
|
||||
bool TriggerClientEvent(int PlayerID, const std::string& EventName, const std::string& Data);
|
||||
size_t GetPlayerCount() { return Engine->Server().ClientCount(); }
|
||||
void DropPlayer(int ID, std::optional<std::string> MaybeReason);
|
||||
void SendChatMessage(int ID, const std::string& Message);
|
||||
void RemoveVehicle(int PlayerID, int VehicleID);
|
||||
void Set(int ConfigID, sol::object NewValue);
|
||||
bool GetPlayerGuest(int ID);
|
||||
bool IsPlayerConnected(int ID);
|
||||
void Sleep(size_t Ms);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,9 @@ public:
|
||||
|
||||
void operator()() override;
|
||||
|
||||
TNetwork& Network() { return mNetwork; }
|
||||
TServer& Server() { return mServer; }
|
||||
|
||||
[[nodiscard]] std::shared_ptr<TLuaResult> EnqueueScript(TLuaStateId StateID, const std::shared_ptr<std::string>& Script);
|
||||
[[nodiscard]] std::shared_ptr<TLuaResult> EnqueueFunctionCall(TLuaStateId StateID, const std::string& FunctionName);
|
||||
void EnsureStateExists(TLuaStateId StateId, const std::string& Name, bool DontCallOnInit = false);
|
||||
@@ -70,11 +73,13 @@ private:
|
||||
[[nodiscard]] std::shared_ptr<TLuaResult> EnqueueFunctionCall(const std::string& FunctionName);
|
||||
void RegisterEvent(const std::string& EventName, const std::string& FunctionName);
|
||||
void operator()() override;
|
||||
|
||||
|
||||
private:
|
||||
sol::table Lua_TriggerGlobalEvent(const std::string& EventName);
|
||||
sol::table Lua_TriggerLocalEvent(const std::string& EventName);
|
||||
|
||||
sol::table Lua_GetPlayerIdentifiers(int ID);
|
||||
sol::table Lua_GetPlayers();
|
||||
|
||||
std::string mName;
|
||||
std::atomic_bool& mShutdown;
|
||||
TLuaStateId mStateId;
|
||||
@@ -85,6 +90,7 @@ private:
|
||||
std::queue<std::pair<std::string, std::shared_ptr<TLuaResult>>> mStateFunctionQueue;
|
||||
std::recursive_mutex mStateFunctionQueueMutex;
|
||||
TLuaEngine* mEngine;
|
||||
sol::state_view mStateView { mState };
|
||||
};
|
||||
|
||||
TNetwork& mNetwork;
|
||||
|
||||
Reference in New Issue
Block a user