Server info on site

Post here if you need help setting up your server, etc.
Post Reply
snake
Average Program
Posts: 59
Joined: Thu Oct 13, 2011 6:24 am

Server info on site

Post by snake »

Hi,

I'm searching for a way to display the online players of a server on a site (forum). Do you know how i can do this ? (maybe there's a way to write the online players to a HTML file and embed it into the site?)

Thx,
$NAK3
User avatar
AI-team
Shutout Match Winner
Posts: 1020
Joined: Tue Jun 23, 2009 6:17 pm
Location: Germany/Munich
Contact:

Re: Server info on site

Post by AI-team »

Here's a script which happend to still be on my harddrive.
It's by one of pru's old members and should work fine after modifying the 'PATH/TO/PLAYERS.TXT'

Code: Select all

<?php

$f = file('PATH/TO/PLAYERS.TXT');

if (count($f)<2) {
    echo FontText('Cannot fetch players online. Reason given by server:', 10, 'ff0000').'<br />';
    echo '&nbsp;&nbsp;&nbsp;'.FontText('Nobody online.', 14, 'ff9999');
} else {
    $a = LinesToArray($f, $arr, true);
    $overall=0;
    $best=0;
    for ($i=0;$i<count($a);$i++) {
        $overall += $a[$i]['Score'];
        if ($best<$a[$i]['Score'])
            $best=$a[$i]['Score'];
    }

    for ($i=1;$i<count($a);$i++) {
        $pn=NoFancyChars($a[$i]['Player']);
        $properNames[$pn]=$a[$i]['Player'];

        $t=$a[$i]['Alive'];
        $a[$i]['Alive'] = (($t=='Yes')?'<span color="#00ff00">':'<span color="#ff0000">').$t.'</span>';
        $t=$a[$i]['Score'];
        $a[$i]['Score'] = Gauge($t, $overall);

        $t=$a[$i]['Member of Team'];
        $a[$i]['Member of Team'] = '<span style="color:>'.$t.'</span>';
    }
     ArrayToTable($a, array('30%','8%','24%','8%','30%'));
}




function FontText($text, $size=10, $color='ffffff') {
    return '<span style="font-size: '.$size.'pt; color: #'.$color.'">'.$text.'</span>';
}

function LinesToArray($lines, &$headers, $addheader=false) {
    $starts = array(0);
    $l = $lines[0];
    $ss = false; //space-sensitive
    for ($i=0;$i<strlen($l);$i++) {
        $ch=$l{$i};
        if ($ss && ( ($ch!=' ')&&($ch!="\n") ) ) {
            $starts[]=$i;
            $ss=false;
        }
        if ($ch==':')
            $ss=true;
    }
    $starts[]=2000;

    $r=array();
    $headers=array();
    $srow=true;
    foreach($lines as $line) {
        $lv=array();
        for ($i=0;$i<(count($starts)-1);$i++) {
        $l=trim(substr($line, $starts[$i], $starts[$i+1]-$starts[$i]));
        if ($srow) {
            $headers[]=substr($l,0,strlen($l)-1);
            if ($addheader)
                $lv[]=$l;
        }
        if (!$srow) $lv[$headers[$i]]=$l;
    }
    $r[]=$lv;
    $srow=false;
    }
    return $r;
}

function ArrayToTable($arr, $widths=false) {
    echo '<table><tbody>';
    $first=true;
    foreach ($arr as $v1) {
        //echo ($first?'<th>':'<tr>');
        echo '<tr>';
        $num=0;
        foreach ($v1 as $v2) {

            if (!$first) echo '<td>'.$v2.'</td>'; else {
                echo '<th';
                if ($widths!==false)
                    echo ' style="width:'.$widths[$num].'"';
                echo '>'.FontText($v2, 10).'</th>';

            }
            $num++;

        }

        echo "</tr>";
        $first=false;
    }
    echo '</tbody></table>';
}
?>
  
 
"95% of people believe in every quote you post on the internet" ~ Abraham Lincoln
 
 
Word
Reverse Adjust Outside Corner Grinder
Posts: 4262
Joined: Wed Jan 07, 2009 6:13 pm

Re: Server info on site

Post by Word »

yeah, kudos to .pRu|TERMITE. Any other files on your harddrive people could benefit from (apart from tactical stuff ^^) ? :)
snake
Average Program
Posts: 59
Joined: Thu Oct 13, 2011 6:24 am

Re: Server info on site

Post by snake »

ty :), but how do i start scripts on a vps with multiple servers on it? (made by the wiki), and is the path to players.txt the ourput path? and can i also change it to players.HTML ?
snake
Average Program
Posts: 59
Joined: Thu Oct 13, 2011 6:24 am

Re: Server info on site

Post by snake »

I have setup multiple servers at one ubuntu vps by this wiki: http://wiki.armagetronad.org/index.php/ ... u_Computer
i changed $f = file('/home/username/armagetronad/players.txt . I have a scripts folder with the following files: online.php srv.sh and start.sh

I use start.sh [server_name] to start a server. Now i put parser=$loc"/scripts/$1/online.php" in the srv.sh hoping it would display the online players of the server i just started in /home/username/armagetron/[server_name]/players.txt . that didn't work. Should i put the script IN srv.sh ? If yes, where in srv.sh should i put it? (on top of all text, somewhere in the middle or on bottom etc...) or does that makes no difference ?

I hope i explained it clearly :P
snake
Average Program
Posts: 59
Joined: Thu Oct 13, 2011 6:24 am

Re: Server info on site

Post by snake »

I was thinking:

Cant i just display a part of the info from the master server ? that way i dont have to **** with scripts and apache etc.
User avatar
AI-team
Shutout Match Winner
Posts: 1020
Joined: Tue Jun 23, 2009 6:17 pm
Location: Germany/Munich
Contact:

Re: Server info on site

Post by AI-team »

snake wrote:Cant i just display a part of the info from the master server ? that way i dont have to **** with scripts and apache etc.
You could indeed do that, but there are many disadvantages
  
 
"95% of people believe in every quote you post on the internet" ~ Abraham Lincoln
 
 
nelg

Re: Server info on site

Post by nelg »

Ai-Team i need to try your script... LOL
User avatar
AI-team
Shutout Match Winner
Posts: 1020
Joined: Tue Jun 23, 2009 6:17 pm
Location: Germany/Munich
Contact:

Re: Server info on site

Post by AI-team »

depending on how much you like the look/simplicity of this you might want to use the following script:

Code: Select all

<style type="text/css">
.online {
    float: left;
    padding: 15px;
}
</style>
<?php

$files = array('feed.txt' => 'servername for server1', 'feed2.txt'  => 'servername for server2', "feed3.txt" => "server 3 is much cooler");

foreach($files as $file => $servername) {
    $lines = file($file);
    array_shift($lines); // remove the first line
    
    if(!$lines) {
        echo "Couldn't read file: $file";
        break;
    }
    
    if((count($lines)) < 2){
        echo "Nobody online.";
        break;
    }
    
    echo "<div class='online'>"
        ."<b>" . $servername . "</b>";
    echo "<ol>";
    
    foreach($lines as $line) {
        // explode doesn't work here
        $line = preg_split("/\s+/", $line);
        
        $name = array();
        
        for($i=0;$i<(count($line)-6);++$i) {
            $name[] = $line[$i];
        }

        echo "<li>" . implode(" ", $name) . "<br>";

    }
    
    echo "</ol></div>";

}
?>
  
 
"95% of people believe in every quote you post on the internet" ~ Abraham Lincoln
 
 
User avatar
Tank Program
Forum & Project Admin, PhD
Posts: 6712
Joined: Thu Dec 18, 2003 7:03 pm

Re: Server info on site

Post by Tank Program »

Shouldn't the online.php script be in some folder that's accessible through a http server so that the script will run and show the players? Or have I missed something here?
Image
User avatar
AI-team
Shutout Match Winner
Posts: 1020
Joined: Tue Jun 23, 2009 6:17 pm
Location: Germany/Munich
Contact:

Re: Server info on site

Post by AI-team »

ofc it should
  
 
"95% of people believe in every quote you post on the internet" ~ Abraham Lincoln
 
 
snake
Average Program
Posts: 59
Joined: Thu Oct 13, 2011 6:24 am

Re: Server info on site

Post by snake »

yea if it works i was planning to change the path to players.txt somewhere where apache can show them. But for now it doesnt even work. But isnt it simpler to put a part of the autput from the master server on my site ? I dont rlly care if its updated every seconds or minute
Post Reply