Browse Source

Update Jupiter submodule; adjust as necessary; cleanup

master
Jessica James 3 years ago
parent
commit
a358d71a57
  1. 2
      src/Jupiter
  2. 17
      src/Plugins/RenX/RenX.Core/RenX_Functions.cpp
  3. 2
      src/Plugins/RenX/RenX.Core/RenX_Functions.h
  4. 167
      src/Plugins/RenX/RenX.Core/RenX_Server.cpp

2
src/Jupiter

@ -1 +1 @@
Subproject commit 714d660508381bc2ff3c775f95b5be11e9eabc68 Subproject commit 5715a041d2791d36128cc840c81626030091157b

17
src/Plugins/RenX/RenX.Core/RenX_Functions.cpp

@ -17,6 +17,7 @@
*/ */
#include <ctime> #include <ctime>
#include "jessilib/unicode.hpp"
#include "Jupiter/Functions.h" #include "Jupiter/Functions.h"
#include "IRC_Bot.h" #include "IRC_Bot.h"
#include "ServerManager.h" #include "ServerManager.h"
@ -26,6 +27,7 @@
#include "RenX_PlayerInfo.h" #include "RenX_PlayerInfo.h"
using namespace Jupiter::literals; using namespace Jupiter::literals;
using namespace std::literals;
/** Team color translations */ /** Team color translations */
Jupiter::ReferenceString NodColor = "04"; Jupiter::ReferenceString NodColor = "04";
@ -363,14 +365,19 @@ RenX::TeamType RenX::getTeam(int teamNum)
} }
} }
RenX::TeamType RenX::getTeam(const Jupiter::ReadableString &team) RenX::TeamType RenX::getTeam(std::string_view team) {
{ if (jessilib::equalsi(team, "GDI"sv)) {
if (team.equalsi("GDI"))
return RenX::TeamType::GDI; return RenX::TeamType::GDI;
if (team.equalsi("Nod")) }
if (jessilib::equalsi(team, "Nod"sv)) {
return RenX::TeamType::Nod; return RenX::TeamType::Nod;
if (team.isEmpty() || team.equalsi("Neutral") || team.equalsi("Civilians")) }
if (team.empty() || jessilib::equalsi(team, "Neutral"sv) || jessilib::equalsi(team, "Civilians"sv)) {
return RenX::TeamType::None; return RenX::TeamType::None;
}
return RenX::TeamType::Other; return RenX::TeamType::Other;
} }

2
src/Plugins/RenX/RenX.Core/RenX_Functions.h

@ -50,7 +50,7 @@ namespace RenX
* @param team Team name * @param team Team name
* @return A corresponding TeamType. * @return A corresponding TeamType.
*/ */
RENX_API TeamType getTeam(const Jupiter::ReadableString &team); RENX_API TeamType getTeam(std::string_view team);
/** /**
* @brief Fetches the corresponding IRC color code for a team. * @brief Fetches the corresponding IRC color code for a team.

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

@ -1284,13 +1284,13 @@ void resolve_rdns(RenX::PlayerInfo *player) {
player->rdns_mutex.unlock(); player->rdns_mutex.unlock();
} }
// TODO: less macros struct parsed_player_token {
#define PARSE_PLAYER_DATA_P(DATA) \ Jupiter::ReferenceString name;
Jupiter::ReferenceString name; \ RenX::TeamType team{};
TeamType team; \ int id{};
int id; \ bool isBot{};
bool isBot; \ bool isPlayer{}; // i.e: they appear on the player list; not "ai"
parsePlayerData(DATA, name, team, id, isBot); };
void RenX::Server::processLine(const Jupiter::ReadableString &line) { void RenX::Server::processLine(const Jupiter::ReadableString &line) {
if (line.isEmpty()) if (line.isEmpty())
@ -1403,22 +1403,34 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) {
m_firstAction = true; m_firstAction = true;
} }
}; };
auto parsePlayerData = [this](const Jupiter::ReadableString &data, Jupiter::ReferenceString &name, TeamType &team, int &id, bool &isBot) auto parsePlayerData = [this](const Jupiter::ReadableString &data) {
{ parsed_player_token result;
Jupiter::ReferenceString idToken = Jupiter::ReferenceString::getToken(data, 1, ',');
name = Jupiter::ReferenceString::gotoToken(data, 2, ','); auto player_tokens = jessilib::split_n_view(std::string_view{data}, ',', 2);
team = RenX::getTeam(Jupiter::ReferenceString::getToken(data, 0, ',')); if (player_tokens.size() < 3) {
return result;
}
Jupiter::ReferenceString idToken = player_tokens[1];
result.name = player_tokens[2];
result.team = RenX::getTeam(player_tokens[0]);
if (idToken.isNotEmpty() && idToken.get(0) == 'b') if (idToken.isNotEmpty() && idToken.get(0) == 'b')
{ {
idToken.shiftRight(1); idToken.shiftRight(1);
isBot = true; result.isBot = true;
result.isPlayer = true;
} }
else if (idToken == "ai") { else if (idToken == "ai") {
isBot = true; result.isBot = true;
result.isPlayer = false;
} }
else else {
isBot = false; result.isBot = false;
id = idToken.asInt(10); result.isPlayer = true;
}
result.id = idToken.asInt(10);
return result;
}; };
auto get_next_temp_playerinfo = [](const Jupiter::ReadableString &name, RenX::TeamType team, bool isBot) { auto get_next_temp_playerinfo = [](const Jupiter::ReadableString &name, RenX::TeamType team, bool isBot) {
static RenX::PlayerInfo s_temp_players[4]; static RenX::PlayerInfo s_temp_players[4];
@ -1537,11 +1549,11 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) {
}; };
auto parseGetPlayerOrAdd = [&parsePlayerData, &getPlayerOrAdd, this](const Jupiter::ReadableString &token) auto parseGetPlayerOrAdd = [&parsePlayerData, &getPlayerOrAdd, this](const Jupiter::ReadableString &token)
{ {
PARSE_PLAYER_DATA_P(token); auto parsed_token = parsePlayerData(token);
if (id == 0 && name.isEmpty()) { if (parsed_token.id == 0 && parsed_token.name.isEmpty()) {
sendAdmChan(IRCCOLOR "04[Error]" IRCCOLOR" Failed to parse player token: %.*s", token.size(), token.ptr()); sendAdmChan(IRCCOLOR "04[Error]" IRCCOLOR" Failed to parse player token: %.*s", token.size(), token.ptr());
} }
return getPlayerOrAdd(name, id, team, isBot, 0U, Jupiter::ReferenceString::empty, Jupiter::ReferenceString::empty); return getPlayerOrAdd(parsed_token.name, parsed_token.id, parsed_token.team, parsed_token.isBot, 0U, Jupiter::ReferenceString::empty, Jupiter::ReferenceString::empty);
}; };
auto gotoToken = [&line, &tokens, this](size_t index) auto gotoToken = [&line, &tokens, this](size_t index)
{ {
@ -1682,8 +1694,13 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) {
} }
}; };
Jupiter::ReadableString *value = table_get("PLAYERLOG"_jrs); Jupiter::ReadableString *value = table_get("PLAYERLOG"_jrs);
if (value != nullptr) if (value != nullptr) {
parse(getPlayerOrAdd(Jupiter::ReferenceString::getToken(*value, 2, ','), Jupiter::ReferenceString::getToken(*value, 1, ',').asInt(), RenX::getTeam(Jupiter::ReferenceString::getToken(*value, 0, ',')), false, table_get_ref("STEAM"_jrs, Jupiter::ReferenceString::empty).asUnsignedLongLong(), table_get_ref("IP"_jrs, Jupiter::ReferenceString::empty), table_get_ref("HWID"_jrs, Jupiter::ReferenceString::empty))); auto parsed_token = parsePlayerData(*value);
parse(getPlayerOrAdd(parsed_token.name, parsed_token.id, parsed_token.team, false,
table_get_ref("STEAM"_jrs, Jupiter::ReferenceString::empty).asUnsignedLongLong(),
table_get_ref("IP"_jrs, Jupiter::ReferenceString::empty),
table_get_ref("HWID"_jrs, Jupiter::ReferenceString::empty)));
}
else else
{ {
Jupiter::ReadableString *name = table_get("NAME"_jrs); Jupiter::ReadableString *name = table_get("NAME"_jrs);
@ -1833,8 +1850,11 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) {
player->vehicle = *value; player->vehicle = *value;
}; };
Jupiter::ReadableString *value = table_get("PLAYERLOG"_jrs); Jupiter::ReadableString *value = table_get("PLAYERLOG"_jrs);
if (value != nullptr) if (value != nullptr) {
parse(getPlayerOrAdd(Jupiter::ReferenceString::getToken(*value, 2, ','), Jupiter::ReferenceString::getToken(*value, 1, ',').substring(1).asInt(), RenX::getTeam(Jupiter::ReferenceString::getToken(*value, 0, ',')), true, 0ULL, Jupiter::ReferenceString::empty, Jupiter::ReferenceString::empty)); auto parsed_token = parsePlayerData(*value);
parse(getPlayerOrAdd(parsed_token.name, parsed_token.id, parsed_token.team, true, 0ULL,
Jupiter::ReferenceString::empty, Jupiter::ReferenceString::empty));
}
else else
{ {
Jupiter::ReadableString *name = table_get("NAME"_jrs); Jupiter::ReadableString *name = table_get("NAME"_jrs);
@ -2061,7 +2081,7 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) {
for (const auto& plugin : xPlugins) { for (const auto& plugin : xPlugins) {
plugin->RenX_OnNameChange(*this, *player, newName); plugin->RenX_OnNameChange(*this, *player, newName);
} }
player->name = getToken(2).gotoToken(2, ','); player->name = newName;
} }
break; break;
case 'l': case 'l':
@ -2158,9 +2178,9 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) {
} }
else if (subHeader.equals("Captured;")) { else if (subHeader.equals("Captured;")) {
// Team ',' Building | "id" | Building ID | "by" | Player // Team ',' Building | "id" | Building ID | "by" | Player
Jupiter::ReferenceString teamBuildingToken = getToken(2); auto teamBuildingToken = jessilib::split_once_view(getToken(2), ',');
Jupiter::ReferenceString building = teamBuildingToken.getToken(1, ','); Jupiter::ReferenceString building = teamBuildingToken.second;
TeamType oldTeam = RenX::getTeam(teamBuildingToken.getToken(0, ',')); TeamType oldTeam = RenX::getTeam(teamBuildingToken.first);
RenX::PlayerInfo *player = parseGetPlayerOrAdd(getToken(6)); RenX::PlayerInfo *player = parseGetPlayerOrAdd(getToken(6));
player->captures++; player->captures++;
for (const auto& plugin : xPlugins) { for (const auto& plugin : xPlugins) {
@ -2170,9 +2190,9 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) {
} }
else if (subHeader.equals("Neutralized;")) { else if (subHeader.equals("Neutralized;")) {
// Team ',' Building | "id" | Building ID | "by" | Player // Team ',' Building | "id" | Building ID | "by" | Player
Jupiter::ReferenceString teamBuildingToken = getToken(2); auto teamBuildingToken = jessilib::split_once_view(getToken(2), ',');
Jupiter::ReferenceString building = teamBuildingToken.getToken(1, ','); Jupiter::ReferenceString building = teamBuildingToken.second;
TeamType oldTeam = RenX::getTeam(teamBuildingToken.getToken(0, ',')); TeamType oldTeam = RenX::getTeam(teamBuildingToken.first);
RenX::PlayerInfo *player = parseGetPlayerOrAdd(getToken(6)); RenX::PlayerInfo *player = parseGetPlayerOrAdd(getToken(6));
for (const auto& plugin : xPlugins) { for (const auto& plugin : xPlugins) {
plugin->RenX_OnNeutralize(*this, *player, building, oldTeam); plugin->RenX_OnNeutralize(*this, *player, building, oldTeam);
@ -2224,12 +2244,11 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) {
// "player" | Player | "character" | Character // "player" | Player | "character" | Character
// "bot" | Player // "bot" | Player
if (getToken(2).equals("vehicle")) { if (getToken(2).equals("vehicle")) {
Jupiter::ReferenceString vehicle = getToken(3); auto vehicle = jessilib::split_once_view(getToken(3), ',');
Jupiter::ReferenceString vehicleTeamToken = vehicle.getToken(0, ','); TeamType team = RenX::getTeam(vehicle.first);
vehicle.shiftRight(vehicleTeamToken.size() + 1); Jupiter::ReferenceString vehicle_name = vehicle.second;
TeamType team = RenX::getTeam(vehicleTeamToken);
for (const auto& plugin : xPlugins) { for (const auto& plugin : xPlugins) {
plugin->RenX_OnVehicleSpawn(*this, team, vehicle); plugin->RenX_OnVehicleSpawn(*this, team, vehicle_name);
} }
} }
else if (getToken(2).equals("player")) { else if (getToken(2).equals("player")) {
@ -2390,31 +2409,18 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) {
{ {
damageType = getToken(7); damageType = getToken(7);
Jupiter::ReferenceString killerData = getToken(5); Jupiter::ReferenceString killerData = getToken(5);
Jupiter::ReferenceString kName = killerData.getToken(2, ','); auto parsed_token = parsePlayerData(killerData);
Jupiter::ReferenceString kIDToken = killerData.getToken(1, ','); if (!parsed_token.isPlayer || parsed_token.id == 0)
RenX::TeamType vTeam = RenX::getTeam(killerData.getToken(0, ','));
if (kIDToken.equals("ai") || kIDToken.isEmpty())
{ {
player->deaths++; player->deaths++;
for (const auto& plugin : xPlugins) { for (const auto& plugin : xPlugins) {
plugin->RenX_OnKill(*this, kName, vTeam, *player, damageType); plugin->RenX_OnKill(*this, parsed_token.name, parsed_token.team, *player, damageType);
} }
} }
else else
{ {
player->deaths++; player->deaths++;
int kID = 0; RenX::PlayerInfo *killer = getPlayerOrAdd(parsed_token.name, parsed_token.id, parsed_token.team, parsed_token.isBot, 0, Jupiter::ReferenceString::empty, Jupiter::ReferenceString::empty);
bool kIsBot = false;
if (kIDToken.get(0) == 'b')
{
kIsBot = true;
kIDToken.shiftRight(1);
kID = kIDToken.asInt();
kIDToken.shiftLeft(1);
}
else
kID = kIDToken.asInt();
RenX::PlayerInfo *killer = getPlayerOrAdd(kName, kID, vTeam, kIsBot, 0, Jupiter::ReferenceString::empty, Jupiter::ReferenceString::empty);
killer->kills++; killer->kills++;
if (damageType.equals("Rx_DmgType_Headshot")) { if (damageType.equals("Rx_DmgType_Headshot")) {
killer->headshots++; killer->headshots++;
@ -2492,28 +2498,16 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) {
if (getToken(4).equals("by")) if (getToken(4).equals("by"))
{ {
Jupiter::ReferenceString killerToken = getToken(5); Jupiter::ReferenceString killerToken = getToken(5);
Jupiter::ReferenceString idToken = killerToken.getToken(1, ','); auto parsed_token = parsePlayerData(killerToken);
Jupiter::ReferenceString name = killerToken.gotoToken(2, ',');
Jupiter::ReferenceString damageType = getToken(7); Jupiter::ReferenceString damageType = getToken(7);
RenX::TeamType team = RenX::getTeam(killerToken.getToken(0, ',')); if (!parsed_token.isPlayer || parsed_token.id == 0) {
if (idToken.equals("ai") || idToken.isEmpty()) {
for (const auto& plugin : xPlugins) { for (const auto& plugin : xPlugins) {
plugin->RenX_OnDestroy(*this, name, team, objectName, RenX::getEnemy(team), damageType, type); plugin->RenX_OnDestroy(*this, parsed_token.name, parsed_token.team, objectName, RenX::getEnemy(parsed_token.team), damageType, type);
}
} }
else
{
int id;
bool isBot = false;
if (idToken.get(0) == 'b')
{
isBot = true;
idToken.shiftRight(1);
} }
id = idToken.asInt(); else {
RenX::PlayerInfo *player = getPlayerOrAdd(name, id, team, isBot, 0, Jupiter::ReferenceString::empty, Jupiter::ReferenceString::empty); RenX::PlayerInfo *player = getPlayerOrAdd(parsed_token.name, parsed_token.id, parsed_token.team, parsed_token.isBot, 0, Jupiter::ReferenceString::empty, Jupiter::ReferenceString::empty);
switch (type) switch (type)
{ {
case RenX::ObjectType::Vehicle: case RenX::ObjectType::Vehicle:
@ -2574,15 +2568,13 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) {
plugin->RenX_OnOverMine(*this, *player, location); plugin->RenX_OnOverMine(*this, *player, location);
} }
} }
else if (subHeader.equals("MatchEnd;")) else if (subHeader.equals("MatchEnd;")) {
{
// "winner" | Winner | Reason("TimeLimit" etc) | "GDI=" GDI Score | "Nod=" Nod Score // "winner" | Winner | Reason("TimeLimit" etc) | "GDI=" GDI Score | "Nod=" Nod Score
// "tie" | Reason | "GDI=" GDI Score | "Nod=" Nod Score // "tie" | Reason | "GDI=" GDI Score | "Nod=" Nod Score
Jupiter::ReferenceString winTieToken = getToken(2); Jupiter::ReferenceString winTieToken = getToken(2);
m_match_state = 2; m_match_state = 2;
if (winTieToken.equals("winner")) if (winTieToken.equals("winner")) {
{
Jupiter::ReferenceString sWinType = getToken(4); Jupiter::ReferenceString sWinType = getToken(4);
WinType winType = WinType::Unknown; WinType winType = WinType::Unknown;
if (sWinType.equals("TimeLimit")) if (sWinType.equals("TimeLimit"))
@ -2595,19 +2587,17 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) {
winType = WinType::Surrender; winType = WinType::Surrender;
TeamType team = RenX::getTeam(getToken(3)); TeamType team = RenX::getTeam(getToken(3));
int gScore = Jupiter::ReferenceString(jessilib::split_once_view(getToken(5), '=').second).asInt();
int gScore = getToken(5).getToken(1, '=').asInt(); int nScore = Jupiter::ReferenceString(jessilib::split_once_view(getToken(6), '=').second).asInt();
int nScore = getToken(6).getToken(1, '=').asInt();
onPreGameOver(winType, team, gScore, nScore); onPreGameOver(winType, team, gScore, nScore);
for (const auto& plugin : xPlugins) { for (const auto& plugin : xPlugins) {
plugin->RenX_OnGameOver(*this, winType, team, gScore, nScore); plugin->RenX_OnGameOver(*this, winType, team, gScore, nScore);
} }
} }
else if (winTieToken.equals("tie")) else if (winTieToken.equals("tie")) {
{ int gScore = Jupiter::ReferenceString(jessilib::split_once_view(getToken(4), '=').second).asInt();
int gScore = getToken(4).getToken(1, '=').asInt(); int nScore = Jupiter::ReferenceString(jessilib::split_once_view(getToken(5), '=').second).asInt();
int nScore = getToken(5).getToken(1, '=').asInt();
for (const auto& plugin : xPlugins) { for (const auto& plugin : xPlugins) {
plugin->RenX_OnGameOver(*this, RenX::WinType::Tie, RenX::TeamType::None, gScore, nScore); plugin->RenX_OnGameOver(*this, RenX::WinType::Tie, RenX::TeamType::None, gScore, nScore);
} }
@ -2755,7 +2745,7 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) {
{ {
if (subHeader.equals("Enter;")) if (subHeader.equals("Enter;"))
{ {
PARSE_PLAYER_DATA_P(getToken(2)); auto parsed_token = parsePlayerData(getToken(2));
uint64_t steamid = 0; uint64_t steamid = 0;
RenX::PlayerInfo *player; RenX::PlayerInfo *player;
@ -2765,7 +2755,7 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) {
if (getToken(7).equals("steamid")) if (getToken(7).equals("steamid"))
steamid = getToken(8).asUnsignedLongLong(); steamid = getToken(8).asUnsignedLongLong();
player = getPlayerOrAdd(name, id, team, isBot, steamid, getToken(4), getToken(6)); player = getPlayerOrAdd(parsed_token.name, parsed_token.id, parsed_token.team, parsed_token.isBot, steamid, getToken(4), getToken(6));
} }
else else
{ {
@ -2773,7 +2763,7 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) {
if (getToken(5).equals("steamid")) if (getToken(5).equals("steamid"))
steamid = getToken(6).asUnsignedLongLong(); steamid = getToken(6).asUnsignedLongLong();
player = getPlayerOrAdd(name, id, team, isBot, steamid, getToken(4), Jupiter::ReferenceString::empty); player = getPlayerOrAdd(parsed_token.name, parsed_token.id, parsed_token.team, parsed_token.isBot, steamid, getToken(4), Jupiter::ReferenceString::empty);
} }
if (steamid != 0ULL && default_ladder_database != nullptr && (player->ban_flags & RenX::BanDatabase::Entry::FLAG_TYPE_LADDER) == 0) if (steamid != 0ULL && default_ladder_database != nullptr && (player->ban_flags & RenX::BanDatabase::Entry::FLAG_TYPE_LADDER) == 0)
@ -2843,13 +2833,10 @@ void RenX::Server::processLine(const Jupiter::ReadableString &line) {
{ {
// Player // Player
Jupiter::ReferenceString playerToken = getToken(2); Jupiter::ReferenceString playerToken = getToken(2);
PARSE_PLAYER_DATA_P(playerToken); auto parsed_token = parsePlayerData(playerToken);
RenX::PlayerInfo *player = getPlayer(id); RenX::PlayerInfo *player = getPlayer(parsed_token.id);
//RenX::PlayerInfo *player = parseGetPlayerOrAdd(getToken(2)); if (player != nullptr) {
if (player != nullptr)
{
for (const auto& plugin : xPlugins) { for (const auto& plugin : xPlugins) {
plugin->RenX_OnPart(*this, *player); plugin->RenX_OnPart(*this, *player);
} }

Loading…
Cancel
Save