PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of sk89q   libdpserver   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Variety of examples
Class: libdpserver
Administer remote Paintball game servers
Author: By
Last change: New version
Date: 16 years ago
Size: 3,932 bytes
 

Contents

Class file image Download
<?php
   
require_once "DigitalPaintServer.php";
   
   
header("Content-type: text/plain");
   
   
$server_host = "127.0.0.1";
   
$server_port = 27910;
   
$rcon_password = "test";
   
    echo
"Testing server $server_host:$server_port\n\n";
   
   
// Create a new instance
   
$paintball = new DigitalPaintServer($server_host, $server_port, $rcon_password);
   
   
// Check if the server is online
   
echo "Is the server online?\n";
    if(
$paintball->is_online())
    {
        echo
"\tOnline!\n";
    }
    else
    {
        echo
"\tIt's not online =(\n";
        echo
"\nQuitting...\n";
        exit;
    }
   
   
// Get server name
   
$server_name = $paintball->get_server_name();
    echo
"\nServer: $server_name\n";
   
   
// Get build
   
$build = $paintball->get_build();
    echo
"\nRunning build: $build\n";
   
   
// Get if a password is set
   
$has_password = $paintball->has_password_set();
    echo
"\nPassword set? ".($has_password ? "yes" : "no")."\n";
   
   
// Get ping
   
$ping = $paintball->ping();
    echo
"\nPing: {$ping}ms\n";
   
   
// This method does not normally have to be called. Some
    // of the methods (like to get the currrent map), require getting
    // the server status data. It is normally done automatically.
    // After it is called, it will continue to use cached data. If
    // you ever want to update the cache after that, you need to
    // call the following method, with true as its first parameter.
   
$paintball->update_status_cache(true);
   
   
// Dump status information
   
echo "\nDump status information\n";
   
$status = $paintball->get_status_info();
    foreach(
$status as $key => $value)
    {
        echo
"\t$key => $value\n";
    }
   
   
// Dump players list
   
echo "\nGet player list\n";
   
$players = $paintball->get_players();
    foreach(
$players as $index => $player)
    {
        echo
"\t$index. {$player['team']}: ".DigitalPaintServer::clean_funname($player['name'])."\n";
        echo
"\t\t{$player['ping']}ms {$player['points']}pts\n";
    }
   
   
// Dump players list with extended information
   
echo "\nGet player list with extended information (via RCON):\n";
   
$players = $paintball->rcon_get_extended_players();
    foreach(
$players as $index => $player)
    {
        echo
"\t$index. {$player['team']}: ".DigitalPaintServer::clean_funname($player['name'])."\n";
       
$client_id = $player['client_id'];
        foreach(
$player as $key => $value)
        {
            if(
in_array($key, array('name', 'team'))) continue;
           
            echo
"\t\t{$key}: {$value}\n";
        }
    }
   
    if(isset(
$client_id))
    {
       
// Dump user information
       
echo "\nGet user information about client ID #$client_id\n";
       
$info = $paintball->rcon_get_user_information($client_id);
        foreach(
$info as $key => $value)
        {
            echo
"\t$key => $value\n";
        }
    }
   
   
// Dump players list
   
echo "\nGet bot list\n";
   
$players = $paintball->rcon_get_bots();
    foreach(
$players as $bot)
    {
        echo
"\t".DigitalPaintServer::clean_funname($bot)."\n";
    }
   
   
// Dump map rotation list
   
echo "\nGet map rotation list\n";
   
$players = $paintball->rcon_get_map_rotation();
    foreach(
$players as $map)
    {
        echo
"\t{$map['mapname']} ({$map['points']})\n";
    }
   
   
// Get current map
   
echo "\nGet current map\n";
    echo
"\t".$paintball->get_map()."\n";
   
   
// Get variable "website"
   
echo "\nGet the variable 'website' (via RCON):\n";
   
$website = $paintball->rcon_get_variable("website");
    echo
"\t$website\n";
   
   
// Dump ban list
   
echo "\nDump the ban list\n";
   
$bans = $paintball->rcon_list_banlist();
    foreach(
$bans as $ip)
    {
        echo
"\t$ip\n";
    }
?>