Im having some problems when my bots update their roster. We are basically one org but split into two for different levels so the bots are setup to relay chat to each other. I have the bots running of the same database with some modificatiosn for the aliens module so that alts/poeple logging/login message are announced between both bots. I've also modified the cron function in the roster so that it checks both orgs for members when it updates.
When i initially start up either bot it will update the members and add players from both orgs to the database. The problem im having is that after so long the members table of the database ends up gettign cleared. My guess is that at some point when the bots go to update then they clear the members of the other org and thats why I end up with no members but the only update i can see is the cron in the roster which I know works at start-up so im not sure where it is going wrong.
Does anyone else have a suggestion as to where things could be going wrong, I had a look through my other modules but I can't see anything else that effects the roster.
The code im using for the roster is...
<?php
/*
* Roster.php - Handle member rooster
*/
/*
Prepare MySQL database
*/
$db -> query("CREATE TABLE IF NOT EXISTS " . $bot -> get_tablename("members") . "
(id INT NOT NULL PRIMARY KEY,
nickname VARCHAR(25),
firstname VARCHAR(25),
lastname VARCHAR(25),
rank TINYINT,
rank_name VARCHAR(20),
level INT,
profession VARCHAR(15),
gender VARCHAR(10),
breed VARCHAR(10),
ai_rank_id INT,
ai_rank VARCHAR(15),
pic VARCHAR(100),
lvlrange VARCHAR(10))");
$roster = new Roster($bot);
$commands["tell"]["member"] = &$rooster;
$commands["tell"]["members"] = &$rooster;
$commands["tell"]["memberlist"] = &$rooster;
$commands["gc"]["member"] = &$rooster;
$commands["gc"]["members"] = &$rooster;
$commands["gc"]["memberlist"] = &$rooster;
$commands["pgmsg"]["member"] = &$rooster;
$commands["pgmsg"]["members"] = &$rooster;
$commands["pgmsg"]["memberlist"] = &$rooster;
$cron["12hour"][] = &$rooster;
/*
The Class itself...
*/
class Roster
{
var $bot;
function Roster (&$bot)
{
$this -> bot = &$bot;
}
/*
This gets called on cron
*/
function cron()
{
$this -> bot -> log("ROSTER", "UPDATE", "Starting roster update");
$this -> bot -> send_gc("Starting roster update");
// Modify to fit your needs:
$relay_bot = "Serbot2";
// List of org ids this bot should keep as members:
// EDIT THOSE TO FIT YOUR NEED!
$orgids[0] = 3424258;
$orgids[1] = 3479561;
// Clean old member list before repopulating:
$this -> bot -> db -> query("TRUNCATE TABLE " . $this -> bot -> get_tablename("members"));
foreach ($orgids as $orgid)
{
$org = $this -> bot -> get_site("http://community.anarchy-online.com/org/stats/d/" . $this -> bot -> dimension . "/name/" . $orgid . "/basicstats.xml");
$org = explode("<member>", $org);
// Parse members
for ($i = 1; $i < count($org); $i++)
{
$memb["nickname"] = $this -> bot -> xmlparse($org[$i], "nickname");
$memb["firstname"] = $this -> bot -> xmlparse($org[$i], "firstname");
$memb["lastname"] = $this -> bot -> xmlparse($org[$i], "lastname");
$memb["rank"] = $this -> bot -> xmlparse($org[$i], "rank");
$memb["rank_name"] = $this -> bot -> xmlparse($org[$i], "rank_name");
$memb["level"] = $this -> bot -> xmlparse($org[$i], "level");
$memb["profession"] = $this -> bot -> xmlparse($org[$i], "profession");
$memb["gender"] = $this -> bot -> xmlparse($org[$i], "gender");
$memb["breed"] = $this -> bot -> xmlparse($org[$i], "breed");
$memb["ai_rank_id"] = $this -> bot -> xmlparse($org[$i], "defender_rank_id");
$memb["ai_rank"] = $this -> bot -> xmlparse($org[$i], "defender_rank");
$memb["pic"] = $this -> bot -> xmlparse($org[$i], "photo_url");
$memb["id"] = $this -> bot -> aoc -> get_uid($memb["nickname"]);
if (($memb["level"] >= 1) && ($memb["level"] <= 99))
$memb["lvlrange"] = "1-99";
else if (($memb["level"] >= 100) && ($memb["level"] <= 149))
$memb["lvlrange"] = "100-149";
else if (($memb["level"] >= 150) && ($memb["level"] <= 199))
$memb["lvlrange"] = "150-199";
else if (($memb["level"] >= 200) && ($memb["level"] <= 214))
$memb["lvlrange"] = "200-214";
else if (($memb["level"] >= 215) && ($memb["level"] <= 220))
$memb["lvlrange"] = "215-220";
else
$memb["lvlrange"] = "unknown";
$this -> bot -> db -> query("INSERT INTO members (id, nickname, firstname,"
. " lastname, rank, rank_name, level, profession, gender, breed, ai_rank_id, ai_rank, pic, lvlrange)"
. " VALUES ('" . $memb["id"] . "', '" . $memb["nickname"] . "', '" . $memb["firstname"] . "', '"
. $memb["lastname"] . "', '" . $memb["rank"] . "', '" . $memb["rank_name"] . "', '" . $memb["level"]
. "', '" . $memb["profession"] . "', '" . $memb["gender"] . "', '" . $memb["breed"] . "', '"
. $memb["ai_rank_id"] . "', '" . $memb["ai_rank"] . "', '" . $memb["pic"] . "', '" . $memb["lvlrange"]
. "')");
}
}
// get memberslist, and add all buddies in there:
$memberlist = $this -> bot -> db -> select("SELECT * FROM " . $this -> bot -> get_tablename("members"));
$buds = $this -> bot -> aoc -> buddies;
$added = 0;
$removed = 0;
foreach ($memberlist as $currentmember)
{
$nickname = $currentmember[1];
$id = $currentmember[0];
if (ucfirst(strtolower($nickname)) != ucfirst(strtolower($this -> bot -> botname))
&& ucfirst(strtolower($nickname)) != ucfirst(strtolower($relay_bot)))
{
if (!$this -> bot -> aoc -> buddy_exists($id))
{
$this -> bot -> aoc -> buddy_add($id);
$this -> bot -> log("BUDDY", "ADD", $this -> bot -> aoc -> get_uname($id));
$added++;
}
unset($buds[$id]);
}
}
$removed = count($buds);
// Remove buddys not on list...
foreach ($buds as $id => $value)
{
$this -> bot -> aoc -> buddy_remove($id);
$this -> bot -> log("BUDDY", "DEL", $this -> bot -> aoc -> get_uname($id));
}
$this -> bot -> log("ROSTER", "UPDATE", "Roster update complete. Added $added members, removed $removed.");
$this -> bot -> send_gc("Roster update completed");
}
/*
This gets called on a tell with the command
*/
function tell($name, $msg)
{
if ($this -> bot -> admin -> in_group($name, "admin"))
{
if (preg_match("/^" . $this -> bot -> commpre . "member del (.+)$/i", $msg, $info))
$this -> bot -> send_tell($name, $this -> member_del($name, $info[1]));
else if (preg_match("/^" . $this -> bot -> commpre . "members$/i", $msg)
|| preg_match("/^" . $this -> bot -> commpre . "memberlist$/i", $msg))
$this -> bot -> send_tell($name, $this -> member_list());
else if (preg_match("/^" . $this -> bot -> commpre . "member (.+)$/i", $msg, $info))
$this -> bot -> send_tell($name, $this -> member_add($name, $info[1]));
}
else
$this -> bot -> send_tell($name, "You must be an admin of this bot to use this command.");
}
/*
This gets called on a msg in the guild chat with the command
*/
function gc($name, $msg)
{
if ($this -> bot -> admin -> in_group($name, "admin"))
{
if (preg_match("/^" . $this -> bot -> commpre . "member del (.+)$/i", $msg, $info))
{
$this -> bot -> send_gc($this -> member_del($name, $info[1]));
}
else if (preg_match("/^" . $this -> bot -> commpre . "notify on (.+)$/i", $msg, $info))
$this -> notify_on($info[1]);
else if (preg_match("/^" . $this -> bot -> commpre . "notify off (.+)$/i", $msg, $info))
$this -> notify_off($info[1]);
else if (preg_match("/^" . $this -> bot -> commpre . "members$/i", $msg)
|| preg_match("/^" . $this -> bot -> commpre . "memberlist$/i", $msg))
{
$this -> bot -> send_gc($this -> member_list());
}
else if (preg_match("/^" . $this -> bot -> commpre . "member (.+)$/i", $msg, $info))
{
$this -> bot -> send_gc($this -> member_add($name, $info[1]));
}
}
else
$this -> bot -> send_tell($name, "You must be an admin of this bot to use this command.");
}
function pgmsg($name, $msg)
{
if ($this -> bot -> admin -> in_group($name, "admin"))
{
if (preg_match("/^" . $this -> bot -> commpre . "member del (.+)$/i", $msg, $info))
{
$this -> bot -> send_pgroup($this -> member_del($name, $info[1]));
}
else if (preg_match("/^" . $this -> bot -> commpre . "members$/i", $msg)
|| preg_match("/^" . $this -> bot -> commpre . "memberlist$/i", $msg))
{
$this -> bot -> send_pgroup($this -> member_list());
}
else if (preg_match("/^" . $this -> bot -> commpre . "member (.+)$/i", $msg, $info))
{
$this -> bot -> send_pgroup($this -> member_add($name, $info[1]));
}
}
else
$this -> bot -> send_tell($name, "You must be an admin of this bot to use this command.");
}
function member_add($name, $info)
{
$result = $this -> bot -> db -> select("SELECT nickname FROM " . $this -> bot -> get_tablename("members") . " WHERE id = "
. $this -> bot -> aoc -> get_uid($info));
if (empty($result))
{
if (!$this -> bot -> aoc -> get_uid($info))
return "Player <font color=#FFFF00>" . $info . "</font> does not exist";
else
{
$member = $this -> bot -> get_site("http://www.anarchy-online.com/character/bio/d/"
. $this -> bot -> dimension . "/name/" . strtolower($info) . "/bio.xml");
$members["nickname"] = ucfirst(strtolower($info));
$members["firstname"] = $this -> bot -> xmlparse($member, "firstname");
$members["lastname"] = $this -> bot -> xmlparse($member, "lastname");
$members["rank"] = $this -> bot -> xmlparse($member, "rank_id");
$members["rank_name"] = $this -> bot -> xmlparse($member, "rank");
$members["level"] = $this -> bot -> xmlparse($member, "level");
$members["profession"] = $this -> bot -> xmlparse($member, "profession");
$members["gender"] = $this -> bot -> xmlparse($member, "gender");
$members["ai_rank_id"] = $this -> bot -> xmlparse($member, "defender_rank_id");
$members["ai_rank"] = $this -> bot -> xmlparse($member, "defender_rank");
$members["breed"] = $this -> bot -> xmlparse($member, "breed");
$members["pic"] = $this -> bot -> xmlparse($member, "smallphoto_url");
$members["id"] = $this -> bot -> aoc -> get_uid($members["nickname"]);
if (($members["level"] >= 1) && ($members["level"] <= 99))
$members["lvlrange"] = "1-99";
else if (($members["level"] >= 100) && ($members["level"] <= 149))