Quake3World.com Forums
     Programming Discussion
        Php Script for Ufreeze dumpstats


Post new topicReply to topic
Login | Profile | | FAQ | Search | IRC




Print view Previous topic | Next topic 
Topic Starter Topic: Php Script for Ufreeze dumpstats

Gibblet
Gibblet
Joined: 09 Jan 2012
Posts: 15
PostPosted: 01-11-2012 02:59 PM           Profile Send private message  E-mail  Edit post Reply with quote


This Code is to login to rcon on a quake3 server running Hastes Ufreeze 1.1+. Ufreeze has a neat feature in the later versions that allows a command called dumpstats which dumps stats information from the server into a xml file, the results from that dump is:
Code:
<game datetime="2012.01.10 15.03.26">
  <map>q3dm4</map>
  <timelimit>20</timelimit>
  <capturelimit>15</capturelimit>
  <team name="Red">
    <score>0</score>
  </team>
  <team name="Blue">
    <score>0</score>
    <player clientnum="0">
      <name>UnnamedPlayer</name>
      <score>0</score>
      <thaws>0</thaws>
      <time>0</time>
      <timeFrozen>0</timeFrozen>
      <megahealth>0</megahealth>
      <redarmor>0</redarmor>
      <yellowarmor>0</yellowarmor>
    </player>
  </team>
</game>


This script dumps live those stats and moves them to your web directory for parsing. The parse script is pasted below the following code

invoke.php:
Code:
<?php

/*
PHP Quake 3 Library
Copyright (C) 2006-2007 Gerald Kaszuba

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

class q3query {

        private $rconpassword;
        private $fp;
        private $cmd;
        private $lastcmd;

        public function __construct($address, $port) {
                $this->cmd = str_repeat(chr(255), 4);
                $this->fp = fsockopen("udp://$address", $port, $errno, $errstr, 30);
                if (!$this->fp)
                        die("$errstr ($errno)<br />\n");
        }

        public function set_rconpassword($p) {
                $this->rconpassword = $p;
        }

        public function rcon($s) {
                sleep(1);
                $this->send('rcon '.$this->rconpassword.' '.$s);
        }

        public function get_response($timeout=5) {
                $s = '';
                $bang = time() + $timeout;
                while (!strlen($s) and time() < $bang) {
                        $s = $this->recv();
                }
                if (substr($s, 0, 4) != $this->cmd) {
                }
                return substr($s, 4);
        }

        private function send($string) {
                fwrite($this->fp, $this->cmd . $string . "\n");
        }

        private function recv() {
                return fread($this->fp, 9999);
        }

}

?>

<?php

$ip = "ChangeMe";
$pass = "ChangeMe";
$ufreezexml = "/root/.q3a/ufreeze/stats/testing.xml";
$webxml = "/var/www/site2/quake/con/testing.xml";

$q = new q3query($ip, 27960);
        $q->set_rconpassword($pass);
        $q->rcon('dumpstats testing');

        $file = file_get_contents($ufreezexml, false);
        $webfile = fopen($webxml,"w+");
                fwrite($webfile, $file);
                fclose($webfile);
                print $q->get_response();
?>



Now I'm not finished with the parse.php however it does work in the most simplest ways. I will post more when I come closer to finishing it.

parse.php:
Code:
<?php

$file = 'testing.xml';

$xmlstr = file_get_contents($file);

$xml = new SimpleXMLElement($xmlstr);

echo "map: {$xml->map}<br />";

echo "Team: {$xml->team['name']}<br />";

$redteam = $xml->team[1]->children();
echo "Team Score: {$redteam->score}<br />";



foreach($xml->team->player as $data ) {
$arr = $data->children();
echo "player name: {$arr->name}<br />";
}



$blueteam = $xml->team[1]->children();
echo "Team: {$xml->team[1]['name']}<br />";
echo "Team Score: {$blueteam->score}<br />";

foreach($xml->team[1]->player as $data ) {
$arr = $data->children();
echo "player name: {$arr->name} thaws:{$arr->thaws}<br />";
}

?>




Top
                 

Recruit
Recruit
Joined: 02 Mar 2012
Posts: 2
PostPosted: 03-02-2012 05:27 AM           Profile Send private message  E-mail  Edit post Reply with quote


Thanx fo this piece of code.



_________________
Mobile phone signal booster for your home.
what is a mobile phone signal booster


Top
                 
Quake3World.com | Forum Index | Programming Discussion


Post new topic Reply to topic


cron
Quake3World.com
© ZeniMax. Zenimax, QUAKE III ARENA, Id Software and associated trademarks are trademarks of the ZeniMax group of companies. All rights reserved.
This is an unofficial fan website without any affiliation with or endorsement by ZeniMax.
All views and opinions expressed are those of the author.