Whitelisting clears sender?

Sentrion

Member
I wrote a chatbotScript for my clannies to use that faxes a Mer-kin tippler into the clan. It dumps a photocopy, goes to a clan with a tippler, comes back to fax that in, and finally tells the sender that it's done. However, I came upon an interesting problem where the sender variable apparently gets cleared by the first whitelist function, resulting in my trying to /msg an empty string (the chat event message I get is 'Unknown recipient "". Message (axed.) not sent.').

Here is the relevant code:
Code:
void main(string sender,string message,string channel)
{
	if (channel == "")
	{
		if (message == "fax tippler")
		{
			if (item_amount($item[photocopied]) == 1)
				cli_execute("fax send");
			cli_execute("/whitelist clan1");
			cli_execute("fax receive");
			cli_execute("/whitelist clan2");
			cli_execute("fax send");
			chat_private(sender,"Faxed.");
		}
	}
}

I put print()s throughout to find the perpetrator, and like I said, it seems to be that first whitelist. I've fixed my script for the time being by declaring a new string, but I'm really curious as to why I was having this problem.
 

slyz

Developer
I used the following chatbotScript:
PHP:
void main( string sender, string msg, string channel )
{
	if ( !sender.contains_text( my_name() ) && ! channel.contains_text( "Events" ) ) return;

	print( "" );
	print( "START chatbotScript( " + sender + ", " + msg + ", " + channel + " )" );

	if ( sender.contains_text( my_name() ) )
	{
		print( "Whitelisting" );
		cli_execute( "/whitelist the hogs of destiny" );
	}

	print( "END chatbotScript( " + sender + ", " + msg + ", " + channel + " )" );
	print( "" );
}
I launched it by say something in chat, and here was the resulting output in the gCLI:
Code:
START chatbotScript( slyz, test, /clan )
Whitelisting
[color=green]Now pledging your allegiance to The Hogs of Destiny.[/color]


START chatbotScript( , Now pledging your allegiance to The Hogs of Destiny., Events )
END chatbotScript( , Now pledging your allegiance to The Hogs of Destiny., Events )

END chatbotScript( , Now pledging your allegiance to The Hogs of Destiny., Events )
It looks like the arguments are global, instead of being specific to each instance.
 

holatuwol

Developer
I believe it's because the same interpreter is reused for chatbot scripts. That used to be okay since incoming chat message processing was single-threaded, but that assumption changed when we started passing in events as well, since those can also come in whenever you send a chat command to the server (as well as any events that are caught outside of chat).

We should probably queue chatbot message handling and have a dedicated thread handle it to allow us to reuse the chatbot interpreter.
 
Top