Connection Script

From Newerth: Savage Wiki

Revision as of 06:16, 11 January 2008 by Pancake (Talk | contribs)
Jump to: navigation, search


Savage 2 Server Connection Script

The Savage 2 Connection script connects to a Savage 2 server and gets information about the server. More details will be presented later


- PHP5 (Won't work with PHP4, but it can be easily modified to work with PHP4) - Apache


You may view the source Here. SImply Copy-And-Paste the code into a new PHP file.


Configuration is very simple. Simply go to the last few lines, and find:

$data = $server->getData('', 11235); 

This is the only line of code required to edit. Enter the Server Address and Port Number, and that is all you need to configure it!

Later you will see:

if(empty($server->error)) {
} else {
    echo $server->error;

This checks for any errors in the script. If there are not any errors in the script, then the information retrieved from the server will be displayed.

However, if there are any errors, then the error will be displayed.

You are able to change this based off your needs.

Using the Returned Data

When you run the script for the first time, you should see:

    [Name] => Can East 3
    [Conn] => 0
    [Max] => 18
    [Status] => Waiting
    [Map] => hellpeak
    [Next Map] => crossroads
    [Location] => ON, CA
    [Min] => 2
    [Game Type] => HvB
    [Version] => 0.9.1
    [Unknown] => �
    [Full] => 

These are all of the values stored into an array.

Returned Array Values

[Name] =>

Name of the Server

[Conn] =>

Amount of people connected to the server

[Status] =>

Status of the server. If a game is going on, then it will display the game time

[Map] =>

The current map

[Next Map] =>

The map that the server will use next when the current game is over

[Location] =>

Location of the server

[Min] =>

Minimum amount of players per team required to start a new game

[Game Type] =>

Type of game. Will be: HvH, HvB, or BvB

[Version] =>

The version that the server is running

[Unknown] =>

Any extra data that the script picked up

[Full] =>

Is the game full? Returns TRUE or FALSE

Referencing the Data Later in the Script

Odds are, you don't want to do print_r() on the data. The simplest way to use the code is


You want to change the ['Name'] with something else from the list above

Example Script

Here's a practical example of how to use the script:

  /* Connection Class Here */
$server = new serverInfo();

$data = $server->getData('', 11235);
if(empty($server->error)) {
    "Server Name: {$data['Name']}<br />\n";
    "Now Playing: {$data['Conn']}<br />\n";
    /* Keep on adding more lines as you see fit */   
} else {
    echo 'Server Offline.';