
|
|||||||
| Go to: | FIFA Series | | | Battlefield Series | | | C&C | | | Need for Speed Series | | | The Sims Series | | |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Rookie
Join Date: Aug 2008
Posts: 231
|
I'm looking for a PHP script or something to provide BC2 server status on my website. Is there one available? My google search came up with nothing, but maybe there's a better way or wording it than "Bad Company 2 Server status".
|
|
|
|
|
|
#2 (permalink) |
|
Rookie
Join Date: Jan 2010
Location: PA, US of A
Age: 40
Posts: 21
|
www.gametracker.com
They added support for BC2 although the game doesn't currently support player scanning so you can't actually see who is playing on the server yet. http://forums.gametracker.com/showthread.php?t=13949 |
|
|
|
|
|
#5 (permalink) |
|
Rookie
Join Date: May 2009
Posts: 21
|
I ported the python functions for querying the rcon protocol to php.
See line 106-116 for how to get playerlists if you have an rcon account Code:
<?php
//
// This code is a port of the functions from http://static.cdn.ea.com/dice/u/f/bfbc2/Static/BFBC2_PC_Server_R3_519901_RemoteAdministration.zip
//
$ip = '';
$query_port = 48888; // rcon query port
$clientSequenceNr = 0;
function EncodeClientRequest($words)
{
global $clientSequenceNr;
$packet = EncodePacket(False, False, $clientSequenceNr, $words);
$clientSequenceNr++;
return $packet;
}
function EncodeHeader($isFromServer, $isResponse, $sequence)
{
$header = $sequence & 0x3fffffff;
if ($isFromServer)
$header += 0x80000000;
if ($isResponse)
$header += 0x40000000;
// Not tested this bit
return pack('I', $header);
}
function DecodeHeader($data)
{
$header = unpack('I', $data);
return array($header & 0x80000000, $header & 0x40000000, $header & 0x3fffffff);
}
function EncodeInt32($size)
{
return pack('I', $size);
}
function DecodeInt32($data)
{
$decode = unpack('I', $data);
return $decode[1];
}
function EncodeWords($words)
{
$size = 0;
$encodedWords = '';
foreach ($words as $word)
{
$strWord = $word;
$encodedWords .= EncodeInt32(strlen($strWord));
$encodedWords .= $strWord;
$encodedWords .= "\x00";
$size += strlen($strWord) + 5;
}
return array($size, $encodedWords);
}
function DecodeWords($size, $data)
{
$numWords = DecodeInt32($data);
$offset = 0;
while ($offset < $size)
{
$wordLen = DecodeInt32(substr($data,$offset,4));
$word = substr($data,$offset+4,$wordLen);
$words[] = $word;
$offset += $wordLen + 5;
}
return $words;
}
function EncodePacket($isFromServer, $isResponse, $sequence, $words)
{
$words = explode(' ',$words);
$encodedHeader = EncodeHeader($isFromServer, $isResponse, $sequence);
$encodedNumWords = EncodeInt32(count($words));
list($wordsSize, $encodedWords) = EncodeWords($words);
$encodedSize = EncodeInt32($wordsSize + 12);
return $encodedHeader . $encodedSize . $encodedNumWords . $encodedWords;
}
function DecodePacket($data)
{
list($isFromServer, $isResponse, $sequence) = DecodeHeader($data);
$wordsSize = DecodeInt32(substr($data,4,4)) - 12;
$words = DecodeWords($wordsSize, substr($data,12));
return array($isFromServer, $isResponse, $sequence, $words);
}
$sock = fsockopen( "tcp://" . $ip, $query_port);
if($sock != false)
{
socket_set_timeout($sock, 0, 500000);
fwrite($sock,EncodeClientRequest("serverInfo")); // OK, serverName, current playercount, max playercount , gamemode, map
list($isFromServer, $isResponse, $sequence, $words) = DecodePacket(fread($sock, 4096));
print_r($words);
/*
// If its your server you could add
//
// fwrite($sock,EncodeClientRequest("login.plainText PASSWORD"));
// list($isFromServer, $isResponse, $sequence, $words) = DecodePacket(fread($sock, 4096));
//
// fwrite($sock,EncodeClientRequest("admin.listPlayers all));
// list($isFromServer, $isResponse, $sequence, $words) = DecodePacket(fread($sock, 4096)); // clantag, player name, squadID, teamID
//
// Then $words contains an array of players on the server (I havn't tested this as I don't have a server to test on)
*/
fwrite($sock,EncodeClientRequest("quit"));
list($isFromServer, $isResponse, $sequence, $words) = DecodePacket(fread($sock, 4096));
fclose($sock);
}
?>
Last edited by XxMASTERUKxX; 07-04-2010 at 10:44 PM. Reason: CyboPat's fix for playerlist |
|
|
|
|
|
#8 (permalink) | |
|
Rookie
Join Date: Mar 2010
Posts: 15
|
Quote:
great work1. fwrite($sock,EncodeClientRequest("admin.listPlayer s")); ...here is little bug, missing char " 2. fwrite($sock,EncodeClientRequest("admin.listPlayer s all")); ...and if you want get list of players, you need put subparameter: all/team/squad Last edited by CyboPat; 07-03-2010 at 01:55 AM. |
|
|
|
|
|
|
#10 (permalink) | |
|
Rookie
Join Date: Aug 2008
Posts: 231
|
I discovered this a couple of days ago but forgot to post it.
It does work too, but it dumps it in an array which is awkward to manage. I used a for loop. I've only just started using PHP, so I'm sure there's a better way of doing this. Quote:
Also, bare in mind that the above code was made for testing, it's not exactly what I will use. for example, only one echo is needed. It just helps me find where errors are. |
|
|
|
|
|
|
#11 (permalink) |
|
Rookie
Join Date: May 2009
Posts: 21
|
Play around with this,
Code:
$players = array_chunk($words, 4);
foreach ($players as $p)
{
$teams[$p[3]][$p[2]][] = $p[0].$p[1];
}
print_r($teams);
Mike Last edited by XxMASTERUKxX; 07-03-2010 at 01:31 AM. |
|
|
|
|
|
#13 (permalink) |
|
Rookie
Join Date: Mar 2010
Posts: 15
|
work in progress...
http://www.eas-clan.cz/?p=server-info&server=1 Last edited by CyboPat; 23-03-2010 at 09:09 AM. Reason: change url |
|
|
|
|
|
#14 (permalink) |
|
Rookie
Join Date: Aug 2008
Posts: 231
|
Nice work by everyone imo.
I'd ask for your code CyboPat, but I want to get it done myself as a way to learn PHP a little more xD Thanks for that better way of doing it Mike, I'll have a play with that, just need to get the server populated now. |
|
|
|
|
|
#15 (permalink) |
|
Rookie
Join Date: Jan 2010
Posts: 80
|
Play with this for a nice table. I do however get a squad of 24 come up with some people... :S
Code:
echo ' <table>' . "\n";
echo ' <thead class="left"><tr><th>Name</th><th>Team</th><th>Squad</th></tr></thead>' . "\n";
echo ' <tbody class="left">' . "\n";
$elements = count($players)-1;
for($i=0;$i<$elements;$i=$i+4)
{
echo ' <tr>';
echo '<td>' . $players[1+$i] . ' ' . $players[2+$i] . '</td>';
echo '<td>' . $players[4+$i] . '</td>';
echo '<td>' . $players[3+$i] . '</td>';
echo '</tr>' . "\n";
}
echo ' </tbody>' . "\n";
echo ' </table>' . "\n";
Last edited by SavageCore; 10-03-2010 at 01:54 PM. |
|
|
|
|
|
#18 (permalink) | |
|
Rookie
Join Date: Aug 2008
Posts: 231
|
Quote:
Got mine working nicely but the squad names are jumbled. I have a few ideas how to fix it. Server Status |
|
|
|
|
|
|
#19 (permalink) |
|
Rookie
|
can someone be nice and post some completed code? I can tinker with php but this is a bit beyond me. all im getting is:
http://www.knightsofkarbala.com/bc2serverscript.php |
|
|
|
|
|
#21 (permalink) |
|
Rookie
Join Date: Mar 2010
Posts: 10
|
here is the full working code i made, already colored and styled for you, i tried to make it kinda look bc2 style :P
in the script.. find 'yourip' 'yourport' and 'yourpass' and replace it with the proper info sorry its a bit scattered in the script lol.if you want to see an example just visit our website FreeFrag.com Free Frag Network BFBC2 BC2 TF2 Bad Company 2 Team Fortress 2 Community FFN or look at this picture ![]() ![]() PHP Code:
|
|
|
|
|
|
#22 (permalink) |
|
Rookie
Join Date: Mar 2010
Posts: 15
|
DOWNLOAD: http://www.cybopat.net/bc2/bc2_server_infoview.zip
ENJOY! ![]() example: EAS - Elite Assault Shooters |
|
|
|
|
|
#24 (permalink) |
|
Forum Guru
Join Date: Mar 2010
Posts: 1,765
|
Changed what was needed but when I try and connect I get this:
Warning: fsockopen() [function.fsockopen]: unable to connect to tcp://68.232.181.105:48888 (Connection refused) Any clue? |
|
|
|
|
|
#25 (permalink) | |
|
Rookie
Join Date: Mar 2010
Posts: 76
|
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
|
|