Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-12-2007, 12:08 AM
godofwarares godofwarares is offline
Webmaster
godofwarares's Avatar
Join Date: Dec 2006
Location: Florida
Posts: 552
godofwarares is on a distinguished road
Send a message via ICQ to godofwarares Send a message via AIM to godofwarares Send a message via MSN to godofwarares Send a message via Yahoo to godofwarares
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?
__________________
What signature? I see no signature?
Reply With Quote
  #2  
Old 02-12-2007, 12:45 AM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
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...
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #3  
Old 02-12-2007, 01:14 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
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.
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #4  
Old 02-12-2007, 01:31 AM
godofwarares godofwarares is offline
Webmaster
godofwarares's Avatar
Join Date: Dec 2006
Location: Florida
Posts: 552
godofwarares is on a distinguished road
Send a message via ICQ to godofwarares Send a message via AIM to godofwarares Send a message via MSN to godofwarares Send a message via Yahoo to godofwarares
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 -__-
__________________
What signature? I see no signature?
Reply With Quote
  #5  
Old 02-12-2007, 01:34 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by JkWhoSaysNi View Post
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.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #6  
Old 02-12-2007, 01:34 AM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by godofwarares View Post
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
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #7  
Old 02-12-2007, 01:56 AM
godofwarares godofwarares is offline
Webmaster
godofwarares's Avatar
Join Date: Dec 2006
Location: Florida
Posts: 552
godofwarares is on a distinguished road
Send a message via ICQ to godofwarares Send a message via AIM to godofwarares Send a message via MSN to godofwarares Send a message via Yahoo to godofwarares
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 =]
__________________
What signature? I see no signature?

Last edited by godofwarares; 02-12-2007 at 01:58 AM.. Reason: Added code.
Reply With Quote
  #8  
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, 217 views)
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #9  
Old 02-12-2007, 02:04 AM
godofwarares godofwarares is offline
Webmaster
godofwarares's Avatar
Join Date: Dec 2006
Location: Florida
Posts: 552
godofwarares is on a distinguished road
Send a message via ICQ to godofwarares Send a message via AIM to godofwarares Send a message via MSN to godofwarares Send a message via Yahoo to godofwarares
If you may remember, MySQL on my computer is busted =]
__________________
What signature? I see no signature?
Reply With Quote
  #10  
Old 02-12-2007, 02:07 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
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.
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #11  
Old 02-12-2007, 02:15 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by Tolnaftate2004 View Post
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.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #12  
Old 02-12-2007, 03:04 AM
godofwarares godofwarares is offline
Webmaster
godofwarares's Avatar
Join Date: Dec 2006
Location: Florida
Posts: 552
godofwarares is on a distinguished road
Send a message via ICQ to godofwarares Send a message via AIM to godofwarares Send a message via MSN to godofwarares Send a message via Yahoo to godofwarares
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? ...
__________________
What signature? I see no signature?

Last edited by godofwarares; 02-12-2007 at 03:05 AM.. Reason: -_-
Reply With Quote
  #13  
Old 02-14-2007, 01:28 PM
godofwarares godofwarares is offline
Webmaster
godofwarares's Avatar
Join Date: Dec 2006
Location: Florida
Posts: 552
godofwarares is on a distinguished road
Send a message via ICQ to godofwarares Send a message via AIM to godofwarares Send a message via MSN to godofwarares Send a message via Yahoo to godofwarares
My MySQL works now, but how do I import tables into it? I assume it's in the MySQL Command Prompt?
__________________
What signature? I see no signature?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 09:58 AM.


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