|
B3 status.xml zelfgemaakte statusviewer
|
Geplaatst op 28-01-2012 09:46 | Gewijzigd door jensser op 28-01-2012 09:48
|

Actief

|
Posts: 109
Joined: 03.05.09
|
Ik probeer op onze website voor al onze server te zetten zoals
17/18 Players on MW2 Zombies
16/18 Players on MW2 GunGame
28/32 Players on AlterOps TDM
waarbij de 28/32 etc bepaald kan worden door de status.xml van b3.
Code<?xml version="1.0" encoding="UTF-8"?>
<B3Status Time="Sat Jan 28 10:37:01 2012">
<Game CaptureLimit="" FragLimit="" Map="mp_cracked" MapTime="290" Name="alterops" RoundTime="273" Rounds="591" TimeLimit="" Type="tdm">
<Data Name="xblive_rankedmatch" Value="0"/>
<Data Name="protocol" Value="2116"/>
<Data Name="com_maxclients" Value="32"/>
<Data Name="gameName" Value="alterops"/>
<Data Name="sv_security" Value="1"/>
<Data Name="sv_maxRate" Value="5000"/>
<Data Name="_mapTimeStart" Value="1327743131"/>
<Data Name="rounds" Value="591"/>
<Data Name="_mapName" Value="mp_cracked"/>
<Data Name="sv_disableClientConsole" Value="0"/>
<Data Name="playlist" Value="1"/>
<Data Name="console" Value="<b3.parsers.alterops.AlteropsParser object at 0x0000000002B33588>"/>
<Data Name="xblive_privatematch" Value="0"/>
<Data Name="sv_pure" Value="1"/>
<Data Name="_roundTimeStart" Value="1327743148"/>
<Data Name="sv_voice" Value="0"/>
<Data Name="sv_minPing" Value="0"/>
<Data Name="playlist_enabled" Value="0"/>
<Data Name="sv_ranked" Value="2"/>
<Data Name="xblive_wagermatch" Value="0"/>
<Data Name="sv_maxclients" Value="32"/>
<Data Name="sv_hostname" Value="^0Tarbax ^3Elite ^1Clan^7 TDM Belgium B3 XlrStats"/>
<Data Name="sv_floodprotect" Value="4"/>
<Data Name="xblive_basictraining" Value="0"/>
<Data Name="scr_team_fftype" Value="0"/>
<Data Name="playlist_entry" Value="0"/>
<Data Name="_Location" Value="BELGIUM"/>
<Data Name="gameType" Value="tdm"/>
<Data Name="shortversion" Value="7"/>
<Data Name="g_logTimeStampInSeconds" Value="0"/>
<Data Name="sv_maxPing" Value="0"/>
</Game>
<Clients Total="3">
<Client CID="1" ColorName="^1IAm^7Supreme" Connections="412" DBID="12" GUID="******" IP="188.***.30.***" Joined="Sat Jan 28 10:34:29 2012" Level="1" Name="IAmSupreme" PBID="" Score="100" State="1" Team="3" Updated="Sat Jan 28 10:34:31 2012">
<Data Name="codguid" Value="301697"/>
</Client>
<Client CID="31" ColorName="^1IAm^7Supremesuper" Connections="412" DBID="12" GUID="******" IP="188.***.30.***" Joined="Sat Jan 28 10:34:29 2012" Level="1" Name="IAmSupremesuper" PBID="" Score="100" State="1" Team="3" Updated="Sat Jan 28 10:34:31 2012">
<Data Name="codguid" Value="301697"/>
</Client>
<Client CID="28" ColorName="^1IAm^7Supremehierzo" Connections="412" DBID="12" GUID="******" IP="188.***.30.***" Joined="Sat Jan 28 10:34:29 2012" Level="1" Name="IAmSupremehierzo" PBID="" Score="100" State="1" Team="3" Updated="Sat Jan 28 10:34:31 2012">
<Data Name="codguid" Value="301697"/>
</Client>
</Clients>
</B3Status>
is het dan mogelijk dmv php ofzo om de xml te lezen en de aantal kern dat <Client .... </Client> erin voorkomt, in dit geval zou dit dan 3/32 zijn.
Kan iemand me tips of tutorial geven?
EDIT of hoe kan ik gewoon dit <Clients Total="3"> weergeven aan een php variabel ofzo?
|
| |
| |
Geplaatst op 28-01-2012 16:21 | Gewijzigd door Stijn op 28-01-2012 16:22
|

Admin
.gif)
|
Posts: 2041
Joined: 17.01.06
|
Het XML-bestand parsen als een DOM-boom is de beste oplossing.
Gewoon een DOMDocument aanmaken, je XML laden, de clients node ophalen, daarvan het attribuut total ophalen:
Voorbeeldcode (niet getest):
GeSHi: PHP$doc = new DOMDocument(); $doc->load('status.xml'); $clients = $doc->getElementsByTagName('Clients'); $aantal = $clients[0]->getAttribute('Total');
Proud Coder & Founder of Modbase
 |
| |
| |
|
Geplaatst op 29-01-2012 11:59
|

Actief

|
Posts: 109
Joined: 03.05.09
|
Ik heb dus nu deze code gebruikt,
GeSHi: PHP<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <?php $doc = new DOMDocument(); $doc->load('D:/COD/b3/28963/b3/conf/status.xml'); $clients = $doc->getElementsByTagName('Clients'); $aantal = $clients[0]->getAttribute('Total'); echo $aantal; ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> Boe <body> </body> </html>
Maar krijg wel deze error, CodeFatal error: Cannot use object of type DOMNodeList as array in C:\xampp\htdocs\bo.php on line 8
|
| |
| |
Geplaatst op 29-01-2012 12:46 | Gewijzigd door Stijn op 29-01-2012 12:53
|

Admin
.gif)
|
Posts: 2041
Joined: 17.01.06
|
Oeps, GetElementsByTagName() geeft een DOMNodeList terug. Ipv als een array te indexeren maak je dus gebruik van DOMNodeList::item(). De error is hier nogal vrij duidelijk in.
En je probeert het aantal uit te schrijven boven de head-sectie. Vrij raar ...
Proud Coder & Founder of Modbase
 |
| |
| |
Geplaatst op 29-01-2012 13:15 | Gewijzigd door jensser op 29-01-2012 13:18
|

Actief

|
Posts: 109
Joined: 03.05.09
|
Ik snap niet wat je bedoelt, ik heb met hulp van een paar andere sits dit bekomen, maar werkt nog steeds niet.
GeSHi: PHP<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <?php $doc = new DOMDocument(); $doc->load('D:/COD/b3/28963/b3/conf/status.xml'); $clients = $doc->getElementsByTagName('Clients'); $aantal = $clients->item('Total')->nodeValue; ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php echo $aantal; ?> </body> </html>
Ik weet niet veel van php af, maar wil het wel beetje leren= D
Waar moet item() ofzo precies komen?
|
| |
| |
Geplaatst op 29-01-2012 13:19 | Gewijzigd door ground zero op 29-01-2012 13:20
|

Master

|
Posts: 2442
Joined: 01.07.08
|
GetElementsByTagName() vervangen door DOMNodeList::item() zou ik afleiden uit de post van Stijn
http://php.net/ma...delist.php
http://php.net/ma...t.item.php
Toekomstige Computer & Cybre Crime Professional @ Howest, Brugge

Vrijetijdsproject - C# Web Browser
"The thing about quotes from the internet is that it's hard to verify their authenticity." - Abraham Lincoln
"The top gets higher the more that you climb" - Ezio Auditore Da Firenze |
| |
| |
Geplaatst op 29-01-2012 14:25 | Gewijzigd door Stijn op 29-01-2012 14:25
|

Admin
.gif)
|
Posts: 2041
Joined: 17.01.06
|
Item verwacht een index als parameter (klik hier eens).
Dus: $clients->item(0)->getAttribute('Total');
Proud Coder & Founder of Modbase
 |
| |
| |
|
Geplaatst op 29-01-2012 14:38
|

Actief

|
Posts: 109
Joined: 03.05.09
|
Allemaal hartelijk bedankt, het werkt nu, ik zie hoeveel man erin zit. =D
maar nog een vraagje hoe krijg ik deze string value eruit?
nl Code <Data Name="com_maxclients" Value="32"/>
? ik zou helemaal niet weten hoe ik dit zou moeten doen =D aangezien er meerdere <data name zijn.
|
| |
| |
|
Geplaatst op 29-01-2012 14:59
|

Moderator
.gif)
Donator
|
Posts: 5001
Joined: 24.08.06
|
Het is overduidelijk dat het 'data' element een unieke naam 'name' heeft, die in dit geval 'com_maxclients' is. Je hoeft geen computerexpert te zijn om dit te zien.
|
| |
| |
|
Geplaatst op 29-01-2012 15:17
|

Actief

|
Posts: 109
Joined: 03.05.09
|
Uniek?
bekijk de status nog eens
Code <Data Name="xblive_rankedmatch" Value="0"/>
<Data Name="protocol" Value="2116"/>
<Data Name="com_maxclients" Value="32"/>
<Data Name="gameName" Value="alterops"/>
<Data Name="sv_security" Value="1"/>
<Data Name="sv_maxRate" Value="5000"/>
<Data Name="_mapTimeStart" Value="1327743131"/>
<Data Name="rounds" Value="591"/>
<Data Name="_mapName" Value="mp_cracked"/>
<Data Name="sv_disableClientConsole" Value="0"/>
<Data Name="playlist" Value="1"/>
<Data Name="console" Value="<b3.parsers.alterops.AlteropsParser object at 0x0000000002B33588>"/>
<Data Name="xblive_privatematch" Value="0"/>
<Data Name="sv_pure" Value="1"/>
<Data Name="_roundTimeStart" Value="1327743148"/>
<Data Name="sv_voice" Value="0"/>
<Data Name="sv_minPing" Value="0"/>
<Data Name="playlist_enabled" Value="0"/>
<Data Name="sv_ranked" Value="2"/>
<Data Name="xblive_wagermatch" Value="0"/>
<Data Name="sv_maxclients" Value="32"/>
<Data Name="sv_hostname" Value="^0Tarbax ^3Elite ^1Clan^7 TDM Belgium B3 XlrStats"/>
<Data Name="sv_floodprotect" Value="4"/>
<Data Name="xblive_basictraining" Value="0"/>
<Data Name="scr_team_fftype" Value="0"/>
<Data Name="playlist_entry" Value="0"/>
<Data Name="_Location" Value="BELGIUM"/>
<Data Name="gameType" Value="tdm"/>
<Data Name="shortversion" Value="7"/>
<Data Name="g_logTimeStampInSeconds" Value="0"/>
<Data Name="sv_maxPing" Value="0"/>
ik denk niet dat er maar 1 data element is en maar 1 Name atribute is?
Dus hoe kan ik nu stellen dat hij de value van de com_maxclients pak?
|
| |
| |
|
Geplaatst op 29-01-2012 15:31
|

Moderator
.gif)
Donator
|
Posts: 5001
Joined: 24.08.06
|
Bekijk JIJ die 'status' nog eens Zie jij 2 elementen over com_maxclients?
Dus, je zal a.d.h.v. die parameter aan de juiste waarde moeten komen.
|
| |
| |
|
Geplaatst op 29-01-2012 16:13
|

Actief

|
Posts: 109
Joined: 03.05.09
|
Dit is nl mijn vraag, hoe kan ik die code laten zeggen dat hij de value van de data pakt met name com_maxclients, ik zou hem eerst moeten zeggen welke value hij meot pakken van alle <data maar weet niet hoe.
|
| |
| |
|
Geplaatst op 29-01-2012 16:17
|

Moderator
.gif)
Donator
|
Posts: 5001
Joined: 24.08.06
|
2 seconden op google
http://stackoverflow.com/questions/4758685/how-to-get-specific-xml-element-parameter-value
|
| |
| |
|
Geplaatst op 29-01-2012 17:58
|

Admin
.gif)
|
Posts: 2041
Joined: 17.01.06
|
Nu voel ik een nieuwe vraag aankomen, want dat is in Java 
Proud Coder & Founder of Modbase
 |
| |
| |
Geplaatst op 29-01-2012 20:35 | Gewijzigd door jensser op 29-01-2012 20:37
|

Actief

|
Posts: 109
Joined: 03.05.09
|
Met die link waarbij iemand dezelfde vraag als mij stelde, een paar antwoorden waar ik nog minder van snap dan de vraag zelf lol
Is dit niet gewoon mogelijk met php? Daar snap ik nl een heel klein beetje vn.
EDIT dit is nu mijn code,
GeSHi: PHP<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <?php //------------------------------------------------------------------------------- $ao28963 = new DOMDocument(); $ao28963->load('D:/COD/b3/28963/b3/conf/status.xml'); $ao28963_clients = $ao28963->getElementsByTagName('Clients'); $ao28963_total = $ao28963_clients->item(0)->getAttribute('Total'); $ao28963_map = $ao28963->getElementsByTagName('Game'); $ao28963_mapname = $ao28963_map->item(0)->getAttribute('Map'); //------------------------------------------------------------------------------- //------------------------------------------------------------------------------- $mw28961 = new DOMDocument(); $mw28961->load('D:/COD/b3/28961/b3/conf/status.xml'); $mw28961_clients = $mw28961->getElementsByTagName('Clients'); $mw28961_total = $mw28961_clients->item(0)->getAttribute('Total'); $mw28961_map = $mw28961->getElementsByTagName('Game'); $mw28961_mapname = $mw28961_map->item(0)->getAttribute('Map'); //------------------------------------------------------------------------------- $mw28962 = new DOMDocument(); $mw28962->load('D:/COD/b3/28962/b3/conf/status.xml'); $mw28962_clients = $mw28962->getElementsByTagName('Clients'); $mw28962_total = $mw28962_clients->item(0)->getAttribute('Total'); $mw28962_map = $mw28962->getElementsByTagName('Game'); $mw28962_mapname = $mw28962_map->item(0)->getAttribute('Map'); //------------------------------------------------------------------------------- ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php echo $ao28963_total; echo ' Alterops Players'; echo '<br>'; echo 'Map: '; echo $ao28963_mapname; ?> <br /> <img src="map_images/bo/<? echo $ao28963_mapname; ?>.jpg" alt="<? echo $ao28963_mapname; ?> Map Image Not Found"/> <br /> <br /> <? echo '<br>'; echo $mw28961_total; echo ' GunGame Players'; echo '<br>'; echo 'Map: '; echo $mw28961_mapname; ?> <br /> <img src="map_images/mw2/<? echo $mw28961_mapname; ?>.jpg" alt="<? echo $mw28961_mapname; ?> Map Image Not Found"/> <br /> <br /> <? echo $mw28962_total; echo ' Zombie Players'; echo '<br>'; echo 'Map: '; echo $mw28962_mapname; ?> <br /> <img src="map_images/mw2/<? echo $mw28962_mapname; ?>.jpg" alt="<? echo $mw28962_mapname; ?> Map Image Not Found"/> <br /> <br /> <? //<img src="url" alt="some_text"/> ?> </body> </html>
|
| |