mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-21 23:50:32 +00:00
Add kick, fix cmakelists pretending to be on linux all the time
lol
This commit is contained in:
@@ -16,7 +16,7 @@ include_directories("${PROJECT_SOURCE_DIR}/deps/sol2/include")
|
|||||||
include_directories("${PROJECT_SOURCE_DIR}/deps/cpp-httplib")
|
include_directories("${PROJECT_SOURCE_DIR}/deps/cpp-httplib")
|
||||||
include_directories("${PROJECT_SOURCE_DIR}/deps")
|
include_directories("${PROJECT_SOURCE_DIR}/deps")
|
||||||
|
|
||||||
add_compile_definitions(CPPHTTPLIB_OPENSSL_SUPPORT __linux)
|
add_compile_definitions(CPPHTTPLIB_OPENSSL_SUPPORT)
|
||||||
|
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
set(LUA_INCLUDE_DIR /usr/local/Cellar/lua@5.3/5.3.6/include/lua5.3)
|
set(LUA_INCLUDE_DIR /usr/local/Cellar/lua@5.3/5.3.6/include/lua5.3)
|
||||||
@@ -24,6 +24,7 @@ if(APPLE)
|
|||||||
include_directories(/usr/local/opt/openssl@1.1/include)
|
include_directories(/usr/local/opt/openssl@1.1/include)
|
||||||
link_directories(/usr/local/Cellar/lua@5.3/5.3.6/lib)
|
link_directories(/usr/local/Cellar/lua@5.3/5.3.6/lib)
|
||||||
link_directories(/usr/local/opt/openssl@1.1/lib)
|
link_directories(/usr/local/opt/openssl@1.1/lib)
|
||||||
|
add_compile_definitions(__linux)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "Compat.h"
|
#include "Compat.h"
|
||||||
|
|
||||||
|
#include "Client.h"
|
||||||
#include "CustomAssert.h"
|
#include "CustomAssert.h"
|
||||||
#include "LuaAPI.h"
|
#include "LuaAPI.h"
|
||||||
#include "TLuaEngine.h"
|
#include "TLuaEngine.h"
|
||||||
@@ -143,15 +144,44 @@ void TConsole::Command_Lua(const std::string& cmd) {
|
|||||||
void TConsole::Command_Help(const std::string&) {
|
void TConsole::Command_Help(const std::string&) {
|
||||||
static constexpr const char* sHelpString = R"(
|
static constexpr const char* sHelpString = R"(
|
||||||
Commands:
|
Commands:
|
||||||
help displays this help
|
help displays this help
|
||||||
exit shuts down the server
|
exit shuts down the server
|
||||||
lua [state id] switches to lua, optionally into a specific state id's lua
|
kick <name> [reason] kicks specified player with an optional reason
|
||||||
|
list lists all players and info about them
|
||||||
|
say <message> sends the message to all players in chat
|
||||||
|
lua [state id] switches to lua, optionally into a specific state id's lua
|
||||||
)";
|
)";
|
||||||
Application::Console().WriteRaw("BeamMP-Server Console: " + std::string(sHelpString));
|
Application::Console().WriteRaw("BeamMP-Server Console: " + std::string(sHelpString));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TConsole::Command_Kick(const std::string& cmd) {
|
void TConsole::Command_Kick(const std::string& cmd) {
|
||||||
cmd.compare()
|
if (cmd.size() > 4) {
|
||||||
|
auto Name = cmd.substr(5);
|
||||||
|
std::string Reason = "Kicked by server console";
|
||||||
|
auto SpacePos = Name.find(' ');
|
||||||
|
if (SpacePos != Name.npos) {
|
||||||
|
Reason = Name.substr(SpacePos + 1);
|
||||||
|
Name = cmd.substr(5, cmd.size() - Reason.size() - 5 - 1);
|
||||||
|
}
|
||||||
|
beammp_trace("attempt to kick '" + Name + "' for '" + Reason + "'");
|
||||||
|
bool Kicked = false;
|
||||||
|
auto NameCompare = [](std::string Name1, std::string Name2) -> bool {
|
||||||
|
std::for_each(Name1.begin(), Name1.end(), [](char& c) { c = tolower(c); });
|
||||||
|
std::for_each(Name2.begin(), Name2.end(), [](char& c) { c = tolower(c); });
|
||||||
|
return StringStartsWith(Name1, Name2) || StringStartsWith(Name2, Name1);
|
||||||
|
};
|
||||||
|
mLuaEngine->Server().ForEachClient([&](std::weak_ptr<TClient> Client) -> bool {
|
||||||
|
if (!Client.expired()) {
|
||||||
|
auto locked = Client.lock();
|
||||||
|
if (NameCompare(locked->GetName(), Name)) {
|
||||||
|
mLuaEngine->Network().ClientKick(*locked, Reason);
|
||||||
|
Kicked = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TConsole::Command_Say(const std::string& cmd) {
|
void TConsole::Command_Say(const std::string& cmd) {
|
||||||
@@ -182,8 +212,10 @@ void TConsole::RunAsCommand(const std::string& cmd, bool IgnoreNotACommand) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (NonNilFutures.size() == 0 && !IgnoreNotACommand) {
|
if (NonNilFutures.size() == 0) {
|
||||||
Application::Console().WriteRaw("Error: Unknown command: '" + cmd + "'");
|
if (!IgnoreNotACommand) {
|
||||||
|
Application::Console().WriteRaw("Error: Unknown command: '" + cmd + "'");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
std::stringstream Reply;
|
std::stringstream Reply;
|
||||||
if (NonNilFutures.size() > 1) {
|
if (NonNilFutures.size() > 1) {
|
||||||
|
|||||||
@@ -460,7 +460,7 @@ TLuaEngine::StateThreadData::StateThreadData(const std::string& Name, std::atomi
|
|||||||
MPTable.set_function("TriggerClientEvent", &LuaAPI::MP::TriggerClientEvent);
|
MPTable.set_function("TriggerClientEvent", &LuaAPI::MP::TriggerClientEvent);
|
||||||
MPTable.set_function("GetPlayerCount", &LuaAPI::MP::GetPlayerCount);
|
MPTable.set_function("GetPlayerCount", &LuaAPI::MP::GetPlayerCount);
|
||||||
MPTable.set_function("IsPlayerConnected", &LuaAPI::MP::IsPlayerConnected);
|
MPTable.set_function("IsPlayerConnected", &LuaAPI::MP::IsPlayerConnected);
|
||||||
MPTable.set_function("GetPlayerIDByName", [&](const std::string& Name) -> std::string {
|
MPTable.set_function("GetPlayerIDByName", [&](const std::string& Name) -> int {
|
||||||
return Lua_GetPlayerIDByName(Name);
|
return Lua_GetPlayerIDByName(Name);
|
||||||
});
|
});
|
||||||
MPTable.set_function("GetPlayerName", [&](int ID) -> std::string {
|
MPTable.set_function("GetPlayerName", [&](int ID) -> std::string {
|
||||||
|
|||||||
Reference in New Issue
Block a user