Author Topic: Gamestat.txt Parser  (Read 1815 times)

0 Members and 2 Guests are viewing this topic.

Offline jrgp

  • Administrator
  • Flamebow Warrior
  • *****
  • Posts: 5037
Gamestat.txt Parser
« on: September 28, 2007, 04:31:59 pm »
I just made a php function that parses the gamestat.txt that the dedicated server generates. The function returns an array of info.

Here is the source and example usage:
http://soldat.jrgp.org/current_stats/function.phps

Here is a live demo:
http://soldat.jrgp.org/current_stats/function.php

feel free to use it for anything. credit me somewhere if you do, please.
There are other worlds than these

Offline mar77a

  • Global Moderator
  • Veteran
  • *****
  • Posts: 1295
  • mad
    • random stuffs
Re: Gamestat.txt Parser
« Reply #1 on: September 28, 2007, 07:48:48 pm »
What about team scores? Another thing, using file() is better than explode to get each line. And the whole unsetting thing is quite useless, it's not 'a lot of ram' plus it'll be free'd automatically when the function ends.

Other than that, good job. Maybe try a Gamestat class for an OOP approach.

Offline FliesLikeABrick

  • Administrator
  • Flamebow Warrior
  • *****
  • Posts: 6144
    • Ultimate 13 Soldat
Re: Gamestat.txt Parser
« Reply #2 on: September 28, 2007, 11:24:58 pm »
Yeah, generally when I write chunks of code that I intend to release (like my PHP ASE parser), I try to make it return an object so that it can be used in a more human-readable and prettier fashion

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: Gamestat.txt Parser
« Reply #3 on: September 29, 2007, 01:44:56 am »
Well, an object may be prettier usually, but in PHP I usually feel more confortable with arrays (maps actually). If I had a PHP editor which had an auto member listing, then it would be another story, but as I don't know about such editor I feel more confortable with arrays... cause I can do things like print "lalal $array[keystring]"; instead of print "lalal {$object->member}".

Anyway, as mar77a said, it's not really a lot of ram, but it's good that you care about clearing up useless stuff.
urraka

Offline jrgp

  • Administrator
  • Flamebow Warrior
  • *****
  • Posts: 5037
Re: Gamestat.txt Parser
« Reply #4 on: September 30, 2007, 08:43:46 pm »
I've made a lot of changes to the function. I will keep the idea of the object oriented method of doing it in mind.

Thanks for the tips, everyone.

Also, here is the script viewing current stats for my self hosted, kinda popular server.
http://soldat.jrgp.org/soldat_servers.php
« Last Edit: September 30, 2007, 08:49:53 pm by jrgp »
There are other worlds than these