|
@ -23,42 +23,70 @@ |
|
|
|
|
|
|
|
|
RenX_AnnouncementsPlugin pluginInstance; |
|
|
RenX_AnnouncementsPlugin pluginInstance; |
|
|
|
|
|
|
|
|
void announce(unsigned int) |
|
|
void announce_(unsigned int x) |
|
|
{ |
|
|
{ |
|
|
if (pluginInstance.random == false) |
|
|
pluginInstance.announce(x); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void RenX_AnnouncementsPlugin::announce(unsigned int) |
|
|
|
|
|
{ |
|
|
|
|
|
if (RenX_AnnouncementsPlugin::random == false) |
|
|
{ |
|
|
{ |
|
|
pluginInstance.lastLine++; |
|
|
RenX_AnnouncementsPlugin::lastLine++; |
|
|
if (pluginInstance.lastLine == pluginInstance.announcementsFile.getLineCount()) pluginInstance.lastLine = 0; |
|
|
if (RenX_AnnouncementsPlugin::lastLine == RenX_AnnouncementsPlugin::announcementsFile.getLineCount()) RenX_AnnouncementsPlugin::lastLine = 0; |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
unsigned int trand; |
|
|
unsigned int trand; |
|
|
do trand = rand() % pluginInstance.announcementsFile.getLineCount(); |
|
|
do trand = rand() % RenX_AnnouncementsPlugin::announcementsFile.getLineCount(); |
|
|
while (trand == pluginInstance.lastLine); |
|
|
while (trand == RenX_AnnouncementsPlugin::lastLine); |
|
|
pluginInstance.lastLine = trand; |
|
|
RenX_AnnouncementsPlugin::lastLine = trand; |
|
|
} |
|
|
} |
|
|
const Jupiter::ReadableString &announcement = pluginInstance.announcementsFile.getLine(pluginInstance.lastLine); |
|
|
Jupiter::StringS announcement = RenX_AnnouncementsPlugin::announcementsFile.getLine(RenX_AnnouncementsPlugin::lastLine); |
|
|
|
|
|
announcement.replace(RenX_AnnouncementsPlugin::dateTag, Jupiter::ReferenceString(getTimeFormat(RenX_AnnouncementsPlugin::dateFmt.c_str()))); |
|
|
|
|
|
announcement.replace(RenX_AnnouncementsPlugin::timeTag, Jupiter::ReferenceString(getTimeFormat(RenX_AnnouncementsPlugin::timeFmt.c_str()))); |
|
|
|
|
|
|
|
|
|
|
|
Jupiter::String msg; |
|
|
RenX::Core *core = RenX::getCore(); |
|
|
RenX::Core *core = RenX::getCore(); |
|
|
RenX::Server *server; |
|
|
RenX::Server *server; |
|
|
for (unsigned int i = 0; i != RenX::getCore()->getServerCount(); i++) |
|
|
for (unsigned int i = 0; i != RenX::getCore()->getServerCount(); i++) |
|
|
{ |
|
|
{ |
|
|
server = core->getServer(i); |
|
|
server = core->getServer(i); |
|
|
if (server->players.size() != 0) |
|
|
if (server->players.size() != 0) |
|
|
server->sendMessage(announcement); |
|
|
{ |
|
|
|
|
|
msg = announcement; |
|
|
|
|
|
msg.replace(RenX_AnnouncementsPlugin::rulesTag, server->getRules()); |
|
|
|
|
|
server->sendMessage(msg); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
RenX_AnnouncementsPlugin::RenX_AnnouncementsPlugin() |
|
|
int RenX_AnnouncementsPlugin::OnRehash() |
|
|
|
|
|
{ |
|
|
|
|
|
RenX_AnnouncementsPlugin::announcementsFile.unload(); |
|
|
|
|
|
return RenX_AnnouncementsPlugin::init(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int RenX_AnnouncementsPlugin::init() |
|
|
{ |
|
|
{ |
|
|
|
|
|
RenX_AnnouncementsPlugin::dateTag = Jupiter::IRC::Client::Config->get(this->getName(), STRING_LITERAL_AS_REFERENCE("DateTag"), STRING_LITERAL_AS_REFERENCE("{DATE}")); |
|
|
|
|
|
RenX_AnnouncementsPlugin::timeTag = Jupiter::IRC::Client::Config->get(this->getName(), STRING_LITERAL_AS_REFERENCE("TimeTag"), STRING_LITERAL_AS_REFERENCE("{TIME}")); |
|
|
|
|
|
RenX_AnnouncementsPlugin::rulesTag = Jupiter::IRC::Client::Config->get(this->getName(), STRING_LITERAL_AS_REFERENCE("RulesTag"), STRING_LITERAL_AS_REFERENCE("{RULES}"));; |
|
|
|
|
|
RenX_AnnouncementsPlugin::dateFmt = Jupiter::IRC::Client::Config->get(this->getName(), STRING_LITERAL_AS_REFERENCE("DateFormat"), STRING_LITERAL_AS_REFERENCE("%A, %B %d, %Y")); |
|
|
|
|
|
RenX_AnnouncementsPlugin::timeFmt = Jupiter::IRC::Client::Config->get(this->getName(), STRING_LITERAL_AS_REFERENCE("TimeFormat"), STRING_LITERAL_AS_REFERENCE("%H:%M:%S")); |
|
|
|
|
|
RenX_AnnouncementsPlugin::random = Jupiter::IRC::Client::Config->getBool(STRING_LITERAL_AS_REFERENCE("RenX.Announcements"), STRING_LITERAL_AS_REFERENCE("Random")); |
|
|
|
|
|
|
|
|
RenX_AnnouncementsPlugin::announcementsFile.load(Jupiter::IRC::Client::Config->get(STRING_LITERAL_AS_REFERENCE("RenX.Announcements"), STRING_LITERAL_AS_REFERENCE("File"), STRING_LITERAL_AS_REFERENCE("Announcements.txt"))); |
|
|
RenX_AnnouncementsPlugin::announcementsFile.load(Jupiter::IRC::Client::Config->get(STRING_LITERAL_AS_REFERENCE("RenX.Announcements"), STRING_LITERAL_AS_REFERENCE("File"), STRING_LITERAL_AS_REFERENCE("Announcements.txt"))); |
|
|
if (RenX_AnnouncementsPlugin::announcementsFile.getLineCount() != 0) |
|
|
if (RenX_AnnouncementsPlugin::announcementsFile.getLineCount() == 0) |
|
|
{ |
|
|
{ |
|
|
RenX_AnnouncementsPlugin::random = Jupiter::IRC::Client::Config->getBool(STRING_LITERAL_AS_REFERENCE("RenX.Announcements"), STRING_LITERAL_AS_REFERENCE("Random")); |
|
|
fputs("[RenX.Announcements] ERROR: No announcements loaded." ENDL, stderr); |
|
|
time_t delay = Jupiter::IRC::Client::Config->getInt(STRING_LITERAL_AS_REFERENCE("RenX.Announcements"), STRING_LITERAL_AS_REFERENCE("Delay"), 60); |
|
|
return -1; |
|
|
RenX_AnnouncementsPlugin::timer = new Jupiter::Timer(0, delay, announce); |
|
|
|
|
|
if (RenX_AnnouncementsPlugin::random == false) RenX_AnnouncementsPlugin::lastLine = RenX_AnnouncementsPlugin::announcementsFile.getLineCount() - 1; |
|
|
|
|
|
} |
|
|
} |
|
|
else fputs("[RenX.Announcements] ERROR: No announcements loaded." ENDL, stderr); |
|
|
time_t delay = Jupiter::IRC::Client::Config->getInt(STRING_LITERAL_AS_REFERENCE("RenX.Announcements"), STRING_LITERAL_AS_REFERENCE("Delay"), 60); |
|
|
|
|
|
RenX_AnnouncementsPlugin::timer = new Jupiter::Timer(0, delay, announce_); |
|
|
|
|
|
if (RenX_AnnouncementsPlugin::random == false) |
|
|
|
|
|
RenX_AnnouncementsPlugin::lastLine = RenX_AnnouncementsPlugin::announcementsFile.getLineCount() - 1; |
|
|
|
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
RenX_AnnouncementsPlugin::~RenX_AnnouncementsPlugin() |
|
|
RenX_AnnouncementsPlugin::~RenX_AnnouncementsPlugin() |
|
@ -67,6 +95,11 @@ RenX_AnnouncementsPlugin::~RenX_AnnouncementsPlugin() |
|
|
RenX_AnnouncementsPlugin::announcementsFile.unload(); |
|
|
RenX_AnnouncementsPlugin::announcementsFile.unload(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
extern "C" __declspec(dllexport) bool load() |
|
|
|
|
|
{ |
|
|
|
|
|
return pluginInstance.init() == 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
extern "C" __declspec(dllexport) Jupiter::Plugin *getPlugin() |
|
|
extern "C" __declspec(dllexport) Jupiter::Plugin *getPlugin() |
|
|
{ |
|
|
{ |
|
|
return &pluginInstance; |
|
|
return &pluginInstance; |
|
|