public function run() { $channels = Config::getValue("channels"); if (!in_array($this->parameters(1), $channels)) { $channels[] = $this->parameters(1); } Config::setValue("channels", $channels); $server = Server::getInstance(); $server->join($this->parameters(1)); }
public function run() { $server = Server::getInstance(); $userPasswords = Config::getValue("userPasswords"); if (!$userPasswords) { $userPasswords = array(); } $userPasswords[$this->senderNick] = md5($this->parameters(1)); Config::setValue("userPasswords", $userPasswords); $server->notify($this->senderNick, "Password for " . $this->senderNick . " set to " . $this->parameters(1)); }
public function run() { if ($this->parameters(1)) { $channel = $this->parameters(1); } else { $channel = $this->channel; } $channels = Config::getValue("channels"); foreach ($channels as $offset => $value) { if ($value == $channel) { unset($channels[$offset]); } } Config::setValue("channels", $channels); $server = Server::getInstance(); $server->part($channel); }
public function run() { $action = $this->parameters(1); $server = Server::getInstance(); switch ($action) { case "set": Config::setValue($this->parameters(2), $this->parameters(3, true)); $server->notify($this->senderNick, "Config key '" . $this->parameters(2) . "' set to '" . $this->parameters(3, true) . "'"); break; case "get": $value = Config::getValue($this->parameters(2)); if (!$value) { $server->notify($this->senderNick, "Config key '" . $this->parameters(2) . "' is not set"); } $server->notify($this->senderNick, $this->parameters(2) . " => " . $value); break; } }
/** * Updates the database with data from the script * arrays */ public function updateDatabase() { // Channels $this->query("DELETE FROM channel_users"); $this->query("DELETE FROM channels"); foreach (ChannelManager::$connectedChannels as $channel) { $stmt = $this->pdo->prepare("INSERT INTO channels(name, topic) VALUES(?,?);"); $stmt->execute(array($channel->channelName, $channel->topic)); foreach ($channel->connectedNicks as $connectedNick) { if (isset($channel->privilegedNicks[$connectedNick])) { $stmt = $this->pdo->prepare("INSERT INTO channel_users(nickname, channel_name, privilege) VALUES(?,?,?);"); $stmt->execute(array($connectedNick, $channel->channelName, $channel->privilegedNicks[$connectedNick])); } else { $stmt = $this->pdo->prepare("INSERT INTO channel_users(nickname, channel_name) VALUES(?,?);"); $stmt->execute(array($connectedNick, $channel->channelName)); } } } // Users $this->query("DELETE FROM users"); foreach (UserManager::$trackedUsers as $user) { if ($user->nickname && $user->ident && $user->host && $user->realName) { $stmt = $this->prepare("INSERT INTO users(nickname, ident, host, real_name) VALUES(?,?,?,?);"); $stmt->execute(array($user->nickname, $user->ident, $user->host, $user->realName)); } else { if ($user->nickname && $user->ident && $user->host) { $stmt = $this->prepare("INSERT INTO users(nickname, ident, host) VALUES(?,?,?);"); $stmt->execute(array($user->nickname, $user->ident, $user->host)); } else { if ($user->nickname) { $stmt = $this->prepare("INSERT INTO users(nickname) VALUES(?);"); $stmt->execute(array($user->nickname)); } } } } // Module data // check if we need to update anything currently in the db $stmt = $this->prepare("SELECT * FROM module_data"); $stmt->execute(); $doneTitles = array(); while ($row = $stmt->fetchObject()) { if (DataManager::checkIfDataExistsAndIsNewerThan($row->title, $row->module, $row->last_updated_time)) { $data = DataManager::retrieve($row->title, $row->module); $dbData = serialize($data); $time = DataManager::getLastUpdatedTime($row->title, $row->module); $stmt = $this->prepare("DELETE FROM module_data WHERE title=?;"); $stmt->execute(array($row->title)); $stmt = $this->prepare("INSERT INTO module_data(title, data, module, last_updated_time) VALUES(?,?,?,?);"); $stmt->execute(array($row->title, $dbData, $row->module, $time)); } $doneTitles[$row->title] = true; } // do everything else $allModules = DataManager::getAllData(); foreach ($allModules as $module => $titles) { foreach ($titles as $title => $types) { if ($doneTitles[$title]) { continue; } $dbData = serialize($types["data"]); $stmt = $this->prepare("DELETE FROM module_data WHERE title=?;"); $stmt->execute(array($title)); $stmt = $this->prepare("INSERT INTO module_data(title, data, module, last_updated_time) VALUES(?,?,?,?);"); $stmt->execute(array($title, $dbData, $module, $types["lastUpdated"])); } } // Config // check if we need to update anything currently in the db $stmt = $this->prepare("SELECT * FROM config"); $stmt->execute(); $doneKeys = array(); while ($row = $stmt->fetchObject()) { if (Config::checkIfValueExistsAndIsNewerThan($row->name, $row->last_updated_time)) { $data = Config::getValue($row->name); $dbData = serialize($data); $time = Config::getLastUpdatedTime($row->name); $stmt = $this->prepare("DELETE FROM config WHERE name=?;"); $stmt->execute(array($row->name)); $stmt = $this->prepare("INSERT INTO config(name, data, last_updated_time) VALUES(?,?,?);"); $stmt->execute(array($row->name, $dbData, $time)); } $doneKeys[$row->name] = true; } // do everything else $allKeys = Config::getAllValues(); foreach ($allKeys as $name => $types) { if ($doneKeys[$name]) { continue; } $dbData = serialize($types["data"]); $stmt = $this->prepare("DELETE FROM config WHERE name=?;"); $stmt->execute(array($name)); $stmt = $this->prepare("INSERT INTO config (name, data, last_updated_time) VALUES (?,?,?);"); $stmt->execute(array($name, $dbData, $types["lastUpdated"])); } }
while (true) { // Connect $server->connect(); // Identify $server->identify(); // If we send anything else too soon after identification it could be // lost, so sleep for 2 seconds sleep(2); // NickServ if (Config::getValue("nickservPassword")) { $server->identifyWithNickServ(); } // Connect commands ModuleManager::runConnectCommands(); // Loop through the channels in the config and join them $channels = Config::getValue("channels"); foreach ($channels as $channel) { $server->join($channel); } // Loop-edy-loop while ($server->connected()) { $line = $server->getNextLine(); $line = new ReceivedLine($line); $line->parse(); if ($line->isMappedCommand()) { $command = new Command($line); $command->execute(); } if ($line->isMappedEvent()) { $event = new Event($line); $event->execute();