collapse collapse
* User Info
 
 
Welcome, Guest. Please login or register.
* Search

* Board Stats
  • stats Total Members: 989
  • stats Total Posts: 18363
  • stats Total Topics: 2500
  • stats Total Categories: 7
  • stats Total Boards: 35
  • stats Most Online: 1144

Author Topic: Roster Update  (Read 2652 times)

0 Members and 1 Guest are viewing this topic.

Offline Tremble

  • BeBot Rookie
  • *
  • Posts: 6
  • Karma: +0/-0
Roster Update
« on: January 01, 2007, 11:35:10 pm »
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...

Code: [Select]
<?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))
$members["lvlrange"] = "100-149";
else if (($members["level"] >= 150) && ($members["level"] <= 199))
$members["lvlrange"] = "150-199";
else if (($members["level"] >= 200) && ($members["level"] <= 214))
$members["lvlrange"] = "200-214";
else if (($members["level"] >= 215) && ($members["level"] <= 220))
$members["lvlrange"] = "215-220";
else
$members["lvlrange"] = "unknown";

$this -> bot -> db -> query("INSERT INTO " $this -> bot -> get_tablename("members")
" (id, nickname, firstname, lastname, rank, rank_name, level, profession, gender, breed,"
" ai_rank_id, ai_rank, pic, lvlrange)
VALUES ('" 
$members["id"] . "',
'" 
$members["nickname"] . "', '" $members["firstname"] . "',
'" 
$members["lastname"] . "', '" $members["rank"] . "',
'" 
$members["rank_name"] . "', '" $members["level"] . "',
'" 
$members["profession"] . "', '" $members["gender"] . "',
'" 
$members["breed"] . "', '" $members["ai_rank_id"] . "',
'" 
$members["ai_rank"] . "', '" $members["pic"] . "',
'" 
$members["lvlrange"] . "')");

$this -> bot -> send_tell($info"<font color=#FFFF00>" $name "</font> has added you to <botname>'s roster.");
return "Player <font color=#FFFF00>" $info "</font> has been added to <botname>'s roster.";
}
}
else
return "<font color=#FFFF00>" $result[0][0] . "</font> is already on <botname>'s roster.";
}

function member_del($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))
{
$id $this -> bot -> aoc -> get_uid($info);
$this -> bot -> db -> query("DELETE FROM " $this -> bot -> get_tablename("members") . " WHERE id = " $id);
$this -> bot -> aoc -> buddy_remove($id);
return "<font color=#FFFF00>" $info "</font> has been removed from <botname>'s roster.";
}
else
return "<font color=#FFFF00>" $info "</font> is not on <botname>'s roster.";
}

function member_list()
{
$result $this -> bot -> db -> select("SELECT nickname FROM " $this -> bot -> get_tablename("members")
" ORDER BY nickname ASC");
$str $this -> bot -> colors -> get("white") . "Members of this bot:<br>"
$this -> bot -> colors -> get("lightgrey");;
$i 0;
foreach ($result as $mem)
{
$i++;
$str .= $mem[0] . "<br>";
}
return $this -> bot -> make_blob($this -> bot -> botname " has " $i " members!"$str);
}
}
?>

Offline Dabaron

  • BeBot Apprentice
  • ***
  • Posts: 163
  • Karma: +0/-0
Re: Roster Update
« Reply #1 on: January 01, 2007, 11:54:56 pm »
I think your assumption is correct.  The bot checks the members table and removes anyone that isn't a member of the org.  With using one table for both orgs you will run into nothing but problems unless you remove the part that it removes non-org members from the table, but then you can run into issues when people leave/get kicked/etc from org.

Offline Tremble

  • BeBot Rookie
  • *
  • Posts: 6
  • Karma: +0/-0
Re: Roster Update
« Reply #2 on: January 02, 2007, 12:22:37 am »
If I know where it does the check then it shouldn't be too difficult to ad a check on the org id's and not remove from either org(same as it adds members to the database).

Offline Malosar

  • BeBot Expert
  • ****
  • Posts: 259
  • Karma: +0/-0
    • http://www.lowerdimension.com
Re: Roster Update
« Reply #3 on: January 02, 2007, 03:04:32 pm »
Your roster module should be setup ok to keep both orgs however it shouldn't be doing truncates before doing member lists. I've attached a copy of my updated Rooster_GUILD.php with some more functions as well which basically gets org list and a REPLACE INTO the member list. If yours might have trouble obtaining member list because of funcom site then it will be gone until the next update because of the truncate. Just modify it again to cycle both orgid's as you did with yours.

Also make sure you remove your Is.php if you have it as the is_online function is built into the new roster file. And if your running bebot 3 then you probably need to change the table name references to the get_tablename function.

Eternalist
General of The Syndicate

Offline Xenixa

  • Contributor
  • *******
  • Posts: 307
  • Karma: +0/-0
Re: Roster Update
« Reply #4 on: January 09, 2007, 02:17:02 am »
If I know where it does the check then it shouldn't be too difficult to ad a check on the org id's and not remove from either org(same as it adds members to the database).

The root of problem is right here:
Code: [Select]
// Clean old member list before repopulating:
$this -> bot -> db -> query("TRUNCATE TABLE " . $this -> bot -> get_tablename("members"));

And further down here:
Code: [Select]
$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"]
. "')");

Loose the TRUNCATE and change INSERT INTO to read REPLACE INTO and it makes more sense. Or modify what Malosar left attached above for your use. It's based on my revised Members list Cron() job. :)
<<< Hack's in Zend Studio

All my Custom Bebot files may be Found Here <-clicky

 

* Recent Posts
[AoC] special char for items module by bitnykk
[February 09, 2024, 09:41:18 pm]


0.8.x updates for AoC by bitnykk
[January 30, 2024, 11:16:08 pm]


0.8.x updates for AO by bitnykk
[January 30, 2024, 11:15:37 pm]


BeBot still alive & kicking ! by bitnykk
[December 17, 2023, 12:58:44 am]


Bebot and Rasberry by bitnykk
[November 29, 2023, 11:04:14 pm]

* Who's Online
  • Dot Guests: 515
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.
* Forum Staff
bitnykk admin bitnykk
Administrator
Khalem admin Khalem
Administrator
WeZoN gmod WeZoN
Global Moderator
SimplePortal 2.3.7 © 2008-2024, SimplePortal