BeBot - An Anarchy Online and Age Of Conan chat automaton

Archive => Age of Conan Archive => AoC 0.6 support => Topic started by: Poonjab on July 17, 2009, 08:00:53 am

Title: IRC relay goes dead
Post by: Poonjab on July 17, 2009, 08:00:53 am
Yea, it's me again.  That annoying guy that keeps coming around here asking questions.

So I got the bot setup in an IRC channel and everything works fine for a while, but it goes dead several times a day and I have to do !irc connect to get the link established again.  Weird thing is that the bot is in the IRC channel, and working fine in guild, but traffic is not going between the two until I issue the connect command again.  Not quite sure what's causing it to flake out.

Any suggestions?

Thanks.
Title: Re: IRC relay goes dead
Post by: Poonjab on July 18, 2009, 01:39:51 am
OK, just a little more info on this.  Commands like !online in the IRC channel still work, but the bot stops relaying chat back and forth from guild chat / IRC.

Any ideas how to fix this to be more consistent?

Title: Re: IRC relay goes dead
Post by: Khalem on July 18, 2009, 08:07:05 pm
This sounds very odd and i honestly cannot think of any reason why this would happen. Especially if the bot is responding to commands on IRC.

Does the text to be relayed display in the console?

Title: Re: IRC relay goes dead
Post by: Poonjab on July 18, 2009, 09:41:14 pm
Yes, displaying fine in console, but stops relaying to IRC.

I've been messing around with the MaxRelaySize setting to see if I can find something more reliable.  Smaller seems to make it work for longer periods of time, but I haven't found a magic setting that keeps it working all the time yet.
Title: Re: IRC relay goes dead
Post by: Poonjab on July 21, 2009, 07:05:28 pm
Well, it's still very unreliable.  I played around with MaxRelaySize a bit but none of that really helped.  Stuff like the !online command still work and will report back to IRC, but the chat just stops getting relayed anywhere from 10 to 30 minutes or so.

It would be nice if you could tell the bot to reconnect to the IRC channel from the IRC channel, but that command seems to be disabled from IRC. 
Title: Re: IRC relay goes dead
Post by: Poonjab on July 25, 2009, 03:24:33 am
So I learned last night that chat from IRC still comes thru to ingame guild chat, but ingame guild chat back to IRC just dies after a while.

Anyone got any ideas yet?  Or know when the next version of bebot is coming out?

Thanks.
Title: Re: IRC relay goes dead
Post by: Khalem on July 25, 2009, 10:01:53 am
In your Relay.php module, find the relay_to_irc function and replace it with this one:
Code: [Select]
function relay_to_irc($msg)
{
$msg = preg_replace("/##end##/U", "", $msg);
$msg = preg_replace("/##(.+)##/U", "", $msg);

echo "Debug IRC sending: $msg\n";
$this -> bot -> send_irc("", "", $msg);
}

This will tell you if the bot actually sends the message to IRC.

Have you tried a different IRC server? Try setting one up on the same machine as the bot if you can to test.
Title: Re: IRC relay goes dead
Post by: Poonjab on July 25, 2009, 08:09:51 pm
In your Relay.php module, find the relay_to_irc function and replace it with this one:
Code: [Select]
function relay_to_irc($msg)
{
$msg = preg_replace("/##end##/U", "", $msg);
$msg = preg_replace("/##(.+)##/U", "", $msg);

echo "Debug IRC sending: $msg\n";
$this -> bot -> send_irc("", "", $msg);
}

This will tell you if the bot actually sends the message to IRC.

Have you tried a different IRC server? Try setting one up on the same machine as the bot if you can to test.

If you mean by try setting one up that I should setup a different IRC client on that machine to see if I have any problems staying connected to that IRC server and channel, then yes, I have done that, and experienced no problems outside what you normally see with IRC servers.

I will give this debug code a shot and let you know what else I come up with, and thanks for the help.
Title: Re: IRC relay goes dead
Post by: Khalem on July 25, 2009, 09:55:25 pm
I am not referring to the IRC client, but rather IRC server.

Make the bot use a different one, ie try irc.funcom.com if thats not what you are using now, or irc.shadow-realm.org

In any case, the debug code will tell you if the bot is even trying to send to the IRC channel when you notice it occuring and will tell us a little bit more. Then we can work from there to track it down if it is indeed an issue with the bot code.
Title: Re: IRC relay goes dead
Post by: Poonjab on July 25, 2009, 11:04:35 pm
Thanks Khalem.  Where will I find this extra information when then problem does happen?
Title: Re: IRC relay goes dead
Post by: Khalem on July 25, 2009, 11:12:08 pm
The information will output directly to the console window.
Title: Re: IRC relay goes dead
Post by: Poonjab on July 26, 2009, 05:16:05 am
Quote
Lawndart [BUDDY]        [LOG]   Coldsoul changed status [6] (MEMBER)
Total Count: 146716
Count: 1
Lawndart [BUDDY]        [LOG]   Subata changed status [6] (MEMBER)
Lawndart [GROUP]        [MSG]   [Dead Kow Kult] Lawndart: [IRC] Pockles: nice poon, bot broken again
Total Count: 146717
Count: 1
Lawndart [BUDDY]        [LOG]   Coolio changed status
  • (MEMBER)

Lawndart [GROUP]        [MSG]   [Dead Kow Kult] Lawndart: Coolio logged off
Lawndart [GROUP]        [MSG]   [Dead Kow Kult] Ayandi: we wiped

That's a quick example of traffic passing from IRC to guild but not from guild to IRC.  I don't see any debug info though.
Title: Re: IRC relay goes dead
Post by: Khalem on July 26, 2009, 12:12:23 pm
My bad. It's been a while since i looked at the IRC relaying code. We need the actual IRC.php module, not Relay.php.

First, find the function send_irc around line 195 and change it to the following
Code: [Select]
function send_irc($prefix, $name, $msg)
{
if (!$this -> bot -> core("settings") -> get("irc", "connected"))
{
echo "Debug IRC: Not connected!!!!\n";
return false;
}

$msg = $this -> strip_formatting($msg);

// If msg is too long to be relayed drop it:
if (strlen($msg) > $this -> bot -> core("settings") -> get("Irc", "Maxrelaysize"))
{
echo "Debug IRC: Message too long to be relayed!!!!\n";
return false;
}

$ircmsg = "";
if ($prefix != "")
{
$ircmsg = chr(2) . chr(2) . chr(2) . $prefix . chr(2) . ' ';
}
if ($name != "")
{
$ircmsg .= $name . ': ';
}
$ircmsg .= $msg;
$ircmsg = htmlspecialchars_decode($ircmsg);
$this -> irc -> message(SMARTIRC_TYPE_CHANNEL, $this -> bot -> core("settings") -> get("Irc", "Channel"), $ircmsg);
return true;
}


Find the function gmsg around line 228 and change it to the following
Code: [Select]
/*
This gets called on a msg in the group
*/
function gmsg($name, $group, $msg)
{
$msg = str_replace(">", ">", $msg);
$msg = str_replace("&lt;", "<", $msg);
echo "Debug IRC i am here!! \n";
if (($this -> irc != null) && ((strtolower($this -> bot -> core("settings") -> get("Irc", "Chat")) == "gc")
|| (strtolower($this -> bot -> core("settings") -> get("Irc", "Chat")) == "both")))
{
echo "Debug IRC i am here 2!! \n";
if (!$this -> send_irc($this -> bot -> core("settings") -> get("Irc", "Ircguildprefix"), $name, $msg))
{
echo "Debug IRC i am here 3!! \n";
if ($this -> bot -> core("settings") -> get("Irc", "Notifyondrop"))
{
echo "Debug IRC i am here 4!! \n";
$msg2 = "##error##Last line not relayed to IRC as it's containing too many characters!##end##";
$this -> spam[2][$this -> spam[0][2] + 1] = time();
if($this -> spam[0][2] == 5)
{
echo "Debug IRC i am here 5!! \n";
if($this -> spam[2][1] > time() - 30)
{
    echo "Debug IRC i am here 6!! \n";
$this -> irc_disconnect();
$msg2 = "IRC Spam Detected, Disconnecting IRC";
}
$this -> spam[0][2] = 0;
}
else
$this -> spam[0][2]++;
echo "Debug IRC i am here 6!! \n";
$this -> bot -> send_gc($msg2);
}
}
}
}


This will allow me to see why your bot stops sending to IRC despite still being connected.
Title: Re: IRC relay goes dead
Post by: Poonjab on July 26, 2009, 07:39:20 pm
OK, got the new debug code in, on irc.funcom.com this is the debug message:

Lawndart [GROUP]        [MSG]   [Dead Kow Kult] Shartgasm: test
Debug IRC i am here!!
Debug IRC i am here 2!!
Debug IRC: Not connected!!!!
Debug IRC i am here 3!!

I'm now going to try irc.shadow-realm.org and see how that goes.  Will let you know.
Title: Re: IRC relay goes dead
Post by: Poonjab on July 26, 2009, 08:26:44 pm
And the same result on irc.shadow-realm.org

Lawndart [GROUP]        [MSG]   [Dead Kow Kult] Shartgasm: test
Debug IRC i am here!!
Debug IRC i am here 2!!
Debug IRC: Not connected!!!!
Debug IRC i am here 3!!
Title: Re: IRC relay goes dead
Post by: Khalem on July 26, 2009, 08:37:23 pm
Both those indicate that the bot is not connected. Do messages go trough from irc -> gc?
Is the bot sitting in the assigned channel?
Title: Re: IRC relay goes dead
Post by: Poonjab on July 26, 2009, 10:22:53 pm
Both those indicate that the bot is not connected. Do messages go trough from irc -> gc?
Is the bot sitting in the assigned channel?

Yes, bot remains in IRC channel the whole time, and messages from IRC go to GC, but not from GC to IRC.

Doing an !irc connect from ingame will cause the bot to reconnect to IRC and it works for a while again, but always for a limited time.
Title: Re: IRC relay goes dead
Post by: Poonjab on July 27, 2009, 07:07:37 am
So I got to thinking (usually a bad thing right?), if the debug messages are able to indicate the connection is no longer there, despite the bot being in the IRC channel and IRC chat going to guild chat, couldn't a function just be written in to have the bot reconnect to IRC and start relaying traffic again?

I looked at the code and realized...  I have no idea how to write something like that.
Title: Re: IRC relay goes dead
Post by: Khalem on July 27, 2009, 12:55:23 pm
Check your IRC settings. There already is a reconnect function. However there is something very odd going on somewhere since the bot is still connected and sending messages from IRC.
Title: Re: IRC relay goes dead
Post by: Poonjab on July 28, 2009, 01:56:25 am
Here's my settings:

Quote
Settings for Irc
AnnounceTo: gc
 Description: Where should joins and leaves to the IRC channel be announced to?
 Change to: [ none | gc | pgmsg | both ]
AnnounceWhat: both
 Description: Which events should be announced to IRC? None, only buddies logging on, only joins to the chatgroup or both?
 Change to: [ none | buddies | joins | both ]
Channel: #dkk
 Description: Which IRC channel should be used?
/tell Lawndart !set Irc Channel <new value>
ChannelKey: passwordremoved
 Description: What is the IRC channel key if any?
/tell Lawndart !set Irc ChannelKey <new value>
Chat: both
 Description: Which channels should be relayed into IRC and vice versa?
 Change to: [ gc | pgroup | both ]
GuildPrefix: [IRC]
 Description: Which prefix should IRC chat relayed to ingame chat get?
/tell Lawndart !set Irc GuildPrefix <new value>
IrcGuestPrefix: [DKK Guest]
 Description: Which prefix should ingame chat in the chat groupf of the bot relayed to IRC get?
/tell Lawndart !set Irc IrcGuestPrefix <new value>
IrcGuildPrefix: [DKK]
 Description: Which prefix should ingame guild chat relayed to IRC get?
/tell Lawndart !set Irc IrcGuildPrefix <new value>
ItemRef: AOMainframe
 Description: Should AO Mainframe of AUNO be used for links in item refs?
 Change to: [ AOMainframe | AUNO ]
MaxRelaySize: 500
 Description: What's the maximum amount of characters relayed to IRC?
/tell Lawndart !set Irc MaxRelaySize <new value>
Nick: Lawndart
 Description: Which nick should the bot use in IRC?
/tell Lawndart !set Irc Nick <new value>
NotifyOnDrop: Off
 Description: Should the chat be notified if something isn't relayed because it's too large?
 Change to: [ On | Off ]
Port: 6667
 Description: Which port is used to connect to the IRC server?
/tell Lawndart !set Irc Port <new value>
Reconnect: On
 Description: Should the bot automatically reconnect to IRC?
 Change to: [ On | Off ]
RelayGuildName:
 Description: What is the name for GC guildrelay?
/tell Lawndart !set Irc RelayGuildName <new value>
Server: irc.funcom.com
 Description: Which IRC server is used?
/tell Lawndart !set Irc Server <new value>
UseGuildRelay: Off
 Description: Should chat coming from IRC also be relayed over the guild relay if it's set up?
 Change to: [ On | Off ]

I do have reconnect turned on, but I don't have anything for RelayGuildName as I'm not sure what it's for and I don't think it applies to me since I'm only running the 1 bot for the guild.

Let me know if you see any problems there.
Title: Re: IRC relay goes dead
Post by: Poonjab on July 29, 2009, 02:14:15 am
Any thoughts on my settings?  Do I have anything wrong here?

Thanks.
Title: Re: IRC relay goes dead
Post by: Khalem on July 29, 2009, 01:24:55 pm
Your settings look fine.

There is something very whacky going on somewhere with your bot somewhere.

Basically, somehow the hidden setting which the bot uses in various functions to check if the bot is connected is being set to FALSE... but not from within the IRC relay from what i can tell. As the only place we do that within the relay is after we have actually disconnected the bot, something would appear to alter this setting for your bot from a custom module or something else.

To put it plainly, given the code, i can see no way what you are experiencing should be possible.

Do you see the following in your logs just as the bot stops sending to IRC?
Code: [Select]
Botname [2009-07-23 11:31:08]   [SETTINGS]      [SAVED] connected for module irc set to FALSE as datatype bool

If you do, the change happens due to the setting being changed by an internal call in the bot. And the only place this happens in the unmodified version of BeBot is when the module is first loaded and when irc_disconnect is called.
The code reads
Code: [Select]
function irc_disconnect()
{
if ($this -> irc != null)
{
$this -> irc -> disconnect();
$this -> irc = null;
$this -> unregister_event("cron", "1sec");
$this -> bot -> core("settings") -> save("irc", "connected", FALSE);
$this -> bot -> db -> query("UPDATE #___online SET status_gc = 0 WHERE botname = '".$this -> bot -> botname . " - IRC'");
return "Disconnected from IRC server.";
}
else
return "IRC already disconnected.";
}
Basically it calls the SmartIRC class and tells it to disconnect the bot from IRC. It then sets the reference to the SmartIRC class to null. Then it removes the internal cronjob which fetches messages from IRC, and then sets the hidden setting to FALSE.

In your case, the hidden setting is being set to FALSE somewhere else.
Do you have multiple bots running on the same database? Do you have anything else interfacing with the bot database?

You could probably try this workaround, but it will only hide the problem by ignoring it:
Code: [Select]
function send_irc($prefix, $name, $msg)
{
if (!$this -> bot -> core("settings") -> get("irc", "connected"))
{
return false;
}
Change to
Code: [Select]
function send_irc($prefix, $name, $msg)
{
if (!$this->irc == NULL)
{
return false;
}
Title: Re: IRC relay goes dead
Post by: Poonjab on July 29, 2009, 07:01:04 pm

Do you see the following in your logs just as the bot stops sending to IRC?
Code: [Select]
Botname [2009-07-23 11:31:08]   [SETTINGS]      [SAVED] connected for module irc set to FALSE as datatype bool


Haven't noticed anything like that yet, but I haven't been looking for it either.  I'll see if I can find that happening.

Do you have multiple bots running on the same database? Do you have anything else interfacing with the bot database?

I don't have multiple bots running, but did at one point change the toon that the bot is running from.  As a result of that I see the database now has tables for the old bot and the new bot.  I wasn't sure what to do about that so I left it there and haven't messed with it.  Would it be safe to delete those tables?

Also don't really have anything interfacing with the bot database.  It's a standard XAMPP (x86 I believe) install (quick and easy for a nub like me to setup) running on a Vista x64 box.  I occasionally use phpMyAdmin to get in the alts table of the bot and manually confirm peoples alts as they are unable to do so themselves for some reason, but I've never bothered to ask here why that might be.

You could probably try this workaround, but it will only hide the problem by ignoring it:
Code: [Select]
function send_irc($prefix, $name, $msg)
{
if (!$this -> bot -> core("settings") -> get("irc", "connected"))
{
return false;
}
Change to
Code: [Select]
function send_irc($prefix, $name, $msg)
{
if (!$this->irc == NULL)
{
return false;
}


I will probably give that a shot and see how it goes.  Would just like it to work and have people stop bothering me every time it stops working.

Thanks for the help.
Title: Re: IRC relay goes dead
Post by: Khalem on July 29, 2009, 07:45:13 pm
You can safely remove the old tables belonging to your old bot when it was run under a different nickname yes.
Title: Re: IRC relay goes dead
Post by: Poonjab on July 30, 2009, 02:41:59 am
OK, so after making that change, the bot doesn't send any guild chat to IRC at all, not even after first connecting.
Title: Re: IRC relay goes dead
Post by: Khalem on July 30, 2009, 03:01:43 am
Oh for crying out loud. Thats what i get for coding while still not awake.

Correct code
Code: [Select]
if ($this->irc == NULL)
{
return false;
}
Title: Re: IRC relay goes dead
Post by: Poonjab on July 30, 2009, 07:51:17 am
Thanks Khalem.  Working mostly well now.  Only problem left is that it stops sending messages about people joining and leaving the game after a while, but the chat part is getting thru reliably now.
SimplePortal 2.3.7 © 2008-2024, SimplePortal