From 5d46100d6d7c176874aef918040f5724d875081b Mon Sep 17 00:00:00 2001 From: JustinAJ Date: Thu, 14 Jan 2016 19:16:10 -0500 Subject: [PATCH] Added "gameinfo" IRC command --- RenX.Commands/RenX_Commands.cpp | 44 +++++++++++++++++++++++++++++++++ RenX.Commands/RenX_Commands.h | 1 + 2 files changed, 45 insertions(+) diff --git a/RenX.Commands/RenX_Commands.cpp b/RenX.Commands/RenX_Commands.cpp index 44fdd35..8010afe 100644 --- a/RenX.Commands/RenX_Commands.cpp +++ b/RenX.Commands/RenX_Commands.cpp @@ -855,6 +855,50 @@ const Jupiter::ReadableString &MapIRCCommand::getHelp(const Jupiter::ReadableStr IRC_COMMAND_INIT(MapIRCCommand) +// GameInfo IRC Command + +void GameInfoIRCCommand::create() +{ + this->addTrigger("gameinfo"_jrs); + this->addTrigger("gi"_jrs); + this->addTrigger("serverinfo"_jrs); + this->addTrigger("si"_jrs); +} + +void GameInfoIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString ¶meters) +{ + Jupiter::IRC::Client::Channel *chan = source->getChannel(channel); + if (chan != nullptr) + { + int type = chan->getType(); + bool match = false; + for (unsigned int i = 0; i != RenX::getCore()->getServerCount(); i++) + { + RenX::Server *server = RenX::getCore()->getServer(i); + if (server->isLogChanType(type)) + { + match = true; + const RenX::Map &map = server->getMap(); + std::chrono::seconds time = std::chrono::duration_cast(server->getGameTime()); + source->sendMessage(channel, IRCCOLOR "03[GameInfo] "_jrs IRCCOLOR + server->getGameVersion()); + source->sendMessage(channel, IRCCOLOR "03[GameInfo] " IRCCOLOR "10Map" IRCCOLOR ": "_jrs + map.name + "; " IRCCOLOR "10GUID" IRCCOLOR ": "_jrs + RenX::formatGUID(map)); + source->sendMessage(channel, Jupiter::StringS::Format(IRCCOLOR "03[GameInfo] " IRCCOLOR "10Elapsed time" IRCCOLOR ": %.2lld:%.2lld:%.2lld", time.count() / 3600, (time.count() % 3600) / 60, time.count() % 60)); + source->sendMessage(channel, Jupiter::StringS::Format(IRCCOLOR "03[GameInfo] " IRCCOLOR "There are " IRCCOLOR "10%d" IRCCOLOR " players online.", server->players.size())); + } + } + if (match == false) + source->sendMessage(channel, "Error: Channel not attached to any connected Renegade X servers."_jrs); + } +} + +const Jupiter::ReadableString &GameInfoIRCCommand::getHelp(const Jupiter::ReadableString &) +{ + static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Returns information about the game in progress. Syntax: GameInfo"); + return defaultHelp; +} + +IRC_COMMAND_INIT(GameInfoIRCCommand) + // Steam IRC Command void SteamIRCCommand::create() diff --git a/RenX.Commands/RenX_Commands.h b/RenX.Commands/RenX_Commands.h index b8fb10d..2d08158 100644 --- a/RenX.Commands/RenX_Commands.h +++ b/RenX.Commands/RenX_Commands.h @@ -64,6 +64,7 @@ GENERIC_IRC_COMMAND(BuildingInfoIRCCommand) GENERIC_IRC_COMMAND(MutatorsIRCCommand) GENERIC_IRC_COMMAND(RotationIRCCommand) GENERIC_IRC_COMMAND(MapIRCCommand) +GENERIC_IRC_COMMAND(GameInfoIRCCommand) GENERIC_IRC_COMMAND(SteamIRCCommand) GENERIC_IRC_COMMAND(KillDeathRatioIRCCommand) GENERIC_IRC_COMMAND(ShowModsIRCCommand)