Connection Script

From Newerth: Savage Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 06:21, 11 January 2008 (edit)
Pancake (Talk | contribs)

← Previous diff
Revision as of 06:21, 11 January 2008 (edit) (undo)
Pancake (Talk | contribs)

Next diff →
Line 1: Line 1:
-= 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 The Savage 2 Connection script connects to a Savage 2 server and gets information about the server. More details will be presented later
-== Requirements ==+= Requirements =
- PHP5 (Won't work with PHP4, but it can be easily modified to work with PHP4) - PHP5 (Won't work with PHP4, but it can be easily modified to work with PHP4)
- Apache - Apache

Revision as of 06:21, 11 January 2008

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

Contents

Requirements

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

Download

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

Configuration

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

$data = $server->getData('74.86.152.58', 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)) {
    print_r($data);
} 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:

Array
(
    [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

$data['Name']

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:

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

$data = $server->getData('74.86.152.58', 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.';
}

if you want to save on typing, you may also consider using foreach();

Other Notes

Any other useful information will be posted below

Charset

This was tested using ISO-8859-1. Any other charsets may show unintended symbols.

If you are unfamiliar with this concept, use this code:

<?php header('Content-type: text/html; charset=ISO-8859-1'); ?>