mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-04 00:36:14 +00:00
Lua function revisions
This commit is contained in:
parent
354ff30b90
commit
3d29067cab
@ -63,11 +63,7 @@ int lua_RegisterEvent(lua_State *L)
|
|||||||
Lua* Script = GetScript(L);
|
Lua* Script = GetScript(L);
|
||||||
if(Args == 2 && lua_isstring(L,1) && lua_isstring(L,2)){
|
if(Args == 2 && lua_isstring(L,1) && lua_isstring(L,2)){
|
||||||
Script->RegisterEvent(lua_tostring(L,1),lua_tostring(L,2));
|
Script->RegisterEvent(lua_tostring(L,1),lua_tostring(L,2));
|
||||||
}else if(Args > 2){
|
}else SendError(L,"RegisterEvent invalid argument count expected 2 got " + std::to_string(Args));
|
||||||
SendError(L,"RegisterEvent too many arguments");
|
|
||||||
}else if(Args < 2){
|
|
||||||
SendError(L,"RegisterEvent not enough arguments");
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int lua_TriggerEventL(lua_State *L)
|
int lua_TriggerEventL(lua_State *L)
|
||||||
@ -81,7 +77,7 @@ int lua_TriggerEventL(lua_State *L)
|
|||||||
SendError(L,"TriggerLocalEvent wrong argument [1] need string");
|
SendError(L,"TriggerLocalEvent wrong argument [1] need string");
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
SendError(L,"TriggerLocalEvent not enough arguments");
|
SendError(L,"TriggerLocalEvent not enough arguments expected 1 got 0");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -170,7 +166,7 @@ int lua_GetDID(lua_State *L){
|
|||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
int lua_GetAllIDs(lua_State *L){
|
int lua_GetAllPlayers(lua_State *L){
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
int i = 1;
|
int i = 1;
|
||||||
for (Client *c : Clients) {
|
for (Client *c : Clients) {
|
||||||
@ -186,15 +182,15 @@ int lua_GetCars(lua_State *L){
|
|||||||
if(lua_isnumber(L,1)){
|
if(lua_isnumber(L,1)){
|
||||||
int ID = lua_tonumber(L, 1);
|
int ID = lua_tonumber(L, 1);
|
||||||
Client*c = GetClient(ID);
|
Client*c = GetClient(ID);
|
||||||
|
|
||||||
if(c != nullptr){
|
if(c != nullptr){
|
||||||
int i = 1;
|
int i = 1;
|
||||||
for (const std::pair<int,std::string> &a : c->GetAllCars()) {
|
for (const std::pair<int,std::string> &a : c->GetAllCars()) {
|
||||||
lua_pushinteger(L, a.first);
|
lua_pushinteger(L, a.first);
|
||||||
lua_pushstring(L, a.second.c_str());
|
lua_pushstring(L, a.second.substr(3).c_str());
|
||||||
lua_settable(L,-3);
|
lua_settable(L,-3);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
if(c->GetAllCars().empty())return 0;
|
||||||
}else return 0;
|
}else return 0;
|
||||||
}else{
|
}else{
|
||||||
SendError(L,"GetPlayerVehicles not enough arguments");
|
SendError(L,"GetPlayerVehicles not enough arguments");
|
||||||
@ -204,11 +200,16 @@ int lua_GetCars(lua_State *L){
|
|||||||
}
|
}
|
||||||
void Respond(Client*c, const std::string& MSG, bool Rel);
|
void Respond(Client*c, const std::string& MSG, bool Rel);
|
||||||
int lua_dropPlayer(lua_State *L){
|
int lua_dropPlayer(lua_State *L){
|
||||||
|
int Args = lua_gettop(L);
|
||||||
if(lua_isnumber(L,1)){
|
if(lua_isnumber(L,1)){
|
||||||
int ID = lua_tonumber(L, 1);
|
int ID = lua_tonumber(L, 1);
|
||||||
Client*c = GetClient(ID);
|
Client*c = GetClient(ID);
|
||||||
|
std::string Reason;
|
||||||
|
if(Args > 1 && lua_isstring(L,2)){
|
||||||
|
Reason = std::string(" Reason : ")+lua_tostring(L,2);
|
||||||
|
}
|
||||||
if(c != nullptr){
|
if(c != nullptr){
|
||||||
Respond(c,"C:Server:You have been Kicked from the server!",true);
|
Respond(c,"C:Server:You have been Kicked from the server!" + Reason,true);
|
||||||
c->SetStatus(-2);
|
c->SetStatus(-2);
|
||||||
closesocket(c->GetTCPSock());
|
closesocket(c->GetTCPSock());
|
||||||
}
|
}
|
||||||
@ -234,11 +235,30 @@ int lua_sendChat(lua_State *L){
|
|||||||
}else SendError(L,"SendChatMessage invalid argument [1] expected number");
|
}else SendError(L,"SendChatMessage invalid argument [1] expected number");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
int lua_RemoveVehicle(lua_State *L){
|
||||||
|
int Args = lua_gettop(L);
|
||||||
|
if(Args != 2){
|
||||||
|
SendError(L,"RemoveVehicle invalid argument count expected 2 got " + std::to_string(Args));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if((lua_isinteger(L,1) || lua_isnumber(L,1)) && (lua_isinteger(L,2) || lua_isnumber(L,2))){
|
||||||
|
int PID = lua_tointeger(L,1);
|
||||||
|
int VID = lua_tointeger(L,2);
|
||||||
|
Client *c = GetClient(PID);
|
||||||
|
if(c != nullptr){
|
||||||
|
if(!c->GetCarData(VID).empty()){
|
||||||
|
std::string Destroy = "Od:" + std::to_string(PID)+"-"+std::to_string(VID);
|
||||||
|
SendToAll(nullptr,Destroy,true,true);
|
||||||
|
c->DeleteCar(VID);
|
||||||
|
}
|
||||||
|
}else SendError(L,"RemoveVehicle invalid Player ID");
|
||||||
|
}else SendError(L,"RemoveVehicle invalid argument expected number");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int lua_HWID(lua_State *L){
|
int lua_HWID(lua_State *L){
|
||||||
lua_pushinteger(L, -1);
|
lua_pushinteger(L, -1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lua::Init(){
|
void Lua::Init(){
|
||||||
luaL_openlibs(luaState);
|
luaL_openlibs(luaState);
|
||||||
lua_register(luaState,"TriggerGlobalEvent",lua_TriggerEventG);
|
lua_register(luaState,"TriggerGlobalEvent",lua_TriggerEventG);
|
||||||
@ -247,12 +267,13 @@ void Lua::Init(){
|
|||||||
lua_register(luaState,"isPlayerConnected",lua_isConnected);
|
lua_register(luaState,"isPlayerConnected",lua_isConnected);
|
||||||
lua_register(luaState,"RegisterEvent",lua_RegisterEvent);
|
lua_register(luaState,"RegisterEvent",lua_RegisterEvent);
|
||||||
lua_register(luaState,"GetPlayerName",lua_GetPlayerName);
|
lua_register(luaState,"GetPlayerName",lua_GetPlayerName);
|
||||||
|
lua_register(luaState,"RemoveVehicle",lua_RemoveVehicle);
|
||||||
lua_register(luaState,"GetPlayerDiscordID",lua_GetDID);
|
lua_register(luaState,"GetPlayerDiscordID",lua_GetDID);
|
||||||
lua_register(luaState,"GetPlayerVehicles",lua_GetCars);
|
lua_register(luaState,"GetPlayerVehicles",lua_GetCars);
|
||||||
lua_register(luaState,"CreateThread",lua_CreateThread);
|
lua_register(luaState,"CreateThread",lua_CreateThread);
|
||||||
lua_register(luaState,"SendChatMessage",lua_sendChat);
|
lua_register(luaState,"SendChatMessage",lua_sendChat);
|
||||||
|
lua_register(luaState,"GetPlayers",lua_GetAllPlayers);
|
||||||
lua_register(luaState,"DropPlayer",lua_dropPlayer);
|
lua_register(luaState,"DropPlayer",lua_dropPlayer);
|
||||||
lua_register(luaState,"GetPlayers",lua_GetAllIDs);
|
|
||||||
lua_register(luaState,"GetPlayerHWID",lua_HWID);
|
lua_register(luaState,"GetPlayerHWID",lua_HWID);
|
||||||
lua_register(luaState,"Sleep",lua_Sleep);
|
lua_register(luaState,"Sleep",lua_Sleep);
|
||||||
Reload();
|
Reload();
|
||||||
|
@ -21,6 +21,7 @@ private:
|
|||||||
int Status = 0;
|
int Status = 0;
|
||||||
int ID = -1; //PlayerID
|
int ID = -1; //PlayerID
|
||||||
public:
|
public:
|
||||||
|
bool isDownloading = true;
|
||||||
std::set<std::pair<int,std::string>> GetAllCars();
|
std::set<std::pair<int,std::string>> GetAllCars();
|
||||||
void AddNewCar(int ident,const std::string& Data);
|
void AddNewCar(int ident,const std::string& Data);
|
||||||
void SetName(const std::string& name);
|
void SetName(const std::string& name);
|
||||||
|
@ -36,6 +36,7 @@ void SendToAll(Client*c, const std::string& Data, bool Self, bool Rel){
|
|||||||
char C = Data.at(0);
|
char C = Data.at(0);
|
||||||
for(Client*client : Clients){
|
for(Client*client : Clients){
|
||||||
if(Self || client != c){
|
if(Self || client != c){
|
||||||
|
if(!client->isDownloading){
|
||||||
if(Rel){
|
if(Rel){
|
||||||
if(C == 'C' || C == 'O' || C == 'T' || Data.length() > 1000)SendLarge(client,Data);
|
if(C == 'C' || C == 'O' || C == 'T' || Data.length() > 1000)SendLarge(client,Data);
|
||||||
else TCPSend(client,Data);
|
else TCPSend(client,Data);
|
||||||
@ -43,6 +44,7 @@ void SendToAll(Client*c, const std::string& Data, bool Self, bool Rel){
|
|||||||
else UDPSend(client,Data);
|
else UDPSend(client,Data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdatePlayers(){
|
void UpdatePlayers(){
|
||||||
|
@ -114,4 +114,5 @@ bool STCPRecv(Client*c){
|
|||||||
}
|
}
|
||||||
void SyncResources(Client*c){
|
void SyncResources(Client*c){
|
||||||
while(c->GetStatus() > -1 && STCPRecv(c));
|
while(c->GetStatus() > -1 && STCPRecv(c));
|
||||||
|
c->isDownloading = false;
|
||||||
}
|
}
|
@ -17,8 +17,8 @@ void ParseConfig();
|
|||||||
void addToLog(const std::string& Data);
|
void addToLog(const std::string& Data);
|
||||||
//void ServerMain(int Port, int MaxClients);
|
//void ServerMain(int Port, int MaxClients);
|
||||||
void HeartbeatInit();
|
void HeartbeatInit();
|
||||||
std::string ServerVersion = "0.3";
|
std::string ServerVersion = "0.4";
|
||||||
std::string ClientVersion = "1.3+";
|
std::string ClientVersion = "1.4+";
|
||||||
std::string CustomIP;
|
std::string CustomIP;
|
||||||
void HandleResources(std::string path);
|
void HandleResources(std::string path);
|
||||||
void StatInit();
|
void StatInit();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user