You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

97 lines
2.9 KiB

/**
* Copyright (C) 2015 Justin 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 Justin James <justin.aj@hotmail.com>
*/
#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;
}