Browse Source

Update Jupiter submodule; adjust code as necessary; general cleanup

master
Jessica James 3 years ago
parent
commit
7858c66518
  1. 2
      src/Jupiter
  2. 591
      src/Plugins/RenX/RenX.Core/RenX_Server.cpp
  3. 6
      src/Plugins/RenX/RenX.Core/RenX_Server.h
  4. 71
      src/Plugins/RenX/RenX.Ladder.Web/RenX_Ladder_Web.cpp
  5. 18
      src/Plugins/RenX/RenX.Ladder.Web/RenX_Ladder_Web.h
  6. 113
      src/Plugins/RenX/RenX.Relay/RenX_Relay.cpp
  7. 6
      src/Plugins/RenX/RenX.Relay/RenX_Relay.h
  8. 32
      src/Plugins/RenX/RenX.ServerList/RenX_ServerList.cpp
  9. 16
      src/Plugins/RenX/RenX.ServerList/RenX_ServerList.h

2
src/Jupiter

@ -1 +1 @@
Subproject commit 1827ab0047b5dcb8e88c096457c77c9d4177bd91
Subproject commit 714d660508381bc2ff3c775f95b5be11e9eabc68

591
src/Plugins/RenX/RenX.Core/RenX_Server.cpp

File diff suppressed because it is too large

6
src/Plugins/RenX/RenX.Core/RenX_Server.h

@ -1038,7 +1038,7 @@ namespace RenX
*
* @return String containing the RCON user name
*/
const Jupiter::ReadableString &getRCONUsername() const;
std::string_view getRCONUsername() const;
/**
* @brief Creates a server object using the provided socket, and loads settings from the specified configuration section.
@ -1110,7 +1110,7 @@ namespace RenX
std::chrono::steady_clock::time_point m_lastActivity = std::chrono::steady_clock::now();
std::chrono::steady_clock::time_point m_lastSendActivity = std::chrono::steady_clock::now();
std::chrono::steady_clock::time_point m_gameover_time;
Jupiter::String m_lastLine;
std::string m_lastLine;
Jupiter::StringS m_rconUser;
Jupiter::StringS m_gameVersion;
Jupiter::StringS m_serverName;
@ -1118,7 +1118,7 @@ namespace RenX
Jupiter::StringS m_lastCommandParams;
RenX::Map m_map;
Jupiter::TCPSocket m_sock;
Jupiter::ReadableString::TokenizeResult<Jupiter::String_Strict> m_commandListFormat;
std::vector<std::string> m_commandListFormat;
std::vector<std::unique_ptr<RenX::GameCommand>> m_commands;
/** Configuration variables */

71
src/Plugins/RenX/RenX.Ladder.Web/RenX_Ladder_Web.cpp

@ -16,6 +16,7 @@
* Written by Jessica James <jessica.aj@outlook.com>
*/
#include "jessilib/unicode.hpp"
#include "Jupiter/IRC_Client.h"
#include "Jupiter/HTTP.h"
#include "Jupiter/HTTP_QueryString.h"
@ -23,6 +24,7 @@
#include "RenX_Tags.h"
#include "RenX_Ladder_Web.h"
using namespace std::literals;
using namespace Jupiter::literals;
bool RenX_Ladder_WebPlugin::initialize() {
@ -167,7 +169,7 @@ Jupiter::String generate_search(RenX::LadderDatabase *db) {
}
/** Database selector */
Jupiter::String generate_database_selector(RenX::LadderDatabase *db, const Jupiter::HTTP::HTMLFormResponse::TableType &query_params) {
Jupiter::String generate_database_selector(RenX::LadderDatabase *db, const Jupiter::HTTP::HTMLFormResponse& query_params) {
Jupiter::String result(256);
result = R"database-select(<form method="get" class="database-select-form"><select name="database" class="database-select">)database-select"_jrs;
@ -191,8 +193,8 @@ Jupiter::String generate_database_selector(RenX::LadderDatabase *db, const Jupit
}
}
auto value = query_params.find("id"_jrs);
if (value != query_params.end()) {
auto value = query_params.tableFind("id"sv);
if (value != query_params.table.end()) {
result += R"html(<input type="hidden" name="id" value=")html"_jrs;
result += value->second;
result += R"html("/>)html"_jrs;
@ -283,7 +285,7 @@ Jupiter::String RenX_Ladder_WebPlugin::generate_entry_table(RenX::LadderDatabase
return result;
}
Jupiter::String *RenX_Ladder_WebPlugin::generate_ladder_page(RenX::LadderDatabase *db, uint8_t format, size_t index, size_t count, const Jupiter::HTTP::HTMLFormResponse::TableType &query_params) {
Jupiter::String *RenX_Ladder_WebPlugin::generate_ladder_page(RenX::LadderDatabase *db, uint8_t format, size_t index, size_t count, const Jupiter::HTTP::HTMLFormResponse& query_params) {
Jupiter::String *result = new Jupiter::String(2048);
if ((format & this->FLAG_INCLUDE_PAGE_HEADER) != 0) // Header
@ -307,7 +309,7 @@ Jupiter::String *RenX_Ladder_WebPlugin::generate_ladder_page(RenX::LadderDatabas
// include_header | include_footer | include_any_headers | include_any_footers
/** Search page */
Jupiter::String *RenX_Ladder_WebPlugin::generate_search_page(RenX::LadderDatabase *db, uint8_t format, size_t start_index, size_t count, const Jupiter::ReadableString &name, const Jupiter::HTTP::HTMLFormResponse::TableType &query_params) {
Jupiter::String *RenX_Ladder_WebPlugin::generate_search_page(RenX::LadderDatabase *db, uint8_t format, size_t start_index, size_t count, std::string_view name, const Jupiter::HTTP::HTMLFormResponse& query_params) {
Jupiter::String *result = new Jupiter::String(2048);
if ((format & this->FLAG_INCLUDE_PAGE_HEADER) != 0) // Header
@ -335,7 +337,7 @@ Jupiter::String *RenX_Ladder_WebPlugin::generate_search_page(RenX::LadderDatabas
Jupiter::String row(256);
RenX::LadderDatabase::Entry *node = db->getHead();
while (node != nullptr) {
if (node->most_recent_name.findi(name) != Jupiter::INVALID_INDEX) { // match found
if (node->most_recent_name.findi(Jupiter::ReferenceString{name}) != Jupiter::INVALID_INDEX) { // match found
row = RenX_Ladder_WebPlugin::entry_table_row;
row.replace(RenX::tags->INTERNAL_OBJECT_TAG, db->getName());
RenX::processTags(row, *node);
@ -354,7 +356,7 @@ Jupiter::String *RenX_Ladder_WebPlugin::generate_search_page(RenX::LadderDatabas
}
/** Profile page */
Jupiter::String *RenX_Ladder_WebPlugin::generate_profile_page(RenX::LadderDatabase *db, uint8_t format, uint64_t steam_id, const Jupiter::HTTP::HTMLFormResponse::TableType &query_params) {
Jupiter::String *RenX_Ladder_WebPlugin::generate_profile_page(RenX::LadderDatabase *db, uint8_t format, uint64_t steam_id, const Jupiter::HTTP::HTMLFormResponse& query_params) {
Jupiter::String *result = new Jupiter::String(2048);
if ((format & this->FLAG_INCLUDE_PAGE_HEADER) != 0)
@ -418,7 +420,7 @@ Jupiter::String *RenX_Ladder_WebPlugin::generate_profile_page(RenX::LadderDataba
/** Content functions */
Jupiter::ReadableString *generate_no_db_page(const Jupiter::HTTP::HTMLFormResponse::TableType &query_params) {
Jupiter::ReadableString *generate_no_db_page(const Jupiter::HTTP::HTMLFormResponse& query_params) {
Jupiter::String *result = new Jupiter::String(pluginInstance.header);
if (RenX::ladder_databases.size() != 0) {
result->concat(generate_search(nullptr));
@ -432,22 +434,22 @@ Jupiter::ReadableString *generate_no_db_page(const Jupiter::HTTP::HTMLFormRespon
return result;
}
Jupiter::ReadableString *handle_ladder_page(const Jupiter::ReadableString &query_string) {
Jupiter::ReadableString *handle_ladder_page(std::string_view query_string) {
Jupiter::HTTP::HTMLFormResponse html_form_response(query_string);
RenX::LadderDatabase *db = RenX::default_ladder_database;
size_t start_index = 0, count = pluginInstance.getEntriesPerPage();
uint8_t format = 0xFF;
if (html_form_response.table.size() != 0) {
format = html_form_response.tableGetCast<uint8_t>("format"_jrs, format);
start_index = html_form_response.tableGetCast<size_t>("start"_jrs, start_index);
count = html_form_response.tableGetCast<size_t>("count"_jrs, count);
format = html_form_response.tableGetCast<uint8_t>("format"sv, format);
start_index = html_form_response.tableGetCast<size_t>("start"sv, start_index);
count = html_form_response.tableGetCast<size_t>("count"sv, count);
const Jupiter::ReadableString &db_name = html_form_response.tableGet("database"_jrs, Jupiter::ReferenceString::empty);
if (db_name.isNotEmpty()) {
std::string_view db_name = html_form_response.tableGet("database"sv, {});
if (!db_name.empty()) {
db = nullptr;
for (const auto& database : RenX::ladder_databases) {
if (database->getName().equalsi(db_name)) {
if (jessilib::equalsi(std::string_view{database->getName()}, db_name)) {
db = database;
break;
}
@ -456,29 +458,29 @@ Jupiter::ReadableString *handle_ladder_page(const Jupiter::ReadableString &query
}
if (db == nullptr)
return generate_no_db_page(html_form_response.table);
return generate_no_db_page(html_form_response);
return pluginInstance.generate_ladder_page(db, format, start_index, count, html_form_response.table);
return pluginInstance.generate_ladder_page(db, format, start_index, count, html_form_response);
}
Jupiter::ReadableString *handle_search_page(const Jupiter::ReadableString &query_string) {
Jupiter::ReadableString *handle_search_page(std::string_view query_string) {
Jupiter::HTTP::HTMLFormResponse html_form_response(query_string);
RenX::LadderDatabase *db = RenX::default_ladder_database;
uint8_t format = 0xFF;
size_t start_index = 0, count = pluginInstance.getEntriesPerPage();
Jupiter::ReferenceString name;
std::string_view name;
if (html_form_response.table.size() != 0) {
format = html_form_response.tableGetCast<uint8_t>("format"_jrs, format);
start_index = html_form_response.tableGetCast<size_t>("start"_jrs, start_index);
count = html_form_response.tableGetCast<size_t>("count"_jrs, count);
name = html_form_response.tableGet("name"_jrs, name);
format = html_form_response.tableGetCast<uint8_t>("format"sv, format);
start_index = html_form_response.tableGetCast<size_t>("start"sv, start_index);
count = html_form_response.tableGetCast<size_t>("count"sv, count);
name = html_form_response.tableGet("name"sv, name);
const Jupiter::ReadableString &db_name = html_form_response.tableGet("database"_jrs, Jupiter::ReferenceString::empty);
if (db_name.isNotEmpty()) {
std::string_view db_name = html_form_response.tableGet("database"sv, {});
if (!db_name.empty()) {
db = nullptr;
for (const auto& database : RenX::ladder_databases) {
if (database->getName().equalsi(db_name)) {
if (jessilib::equalsi(std::string_view{database->getName()}, db_name)) {
db = database;
break;
}
@ -487,15 +489,15 @@ Jupiter::ReadableString *handle_search_page(const Jupiter::ReadableString &query
}
if (db == nullptr)
return generate_no_db_page(html_form_response.table);
return generate_no_db_page(html_form_response);
if (name.size() < pluginInstance.getMinSearchNameLength()) // Generate ladder page when no name specified
return handle_ladder_page(query_string);
return pluginInstance.generate_search_page(db, format, start_index, count, name, html_form_response.table);
return pluginInstance.generate_search_page(db, format, start_index, count, name, html_form_response);
}
Jupiter::ReadableString *handle_profile_page(const Jupiter::ReadableString &query_string)
Jupiter::ReadableString *handle_profile_page(std::string_view query_string)
{
Jupiter::HTTP::HTMLFormResponse html_form_response(query_string);
RenX::LadderDatabase *db = RenX::default_ladder_database;
@ -507,12 +509,11 @@ Jupiter::ReadableString *handle_profile_page(const Jupiter::ReadableString &quer
format = html_form_response.tableGetCast<uint8_t>("format"_jrs, format);
steam_id = html_form_response.tableGetCast<uint64_t>("id"_jrs, steam_id);
const Jupiter::ReadableString &db_name = html_form_response.tableGet("database"_jrs, Jupiter::ReferenceString::empty);
if (db_name.isNotEmpty())
{
std::string_view db_name = html_form_response.tableGet("database"sv, {});
if (!db_name.empty()) {
db = nullptr;
for (const auto& database : RenX::ladder_databases) {
if (database->getName().equalsi(db_name)) {
if (jessilib::equalsi(std::string_view{database->getName()}, db_name)) {
db = database;
break;
}
@ -521,9 +522,9 @@ Jupiter::ReadableString *handle_profile_page(const Jupiter::ReadableString &quer
}
if (db == nullptr)
return generate_no_db_page(html_form_response.table);
return generate_no_db_page(html_form_response);
return pluginInstance.generate_profile_page(db, format, steam_id, html_form_response.table);
return pluginInstance.generate_profile_page(db, format, steam_id, html_form_response);
}
extern "C" JUPITER_EXPORT Jupiter::Plugin *getPlugin()

18
src/Plugins/RenX/RenX.Ladder.Web/RenX_Ladder_Web.h

@ -39,9 +39,9 @@ public:
Jupiter::StringS header;
Jupiter::StringS footer;
Jupiter::String *generate_ladder_page(RenX::LadderDatabase *db, uint8_t format, size_t start_index, size_t count, const Jupiter::HTTP::HTMLFormResponse::TableType &query_params);
Jupiter::String *generate_search_page(RenX::LadderDatabase *db, uint8_t format, size_t start_index, size_t count, const Jupiter::ReadableString &name, const Jupiter::HTTP::HTMLFormResponse::TableType &query_params);
Jupiter::String *generate_profile_page(RenX::LadderDatabase *db, uint8_t format, uint64_t steam_id, const Jupiter::HTTP::HTMLFormResponse::TableType &query_params);
Jupiter::String *generate_ladder_page(RenX::LadderDatabase *db, uint8_t format, size_t start_index, size_t count, const Jupiter::HTTP::HTMLFormResponse& query_params);
Jupiter::String *generate_search_page(RenX::LadderDatabase *db, uint8_t format, size_t start_index, size_t count, std::string_view name, const Jupiter::HTTP::HTMLFormResponse& query_params);
Jupiter::String *generate_profile_page(RenX::LadderDatabase *db, uint8_t format, uint64_t steam_id, const Jupiter::HTTP::HTMLFormResponse& query_params);
inline size_t getEntriesPerPage() const { return this->entries_per_page; }
inline size_t getMinSearchNameLength() const { return this->min_search_name_length; };
@ -57,9 +57,9 @@ private:
/** Configuration variables */
size_t entries_per_page;
size_t min_search_name_length;
Jupiter::StringS ladder_page_name, search_page_name, profile_page_name, ladder_table_header, ladder_table_footer;
Jupiter::StringS web_hostname;
Jupiter::StringS web_path;
std::string ladder_page_name, search_page_name, profile_page_name, ladder_table_header, ladder_table_footer;
std::string web_hostname;
std::string web_path;
std::string web_header_filename;
std::string web_footer_filename;
std::string web_profile_filename;
@ -69,8 +69,8 @@ private:
Jupiter::StringS entry_table_row, entry_profile, entry_profile_previous, entry_profile_next;
};
Jupiter::ReadableString *handle_ladder_page(const Jupiter::ReadableString &parameters);
Jupiter::ReadableString *handle_search_page(const Jupiter::ReadableString &parameters);
Jupiter::ReadableString *handle_profile_page(const Jupiter::ReadableString &parameters);
Jupiter::ReadableString *handle_ladder_page(std::string_view query_string);
Jupiter::ReadableString *handle_search_page(std::string_view query_string);
Jupiter::ReadableString *handle_profile_page(std::string_view query_string);
#endif // _RENX_LADDER_WEB_H

113
src/Plugins/RenX/RenX.Relay/RenX_Relay.cpp

@ -11,6 +11,9 @@
#include <unordered_set>
#include <cassert>
#include <fstream>
#include "fmt/format.h" // TODO: replace with <format> later
#include <charconv>
#include "jessilib/split.hpp"
#include "Jupiter/IRC.h"
#include "RenX_Functions.h"
#include "RenX_Server.h"
@ -62,18 +65,17 @@ int RenX_RelayPlugin::think() {
else {
// Connected and fine
if (upstream_socket->recv() > 0) { // Data received
auto& buffer = upstream_socket->getBuffer();
Jupiter::ReadableString::TokenizeResult<Jupiter::Reference_String> result = Jupiter::ReferenceString::tokenize(buffer, '\n');
if (result.token_count != 0) {
auto tokens = jessilib::split_view(upstream_socket->getBuffer(), '\n');
if (!tokens.empty()) {
server_info.m_last_activity = std::chrono::steady_clock::now();
server_info.m_last_line.concat(result.tokens[0]);
if (result.token_count != 1) {
server_info.m_last_line += tokens[0];
if (tokens.size() != 1) {
// Process upstream message received
process_upstream_message(server, server_info.m_last_line, server_info);
server_info.m_last_line = result.tokens[result.token_count - 1];
server_info.m_last_line = tokens[tokens.size() - 1];
for (size_t index = 1; index != result.token_count - 1; ++index) {
process_upstream_message(server, result.tokens[index], server_info);
for (size_t index = 1; index != tokens.size() - 1; ++index) {
process_upstream_message(server, tokens[index], server_info);
}
}
}
@ -279,10 +281,10 @@ std::string to_hex(T in_integer) {
void RenX_RelayPlugin::RenX_OnRaw(RenX::Server &server, const Jupiter::ReadableString &line) {
// Not parsing any escape sequences, so data gets sent upstream exactly as it's received here. Copy tokens where needed to process escape sequences.
Jupiter::ReadableString::TokenizeResult <Jupiter::String_Strict> tokens = Jupiter::StringS::tokenize(line, RenX::DelimC);
auto tokens = jessilib::split(std::string_view{line}, RenX::DelimC);
// Ensure valid message received
if (tokens.token_count == 0) {
if (tokens.empty()) {
return;
}
@ -294,12 +296,12 @@ void RenX_RelayPlugin::RenX_OnRaw(RenX::Server &server, const Jupiter::ReadableS
}
// Suppress unassociated command execution logs from going upstream
if (tokens.token_count >= 5
&& tokens.tokens[0] == "lRCON"
&& tokens.tokens[1] == "Command;"
&& tokens.tokens[3] == "executed:"
&& tokens.tokens[4].isNotEmpty()) {
if (tokens.tokens[2] != server.getRCONUsername()) {
if (tokens.size() >= 5
&& tokens[0] == "lRCON"
&& tokens[1] == "Command;"
&& tokens[3] == "executed:"
&& !tokens[4].empty()) {
if (tokens[2] != server.getRCONUsername()) {
if (m_default_settings.m_suppress_rcon_command_logs) { // TODO: move away from per-stream settings
// Suppress RCON command logs from other RCON users
return;
@ -313,7 +315,7 @@ void RenX_RelayPlugin::RenX_OnRaw(RenX::Server &server, const Jupiter::ReadableS
upstream_server_info* front_server_info = m_command_tracker.front();
if (front_server_info == nullptr
|| front_server_info->m_processing_command
|| tokens.tokens[4] != front_server_info->m_response_queue.front().m_command) {
|| tokens[4] != front_server_info->m_response_queue.front().m_command) {
// This command response wasn't requested by any current upstream connections; suppress it
return;
}
@ -331,13 +333,13 @@ void RenX_RelayPlugin::RenX_OnRaw(RenX::Server &server, const Jupiter::ReadableS
}
else {
// TODO: add assignment operators to Jupiter::string crap
tokens.tokens[2].set(rcon_username.data(), rcon_username.size());
tokens[2] = rcon_username;
// Construct line to send and send it
line_sanitized = tokens.tokens[0];
for (size_t index = 1; index != tokens.token_count; ++index) {
line_sanitized = tokens[0];
for (size_t index = 1; index != tokens.size(); ++index) {
line_sanitized += RenX::DelimC;
line_sanitized += tokens.tokens[index];
line_sanitized += tokens[index];
}
}
line_sanitized += '\n';
@ -355,7 +357,7 @@ void RenX_RelayPlugin::RenX_OnRaw(RenX::Server &server, const Jupiter::ReadableS
}
}
void RenX_RelayPlugin::process_renx_message(RenX::Server& server, upstream_server_info& server_info, const Jupiter::ReadableString& line, Jupiter::ReadableString::TokenizeResult<Jupiter::String_Strict> tokens) {
void RenX_RelayPlugin::process_renx_message(RenX::Server& server, upstream_server_info& server_info, std::string_view line, std::vector<std::string> tokens) {
bool required_sanitization = false;
if (!server_info.m_socket) {
// early out: no upstream RCON session
@ -364,21 +366,21 @@ void RenX_RelayPlugin::process_renx_message(RenX::Server& server, upstream_serve
const upstream_settings& settings = *server_info.m_settings;
if (settings.m_suppress_chat_logs
&& tokens.getToken(0) == "lCHAT") {
&& tokens[0] == "lCHAT") {
return;
}
// Suppress unassociated command responses from going upstream
if (tokens.tokens[0].isNotEmpty()
&& (tokens.tokens[0][0] == 'r' || tokens.tokens[0][0] == 'c')
if (!tokens[0].empty()
&& (tokens[0][0] == 'r' || tokens[0][0] == 'c')
&& !server_info.m_processing_command) {
// This command response wasn't requested upstream; suppress it
return;
}
auto findPlayerByIP = [&server](const Jupiter::ReadableString& in_ip) -> const RenX::PlayerInfo* {
auto findPlayerByIP = [&server](std::string in_ip) -> const RenX::PlayerInfo* {
// Parse into integer so we're doing int comparisons instead of strings
auto ip32 = Jupiter::Socket::pton4(static_cast<std::string>(in_ip).c_str());
auto ip32 = Jupiter::Socket::pton4(in_ip.c_str());
if (ip32 == 0) {
return nullptr;
}
@ -393,8 +395,8 @@ void RenX_RelayPlugin::process_renx_message(RenX::Server& server, upstream_serve
return nullptr;
};
auto findPlayerByHWID = [&server](const Jupiter::ReadableString& in_hwid) -> const RenX::PlayerInfo* {
if (in_hwid.isEmpty()) {
auto findPlayerByHWID = [&server](std::string_view in_hwid) -> const RenX::PlayerInfo* {
if (in_hwid.empty()) {
return nullptr;
}
@ -407,8 +409,9 @@ void RenX_RelayPlugin::process_renx_message(RenX::Server& server, upstream_serve
return nullptr;
};
auto findPlayerBySteamID = [&server](const Jupiter::ReadableString& in_steamid) -> const RenX::PlayerInfo* {
uint64_t steamid = in_steamid.asUnsignedLongLong();
auto findPlayerBySteamID = [&server](std::string_view in_steamid) -> const RenX::PlayerInfo* {
uint64_t steamid{};
std::from_chars(in_steamid.data(), in_steamid.data() + in_steamid.size(), steamid);
if (steamid == 0) {
return nullptr;
}
@ -423,19 +426,19 @@ void RenX_RelayPlugin::process_renx_message(RenX::Server& server, upstream_serve
};
if (settings.m_sanitize_names) {
for (size_t index = 0; index != tokens.token_count; ++index) {
auto& token = tokens.tokens[index];
if (is_player_token(token.ptr(), token.ptr() + token.size())) {
for (size_t index = 0; index != tokens.size(); ++index) {
auto& token = tokens[index];
if (is_player_token(token.data(), token.data() + token.size())) {
// Get token pieces
Jupiter::ReferenceString teamToken = Jupiter::ReferenceString::getToken(token, 0, ',');
Jupiter::ReferenceString idToken = Jupiter::ReferenceString::getToken(token, 1, ',');
auto player_tokens = jessilib::split_n_view(token, ',', 2);
std::string_view idToken = player_tokens[1];
Jupiter::StringS replacement_player = teamToken;
std::string replacement_player = static_cast<std::string>(player_tokens[0]);
replacement_player += ',';
replacement_player += idToken;
replacement_player += ',';
if (idToken.isNotEmpty() && idToken.get(0) == 'b') {
idToken.shiftRight(1);
if (!idToken.empty() && idToken.front() == 'b') {
idToken.remove_prefix(1);
}
// Name (sanitized)
@ -452,8 +455,8 @@ void RenX_RelayPlugin::process_renx_message(RenX::Server& server, upstream_serve
// It's way too much of a pain to check for command usages, and it's not full-proof either (an alias or similar could be added).
// So instead, we'll just search all messages for any tokens containing any player's IP or HWID.
// This isn't terribly efficient, but there's only up to 64 players, so not a huge concern
for (size_t index = 0; index != tokens.token_count; ++index) {
auto& token = tokens.tokens[index];
for (size_t index = 0; index != tokens.size(); ++index) {
auto& token = tokens[index];
const RenX::PlayerInfo* player;
if (settings.m_sanitize_ips) {
player = findPlayerByIP(token);
@ -464,7 +467,8 @@ void RenX_RelayPlugin::process_renx_message(RenX::Server& server, upstream_serve
std::uniform_int_distribution<uint32_t> dist(10, 200);
// Replace real IP with fake
token.format("%u.%u.%u.%u",
//token.format("%u.%u.%u.%u",
token = fmt::format("{}.{}.{}.{}",
static_cast<unsigned int>(dist(randgen)),
static_cast<unsigned int>(dist(randgen)),
static_cast<unsigned int>(dist(randgen)),
@ -506,13 +510,13 @@ void RenX_RelayPlugin::process_renx_message(RenX::Server& server, upstream_serve
}
}
Jupiter::StringS line_sanitized;
std::string line_sanitized;
if (required_sanitization) {
// Construct line to send and send it
line_sanitized = tokens.tokens[0];
for (size_t index = 1; index != tokens.token_count; ++index) {
line_sanitized = tokens[0];
for (size_t index = 1; index != tokens.size(); ++index) {
line_sanitized += RenX::DelimC;
line_sanitized += tokens.tokens[index];
line_sanitized += tokens[index];
}
}
else {
@ -666,17 +670,17 @@ void RenX_RelayPlugin::upstream_disconnected(RenX::Server&, upstream_server_info
}
}
void RenX_RelayPlugin::process_upstream_message(RenX::Server* in_server, const Jupiter::ReadableString& in_line, upstream_server_info& in_server_info) {
if (in_line.isEmpty()) {
void RenX_RelayPlugin::process_upstream_message(RenX::Server* in_server, std::string_view in_line, upstream_server_info& in_server_info) {
if (in_line.empty()) {
return;
}
if (in_line == 's') {
if (in_line.front() == 's') {
// we're already subscribed
return;
}
if (in_line[0] == 'a') {
if (in_line.front() == 'a') {
// we're already authenticated
return;
}
@ -695,10 +699,7 @@ void RenX_RelayPlugin::process_upstream_message(RenX::Server* in_server, const J
if (in_line[0] == 'c' && in_line.size() > 1) {
// Sanitize unknown & blacklisted commands
if (settings.m_suppress_unknown_commands || (settings.m_suppress_blacklisted_commands && !settings.m_fake_ignored_commands)) {
Jupiter::ReferenceString command_str = Jupiter::ReferenceString::getToken(in_line, 0, ' ');
command_str.shiftRight(1);
std::string_view command_view{ command_str.ptr(), command_str.size() };
std::string_view command_view = jessilib::split_once_view(in_line, ' ').first.substr(1);
if (settings.m_suppress_unknown_commands
&& g_known_commands.find(command_view) == g_known_commands.end()) {
// Command not in known commands list; ignore it
@ -731,7 +732,7 @@ void RenX_RelayPlugin::process_upstream_message(RenX::Server* in_server, const J
}
}
std::string_view command_line{ in_line.ptr() + 1, in_line.size() - 1 };
std::string_view command_line = in_line.substr(1);
std::string_view command_word = command_line.substr(0, std::min(command_line.find(' '), command_line.size()));
std::string command_word_lower;
command_word_lower.reserve(command_word.size());
@ -764,7 +765,7 @@ void RenX_RelayPlugin::process_upstream_message(RenX::Server* in_server, const J
}
// Send line to game server
Jupiter::StringS sanitized_message = in_line;
std::string sanitized_message = static_cast<std::string>(in_line);
sanitized_message += '\n';
send_downstream(*in_server, sanitized_message, in_server_info);
}

6
src/Plugins/RenX/RenX.Relay/RenX_Relay.h

@ -64,7 +64,7 @@ private:
bool m_connected{};
std::chrono::steady_clock::time_point m_last_connect_attempt{};
std::chrono::steady_clock::time_point m_last_activity{};
Jupiter::StringL m_last_line;
std::string m_last_line;
std::deque<UpstreamCommand> m_response_queue; // Contains both real & fake commands
bool m_processing_command{};
const upstream_settings* m_settings; // weak_ptr to upstream_settings owned by m_configured_upstreams
@ -79,8 +79,8 @@ private:
void upstream_connected(RenX::Server& in_server, upstream_server_info& in_server_info);
void upstream_disconnected(RenX::Server& in_server, upstream_server_info& in_server_info);
void process_upstream_message(RenX::Server* in_server, const Jupiter::ReadableString& in_line, upstream_server_info& in_server_info);
void process_renx_message(RenX::Server& server, upstream_server_info& in_server_info, const Jupiter::ReadableString &raw, Jupiter::ReadableString::TokenizeResult<Jupiter::String_Strict> tokens);
void process_upstream_message(RenX::Server* in_server, std::string_view in_line, upstream_server_info& in_server_info);
void process_renx_message(RenX::Server& server, upstream_server_info& in_server_info, std::string_view raw, std::vector<std::string> tokens);
std::unordered_map<RenX::Server*, std::vector<upstream_server_info>> m_server_info_map;
std::deque<upstream_server_info*> m_command_tracker; // Tracks the order of REAL commands executed across upstreams, to keep things from getting fudged

32
src/Plugins/RenX/RenX.ServerList/RenX_ServerList.cpp

@ -16,6 +16,7 @@
* Written by Jessica James <jessica.aj@outlook.com>
*/
#include "jessilib/split.hpp"
#include "Jupiter/IRC_Client.h"
#include "Jupiter/HTTP.h"
#include "Jupiter/HTTP_QueryString.h"
@ -27,6 +28,7 @@
#include "RenX_ServerList.h"
using namespace Jupiter::literals;
using namespace std::literals;
static STRING_LITERAL_AS_NAMED_REFERENCE(CONTENT_TYPE_APPLICATION_JSON, "application/json");
@ -190,9 +192,9 @@ Jupiter::StringS RenX_ServerListPlugin::server_as_json(const RenX::Server &serve
server_attributes.reserve(16 * serverInfo.attributes.size() + 16);
server_attributes = R"json("Attributes":[)json";
for (Jupiter::ReferenceString& attribute : serverInfo.attributes) {
for (std::string_view attribute : serverInfo.attributes) {
server_attributes += '\"';
server_attributes.append(attribute.ptr(), attribute.size());
server_attributes += attribute;
server_attributes += "\",";
}
@ -331,12 +333,12 @@ Jupiter::StringS RenX_ServerListPlugin::server_as_long_json(const RenX::Server &
server_attributes = "[";
const char* comma = "\n";
for (Jupiter::ReferenceString& attribute : serverInfo.attributes) {
for (std::string_view attribute : serverInfo.attributes) {
server_attributes += comma;
comma = ",\n";
server_attributes += "\t\t\t\"";
server_attributes.append(attribute.ptr(), attribute.size());
server_attributes += attribute;
server_attributes += "\"";
}
@ -567,11 +569,9 @@ RenX_ServerListPlugin::ListServerInfo RenX_ServerListPlugin::getListServerInfo(c
result.namePrefix = section->get("ListNamePrefix"_jrs, result.namePrefix);
// Attributes
Jupiter::ReferenceString attributes_str = section->get("ListAttributes"_jrs);
if (attributes_str.isNotEmpty()) {
// TODO: Make tokenize just return a vector instead of this crap
Jupiter::ReadableString::TokenizeResult<Jupiter::Reference_String> attributes = Jupiter::ReferenceString::tokenize(attributes_str, ' ');
result.attributes.assign(attributes.tokens, attributes.tokens + attributes.token_count);
std::string_view attributes_str = section->get("ListAttributes"_jrs);
if (!attributes_str.empty()) {
result.attributes = jessilib::split_view(attributes_str, ' ');
}
};
@ -619,11 +619,11 @@ void RenX_ServerListPlugin::RenX_OnMapLoad(RenX::Server &server, const Jupiter::
// Plugin instantiation and entry point.
RenX_ServerListPlugin pluginInstance;
Jupiter::ReadableString *handle_server_list_page(const Jupiter::ReadableString &) {
Jupiter::ReadableString *handle_server_list_page(std::string_view) {
return pluginInstance.getServerListJSON();
}
Jupiter::ReadableString *handle_server_list_long_page(const Jupiter::ReadableString &) {
Jupiter::ReadableString *handle_server_list_long_page(std::string_view) {
const auto& servers = RenX::getCore()->getServers();
size_t index = 0;
RenX::Server *server;
@ -657,7 +657,7 @@ Jupiter::ReadableString *handle_server_list_long_page(const Jupiter::ReadableStr
return server_list_long_json;
}
Jupiter::ReadableString *handle_server_page(const Jupiter::ReadableString &query_string) {
Jupiter::ReadableString *handle_server_page(std::string_view query_string) {
Jupiter::HTTP::HTMLFormResponse html_form_response(query_string);
Jupiter::ReferenceString address;
int port = 0;
@ -669,8 +669,8 @@ Jupiter::ReadableString *handle_server_page(const Jupiter::ReadableString &query
return new Jupiter::ReferenceString();
if (html_form_response.table.size() != 0) {
address = html_form_response.tableGet("ip"_jrs, address);
port = html_form_response.tableGetCast<int>("port"_jrs, port);
address = html_form_response.tableGet("ip"sv, address);
port = html_form_response.tableGetCast<int>("port"sv, port);
}
// search for server
@ -693,11 +693,11 @@ Jupiter::ReadableString *handle_server_page(const Jupiter::ReadableString &query
return new Jupiter::ReferenceString(server->varData[pluginInstance.getName()].get("j"_jrs));
}
Jupiter::ReadableString *handle_metadata_page(const Jupiter::ReadableString&) {
Jupiter::ReadableString *handle_metadata_page(std::string_view) {
return pluginInstance.getMetadataJSON();
}
Jupiter::ReadableString *handle_metadata_prometheus_page(const Jupiter::ReadableString&) {
Jupiter::ReadableString *handle_metadata_prometheus_page(std::string_view) {
return pluginInstance.getMetadataPrometheus();
}

16
src/Plugins/RenX/RenX.ServerList/RenX_ServerList.h

@ -30,7 +30,7 @@ public: // RenX_ServerListPlugin
Jupiter::ReferenceString hostname;
unsigned short port;
Jupiter::ReferenceString namePrefix;
std::vector<Jupiter::ReferenceString> attributes;
std::vector<std::string_view> attributes;
};
size_t getListedPlayerCount(const RenX::Server& server);
@ -62,14 +62,14 @@ public: // RenX::Plugin
private:
Jupiter::StringS m_server_list_json, m_metadata_json, m_metadata_prometheus;
Jupiter::StringS m_web_hostname, m_web_path;
Jupiter::StringS m_server_list_page_name, m_server_list_long_page_name, m_server_page_name, m_metadata_page_name, m_metadata_prometheus_page_name;
std::string m_web_hostname, m_web_path;
std::string m_server_list_page_name, m_server_list_long_page_name, m_server_page_name, m_metadata_page_name, m_metadata_prometheus_page_name;
};
Jupiter::ReadableString *handle_server_list_page(const Jupiter::ReadableString &);
Jupiter::ReadableString *handle_server_list_long_page(const Jupiter::ReadableString &);
Jupiter::ReadableString *handle_server_page(const Jupiter::ReadableString &);
Jupiter::ReadableString *handle_metadata_page(const Jupiter::ReadableString &);
Jupiter::ReadableString *handle_metadata_prometheus_page(const Jupiter::ReadableString&);
Jupiter::ReadableString *handle_server_list_page(std::string_view);
Jupiter::ReadableString *handle_server_list_long_page(std::string_view);
Jupiter::ReadableString *handle_server_page(std::string_view);
Jupiter::ReadableString *handle_metadata_page(std::string_view);
Jupiter::ReadableString *handle_metadata_prometheus_page(std::string_view);
#endif // _RENX_SERVERLIST_H_HEADER

Loading…
Cancel
Save