summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiftob/Swiftob.cpp')
-rw-r--r--Swiftob/Swiftob.cpp35
1 files changed, 28 insertions, 7 deletions
diff --git a/Swiftob/Swiftob.cpp b/Swiftob/Swiftob.cpp
index 331e55e..1578e34 100644
--- a/Swiftob/Swiftob.cpp
+++ b/Swiftob/Swiftob.cpp
@@ -33,12 +33,12 @@ po::options_description Swiftob::getOptionsDescription() {
Swiftob::Swiftob(const po::variables_map& options) : options_(options), networkFactories_(&eventLoop_), quitting_(false) {
- std::string path;
- path = options["path"].as<std::string>();
+ path_ = options["path"].as<std::string>();
client_ = new Swift::Client(Swift::JID(options["jid"].as<std::string>()), options["password"].as<std::string>(), &networkFactories_);
- storage_ = new Storage(boost::filesystem::path(path) / "settings.txt");
- mucs_ = new MUCs(client_, storage_);
- users_ = new Users(client_, mucs_);
- commands_ = new Commands(users_, client_, storage_, mucs_);
- lua_ = new LuaCommands(commands_, path, client_, networkFactories_.getTimerFactory(), mucs_);
+ storage_ = new Storage(boost::filesystem::path(path_) / "settings.txt");
+ mucs_ = NULL;
+ users_ = NULL;
+ commands_ = NULL;
+ lua_ = NULL;
+ init();
client_->onConnected.connect(boost::bind(&Swiftob::handleConnected, this));
client_->onDisconnected.connect(boost::bind(&Swiftob::handleDisconnected, this, _1));
@@ -55,4 +55,21 @@ Swiftob::Swiftob(const po::variables_map& options) : options_(options), networkF
}
+void Swiftob::init() {
+ delete mucs_;
+ mucs_ = new MUCs(client_, storage_);
+ delete users_;
+ users_ = new Users(client_, mucs_);
+ delete commands_;
+ commands_ = new Commands(users_, client_, storage_, mucs_);
+ commands_->onRestartRequested.connect(boost::bind(&Swiftob::handleRestartRequested, this));
+ delete lua_;
+ lua_ = new LuaCommands(commands_, path_, client_, networkFactories_.getTimerFactory(), mucs_);
+}
+
+void Swiftob::handleRestartRequested() {
+ client_->disconnect();
+ init();
+}
+
void Swiftob::handleConnected() {
std::cout << "Connected" << std::endl;
@@ -88,4 +105,8 @@ void Swiftob::handleMessageReceived(Swift::Message::ref message) {
return;
}
+
+ /* Run through any full-message listeners */
+ commands_->runListeners(message);
+
/*Convert body into !command if it's not a MUC, and it misses the bang*/
std::string bangBody(body);