From 20989f263dfe98d5a673d4682a7a730456806091 Mon Sep 17 00:00:00 2001 From: JustinAJ Date: Sun, 28 Jun 2015 19:08:59 -0400 Subject: [PATCH] Added ChannelRelay Plugin. --- ChannelRelay/ChannelRelay.cpp | 96 +++++++++++++++++++++++ ChannelRelay/ChannelRelay.h | 37 +++++++++ ChannelRelay/ChannelRelay.vcxproj | 84 ++++++++++++++++++++ ChannelRelay/ChannelRelay.vcxproj.filters | 35 +++++++++ Jupiter Bot.sln | 6 ++ 5 files changed, 258 insertions(+) create mode 100644 ChannelRelay/ChannelRelay.cpp create mode 100644 ChannelRelay/ChannelRelay.h create mode 100644 ChannelRelay/ChannelRelay.vcxproj create mode 100644 ChannelRelay/ChannelRelay.vcxproj.filters diff --git a/ChannelRelay/ChannelRelay.cpp b/ChannelRelay/ChannelRelay.cpp new file mode 100644 index 0000000..6154fe0 --- /dev/null +++ b/ChannelRelay/ChannelRelay.cpp @@ -0,0 +1,96 @@ +/** + * Copyright (C) 2015 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 "Jupiter/IRC_Client.h" +#include "Jupiter/INIFile.h" +#include "Jupiter/String.h" +#include "ServerManager.h" +#include "IRC_Bot.h" +#include "ChannelRelay.h" + +using namespace Jupiter::literals; + +int ChannelRelayPlugin::init() +{ + Jupiter::ReferenceString str = Jupiter::IRC::Client::Config->get(this->getName(), "Types"_jrs); + unsigned int words = str.wordCount(WHITESPACE); + if (words == 0) + return 1; + + while (words != 0) + ChannelRelayPlugin::types.concat(str.getWord(--words, WHITESPACE).asInt()); + + return 0; +} + +int ChannelRelayPlugin::OnRehash() +{ + ChannelRelayPlugin::types.erase(); + return ChannelRelayPlugin::init(); +} + +void ChannelRelayPlugin::OnChat(Jupiter::IRC::Client *server, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &message) +{ + Jupiter::IRC::Client::Channel *chan = server->getChannel(channel); + if (chan != nullptr) + { + int type = chan->getType(); + if (ChannelRelayPlugin::types.contains(type)) + { + Jupiter::IRC::Client::Channel *tchan; + Jupiter::IRC::Client *tserver; + unsigned int count = server->getChannelCount(); + unsigned int serverCount = serverManager->size(); + char prefix = chan->getUserPrefix(nick); + auto str = prefix == 0 ? "<"_jrs + nick + "> "_jrs + message : "<"_js + prefix + nick + "> "_jrs + message; + while (count != 0) + { + tchan = server->getChannel(--count); + if (tchan->getType() == type && chan != tchan) + server->sendMessage(tchan->getName(), str); + } + + while (serverCount != 0) + { + tserver = serverManager->getServer(--serverCount); + if (tserver != server) + { + count = tserver->getChannelCount(); + while (count != 0) + { + tchan = tserver->getChannel(--count); + if (tchan->getType() == type) + tserver->sendMessage(tchan->getName(), str); + } + } + } + } + } +} + +// Plugin instantiation and entry point. +ChannelRelayPlugin pluginInstance; + +extern "C" __declspec(dllexport) bool load() +{ + return pluginInstance.init() == 0; +} + +extern "C" __declspec(dllexport) Jupiter::Plugin *getPlugin() +{ + return &pluginInstance; +} diff --git a/ChannelRelay/ChannelRelay.h b/ChannelRelay/ChannelRelay.h new file mode 100644 index 0000000..153845a --- /dev/null +++ b/ChannelRelay/ChannelRelay.h @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2015 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 _CHANNELRELAY_H_HEADER +#define _CHANNELRELAY_H_HEADER + +#include "Jupiter/Plugin.h" +#include "Jupiter/Reference_String.h" + +class ChannelRelayPlugin : public Jupiter::Plugin +{ +public: // Jupiter::Plugin + void OnChat(Jupiter::IRC::Client *server, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &message) override; + const Jupiter::ReadableString &getName() override { return name; } + int OnRehash() override; + + int init(); +private: + Jupiter::String_Strict types; + STRING_LITERAL_AS_NAMED_REFERENCE(name, "ChannelRelay"); +}; + +#endif // _CHANNELRELAY_H_HEADER \ No newline at end of file diff --git a/ChannelRelay/ChannelRelay.vcxproj b/ChannelRelay/ChannelRelay.vcxproj new file mode 100644 index 0000000..50e352a --- /dev/null +++ b/ChannelRelay/ChannelRelay.vcxproj @@ -0,0 +1,84 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {ADAD973E-EAA8-446D-BCD3-83B53DBC3A3F} + ChannelRelay + + + + 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 + _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + + + true + true + true + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ChannelRelay/ChannelRelay.vcxproj.filters b/ChannelRelay/ChannelRelay.vcxproj.filters new file mode 100644 index 0000000..db13a8b --- /dev/null +++ b/ChannelRelay/ChannelRelay.vcxproj.filters @@ -0,0 +1,35 @@ + + + + + {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 + + + + + Header Files + + + + + Source Files + + + + + Resource Files + + + Resource Files + + + \ No newline at end of file diff --git a/Jupiter Bot.sln b/Jupiter Bot.sln index bd777fa..88da219 100644 --- a/Jupiter Bot.sln +++ b/Jupiter Bot.sln @@ -157,6 +157,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RenX.Listen", "RenX.Listen\ {9103DF3D-8B4A-48E5-A6B3-CBE2554630E2} = {9103DF3D-8B4A-48E5-A6B3-CBE2554630E2} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ChannelRelay", "ChannelRelay\ChannelRelay.vcxproj", "{ADAD973E-EAA8-446D-BCD3-83B53DBC3A3F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -271,6 +273,10 @@ Global {DA05D8B5-5E24-410E-A201-CC5905E327D3}.Debug|Win32.Build.0 = Debug|Win32 {DA05D8B5-5E24-410E-A201-CC5905E327D3}.Release|Win32.ActiveCfg = Release|Win32 {DA05D8B5-5E24-410E-A201-CC5905E327D3}.Release|Win32.Build.0 = Release|Win32 + {ADAD973E-EAA8-446D-BCD3-83B53DBC3A3F}.Debug|Win32.ActiveCfg = Debug|Win32 + {ADAD973E-EAA8-446D-BCD3-83B53DBC3A3F}.Debug|Win32.Build.0 = Debug|Win32 + {ADAD973E-EAA8-446D-BCD3-83B53DBC3A3F}.Release|Win32.ActiveCfg = Release|Win32 + {ADAD973E-EAA8-446D-BCD3-83B53DBC3A3F}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE