Browse Source

Fix some server list crashes

Fix /server endpoint JSON never being updated
master
Jessica James 3 years ago
parent
commit
4a855b231d
  1. 2
      CMakeLists.txt
  2. 187
      src/Plugins/RenX/RenX.ServerList/RenX_ServerList.cpp
  3. 3
      src/Plugins/RenX/RenX.ServerList/RenX_ServerList.h

2
CMakeLists.txt

@ -5,6 +5,8 @@ set(CMAKE_CXX_STANDARD 20)
# Try to set JUPITER_VERSION_SHORT if it isn't already # Try to set JUPITER_VERSION_SHORT if it isn't already
if (NOT DEFINED JUPITER_VERSION_SHORT) if (NOT DEFINED JUPITER_VERSION_SHORT)
# Gets the version string portion a release/ branch name if on a release/ branch,
# gets "{branch_name}-{short_commit_hash}" otherwise
find_package(Git) find_package(Git)
if (GIT_FOUND) if (GIT_FOUND)
execute_process( execute_process(

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

@ -231,6 +231,88 @@ Jupiter::StringS RenX_ServerListPlugin::server_as_json(const RenX::Server &serve
return server_json_block; return server_json_block;
} }
Jupiter::StringS RenX_ServerListPlugin::server_as_server_details_json(const RenX::Server& server) {
Jupiter::StringS server_json_block;
server_json_block = '{';
// Levels
if (server.maps.size() != 0) {
server_json_block += "\"Levels\":["_jrs;
server_json_block += "{\"Name\":\""_jrs;
server_json_block += jsonify(server.maps[0].name);
server_json_block += "\",\"GUID\":\""_jrs;
server_json_block += RenX::formatGUID(server.maps[0]);
server_json_block += "\"}"_jrs;
for (size_t index = 1; index != server.maps.size(); ++index) {
server_json_block += ",{\"Name\":\""_jrs;
server_json_block += jsonify(server.maps[index].name);
server_json_block += "\",\"GUID\":\""_jrs;
server_json_block += RenX::formatGUID(server.maps[index]);
server_json_block += "\"}"_jrs;
}
server_json_block += ']';
}
// Mutators
if (server.mutators.size() != 0) {
if (server.maps.size() != 0)
server_json_block += ","_jrs;
server_json_block += "\"Mutators\":["_jrs;
server_json_block += "{\"Name\":\""_jrs;
server_json_block += jsonify(server.mutators[0]);
server_json_block += "\"}"_jrs;
for (size_t index = 1; index != server.mutators.size(); ++index) {
server_json_block += ",{\"Name\":\""_jrs;
server_json_block += jsonify(server.mutators[index]);
server_json_block += "\"}"_jrs;
}
server_json_block += ']';
}
// Player List
if (server.players.size() != 0 && server.players.size() != server.getBotCount()) {
server_json_block += ",\"PlayerList\":["_jrs;
auto node = server.players.begin();
if (node != server.players.end()) {
server_json_block += "{\"Name\":\""_jrs;
server_json_block += jsonify(node->name);
server_json_block += "\", \"isBot\":"_jrs;
server_json_block += json_bool_as_cstring(node->isBot);
server_json_block += ", \"Team\":"_jrs;
server_json_block.aformat("%d", static_cast<int>(node->team));
server_json_block += "}"_jrs;
++node;
}
while (node != server.players.end()) {
server_json_block += ",{\"Name\":\""_jrs;
server_json_block += jsonify(node->name);
server_json_block += "\", \"isBot\":"_jrs;
server_json_block += json_bool_as_cstring(node->isBot);
server_json_block += ", \"Team\":"_jrs;
server_json_block.aformat("%d", static_cast<int>(node->team));
server_json_block += "}"_jrs;
++node;
}
server_json_block += "]"_jrs;
}
server_json_block += '}';
return server_json_block;
}
Jupiter::StringS RenX_ServerListPlugin::server_as_long_json(const RenX::Server &server) { Jupiter::StringS RenX_ServerListPlugin::server_as_long_json(const RenX::Server &server) {
Jupiter::String server_json_block(128); Jupiter::String server_json_block(128);
ListServerInfo serverInfo = getListServerInfo(server); ListServerInfo serverInfo = getListServerInfo(server);
@ -391,86 +473,6 @@ void RenX_ServerListPlugin::addServerToServerList(RenX::Server &server) {
m_server_list_json += ']'; m_server_list_json += ']';
server_json_block.erase(); server_json_block.erase();
// add to individual listing
server_json_block = '{';
if (server.maps.size() != 0) {
server_json_block += "\"Levels\":["_jrs;
server_json_block += "{\"Name\":\""_jrs;
server_json_block += jsonify(server.maps[0].name);
server_json_block += "\",\"GUID\":\""_jrs;
server_json_block += RenX::formatGUID(server.maps[0]);
server_json_block += "\"}"_jrs;
for (size_t index = 1; index != server.maps.size(); ++index) {
server_json_block += ",{\"Name\":\""_jrs;
server_json_block += jsonify(server.maps[index].name);
server_json_block += "\",\"GUID\":\""_jrs;
server_json_block += RenX::formatGUID(server.maps[index]);
server_json_block += "\"}"_jrs;
}
server_json_block += ']';
}
// Mutators
if (server.mutators.size() != 0) {
if (server.maps.size() != 0)
server_json_block += ","_jrs;
server_json_block += "\"Mutators\":["_jrs;
server_json_block += "{\"Name\":\""_jrs;
server_json_block += jsonify(server.mutators[0]);
server_json_block += "\"}"_jrs;
for (size_t index = 1; index != server.mutators.size(); ++index) {
server_json_block += ",{\"Name\":\""_jrs;
server_json_block += jsonify(server.mutators[index]);
server_json_block += "\"}"_jrs;
}
server_json_block += ']';
}
// Player List
if (server.players.size() != 0 && server.players.size() != server.getBotCount()) {
server_json_block += ",\"PlayerList\":["_jrs;
auto node = server.players.begin();
if (node != server.players.end()) {
server_json_block += "{\"Name\":\""_jrs;
server_json_block += jsonify(node->name);
server_json_block += "\", \"isBot\":"_jrs;
server_json_block += json_bool_as_cstring(node->isBot);
server_json_block += ", \"Team\":"_jrs;
server_json_block.aformat("%d", static_cast<int>(node->team));
server_json_block += "}"_jrs;
++node;
}
while (node != server.players.end()) {
server_json_block += ",{\"Name\":\""_jrs;
server_json_block += jsonify(node->name);
server_json_block += "\", \"isBot\":"_jrs;
server_json_block += json_bool_as_cstring(node->isBot);
server_json_block += ", \"Team\":"_jrs;
server_json_block.aformat("%d", static_cast<int>(node->team));
server_json_block += "}"_jrs;
++node;
}
server_json_block += "]"_jrs;
}
server_json_block += '}';
server.varData[this->name].set("j"_jrs, server_json_block);
// Also update metadata so it reflects the now added server // Also update metadata so it reflects the now added server
updateMetadata(); updateMetadata();
} }
@ -529,6 +531,18 @@ void RenX_ServerListPlugin::updateMetadata() {
player_count, server_count); player_count, server_count);
} }
void RenX_ServerListPlugin::markStale(RenX::Server& in_server) {
in_server.varData[this->name].remove("j"_jrs);
}
void RenX_ServerListPlugin::touch(RenX::Server& in_server) {
auto& server_varData = in_server.varData[this->name];
if (server_varData.get("j"_jrs).isEmpty()) {
auto server_json_block = server_as_server_details_json(in_server);
server_varData.set("j"_jrs, server_json_block);
}
}
Jupiter::ReferenceString RenX_ServerListPlugin::getListServerAddress(const RenX::Server& server) { Jupiter::ReferenceString RenX_ServerListPlugin::getListServerAddress(const RenX::Server& server) {
Jupiter::ReferenceString serverHostname; Jupiter::ReferenceString serverHostname;
serverHostname = server.getSocketHostname(); serverHostname = server.getSocketHostname();
@ -582,21 +596,23 @@ void RenX_ServerListPlugin::RenX_OnServerFullyConnected(RenX::Server &server) {
void RenX_ServerListPlugin::RenX_OnServerDisconnect(RenX::Server &server, RenX::DisconnectReason) { void RenX_ServerListPlugin::RenX_OnServerDisconnect(RenX::Server &server, RenX::DisconnectReason) {
this->updateServerList(); this->updateServerList();
markStale(server);
// remove from individual listing
server.varData[this->name].remove("j"_jrs);
} }
void RenX_ServerListPlugin::RenX_OnJoin(RenX::Server &, const RenX::PlayerInfo &) { void RenX_ServerListPlugin::RenX_OnJoin(RenX::Server& server, const RenX::PlayerInfo &) {
markStale(server);
this->updateServerList(); this->updateServerList();
} }
void RenX_ServerListPlugin::RenX_OnPart(RenX::Server &server, const RenX::PlayerInfo &) { void RenX_ServerListPlugin::RenX_OnPart(RenX::Server &server, const RenX::PlayerInfo &) {
if (server.isTravelling() == false || server.isSeamless()) if (server.isTravelling() == false || server.isSeamless()) {
markStale(server);
this->updateServerList(); this->updateServerList();
}
} }
void RenX_ServerListPlugin::RenX_OnMapLoad(RenX::Server &server, const Jupiter::ReadableString &map) { void RenX_ServerListPlugin::RenX_OnMapLoad(RenX::Server &server, const Jupiter::ReadableString &map) {
markStale(server);
this->updateServerList(); this->updateServerList();
} }
@ -673,6 +689,7 @@ Jupiter::ReadableString *handle_server_page(const Jupiter::ReadableString &query
} }
// return server data // return server data
pluginInstance.touch(*server);
return new Jupiter::ReferenceString(server->varData[pluginInstance.getName()].get("j"_jrs)); return new Jupiter::ReferenceString(server->varData[pluginInstance.getName()].get("j"_jrs));
} }

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

@ -42,9 +42,12 @@ public: // RenX_ServerListPlugin
void addServerToServerList(RenX::Server &server); void addServerToServerList(RenX::Server &server);
void updateServerList(); void updateServerList();
void updateMetadata(); void updateMetadata();
void markStale(RenX::Server& in_server);
void touch(RenX::Server& in_server);
Jupiter::ReferenceString getListServerAddress(const RenX::Server& server); Jupiter::ReferenceString getListServerAddress(const RenX::Server& server);
ListServerInfo getListServerInfo(const RenX::Server& server); ListServerInfo getListServerInfo(const RenX::Server& server);
Jupiter::StringS server_as_json(const RenX::Server &server); Jupiter::StringS server_as_json(const RenX::Server &server);
Jupiter::StringS server_as_server_details_json(const RenX::Server& server);
Jupiter::StringS server_as_long_json(const RenX::Server &server); Jupiter::StringS server_as_long_json(const RenX::Server &server);
virtual bool initialize() override; virtual bool initialize() override;

Loading…
Cancel
Save