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

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

Author Topic: updated Rooster_RAID.php (from svn)  (Read 7947 times)

0 Members and 1 Guest are viewing this topic.

Offline Wanuarmi

  • Contributor
  • *******
  • Posts: 121
  • Karma: +0/-0
updated Rooster_RAID.php (from svn)
« on: January 22, 2006, 10:46:41 pm »
No changes, just code organization, removed alot of duplicated code and made functions for them

The tell() and pgmsg() functoins had the same code, changing only output :P

Its alot easier now to find stuff and modify.

Code: [Select]
<?
/*
* Rooster.php - Handle member rooster
*
* BeBot - An Anarchy Online Chat Automaton
* Copyright (C) 2004 Jonas Jax
*
* Developed by Blondengy (RK1)
* Special thanks goes out to Khalem (RK1) for his support.
*
* File last changed at $LastChangedDate$
* Revision: $Id$
*/

/*
Prepare MySQL database
*/
$db -> query("CREATE TABLE IF NOT EXISTS 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),
                guild VARCHAR(35),
                pic VARCHAR(100),
                lvlrange VARCHAR(10),
updated INT,
                ailevel INT,
                aititle VARCHAR(25))");

$db -> query("CREATE TABLE IF NOT EXISTS member_settings
                (id INT NOT NULL PRIMARY KEY,
                on_list INT(1) DEFAULT '0',
                notify INT(1) DEFAULT '1')");


$rooster = new Rooster($bot);
$commands["tell"]["member"] = &$rooster;
$commands["tell"]["rosterupdate"] = &$rooster;
$commands["tell"]["notify"] = &$rooster;
$commands["tell2"]["member"] = &$rooster;
$commands["tell"]["members"] = &$rooster;
$commands["pgmsg"]["member"] = &$rooster;
$commands["pgmsg"]["members"] = &$rooster;
$commands["pgjoin"][] = &$rooster;

$cron["24hour"][] = &$rooster;

/*
The Class itself...
*/
class Rooster
{
var $bot;


/*
Constructor:
Hands over a referance to the "Bot" class
*/
function Rooster (&$bot)
{
$this -> bot = &$bot;
}



/*
This gets called on a tell with the command
*/
function tell($name, $msg)
{
$this -> bot -> send_tell($name, proccess_command($name, $msg));
}



/*
This gets called on a tell with the command from person outside guild
*/
function tell2($name, $msg)
{
if ($this -> bot -> admin -> in_group($name, "superadmin"))
$this -> bot -> send_tell($name, proccess_command($name, $msg));
}



/*
This gets called on a priv group msg with the command
*/
function pgmsg($name, $msg)
{
$this -> bot -> send_pgroup(proccess_command($name, $msg));
}



/*
This gets called if someone joins the privgroup
*/
function pgjoin($name)
{
if ($this -> bot -> is_member($name) == 1)
{
$result = $this -> bot -> db -> select("SELECT updated FROM members WHERE id = " .
$this -> bot -> aoc -> get_uid($name));
if ((time() - $result[0][0]) > (60 * 60 * 48))
{
$members = $this -> get_player_info($name);


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";

if (!empty($members["level"]))
{
$this -> bot -> aoc -> buddy_add($members["id"]);

$this -> bot -> db -> query("DELETE FROM members WHERE id = " . $members["id"]);
$this -> bot -> db -> query("INSERT INTO members (id, nickname, firstname, lastname, rank, rank_name, level, profession, gender, breed, pic, guild, lvlrange, updated, ailevel, aititle)
                        VALUES ('" . $members["id"] . "',
                                '" . $members["nickname"] . "', '" . $members["firstname"] . "',
                                '" . $members["lastname"] . "', '" . $members["rank"] . "',
                                '" . $members["rank_name"] . "', '" . $members["level"] . "',
                                '" . $members["profession"] . "', '" . $members["gender"] . "',
                                '" . $members["breed"] . "', '" . $members["pic"] . "',
                                '" . $members["guild"] . "', '" . $members["lvlrange"] . "',
                                " . time() . ", '" . $members["ailevel"] . "',
                                '" . $members["aititle"] . "')");
}
}
}
}



/*
* Takes care of commands and returns a message to channel used
*/
function proccess_command($name, $msg)
{
if ($this -> bot -> admin -> in_group($name, "admin")) //admin and superadmin
{
if (preg_match("/^" . $this -> bot -> commpre . "member del (.+)$/i", $msg, $info))
return $this -> delete_member($info[1]);
else if (preg_match("/^" . $this -> bot -> commpre . "members$/i", $msg))
return $this -> members();
else if (preg_match("/^" . $this -> bot -> commpre . "members list$/i", $msg))
$this -> list_members($name);
else if (preg_match("/^" . $this -> bot -> commpre . "member (.+)$/i", $msg, $info))
return $this -> add_member($info[1]);
else if (preg_match("/^" . $this -> bot -> commpre . "rosterupdate$/i", $msg))
$this -> update_roster();
}
else if(preg_match("/^" . $this -> bot -> commpre . "notify (on|off)$/i", $msg, $info))
{
$this -> set_notify($name, strtolower($info[1]));
}
else if(preg_match("/^" . $this -> bot -> commpre . "notify/i", $msg, $info))
{
return "Please use /tell <botname> <pre>notify (on|off)";
}
else
{
return "Your are not an admin of this bot";
}
}



/*
* Add a member
*/
function add_member($name, $add_name)
{
$result = $this -> bot -> db -> select("SELECT nickname FROM members WHERE id = " . $this -> bot -> aoc -> get_uid($add_name));
if (empty($result))
{
if (!$this -> bot -> aoc -> get_uid($add_name))
return "Player <font color=#ffff00>" . $add_name . "</font> does not exist";
else
{
$members = $this -> get_player_info($add_name);


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 members (id, nickname, firstname, lastname, rank, rank_name, level, profession, gender, breed, pic, guild, lvlrange, updated, ailevel, aititle)
                        VALUES ('" . $members["id"] . "',
                                '" . $members["nickname"] . "', '" . $members["firstname"] . "',
                                '" . $members["lastname"] . "', '" . $members["rank"] . "',
                                '" . $members["rank_name"] . "', '" . $members["level"] . "',
                                '" . $members["profession"] . "', '" . $members["gender"] . "',
                                '" . $members["breed"] . "', '" . $members["pic"] . "',
                                '" . $members["guild"] . "', '" . $members["lvlrange"] . "',
  " . time() . ", '" . $members["ailevel"] . "',
                                '" . $members["aititle"] . "')");

$this -> bot -> db -> query("INSERT INTO raid_points (id, points) VALUES (" . $members["id"] . ", 0)");
$this -> bot -> db -> query("INSERT INTO member_settings (id) VALUES (" . $members["id"] . ")");
$this -> bot -> send_tell($add_name, "<font color=#ffff00>" . $name . "</font> has added you to the bot.");
return "Player <font color=#ffff00>" . $add_name . "</font> has been added to the bot.";
}
}
else
return "<font color=#ffff00>" . $result[0][0] . "</font> is already a member.";
}



/*
* Shows how many members
*/
function members($member)
{
$result = $this -> bot -> db -> select("SELECT count(*) FROM members");
$result = $this -> bot -> db -> select("SELECT nickname FROM members ORDER BY nickname ASC LIMIT 0,300");
foreach($result as $nick)
$this -> bot -> aoc -> buddy_add($nick[0]);
for ($i = 0; $i < 300; $i++)
$this -> bot -> aoc -> get_packet();
$result = $this -> bot -> db -> select("SELECT nickname FROM members ORDER BY nickname ASC LIMIT 300,300");
foreach($result as $nick)
$this -> bot -> aoc -> buddy_add($nick[0]);
return "<font color=#ffff00>" . $result[0][0] . "</font> members on the bot.";
}



/*
* Delete a member
*/
function delete_member($member)
{
$result = $this -> bot -> db -> select("SELECT nickname FROM members WHERE id = " . $this -> bot -> aoc -> get_uid($member));
if (!empty($result))
{
$id = $this -> bot -> aoc -> get_uid($info[1]);
$this -> bot -> db -> query("DELETE FROM members WHERE id = " . $id);
$this -> bot -> db -> query("DELETE FROM raid_points WHERE id = " . $id);
$this -> bot -> db -> query("DELETE FROM member_settings WHERE id = " . $id);
$this -> bot -> aoc -> buddy_remove($id);
return "<font color=#ffff00>" . $info[1] . "</font> has been removed from member list.";
}
else
return "<font color=#ffff00>" . $info[1] . "</font> is not a member.";
}



/*
* Sets the notify state
*/
function set_notify($name, $status)
{
$id = $this -> bot -> aoc -> get_uid($name);
if ($status == "off")
{
$this -> bot -> aoc -> buddy_remove($id);
$this -> bot -> db -> query("UPDATE member_settings SET on_list = '0', notify = '0' WHERE id = '".$id."'");
}
else
$this -> bot -> db -> query("UPDATE member_settings SET notify = '1' WHERE id = '".$id."'");
$this -> bot -> send_tell($name, "Notify has been switched <font color=#ffff00>" . $status . "</font>.");
}



/*
* Update the roster of the bot
* This may take a while and goes heavy on the MySQL server
* so please use with care (in other words: only when updateing the bot)
*/
function update_roster()
{
// Set all people as not on list
$this -> bot -> db -> query("UPDATE member_settings SET on_list = '0'");

// Select all members
$result = $this -> bot -> db -> select("SELECT id FROM members");
for ($i = 0; $i < count($result); $i++)
{
// Remove everyone from list
if ($this -> bot -> aoc -> buddy_exists($result[$i][0]))
$this -> bot -> aoc -> buddy_remove($result[$i][0]);

// Add them to member_settings list if they're not on it already.
$res = $this -> bot -> db -> select("SELECT id FROM member_settings WHERE id = '" . $result[$i][0] . "'");
if (empty($res[0][0]))
$this -> bot -> db -> query("INSERT INTO member_settings (id) VALUES ('" . $result[$i][0] . "')");
}

// Add 980 people onto members-list...
$result = $this -> bot -> db -> select("SELECT members.id, nickname FROM members, member_settings WHERE members.id = member_settings.id AND member_settings.notify = 1 ORDER  BY updated DESC  LIMIT 0 , 980");
for ($i = 0; $i < count($result); $i++)
{
if ($id = $this -> bot -> aoc -> get_uid($result[$i][1]))
{
if ($id != $result[$i][0])
{
$this -> bot -> send_pgroup("The character <font color=#ffff00>" . $result[$i][1] . "</font> has rerolled. Correcting Member-ID.");
$this -> bot -> db -> query("UPDATE members SET id = '" . $id . "' WHERE id = '" . $result[$i][0] . "'");
$this -> bot -> db -> query("UPDATE raid_points SET id = '" . $id . "' WHERE id = '" . $result[$i][0] . "'");
$this -> bot -> db -> query("UPDATE member_settings SET id = '" . $id . "' WHERE id = '" . $result[$i][0] . "'");
}
$this -> bot -> aoc -> buddy_add($id);
$this -> bot -> db -> query("UPDATE member_settings SET on_list = '1' WHERE id = '" . $result[$i][0] . "'");
}
else
$this -> bot -> send_pgroup("The character <font color=#ffff00>" . $result[$i][1] . "</font> might have been deleted but is still on the members list.");
}
}



/*
* Update the rooster every 24h
*/
function cron()
{
$this -> bot -> log("CRON", "ROSTER", "Updateing buddylist");
$num = 0;

// Select oldest update
$oldest = $this -> bot -> db -> select("SELECT MIN(updated) FROM members, member_settings WHERE members.id = member_settings.id AND on_list = '1'");
$oldest = $oldest[0][0];

// Select all not on buddylist with notify on with newer update
$new = $this -> bot -> db -> select("SELECT members.id, nickname FROM members, member_settings WHERE members.id = member_settings.id AND on_list = '0' AND notify = '1' AND updated > '".$oldest."'");

// If changes have accured...
if (!empty($new[0][0]))
{
$num = count($new);
$start = 980 - $num;

// Select all those on buddy list to be removed
$remove = $this -> bot -> db -> select("SELECT members.id, nickname FROM members, member_settings WHERE members.id = member_settings.id AND member_settings.notify = 1 ORDER  BY updated DESC  LIMIT $start , $num");

// Remove them
if (!empty($remove))
{
for ($i = 0; $i < count($remove); $i++)
{
$this -> bot -> log ("BUDDY", "REM", $remove[$i][1]);
$this -> bot -> aoc -> buddy_remove($remove[$i][1]);
$this -> bot -> db -> query("UPDATE member_settings SET on_list = '0' WHERE id = '" . $remove[$i][0] . "'");
}
}
// Add the new ones
for ($i = 0; $i < count($new); $i++)
{
$this -> bot -> log ("BUDDY", "ADD", $new[$i][1]);
$this -> bot -> aoc -> buddy_add($new[$i][0]);
$this -> bot -> db -> query("UPDATE member_settings SET on_list = '1' WHERE id = '" . $new[$i][0] . "'");
}
}
$this -> bot -> log("CRON", "ROSTER", "Done updateing buddylist: " . $num. " new people getting messages.");
}



function list_members($name)
{
$result = $this -> bot -> db -> select("SELECT nickname, guild FROM members ORDER BY guild DESC");
$msg = "";
for ($i = 0; $i < count($result); $i++)
$msg .= $result[$i][0] . " (" . $result[$i][1] . ")\n";

$this -> bot -> send_tell($name, $this -> bot -> make_blob("Members", $msg));
}


function get_player_info($name)
{
$member = $this -> bot -> get_site("http://www.anarchy-online.com/character/bio/d/" . $this -> bot -> dimension . "/name/" . strtolower($name) . "/bio.xml");
$members["nickname"] = ucfirst(strtolower($add_name));
$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["guild"] = $this -> bot -> xmlparse($member, "organization_name");
$members["breed"] = $this -> bot -> xmlparse($member, "breed");
$members["pic"] = $this -> bot -> xmlparse($member, "pictureurl");
$members["id"] = $this -> bot -> aoc -> get_uid($members["nickname"]);
$members["ailevel"] = $this -> bot -> xmlparse($member, "defender_rank_id");
$members["aititle"] = $this -> bot -> xmlparse($member, "defender_rank");
return $members;
}
}
?>

Offline Xenixa

  • Contributor
  • *******
  • Posts: 307
  • Karma: +0/-0
Re: updated Rooster_RAID.php (from svn)
« Reply #1 on: January 23, 2006, 02:37:58 pm »
Hmm... interesting. I see this has alot of buddy list updating and member_settings table updating in the cron job and the manual forced roster update function.. but umm where exactly does it auto populate the Members table?
<<< Hack's in Zend Studio

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

Offline Wanuarmi

  • Contributor
  • *******
  • Posts: 121
  • Karma: +0/-0
Re: updated Rooster_RAID.php (from svn)
« Reply #2 on: January 24, 2006, 07:27:28 pm »
not sure... I dont even know whats that for, it would break bots with more than 1k member it seems... I think its the exact same function from the one in svn, but let me know if I messed anything

 

* Recent Posts
Com bot module by bitnykk
[November 25, 2024, 05:36:11 pm ]


0.8.x updates for AO by bitnykk
[June 23, 2024, 03:19:47 pm ]


0.8.x updates for AoC by bitnykk
[June 23, 2024, 03:19:44 pm ]


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


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

* Who's Online
  • Dot Guests: 174
  • 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