[Chat]: Check client number from input (#872)
This commit is contained in:
parent
b4500226dd
commit
655b7fe913
@ -451,7 +451,7 @@ namespace Components
|
|||||||
Utils::Hook::Set<DWORD>(0x4D0D60, 0xC301B0);
|
Utils::Hook::Set<DWORD>(0x4D0D60, 0xC301B0);
|
||||||
|
|
||||||
// Guid command
|
// Guid command
|
||||||
Command::Add("guid", [](Command::Params*)
|
Command::Add("guid", []
|
||||||
{
|
{
|
||||||
Logger::Print("Your guid: {:#X}\n", Steam::SteamUser()->GetSteamID().bits);
|
Logger::Print("Your guid: {:#X}\n", Steam::SteamUser()->GetSteamID().bits);
|
||||||
});
|
});
|
||||||
|
@ -259,17 +259,17 @@ namespace Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto num = std::atoi(input);
|
const auto clientNum = std::strtoul(input, nullptr, 10);
|
||||||
if (num < 0 || num >= *Game::svs_clientCount)
|
if (clientNum >= Game::MAX_CLIENTS)
|
||||||
{
|
{
|
||||||
Logger::Print("Bad client slot: {}\n", num);
|
Logger::Print("Bad client slot: {}\n", clientNum);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto* cl = &Game::svs_clients[num];
|
const auto* cl = &Game::svs_clients[clientNum];
|
||||||
if (cl->header.state == Game::CS_FREE)
|
if (cl->header.state < Game::CS_ACTIVE)
|
||||||
{
|
{
|
||||||
Logger::Print("Client {} is not active\n", num);
|
Logger::Print("Client {} is not active\n", clientNum);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,7 +279,7 @@ namespace Components
|
|||||||
}
|
}
|
||||||
|
|
||||||
const std::string reason = params->size() < 3 ? "EXE_ERR_BANNED_PERM" : params->join(2);
|
const std::string reason = params->size() < 3 ? "EXE_ERR_BANNED_PERM" : params->join(2);
|
||||||
BanClient(&Game::svs_clients[num], reason);
|
BanClient(&Game::svs_clients[clientNum], reason);
|
||||||
});
|
});
|
||||||
|
|
||||||
Command::Add("unbanClient", [](Command::Params* params)
|
Command::Add("unbanClient", [](Command::Params* params)
|
||||||
@ -309,7 +309,7 @@ namespace Components
|
|||||||
else if (type == "guid"s)
|
else if (type == "guid"s)
|
||||||
{
|
{
|
||||||
SteamID id;
|
SteamID id;
|
||||||
id.bits = strtoull(params->get(2), nullptr, 16);
|
id.bits = std::strtoull(params->get(2), nullptr, 16);
|
||||||
|
|
||||||
UnbanClient(id);
|
UnbanClient(id);
|
||||||
|
|
||||||
|
@ -461,8 +461,8 @@ namespace Components
|
|||||||
|
|
||||||
if (params->size() < 2) return;
|
if (params->size() < 2) return;
|
||||||
|
|
||||||
auto message = params->join(1);
|
const auto message = params->join(1);
|
||||||
auto name = sv_sayName.get<std::string>();
|
const auto name = sv_sayName.get<std::string>();
|
||||||
|
|
||||||
if (!name.empty())
|
if (!name.empty())
|
||||||
{
|
{
|
||||||
@ -486,19 +486,21 @@ namespace Components
|
|||||||
|
|
||||||
if (params->size() < 3) return;
|
if (params->size() < 3) return;
|
||||||
|
|
||||||
const auto client = std::atoi(params->get(1));
|
const auto parsedInput = std::strtoul(params->get(1), nullptr, 10);
|
||||||
auto message = params->join(2);
|
const auto clientNum = static_cast<int>(std::min<std::size_t>(parsedInput, Game::MAX_CLIENTS));
|
||||||
auto name = sv_sayName.get<std::string>();
|
|
||||||
|
const auto message = params->join(2);
|
||||||
|
const auto name = sv_sayName.get<std::string>();
|
||||||
|
|
||||||
if (!name.empty())
|
if (!name.empty())
|
||||||
{
|
{
|
||||||
Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::Format("{:c} \"{}: {}\"", 0x68, name.data(), message));
|
Game::SV_GameSendServerCommand(clientNum, Game::SV_CMD_CAN_IGNORE, Utils::String::Format("{:c} \"{}: {}\"", 0x68, name.data(), message));
|
||||||
Logger::Print(Game::CON_CHANNEL_SERVER, "{} -> {}: {}\n", name, client, message);
|
Logger::Print(Game::CON_CHANNEL_SERVER, "{} -> {}: {}\n", name, clientNum, message);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::Format("{:c} \"Console: {}\"", 0x68, message));
|
Game::SV_GameSendServerCommand(clientNum, Game::SV_CMD_CAN_IGNORE, Utils::String::Format("{:c} \"Console: {}\"", 0x68, message));
|
||||||
Logger::Print(Game::CON_CHANNEL_SERVER, "Console -> {}: {}\n", client, message);
|
Logger::Print(Game::CON_CHANNEL_SERVER, "Console -> {}: {}\n", clientNum, message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -512,7 +514,7 @@ namespace Components
|
|||||||
|
|
||||||
if (params->size() < 2) return;
|
if (params->size() < 2) return;
|
||||||
|
|
||||||
auto message = params->join(1);
|
const auto message = params->join(1);
|
||||||
Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::Format("{:c} \"{}\"", 0x68, message));
|
Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::Format("{:c} \"{}\"", 0x68, message));
|
||||||
Logger::Print(Game::CON_CHANNEL_SERVER, "Raw: {}\n", message);
|
Logger::Print(Game::CON_CHANNEL_SERVER, "Raw: {}\n", message);
|
||||||
});
|
});
|
||||||
@ -527,10 +529,12 @@ namespace Components
|
|||||||
|
|
||||||
if (params->size() < 3) return;
|
if (params->size() < 3) return;
|
||||||
|
|
||||||
const auto client = atoi(params->get(1));
|
const auto parsedInput = std::strtoul(params->get(1), nullptr, 10);
|
||||||
std::string message = params->join(2);
|
const auto clientNum = static_cast<int>(std::min<std::size_t>(parsedInput, Game::MAX_CLIENTS));
|
||||||
Game::SV_GameSendServerCommand(client, Game::SV_CMD_CAN_IGNORE, Utils::String::Format("{:c} \"{}\"", 0x68, message));
|
|
||||||
Logger::Print(Game::CON_CHANNEL_SERVER, "Raw -> {}: {}\n", client, message);
|
const auto message = params->join(2);
|
||||||
|
Game::SV_GameSendServerCommand(clientNum, Game::SV_CMD_CAN_IGNORE, Utils::String::Format("{:c} \"{}\"", 0x68, message));
|
||||||
|
Logger::Print(Game::CON_CHANNEL_SERVER, "Raw -> {}: {}\n", clientNum, message);
|
||||||
});
|
});
|
||||||
|
|
||||||
sv_sayName = Dvar::Register<const char*>("sv_sayName", "^7Console", Game::DVAR_NONE, "The alias of the server when broadcasting a chat message");
|
sv_sayName = Dvar::Register<const char*>("sv_sayName", "^7Console", Game::DVAR_NONE, "The alias of the server when broadcasting a chat message");
|
||||||
|
@ -57,16 +57,16 @@ namespace Components
|
|||||||
static Game::cmd_function_s* Allocate();
|
static Game::cmd_function_s* Allocate();
|
||||||
|
|
||||||
static void Add(const char* name, const std::function<void()>& callback);
|
static void Add(const char* name, const std::function<void()>& callback);
|
||||||
static void Add(const char* name, const std::function<void(Command::Params*)>& callback);
|
static void Add(const char* name, const std::function<void(Params*)>& callback);
|
||||||
static void AddRaw(const char* name, void(*callback)(), bool key = false);
|
static void AddRaw(const char* name, void(*callback)(), bool key = false);
|
||||||
static void AddSV(const char* name, const std::function<void(Command::Params*)>& callback);
|
static void AddSV(const char* name, const std::function<void(Params*)>& callback);
|
||||||
static void Execute(std::string command, bool sync = true);
|
static void Execute(std::string command, bool sync = true);
|
||||||
|
|
||||||
static Game::cmd_function_s* Find(const std::string& command);
|
static Game::cmd_function_s* Find(const std::string& command);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::unordered_map<std::string, std::function<void(Command::Params*)>> FunctionMap;
|
static std::unordered_map<std::string, std::function<void(Params*)>> FunctionMap;
|
||||||
static std::unordered_map<std::string, std::function<void(Command::Params*)>> FunctionMapSV;
|
static std::unordered_map<std::string, std::function<void(Params*)>> FunctionMapSV;
|
||||||
|
|
||||||
static void AddRawSV(const char* name, void(*callback)());
|
static void AddRawSV(const char* name, void(*callback)());
|
||||||
|
|
||||||
|
@ -226,7 +226,7 @@ namespace Components
|
|||||||
Command::Add("ipcping", []([[maybe_unused]] Command::Params* params)
|
Command::Add("ipcping", []([[maybe_unused]] Command::Params* params)
|
||||||
{
|
{
|
||||||
Logger::Print("Sending ping to pipe!\n");
|
Logger::Print("Sending ping to pipe!\n");
|
||||||
Write("ping", "");
|
Write("ping", {});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ namespace Components
|
|||||||
|
|
||||||
const char* data = Game::Scr_AddSourceBuffer(nullptr, file.getName().data(), nullptr, false);
|
const char* data = Game::Scr_AddSourceBuffer(nullptr, file.getName().data(), nullptr, false);
|
||||||
|
|
||||||
if (data != nullptr)
|
if (data)
|
||||||
{
|
{
|
||||||
Utils::IO::WriteFile("raw/" + file.getName(), data);
|
Utils::IO::WriteFile("raw/" + file.getName(), data);
|
||||||
Logger::Print("File '{}' written to raw!\n", file.getName());
|
Logger::Print("File '{}' written to raw!\n", file.getName());
|
||||||
|
@ -45,7 +45,7 @@ namespace Utils::String
|
|||||||
|
|
||||||
bool Compare(const std::string& lhs, const std::string& rhs)
|
bool Compare(const std::string& lhs, const std::string& rhs)
|
||||||
{
|
{
|
||||||
return std::ranges::equal(lhs, rhs, [](const unsigned char a, const unsigned char b)
|
return std::ranges::equal(lhs, rhs, [](const unsigned char a, const unsigned char b) -> bool
|
||||||
{
|
{
|
||||||
return std::tolower(a) == std::tolower(b);
|
return std::tolower(a) == std::tolower(b);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user