Add kick, fix cmakelists pretending to be on linux all the time

lol
This commit is contained in:
Lion Kortlepel
2021-11-29 01:34:35 +01:00
parent 19d67dee95
commit 8f77f1c8c0
3 changed files with 41 additions and 8 deletions

View File

@@ -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")
add_compile_definitions(CPPHTTPLIB_OPENSSL_SUPPORT __linux)
add_compile_definitions(CPPHTTPLIB_OPENSSL_SUPPORT)
if(APPLE)
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)
link_directories(/usr/local/Cellar/lua@5.3/5.3.6/lib)
link_directories(/usr/local/opt/openssl@1.1/lib)
add_compile_definitions(__linux)
endif()
if (WIN32)

View File

@@ -2,6 +2,7 @@
#include "Common.h"
#include "Compat.h"
#include "Client.h"
#include "CustomAssert.h"
#include "LuaAPI.h"
#include "TLuaEngine.h"
@@ -143,15 +144,44 @@ void TConsole::Command_Lua(const std::string& cmd) {
void TConsole::Command_Help(const std::string&) {
static constexpr const char* sHelpString = R"(
Commands:
help displays this help
exit shuts down the server
lua [state id] switches to lua, optionally into a specific state id's lua
help displays this help
exit shuts down the server
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));
}
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) {
@@ -182,8 +212,10 @@ void TConsole::RunAsCommand(const std::string& cmd, bool IgnoreNotACommand) {
}
}
}
if (NonNilFutures.size() == 0 && !IgnoreNotACommand) {
Application::Console().WriteRaw("Error: Unknown command: '" + cmd + "'");
if (NonNilFutures.size() == 0) {
if (!IgnoreNotACommand) {
Application::Console().WriteRaw("Error: Unknown command: '" + cmd + "'");
}
} else {
std::stringstream Reply;
if (NonNilFutures.size() > 1) {

View File

@@ -460,7 +460,7 @@ TLuaEngine::StateThreadData::StateThreadData(const std::string& Name, std::atomi
MPTable.set_function("TriggerClientEvent", &LuaAPI::MP::TriggerClientEvent);
MPTable.set_function("GetPlayerCount", &LuaAPI::MP::GetPlayerCount);
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);
});
MPTable.set_function("GetPlayerName", [&](int ID) -> std::string {