View Single Post
  #7  
Old 02-12-2007, 02:02 AM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
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` (
`
accountVARCHAR25 NOT NULL ,
`
nickVARCHAR256 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.
Attached Files
File Type: txt dbconnect.txt (4.0 KB, 259 views)
__________________

Coming soon (Hopefully:P)
Reply With Quote