1
talunceford
BF2 Server Status Module...

Well I have been busy working on a new module that will allow bf2 fans to query thier favorite server to see who is on it, what the ping times are for each player, and hopefully be able to join to that server from the page. This script will allow you to search the database for specific servers and it will allow you to add your own server information to the database. I am still working on quite a few of the key features, but for the most part it works very well. I found the display script on another site, and integrated it into the one I was originally developing.

I am looking out for a way that I can have the database update on a regular basis, as to have it as current as possible. Does anyone know of a way, or has anyone come across a way or site that does this? Because right now the only hard variables it needs are the server name, the ip address of the server and the server port, which is usually 29900. I need a script that can parse a list and insert it into the db. Anyway, you can view it here. www.bf2online.com/modules/bf2query

It is far from done, but I think it will make a pretty good addition to a bf2 fan site.
Tim
www.tswn.com | www.bf2online.com | aquaria.tswn.com | www.bf2142online.org

2
kylgarmor
Re: BF2 Server Status Module...
  • 2005/8/13 6:42

  • kylgarmor

  • Just popping in

  • Posts: 4

  • Since: 2005/8/13


dude! I have been wanting a module that does this :)

Any chance of getting ahold of your work in progress?

Cheers!

3
Windrider
Re: BF2 Server Status Module...
  • 2005/8/14 10:46

  • Windrider

  • Just popping in

  • Posts: 4

  • Since: 2005/2/15


Good thinking m8!
Fix that TS script also! Thx for all the good work!

And tell me to Beta test!

Cheers,
Windy

4
talunceford
Re: BF2 Server Status Module...

Heya fellas!

I am currently still developing the script. I am doing most of the coding in Dreamweaver, and haven't cleaned up the code to work with XOOPS yet. I am still adding features to it, and there is one feature that I have yet to find code for, thanks to Gamespy being the jerks that they are. I am still looking for code that will return the entire list of Gamespy servers to me in an array. Err.... at least a script that works. I have some code, but it gives me a white screen when I run it. Mithy, could you possibly take a look at this code for me and tell me what the !@#$ is wrong with it?

Thanks guys, and keep checking this post for updates.

here is a screenshot, with an explanation of some of the newer features.

Resized Image
Tim
www.tswn.com | www.bf2online.com | aquaria.tswn.com | www.bf2142online.org

5
Windrider
Re: BF2 Server Status Module...
  • 2005/8/14 14:12

  • Windrider

  • Just popping in

  • Posts: 4

  • Since: 2005/2/15


We in =tGA= use this site:
http://www.game-monitor.com/search.php?player=%3Dtga%3D&game=bf2&country=
(url is with search for =tGA=)

Works not 100.. now two players are online but dosn't show.. but maybe it helps.

/Windy

6
talunceford
Re: BF2 Server Status Module...

Here is the gamespy class


<?php
/*
    gamespy.php v1.1

    Copyright    : 2004-2005 by FiRe^ <fire_1@gmx.de>
    Created      : 2004-11-04
    Last edit    : 2005-05-13
    License      : GPL (http://www.gnu.org/licenses/gpl.txt)
    Requirements : PHP4 (Sockets enabled :D)
    Description  : The GameSpy-Class allows you to get the Serverlists for
                   GameSpy-supported Games. The list of all Gamenames is here:
                   http://motd.gamespy.com/software/services/index.aspx
                   You can get the Handoff by visiting the following page:
                   http://motd.gamespy.com/software/services/index.aspx?mode=full&services=GAMENAME
    To-Do        : Improve the socket code

    Example      : require("gamespy.php"); // Path to this php file
                   $GS = new GameSpy(); // Create new GameSpy-Instance
                   $Servers = $GS->GetServers("bfield1942", "XoHHptWIxA9sz3"); // Get the Serverlist for 'Battlefield 1942'
                   if(!$Servers) { // Check if an error has occurred..
                       echo "Error while retrieving the Serverlist!!!";
                   } else {
                       // Debug-Print the Serverlist:
                       print_r($Servers);
                   }
*/

class GameSpy {
    var 
$Host;
    var 
$Port;
    var 
$Sock;

    function 
GameSpy($Host "master.gamespy.com"$Port 28900) {
        
/*
            --Constructor--
            $Host: GameSpy-Master IP
            $Port: GameSpy-Master Port
        */
        
$this->Host $Host;
        
$this->Port $Port;
    }

    function 
GetServers($Gamename$Handoff$Filter "") {
        
/*
            This function will return the Serverlist for $Gamename in an Array.
            $Gamename: (http://motd.gamespy.com/software/services/index.aspx)
            $Handoff: (http://motd.gamespy.com/software/services/index.aspx?mode=full&services=$Gamename)
                      If the Handoff is >= 13 chars, it will be sized to an 6-char Handoff
            $Filter: The GS-Filter

            Example:
            Array
                (
                        [0] => Array
                        (
                            [ip] => 69.44.61.202
                            [port] => 23000
                        )
                        [1] => Array
                        (
                            [ip] => 195.140.135.250
                            [port] => 23000
                        )
                        ...
                )
        */

        // Try to connect to the GameSpy-Master:
        
$this->Sock = @fsockopen("tcp://$this->Host"$this->Port, &$errno, &$errstr2);
        @
stream_set_timeout($this->Sock2);

        if(!
$this->Sock) { // Error while connecting
            
return false// :-(
        
} else {
            
$this->Connected true;
        }

        
// Receive the Secure-Key:
        
$SecureKey substr(fgets($this->Sock256), -76);

        
// Create the Validate-Key:
        
$ValidateKey $this->__MakeValidate($SecureKey$Handoff);

        
// Send the packet
        
$Packet "\gamename\$Gamename\enctype\0\validate\$ValidateKey\final\.
                  
"\queryid\1.1\list\cmp\gamename\$Gamename\where\$Filter\final\";
        
fwrite($this->Sock$Packet);

        
// Receive the (compressed) Serverlist:
        
$Data "";
        do {
            
$Data .= fgets($this->Sock2048);
            
$Buffer socket_get_status($this->Sock);
        } while(
$Buffer["unread_bytes"] > 0);

        
fclose($this->Sock); // Close socket

        
return $this->__ParseCompressedIPs($Data); // Return the parsed Serverlist
    
}

    function 
__ParseCompressedIPs($Data) {
        
/*
            Parse the 6-Byte-IP packet and return the Serverlist-Array
            $Data: Compressed IPs received from the Server
        */

        
$UnComp = array();
        
$i 0;
        
$c 0;

        
// Remove the "final":
        
$Data str_replace("\final\"""$Data);

        while(
$i <= strlen($Data) - 6) {
            
// IP
            
$UnComp[$c]["ip"] = ord($Data{$i++}).".".ord($Data{$i++}).".".ord($Data{$i++}).".".ord($Data{$i++});
            
// Port
            
$UnComp[$c++]["port"] = (ord($Data{$i++}) * 256) + ord($Data{$i++});
        }
        
        return 
$UnComp;
    }

    function 
__MakeValidate($SecureKey$Handoff) {
        
/*
            MakeValidate creates a Validate-Key for you :D
            $SecureKey: The Secure-Key received from the GS Master
            $Handoff: See GetServers()
        */

        
$Temp = array(0000$Handoff); // Array for some temporary Variables
        
$Table = array();

        for(
$i 0$i <= 255$i++) {
            
$Table[$i] = $i// Fill the buffer
        
}

        
// Check the Handoff-Length:
        
if(strlen($Handoff) >= 13) {
            
$Handoff "";
            
// Invalid Handoff! -> Need 6-char Handoff
            
for($i 2$i <= 13$i += 2) {
                
$Handoff .= $Temp[4]{$i};
            }
        }

        
// Add the length of the Keys to the array:
        
$Length = array(strlen($Handoff), strlen($SecureKey));

        for(
$i 0$i <= 255$i++) {
            
// Scramble the Table with the Handoff:
            
$Temp[0] = ($Temp[0] + $Table[$i] + ord($Handoff{$i $Length[0]})) & 255;
            
$Temp[1] = $Table[$Temp[0]];

            
// Update the buffer:
            
$Table[$Temp[0]] = $Table[$i];
            
$Table[$i] = $Temp[1];
        }

        
$Temp[0] = 0;
        
$Key = array();

        
// Scramble the SecureKey with the Table:
        
for($i 0$i $Length[1]; $i++) {
            
// Add the next char to the Array
            
$Key[$i] = ord($SecureKey{$i});

            
$Temp[0] = ($Temp[0] + $Key[$i] + 1) & 255;
            
$Temp[1] = $Table[$Temp[0]];
            
$Temp[2] = ($Temp[2] + $Temp[1]) & 255;
            
$Temp[3] = $Table[$Temp[2]];

            
$Table[$Temp[2]] = $Temp[1];
            
$Table[$Temp[0]] = $Temp[3];

            
// XOR the Key with the Buffer:
            
$Key[$i] ^= $Table[($Temp[1] + $Temp[3]) & 255];
        }

        
$Length[1] /= 3;
        
$i 0;
        
$ValidateKey "";

        
// Create the ValidateKey:
        
while($Length[1]--) {
            
$Temp[1] = $Key[$i++];
            
$Temp[3] = $Key[$i++];

            
$ValidateKey .= $this->__AddChar($Temp[1] >> 2);
            
$ValidateKey .= $this->__AddChar((($Temp[1] & 3) << 4) | ($Temp[3] >> 4));

            
$Temp[1] = $Key[$i++];

            
$ValidateKey .= $this->__AddChar((($Temp[3] & 15) << 2) | ($Temp[1] >> 6));
            
$ValidateKey .= $this->__AddChar($Temp[1] & 63);
        }

        return 
$ValidateKey;
    }

    function 
__AddChar($Number) {
        
// Return a new char
        
if($Number 26) {
            return 
chr($Number 65);
        } elseif(
$Number 52) {
            return 
chr($Number 71);
        } elseif(
$Number 62) {
            return 
chr($Number 4);
        } elseif(
$Number == 62) {
            return 
"+";
        } elseif(
$Number == 63) {
            return 
"/";
        }
    }
}
?>



Here is the code that is supposed to display it on your site, but I cant get it to work.

<?php
include("include/gamespy.php"); // GameSpy Class

$GS = new GameSpy(); // Create new GameSpy-Instance
$Gamename "battlefield2d";
$Handoff "NqhaWF6Hms9Vao";
$Servers $GS->GetServers("$Gamename""$Handoff"""); // Get the Serverlist for 'Battlefield 1942'
if(!$Servers) { // Check if an error has occurred..
echo "Error while retrieving the Serverlist!!!";
} else {
// Print the Serverlist:
foreach($Servers as $Server) {
 echo 
$Server["ip"] .":"$Server["port"] ."<br />n";
}
}
?>




Mithy, if you have time, could you look at this and tell me what is causing it to white screen on me? I commented out the call to the function GetServers and it works. Any and all help is greatly appreciated.
Tim
www.tswn.com | www.bf2online.com | aquaria.tswn.com | www.bf2142online.org

7
Mithrandir
Re: BF2 Server Status Module...

Are there no PHP errors with PHP debug on?

try removing the @ from these lines:
$this->Sock = @fsockopen("tcp://$this->Host"$this->Port, &$errno, &$errstr2);
@
stream_set_timeout($this->Sock2);
"When you can flatten entire cities at a whim, a tendency towards quiet reflection and seeing-things-from-the-other-fellow's-point-of-view is seldom necessary."

Cusix Software

8
rowdie
Re: BF2 Server Status Module...
  • 2005/8/14 17:19

  • rowdie

  • Just can't stay away

  • Posts: 846

  • Since: 2004/7/21


Quote:

$Servers = $GS->GetServers("$Gamename", "$Handoff", ""); //


Have you tried removing the quotes around the parameters in the $GS->GetServers call?

9
talunceford
Re: BF2 Server Status Module...

Thanks guys for the quick reply. I've got a few more things to show you here.

Here is a screenshot of the admin side.

Resized Image


I will look at the code and see whats going on with the gamespy class. I will let you guys know what I find out. Thanks so much again!
Tim
www.tswn.com | www.bf2online.com | aquaria.tswn.com | www.bf2142online.org

10
kylgarmor
Re: BF2 Server Status Module...
  • 2005/8/14 23:57

  • kylgarmor

  • Just popping in

  • Posts: 4

  • Since: 2005/8/13


dude, again i will say that looks totally awesome. I especially love the fact that you've got the admin tool in place as well :)

Login

Who's Online

244 user(s) are online (180 user(s) are browsing Support Forums)


Members: 0


Guests: 244


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits