diff --git a/Jupiter b/Jupiter index 0fba343..1df5bee 160000 --- a/Jupiter +++ b/Jupiter @@ -1 +1 @@ -Subproject commit 0fba343102afa3d397e613c85ca451d0085522f8 +Subproject commit 1df5bee1d49817471d9151b019dd244a610069eb diff --git a/Jupiter Bot.sln b/Jupiter Bot.sln index 32a6ffc..ad75497 100644 --- a/Jupiter Bot.sln +++ b/Jupiter Bot.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.23107.0 +VisualStudioVersion = 14.0.24720.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Bot", "Bot\Bot.vcxproj", "{C188871B-5F32-4946-B301-24CA2EBB275D}" EndProject @@ -178,7 +178,36 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RenX.Ladder.Web", "RenX.Lad {C188871B-5F32-4946-B301-24CA2EBB275D} = {C188871B-5F32-4946-B301-24CA2EBB275D} {9103DF3D-8B4A-48E5-A6B3-CBE2554630E2} = {9103DF3D-8B4A-48E5-A6B3-CBE2554630E2} {BB048D6F-F001-4E9B-95F4-886081E0807A} = {BB048D6F-F001-4E9B-95F4-886081E0807A} - {B2846BD6-2332-4DA6-A13B-113318F76D5E} = {B2846BD6-2332-4DA6-A13B-113318F76D5E} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RenX.Ladder.All-Time", "RenX.Ladder.All-Time\RenX.Ladder.All-Time.vcxproj", "{24B039D0-5A71-4F76-8908-BAD772FDBE1A}" + ProjectSection(ProjectDependencies) = postProject + {C188871B-5F32-4946-B301-24CA2EBB275D} = {C188871B-5F32-4946-B301-24CA2EBB275D} + {9103DF3D-8B4A-48E5-A6B3-CBE2554630E2} = {9103DF3D-8B4A-48E5-A6B3-CBE2554630E2} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RenX.Ladder.Monthly", "RenX.Ladder.Monthly\RenX.Ladder.Monthly.vcxproj", "{34FDE301-A29D-44ED-8ECC-15693F137DE2}" + ProjectSection(ProjectDependencies) = postProject + {C188871B-5F32-4946-B301-24CA2EBB275D} = {C188871B-5F32-4946-B301-24CA2EBB275D} + {9103DF3D-8B4A-48E5-A6B3-CBE2554630E2} = {9103DF3D-8B4A-48E5-A6B3-CBE2554630E2} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RenX.Ladder.Yearly", "RenX.Ladder.Yearly\RenX.Ladder.Yearly.vcxproj", "{075AF69B-71D6-43B9-B102-4649CB2CA40C}" + ProjectSection(ProjectDependencies) = postProject + {C188871B-5F32-4946-B301-24CA2EBB275D} = {C188871B-5F32-4946-B301-24CA2EBB275D} + {9103DF3D-8B4A-48E5-A6B3-CBE2554630E2} = {9103DF3D-8B4A-48E5-A6B3-CBE2554630E2} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RenX.Ladder.Weekly", "RenX.Ladder.Weekly\RenX.Ladder.Weekly.vcxproj", "{6F0141F3-CF64-47D9-8EC2-80A38FAFDAC7}" + ProjectSection(ProjectDependencies) = postProject + {C188871B-5F32-4946-B301-24CA2EBB275D} = {C188871B-5F32-4946-B301-24CA2EBB275D} + {9103DF3D-8B4A-48E5-A6B3-CBE2554630E2} = {9103DF3D-8B4A-48E5-A6B3-CBE2554630E2} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RenX.Ladder.Daily", "RenX.Ladder.Daily\RenX.Ladder.Daily.vcxproj", "{73F0EEF6-CE5E-46EB-80B4-2B319AE2B258}" + ProjectSection(ProjectDependencies) = postProject + {C188871B-5F32-4946-B301-24CA2EBB275D} = {C188871B-5F32-4946-B301-24CA2EBB275D} + {9103DF3D-8B4A-48E5-A6B3-CBE2554630E2} = {9103DF3D-8B4A-48E5-A6B3-CBE2554630E2} EndProjectSection EndProject Global @@ -311,6 +340,26 @@ Global {57661A2A-EE94-4E9C-B792-AB756533DEFA}.Debug|Win32.Build.0 = Debug|Win32 {57661A2A-EE94-4E9C-B792-AB756533DEFA}.Release|Win32.ActiveCfg = Release|Win32 {57661A2A-EE94-4E9C-B792-AB756533DEFA}.Release|Win32.Build.0 = Release|Win32 + {24B039D0-5A71-4F76-8908-BAD772FDBE1A}.Debug|Win32.ActiveCfg = Debug|Win32 + {24B039D0-5A71-4F76-8908-BAD772FDBE1A}.Debug|Win32.Build.0 = Debug|Win32 + {24B039D0-5A71-4F76-8908-BAD772FDBE1A}.Release|Win32.ActiveCfg = Release|Win32 + {24B039D0-5A71-4F76-8908-BAD772FDBE1A}.Release|Win32.Build.0 = Release|Win32 + {34FDE301-A29D-44ED-8ECC-15693F137DE2}.Debug|Win32.ActiveCfg = Debug|Win32 + {34FDE301-A29D-44ED-8ECC-15693F137DE2}.Debug|Win32.Build.0 = Debug|Win32 + {34FDE301-A29D-44ED-8ECC-15693F137DE2}.Release|Win32.ActiveCfg = Release|Win32 + {34FDE301-A29D-44ED-8ECC-15693F137DE2}.Release|Win32.Build.0 = Release|Win32 + {075AF69B-71D6-43B9-B102-4649CB2CA40C}.Debug|Win32.ActiveCfg = Debug|Win32 + {075AF69B-71D6-43B9-B102-4649CB2CA40C}.Debug|Win32.Build.0 = Debug|Win32 + {075AF69B-71D6-43B9-B102-4649CB2CA40C}.Release|Win32.ActiveCfg = Release|Win32 + {075AF69B-71D6-43B9-B102-4649CB2CA40C}.Release|Win32.Build.0 = Release|Win32 + {6F0141F3-CF64-47D9-8EC2-80A38FAFDAC7}.Debug|Win32.ActiveCfg = Debug|Win32 + {6F0141F3-CF64-47D9-8EC2-80A38FAFDAC7}.Debug|Win32.Build.0 = Debug|Win32 + {6F0141F3-CF64-47D9-8EC2-80A38FAFDAC7}.Release|Win32.ActiveCfg = Release|Win32 + {6F0141F3-CF64-47D9-8EC2-80A38FAFDAC7}.Release|Win32.Build.0 = Release|Win32 + {73F0EEF6-CE5E-46EB-80B4-2B319AE2B258}.Debug|Win32.ActiveCfg = Debug|Win32 + {73F0EEF6-CE5E-46EB-80B4-2B319AE2B258}.Debug|Win32.Build.0 = Debug|Win32 + {73F0EEF6-CE5E-46EB-80B4-2B319AE2B258}.Release|Win32.ActiveCfg = Release|Win32 + {73F0EEF6-CE5E-46EB-80B4-2B319AE2B258}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Release/Bot.lib b/Release/Bot.lib index 8016e2f..42759c5 100644 Binary files a/Release/Bot.lib and b/Release/Bot.lib differ diff --git a/Release/Plugins/RenX.Core.lib b/Release/Plugins/RenX.Core.lib index aeff645..3c0edd0 100644 Binary files a/Release/Plugins/RenX.Core.lib and b/Release/Plugins/RenX.Core.lib differ diff --git a/RenX.Commands/RenX_Commands.cpp b/RenX.Commands/RenX_Commands.cpp index 6aa5adf..4715928 100644 --- a/RenX.Commands/RenX_Commands.cpp +++ b/RenX.Commands/RenX_Commands.cpp @@ -1307,6 +1307,8 @@ void GameOverIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString { int type = chan->getType(); bool match = false; + std::chrono::seconds delay; + for (unsigned int i = 0; i != RenX::getCore()->getServerCount(); i++) { RenX::Server *server = RenX::getCore()->getServer(i); @@ -1317,15 +1319,28 @@ void GameOverIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString server->gameoverWhenEmpty(); if (parameters.equalsi("if empty"_jrs)) { - if (server->players.size() == 0) + if (server->players.size() == server->getBotCount()) server->gameover(); } else if (parameters.equalsi("now"_jrs)) server->gameover(); - else if (parameters.isEmpty()) - server->gameover(std::chrono::seconds(10)); + else if (parameters.equalsi("stop"_jrs) || parameters.equalsi("cancel"_jrs)) + { + if (server->gameoverStop()) + server->sendMessage("Notice: The scheduled gameover has been cancelled."_jrs); + else + source->sendNotice(nick, "Error: There is no gameover scheduled."_jrs); + } else - server->gameover(std::chrono::seconds(parameters.asInt())); + { + if (parameters.isEmpty()) + delay = std::chrono::seconds(10); + else + delay = std::chrono::seconds(parameters.asLongLong()); + + server->sendMessage(Jupiter::StringS::Format("Notice: This server will gameover in %lld seconds.", static_cast(delay.count()))); + server->gameover(delay); + } } } if (match == false) @@ -1335,7 +1350,7 @@ void GameOverIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString const Jupiter::ReadableString &GameOverIRCCommand::getHelp(const Jupiter::ReadableString &) { - static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Ends the game immediately. Syntax: Gameover [NOW | Empty | Seconds = 10]"); + static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Forcefully ends the game in progress. Syntax: Gameover [NOW | STOP | Empty | Seconds = 10]"); return defaultHelp; } diff --git a/RenX.Core/RenX_LadderDatabase.cpp b/RenX.Core/RenX_LadderDatabase.cpp index 36e83e8..9b9624a 100644 --- a/RenX.Core/RenX_LadderDatabase.cpp +++ b/RenX.Core/RenX_LadderDatabase.cpp @@ -1,32 +1,41 @@ /** -* Copyright (C) 2015-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 -*/ + * Copyright (C) 2015-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 + */ #include "RenX_LadderDatabase.h" #include "RenX_Server.h" #include "RenX_PlayerInfo.h" #include "RenX_BanDatabase.h" +RenX::LadderDatabase *RenX::default_ladder_database = nullptr; Jupiter::ArrayList _ladder_databases; Jupiter::ArrayList &RenX::ladder_databases = _ladder_databases; RenX::LadderDatabase::LadderDatabase() { _ladder_databases.add(this); + + if (RenX::default_ladder_database == nullptr) + RenX::default_ladder_database = this; +} + +RenX::LadderDatabase::LadderDatabase(const Jupiter::ReadableString &in_name) : LadderDatabase() +{ + RenX::LadderDatabase::setName(in_name); } RenX::LadderDatabase::~LadderDatabase() @@ -37,6 +46,21 @@ RenX::LadderDatabase::~LadderDatabase() RenX::LadderDatabase::head = RenX::LadderDatabase::head->next; delete RenX::LadderDatabase::end; } + + for (size_t index = 0; index != _ladder_databases.size(); ++index) + if (_ladder_databases.get(index) == this) + { + _ladder_databases.remove(index); + break; + } + + if (RenX::default_ladder_database == this) + { + if (_ladder_databases.size() == 0) + RenX::default_ladder_database = nullptr; + else + RenX::default_ladder_database = _ladder_databases.get(0); + } } void RenX::LadderDatabase::process_data(Jupiter::DataBuffer &buffer, FILE *file, fpos_t pos) @@ -371,6 +395,10 @@ void RenX::LadderDatabase::updateLadder(RenX::Server *server, const RenX::TeamTy { if (server->players.size() != server->getBotCount()) { + // call the PreUpdateLadder event + if (this->OnPreUpdateLadder != nullptr) + this->OnPreUpdateLadder(*this, server, team, output_times); + // update player stats in memory RenX::PlayerInfo *player; RenX::LadderDatabase::Entry *entry; @@ -482,3 +510,13 @@ void RenX::LadderDatabase::erase() RenX::LadderDatabase::end = nullptr; } } + +const Jupiter::ReadableString &RenX::LadderDatabase::getName() const +{ + return RenX::LadderDatabase::name; +} + +void RenX::LadderDatabase::setName(const Jupiter::ReadableString &in_name) +{ + RenX::LadderDatabase::name = in_name; +} diff --git a/RenX.Core/RenX_LadderDatabase.h b/RenX.Core/RenX_LadderDatabase.h index 0609a7d..54a73b9 100644 --- a/RenX.Core/RenX_LadderDatabase.h +++ b/RenX.Core/RenX_LadderDatabase.h @@ -1,20 +1,20 @@ /** -* Copyright (C) 2015-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 -*/ + * Copyright (C) 2015-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 + */ #if !defined _RENX_LADDERDATABASE_H_HEADER #define _RENX_LADDERDATABASE_H_HEADER @@ -39,13 +39,14 @@ namespace RenX class RENX_API LadderDatabase : public Jupiter::Database { public: // Jupiter::Database - /** - * @brief Processes a chunk of data in a database. - * - * @param buffer Buffer to process - * @param file File being processed - * @param pos position that the buffer starts at in the file - */ + + /** + * @brief Processes a chunk of data in a database. + * + * @param buffer Buffer to process + * @param file File being processed + * @param pos position that the buffer starts at in the file + */ void process_data(Jupiter::DataBuffer &buffer, FILE *file, fpos_t pos) override; /** @@ -174,27 +175,47 @@ namespace RenX */ void erase(); + /** + * @brief Gets the name of this database. + */ + const Jupiter::ReadableString &getName() const; + + /** + * @brief Sets the name of this database. + */ + void setName(const Jupiter::ReadableString &in_name); + /** * @brief Constructor for the LadderDatabase class */ LadderDatabase(); + /** + * @brief Named constructor for the LadderDatabase class + */ + LadderDatabase(const Jupiter::ReadableString &in_name); + /** * @brief Deconstructor for the LadderDatabase class */ ~LadderDatabase(); - private: + typedef void PreUpdateLadderFunction(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team, bool output_times); + PreUpdateLadderFunction *OnPreUpdateLadder = nullptr; + + private: /** Database version */ const uint8_t write_version = 0; uint8_t read_version = write_version; + Jupiter::StringS name; std::chrono::steady_clock::time_point last_sort = std::chrono::steady_clock::now(); size_t entries = 0; Entry *head = nullptr; - Entry *end; + Entry *end = nullptr; }; + RENX_API extern RenX::LadderDatabase *default_ladder_database; RENX_API extern Jupiter::ArrayList &ladder_databases; } diff --git a/RenX.Core/RenX_Server.h b/RenX.Core/RenX_Server.h index bb779d5..41e1339 100644 --- a/RenX.Core/RenX_Server.h +++ b/RenX.Core/RenX_Server.h @@ -430,6 +430,13 @@ namespace RenX */ void gameover(std::chrono::seconds delay); + /** + * @brief Prevents a delayed gameover from starting. + * + * @return True if a delayed gameover was stopped, false otherwise. + */ + bool gameoverStop(); + /** * @brief Forces the game to end when the server is empty */ diff --git a/RenX.Core/RenX_Tags.h b/RenX.Core/RenX_Tags.h index a0eb0b7..2f0b7d0 100644 --- a/RenX.Core/RenX_Tags.h +++ b/RenX.Core/RenX_Tags.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2015 Jessica James. + * Copyright (C) 2015-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 diff --git a/RenX.Ladder.All-Time/RenX.Ladder.All-Time.vcxproj b/RenX.Ladder.All-Time/RenX.Ladder.All-Time.vcxproj new file mode 100644 index 0000000..5bab885 --- /dev/null +++ b/RenX.Ladder.All-Time/RenX.Ladder.All-Time.vcxproj @@ -0,0 +1,85 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {24B039D0-5A71-4F76-8908-BAD772FDBE1A} + RenX.Ladder.All-Time + + + + Application + true + v140 + MultiByte + + + DynamicLibrary + false + v140 + true + Unicode + + + + + + + + + + + + + $(SolutionDir)$(Configuration)\Plugins\ + AllRules.ruleset + + + + Level3 + Disabled + true + + + true + + + + + Level3 + MaxSpeed + true + true + true + ../Bot;../Jupiter;../RenX.Core + _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + + + true + true + true + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/RenX.Ladder.All-Time/RenX.Ladder.All-Time.vcxproj.filters b/RenX.Ladder.All-Time/RenX.Ladder.All-Time.vcxproj.filters new file mode 100644 index 0000000..3199366 --- /dev/null +++ b/RenX.Ladder.All-Time/RenX.Ladder.All-Time.vcxproj.filters @@ -0,0 +1,38 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Resource Files + + + Resource Files + + + Resource Files + + + + + Header Files + + + + + Source Files + + + \ No newline at end of file diff --git a/RenX.Ladder.All-Time/RenX_Ladder_All_Time.cpp b/RenX.Ladder.All-Time/RenX_Ladder_All_Time.cpp new file mode 100644 index 0000000..27c3e37 --- /dev/null +++ b/RenX.Ladder.All-Time/RenX_Ladder_All_Time.cpp @@ -0,0 +1,42 @@ +/** + * 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 + */ + +#include "Jupiter/INIFile.h" +#include "Jupiter/IRC_Client.h" +#include "RenX_Ladder_All_Time.h" + +using namespace Jupiter::literals; + +RenX_Ladder_All_TimePlugin::RenX_Ladder_All_TimePlugin() +{ + // Load database + this->database.process_file(Jupiter::IRC::Client::Config->get(this->getName(), "LadderDatabase"_jrs, "Ladder.db"_jrs)); + this->database.setName(Jupiter::IRC::Client::Config->get(this->getName(), "DatabaseName"_jrs, "All-Time"_jrs)); + + // Force database to default, if desired + if (Jupiter::IRC::Client::Config->getBool(this->getName(), "ForceDefault"_jrs, false)) + RenX::default_ladder_database = &this->database; +} + +// Plugin instantiation and entry point. +RenX_Ladder_All_TimePlugin pluginInstance; + +extern "C" __declspec(dllexport) Jupiter::Plugin *getPlugin() +{ + return &pluginInstance; +} diff --git a/RenX.Ladder.All-Time/RenX_Ladder_All_Time.h b/RenX.Ladder.All-Time/RenX_Ladder_All_Time.h new file mode 100644 index 0000000..2b47656 --- /dev/null +++ b/RenX.Ladder.All-Time/RenX_Ladder_All_Time.h @@ -0,0 +1,38 @@ +/** + * 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 + */ + +#if !defined _RENX_LADDER_ALL_TIME +#define _RENX_LADDER_ALL_TIME + +#include "Jupiter/Plugin.h" +#include "Jupiter/Reference_String.h" +#include "RenX_Plugin.h" +#include "RenX_LadderDatabase.h" + +class RenX_Ladder_All_TimePlugin : public RenX::Plugin +{ +public: + const Jupiter::ReadableString &getName() override { return name; } + + RenX_Ladder_All_TimePlugin(); +private: + RenX::LadderDatabase database; + STRING_LITERAL_AS_NAMED_REFERENCE(name, "RenX.Ladder.All-Time"); +}; + +#endif // _RENX_LADDER_ALL_TIME \ No newline at end of file diff --git a/RenX.Ladder.Daily/RenX.Ladder.Daily.vcxproj b/RenX.Ladder.Daily/RenX.Ladder.Daily.vcxproj new file mode 100644 index 0000000..a43cd17 --- /dev/null +++ b/RenX.Ladder.Daily/RenX.Ladder.Daily.vcxproj @@ -0,0 +1,85 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {73F0EEF6-CE5E-46EB-80B4-2B319AE2B258} + RenX.Ladder.Daily + + + + Application + true + v140 + MultiByte + + + DynamicLibrary + false + v140 + true + Unicode + + + + + + + + + + + + + $(SolutionDir)$(Configuration)\Plugins\ + AllRules.ruleset + + + + Level3 + Disabled + true + + + true + + + + + Level3 + MaxSpeed + true + true + true + ../Bot;../Jupiter;../RenX.Core + _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + + + true + true + true + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/RenX.Ladder.Daily/RenX.Ladder.Daily.vcxproj.filters b/RenX.Ladder.Daily/RenX.Ladder.Daily.vcxproj.filters new file mode 100644 index 0000000..21fc8b3 --- /dev/null +++ b/RenX.Ladder.Daily/RenX.Ladder.Daily.vcxproj.filters @@ -0,0 +1,38 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + + + Resource Files + + + Resource Files + + + Resource Files + + + + + Header Files + + + \ No newline at end of file diff --git a/RenX.Ladder.Daily/RenX_Ladder_Daily.cpp b/RenX.Ladder.Daily/RenX_Ladder_Daily.cpp new file mode 100644 index 0000000..5b90824 --- /dev/null +++ b/RenX.Ladder.Daily/RenX_Ladder_Daily.cpp @@ -0,0 +1,54 @@ +/** + * 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 + */ + +#include +#include "Jupiter/INIFile.h" +#include "Jupiter/IRC_Client.h" +#include "RenX_Ladder_Daily.h" + +using namespace Jupiter::literals; + +RenX_Ladder_Daily_TimePlugin::RenX_Ladder_Daily_TimePlugin() +{ + // Load database + this->database.process_file(Jupiter::IRC::Client::Config->get(this->getName(), "LadderDatabase"_jrs, "Ladder.Daily.db"_jrs)); + this->database.setName(Jupiter::IRC::Client::Config->get(this->getName(), "DatabaseName"_jrs, "Daily"_jrs)); + + this->last_sorted_day = gmtime(std::addressof(time(0)))->tm_wday; + this->database.OnPreUpdateLadder = OnPreUpdateLadder; + + // Force database to default, if desired + if (Jupiter::IRC::Client::Config->getBool(this->getName(), "ForceDefault"_jrs, false)) + RenX::default_ladder_database = &this->database; +} + +// Plugin instantiation and entry point. +RenX_Ladder_Daily_TimePlugin pluginInstance; + +void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team, bool output_times) +{ + tm *tm_ptr = gmtime(std::addressof(time(0))); + if (pluginInstance.last_sorted_day != tm_ptr->tm_wday) + database.erase(); + pluginInstance.last_sorted_day = tm_ptr->tm_wday; +} + +extern "C" __declspec(dllexport) Jupiter::Plugin *getPlugin() +{ + return &pluginInstance; +} diff --git a/RenX.Ladder.Daily/RenX_Ladder_Daily.h b/RenX.Ladder.Daily/RenX_Ladder_Daily.h new file mode 100644 index 0000000..be3f87c --- /dev/null +++ b/RenX.Ladder.Daily/RenX_Ladder_Daily.h @@ -0,0 +1,42 @@ +/** + * 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 + */ + +#if !defined _RENX_LADDER_ALL_TIME +#define _RENX_LADDER_ALL_TIME + +#include "Jupiter/Plugin.h" +#include "Jupiter/Reference_String.h" +#include "RenX_Plugin.h" +#include "RenX_LadderDatabase.h" + +class RenX_Ladder_Daily_TimePlugin : public RenX::Plugin +{ +public: + const Jupiter::ReadableString &getName() override { return name; } + + RenX_Ladder_Daily_TimePlugin(); + + int last_sorted_day = 0; +private: + RenX::LadderDatabase database; + STRING_LITERAL_AS_NAMED_REFERENCE(name, "RenX.Ladder.Daily"); +}; + +void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team, bool output_times); + +#endif // _RENX_LADDER_ALL_TIME \ No newline at end of file diff --git a/RenX.Ladder.Monthly/RenX.Ladder.Monthly.vcxproj b/RenX.Ladder.Monthly/RenX.Ladder.Monthly.vcxproj new file mode 100644 index 0000000..bbe7002 --- /dev/null +++ b/RenX.Ladder.Monthly/RenX.Ladder.Monthly.vcxproj @@ -0,0 +1,85 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {34FDE301-A29D-44ED-8ECC-15693F137DE2} + RenX.Ladder.Monthly + + + + Application + true + v140 + MultiByte + + + DynamicLibrary + false + v140 + true + Unicode + + + + + + + + + + + + + $(SolutionDir)$(Configuration)\Plugins\ + AllRules.ruleset + + + + Level3 + Disabled + true + + + true + + + + + Level3 + MaxSpeed + true + true + true + ../Bot;../Jupiter;../RenX.Core + _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + + + true + true + true + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/RenX.Ladder.Monthly/RenX.Ladder.Monthly.vcxproj.filters b/RenX.Ladder.Monthly/RenX.Ladder.Monthly.vcxproj.filters new file mode 100644 index 0000000..81306c7 --- /dev/null +++ b/RenX.Ladder.Monthly/RenX.Ladder.Monthly.vcxproj.filters @@ -0,0 +1,38 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + + + Resource Files + + + Resource Files + + + Resource Files + + + + + Header Files + + + \ No newline at end of file diff --git a/RenX.Ladder.Monthly/RenX_Ladder_Monthly.cpp b/RenX.Ladder.Monthly/RenX_Ladder_Monthly.cpp new file mode 100644 index 0000000..f4a46e1 --- /dev/null +++ b/RenX.Ladder.Monthly/RenX_Ladder_Monthly.cpp @@ -0,0 +1,54 @@ +/** + * 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 + */ + +#include +#include "Jupiter/INIFile.h" +#include "Jupiter/IRC_Client.h" +#include "RenX_Ladder_Monthly.h" + +using namespace Jupiter::literals; + +RenX_Ladder_Monthly_TimePlugin::RenX_Ladder_Monthly_TimePlugin() +{ + // Load database + this->database.process_file(Jupiter::IRC::Client::Config->get(this->getName(), "LadderDatabase"_jrs, "Ladder.Monthly.db"_jrs)); + this->database.setName(Jupiter::IRC::Client::Config->get(this->getName(), "DatabaseName"_jrs, "Monthly"_jrs)); + + this->last_sorted_month = gmtime(std::addressof(time(0)))->tm_mon; + this->database.OnPreUpdateLadder = OnPreUpdateLadder; + + // Force database to default, if desired + if (Jupiter::IRC::Client::Config->getBool(this->getName(), "ForceDefault"_jrs, false)) + RenX::default_ladder_database = &this->database; +} + +// Plugin instantiation and entry point. +RenX_Ladder_Monthly_TimePlugin pluginInstance; + +void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team, bool output_times) +{ + tm *tm_ptr = gmtime(std::addressof(time(0))); + if (pluginInstance.last_sorted_month != tm_ptr->tm_mon) + database.erase(); + pluginInstance.last_sorted_month = tm_ptr->tm_mon; +} + +extern "C" __declspec(dllexport) Jupiter::Plugin *getPlugin() +{ + return &pluginInstance; +} diff --git a/RenX.Ladder.Monthly/RenX_Ladder_Monthly.h b/RenX.Ladder.Monthly/RenX_Ladder_Monthly.h new file mode 100644 index 0000000..a556d37 --- /dev/null +++ b/RenX.Ladder.Monthly/RenX_Ladder_Monthly.h @@ -0,0 +1,42 @@ +/** + * 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 + */ + +#if !defined _RENX_LADDER_ALL_TIME +#define _RENX_LADDER_ALL_TIME + +#include "Jupiter/Plugin.h" +#include "Jupiter/Reference_String.h" +#include "RenX_Plugin.h" +#include "RenX_LadderDatabase.h" + +class RenX_Ladder_Monthly_TimePlugin : public RenX::Plugin +{ +public: + const Jupiter::ReadableString &getName() override { return name; } + + RenX_Ladder_Monthly_TimePlugin(); + + int last_sorted_month = 0; +private: + RenX::LadderDatabase database; + STRING_LITERAL_AS_NAMED_REFERENCE(name, "RenX.Ladder.Monthly"); +}; + +void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team, bool output_times); + +#endif // _RENX_LADDER_ALL_TIME \ No newline at end of file diff --git a/RenX.Ladder.Web/RenX_Ladder_Web.cpp b/RenX.Ladder.Web/RenX_Ladder_Web.cpp index 3982630..60cd309 100644 --- a/RenX.Ladder.Web/RenX_Ladder_Web.cpp +++ b/RenX.Ladder.Web/RenX_Ladder_Web.cpp @@ -150,15 +150,62 @@ int RenX_Ladder_WebPlugin::OnRehash() return 0; } -/** Ladder page */ +/** Search bar */ +Jupiter::String generate_search(RenX::LadderDatabase *db) +{ + Jupiter::String result(256); + + result = R"database-search()database-search"_jrs; + return result; +} -Jupiter::String RenX_Ladder_WebPlugin::generate_entry_table(size_t index, size_t count) +/** Database selector */ +Jupiter::String generate_database_selector(RenX::LadderDatabase *db) { - if (RenX::ladder_databases.size() == 0) - return Jupiter::String("Error: No ladder databases loaded"_jrs); + RenX::LadderDatabase *db_ptr; + Jupiter::String result(256); + + result = R"database-select(
)database-select"_jrs; + return result; +} - RenX::LadderDatabase *db = RenX::ladder_databases.get(0); +/** Ladder page */ +Jupiter::String RenX_Ladder_WebPlugin::generate_entry_table(RenX::LadderDatabase *db, size_t index, size_t count) +{ if (db->getEntries() == 0) // No ladder data return Jupiter::String("Error: No ladder data"_jrs); @@ -197,27 +244,22 @@ Jupiter::String RenX_Ladder_WebPlugin::generate_entry_table(size_t index, size_t return result; } -Jupiter::String *RenX_Ladder_WebPlugin::generate_ladder_page(size_t index, size_t count) +Jupiter::String *RenX_Ladder_WebPlugin::generate_ladder_page(RenX::LadderDatabase *db, size_t index, size_t count) { Jupiter::String *result = new Jupiter::String(RenX_Ladder_WebPlugin::header); - result->concat(this->generate_entry_table(index, count)); + result->concat(generate_search(db)); + result->concat(generate_database_selector(db)); + result->concat(this->generate_entry_table(db, index, count)); result->concat(RenX_Ladder_WebPlugin::footer); return result; } /** Search page */ -Jupiter::String *RenX_Ladder_WebPlugin::generate_search_page(const Jupiter::ReadableString &name) +Jupiter::String *RenX_Ladder_WebPlugin::generate_search_page(RenX::LadderDatabase *db, const Jupiter::ReadableString &name) { Jupiter::String *result = new Jupiter::String(RenX_Ladder_WebPlugin::header); - - if (RenX::ladder_databases.size() == 0) - { - result->concat("Error: No ladder databases loaded"_jrs); - result->concat(RenX_Ladder_WebPlugin::footer); - return result; - } - - RenX::LadderDatabase *db = RenX::ladder_databases.get(0); + result->concat(generate_search(db)); + result->concat(generate_database_selector(db)); if (db->getEntries() == 0) // No ladder data { @@ -248,18 +290,11 @@ Jupiter::String *RenX_Ladder_WebPlugin::generate_search_page(const Jupiter::Read } /** Profile page */ -Jupiter::String *RenX_Ladder_WebPlugin::generate_profile_page(uint64_t steam_id) +Jupiter::String *RenX_Ladder_WebPlugin::generate_profile_page(RenX::LadderDatabase *db, uint64_t steam_id) { Jupiter::String *result = new Jupiter::String(RenX_Ladder_WebPlugin::header); - - if (RenX::ladder_databases.size() == 0) - { - result->concat("Error: No ladder databases loaded"_jrs); - result->concat(RenX_Ladder_WebPlugin::footer); - return result; - } - - RenX::LadderDatabase *db = RenX::ladder_databases.get(0); + result->concat(generate_search(db)); + result->concat(generate_database_selector(db)); if (db->getEntries() == 0) // No ladder data { @@ -294,8 +329,24 @@ RenX_Ladder_WebPlugin pluginInstance; /** Content functions */ +Jupiter::ReadableString *generate_no_db_page() +{ + Jupiter::String *result = new Jupiter::String(pluginInstance.header); + if (RenX::ladder_databases.size() != 0) + { + result->concat(generate_search(nullptr)); + result->concat(generate_database_selector(nullptr)); + result->concat("Error: No such database exists"_jrs); + } + else + result->concat("Error: No ladder databases loaded"_jrs); + result->concat(pluginInstance.footer); + return result; +} + Jupiter::ReadableString *handle_ladder_page(const Jupiter::ReadableString &query_string) { + RenX::LadderDatabase *db = RenX::default_ladder_database; size_t start_index = 0, count = 50; if (query_string.isNotEmpty()) @@ -303,35 +354,85 @@ Jupiter::ReadableString *handle_ladder_page(const Jupiter::ReadableString &query Jupiter::HTTP::HTMLFormResponse html_form_response(query_string); start_index = static_cast(html_form_response.table.getInt("start"_jrs, 0)); count = static_cast(html_form_response.table.getInt("count"_jrs, 50)); + + const Jupiter::ReadableString &db_name = html_form_response.table.get("database"_jrs); + if (db_name.isNotEmpty()) + { + db = nullptr; + for (size_t index = 0; index != RenX::ladder_databases.size(); ++index) + if (RenX::ladder_databases.get(index)->getName().equalsi(db_name)) + { + db = RenX::ladder_databases.get(index); + break; + } + } } - return pluginInstance.generate_ladder_page(start_index, count); + + if (db == nullptr) + return generate_no_db_page(); + + return pluginInstance.generate_ladder_page(db, start_index, count); } Jupiter::ReadableString *handle_search_page(const Jupiter::ReadableString &query_string) { + RenX::LadderDatabase *db = RenX::default_ladder_database; Jupiter::ReferenceString name; + if (query_string.isNotEmpty()) { Jupiter::HTTP::HTMLFormResponse html_form_response(query_string); name = html_form_response.table.get("name"_jrs); + + const Jupiter::ReadableString &db_name = html_form_response.table.get("database"_jrs); + if (db_name.isNotEmpty()) + { + db = nullptr; + for (size_t index = 0; index != RenX::ladder_databases.size(); ++index) + if (RenX::ladder_databases.get(index)->getName().equalsi(db_name)) + { + db = RenX::ladder_databases.get(index); + break; + } + } } + if (db == nullptr) + return generate_no_db_page(); + if (name.isEmpty()) // Generate ladder page when no name specified return handle_ladder_page(query_string); - return pluginInstance.generate_search_page(name); + return pluginInstance.generate_search_page(db, name); } Jupiter::ReadableString *handle_profile_page(const Jupiter::ReadableString &query_string) { + RenX::LadderDatabase *db = RenX::default_ladder_database; uint64_t steam_id = 0; + if (query_string.isNotEmpty()) { Jupiter::HTTP::HTMLFormResponse html_form_response(query_string); steam_id = html_form_response.table.getLongLong("id"_jrs); + + const Jupiter::ReadableString &db_name = html_form_response.table.get("database"_jrs); + if (db_name.isNotEmpty()) + { + db = nullptr; + for (size_t index = 0; index != RenX::ladder_databases.size(); ++index) + if (RenX::ladder_databases.get(index)->getName().equalsi(db_name)) + { + db = RenX::ladder_databases.get(index); + break; + } + } } - return pluginInstance.generate_profile_page(steam_id); + if (db == nullptr) + return generate_no_db_page(); + + return pluginInstance.generate_profile_page(db, steam_id); } extern "C" __declspec(dllexport) Jupiter::Plugin *getPlugin() diff --git a/RenX.Ladder.Web/RenX_Ladder_Web.h b/RenX.Ladder.Web/RenX_Ladder_Web.h index c4478e3..0715a57 100644 --- a/RenX.Ladder.Web/RenX_Ladder_Web.h +++ b/RenX.Ladder.Web/RenX_Ladder_Web.h @@ -27,14 +27,14 @@ class RenX_Ladder_WebPlugin : public RenX::Plugin { protected: - Jupiter::String generate_entry_table(size_t index, size_t count); + Jupiter::String generate_entry_table(RenX::LadderDatabase *db, size_t index, size_t count); public: Jupiter::StringS header; Jupiter::StringS footer; - Jupiter::String *generate_ladder_page(size_t start_index, size_t count); - Jupiter::String *generate_search_page(const Jupiter::ReadableString &name); - Jupiter::String *generate_profile_page(uint64_t steam_id); + Jupiter::String *generate_ladder_page(RenX::LadderDatabase *db, size_t start_index, size_t count); + Jupiter::String *generate_search_page(RenX::LadderDatabase *db, const Jupiter::ReadableString &name); + Jupiter::String *generate_profile_page(RenX::LadderDatabase *db, uint64_t steam_id); RenX_Ladder_WebPlugin(); ~RenX_Ladder_WebPlugin(); diff --git a/RenX.Ladder.Weekly/RenX.Ladder.Weekly.vcxproj b/RenX.Ladder.Weekly/RenX.Ladder.Weekly.vcxproj new file mode 100644 index 0000000..e2492f6 --- /dev/null +++ b/RenX.Ladder.Weekly/RenX.Ladder.Weekly.vcxproj @@ -0,0 +1,85 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {6F0141F3-CF64-47D9-8EC2-80A38FAFDAC7} + RenX.Ladder.Weekly + + + + Application + true + v140 + MultiByte + + + DynamicLibrary + false + v140 + true + Unicode + + + + + + + + + + + + + $(SolutionDir)$(Configuration)\Plugins\ + AllRules.ruleset + + + + Level3 + Disabled + true + + + true + + + + + Level3 + MaxSpeed + true + true + true + ../Bot;../Jupiter;../RenX.Core + _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + + + true + true + true + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/RenX.Ladder.Weekly/RenX.Ladder.Weekly.vcxproj.filters b/RenX.Ladder.Weekly/RenX.Ladder.Weekly.vcxproj.filters new file mode 100644 index 0000000..4e22405 --- /dev/null +++ b/RenX.Ladder.Weekly/RenX.Ladder.Weekly.vcxproj.filters @@ -0,0 +1,38 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + + + Resource Files + + + Resource Files + + + Resource Files + + + + + Header Files + + + \ No newline at end of file diff --git a/RenX.Ladder.Weekly/RenX_Ladder_Weekly.cpp b/RenX.Ladder.Weekly/RenX_Ladder_Weekly.cpp new file mode 100644 index 0000000..fe58a1e --- /dev/null +++ b/RenX.Ladder.Weekly/RenX_Ladder_Weekly.cpp @@ -0,0 +1,55 @@ +/** + * 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 + */ + +#include +#include "Jupiter/INIFile.h" +#include "Jupiter/IRC_Client.h" +#include "RenX_Ladder_Weekly.h" + +using namespace Jupiter::literals; + +RenX_Ladder_Weekly_TimePlugin::RenX_Ladder_Weekly_TimePlugin() +{ + // Load database + this->database.process_file(Jupiter::IRC::Client::Config->get(this->getName(), "LadderDatabase"_jrs, "Ladder.Weekly.db"_jrs)); + this->database.setName(Jupiter::IRC::Client::Config->get(this->getName(), "DatabaseName"_jrs, "Weekly"_jrs)); + + this->last_sorted_day = gmtime(std::addressof(time(0)))->tm_wday; + this->reset_day = Jupiter::IRC::Client::Config->getInt(this->getName(), "ResetDay"_jrs); + this->database.OnPreUpdateLadder = OnPreUpdateLadder; + + // Force database to default, if desired + if (Jupiter::IRC::Client::Config->getBool(this->getName(), "ForceDefault"_jrs, false)) + RenX::default_ladder_database = &this->database; +} + +// Plugin instantiation and entry point. +RenX_Ladder_Weekly_TimePlugin pluginInstance; + +void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team, bool output_times) +{ + tm *tm_ptr = gmtime(std::addressof(time(0))); + if (pluginInstance.last_sorted_day != tm_ptr->tm_wday && tm_ptr->tm_wday == pluginInstance.reset_day) + database.erase(); + pluginInstance.last_sorted_day = tm_ptr->tm_wday; +} + +extern "C" __declspec(dllexport) Jupiter::Plugin *getPlugin() +{ + return &pluginInstance; +} diff --git a/RenX.Ladder.Weekly/RenX_Ladder_Weekly.h b/RenX.Ladder.Weekly/RenX_Ladder_Weekly.h new file mode 100644 index 0000000..b3d5542 --- /dev/null +++ b/RenX.Ladder.Weekly/RenX_Ladder_Weekly.h @@ -0,0 +1,43 @@ +/** + * 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 + */ + +#if !defined _RENX_LADDER_ALL_TIME +#define _RENX_LADDER_ALL_TIME + +#include "Jupiter/Plugin.h" +#include "Jupiter/Reference_String.h" +#include "RenX_Plugin.h" +#include "RenX_LadderDatabase.h" + +class RenX_Ladder_Weekly_TimePlugin : public RenX::Plugin +{ +public: + const Jupiter::ReadableString &getName() override { return name; } + + RenX_Ladder_Weekly_TimePlugin(); + + int last_sorted_day; + int reset_day; +private: + RenX::LadderDatabase database; + STRING_LITERAL_AS_NAMED_REFERENCE(name, "RenX.Ladder.Weekly"); +}; + +void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team, bool output_times); + +#endif // _RENX_LADDER_ALL_TIME \ No newline at end of file diff --git a/RenX.Ladder.Yearly/RenX.Ladder.Yearly.vcxproj b/RenX.Ladder.Yearly/RenX.Ladder.Yearly.vcxproj new file mode 100644 index 0000000..ce5eef8 --- /dev/null +++ b/RenX.Ladder.Yearly/RenX.Ladder.Yearly.vcxproj @@ -0,0 +1,85 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {075AF69B-71D6-43B9-B102-4649CB2CA40C} + RenX.Ladder.Yearly + + + + Application + true + v140 + MultiByte + + + DynamicLibrary + false + v140 + true + Unicode + + + + + + + + + + + + + $(SolutionDir)$(Configuration)\Plugins\ + AllRules.ruleset + + + + Level3 + Disabled + true + + + true + + + + + Level3 + MaxSpeed + true + true + true + ../Bot;../Jupiter;../RenX.Core + _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + + + true + true + true + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/RenX.Ladder.Yearly/RenX.Ladder.Yearly.vcxproj.filters b/RenX.Ladder.Yearly/RenX.Ladder.Yearly.vcxproj.filters new file mode 100644 index 0000000..6a93ff7 --- /dev/null +++ b/RenX.Ladder.Yearly/RenX.Ladder.Yearly.vcxproj.filters @@ -0,0 +1,38 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + + + Resource Files + + + Resource Files + + + Resource Files + + + + + Header Files + + + \ No newline at end of file diff --git a/RenX.Ladder.Yearly/RenX_Ladder_Yearly.cpp b/RenX.Ladder.Yearly/RenX_Ladder_Yearly.cpp new file mode 100644 index 0000000..acee35f --- /dev/null +++ b/RenX.Ladder.Yearly/RenX_Ladder_Yearly.cpp @@ -0,0 +1,54 @@ +/** + * 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 + */ + +#include +#include "Jupiter/INIFile.h" +#include "Jupiter/IRC_Client.h" +#include "RenX_Ladder_Yearly.h" + +using namespace Jupiter::literals; + +RenX_Ladder_Yearly_TimePlugin::RenX_Ladder_Yearly_TimePlugin() +{ + // Load database + this->database.process_file(Jupiter::IRC::Client::Config->get(this->getName(), "LadderDatabase"_jrs, "Ladder.Yearly.db"_jrs)); + this->database.setName(Jupiter::IRC::Client::Config->get(this->getName(), "DatabaseName"_jrs, "Yearly"_jrs)); + + this->last_sorted_year = gmtime(std::addressof(time(0)))->tm_year; + this->database.OnPreUpdateLadder = OnPreUpdateLadder; + + // Force database to default, if desired + if (Jupiter::IRC::Client::Config->getBool(this->getName(), "ForceDefault"_jrs, false)) + RenX::default_ladder_database = &this->database; +} + +// Plugin instantiation and entry point. +RenX_Ladder_Yearly_TimePlugin pluginInstance; + +void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team, bool output_times) +{ + tm *tm_ptr = gmtime(std::addressof(time(0))); + if (pluginInstance.last_sorted_year != tm_ptr->tm_year) + database.erase(); + pluginInstance.last_sorted_year = tm_ptr->tm_year; +} + +extern "C" __declspec(dllexport) Jupiter::Plugin *getPlugin() +{ + return &pluginInstance; +} diff --git a/RenX.Ladder.Yearly/RenX_Ladder_Yearly.h b/RenX.Ladder.Yearly/RenX_Ladder_Yearly.h new file mode 100644 index 0000000..85ae403 --- /dev/null +++ b/RenX.Ladder.Yearly/RenX_Ladder_Yearly.h @@ -0,0 +1,42 @@ +/** + * 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 + */ + +#if !defined _RENX_LADDER_ALL_TIME +#define _RENX_LADDER_ALL_TIME + +#include "Jupiter/Plugin.h" +#include "Jupiter/Reference_String.h" +#include "RenX_Plugin.h" +#include "RenX_LadderDatabase.h" + +class RenX_Ladder_Yearly_TimePlugin : public RenX::Plugin +{ +public: + const Jupiter::ReadableString &getName() override { return name; } + + RenX_Ladder_Yearly_TimePlugin(); + + int last_sorted_year = 0; +private: + RenX::LadderDatabase database; + STRING_LITERAL_AS_NAMED_REFERENCE(name, "RenX.Ladder.Yearly"); +}; + +void OnPreUpdateLadder(RenX::LadderDatabase &database, RenX::Server *server, const RenX::TeamType &team, bool output_times); + +#endif // _RENX_LADDER_ALL_TIME \ No newline at end of file diff --git a/RenX.Ladder/RenX_Ladder.cpp b/RenX.Ladder/RenX_Ladder.cpp index c53ce15..cb722cf 100644 --- a/RenX.Ladder/RenX_Ladder.cpp +++ b/RenX.Ladder/RenX_Ladder.cpp @@ -35,10 +35,6 @@ RenX_LadderPlugin::RenX_LadderPlugin() RenX_LadderPlugin::max_ladder_command_part_name_output = 0; else RenX_LadderPlugin::max_ladder_command_part_name_output = mlcpno; - RenX_LadderPlugin::db_filename = Jupiter::IRC::Client::Config->get(this->getName(), "LadderDatabase"_jrs, "Ladder.db"_jrs); - - // load database - RenX_LadderPlugin::database.process_file(RenX_LadderPlugin::db_filename); } /** Wait until the client list has been updated to update the ladder */ @@ -62,7 +58,8 @@ void RenX_LadderPlugin::RenX_OnCommand(RenX::Server *server, const Jupiter::Read { server->varData.set(this->name, "w"_jrs, "0"_jrs); RenX::TeamType team = static_cast(server->varData.get(this->name, "t"_jrs, "\0"_jrs).get(0)); - RenX_LadderPlugin::database.updateLadder(server, team, RenX_LadderPlugin::output_times); + for (size_t index = 0; index != RenX::ladder_databases.size(); ++index) + RenX::ladder_databases.get(index)->updateLadder(server, team, RenX_LadderPlugin::output_times); } } } @@ -103,14 +100,14 @@ GenericCommand::ResponseLine *LadderGenericCommand::trigger(const Jupiter::Reada if (rank == 0) return new GenericCommand::ResponseLine("Error: Invalid parameters"_jrs, GenericCommand::DisplayType::PrivateError); - entry = pluginInstance.database.getPlayerEntryByIndex(rank - 1); + entry = RenX::default_ladder_database->getPlayerEntryByIndex(rank - 1); if (entry == nullptr) return new GenericCommand::ResponseLine("Error: Player not found"_jrs, GenericCommand::DisplayType::PrivateError); return new GenericCommand::ResponseLine(FormatLadderResponse(entry, rank), GenericCommand::DisplayType::PublicSuccess); } - Jupiter::SLList> list = pluginInstance.database.getPlayerEntriesAndIndexByPartName(parameters, pluginInstance.getMaxLadderCommandPartNameOutput()); + Jupiter::SLList> list = RenX::default_ladder_database->getPlayerEntriesAndIndexByPartName(parameters, pluginInstance.getMaxLadderCommandPartNameOutput()); if (list.size() == 0) return new GenericCommand::ResponseLine("Error: Player not found"_jrs, GenericCommand::DisplayType::PrivateError); @@ -152,7 +149,7 @@ void LadderGameCommand::trigger(RenX::Server *source, RenX::PlayerInfo *player, { if (player->steamid != 0) { - std::pair pair = pluginInstance.database.getPlayerEntryAndIndex(player->steamid); + std::pair pair = RenX::default_ladder_database->getPlayerEntryAndIndex(player->steamid); if (pair.first != nullptr) source->sendMessage(FormatLadderResponse(pair.first, pair.second + 1)); else diff --git a/RenX.Ladder/RenX_Ladder.h b/RenX.Ladder/RenX_Ladder.h index 88b97a7..f7cc16d 100644 --- a/RenX.Ladder/RenX_Ladder.h +++ b/RenX.Ladder/RenX_Ladder.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2015 Jessica James. + * Copyright (C) 2015-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 @@ -42,12 +42,10 @@ public: size_t getMaxLadderCommandPartNameOutput() const; RenX_LadderPlugin(); - RenX::LadderDatabase database; private: /** Configuration variables */ bool only_pure, output_times; size_t max_ladder_command_part_name_output; - Jupiter::CStringS db_filename; STRING_LITERAL_AS_NAMED_REFERENCE(name, "RenX.Ladder"); };