NS2 Server Query Request

scottyscotty Join Date: 2011-07-01 Member: 107400Members
edited December 2011 in NS2 General Discussion
Greetings,

Would anyone happen to know how to send query requests to NS2 servers?

Need this to display server information on a website, such as; current players online, current map.

Cheers,

Scott.C

Comments

  • playerplayer Join Date: 2010-09-12 Member: 73982Members
    I think you're looking for <a href="http://sourceforge.net/projects/qstat/" target="_blank">QStat</a>.
  • scottyscotty Join Date: 2011-07-01 Member: 107400Members
    Greetings Player,

    I'm looking for something php compatible.

    I've discovered this: <a href="https://developer.valvesoftware.com/wiki/Server_Queries" target="_blank">https://developer.valvesoftware.com/wiki/Server_Queries</a>

    Though this does not actually work for ns2 servers. Unless i'm using the wrong port.

    Cheers,

    -Scott.C
  • basti1337basti1337 Join Date: 2011-05-13 Member: 98538Members
    Have a look at this library

    <a href="https://github.com/koraktor/steam-condenser" target="_blank">https://github.com/koraktor/steam-condenser</a>
  • playerplayer Join Date: 2010-09-12 Member: 73982Members
    edited December 2011
    NS2 uses the Source-protocol, so if you a PHP-script that can query CS:S\HL2:DM\L4D\TF2\et cetera, it can also query NS2-servers.

    Oh and you need to query 1 port above the connect-port (instead of the connect-port directly as with Source-games). This is usually 27016 (27015 + 1).
  • scottyscotty Join Date: 2011-07-01 Member: 107400Members
    edited December 2011
    Greetings,

    Having some trouble with this, i can't seem to connect to other servers either, such as CS:S.

    <a href="http://www.game-monitor.com/cstrike2_GameServer/64.94.238.36:27015/TGTrue_Grit_Monster_Server_No_AWPAuto.html" target="_blank">Server to Connect</a>

    Have been trying to connect to this server with IP: 64.94.238.36 and Port: 27016.

    I'm also using this <a href="https://github.com/xPaw/PHP-Source-Query-Class" target="_blank">Library</a>.

    Sorry if this might seem off-topic, though it's for the NS2 community -secret- .

    I did manage to take a look at the library you mentioned basti, though from what i can gather. The one you mentioned is very similar to the one i'm currently using. Though that library has more server connections, when i only need source.

    Cheers,

    -Scott.C
  • playerplayer Join Date: 2010-09-12 Member: 73982Members
    That CS:S-server runs on port 27015, so that's the port you need to query.
  • basti1337basti1337 Join Date: 2011-05-13 Member: 98538Members
    I don't know the library you're using, but the server you want to query does not respond. So I don't know if there is a problem with the server, the library you are using or your script...
    I've created an example for you with the steam-condenser library in PHP:

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php
    error_reporting( E_ALL & ~E_USER_NOTICE );

    require "./steam-condenser.php";

    try {
        // HBZ Server
        $conn = new SourceServer( "95.156.232.240", 27016 );

        $ping        = $conn->getPing();
        $serverinfo    = $conn->getServerInfo();
        $players    = $conn->getPlayers();

        var_dump( "Ping", $ping, "Serverinfo", $serverinfo, "Players", $players );

    } catch ( SteamCondenserException $e ) {
        var_dump( "Exception", $e );
    }

    ?><!--c2--></div><!--ec2-->
  • scottyscotty Join Date: 2011-07-01 Member: 107400Members
    edited December 2011
    Greetings Player,

    I've already tried 27015, though when you mentioned (IP + 1) I assumed it was for all servers.


    This is what i'm doing.

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php


    require 'SourceQuery.class.php';

    $Query = new SourceQuery( );

    try
    {
    $Query->Connect( '64.94.238.36', 27015 );


    print_r("Info:".$Query->GetInfo( ) );
    print_r( $Query->GetPlayers( ) );
    print_r( $Query->GetRules( ) );

    $Query->Disconnect( );
    }
    catch( SQueryException $e )
    {
    $Query->Disconnect( );

    echo "Error: " . $e->getMessage( );
    }

    ?><!--c2--></div><!--ec2-->


    Cheers,

    -Scott.C
  • scottyscotty Join Date: 2011-07-01 Member: 107400Members
    <!--quoteo(post=1888651:date=Dec 5 2011, 08:35 PM:name=basti1337)--><div class='quotetop'>QUOTE (basti1337 @ Dec 5 2011, 08:35 PM) <a href="index.php?act=findpost&pid=1888651"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->I don't know the library you're using, but the server you want to query does not respond. So I don't know if there is a problem with the server, the library you are using or your script...
    I've created an example for you with the steam-condenser library in PHP:

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php
    error_reporting( E_ALL & ~E_USER_NOTICE );

    require "./steam-condenser.php";

    try {
        // HBZ Server
        $conn = new SourceServer( "95.156.232.240", 27016 );

        $ping        = $conn->getPing();
        $serverinfo    = $conn->getServerInfo();
        $players    = $conn->getPlayers();

        var_dump( "Ping", $ping, "Serverinfo", $serverinfo, "Players", $players );

    } catch ( SteamCondenserException $e ) {
        var_dump( "Exception", $e );
    }

    ?><!--c2--></div><!--ec2--><!--QuoteEnd--></div><!--QuoteEEnd-->

    Will give this a go and let you know how it turns out.

    Cheers,

    -Scott.C
  • playerplayer Join Date: 2010-09-12 Member: 73982Members
    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->64.94.238.36:27015 [TG]True Grit Monster Server [No AWP/Auto]<!--c2--></div><!--ec2-->

    Appears to work properly, but it does respond with quite a latency (about 2 seconds worth), so that may screw up your script a bit. You can try that NS2-server basti1337 mentioned (95.156.232.240:27016), it should respond immidiately.

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->95.156.232.240:27016 Heidis Ziegenfarm 1 (HBZ)<!--c2--></div><!--ec2-->
  • scottyscotty Join Date: 2011-07-01 Member: 107400Members
    <!--quoteo--><div class='quotetop'>QUOTE </div><div class='quotemain'><!--quotec-->Helpdesk
    Problem using fsockopen function

    Why am I unable to use the fsockopen function?

    The fsockopen function will work for outbound connection to any URL on port 80 (HTTP) or 443 (HTTPS). If fsockopen is attempting to use another port, it will not work until we have added that port to the firewall.

    By default, your account is on a shared IP address. We have a firewall for our shared IP customers which prohibits opening additional ports. If you need to connect using a port number other than 80 or 443, this will require you Purchase a Dedicated IP for your Bluehost account.

    Dedicated IPs cost $2.50 per month, the equivalent of $30 per year (prorated to the remaining hosting term). You may purchase a Dedicated IP address from within your cPanel by clicking on the Dedicated IP tab at the top of the page.

    Once you have a dedicated IP, you will need to contact us via Phone, Live Chat or by Opening a Ticket to request the specific port number is added to the firewall.

    Note: While we can can generally open any port over 1024, ports 1024 and lower are restricted and cannot be opened.<!--QuoteEnd--></div><!--QuoteEEnd-->

    Be right back, gotta make a phone call.
  • scottyscotty Join Date: 2011-07-01 Member: 107400Members
    Greetings Player & basti,

    Thanks for your help, everything is running smoothly now.

    Once i rang up my website provider and forwarded the port, everything works.

    Cheers for the help,

    -Scott.C
Sign In or Register to comment.