Get stats for the website from et server php


(sidx) #1

Hello!

I’m working on a website script that will display server stats from the enemy territory game server.
Now bear with me i am a newbie at php coding and i was hoping to get some info.

This what i have:

<?php
$conne = fsockopen('udp://xxx.xxx.xxx.xxx','27960');
fwrite($conne, chr(255) . chr(255) . chr(255) . chr(255) . chr(0x02) . 'getstatus' . chr(0x00));
fread($conne, 4);
$status = socket_get_status($conne);
$data = fread($conne, $status['unread_bytes']);
fclose($conne);
echo $data; 
 ?>

and it displays server data like this(messy)

\0\sv_minguidage\0\sv_maxRate\45000\sv_minPing\0\sv_maxPing\0\sv_floodProtect\0\g_friendlyFire\0\g_maxlives\0\g_antilag\1\g_heavyWeaponRestriction\100 5106  0 "^6Aimless" 5724 0 "^4Tarnen" 4198 0 "^6WhittlinMan" 5561 0 "^7Morgriff" 4670 0 "^8Ilikechocmilk" 6047 0 "^5Halfwit" 4844 0 "^4Noammo" 4621 0 "^4Beelz" 4424 0 "^8Flint" 5561 0 "^8Narice" 4018 0 "^3Merki" 5069 0 "^1Milius" 4350 0 "^9Garbok" 4955 0 "^7Fullmonty" 4278 0 "^9Newbie" 5073 0 "^5Malin"

etc…

Now is it possible to assign variables to that code so that nicknames, xp, ping, map,… and other stuff could be displayed seperatly and so that i could edit them with html and css.

All stats that i need are echoed out but i don’t know how to assign variables to them.

i hope you can understand what i mean english is not my first language :slight_smile:

btw i used search too :slight_smile:

Thanks!


(amd3200) #2

Hi,

You should have a look at this: http://gameq.sourceforge.net/
It’s called GameQ, it’s a PHP library, it should do what you are looking for.


(schnoog) #3

You can also use the Splatterladder API:
http://et.splatterladder.com/api/squery.php?format=json&svadd[]=213.239.206.82:27960
It`s available as xml and json
http://et.splatterladder.com/api/squery.php?format=xml&svadd[]=213.239.206.82:27960


(Indloon) #4

Making a own server tracking system can be done, but yet it takes time and it’s not worth if there is a good service as Splatterladder, which provides API as posted above by schnoog.


(sidx) #5

Actually after hours of sweating i was able to pull out info with GameQ like i wanted.
Thanks for ur help!


(sidx) #6

Ok i have one more question.

i have an array

        $this->vars = array(
            // target       => source
            'players'       => array('player')
        );

        $this->player = array(
            'name'          => array('nick', 'player'),
            'score'         => array('score', 'kills', 'frags', 'skill'),
            'ping'          => array(),
        );
    }

by using

<?php print_r($info['players']). '<br>'; ?>

it’s echoing out like this:

Array
(
    [0] => Array
        (
            [frags] => 7829
            [ping] => 0
            [nick] => Thor
            [gq_name] => Thor
            [gq_score] => 7829
            [gq_ping] => 0
        )

    [1] => Array
        (
            [frags] => 9330
            [ping] => 0
            [nick] => Morgriff
            [gq_name] => Morgriff
            [gq_score] => 9330
            [gq_ping] => 0
        )

how do i make it to echo like

Nickname:Thor Score:7829 Ping:0
Nickname:Morgriff Score:9330 Ping:0
etc…


(amd3200) #7

[QUOTE=sidx;406839]Ok i have one more question.

i have an array

        $this->vars = array(
            // target       => source
            'players'       => array('player')
        );

        $this->player = array(
            'name'          => array('nick', 'player'),
            'score'         => array('score', 'kills', 'frags', 'skill'),
            'ping'          => array(),
        );
    }

by using

<?php print_r($info['players']). '<br>'; ?>

it’s echoing out like this:

Array
(
    [0] => Array
        (
            [frags] => 7829
            [ping] => 0
            [nick] => Thor
            [gq_name] => Thor
            [gq_score] => 7829
            [gq_ping] => 0
        )

    [1] => Array
        (
            [frags] => 9330
            [ping] => 0
            [nick] => Morgriff
            [gq_name] => Morgriff
            [gq_score] => 9330
            [gq_ping] => 0
        )

how do i make it to echo like

Nickname:Thor Score:7829 Ping:0
Nickname:Morgriff Score:9330 Ping:0
etc…[/QUOTE]

Use foreachon your array to iterate over it and at each loop, print what you want with echo function for example.


(sidx) #8

yes yes yes! it works! thanks for ur help!