Php Script for Ufreeze dumpstats

Locked
redonkuless
Posts: 15
Joined: Mon Jan 09, 2012 11:58 pm

Php Script for Ufreeze dumpstats

Post by redonkuless »

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: Select all

<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: Select all

<?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: Select all

<?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 />";
}

?>

WizzardOz
Posts: 2
Joined: Fri Mar 02, 2012 1:23 pm

Re: Php Script for Ufreeze dumpstats

Post by WizzardOz »

Thanx fo this piece of code.
[url=http://www.embedds.com/mobile-phone-signal-booster-for-home/]Mobile phone signal booster[/url] for your home.
what is a [url=http://www.aliencoders.org/content/how-mobile-phone-signal-booster-can-be-useful-you/]mobile phone signal booster[/url]
Locked