BeBot - An Anarchy Online and Age Of Conan chat automaton

Archive => Anarchy Online Archive => BeBot 0.2 support => Topic started by: Xenixa on December 12, 2005, 10:44:17 pm

Title: Auto invites revisited
Post by: Xenixa on December 12, 2005, 10:44:17 pm
So for the last month I have been sitting here playing with (and some times banging my head on the desk) a way to get auto invites to work correctly.

So what did I discover? Well I discovered Guests only got invited one time and one time only. That would be the first time the bot see's them. Why do they never get another Invite to the private channel was my question. It never occured to me that someone would in Bot.php do this:
Code: [Select]
if (!$mem)
      $end = " (not member)";
else if ($mem == 2)
$end = " (guest)";
if (!$mem || ($mem == 2))
$this -> aoc -> buddy_remove($user);

if ($this -> is_member($name) != 1)
        $this -> aoc -> buddy_remove($name);
So just to make this clear, as long as the Bot adds Buddies when a Guild member adds a Guest to the bot, the code piece above will never let any module Auto invite Guests to Private chat channel. They keep getting removed as buddies!!
Title: Re: Auto invites revisited
Post by: Xenixa on December 13, 2005, 12:36:31 am
On a Related note, the is_member function will never work as written in the SVN version of Bot.php to eval if they are a Member or a Guest.
This will not work:
Code: [Select]
<?
function is_member($uname)
{
$result = $this -> db -> select("SELECT nickname FROM members WHERE id = " . $this -> aoc -> get_uid($uname));
if (!empty($result))
return 1;

$result = $this -> db -> select("SELECT id FROM guests WHERE id = " . $this -> aoc -> get_uid($uname));
if (!empty($result))
return 2;

return false;
}
?>
I'll explain why. Return can't be used conditionally like that. When PHP encounters a Return it forces the Function to exit with the value set. So in the code above guess what will always be returned? If you guessed 1 or NOTHING(Null) you would be correct.
My suggestion would be to do something like this:
Code: [Select]
    function is_member($uname)
    {
if ($uid = $this -> aoc -> get_uid($uname))
{
$result = $this -> db -> select("SELECT nickname FROM members WHERE id = " . $uid);
    if (!empty($result))
        return 1;   
else
$result = $this -> db -> select("SELECT id FROM guests WHERE id = " . $uid);
      if (!empty($result))
      return 2;     
else
      return false;
}
    }
The above works for me and doesn't break the bot in other places were it uses the is_member() function.
Title: Re: Auto invites revisited
Post by: Khalem on December 13, 2005, 01:24:29 am
Blondengy wrote the checks, and i assume it was done this way to keep guests from generating logon/login notices.

Its essentially a part of the entire rooster cleanup id like to do where the members table contains everyone with access, guest or member, and then use flags to signify if they are a guest, if they should generate a login notification, recieve announce and massinvites etc.
Title: Re: Auto invites revisited
Post by: Xenixa on December 13, 2005, 09:01:16 am
Hmmm... well since the function inc_buddy() in Bot.php just outputs to the Log and since it would be nice for Org bots to auto invite Guests automatically as an option(using Autoinv.php), I changed/tweaked the Function a bit to not remove Characters on the Guest Table from the bots buddy list. Will only remove names from the Buddy list if they are not on either the Members or Guest table the next time the bot see's them.
Re-written looks like this:
Code: [Select]
function inc_buddy($args)
{
$user = $this -> aoc -> get_uname($args[0]);

$mem = $this -> is_member($user);

$end = "";
if (!$mem)
{
$end = " (not member)";
}
else if ($mem == 2)
{
$end = " (guest)";
}

if ($this -> is_member($name) != 1)
$this -> aoc -> buddy_remove($name);

$this -> log("BUDDY", "LOG", $user . " logged [" . (($args[1] == 1) ? "on" : "off") . "]" . $end);

if (!empty($this -> commands["buddy"]))
{
$keys = array_keys($this -> commands["buddy"]);
foreach ($keys as $key)
$this -> commands["buddy"][$key] -> buddy($user, $args[1]);
}
}
This assumes you're using the modified is_member() I have above since the original would never return a 2.

The generation of logon/login notices is handled by Logon_GUILD.php which uses it's own Funtion to see if they are a Member. Players on Guests list aren't announced unless you've done like I have in Relay_GUILD.php and have it only announce when they actually Join the Private channel rather then when they logon. Which IMHO is the better solution... Untill that 1000 character Buddy list limitation is hit anyway.

Guess this means I'll have to re-write autoinv.php also so it can be set via ingame to auto invite either Members, Guests, Both or Off rather than just On or Off. :)
Title: Re: Auto invites revisited
Post by: Oneforderoad on December 14, 2005, 12:58:03 pm
pardon me for sticking in my 2 cents worth but:

 function is_member($uname)
    {
   if ($uid = $this -> aoc -> get_uid($uname))

shouldnt that be
      if ($uid  == $this -> aoc -> get_uid($uname))

Title: Re: Auto invites revisited
Post by: Alreadythere on December 14, 2005, 01:18:14 pm
pardon me for sticking in my 2 cents worth but:

 function is_member($uname)
    {
   if ($uid = $this -> aoc -> get_uid($uname))

shouldnt that be
      if ($uid  == $this -> aoc -> get_uid($uname))


No. It's ugly C tradition, but you actually are allowed to set variables in if () checks - then the value of the variable is the comparator.
Title: Re: Auto invites revisited
Post by: Xenixa on December 14, 2005, 01:35:23 pm
Yup, and since the Value of the comparitor($uid) in the condition check remains the same through each step, it relies on the inner/sub condition check to move the comparitive pointer down the list.

This can also be done with a "While" loop in PHP btw. Kinda of a dirty trick I did there but PHP's parser handles it well enough. That and I just wanted to show a way to keep Return from exiting the the function before all conditions were checked.   ;D
Title: Re: Auto invites revisited
Post by: Naturalistic on December 15, 2005, 05:34:22 pm
What that is saying:

Set $uid to be $this -> aoc -> get_uid($uname), when inside the if statement, if that varible is "valid" or a true variable (meaning there is info in that variable)...that makes the If statement true.

Hope that kinda clears things up ;)


You can also have: (but it's faster to do it the first way :P)
...
$uid = $this -> aoc -> get_uid($uname);
if ($uid)
{
  blah blah;
}
...
Title: Re: Auto invites revisited
Post by: Khalem on December 15, 2005, 07:39:08 pm
Once i do my member table changes, is_member will be rewritten to work properly anyways. *kicks is_member*
SimplePortal 2.3.7 © 2008-2025, SimplePortal