Browse Source

Server list IPs can now be replaced via config

pull/13/head
Jessica James 5 years ago
parent
commit
142df4d0aa
  1. 28
      src/Plugins/RenX/RenX.ServerList/RenX_ServerList.cpp
  2. 3
      src/Plugins/RenX/RenX.ServerList/RenX_ServerList.h

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

@ -200,13 +200,14 @@ constexpr const char *json_bool_as_cstring(bool in)
return in ? "true" : "false"; return in ? "true" : "false";
} }
Jupiter::StringS server_as_json(const RenX::Server &server) Jupiter::StringS RenX_ServerListPlugin::server_as_json(const RenX::Server &server)
{ {
Jupiter::String server_json_block(128); Jupiter::String server_json_block(128);
Jupiter::String server_name = jsonify(server.getName()); Jupiter::String server_name = jsonify(server.getName());
Jupiter::String server_map = jsonify(server.getMap().name); Jupiter::String server_map = jsonify(server.getMap().name);
Jupiter::String server_version = jsonify(server.getGameVersion()); Jupiter::String server_version = jsonify(server.getGameVersion());
Jupiter::ReferenceString server_hostname = getListServerInfo(server);
server_json_block.format(R"json({"Name":"%.*s","Current Map":"%.*s","Bots":%u,"Players":%u,"Game Version":"%.*s","Variables":{"Mine Limit":%d,"bSteamRequired":%s,"bPrivateMessageTeamOnly":%s,"bPassworded":%s,"bAllowPrivateMessaging":%s,"bRanked":%s,"Game Type":%d,"Player Limit":%d,"Vehicle Limit":%d,"bAutoBalanceTeams":%s,"Team Mode":%d,"bSpawnCrates":%s,"CrateRespawnAfterPickup":%f,"Time Limit":%d},"Port":%u,"IP":"%.*s")json", server_json_block.format(R"json({"Name":"%.*s","Current Map":"%.*s","Bots":%u,"Players":%u,"Game Version":"%.*s","Variables":{"Mine Limit":%d,"bSteamRequired":%s,"bPrivateMessageTeamOnly":%s,"bPassworded":%s,"bAllowPrivateMessaging":%s,"bRanked":%s,"Game Type":%d,"Player Limit":%d,"Vehicle Limit":%d,"bAutoBalanceTeams":%s,"Team Mode":%d,"bSpawnCrates":%s,"CrateRespawnAfterPickup":%f,"Time Limit":%d},"Port":%u,"IP":"%.*s")json",
server_name.size(), server_name.ptr(), server_name.size(), server_name.ptr(),
@ -229,20 +230,21 @@ Jupiter::StringS server_as_json(const RenX::Server &server)
server.getCrateRespawnDelay(), server.getCrateRespawnDelay(),
server.getTimeLimit(), server.getTimeLimit(),
server.getPort(), server.getPort(),
server.getSocketHostname().size(), server.getSocketHostname().c_str()); server_hostname.size(), server_hostname.ptr());
server_json_block += '}'; server_json_block += '}';
return server_json_block; return server_json_block;
} }
Jupiter::StringS 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);
Jupiter::String server_name = jsonify(server.getName()); Jupiter::String server_name = jsonify(server.getName());
Jupiter::String server_map = jsonify(server.getMap().name); Jupiter::String server_map = jsonify(server.getMap().name);
Jupiter::String server_version = jsonify(server.getGameVersion()); Jupiter::String server_version = jsonify(server.getGameVersion());
Jupiter::ReferenceString server_hostname = getListServerInfo(server);
std::vector<const RenX::PlayerInfo*> activePlayers = server.activePlayers(false); std::vector<const RenX::PlayerInfo*> activePlayers = server.activePlayers(false);
server_json_block.format(R"json({ server_json_block.format(R"json({
@ -267,7 +269,6 @@ Jupiter::StringS server_as_long_json(const RenX::Server &server)
}, },
"Port": %u, "Port": %u,
"IP": "%.*s")json", "IP": "%.*s")json",
server_name.size(), server_name.ptr(), server_name.size(), server_name.ptr(),
server_map.size(), server_map.ptr(), server_map.size(), server_map.ptr(),
server.getBotCount(), server.getBotCount(),
@ -288,7 +289,7 @@ Jupiter::StringS server_as_long_json(const RenX::Server &server)
server.getTimeLimit(), server.getTimeLimit(),
server.getPort(), server.getPort(),
server.getSocketHostname().size(), server.getSocketHostname().c_str()); server_hostname.size(), server_hostname.ptr());
// Level Rotation // Level Rotation
@ -507,6 +508,17 @@ void RenX_ServerListPlugin::updateServerList()
RenX_ServerListPlugin::server_list_json += ']'; RenX_ServerListPlugin::server_list_json += ']';
} }
Jupiter::ReferenceString RenX_ServerListPlugin::getListServerInfo(const RenX::Server& server) {
Jupiter::ReferenceString serverHostname;
serverHostname = server.getSocketHostname();
if (auto section = config.getSection(serverHostname)) {
serverHostname = section->get("ListAddress"_jrs, serverHostname);
}
return serverHostname;
}
void RenX_ServerListPlugin::RenX_OnServerFullyConnected(RenX::Server &server) void RenX_ServerListPlugin::RenX_OnServerFullyConnected(RenX::Server &server)
{ {
this->addServerToServerList(server); this->addServerToServerList(server);
@ -561,7 +573,7 @@ Jupiter::ReadableString *handle_server_list_long_page(const Jupiter::ReadableStr
if (server->isConnected() && server->isFullyConnected()) if (server->isConnected() && server->isFullyConnected())
{ {
*server_list_long_json += "\n\t"_jrs; *server_list_long_json += "\n\t"_jrs;
*server_list_long_json += server_as_long_json(*server); *server_list_long_json += pluginInstance.server_as_long_json(*server);
++index; ++index;
break; break;
} }
@ -573,7 +585,7 @@ Jupiter::ReadableString *handle_server_list_long_page(const Jupiter::ReadableStr
if (server->isConnected() && server->isFullyConnected()) if (server->isConnected() && server->isFullyConnected())
{ {
*server_list_long_json += ",\n\t"_jrs; *server_list_long_json += ",\n\t"_jrs;
*server_list_long_json += server_as_long_json(*server); *server_list_long_json += pluginInstance.server_as_long_json(*server);
} }
++index; ++index;
} }
@ -611,7 +623,7 @@ Jupiter::ReadableString *handle_server_page(const Jupiter::ReadableString &query
return new Jupiter::ReferenceString(); return new Jupiter::ReferenceString();
server = servers.get(index); server = servers.get(index);
if (address.equals(server->getSocketHostname()) && server->getPort() == port) if (address.equals(pluginInstance.getListServerInfo(*server)) && server->getPort() == port)
break; break;
++index; ++index;

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

@ -30,6 +30,9 @@ public: // RenX_ServerListPlugin
void addServerToServerList(RenX::Server &server); void addServerToServerList(RenX::Server &server);
void updateServerList(); void updateServerList();
Jupiter::ReferenceString getListServerInfo(const RenX::Server& server);
Jupiter::StringS server_as_json(const RenX::Server &server);
Jupiter::StringS server_as_long_json(const RenX::Server &server);
virtual bool initialize() override; virtual bool initialize() override;
~RenX_ServerListPlugin(); ~RenX_ServerListPlugin();

Loading…
Cancel
Save