Files
csgo2_tiny_server_plugin_sy…/csgo2/sdk_tools.cpp

56 lines
1.5 KiB
C++
Raw Normal View History

2023-10-02 17:31:02 +08:00
#include "sdk_tools.h"
namespace SdkTools {
2023-10-06 05:08:40 +08:00
auto ProcessChatString(const std::string& input)
-> std::tuple<bool, _ChatType, std::string> {
_ChatType chatType;
std::string content;
bool success = true;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD> "say_team" <20><> "say" <20><>ͷ
if (input.size() >= 9 && input.substr(0, 9) == "say_team ") {
chatType = _ChatType::kTeam;
content = input.substr(9);
} else if (input.size() >= 5 && input.substr(0, 4) == "say ") {
chatType = _ChatType::kAll;
content = input.substr(4);
} else {
success = false;
}
if (success == true) {
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ű<EFBFBD>Χ
if (content.front() != '"' || content.back() != '"') {
2023-10-02 17:31:02 +08:00
success = false;
2023-10-06 05:08:40 +08:00
} else {
// <20>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD>
content = content.substr(1, content.size() - 2);
2023-10-02 17:31:02 +08:00
}
2023-10-06 05:08:40 +08:00
}
return std::make_tuple(success, chatType, content);
}
auto SentChatToClient(CCSPlayerController* player, _HubType hubtype, const char* msg, ...) -> void {
va_list args;
va_start(args, msg);
char buf[256];
vsnprintf(buf, sizeof(buf), msg, args);
va_end(args);
2023-10-19 03:16:12 +08:00
Offset::FnClientPrint(player, static_cast<int>(hubtype), buf, nullptr, nullptr, nullptr, nullptr);
2023-10-06 05:08:40 +08:00
}
auto SendConsoleChat(_HubType hubtype, const char* msg, ...) -> void
{
va_list args;
va_start(args, msg);
char buf[256];
vsnprintf(buf, sizeof(buf), msg, args);
va_end(args);
2023-10-02 17:31:02 +08:00
2023-10-19 03:16:12 +08:00
Offset::FnUTIL_ClientPrintAll(static_cast<int>(hubtype), buf, nullptr, nullptr, nullptr, nullptr);
2023-10-06 05:08:40 +08:00
}
}; // namespace SdkTools