BeBot - An Anarchy Online and Age Of Conan chat automaton

Development => Coding and development discussion => Topic started by: Vhab on March 07, 2007, 07:27:33 am

Title: Improving relay over IRC
Post by: Vhab on March 07, 2007, 07:27:33 am
I promissed khalem I'd post this, so here it goes.

Currently things like items etc aren't relayed properly.
Also when using IRC to relay between guilds the output is a bit dodgy like:
[Your Guild] Bot: [IRC] Otherbot: [Their Guild] Someguy: hi

To solve this without affecting the readability on IRC, I build a very small protocol using "hidden characters".
I have currently implemented this in VhaBot and it would be nice if more bots adopt it.

Some basic information:
[BOLD]: Character 2
[REVERSE]: Character 22
[UNDERLINE]: Character 31
[COLOR]: Character 3

These are all characters used by most IRC clients to format text.
They function as a toggle. each appearance of the character reverses the effect. (placing a bold makes the text bold, placing another makes the text normal again).
We can abuse this by placing them in sets of 2, which means they are visually invisible to the users (on any modern irc client).

Message relaying:
Before: [Channel] Nickname: message
After: [BOLD][BOLD][BOLD][Channel][BOLD] Nickname: message
It starts with 2 bold characters, followed by the [Channel] outputted as bold.
When receiving a message following this structure, you don't display [IRC] Botname: [Channel] Nickname: message
but directly display: [Channel] Nickname: message
Also, this is the way it's currently implemented in IGN. while it may be a dying piece of crap, some compat never hurts.
All bold characters are required.

Items relaying:
Before: check this item Burden of Incompetence (http://url to auno/aodb)
After: check this item [COLOR][COLOR]Burden of Incompetence[COLOR] [COLOR](http://auno.org/ao/db.php?id=123&id2=123&ql=200)[COLOR][COLOR]
The space between the second set of [COLOR] is intentional.
There's also an id2= added to the url. this is done because while auno only need 1 id to operate, we need both to generate a valid item ingame.
Some patterns I'm using for this:
this.ItemFormat = this.COLOR + this.COLOR + "{0}" + this.COLOR + " " + this.COLOR + "(http://auno.org/ao/db.php?id={1}&id2={2}&ql={3})" + this.COLOR + this.COLOR;
this.ItemPattern = this.COLOR + this.COLOR + "(.+?)" + this.COLOR + " " + this.COLOR + "[(](.+?)id=([0-9]+)&id2=([0-9]+)&ql=([0-9]+)[)]" + this.COLOR + this.COLOR;
First line is the way we format it, second line is the regexp for finding the messages.
On the first line replace {0} with the item name, {1} with the lowID, {2} with the highID, {3} with QL
(LowID doesn't mean the ID is lower than HighID. it means the associated QL with that ID is lower than the QL of the HighID. in case of doubt, just use how AO sends it to you)
Title: Re: Improving relay over IRC
Post by: Khalem on March 09, 2007, 11:56:04 pm
Thanx Vhab.

Been giving this some thought as of late. Just need time :\
Title: Re: Improving relay over IRC
Post by: Vhab on March 16, 2007, 07:25:34 pm
Seeing there's some development regarding IRC going on by non-contributors (no offense intended, refering to people without access to the contributors forum) can this post be moved to a public sub-forum?
Title: Re: Improving relay over IRC
Post by: jjones666 on March 16, 2007, 08:50:36 pm
Moved to 0.2 support, lemme know if you want it anywhere different.

-jj-
Title: Re: Improving relay over IRC
Post by: Nytridr on March 17, 2007, 02:51:23 am
I have posted this before somewhere else.. but atm really just to sick to look for it.. but here is some of the mods I made for the alliance I am in.. and it seems to work halfway decent..

I have added a lang filter which you can turn it on and off while in game..

put a limit that the IRC will send out that way if something is to long it will just not send it..

took out the formating changing in the sending and reciving for now.. till either I can figure out how to do it correctly or someone else can.. with the items across the IRC.. since on the reciving side it needs to be reconverted back into a workable link.

http://metanyt.homeip.net:8888/bebot/ (http://metanyt.homeip.net:8888/bebot/)


since to me it seems things should problably be under the same topic I figured I would repost it here.. that way who ever wants to look my simple changing of things can..:)
Title: Re: Improving relay over IRC
Post by: Alreadythere on May 04, 2007, 07:26:29 pm
What char is [COLOR]? Or is that something else? Got no real clue about IRC tbh :)
Title: Re: Improving relay over IRC
Post by: Vhab on May 04, 2007, 10:18:28 pm
my bad, seems i forgot that one.
it's ascii 3
Title: Re: Improving relay over IRC
Post by: Alreadythere on May 05, 2007, 12:25:54 pm
Implemented and working, just got to wait for the SVN to be back up to commit it.
Title: Re: Improving relay over IRC
Post by: Vhab on May 05, 2007, 12:29:24 pm
nice :D
Title: Re: Improving relay over IRC
Post by: Alreadythere on May 05, 2007, 01:25:48 pm
One question:

Code: [Select]
$msg = preg_replace("/<a href=\"(.+)\">/isU", "[link]", $msg);
$msg = preg_replace("/<\/a>/iU", "[/link]", $msg);
$msg = preg_replace("/<font(.+)>/iU", "", $msg);
$msg = preg_replace("/<\/font>/iU", "", $msg);
The code above is in the gmsg() and privgroup() functions, removing ingame blobs and colors.

Is there any way to format it in a decent way for IRC while saving all information so the tags can be recreated on the other bots of the relay?
Title: Re: Improving relay over IRC
Post by: Vhab on May 05, 2007, 02:44:50 pm
don't think so, firstly because of the size of the blobs, it'll easy hit the irc max and flood limit.
also, you'll have to visualize all data on the irc side in some way, and spamming the full contents of a blob to irc is a tad too spammy imo.
Title: Re: Improving relay over IRC
Post by: Blueeagle on May 05, 2007, 02:49:42 pm
The only way I see such a thing fesable is if someone runs a command and then have the bot reply in /msg-s.

Well you could always write the blob to a file and post it to a web-server or such. :)
Title: Re: Improving relay over IRC
Post by: Alreadythere on May 05, 2007, 02:52:55 pm
I'll just leave it then.
Title: Re: Improving relay over IRC
Post by: Khalem on May 06, 2007, 01:04:24 am
SVN is up. I know it's been a bit unstable in the past few days.

We are experiencing some hardware issues with this system as it has frozen up completely 5 or 6 times now in the past few days.

A hardware swap is planned asap which hopefully will bring SVN back to being stable.
Title: Re: Improving relay over IRC
Post by: Alreadythere on May 06, 2007, 01:07:25 am
Commited.
Title: Re: Improving relay over IRC
Post by: Nytridr on May 06, 2007, 06:33:14 am
seems like privgroup isnt being relayed over the IRC channel and the IRC channel isnt being relayed to privgroup either..
Title: Re: Improving relay over IRC
Post by: Vhab on May 06, 2007, 09:02:52 am
i think that's located in the config now.
you should be able to turn it on/off
Title: Re: Improving relay over IRC
Post by: Alreadythere on May 06, 2007, 10:30:25 am
Yes, it's a setting now, irc_chat. Default is gc.
Title: Re: Improving relay over IRC
Post by: Nytridr on May 06, 2007, 03:37:55 pm
appreciate it.. for some reason I didnt see it when I was looking at the settings irc lastnight..
Title: Re: Improving relay over IRC
Post by: Nytridr on May 06, 2007, 07:45:17 pm
I am assuming this is in the IRC part of the bot.. since when I do not have the IRC mod going this dont happen..

the bot will build up using about 20+ megs of ram and just hang there..

Code: [Select]
[06-May-2007 10:48:49] PHP Fatal error:  Allowed memory size of 20971520 bytes exhausted (tried to allocate 8 bytes) in C:\aobots\RS\rsbot\Sources\MySQL.php on line 146

[06-May-2007 11:19:12] PHP Fatal error:  Allowed memory size of 20971520 bytes exhausted (tried to allocate 35 bytes) in C:\aobots\RS\rsbot\Sources\MySQL.php on line 164

[06-May-2007 11:31:53] PHP Fatal error:  Allowed memory size of 20971520 bytes exhausted (tried to allocate 96 bytes) in C:\aobots\RS\rsbot\Sources\MySQL.php on line 146

Now this didnt start happening till again till I turned on IRC Chat to both instead of GC.. 

Title: Re: Improving relay over IRC
Post by: Alreadythere on May 06, 2007, 08:05:54 pm
Uhm...

No clue, it shouldn't use more memory really...
Title: Re: Improving relay over IRC
Post by: Alreadythere on May 06, 2007, 08:19:16 pm
I've checked the code that I added, and besides a few instances of old settings names that I forgot to switch the only thing that could eat some memory is the regex checks. But the garbage collection should clean that up after the function calls are over...
Title: Re: Improving relay over IRC
Post by: Nytridr on May 06, 2007, 09:07:14 pm
I've checked the code that I added, and besides a few instances of old settings names that I forgot to switch the only thing that could eat some memory is the regex checks. But the garbage collection should clean that up after the function calls are over...

IDK this is like a doctor problem.. when your at home you feel sick and think you need to go to the docs.. but when you get there you feel fine and the doc says theres nothing wrong..

well guess what.. mem is stable now and even though each bot is using differnt ram ammounts they are not going up and are staying pretty stable.. even though I have seen the bot still spamming off and on.. but I am woundering  if it has something to do with what ever is going on....  the differnt org bots are using between 5meg to 15megs right now.. all differnt.. not sure why either.
Title: Re: Improving relay over IRC
Post by: Dabaron on June 25, 2007, 12:30:44 am
I had added a few things to my IRC module in .2 but can't seem to get them working in .3.4 so thought I'd see what you guys think.  I'm sure its just something with the way .3.x handles stuff differently.  I changed the !online to show difference in org chat and private group and added a whois.

Code: [Select]
/*
* Gets called when someone does !online
*/
function irc_online(&$irc, &$data)
{
if (isset($this -> bot -> commands["tell"]["online"]))
{
foreach($this -> bot -> commands["tell"]["online"] -> guild as $player)
$nick[$player[0]] = 1;
ksort($nick);
$msg = count($nick) . " org members online: ";
foreach ($nick as $name => $val)
$msg .= $name . ", ";

foreach($this -> bot -> commands["tell"]["online"] -> pgroup as $guestplayer)
$guestnick[$guestplayer[0]] = 1;
ksort($guestnick);
$guestmsg = count($guestnick) . " players in guest channel: ";
foreach ($guestnick as $guestname => $val)
$guestmsg .= $guestname . ", ";


$this -> irc -> message(SMARTIRC_TYPE_CHANNEL, $this -> chan, $msg);
$this -> irc -> message(SMARTIRC_TYPE_CHANNEL, $this -> chan, $guestmsg);
}
else
$this -> irc -> message(SMARTIRC_TYPE_CHANNEL, $this -> chan, "Online module not installed.");
}

/*
        * Whois Function - Used exclusively for IRC to strip color codes and add IRC specific coding
        */
function whois_player($name)
{
$content = $this -> bot -> get_site("http://www.anarchy-online.com/character/bio/d/" . $this -> bot -> dimension . "/name/" . strtolower($name) . "/bio.xml");
$who["nick"] = $this -> bot -> xmlparse($content, "nick");
$who["firstname"] = $this -> bot -> xmlparse($content, "firstname");
$who["lastname"] = $this -> bot -> xmlparse($content, "lastname");
$who["level"] = $this -> bot -> xmlparse($content, "level");
$who["gender"] = $this -> bot -> xmlparse($content, "gender");
$who["breed"] = $this -> bot -> xmlparse($content, "breed");
$who["profession"] = $this -> bot -> xmlparse($content, "profession");
$who["faction"] = $this -> bot -> xmlparse($content, "faction");
$who["rank"] = $this -> bot -> xmlparse($content, "rank");
$who["org"] = $this -> bot -> xmlparse($content, "organization_name");
$who["at_name"] = $this -> bot -> xmlparse($content, "defender_rank");
$who["at"] = $this -> bot -> xmlparse($content, "defender_rank_id");

if (!empty($who["nick"]))
{
$at = "(AT " . $who["at"] . " - " . $who["at_name"] . ") ";
$result = "\"" . $who["nick"] . "\"";
if (!empty($who["firstname"]) && ($who["firstname"] != "Unknown"))
$result = $who["firstname"] . " " . $result;
if (!empty($who["lastname"]) && ($who["lastname"] != "Unknown"))
$result .= " " . $who["lastname"];

$result .= " is a level " . $who["level"] . " " . $at . $who["gender"] . " " . $who["breed"] . " " . $who["profession"] . ", " . $who["faction"];
if (!empty($who["rank"]))
$result .= ", " . $who["rank"] . " of " . $who["org"] . ".";
else
$result .= ".";
}
else
$result = "www.anarchy-online.com was too slow to respond.";

return $result;
}

/*
* Gets called when someone does !whois
*/
function irc_whois(&$irc, &$data)
{
if (isset($this -> bot -> commands["tell"]["whois"]))
{
   preg_match("/^" . $this -> bot -> commpre . "whois (.+)$/i", $data -> message, $info);
                   $info[1] = ucfirst(strtolower($info[1]));

   if ($this -> bot -> aoc -> get_uid($info[1]))
      $this -> irc -> message(SMARTIRC_TYPE_CHANNEL, $this -> chan, $this -> whois_player($info[1]));
                   else
       $this -> irc -> message(SMARTIRC_TYPE_CHANNEL, $this -> chan, "Player " . $info[1] . " does not exist.");
}
else
    $this -> irc -> message(SMARTIRC_TYPE_CHANNEL, $this -> chan, "Whois module not installed.");
}
Title: Re: Improving relay over IRC
Post by: Alreadythere on June 25, 2007, 12:42:10 am
Online no longer stores anything in arrays, so reading the online -> guild array won't work.

You have to query the online table, like the 0.3.4 version does.
Code: [Select]
$online = $this -> bot -> db -> select("SELECT nickname FROM #___online WHERE botname = '" . $this -> bot -> botname . "' AND status_gc = 1 ORDER BY nickname ASC");The $online array contains the nicknames of all online buddies then.

Replace status_gc = 1 with status_pg to get charaters in private group.

For the whois you should call $this -> bot -> whois -> lookup($name), the whois cache is integrated in 0.3.4 already. Then just adapt your output generation to the slightly different array names used in the return, check core/Whois.php for a listing. It should work otherwise.
Title: Re: Improving relay over IRC
Post by: Dabaron on June 25, 2007, 01:26:41 am
Thanks, I'll give that a try.
Title: Re: Improving relay over IRC
Post by: Tyrence on August 26, 2011, 03:16:09 am
I am finally getting around to having this implemented on Budabot so it will finally be compatible.  I was wondering if anyone is using this on their Bebot install that I could test with to make sure it all works?
SimplePortal 2.3.7 © 2008-2024, SimplePortal