Browse Source
Added event: 'RenX_OnFullyConnected' Added RenX.ServerList plugin Updated Jupiterpull/3/head
Jessica James
9 years ago
20 changed files with 1057 additions and 58 deletions
@ -1 +1 @@ |
|||||
Subproject commit e656b6f6ba3614b57bc19cb4c4835801e33daf8e |
Subproject commit 87f1b47149f7974ab5faa81b8b9d3c4b26b68838 |
Binary file not shown.
Binary file not shown.
@ -0,0 +1,63 @@ |
|||||
|
/**
|
||||
|
* Copyright (C) 2016 Jessica James. |
||||
|
* |
||||
|
* Permission to use, copy, modify, and/or distribute this software for any |
||||
|
* purpose with or without fee is hereby granted, provided that the above |
||||
|
* copyright notice and this permission notice appear in all copies. |
||||
|
* |
||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
||||
|
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
||||
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
||||
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
||||
|
* |
||||
|
* Written by Jessica James <jessica.aj@outlook.com> |
||||
|
*/ |
||||
|
|
||||
|
#if !defined _RENX_TEAMINFO_H_HEADER |
||||
|
#define _RENX_TEAMINFO_H_HEADER |
||||
|
|
||||
|
/**
|
||||
|
* @file RenX_BuildingInfo.h |
||||
|
* @brief Defines the BuildingInfo structure. |
||||
|
*/ |
||||
|
|
||||
|
#include "Jupiter/String.h" |
||||
|
#include "Jupiter/INIFile.h" |
||||
|
#include "RenX.h" |
||||
|
|
||||
|
/** DLL Linkage Nagging */ |
||||
|
#if defined _MSC_VER |
||||
|
#pragma warning(push) |
||||
|
#pragma warning(disable: 4251) |
||||
|
#endif |
||||
|
|
||||
|
namespace RenX |
||||
|
{ |
||||
|
|
||||
|
/**
|
||||
|
* @brief Includes all of the tracked information about a team. |
||||
|
*/ |
||||
|
struct RENX_API TeamInfo |
||||
|
{ |
||||
|
uint8_t id; |
||||
|
int32_t score; |
||||
|
int32_t kills; |
||||
|
int32_t deaths; |
||||
|
int32_t mine_count; |
||||
|
int32_t mine_limit; |
||||
|
int32_t vehicle_count; |
||||
|
int32_t vehicle_limit; |
||||
|
Jupiter::StringS name; |
||||
|
}; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/** Re-enable warnings */ |
||||
|
#if defined _MSC_VER |
||||
|
#pragma warning(pop) |
||||
|
#endif |
||||
|
|
||||
|
#endif // _RENX_TEAMINFO_H_HEADER
|
@ -0,0 +1,86 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
|
<ItemGroup Label="ProjectConfigurations"> |
||||
|
<ProjectConfiguration Include="Debug|Win32"> |
||||
|
<Configuration>Debug</Configuration> |
||||
|
<Platform>Win32</Platform> |
||||
|
</ProjectConfiguration> |
||||
|
<ProjectConfiguration Include="Release|Win32"> |
||||
|
<Configuration>Release</Configuration> |
||||
|
<Platform>Win32</Platform> |
||||
|
</ProjectConfiguration> |
||||
|
</ItemGroup> |
||||
|
<PropertyGroup Label="Globals"> |
||||
|
<ProjectGuid>{6B0D59BA-B153-4DE8-8DD4-FBE5D810B033}</ProjectGuid> |
||||
|
<RootNamespace>RenX.ServerList</RootNamespace> |
||||
|
</PropertyGroup> |
||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> |
||||
|
<ConfigurationType>Application</ConfigurationType> |
||||
|
<UseDebugLibraries>true</UseDebugLibraries> |
||||
|
<PlatformToolset>v140</PlatformToolset> |
||||
|
<CharacterSet>MultiByte</CharacterSet> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> |
||||
|
<ConfigurationType>DynamicLibrary</ConfigurationType> |
||||
|
<UseDebugLibraries>false</UseDebugLibraries> |
||||
|
<PlatformToolset>v140</PlatformToolset> |
||||
|
<WholeProgramOptimization>true</WholeProgramOptimization> |
||||
|
<CharacterSet>Unicode</CharacterSet> |
||||
|
</PropertyGroup> |
||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> |
||||
|
<ImportGroup Label="ExtensionSettings"> |
||||
|
</ImportGroup> |
||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |
||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||
|
</ImportGroup> |
||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |
||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||
|
</ImportGroup> |
||||
|
<PropertyGroup Label="UserMacros" /> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |
||||
|
<OutDir>$(SolutionDir)$(Configuration)\Plugins\</OutDir> |
||||
|
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> |
||||
|
</PropertyGroup> |
||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |
||||
|
<ClCompile> |
||||
|
<WarningLevel>Level3</WarningLevel> |
||||
|
<Optimization>Disabled</Optimization> |
||||
|
<SDLCheck>true</SDLCheck> |
||||
|
</ClCompile> |
||||
|
<Link> |
||||
|
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
|
</Link> |
||||
|
</ItemDefinitionGroup> |
||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |
||||
|
<ClCompile> |
||||
|
<WarningLevel>Level3</WarningLevel> |
||||
|
<Optimization>MaxSpeed</Optimization> |
||||
|
<FunctionLevelLinking>true</FunctionLevelLinking> |
||||
|
<IntrinsicFunctions>true</IntrinsicFunctions> |
||||
|
<SDLCheck>true</SDLCheck> |
||||
|
<AdditionalIncludeDirectories>../Bot;../Jupiter;../RenX.Core;../HTTPServer</AdditionalIncludeDirectories> |
||||
|
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
</ClCompile> |
||||
|
<Link> |
||||
|
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding> |
||||
|
<OptimizeReferences>true</OptimizeReferences> |
||||
|
</Link> |
||||
|
</ItemDefinitionGroup> |
||||
|
<ItemGroup> |
||||
|
<ClInclude Include="RenX_ServerList.h" /> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<ClCompile Include="RenX_ServerList.cpp" /> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<Library Include="..\Jupiter\Release\Jupiter.lib" /> |
||||
|
<Library Include="..\Release\Bot.lib" /> |
||||
|
<Library Include="..\Release\Plugins\HTTPServer.lib" /> |
||||
|
<Library Include="..\Release\Plugins\RenX.Core.lib" /> |
||||
|
</ItemGroup> |
||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> |
||||
|
<ImportGroup Label="ExtensionTargets"> |
||||
|
</ImportGroup> |
||||
|
</Project> |
@ -0,0 +1,41 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
|
<ItemGroup> |
||||
|
<Filter Include="Source Files"> |
||||
|
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> |
||||
|
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> |
||||
|
</Filter> |
||||
|
<Filter Include="Header Files"> |
||||
|
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> |
||||
|
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions> |
||||
|
</Filter> |
||||
|
<Filter Include="Resource Files"> |
||||
|
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> |
||||
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> |
||||
|
</Filter> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<ClInclude Include="RenX_ServerList.h"> |
||||
|
<Filter>Header Files</Filter> |
||||
|
</ClInclude> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<ClCompile Include="RenX_ServerList.cpp"> |
||||
|
<Filter>Source Files</Filter> |
||||
|
</ClCompile> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<Library Include="..\Release\Plugins\RenX.Core.lib"> |
||||
|
<Filter>Resource Files</Filter> |
||||
|
</Library> |
||||
|
<Library Include="..\Release\Bot.lib"> |
||||
|
<Filter>Resource Files</Filter> |
||||
|
</Library> |
||||
|
<Library Include="..\Jupiter\Release\Jupiter.lib"> |
||||
|
<Filter>Resource Files</Filter> |
||||
|
</Library> |
||||
|
<Library Include="..\Release\Plugins\HTTPServer.lib"> |
||||
|
<Filter>Resource Files</Filter> |
||||
|
</Library> |
||||
|
</ItemGroup> |
||||
|
</Project> |
@ -0,0 +1,487 @@ |
|||||
|
/**
|
||||
|
* Copyright (C) 2016 Jessica James. |
||||
|
* |
||||
|
* Permission to use, copy, modify, and/or distribute this software for any |
||||
|
* purpose with or without fee is hereby granted, provided that the above |
||||
|
* copyright notice and this permission notice appear in all copies. |
||||
|
* |
||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
||||
|
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
||||
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
||||
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
||||
|
* |
||||
|
* Written by Jessica James <jessica.aj@outlook.com> |
||||
|
*/ |
||||
|
|
||||
|
#include "Jupiter/IRC_Client.h" |
||||
|
#include "Jupiter/INIFile.h" |
||||
|
#include "Jupiter/HTTP.h" |
||||
|
#include "Jupiter/HTTP_QueryString.h" |
||||
|
#include "HTTPServer.h" |
||||
|
#include "RenX_Core.h" |
||||
|
#include "RenX_Server.h" |
||||
|
#include "RenX_ServerList.h" |
||||
|
#include "RenX_Functions.h" |
||||
|
|
||||
|
using namespace Jupiter::literals; |
||||
|
|
||||
|
static STRING_LITERAL_AS_NAMED_REFERENCE(CONTENT_TYPE_APPLICATION_JSON, "application/json"); |
||||
|
|
||||
|
Jupiter::String jsonify(const Jupiter::ReadableString &in_str) |
||||
|
{ |
||||
|
const char *ptr = in_str.ptr(); |
||||
|
size_t str_length = in_str.size(); |
||||
|
Jupiter::String result(str_length); |
||||
|
|
||||
|
while (str_length != 0) |
||||
|
{ |
||||
|
if (*ptr == '\\') // backslash
|
||||
|
{ |
||||
|
result += '\\'; |
||||
|
result += '\\'; |
||||
|
} |
||||
|
else if (*ptr == '\"') // quotation
|
||||
|
{ |
||||
|
result += '\\'; |
||||
|
result += '\"'; |
||||
|
} |
||||
|
else if (*ptr < 0x20) // control characters
|
||||
|
result += Jupiter::StringS::Format("\\u00%x", *ptr); |
||||
|
else if ((*ptr & 0x80) != 0) // UTF-8 sequence; copy to bypass above processing |
||||
|
{ |
||||
|
result += *ptr; |
||||
|
|
||||
|
if ((*ptr & 0x40) != 0) |
||||
|
{ |
||||
|
// this is a 2+ byte sequence
|
||||
|
|
||||
|
if ((*ptr & 0x20) != 0) |
||||
|
{ |
||||
|
// this is a 3+ byte sequence
|
||||
|
|
||||
|
if ((*ptr & 0x10) != 0) |
||||
|
{ |
||||
|
// this is a 4 byte sequnce
|
||||
|
result += *++ptr; |
||||
|
} |
||||
|
|
||||
|
result += *++ptr; |
||||
|
} |
||||
|
|
||||
|
result += *++ptr; |
||||
|
} |
||||
|
} |
||||
|
else // Character in standard ASCII table
|
||||
|
result += *ptr; |
||||
|
|
||||
|
++ptr; |
||||
|
--str_length; |
||||
|
} |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
RenX_ServerListPlugin::RenX_ServerListPlugin() |
||||
|
{ |
||||
|
RenX_ServerListPlugin::web_hostname = Jupiter::IRC::Client::Config->get(this->name, "Hostname"_jrs, ""_jrs); |
||||
|
RenX_ServerListPlugin::web_path = Jupiter::IRC::Client::Config->get(this->name, "Path"_jrs, "/"_jrs); |
||||
|
RenX_ServerListPlugin::server_list_page_name = Jupiter::IRC::Client::Config->get(this->name, "ServersPageName"_jrs, "servers.json"_jrs); |
||||
|
RenX_ServerListPlugin::server_page_name = Jupiter::IRC::Client::Config->get(this->name, "ServerPageName"_jrs, "server.json"_jrs); |
||||
|
|
||||
|
/** Initialize content */ |
||||
|
Jupiter::HTTP::Server &server = getHTTPServer(); |
||||
|
|
||||
|
// Server list page
|
||||
|
Jupiter::HTTP::Server::Content *content = new Jupiter::HTTP::Server::Content(RenX_ServerListPlugin::server_list_page_name, handle_server_list_page); |
||||
|
content->language = &Jupiter::HTTP::Content::Language::ENGLISH; |
||||
|
content->type = &CONTENT_TYPE_APPLICATION_JSON; |
||||
|
content->charset = &Jupiter::HTTP::Content::Type::Text::Charset::UTF8; |
||||
|
content->free_result = false; |
||||
|
server.hook(RenX_ServerListPlugin::web_hostname, RenX_ServerListPlugin::web_path, content); |
||||
|
|
||||
|
// Server page (GUIDs)
|
||||
|
content = new Jupiter::HTTP::Server::Content(RenX_ServerListPlugin::server_page_name, handle_server_page); |
||||
|
content->language = &Jupiter::HTTP::Content::Language::ENGLISH; |
||||
|
content->type = &CONTENT_TYPE_APPLICATION_JSON; |
||||
|
content->charset = &Jupiter::HTTP::Content::Type::Text::Charset::UTF8; |
||||
|
content->free_result = true; |
||||
|
server.hook(RenX_ServerListPlugin::web_hostname, RenX_ServerListPlugin::web_path, content); |
||||
|
|
||||
|
this->updateServerList(); |
||||
|
} |
||||
|
|
||||
|
RenX_ServerListPlugin::~RenX_ServerListPlugin() |
||||
|
{ |
||||
|
Jupiter::HTTP::Server &server = getHTTPServer(); |
||||
|
server.remove(RenX_ServerListPlugin::web_hostname, RenX_ServerListPlugin::web_path, RenX_ServerListPlugin::server_list_page_name); |
||||
|
server.remove(RenX_ServerListPlugin::web_hostname, RenX_ServerListPlugin::web_path, RenX_ServerListPlugin::server_page_name); |
||||
|
} |
||||
|
|
||||
|
Jupiter::ReadableString *RenX_ServerListPlugin::getServerListJSON() |
||||
|
{ |
||||
|
return std::addressof(RenX_ServerListPlugin::server_list_json); |
||||
|
} |
||||
|
|
||||
|
const char *json_bool_as_cstring(bool in) |
||||
|
{ |
||||
|
if (in) |
||||
|
return "true"; |
||||
|
return "false"; |
||||
|
} |
||||
|
|
||||
|
Jupiter::StringS server_as_json(const RenX::Server *server) |
||||
|
{ |
||||
|
Jupiter::String server_json_block(128); |
||||
|
|
||||
|
Jupiter::String server_name = jsonify(server->getName()); |
||||
|
Jupiter::String server_map = jsonify(server->getMap().name); |
||||
|
Jupiter::String server_version = jsonify(server->getGameVersion()); |
||||
|
|
||||
|
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,"Player Limit":%d,"Vehicle Limit":%d,"bAutoBalanceTeams":%s,"bSpawnCrates":%s,"CrateRespawnAfterPickup":%f,"Time Limit":%d},"Port":%u,"IP":"%.*s")json", |
||||
|
server_name.size(), server_name.ptr(), |
||||
|
server_map.size(), server_map.ptr(), |
||||
|
server->getBotCount(), |
||||
|
server->players.size() - server->getBotCount(), |
||||
|
server_version.size(), server_version.ptr(), |
||||
|
server->getMineLimit(), |
||||
|
json_bool_as_cstring(server->isSteamRequired()), |
||||
|
json_bool_as_cstring(server->isPrivateMessageTeamOnly()), |
||||
|
json_bool_as_cstring(server->isPassworded()), |
||||
|
json_bool_as_cstring(server->isPrivateMessagingEnabled()), |
||||
|
server->getPlayerLimit(), |
||||
|
server->getVehicleLimit(), |
||||
|
json_bool_as_cstring(server->isAutoBalanceEnabled()), |
||||
|
json_bool_as_cstring(server->isCratesEnabled()), |
||||
|
server->getCrateRespawnDelay(), |
||||
|
server->getTimeLimit(), |
||||
|
server->getPort(), |
||||
|
server->getSocketHostname().size(), server->getSocketHostname().ptr()); |
||||
|
|
||||
|
|
||||
|
// Level Rotation
|
||||
|
/*if (server->maps.size() != 0)
|
||||
|
{ |
||||
|
server_json_block += ",\"Levels\":["_jrs; |
||||
|
|
||||
|
server_json_block += "{\"Name\":\""_jrs; |
||||
|
server_json_block += server->maps.get(0)->name; |
||||
|
server_json_block += "\",\"GUID\":\""_jrs; |
||||
|
server_json_block += RenX::formatGUID(*server->maps.get(0)); |
||||
|
server_json_block += "\"}"_jrs; |
||||
|
|
||||
|
for (size_t index = 1; index != server->maps.size(); ++index) |
||||
|
{ |
||||
|
server_json_block += ",{\"Name\":\""_jrs; |
||||
|
server_json_block += server->maps.get(index)->name; |
||||
|
server_json_block += "\",\"GUID\":\""_jrs; |
||||
|
server_json_block += RenX::formatGUID(*server->maps.get(index)); |
||||
|
server_json_block += "\"}"_jrs; |
||||
|
} |
||||
|
|
||||
|
server_json_block += "]"_jrs; |
||||
|
} |
||||
|
|
||||
|
// Mutators
|
||||
|
if (server->mutators.size() != 0) |
||||
|
{ |
||||
|
server_json_block += ",\"Mutators\": ["_jrs; |
||||
|
|
||||
|
server_json_block += "{\"Name\":\""_jrs; |
||||
|
server_json_block += *server->mutators.get(0); |
||||
|
server_json_block += "\"}"_jrs; |
||||
|
|
||||
|
for (size_t index = 1; index != server->mutators.size(); ++index) |
||||
|
{ |
||||
|
server_json_block += ",{\"Name\":\""_jrs; |
||||
|
server_json_block += *server->mutators.get(index); |
||||
|
server_json_block += "\"}"_jrs; |
||||
|
} |
||||
|
|
||||
|
server_json_block += "]"_jrs; |
||||
|
}*/ |
||||
|
|
||||
|
server_json_block += "}"_jrs; |
||||
|
|
||||
|
return server_json_block; |
||||
|
} |
||||
|
|
||||
|
Jupiter::StringS server_as_hr_json(const RenX::Server *server) |
||||
|
{ |
||||
|
Jupiter::String server_json_block(128); |
||||
|
|
||||
|
Jupiter::String server_name = jsonify(server->getName()); |
||||
|
Jupiter::String server_map = jsonify(server->getMap().name); |
||||
|
Jupiter::String server_version = jsonify(server->getGameVersion()); |
||||
|
|
||||
|
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, |
||||
|
"Player Limit": %d, |
||||
|
"Vehicle Limit": %d, |
||||
|
"bAutoBalanceTeams": %s, |
||||
|
"bSpawnCrates": %s, |
||||
|
"CrateRespawnAfterPickup": %f, |
||||
|
"Time Limit": %d |
||||
|
}, |
||||
|
"Port": %u, |
||||
|
"IP": "%.*s")json", |
||||
|
|
||||
|
server_name.size(), server_name.ptr(), |
||||
|
server_map.size(), server_map.ptr(), |
||||
|
server->getBotCount(), |
||||
|
server->players.size() - server->getBotCount(), |
||||
|
server_version.size(), server_version.ptr(), |
||||
|
|
||||
|
server->getMineLimit(), |
||||
|
json_bool_as_cstring(server->isSteamRequired()), |
||||
|
json_bool_as_cstring(server->isPrivateMessageTeamOnly()), |
||||
|
json_bool_as_cstring(server->isPassworded()), |
||||
|
json_bool_as_cstring(server->isPrivateMessagingEnabled()), |
||||
|
server->getPlayerLimit(), |
||||
|
server->getVehicleLimit(), |
||||
|
json_bool_as_cstring(server->isAutoBalanceEnabled()), |
||||
|
json_bool_as_cstring(server->isCratesEnabled()), |
||||
|
server->getCrateRespawnDelay(), |
||||
|
server->getTimeLimit(), |
||||
|
|
||||
|
server->getPort(), |
||||
|
server->getSocketHostname().size(), server->getSocketHostname().ptr()); |
||||
|
|
||||
|
|
||||
|
// Level Rotation
|
||||
|
if (server->maps.size() != 0) |
||||
|
{ |
||||
|
server_json_block += ",\n\t\t\"Levels\": ["_jrs; |
||||
|
|
||||
|
server_json_block += "\n\t\t\t{\n\t\t\t\t\"Name\": \""_jrs; |
||||
|
server_json_block += server->maps.get(0)->name; |
||||
|
server_json_block += "\",\n\t\t\t\t\"GUID\": \""_jrs; |
||||
|
server_json_block += RenX::formatGUID(*server->maps.get(0)); |
||||
|
server_json_block += "\"\n\t\t\t}"_jrs; |
||||
|
|
||||
|
for (size_t index = 1; index != server->maps.size(); ++index) |
||||
|
{ |
||||
|
server_json_block += ",\n\t\t\t{\n\t\t\t\t\"Name\": \""_jrs; |
||||
|
server_json_block += server->maps.get(index)->name; |
||||
|
server_json_block += "\",\n\t\t\t\t\"GUID\": \""_jrs; |
||||
|
server_json_block += RenX::formatGUID(*server->maps.get(index)); |
||||
|
server_json_block += "\"\n\t\t\t}"_jrs; |
||||
|
} |
||||
|
|
||||
|
server_json_block += "\n\t\t]"_jrs; |
||||
|
} |
||||
|
|
||||
|
// Mutators
|
||||
|
if (server->mutators.size() != 0) |
||||
|
{ |
||||
|
server_json_block += ",\n\t\t\"Mutators\": ["_jrs; |
||||
|
|
||||
|
server_json_block += "\n\t\t\t{\n\t\t\t\t\"Name\": \""_jrs; |
||||
|
server_json_block += *server->mutators.get(0); |
||||
|
server_json_block += "\"\n\t\t\t}"_jrs; |
||||
|
|
||||
|
for (size_t index = 1; index != server->mutators.size(); ++index) |
||||
|
{ |
||||
|
server_json_block += ",\n\t\t\t{\n\t\t\t\t\"Name\": \""_jrs; |
||||
|
server_json_block += *server->mutators.get(index); |
||||
|
server_json_block += "\"\n\t\t\t}"_jrs; |
||||
|
} |
||||
|
|
||||
|
server_json_block += "\n\t\t]"_jrs; |
||||
|
} |
||||
|
|
||||
|
server_json_block += "\n\t}"_jrs; |
||||
|
|
||||
|
return server_json_block; |
||||
|
} |
||||
|
|
||||
|
void RenX_ServerListPlugin::addServerToServerList(const RenX::Server *server) |
||||
|
{ |
||||
|
// append to server_list_json
|
||||
|
|
||||
|
if (RenX_ServerListPlugin::server_list_json.isEmpty()) |
||||
|
{ |
||||
|
RenX_ServerListPlugin::server_list_json = '['; |
||||
|
RenX_ServerListPlugin::server_list_json += server_as_json(server); |
||||
|
RenX_ServerListPlugin::server_list_json += ']'; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
RenX_ServerListPlugin::server_list_json.truncate(1); // remove trailing ']'.
|
||||
|
RenX_ServerListPlugin::server_list_json += ','; |
||||
|
RenX_ServerListPlugin::server_list_json += server_as_json(server); |
||||
|
RenX_ServerListPlugin::server_list_json += ']'; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void RenX_ServerListPlugin::updateServerList() |
||||
|
{ |
||||
|
Jupiter::ArrayList<RenX::Server> servers = RenX::getCore()->getServers(); |
||||
|
size_t index = 0; |
||||
|
RenX::Server *server; |
||||
|
|
||||
|
// regenerate server_list_json
|
||||
|
|
||||
|
RenX_ServerListPlugin::server_list_json = '['; |
||||
|
|
||||
|
while (index != servers.size()) |
||||
|
{ |
||||
|
server = servers.get(index); |
||||
|
if (server->isConnected() && server->isFullyConnected()) |
||||
|
{ |
||||
|
RenX_ServerListPlugin::server_list_json += server_as_json(server); |
||||
|
++index; |
||||
|
break; |
||||
|
} |
||||
|
++index; |
||||
|
} |
||||
|
while (index != servers.size()) |
||||
|
{ |
||||
|
server = servers.get(index); |
||||
|
if (server->isConnected() && server->isFullyConnected()) |
||||
|
{ |
||||
|
RenX_ServerListPlugin::server_list_json += ','; |
||||
|
RenX_ServerListPlugin::server_list_json += server_as_json(server); |
||||
|
} |
||||
|
++index; |
||||
|
} |
||||
|
|
||||
|
RenX_ServerListPlugin::server_list_json += ']'; |
||||
|
} |
||||
|
|
||||
|
void RenX_ServerListPlugin::RenX_OnServerFullyConnected(RenX::Server *server) |
||||
|
{ |
||||
|
Jupiter::String server_json_block(256); |
||||
|
|
||||
|
this->addServerToServerList(server); |
||||
|
|
||||
|
// 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.get(0)->name); |
||||
|
server_json_block += "\",\"GUID\":\""_jrs; |
||||
|
server_json_block += RenX::formatGUID(*server->maps.get(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.get(index)->name); |
||||
|
server_json_block += "\",\"GUID\":\""_jrs; |
||||
|
server_json_block += RenX::formatGUID(*server->maps.get(index)); |
||||
|
server_json_block += "\"}"_jrs; |
||||
|
} |
||||
|
|
||||
|
server_json_block += ']'; |
||||
|
} |
||||
|
|
||||
|
// Mutators
|
||||
|
if (server->mutators.size() != 0) |
||||
|
{ |
||||
|
server_json_block += ",\"Mutators\":["_jrs; |
||||
|
|
||||
|
server_json_block += "{\"Name\":\""_jrs; |
||||
|
server_json_block += jsonify(*server->mutators.get(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.get(index)); |
||||
|
server_json_block += "\"}"_jrs; |
||||
|
} |
||||
|
|
||||
|
server_json_block += ']'; |
||||
|
} |
||||
|
|
||||
|
server_json_block += '}'; |
||||
|
|
||||
|
server->varData.set(this->name, "j"_jrs, server_json_block); |
||||
|
} |
||||
|
|
||||
|
void RenX_ServerListPlugin::RenX_OnServerDisconnect(RenX::Server *server, RenX::DisconnectReason) |
||||
|
{ |
||||
|
this->updateServerList(); |
||||
|
|
||||
|
// remove from individual listing
|
||||
|
server->varData.remove(this->name, "j"_jrs); |
||||
|
} |
||||
|
|
||||
|
void RenX_ServerListPlugin::RenX_OnJoin(RenX::Server *, const RenX::PlayerInfo *) |
||||
|
{ |
||||
|
this->updateServerList(); |
||||
|
} |
||||
|
|
||||
|
void RenX_ServerListPlugin::RenX_OnPart(RenX::Server *, const RenX::PlayerInfo *) |
||||
|
{ |
||||
|
this->updateServerList(); |
||||
|
} |
||||
|
|
||||
|
// Plugin instantiation and entry point.
|
||||
|
RenX_ServerListPlugin pluginInstance; |
||||
|
|
||||
|
Jupiter::ReadableString *handle_server_list_page(const Jupiter::ReadableString &) |
||||
|
{ |
||||
|
return pluginInstance.getServerListJSON(); |
||||
|
} |
||||
|
|
||||
|
Jupiter::ReadableString *handle_server_page(const Jupiter::ReadableString &query_string) |
||||
|
{ |
||||
|
Jupiter::HTTP::HTMLFormResponse html_form_response(query_string); |
||||
|
Jupiter::ReferenceString address; |
||||
|
int port = 0; |
||||
|
RenX::Server *server; |
||||
|
|
||||
|
// parse form data
|
||||
|
|
||||
|
if (html_form_response.table.size() < 2) |
||||
|
return new Jupiter::ReferenceString(); |
||||
|
|
||||
|
if (html_form_response.table.size() != 0) |
||||
|
{ |
||||
|
address = html_form_response.table.get("ip"_jrs, address); |
||||
|
port = html_form_response.table.getInt("port"_jrs, port); |
||||
|
} |
||||
|
|
||||
|
// search for server
|
||||
|
Jupiter::ArrayList<RenX::Server> servers = RenX::getCore()->getServers(); |
||||
|
size_t index = 0; |
||||
|
|
||||
|
while (true) |
||||
|
{ |
||||
|
if (index == servers.size()) |
||||
|
return new Jupiter::ReferenceString(); |
||||
|
|
||||
|
server = servers.get(index); |
||||
|
if (server->getSocketHostname().equals(address) && server->getPort() == port) |
||||
|
break; |
||||
|
|
||||
|
++index; |
||||
|
} |
||||
|
|
||||
|
// return server data
|
||||
|
return new Jupiter::ReferenceString(server->varData.get(pluginInstance.getName(), "j"_jrs)); |
||||
|
} |
||||
|
|
||||
|
extern "C" __declspec(dllexport) Jupiter::Plugin *getPlugin() |
||||
|
{ |
||||
|
return &pluginInstance; |
||||
|
} |
@ -0,0 +1,57 @@ |
|||||
|
/**
|
||||
|
* Copyright (C) 2016 Jessica James. |
||||
|
* |
||||
|
* Permission to use, copy, modify, and/or distribute this software for any |
||||
|
* purpose with or without fee is hereby granted, provided that the above |
||||
|
* copyright notice and this permission notice appear in all copies. |
||||
|
* |
||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
||||
|
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
||||
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
||||
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
||||
|
* |
||||
|
* Written by Jessica James <jessica.aj@outlook.com> |
||||
|
*/ |
||||
|
|
||||
|
#if !defined _RENX_SERVERLIST_H_HEADER |
||||
|
#define _RENX_SERVERLIST_H_HEADER |
||||
|
|
||||
|
#include "Jupiter/Plugin.h" |
||||
|
#include "Jupiter/Reference_String.h" |
||||
|
#include "RenX_Plugin.h" |
||||
|
|
||||
|
class RenX_ServerListPlugin : public RenX::Plugin |
||||
|
{ |
||||
|
public: // RenX_ServerListPlugin
|
||||
|
Jupiter::ReadableString *getServerListJSON(); |
||||
|
|
||||
|
void addServerToServerList(const RenX::Server *server); |
||||
|
void updateServerList(); |
||||
|
|
||||
|
RenX_ServerListPlugin(); |
||||
|
~RenX_ServerListPlugin(); |
||||
|
|
||||
|
public: // RenX::Plugin
|
||||
|
void RenX_OnServerFullyConnected(RenX::Server *server) override; |
||||
|
|
||||
|
void RenX_OnServerDisconnect(RenX::Server *server, RenX::DisconnectReason reason) override; |
||||
|
void RenX_OnJoin(RenX::Server *server, const RenX::PlayerInfo *player) override; |
||||
|
void RenX_OnPart(RenX::Server *server, const RenX::PlayerInfo *player) override; |
||||
|
|
||||
|
public: // Jupiter::Plugin
|
||||
|
const Jupiter::ReadableString &getName() override { return name; } |
||||
|
|
||||
|
private: |
||||
|
STRING_LITERAL_AS_NAMED_REFERENCE(name, "RenX.ServerList"); |
||||
|
|
||||
|
Jupiter::StringS server_list_json; |
||||
|
Jupiter::StringS web_hostname, web_path, server_list_page_name, server_page_name; |
||||
|
}; |
||||
|
|
||||
|
Jupiter::ReadableString *handle_server_list_page(const Jupiter::ReadableString &); |
||||
|
Jupiter::ReadableString *handle_server_page(const Jupiter::ReadableString &query_string); |
||||
|
|
||||
|
#endif // _RENX_SERVERLIST_H_HEADER
|
Loading…
Reference in new issue