diff --git a/Jupiter Bot.sln b/Jupiter Bot.sln index f5f799b..f1ee49e 100644 --- a/Jupiter Bot.sln +++ b/Jupiter Bot.sln @@ -82,6 +82,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RenX.Announcements", "RenX. EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{844CF9EF-70F3-449D-ACF3-A70D3501A775}" + ProjectSection(SolutionItems) = preProject + RenX.Greetings\RenX.Greetings.vcxproj = RenX.Greetings\RenX.Greetings.vcxproj + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RenX.Medals", "RenX.Medals\RenX.Medals.vcxproj", "{C295FFC2-8CE5-4387-B237-E4E1B1AB9987}" ProjectSection(ProjectDependencies) = postProject @@ -106,6 +109,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RenX.DNS", "RenX.DNS\RenX.D {9103DF3D-8B4A-48E5-A6B3-CBE2554630E2} = {9103DF3D-8B4A-48E5-A6B3-CBE2554630E2} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RenX.Greetings", "RenX.Greetings\RenX.Greetings.vcxproj", "{8709993F-B08A-4156-BD93-581F297FE0A4}" + 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 GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -188,6 +197,10 @@ Global {812E9781-A9CB-43C6-8C40-87908D50B363}.Debug|Win32.Build.0 = Debug|Win32 {812E9781-A9CB-43C6-8C40-87908D50B363}.Release|Win32.ActiveCfg = Release|Win32 {812E9781-A9CB-43C6-8C40-87908D50B363}.Release|Win32.Build.0 = Release|Win32 + {8709993F-B08A-4156-BD93-581F297FE0A4}.Debug|Win32.ActiveCfg = Debug|Win32 + {8709993F-B08A-4156-BD93-581F297FE0A4}.Debug|Win32.Build.0 = Debug|Win32 + {8709993F-B08A-4156-BD93-581F297FE0A4}.Release|Win32.ActiveCfg = Release|Win32 + {8709993F-B08A-4156-BD93-581F297FE0A4}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Release/Bot.lib b/Release/Bot.lib index afa2c76..ad75b33 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 379dfe9..1eba55b 100644 Binary files a/Release/Plugins/RenX.Core.lib and b/Release/Plugins/RenX.Core.lib differ diff --git a/RenX.Greetings/RenX.Greetings.vcxproj b/RenX.Greetings/RenX.Greetings.vcxproj new file mode 100644 index 0000000..2ad44a3 --- /dev/null +++ b/RenX.Greetings/RenX.Greetings.vcxproj @@ -0,0 +1,86 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {8709993F-B08A-4156-BD93-581F297FE0A4} + PluginExample + RenX.Greetings + + + + Application + true + v120 + MultiByte + + + DynamicLibrary + false + v120 + 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.Greetings/RenX.Greetings.vcxproj.filters b/RenX.Greetings/RenX.Greetings.vcxproj.filters new file mode 100644 index 0000000..2a35b21 --- /dev/null +++ b/RenX.Greetings/RenX.Greetings.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 + + + + + Source Files + + + + + Header Files + + + \ No newline at end of file diff --git a/RenX.Greetings/RenX_Greetings.cpp b/RenX.Greetings/RenX_Greetings.cpp new file mode 100644 index 0000000..baf9697 --- /dev/null +++ b/RenX.Greetings/RenX_Greetings.cpp @@ -0,0 +1,95 @@ +/** + * Copyright (C) 2014 Justin James. + * + * This license must be preserved. + * Any applications, libraries, or code which make any use of any + * component of this program must not be commercial, unless explicit + * permission is granted from the original author. The use of this + * program for non-profit purposes is permitted. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * In the event that this license restricts you from making desired use of this program, contact the original author. + * Written by Justin James + */ + +#include "RenX_Greetings.h" +#include "RenX_PlayerInfo.h" +#include "RenX_Server.h" +#include "Jupiter/IRC_Client.h" +#include "Jupiter/INIFile.h" + +void RenX_GreetingsPlugin::RenX_OnJoin(RenX::Server *server, const RenX::PlayerInfo *player) +{ + auto sendMessage = [&](const Jupiter::ReadableString &m) + { + Jupiter::String msg = m; + msg.replace(this->steamTag, server->formatSteamID(player)); + msg.replace(this->ipTag, player->ip); + msg.replace(this->uuidTag, player->uuid); + msg.replace(this->nameTag, player->name); + + if (this->sendPrivate) + server->sendMessage(player, msg); + else + server->sendMessage(msg); + }; + if (player->isBot == false) + { + switch (RenX_GreetingsPlugin::sendMode) + { + case 0: + RenX_GreetingsPlugin::lastLine = rand() % RenX_GreetingsPlugin::greetingsFile.getLineCount(); + sendMessage(RenX_GreetingsPlugin::greetingsFile.getLine(RenX_GreetingsPlugin::lastLine)); + break; + case 1: + if (++RenX_GreetingsPlugin::lastLine == RenX_GreetingsPlugin::greetingsFile.getLineCount()) + RenX_GreetingsPlugin::lastLine = 0; + sendMessage(RenX_GreetingsPlugin::greetingsFile.getLine(RenX_GreetingsPlugin::lastLine)); + break; + case 2: + for (RenX_GreetingsPlugin::lastLine = 0; RenX_GreetingsPlugin::lastLine != RenX_GreetingsPlugin::greetingsFile.getLineCount(); RenX_GreetingsPlugin::lastLine++) + sendMessage(RenX_GreetingsPlugin::greetingsFile.getLine(RenX_GreetingsPlugin::lastLine)); + break; + default: + return; + } + } +} + +int RenX_GreetingsPlugin::OnRehash() +{ + RenX_GreetingsPlugin::greetingsFile.unload(); + RenX_GreetingsPlugin::init(); + return 0; +} + +RenX_GreetingsPlugin::RenX_GreetingsPlugin() +{ + RenX_GreetingsPlugin::init(); +} + +void RenX_GreetingsPlugin::init() +{ + RenX_GreetingsPlugin::sendPrivate = Jupiter::IRC::Client::Config->getBool(RenX_GreetingsPlugin::name, STRING_LITERAL_AS_REFERENCE("SendPrivate"), true); + RenX_GreetingsPlugin::sendMode = Jupiter::IRC::Client::Config->getInt(RenX_GreetingsPlugin::name, STRING_LITERAL_AS_REFERENCE("SendMode"), 0); + RenX_GreetingsPlugin::greetingsFile.load(Jupiter::IRC::Client::Config->get(RenX_GreetingsPlugin::name, STRING_LITERAL_AS_REFERENCE("GreetingsFile"), STRING_LITERAL_AS_REFERENCE("RenX.Greetings.txt"))); + if (RenX_GreetingsPlugin::greetingsFile.getLineCount() == 0) + RenX_GreetingsPlugin::greetingsFile.addData(STRING_LITERAL_AS_REFERENCE("Please notify the server administrator to properly configure or disable server greetings.\r\n")); + RenX_GreetingsPlugin::lastLine = RenX_GreetingsPlugin::greetingsFile.getLineCount() - 1; + + RenX_GreetingsPlugin::nameTag = Jupiter::IRC::Client::Config->get(RenX_GreetingsPlugin::name, STRING_LITERAL_AS_REFERENCE("NameTag"), STRING_LITERAL_AS_REFERENCE("{NAME}")); + RenX_GreetingsPlugin::ipTag = Jupiter::IRC::Client::Config->get(RenX_GreetingsPlugin::name, STRING_LITERAL_AS_REFERENCE("IPTag"), STRING_LITERAL_AS_REFERENCE("{IP}")); + RenX_GreetingsPlugin::steamTag = Jupiter::IRC::Client::Config->get(RenX_GreetingsPlugin::name, STRING_LITERAL_AS_REFERENCE("SteamTag"), STRING_LITERAL_AS_REFERENCE("{STEAM}")); + RenX_GreetingsPlugin::uuidTag = Jupiter::IRC::Client::Config->get(RenX_GreetingsPlugin::name, STRING_LITERAL_AS_REFERENCE("UUIDTag"), STRING_LITERAL_AS_REFERENCE("{UUID}")); +} + +// Plugin instantiation and entry point. +RenX_GreetingsPlugin pluginInstance; + +extern "C" __declspec(dllexport) Jupiter::Plugin *getPlugin() +{ + return &pluginInstance; +} diff --git a/RenX.Greetings/RenX_Greetings.h b/RenX.Greetings/RenX_Greetings.h new file mode 100644 index 0000000..3012b96 --- /dev/null +++ b/RenX.Greetings/RenX_Greetings.h @@ -0,0 +1,50 @@ +/** + * Copyright (C) 2014 Justin James. + * + * This license must be preserved. + * Any applications, libraries, or code which make any use of any + * component of this program must not be commercial, unless explicit + * permission is granted from the original author. The use of this + * program for non-profit purposes is permitted. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * In the event that this license restricts you from making desired use of this program, contact the original author. + * Written by Justin James + */ + +#if !defined _RENX_GREETING_H_HEADER +#define _RENX_GREETING_H_HEADER + +#include "Jupiter/Plugin.h" +#include "Jupiter/Reference_String.h" +#include "Jupiter/File.h" +#include "Jupiter/String.h" +#include "RenX_Plugin.h" + +class RenX_GreetingsPlugin : public RenX::Plugin +{ +public: // RenX::Plugin + void RenX_OnJoin(RenX::Server *server, const RenX::PlayerInfo *player) override; + +public: // Jupiter::Plugin + int OnRehash() override; + const Jupiter::ReadableString &getName() override { return name; } + + RenX_GreetingsPlugin(); +private: + void init(); + bool sendPrivate; + unsigned int lastLine; + unsigned int sendMode = 0; /** 0 = Send greetings randomly, 1 = Send greetings sequentially, 2 = Send all greetings */ + Jupiter::File greetingsFile; + Jupiter::StringS nameTag; + Jupiter::StringS ipTag; + Jupiter::StringS steamTag; + Jupiter::StringS uuidTag; + STRING_LITERAL_AS_NAMED_REFERENCE(name, "RenX.Greetings"); +}; + +#endif // _RENX_GREETING_H_HEADER \ No newline at end of file