AUX scripts

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.
Post Reply
Aeros
Journeyman Poster
Posts: 69
Joined: Mon Apr 24, 2006 10:56 am

AUX scripts

Post by Aeros »

Hi guys,

If there's anyone who's familiar with Aux scripts, and wants to post a small explanation of how they work.. it'd be very handy to the rest of us :)

Anyone?
User avatar
tekproxy
Forum Regular
Posts: 352
Joined: Thu Apr 06, 2006 5:11 pm

Post by tekproxy »

It's all explained in the documentation. What exactly do you want to know?

Define an auxsvc.cfg in the package.

Code: Select all

AuxService
{
    Port (intger port)
    Script (string script filename)
}
Then you write a control script (defined by Script in auxsvc.cfg)

Code: Select all

use uo;
use os;

program auxControl(connection)
	var ev;
	print("AuxControl->connection established");
	while ( connection )
		ev := wait_for_event(5);
		print("AuxControl->recieved: "+ev.value);
		if ( ev )
			print ev.value;
		endif
	endwhile
	print("AuxControl->connection terminated");
endprogram
Again, all of this stuff is in the documentation.

You can do all sorts of neat things with these. The only thing neat I have laying around that I can think of is account authentication. If you think that would be neat I could upload it to the forums.
Aeros
Journeyman Poster
Posts: 69
Joined: Mon Apr 24, 2006 10:56 am

Post by Aeros »

Thanks texproxy,

What I would like to know, and what I could not find in the documentation, is:

1. How do you "call" the aux script from an external webpage?

2. How do you send data back to the webpage, and in what format?
User avatar
tekproxy
Forum Regular
Posts: 352
Joined: Thu Apr 06, 2006 5:11 pm

Post by tekproxy »

By webpage I'm going to assume you mean PHP. In PHP you'd make a connection like you would to any other server. This is how I do it. Mind you it's been a while since I've used PHP and I just threw this together from some other code I had.

Code: Select all

<?
$polServer = "tribulation.sytes.net";
$polAuxPort = 5012;

$fp = fSockOpen($polServer, $polAuxPort);

if ( $fp ) {
	// sHello = string "Hello", i10 = integer 10, like any other "packed" data
	// very important to have \r\n or POL will not know when the string is terminated
	fwrite($fp, "sHello\r\n"); 
	stream_set_timeout($fp, 2);
	$status = socket_get_status($fp);

	$data = "";
	while ( !feof($fp) && !$status['timed_out'] ) {
		$data .= fgets($fp, 1000);

		// Data is finished if last char is return
		if ( ord(substr($data, strlen($data) - 1, 1) == chr(10)) )
			break;
		else
			$status = socket_get_status($fp);
	}
}

if ( $data )
	echo "Recieved response: " . $data;
else
	echo "No data returned from server. Prepare for crying.";
?>
In your auxControl.src you would check to see if the ev.value == "Hello" and if so, send a response.

How to send data from the auxscript is in the documentation.

Code: Select all

connection.transmit(stuff);
When data is sent TO or FROM the server it must be "packed". It's quite simple and if you're too lazy you can just poke around for MuadDib's PHP packer. What you could do is just send different types of data and see how POL sends it.
Aeros
Journeyman Poster
Posts: 69
Joined: Mon Apr 24, 2006 10:56 am

Post by Aeros »

Thanks tekproxy, that was very helpful.

One thing, though - when the server is down or off, the PHP page gives this response:

Code: Select all

CGI Timeout
The specified CGI application exceeded the allowed time for processing. The server has deleted the process.
Is there any way to avoid this?

EDIT: Nevermind, I forgot about the fsock timeout setting. Sorry about that :P

:?
Aeros
Journeyman Poster
Posts: 69
Joined: Mon Apr 24, 2006 10:56 am

Post by Aeros »

I do have a question that I can't find an answer to though - due to my lack of knowledge of PHP. If the server is down/off, and the connection therefore times out, it gives this report in the PHP page:

Code: Select all

Warning: fsockopen(): unable to connect to ***.**.*.***:5003 in d:\inetpub\chyrellos\auxtest.php on line 8
As I want to use this for a server status script, I can't have error messages in my page. Any ideas?
Zacharias
New User
Posts: 16
Joined: Wed Mar 08, 2006 7:30 am

Post by Zacharias »

Code: Select all

if (($connect = @fsockopen("127.0.0.1", 2020, $errno, $errstr, 2)) === FALSE) {
// the server is offline. 
} else {

fputs($connect, $packet."\n");
$data = fgets($connect);
fclose($connect);

// the server is online. Information is stored in $data
}
You should look into the status-packet of PHPNuke. It's very usefull:
http://forums.polserver.com/viewtopic.p ... ht=phpnuke
Aeros
Journeyman Poster
Posts: 69
Joined: Mon Apr 24, 2006 10:56 am

Post by Aeros »

Zacharias, thanks a mil.
Post Reply