DutchTux Posted August 6, 2003 Share Posted August 6, 2003 (edited) I made this script just for fun. It makes possible to Query ESA enabled servers. You directly wonder why? It's usefull if you want give information of your own server on your homepage. I didnt got out the bug where the server name and Player not show correctly when there are less then 10 players on the server. You can test it here: http://dutchtux.decksix.com/mtaquery/query.php And the basic source is here: // Caching header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1 header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); // HTTP/1.0 // Getting information of teh form. $ServerIP = ""// Server IP here $ServerPort = "" // Server IP here $fp = fsockopen("udp://" . $ServerIP, $ServerPort + 123, $errno, $errstr); if (!$fp) { echo "$errstr ($errno) \n"; exit; } else { fputs ($fp, "s"); $c = ''; do { $c .= fread ($fp,1); $fpstatus = socket_get_status($fp); } while ($fpstatus["unread_bytes"] ); fclose ($fp); $playerquery = strchr($c,"?"); $serverquery = substr($c,0, strlen($c) - strlen($playerquery)); $players = explode ("?",$playerquery); unset($players[0]); // Remove Array number 0 because nothing is entered by explode. $serverquery = str_replace("","<=>",$serverquery); $serverquery = str_replace("","<=>",$serverquery); $serverquery = str_replace("","<=>",$serverquery); $serverquery = str_replace("","<=>",$serverquery); $serverquery = str_replace("","<=>",$serverquery); $serverquery = str_replace("","<=>",$serverquery); for($i=0;$i<(count($serverquery));$i++){ $explodedata = explode("<=>",$serverquery); } } $string = "$ServerPort"; $stringlengte = strlen($string); $server_name_ip = $ServerPort; $server_name_ip .= $explodedata[2][$stringlengte]; $server_name = str_replace("$server_name_ip","",$explodedata[2]); if (!$serverquery) { echo "Server offline"; } else { echo $server_name; // Server name echo $explodedata[3]; // Game name echo $explodedata[4]; // version echo $explodedata[6] ."/" . $explodedata[7]; // Current Players and max players // Player List $pcount = 0; foreach (array_keys($players) as $player) { $pcount++; echo $pcount; // Player number echo substr($players[$player],1,strlen($players[$player]) - 6); // Player name } } Edited August 14, 2003 by Guest Link to comment
MTA Team Blokker_1999 Posted August 6, 2003 MTA Team Share Posted August 6, 2003 once debugged it could be used on the site Link to comment
DutchTux Posted August 6, 2003 Author Share Posted August 6, 2003 Well I see I have problem with the name to...It seems the charactor changes. Dont know why yet. Link to comment
Gussi Posted August 6, 2003 Share Posted August 6, 2003 yes it's a little buggy, just think and you'll find some way to fix this Link to comment
DutchTux Posted August 9, 2003 Author Share Posted August 9, 2003 Well I love to but It seems that my windows is dead. I am now Mandrake 9.1, But I didnt install a webserver on it. I am trying to save my data and get windows back. But Anybody else can modify the code and Improve it. Just go ahead Link to comment
DutchTux Posted August 14, 2003 Author Share Posted August 14, 2003 Someone has fixed the bugs thats found in the script. I updated the basic script from above. Thank again for fixing those Mulle. You can use this code freely. If the basic script doesnt work....Just send me E-mail and you will get the source of the sample script that is on my site. Link to comment
Robpol86 Posted September 23, 2003 Share Posted September 23, 2003 <?=$simp_sw[6]?> <?=$simp_sw[6]?> is a multiplayer mod for <?=$simp_sw[7]?> for the PC. You can get it from http://www.MTAVC.com/. It's still in its developing stages but its well worth the download. I have a dedicated linux server on a 10 Mbit network.Name: <?=$servername ?> IP and Port: mta.robpol86.com:<?=$port_num ?> Users: <?=$user_count ?> Status: <?=$srvstatus ?> <?php if ($srvstatus_code == 2 || $srvstatus_code == 3) //decide to show user table or not { echo "Current players in server:"; echo "";?>Raw Data from Server: <?=$c?> <? }?> Link to comment
wildz0r Posted September 23, 2003 Share Posted September 23, 2003 Nice work guys, and on a side note, can the admins change the forum style so the code isn't orange on grey if at all possible? My eyes are gonna go bad from looking at a computer screen soon enough without having to strain them looking at low-contrast text. Link to comment
SteadVéx Posted September 23, 2003 Share Posted September 23, 2003 if the good people behind mta could work this into there offical server list page, like have alink to unoffical servers? which could list them all from the mta website, it would make mta a lot more popular, if the offical servers are full i can't be bothered to download ase, i know its free and you can keep clicking try for 7 more days but i'd still prefer to use this script if it works properly Link to comment
Guest Posted September 23, 2003 Share Posted September 23, 2003 umm... whats all that orange stuff... Link to comment
Robpol86 Posted September 23, 2003 Share Posted September 23, 2003 its called code... hard to read code wtf its like, aqua now? Link to comment
Pic0o Posted September 23, 2003 Share Posted September 23, 2003 Been hunting for this all day, Saw someone running 0.5, but no linky for Code Nice job on the Stats Tho, I hope to help out in flaw hunts Link to comment
Guest Posted September 23, 2003 Share Posted September 23, 2003 hmmm... it changed color since I was here earlier today... what the... Link to comment
Pic0o Posted September 24, 2003 Share Posted September 24, 2003 here, thnx 2 DutchTux i got a good jump start w/ my server stats, and i resumed work on it since .2 came out.to test it, go here http://www.robpol86.com/?id=mta and click on the title to toggle between servers. this bitch does MTA:VC 0.2 AND GTA3:MTA! and heres the source if ne1 cares lol, good luck understanding that! somehow i got all that bs to work! dont just change the ip and port and expect it to work, cuz it WONT! you have to modify this. this is just a "guide". and dont go asking me to do it for u! any tips on making this simpler or making it do more stuff "like get KILLS and DEATHS from server sintax and ijs will be greatly appreciated !! Is this code still affected by the base <10 Player Issue? I got the tracking working fine for a bigger then 10 player, but I only host a 5 player, and the script does not like that P.S. Here is the Best version of the stats I found, Looks to be hosted from here. Any input is apprecated for my noob coding self Link to comment
Robpol86 Posted September 26, 2003 Share Posted September 26, 2003 no, i fixed the "bug". it wont screw up if u got 0, 2, 10, 25 players. it will function correctly btw, that "best" stats that u "found" isnt live, its static. mine is live Link to comment
Guest Posted September 29, 2003 Share Posted September 29, 2003 Hi! can anyone send me the complete file(s)? or post downloadlinks or anything else?? the posted source doesn't run at my apache machine... mfg Ingo Link to comment
Robpol86 Posted September 29, 2003 Share Posted September 29, 2003 of course it wont work! only way it will work is if u change the ip and customize it to ur server, you gots to know how it works and what $c is made of. theres only 1 file i use, and its mta_servers.php, which is made up of that source. /me did not hide nething Link to comment
Pic0o Posted October 13, 2003 Share Posted October 13, 2003 Thanks for the Info Rob Take no offense to my coding nubness Link to comment
dusty Posted October 23, 2003 Share Posted October 23, 2003 <? $server['ip'] = $_GET['ip']; $server['port'] = $_GET['port']; $fp = @fsockopen("udp://" . $server['ip'], $server['port'] + 123); if(!$fp) { die("No Response"); } else { fwrite($fp,"s"); $data = fread($fp,4096); $data = preg_replace("/{5}\??|\?/","/////",$data); $data = explode("/////",$data); $raw = preg_replace("/^EYE1??(gta3)?mta\[0-9]{4}||||/","/////",$data[0]); list($null,$server['name'],$server['version'],$null,$server['current'],$server['max']) = explode("/////",$raw); $server['players'] = array_slice($data,1,-1); } print_r($server); ?> to display the players correctly you'd just chop the first character off like foreach($server['players'] as $temp) { echo substr($temp,1) . " "; } should work for gta3 and vc Link to comment
Robpol86 Posted October 24, 2003 Share Posted October 24, 2003 ? wtf? weird, i dont get "/////" EYE1mta2003Robpol86's MTA:VC v0.2 ServerMTA Vice City0.2.00515 ?Fekete? [VCT].Phuk?Ash? VC=RENAGADE?MOBAXX i chop players into their own vars: $user = explode("?", $c); 0 = dontworry,its_bs 1 = Fekete 2 = [VCT].Phuk 3 = Ash 4 = VC=RENAGADE 5 = MOBAXX then i kill those gay boxes function charfix($usr="") //fix user colors { $charset = ",,,,,,, ,,,,,›,,¤,©,¥,”,¡,¶,æ,ì,í,Ç,áçº,Ï,¬"; $charset = explode(",", $charset); $a = 26; for ($i = 0; $i <= $a; $i++) { $usr = str_replace($charset[$i], "", $usr); } return $usr; } $user[1] = charfix($user[1]); i call a function because it does more than just that, it also "fixes" names w/ colors and actually displays the right color, but im keeping that to myself. i end up outputting "Fekete" at the end. i throw this in a loop so i can list the players. Link to comment
dusty Posted October 24, 2003 Share Posted October 24, 2003 function color($name) { $colors = array("ÿÿ"=>"#FF0000"); foreach($colors as $key => $val) { $name = ereg_replace($key,"",$name); } return $name; } i don't really know the color codes so i only did the red one, but that should color names using: foreach($server['players'] as $temp) { echo substr(color($temp),1) . " "; } the substr() gets rid of the first character (those gay boxes) so i don't use another function for that.. unless they show up some place else? the final code was: <? function color($name) { $colors = array("ÿÿ"=>"#FF0000"); foreach($colors as $key => $val) { $name = ereg_replace($key,"",$name); } return $name; } $server['ip'] = $_GET['ip']; $server['port'] = $_GET['port']; $fp = @fsockopen("udp://" . $server['ip'], $server['port'] + 123); if(!$fp) { die("No Response"); } else { fwrite($fp,"s"); $data = fread($fp,4096); $data = preg_replace("/{5}\??|\?/","/////",$data); $data = explode("/////",$data); $raw = preg_replace("/^EYE1??(gta3)?mta\[0-9]{4}||||/","/////",$data[0]); list($null,$server['name'],$server['version'],$null,$server['current'],$server['max']) = explode("/////",$raw); $server['players'] = array_slice($data,1,-1); } print_r($server); foreach($server['players'] as $temp) { echo substr(color($temp),1) . " "; } ?> the output would be something like: Array ( [ip] => tyyy.org [port] => 2003 [max] => 14 [current] => 1 [version] => MTA Vice City0.2.0 [name] => dusty's mta:vc 0.2 ded server [players] => Array ( [0] => ÿÿtest ) ) test and can be called through filename.php?ip=0.0.0.0&port=0000 and the /////'s just replace some of the separators in the raw data so i can explode by 1 delimiter Link to comment
Robpol86 Posted October 24, 2003 Share Posted October 24, 2003 hmm, ur code seems a bit diff than mine, but then again i dont know all the good functions in my head. a few weeks ago i didnt even know bout strstr() or stristr()!! heres my example of fixing colors $combo[0] = "FF6633@@@3fÿÿ"; //orange$combo[1] = "FF6139@@@9aÿÿ"; //orange $a = 1; for ($i = 0; $i <= $a; $i++) { list($hex, $chars) = explode("@@@", $combo[$i]); if (stristr($usr, $chars)) { $usrcolor = explode($chars, $usr); $usr = $usrcolor[0] . "" . $usrcolor[1] . "" . $usrcolor[2]; } } i stick that in that function i made in the prv post, under the current code i do this incase sum1 has 2 colors in their nick like Robpol86 (damn winme and its non-able-to-paste-tabs) Link to comment
dusty Posted October 24, 2003 Share Posted October 24, 2003 don't be scared to use regex, they can save you alot of time :] but they seem to both work the same way, my coloring function will color multicolored names as well, just coded differently.. Link to comment
dusty Posted October 27, 2003 Share Posted October 27, 2003 <? function format_player($player) { $player = htmlentities(substr($player,1)); list($name,$score,$ping) = split("||||",$player); $colors = array("ÿÿ"=>"#FF0000"); foreach($colors as $key => $val) { $name = ereg_replace($key,"",$name); } $player = array("score"=>$score,"name"=>$name,"ping"=>$ping); return $player; } $server['ip'] = $_GET['ip']; $server['port'] = $_GET['port']; $fp = @fsockopen("udp://" . $server['ip'], $server['port'] + 123); if(!$fp) { die("No Response"); } else { fwrite($fp,"s"); $data = fread($fp,4096); $data = preg_replace("/{5}\??|\?/","/////",$data); $data = explode("/////",$data); $raw = preg_replace("/^EYE1??(gta3)?mta\" . $server['port'] . "||||/","/////",$data[0]); list($null,$server['name'],$server['version'],$null,$server['current'],$server['max']) = explode("/////",$raw); $server['players'] = array_slice($data,1); } echo ""; print_r($server); echo "\n\nActual Player Output:\n"; for($i=0;$i<$server['current'];$i++) { $temp = format_player($server['players'][$i]); print_r($temp); echo "\n"; } echo ""; ?> updated to work with 0.2.2 which now shows score/ping! Link to comment
Robpol86 Posted October 27, 2003 Share Posted October 27, 2003 yay! but i beat u!! ahaha i wont release it though... since most people use those damned logfile parsers!! DAMN YOU WARTECH Link to comment
Recommended Posts