Browse Source

Updated Jupiter; adjusted config and Bot as necessary

pull/3/head
Jessica James 8 years ago
parent
commit
e0cc12e207
  1. 16
      Bot/IRC_Bot.cpp
  2. 4
      Bot/IRC_Bot.h
  3. 12
      Bot/Jupiter_Bot.h
  4. 48
      Bot/Main.cpp
  5. 8
      Bot/ServerManager.cpp
  6. 12
      Config.ini
  7. 2
      Jupiter
  8. BIN
      Release/Bot.lib
  9. BIN
      Release/Plugins/RenX.Core.lib
  10. 1
      RenX.Commands/RenX_Commands.cpp

16
Bot/IRC_Bot.cpp

@ -27,7 +27,7 @@
using namespace Jupiter::literals;
IRC_Bot::IRC_Bot(const Jupiter::ReadableString &configSection) : Client(configSection)
IRC_Bot::IRC_Bot(const Jupiter::INIFile::Section *in_primary_section, const Jupiter::INIFile::Section *in_secondary_section) : Client(in_primary_section, in_secondary_section)
{
IRC_Bot::commandPrefix = this->readConfigValue("Prefix"_jrs);
for (size_t i = 0; i != IRCMasterCommandList->size(); i++)
@ -105,7 +105,7 @@ void IRC_Bot::setCommandAccessLevels()
{
auto set_command_access_levels = [this](const Jupiter::ReadableString &section_name)
{
Jupiter::INIFile::Section *section = this->Config->getSection(section_name);
Jupiter::INIFile::Section *section = g_config->getSection(section_name);
if (section != nullptr)
{
@ -162,13 +162,19 @@ void IRC_Bot::setCommandAccessLevels()
}
};
set_command_access_levels("DefaultCommands"_jrs);
set_command_access_levels(this->getConfigSection() + "Commands"_jrs);
const Jupiter::INIFile::Section *section;
section = this->getSecondaryConfigSection();
if (section != nullptr)
set_command_access_levels(section->getName() + "Commands"_jrs);
section = this->getPrimaryConfigSection();
if (section != nullptr)
set_command_access_levels(section->getName() + "Commands"_jrs);
}
int IRC_Bot::OnRehash()
{
if (Config->reload() == Jupiter::ERROR_INDICATOR) return 1;
IRC_Bot::setCommandAccessLevels();
return 0;
}

4
Bot/IRC_Bot.h

@ -1,5 +1,5 @@
/**
* Copyright (C) 2013-2015 Jessica James.
* Copyright (C) 2013-2016 Jessica 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
@ -110,7 +110,7 @@ public:
bool OnBadRehash(bool removed) { return removed; };
/** Constructor for IRC_Bot */
IRC_Bot(const Jupiter::ReadableString &configSection);
IRC_Bot(const Jupiter::INIFile::Section *in_primary_section, const Jupiter::INIFile::Section *in_secondary_section);
/** Destructor for IRC_Bot */
~IRC_Bot();

12
Bot/Jupiter_Bot.h

@ -1,5 +1,5 @@
/**
* Copyright (C) 2013-2015 Jessica James.
* Copyright (C) 2013-2016 Jessica 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
@ -36,4 +36,14 @@
#define JUPITER_BOT_API
#endif // _WIN32
#if defined __cplusplus
/** Forward declaration */
namespace Jupiter { class INIFile; }
/** Application config file */
extern Jupiter::INIFile *g_config;
#endif // __cplusplus
#endif // JUPITER_BOT_API

48
Bot/Main.cpp

@ -35,6 +35,9 @@
using namespace Jupiter::literals;
Jupiter::INIFile o_config;
Jupiter::INIFile *g_config = &o_config;
#define INPUT_BUFFER_SIZE 2048
struct ConsoleInput
@ -89,11 +92,11 @@ int main(int argc, const char **args)
atexit(onExit);
std::set_terminate(onTerminate);
std::thread inputThread(inputLoop);
Jupiter::ReferenceString command;
Jupiter::ReferenceString command, plugins_directory, configs_directory;
srand(static_cast<unsigned int>(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count()));
puts(Jupiter::copyright);
const char *configFileName = CONFIG_INI;
const char *configFileName = "Config.ini";
for (int i = 1; i < argc; i++)
{
@ -105,9 +108,9 @@ int main(int argc, const char **args)
else if ("-config"_jrs.equalsi(args[i]) && ++i < argc)
configFileName = args[i];
else if ("-pluginsdir"_jrs.equalsi(args[i]) && ++i < argc)
Jupiter::Plugin::setDirectory(Jupiter::ReferenceString(args[i]));
plugins_directory = args[i];
else if ("-configsdir"_jrs.equals(args[i]) && ++i < argc)
Jupiter::Plugin::setConfigDirectory(Jupiter::ReferenceString(args[i]));
configs_directory = args[i];
else if ("-configFormat"_jrs.equalsi(args[i]) && ++i < argc)
puts("Feature not yet supported!");
else
@ -115,30 +118,34 @@ int main(int argc, const char **args)
}
puts("Loading config file...");
if (!Jupiter::IRC::Client::Config->readFile(configFileName))
if (!o_config.readFile(configFileName))
{
puts("Unable to read config file. Closing...");
exit(0);
}
fputs("Config loaded. ", stdout);
puts("Config loaded.");
if (plugins_directory.isEmpty())
plugins_directory = o_config.get(Jupiter::ReferenceString::empty, "PluginsDirectory"_jrs);
if (configs_directory.isEmpty())
configs_directory = o_config.get(Jupiter::ReferenceString::empty, "ConfigsDirectory"_jrs);
const Jupiter::ReadableString &pDir = Jupiter::IRC::Client::Config->get(STRING_LITERAL_AS_REFERENCE("Config"), STRING_LITERAL_AS_REFERENCE("PluginsDirectory"));
if (pDir.isNotEmpty())
if (plugins_directory.isNotEmpty())
{
Jupiter::Plugin::setDirectory(pDir);
printf("Plugins will be loaded from \"%.*s\"." ENDL, pDir.size(), pDir.ptr());
Jupiter::Plugin::setDirectory(plugins_directory);
printf("Plugins will be loaded from \"%.*s\"." ENDL, plugins_directory.size(), plugins_directory.ptr());
}
const Jupiter::ReadableString &cDir = Jupiter::IRC::Client::Config->get(STRING_LITERAL_AS_REFERENCE("Config"), STRING_LITERAL_AS_REFERENCE("PluginConfigsDirectory"));
if (cDir.isNotEmpty())
if (configs_directory.isNotEmpty())
{
Jupiter::Plugin::setDirectory(cDir);
printf("Plugin configs will be loaded from \"%.*s\"." ENDL, cDir.size(), cDir.ptr());
Jupiter::Plugin::setDirectory(configs_directory);
printf("Plugin configs will be loaded from \"%.*s\"." ENDL, configs_directory.size(), configs_directory.ptr());
}
puts("Loading plugins...");
const Jupiter::ReadableString &pluginList = Jupiter::IRC::Client::Config->get(STRING_LITERAL_AS_REFERENCE("Config"), STRING_LITERAL_AS_REFERENCE("Plugins"));
const Jupiter::ReadableString &pluginList = o_config.get(Jupiter::ReferenceString::empty, "Plugins"_jrs);
if (pluginList.isEmpty())
puts("No plugins to load!");
else
@ -148,26 +155,27 @@ int main(int argc, const char **args)
for (unsigned int i = 0; i < nPlugins; i++)
{
Jupiter::ReferenceString plugin = Jupiter::ReferenceString::getWord(pluginList, i, WHITESPACE);
if (Jupiter::Plugin::load(plugin) == nullptr) fprintf(stderr, "WARNING: Failed to load plugin \"%.*s\"!" ENDL, plugin.size(), plugin.ptr());
if (Jupiter::Plugin::load(plugin) == nullptr)
fprintf(stderr, "WARNING: Failed to load plugin \"%.*s\"!" ENDL, plugin.size(), plugin.ptr());
else printf("\"%.*s\" loaded successfully." ENDL, plugin.size(), plugin.ptr());
}
}
if (consoleCommands->size() > 0)
printf("%u Console Commands have been initialized%s" ENDL, consoleCommands->size(), getConsoleCommand(STRING_LITERAL_AS_REFERENCE("help")) == nullptr ? "." : "; type \"help\" for more information.");
printf("%u Console Commands have been initialized%s" ENDL, consoleCommands->size(), getConsoleCommand("help"_jrs) == nullptr ? "." : "; type \"help\" for more information.");
if (IRCMasterCommandList->size() > 0)
printf("%u IRC Commands have been loaded into the master list." ENDL, IRCMasterCommandList->size());
puts("Retreiving network list...");
const Jupiter::ReadableString &serverList = Jupiter::IRC::Client::Config->get(STRING_LITERAL_AS_REFERENCE("Config"), STRING_LITERAL_AS_REFERENCE("Servers"));
const Jupiter::ReadableString &serverList = o_config.get(Jupiter::ReferenceString::empty, "Servers"_jrs);
if (serverList == nullptr)
puts("Unable to find network list.");
else
{
unsigned int nServers = serverList.wordCount(WHITESPACE);
printf("Attempting to connect to %u servers..." ENDL, nServers);
for (unsigned int i = 0; i < nServers; i++)
serverManager->addServer(Jupiter::ReferenceString::getWord(serverList, i, WHITESPACE));
for (unsigned int index = 0; index < nServers; ++index)
serverManager->addServer(Jupiter::ReferenceString::getWord(serverList, index, WHITESPACE));
}
puts("Sockets established.");

8
Bot/ServerManager.cpp

@ -1,5 +1,5 @@
/**
* Copyright (C) 2014-2015 Jessica James.
* Copyright (C) 2014-2016 Jessica 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
@ -21,6 +21,8 @@
#include "IRC_Bot.h"
#include "IRC_Command.h"
using namespace Jupiter::literals;
ServerManager _serverManager;
ServerManager *serverManager = &_serverManager;
@ -94,8 +96,8 @@ IRC_Bot *ServerManager::getServer(size_t serverIndex)
bool ServerManager::addServer(const Jupiter::ReadableString &serverConfig)
{
IRC_Bot *server = new IRC_Bot(serverConfig);
if (server->connect() == true)
IRC_Bot *server = new IRC_Bot(g_config->getSection(serverConfig), g_config->getSection("Default"_jrs));
if (server->connect())
{
ServerManager::servers.add(server);
return true;

12
Config.ini

@ -6,7 +6,7 @@
; A Bool is either true or false.
; A Float is a decimal number.
;
; [Config]
; This block is used to define settings that are global in nature.
; Currently, there is a "Servers" option to specify what sections
; to look at for server configuration options, and a "Plugins"
@ -14,17 +14,15 @@
; folder.
; DO NOT INCLUDE A PLUGIN'S FILE EXTENSION (.dll or .so).
;
; Required Settings:
; Servers=String (Format: Server1 Server2)
;
; Optional Settings:
; Settings:
; Plugins=String (Format: Plugin1 Plugin2)
; Servers=String (Format: Server1 Server2)
; PluginsDirectory=String (Default: Plugins\)
; ConfigsDirectory=String (Default: Configs\)
;
[Config]
Plugins=CoreCommands PluginManager ExtraCommands RenX.Core RenX.Commands RenX.Logging RenX.Medals
Servers=CnCIRC
Plugins=CoreCommands PluginManager ExtraCommands RenX.Core RenX.Commands RenX.Logging RenX.Medals RenX.SetJoin
; [Default]
;

2
Jupiter

@ -1 +1 @@
Subproject commit 427ddecf8d89d64fbe90cbcd8eba3aaa7931939a
Subproject commit f52413a0f821f4bec3e1903ba1629023e3231a09

BIN
Release/Bot.lib

Binary file not shown.

BIN
Release/Plugins/RenX.Core.lib

Binary file not shown.

1
RenX.Commands/RenX_Commands.cpp

@ -16,7 +16,6 @@
* Written by Jessica James <jessica.aj@outlook.com>
*/
#include <functional>
#include "Jupiter/Functions.h"
#include "Jupiter/SLList.h"
#include "IRC_Bot.h"

Loading…
Cancel
Save