Voiceserver

The voiceserver api request manages your voiceserver. Multiple options are available

  • Get information about your voiceserver(s)
  • Restart your voiceserver
  • Get a voiceserver viewer as html table

Version

1.0.1

Request Parameters

Parameter Valid Input Default Required Description
customer_id unsigned integer - yes The customer_id the data should be requested for
token string - yes The token generated for this request. See token for more information
pw boolean true no Include passwords for servers
server_id unsigned integer null no The server_id, needed to run a command on your voiceserver
(Use either in URL or as JSON command)
command string null no The command for your gameserver, possibilities: (restart)

Examples

For all examples we are using GuzzleHttpClient.

Get voiceserver from customer_id 1

<?php 

use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;

function getVoiceserver() {
    try {
        $client = new Client();
        $response = $client->post('https://my.ngz.net/api/voiceserver',
            array(
                'json' => array(
                    'customer_id' => 1,
                    'token' => 'C9FBFB090B8E6BBB1EED94D2259F94D98CDBCB57A710558DA0'
                )
            )
        );
    } catch (ClientException $e) {
        throw new Exception($e->getResponse()->getBody()->getContents(), $e->getResponse()->getStatusCode());
    }
    $reply = array();
    if(is_object($response) && $response->getStatusCode() == 200) {
        $reply = json_decode($response->getBody()->getContents(), true);
    }
    return $reply;
}
var_dump(getVoiceserver());

Sample output

<?php
Array 
(
    [0] => stdClass Object
    (
        [id] => 201201
        [product_id] => 302302
        [name ]=> "TeamSpeak 2 / 3 - Mumble"
        [server] => stdClass Object
        (
            [ip] => "11.22.333.444"
            [port] => 10390
            [server_pw] => "password"
            [admin_pw] => "password"
            [name] => "Your voiceserver name"
            [players] => stdClass Object
            (
                [max] => "60"
            )
        )
    )
)

Restart voiceserver from customer_id 1 with server_id 201201

<?php 

use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;

function restartGameserver() {
    try {
        $client = new Client();
        $response = $client->post('https://my.ngz.net/api/voiceserver',
            array(
                'json' => array(
                    'customer_id' => 1,
                    'token' => 'C9FBFB090B8E6BBB1EED94D2259F94D98CDBCB57A710558DA0',
                    'server_id' => '201201',
                    'command' => 'restart'
                )
            )
        );
    } catch (ClientException $e) {
        throw new Exception($e->getResponse()->getBody()->getContents(), $e->getResponse()->getStatusCode());
    }
    $reply = array();
    if(is_object($response) && $response->getStatusCode() == 202) {
        $reply = json_decode($response->getBody()->getContents(), true);
    }
    return $reply;
}
var_dump(restartGameserver());

Sample output

(
    "Accepted"
)   

get the voiceserver viewer from customer_id 1 with server_id 201201

The return of the getviewer command is a table in HTML format looking just like the one you can see within your webinterface. It is only available for users of the new TS3 servers.

You can style the table with the included CSS class .ts3_viewer

<?php

use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;

function getVoiceserverViewer() {
    try {
        $client = new Client();
        $response = $client->post('https://my.ngz.net/api/voiceserver/201201',
            array(
                'json' => array(
                    'customer_id' => 1,
                    'token' => 'C9FBFB090B8E6BBB1EED94D2259F94D98CDBCB57A710558DA0',
                    'command' => 'getviewer'
                )
            )
        );
    } catch (ClientException $e) {
        throw new Exception($e->getResponse()->getBody()->getContents(), $e->getResponse()->getStatusCode());
    }
    $return = '';
    if(is_object($response) && $response->getStatusCode() == 200) {
        $reply = json_decode($response->getBody()->getContents(), true);
        $return = $reply[0];
    }
    return $return;
}

echo getVoiceserverViewer();

Sample output in HTML

<table id='ts3_h_s2' class='ts3_viewer server' summary='2'>...</table>
Copyright 2016 by United Gameserver GmbH. Alle Rechte vorbehalten.V3.1.5.1337