Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Getting Players online status via PHP (https://forums.graalonline.com/forums/showthread.php?t=72131)

godofwarares 02-12-2007 12:08 AM

Getting Players online status via PHP
 
How do I do this?

I want to make my website show all the admins on the server's status online:

E.g.

Hikaru is online now!
or
Hikaru is offline.

Any particular way to do this?

Tolnaftate2004 02-12-2007 12:45 AM

You can manipulate http://www.graalonline.com/members/viewprofile.php?accname=someaccount to get the online status.

The easiest would be:
PHP Code:

$lines file("http://www.graalonline.com/members/viewprofile.php?accname=" $account); 

One of the lines will contain the online status, but this isn't the most efficient way of doing it...

There may even be a different file to manipulate, but that's how I know how to do it...

JkWhoSaysNi 02-12-2007 01:14 AM

Nah, the best way is to made graal call a PHP file through graal using requesturl

PHP Code:

function onActionPlayeronline() {
requesturl("http://location/to/php.file?online=1&account=" player.account);


Then, in the php file have it store the online players to either a text file or a database, make a new request when the player goes offline to remove the player from the list.

godofwarares 02-12-2007 01:31 AM

Anyone got an easier way to do it ... ?

Quote:

Originally Posted by Tolnaftate2004
You can manipulate http://www.graalonline.com/members/v...me=someaccount to get the online status.

The easiest would be:
PHP Code:

$lines file("http://www.graalonline.com/members/viewprofile.php?accname=" $account); 

One of the lines will contain the online status, but this isn't the most efficient way of doing it...

There may even be a different file to manipulate, but that's how I know how to do it...

That didn't work man -__-

xXziroXx 02-12-2007 01:34 AM

Quote:

Originally Posted by JkWhoSaysNi (Post 1276343)
Nah, the best way is to made graal call a PHP file through graal using requesturl

PHP Code:

function onActionPlayeronline() {
requesturl("http://location/to/php.file?online=1&account=" player.account);


Then, in the php file have it store the online players to either a text file or a database, make a new request when the player goes offline to remove the player from the list.

I would say this is the best way to do it aswell.

Tolnaftate2004 02-12-2007 01:34 AM

Quote:

Originally Posted by godofwarares (Post 1276347)
Anyone got an easier way to do it ... ?
That didn't work man -__-

It is returning an array... You'd probably have to use print_r to find which index to display... o_o

godofwarares 02-12-2007 01:56 AM

I'll be damned -- It works :o

Line 59: <td>Dual Ortus</td>

PHP Code:

<?php
$account 
"godofwarares";

$lines file("http://www.graalonline.com/members/viewprofile.php?accname=" $account);

echo 
$lines[59];
fclose($lines);
?>

Have fun kids =]

JkWhoSaysNi 02-12-2007 02:02 AM

1 Attachment(s)
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.

godofwarares 02-12-2007 02:04 AM

If you may remember, MySQL on my computer is busted =]

JkWhoSaysNi 02-12-2007 02:07 AM

Well I cannot get the member profile to show anything about me. http://www.graalonline.com/members/v...me=JkWhoSaysNi I'm on Dark Nations right now and it doesn't show it.

xXziroXx 02-12-2007 02:15 AM

Quote:

Originally Posted by Tolnaftate2004 (Post 1276336)
You can manipulate http://www.graalonline.com/members/viewprofile.php?accname=someaccount to get the online status.

The easiest would be:
PHP Code:

$lines file("http://www.graalonline.com/members/viewprofile.php?accname=" $account); 

One of the lines will contain the online status, but this isn't the most efficient way of doing it...

There may even be a different file to manipulate, but that's how I know how to do it...

Problem with this is that not everyone has enabled so people can view their online status.

godofwarares 02-12-2007 03:04 AM

Um . . .

Don't try that; It bans you if you try to retrieve the content via scripts:


HTML Code:

Searching . . .
2
Line 1: GraalOnline - Member Profiles
Your host has been temporary banned for bombing this script.
Home Page (Click here if your browser does not automatically forward you)


... Any comments? ...

godofwarares 02-14-2007 01:28 PM

My MySQL works now, but how do I import tables into it? I assume it's in the MySQL Command Prompt?


All times are GMT +2. The time now is 02:44 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.