query("CREATE TABLE IF NOT EXISTS " . $db -> define_tablename("users", "true") . " (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, char_id INT NOT NULL UNIQUE, nickname VARCHAR(25) UNIQUE, password VARCHAR(64), password_salt VARCHAR(5), last_seen INT(11) DEFAULT '0', last_raid INT(11) DEFAULT '0', recieve_announce INT(1) DEFAULT '1', recieve_invite INT(1) DEFAULT '1', auto_invite INT(1) DEFAULT '0', added_by VARCHAR(25), added_at INT(11) DEFAULT '0', deleted_by VARCHAR(25), deleted_at INT(11), banned_by VARCHAR(25), banned_at INT(11), banned_for VARCHAR(100), banned_until INT(11) DEFAULT '0', notify INT(1) DEFAULT '0', user_level INT(1) DEFAULT '0', admin_level INT(1) DEFAULT '0', updated_at INT(11) DEFAULT '0', INDEX user_level (user_level), INDEX banned_until (banned_until), INDEX notify (notify))"); $db -> query("INSERT IGNORE INTO roster_updates (botname, status) VALUES ('" . $bot -> botname . "', 'false')"); $roster_core = new Roster_Core($bot); if ($bot -> guildbot) { $commands['gmsg']['Org Msg'][] = &$roster_core; } $cron["5min"][] = &$roster_core; class Roster_Core { var $bot; function Roster_Core (&$bot) { $this -> bot = &$bot; $this -> bot -> settings -> create("Members", "ParseOrgMsg", TRUE, "Should the Org.Msg. channel be parsed for joins, leaves and kicks?"); $this -> bot -> settings -> create("Members", "SchemaVersion", 1, "The version of the user table schema.", NULL, TRUE, 1); $this -> schema_version = 3; $this -> update_user_table(); } function update_user_table() { switch ($this -> bot -> settings -> get("members", "schemaversion")) { case 1: $this -> bot -> db -> query("ALTER TABLE #___users ADD banned_for VARCHAR(100) AFTER banned_at, " . "ADD banned_until INT(11) DEFAULT '0' AFTER banned_for"); case 2: $this -> bot -> db -> query("ALTER TABLE #___users ADD INDEX user_level (user_level), " . "ADD INDEX banned_until (banned_until), ADD INDEX notify (notify)"); case 3: default: } $this -> bot -> settings -> save("members", "schemaversion", $this -> schema_version); } function gmsg($name, $group, $msg) { if (!($this -> bot -> settings -> get("Members", "Parseorgmsg"))) { return; } if ($name == "0") { if (preg_match("/(.+) kicked (.+) from the organization./i", $msg, $info)) { $person = $info[2]; $source = $info[1]; $id = $this -> bot -> aoc -> get_uid($person); $this -> del ("Org Message", $id, $person, "from Org Message, kicked by $source"); unset($this -> bot -> glob["online"][$person]); $this -> bot -> db -> query("REPLACE INTO #___org_changes" . " (nickname, lastaction, timestamp) VALUES ('" . $person . "', 'kick', " . time() . ")"); $this -> update_relay("##red##$person is gone! Good riddance, ##highlight##$source!"); } else if (preg_match("/(.+) has left the organization./i", $msg, $info)) { $person = $info[1]; $id = $this -> bot -> aoc -> get_uid($person); $this -> del ("Org Message", $id, $person, "from Org Message"); unset($this -> bot -> glob["online"][$person]); $this -> bot -> db -> query("REPLACE INTO #___org_changes" . " (nickname, lastaction, timestamp) VALUES ('" . $person . "', 'leave', " . time() . ")"); $this -> update_relay("##red##$person has left the org!"); } else if (preg_match("/(.+) has joined the organization./i", $msg, $info)) { $person = $info[1]; $id = $this -> bot -> aoc -> get_uid($person); $this -> add ("Org Message", $id, $person, "from Org Message"); $this -> bot -> db -> query("REPLACE INTO #___org_changes" . " (nickname, lastaction, timestamp) VALUES ('" . $person . "', 'join', " . time() . ")"); $this -> update_relay("Welcome ##highlight##$person!"); } } } /* This gets called on cron */ function cron() { // Only do someting if it's wished for: if (!($this -> bot -> settings -> get("Members", "Updatebuddies"))) { return; } // Only got work to do if an update is required: $res = $this -> bot -> db -> select("SELECT status FROM roster_updates WHERE botname = '" . $this -> bot -> botname . "'"); if ($res[0][0] != 'true') { return; } $this -> bot -> log("ROSTER", "UPDATE", "Starting roster update"); $relay_bot = $this -> bot -> settings -> get("Relay", "Bot"); // get all toons on notify, and add them to the buddies list: $memberlist = $this -> bot -> db -> select("SELECT nickname FROM #___users WHERE notify = 1"); // update notify cache: $this -> bot -> notify -> update_cache(); $buds = $this -> bot -> aoc -> buddies; $added = 0; $removed = 0; if (!empty($memberlist)) { foreach ($memberlist as $currentmember) { $nickname = $currentmember[0]; $id = $this -> bot -> aoc -> get_uid($nickname); if ($id > 0 && ucfirst(strtolower($nickname)) != ucfirst(strtolower($this -> bot -> botname)) && ucfirst(strtolower($nickname)) != ucfirst(strtolower($relay_bot))) { $this -> bot -> buddy_add($nickname); unset($buds[$id]); } } } $removed = count($buds); // Remove buddys not on list... foreach ($buds as $id => $value) { $this -> bot -> buddy_remove($this -> bot -> aoc -> get_uname($id)); } $this -> bot -> db -> query("UPDATE roster_updates SET status = 'false' WHERE botname = '" . $this -> bot -> botname . "'"); $this -> bot -> log("ROSTER", "UPDATE", "Roster update complete. Added $added members, removed $removed."); // Update security cache $this -> bot -> security -> cache_security(); } function add($source, $id, $name, $reason) { $this -> bot -> log("ROSTER", "ADD", "Adding $name $reason"); $result = $this -> bot -> user -> add($source, $name, $id, MEMBER, 0, 1); if ($result["error"]) { $this -> bot -> log("ROSTER", "ERROR", $result["errordesc"]); } else { $this -> added++; } $this -> bot -> buddy_add($name); $this -> bot -> db -> query("UPDATE roster_updates SET status = 'true' WHERE botname = '" . $this -> bot -> botname . "'"); } function del($source, $id, $name, $reason) { $this -> bot -> log("ROSTER", "DEL", "Deleting $name $reason"); $result = $this -> bot -> user -> del($source, $name, $id, 1); if ($result["error"]) { $this -> bot -> log("ROSTER", "ERROR", $result["errordesc"]); } else { $this -> removed++; } $this -> bot -> buddy_remove($name); $this -> bot -> db -> query("UPDATE roster_updates SET status = 'true' WHERE botname = '" . $this -> bot -> botname . "'"); } function erase($source, $id, $name, $reason) { $this -> bot -> log("ROSTER", "ERASE", "Erasing $nickname $reason"); $result = $this -> bot -> user -> erase($source, $nickname, $id, 1); if ($result["error"]) { $this -> bot -> log("ROSTER", "ERROR", $result["errordesc"]); } $this -> bot -> buddy_remove($name); $this -> bot -> db -> query("UPDATE roster_updates SET status = 'true' WHERE botname = '" . $this -> bot -> botname . "'"); } function update_relay($note) { $this -> bot -> send_gc($note); $this -> bot -> send_pgroup($note); $relay_bot = $this -> bot -> settings -> get("Relay", "Roster_update_bot"); if ($relay_bot != '') { $this -> bot -> db -> query("UPDATE roster_updates SET status = 'true' WHERE botname = '" . $relay_bot . "'"); if ($this -> bot -> settings -> get("Relay", "Status")) { $this -> bot -> relay -> relay_to_bot($note); } } } } ?>