Because I'm nice and I was gonna make this for my playerworld eventually anyway:
In Control-NPC:
PHP Code:
function onActionPlayerOnline() {
requesturl("http://www.example.org/online.php?action=online&account=" @ player.account @ "&nick=" @ player.nick);
}
function onPlayerLogout(pl) {
requesturl("http://www.example.org/online.php?action=offline&account=" @ pl.account);
}
Import this table to MySQL:
PHP Code:
CREATE TABLE `playersonline` (
`account` VARCHAR( 25 ) NOT NULL ,
`nick` VARCHAR( 256 ) NOT NULL ,
PRIMARY KEY ( `account` )
) TYPE = MYISAM;
online.php:
PHP Code:
<?
include('dbconnect.php');
$db = new MySQLidb('localhost','username','password','databasename');
if (isset($_GET['action'])) {
if ($_SERVER['REMOTE_ADDR'] == '194.5.30.2' && $_SERVER['HTTP_USER_AGENT'] == 'Graal-NPCServer') {
if ($_GET['action'] == 'online') {
$db->query('INSERT INTO playersonline (account,nick) VALUES (?,?)',array($_GET['account'],$_GET['nick']));
}
else if ($_GET['action'] == 'offline') {
$db->query('DELETE FROM playersonline WHERE account = ?',array($_GET['account']));
}
}
else {
die ('Invalid request');
}
}
else {
$db->query('SELECT account,nick FROM playersonline');
while($row = $db->fetch_object()) {
echo $row->account . ' ' . $row->nick . "\n";
}
}
?>
Download dbconnect.txt (attatched), save it as dbconnect.php in the same place as online.php this a DBA I created which supports MySQLi and MySQL i have another version of this which supports Oracle and Matisse if you need it.
Change MySQLidb to MySQLdb in the script to switch. MySQLi should be slightly faster though if you're using php4 you'll need to use the MySQL class.
In the script you'll need to find your server IP and replace 194.5.30.2 with it, this is to stop people abusing the script.