Forums

Discussions of the easy to use open source game control panel.

You are not logged in.

Announcement

Welcome on board ! We are very proud to present you our forums powered by FluxBB ! Please Register, do not forget to read carefully Forum Rules and feel free to Contact Us if you see any problems. Finally, take part in site life !

#1 2013-10-16 16:53:37

mjmfighter
Member
Registered: 2013-10-08
Posts: 2

Teamspeak Integration

First off, Love the panel.  Keep up the amazing work!

So I have been using the panel for the past few weeks and I decided I wanted teamspeak integration with it as well.  I was poking around the code and decided it would probably be easiest if I just modified the LGSL code a bit to support teamspeak querying.  I also am having to modify some of the panel code as the default live queries do not pass in a connection port (which ts queries require).  Here is a pic of what it looks like so far:

http://puu.sh/4RClV.png

I'll post the modifications that I have done soon, once I am sure it all works perfectly.

Offline

#2 2013-10-19 16:25:27

max1982
Member
From: london
Registered: 2013-09-30
Posts: 2
Website

Re: Teamspeak Integration

Hi

Looking forward to see it working hope you have a good luck with it smile

Kind regards
Wafic

Offline

#3 2014-01-17 09:11:22

Teo
Member
Registered: 2014-01-16
Posts: 43

Re: Teamspeak Integration

Can i ask you how did you set up the launcher plz?

____________
about the server query i added this from (http://www.greycube.com)

LGSL Teamspeak 3
NOT NATIVE, USING EXTERNAL LIBRARY!

Save this pastebin as ts3.class.php:

[== PHP ==]
<?PHP

/**
 * @author      Par0noid Solutions <par0noid@gmx.de>
 * @package     ts3admin
 * @version     0.6.6
 * @copyright   Copyright (c) 2009-2012, Stefan Z.
 * @link        http://ts3admin.info
 * @link        http://par0noid.info
**/
class ts3admin {

	private $runtime = array('socket' => '', 'selected' => false, 'host' => '', 'queryport' => '10011', 'timeout' => 2, 'debug' => array(), 'fileSocket' => '');

	function channelList($params = '') {
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
		if(!empty($params)) { $params = ' '.$params; }
		
		return $this->getData('multi', 'channellist'.$params);
	}

	function clientInfo($clid) {
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
		return $this->getData('array', 'clientinfo clid='.$clid);
	}


	function clientList($params = '') {
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
		
		if(!empty($params)) { $params = ' '.$params; }
		
		return $this->getData('multi', 'clientlist'.$params);
	}

	function selectServer($value, $type = 'port', $virtual = false) {
		if(in_array($type, array('port', 'serverId'))) {
			if($type == 'port') {
				if($virtual) { $virtual = ' -virtual'; }else{ $virtual = ''; }
				$res = $this->getData('boolean', 'use port='.$value.$virtual);
				if($res['success']) {
					$this->runtime['selected'] = true;
				}
				return $res;
			}else{
				$res = $this->getData('boolean', 'use sid='.$value);
				if($res['success']) {
					$this->runtime['selected'] = true;
				}
				return $res;
			}
		}else{
			return $this->generateOutput(false, array('Error: wrong value type'), false);
		}
	}

	function serverInfo() {
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
		return $this->getData('array', 'serverinfo');
	}

	function __construct($host, $queryport, $timeout = 2) {
		if($queryport >= 1 and $queryport <= 65536) {
			if($timeout >= 1) {
				$this->runtime['host'] = $host;
				$this->runtime['queryport'] = $queryport;
				$this->runtime['timeout'] = $timeout;
			}else{
			}
		}else{
		}
	}

	private function isConnected() {
		if(empty($this->runtime['socket'])) {
			return false;
		}else{
			return true;
		}
	}

	private function generateOutput($success, $errors, $data) {
		return array('success' => $success, 'errors' => $errors, 'data' => $data);
	}

 	private function unEscapeText($text) {
 		$escapedChars = array("\t", "\v", "\r", "\n", "\f", "\s", "\p", "\/");
 		$unEscapedChars = array('', '', '', '', '', ' ', '|', '/');
		$text = str_replace($escapedChars, $unEscapedChars, $text);
		return $text;
	}

	public function connect() {
		if($this->isConnected()) { 
			return $this->generateOutput(false, array('Error: the script is already connected!'), false);
		}
		$socket = @fsockopen($this->runtime['host'], $this->runtime['queryport'], $errnum, $errstr, $this->runtime['timeout']);

		if(!$socket) {
			return $this->generateOutput(false, array('Error: connection failed!', 'Server returns: '.$errstr), false);
		}else{
			if(strpos(fgets($socket), 'TS3') !== false) {
				$tmpVar = fgets($socket);
				$this->runtime['socket'] = $socket;
				return $this->generateOutput(true, array(), true);
			}else{
				return $this->generateOutput(false, array('Error: host isn\'t a ts3 instance!'), false);
			}
		}
	}

	private function executeCommand($command, $tracert) {
		if(!$this->isConnected()) {
			return $this->generateOutput(false, array('Error: script isn\'t connected to server'), false);
		}
		
		$data = '';

		
		$splittedCommand = str_split($command, 1024);
		
		$splittedCommand[(count($splittedCommand) - 1)] .= "\n";
		
		foreach($splittedCommand as $commandPart) {
			fputs($this->runtime['socket'], $commandPart);
		}

		do {
			$data .= fgets($this->runtime['socket'], 4096);
			
			if(strpos($data, 'error id=3329 msg=connection') !== false) {
				$this->runtime['socket'] = '';
				return $this->generateOutput(false, array('You got banned from server. Connection closed.'), false);
			}
			
		} while(strpos($data, 'msg=') === false or strpos($data, 'error id=') === false);

		if(strpos($data, 'error id=0 msg=ok') === false) {
			$splittedResponse = explode('error id=', $data);
			$chooseEnd = count($splittedResponse) - 1;
			
			$cutIdAndMsg = explode(' msg=', $splittedResponse[$chooseEnd]);
			
			
			return $this->generateOutput(false, array('ErrorID: '.$cutIdAndMsg[0].' | Message: '.$this->unEscapeText($cutIdAndMsg[1])), false);
		}else{
			return $this->generateOutput(true, array(), $data);
		}
	}

	private function getData($mode, $command) {
	
		$validModes = array('boolean', 'array', 'multi', 'plain');
	
		if(!in_array($mode, $validModes)) {
			return $this->generateOutput(false, array('Error: '.$mode.' is an invalid mode'), false);
		}
		
		if(empty($command)) {
			return $this->generateOutput(false, array('Error: you have to enter a command'), false);
		}
		
		$fetchData = $this->executeCommand($command, debug_backtrace());
		
		
		$fetchData['data'] = str_replace(array('error id=0 msg=ok', chr('01')), '', $fetchData['data']);
		
		
		if($fetchData['success']) {
			if($mode == 'boolean') {
				return $this->generateOutput(true, array(), true);
			}
			
			if($mode == 'array') {
				if(empty($fetchData['data'])) { return $this->generateOutput(true, array(), array()); }
				$datasets = explode(' ', $fetchData['data']);
				
				$output = array();
				
				foreach($datasets as $dataset) {
					$dataset = explode('=', $dataset);
					
					if(count($dataset) > 2) {
						for($i = 2; $i < count($dataset); $i++) {
							$dataset[1] .= '='.$dataset[$i];
						}
						$output[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);
					}else{
						if(count($dataset) == 1) {
							$output[$this->unEscapeText($dataset[0])] = '';
						}else{
							$output[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);
						}
						
					}
				}
				return $this->generateOutput(true, array(), $output);
			}
			if($mode == 'multi') {
				if(empty($fetchData['data'])) { return $this->generateOutput(true, array(), array()); }
				$datasets = explode('|', $fetchData['data']);
				
				$output = array();
				
				foreach($datasets as $datablock) {
					$datablock = explode(' ', $datablock);
					
					$tmpArray = array();
					
					foreach($datablock as $dataset) {
						$dataset = explode('=', $dataset);
						if(count($dataset) > 2) {
							for($i = 2; $i < count($dataset); $i++) {
								$dataset[1] .= '='.$dataset[$i];
							}
							$tmpArray[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);
						}else{
							if(count($dataset) == 1) {
								$tmpArray[$this->unEscapeText($dataset[0])] = '';
							}else{
								$tmpArray[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);
							}
						}					
					}
					$output[] = $tmpArray;
				}
				return $this->generateOutput(true, array(), $output);
			}
			if($mode == 'plain') {
				return $fetchData;
			}
		}else{
			return $this->generateOutput(false, $fetchData['errors'], false);
		}
	}
}

?>

In lgsl_protocol.php

After

[== PHP ==]
"swat4" => "SWAT 4",

Add

[== PHP ==]
"ts3" => "Teamspeak 3",

After

[== PHP ==]
"swat4" => "03",

Add

[== PHP ==]
"ts3" => "97",

After

[== PHP ==]
"swat4" => "qtracker://{IP}:{S_PORT}?game=SWAT4&action=show",

Add

[== PHP ==]
"ts3" => "http://www.teamspeak.com",


Before

[== PHP ==]
function lgsl_query_02(&$server, &$lgsl_need, &$lgsl_fp)

Add


[== PHP ==]
  function lgsl_query_97(&$server, &$lgsl_need, &$lgsl_fp) 
  { 
    require_once("opt_classes/ts3.class.php"); 

    $ts3_ip = $server['b']['ip']; 
    $ts3_queryport = $server['b']['q_port']; 
    $ts3_port = $server['b']['c_port']; 

    $tsAdmin = new ts3admin($ts3_ip, $ts3_queryport); 
    $tsAdmin->connect(); 
    $tsAdmin->selectServer($ts3_port); 
    $hinfo = $tsAdmin->serverInfo(); 

    if($hinfo['data']['virtualserver_name'] == NULL) { return false; } 

    $server['s']['status']             = 1; 
    $server['s']['name']             = $hinfo['data']['virtualserver_name']; 
    $server['s']['password']         = $hinfo['data']['virtualserver_password']; 
    $server['s']['players']         = $hinfo['data']['virtualserver_clientsonline']; 
    $server['s']['playersmax']         = $hinfo['data']['virtualserver_maxclients']; 
    $server['s']['channelcount']     = $hinfo['data']['virtualserver_channelsonline']; 
    $server['s']['map']             = "Teamspeak 3"; 
     
    $server['e']['motd']             = $hinfo['data']['virtualserver_welcomemessage']; 
    $server['e']['platform']         = $hinfo['data']['virtualserver_platform']; 
    $server['e']['version']         = $hinfo['data']['virtualserver_version']; 
     
    if ($lgsl_need['p']){ 
        $clients = $tsAdmin->clientList(); 
        for($i=0;$i<sizeof($clients['data']);$i++){ 
            $server['p'][$i]['id'] = $i; 
            $server['p'][$i]['name'] = $clients['data'][$i]['client_nickname']; 
            $server['p'][$i]['score'] = "-"; 
            $server['p'][$i]['time'] = "-"; 
        } 
    } 
    return TRUE; 
  } 

Offline

#4 2014-01-19 11:37:42

super_g2
Idea's master ;)
Registered: 2013-05-29
Posts: 116
Website

Re: Teamspeak Integration

nice thks !!
we keep it in mind for the next release smile

Offline

#5 2015-02-25 22:17:17

capoeira
Member
Registered: 2015-02-24
Posts: 13

Re: Teamspeak Integration

a bit old topic but I figured there is no need to create a new one, when I paste the last bit of code

 function lgsl_query_97(&$server, &$lgsl_need, &$lgsl_fp) 
  { 
    require_once("opt_classes/ts3.class.php"); 

    $ts3_ip = $server['b']['ip']; 
    $ts3_queryport = $server['b']['q_port']; 
    $ts3_port = $server['b']['c_port']; 

    $tsAdmin = new ts3admin($ts3_ip, $ts3_queryport); 
    $tsAdmin->connect(); 
    $tsAdmin->selectServer($ts3_port); 
    $hinfo = $tsAdmin->serverInfo(); 

    if($hinfo['data']['virtualserver_name'] == NULL) { return false; } 

    $server['s']['status']             = 1; 
    $server['s']['name']             = $hinfo['data']['virtualserver_name']; 
    $server['s']['password']         = $hinfo['data']['virtualserver_password']; 
    $server['s']['players']         = $hinfo['data']['virtualserver_clientsonline']; 
    $server['s']['playersmax']         = $hinfo['data']['virtualserver_maxclients']; 
    $server['s']['channelcount']     = $hinfo['data']['virtualserver_channelsonline']; 
    $server['s']['map']             = "Teamspeak 3"; 
     
    $server['e']['motd']             = $hinfo['data']['virtualserver_welcomemessage']; 
    $server['e']['platform']         = $hinfo['data']['virtualserver_platform']; 
    $server['e']['version']         = $hinfo['data']['virtualserver_version']; 
     
    if ($lgsl_need['p']){ 
        $clients = $tsAdmin->clientList(); 
        for($i=0;$i<sizeof($clients['data']);$i++){ 
            $server['p'][$i]['id'] = $i; 
            $server['p'][$i]['name'] = $clients['data'][$i]['client_nickname']; 
            $server['p'][$i]['score'] = "-"; 
            $server['p'][$i]['time'] = "-"; 
        } 
    } 
    return TRUE; 
  } 

Client panel is blank, i can see a white page, why is that?

Offline

#6 2015-02-26 13:59:18

Angrytoilet
Member
From: Dalls, Texas
Registered: 2015-02-04
Posts: 100
Website

Re: Teamspeak Integration

white page = permissions issue or php/apache issue
also, make sure the code points to your stuff properly, i didnt jump in and test it since im at work, but, i would assume:  permissions, or, bad code (not pointing at your stuff properly)

Offline

#7 2015-02-28 15:49:29

wizYq
Member
Registered: 2013-07-08
Posts: 97

Re: Teamspeak Integration

and where do ppl put the  ts3.class.php file on??..
kinda missed out on that bit of info eh.

Offline

#8 2015-03-05 11:42:56

capoeira
Member
Registered: 2015-02-24
Posts: 13

Re: Teamspeak Integration

I believe

function lgsl_query_97(&$server, &$lgsl_need, &$lgsl_fp) 
  { 
    require_once("opt_classes/ts3.class.php"); 

    $ts3_ip = $server['b']['ip']; 
    $ts3_queryport = $server['b']['q_port']; 
    $ts3_port = $server['b']['c_port']; 

    $tsAdmin = new ts3admin($ts3_ip, $ts3_queryport); 
    $tsAdmin->connect(); 
    $tsAdmin->selectServer($ts3_port); 
    $hinfo = $tsAdmin->serverInfo(); 

    if($hinfo['data']['virtualserver_name'] == NULL) { return false; } 

    $server['s']['status']             = 1; 
    $server['s']['name']             = $hinfo['data']['virtualserver_name']; 
    $server['s']['password']         = $hinfo['data']['virtualserver_password']; 
    $server['s']['players']         = $hinfo['data']['virtualserver_clientsonline']; 
    $server['s']['playersmax']         = $hinfo['data']['virtualserver_maxclients']; 
    $server['s']['channelcount']     = $hinfo['data']['virtualserver_channelsonline']; 
    $server['s']['map']             = "Teamspeak 3"; 
     
    $server['e']['motd']             = $hinfo['data']['virtualserver_welcomemessage']; 
    $server['e']['platform']         = $hinfo['data']['virtualserver_platform']; 
    $server['e']['version']         = $hinfo['data']['virtualserver_version']; 
     
    if ($lgsl_need['p']){ 
        $clients = $tsAdmin->clientList(); 
        for($i=0;$i<sizeof($clients['data']);$i++){ 
            $server['p'][$i]['id'] = $i; 
            $server['p'][$i]['name'] = $clients['data'][$i]['client_nickname']; 
            $server['p'][$i]['score'] = "-"; 
            $server['p'][$i]['time'] = "-"; 
        } 
    } 
    return TRUE; 
  } 

is the issue here, because

 function lgsl_query_97(&$server, &$lgsl_need, &$lgsl_fp)

is already used in lgsl_protocol.php by something else

Offline

#9 2015-03-11 16:47:39

wizYq
Member
Registered: 2013-07-08
Posts: 97

Re: Teamspeak Integration

i did this. but i used the tut from
http://www.greycube.com/site/e107_plugi … .php?15842

and now when i try to add a "game" to BGP, the page shows up white and blank.
/admin/configgameadd.php

Offline

#10 2015-03-11 17:17:27

Angrytoilet
Member
From: Dalls, Texas
Registered: 2015-02-04
Posts: 100
Website

Re: Teamspeak Integration

white blank ...
hmmmmm, thats a config issue and i solved it prior ... now i forget what i did to solve ...


OH!

if you set one area of the config to "localhost" set it to :  127.0.0.1
otherwise you get php issues
i flipped all my apache stuff to "127.0.0.1" from "localhost" and have not seen a white page since.  Why the change for you?  because you made a change to the coding some how.  revert back, or, change all the localhosts to the 127 IP

Offline

#11 2015-03-11 17:20:22

Angrytoilet
Member
From: Dalls, Texas
Registered: 2015-02-04
Posts: 100
Website

Re: Teamspeak Integration

on a side note:  looking at the coders talking, this works for 5.8 not 5.7 LGSL ... im not sure what version BGP uses

Offline

#12 2015-03-11 17:33:49

wizYq
Member
Registered: 2013-07-08
Posts: 97

Re: Teamspeak Integration

bgp uses 5.8 as well. im not sure i trust myself to set all my apache ip's from local to something else.
as im just a basic guy knowing basic stuff. so, idk if i trust myself enough. as im not willing to start from the beginning if i mess it up lol.

Last edited by wizYq (2015-03-11 17:45:45)

Offline

#13 2015-03-11 22:53:44

Angrytoilet
Member
From: Dalls, Texas
Registered: 2015-02-04
Posts: 100
Website

Re: Teamspeak Integration

LOL i agree with you - i usually endup formatting and reinstalling the entire thing.

Just make sure BGP is set to not "localhost" and apache references are 127.0.0.1

i found this resolved ALL of my white page PHP issues.

Offline

#14 2015-03-19 22:20:28

wizYq
Member
Registered: 2013-07-08
Posts: 97

Re: Teamspeak Integration

but back to the TS# thing, has anyone else successfully added this service to BGP?

Offline

#15 2015-03-20 02:58:33

Angrytoilet
Member
From: Dalls, Texas
Registered: 2015-02-04
Posts: 100
Website

Re: Teamspeak Integration

I'm about to go to bed wiz, in the morning, i will run an install (or at least attempt to) and see what i can do.  I have Teamspeak on my cluster and will give it a shot and report back

Offline

#16 2015-03-20 13:52:23

wizYq
Member
Registered: 2013-07-08
Posts: 97

Re: Teamspeak Integration

that would be great big_smile

Offline

#17 2015-03-20 15:52:06

Angrytoilet
Member
From: Dalls, Texas
Registered: 2015-02-04
Posts: 100
Website

Re: Teamspeak Integration

so this entire code breaks BGP ...
Specificly:

  function lgsl_query_97(&$server, &$lgsl_need, &$lgsl_fp) 
  { 
    require_once("opt_classes/ts3.class.php"); 

    $ts3_ip = $server['b']['ip']; 
    $ts3_queryport = $server['b']['q_port']; 
    $ts3_port = $server['b']['c_port']; 

    $tsAdmin = new ts3admin($ts3_ip, $ts3_queryport); 
    $tsAdmin->connect(); 
    $tsAdmin->selectServer($ts3_port); 
    $hinfo = $tsAdmin->serverInfo(); 

    if($hinfo['data']['virtualserver_name'] == NULL) { return false; } 

    $server['s']['status']             = 1; 
    $server['s']['name']             = $hinfo['data']['virtualserver_name']; 
    $server['s']['password']         = $hinfo['data']['virtualserver_password']; 
    $server['s']['players']         = $hinfo['data']['virtualserver_clientsonline']; 
    $server['s']['playersmax']         = $hinfo['data']['virtualserver_maxclients']; 
    $server['s']['channelcount']     = $hinfo['data']['virtualserver_channelsonline']; 
    $server['s']['map']             = "Teamspeak 3"; 
     
    $server['e']['motd']             = $hinfo['data']['virtualserver_welcomemessage']; 
    $server['e']['platform']         = $hinfo['data']['virtualserver_platform']; 
    $server['e']['version']         = $hinfo['data']['virtualserver_version']; 
     
    if ($lgsl_need['p']){ 
        $clients = $tsAdmin->clientList(); 
        for($i=0;$i<sizeof($clients['data']);$i++){ 
            $server['p'][$i]['id'] = $i; 
            $server['p'][$i]['name'] = $clients['data'][$i]['client_nickname']; 
            $server['p'][$i]['score'] = "-"; 
            $server['p'][$i]['time'] = "-"; 
        } 
    } 
    return TRUE; 
  } 

Offline

#18 2015-03-20 16:27:41

Angrytoilet
Member
From: Dalls, Texas
Registered: 2015-02-04
Posts: 100
Website

Re: Teamspeak Integration

Every time i add that section, it breaks my BGP.
Now, even with it added, i dont see TS3 on that list for installs.  So, im not sure how its getting added by anyone at this point.  Did something change from the "working BGP" verison and this 0.47 from git?  I dont know. 

Wiz, you have this working at all?

Offline

#19 2015-03-20 20:27:37

super_g2
Idea's master ;)
Registered: 2013-05-29
Posts: 116
Website

Re: Teamspeak Integration

please, have a look at the line "    require_once("opt_classes/ts3.class.php"); "
is this file "ts3.class.php" located in the opt_casses directory ?
if not, stop lloking for another issue, it's because of this smile

You have to create the ts3.class.php file and place it in a directory, then the require_once statement needs to be well typed smile

Offline

#20 2015-03-20 22:46:26

wizYq
Member
Registered: 2013-07-08
Posts: 97

Re: Teamspeak Integration

opt_casses dir where?
cus it's not in lgsl nor a default install of a ts3 server.
so maybe instead of being a douche bag, mr.super boi. care to explain it fully. cus none even said where to save the file.

Offline

#21 2015-03-20 23:24:43

Angrytoilet
Member
From: Dalls, Texas
Registered: 2015-02-04
Posts: 100
Website

Re: Teamspeak Integration

super_g2 wrote:

please, have a look at the line "    require_once("opt_classes/ts3.class.php"); "
is this file "ts3.class.php" located in the opt_casses directory ?
if not, stop lloking for another issue, it's because of this smile

You have to create the ts3.class.php file and place it in a directory, then the require_once statement needs to be well typed smile


in not soo many words .....
can we get a directory breakdown since it is clearly not a default setup with the current directory tree.  Please.

Offline

#22 2015-03-20 23:25:48

Angrytoilet
Member
From: Dalls, Texas
Registered: 2015-02-04
Posts: 100
Website

Re: Teamspeak Integration

wizYq wrote:

and where do ppl put the  ts3.class.php file on??..
kinda missed out on that bit of info eh.


^ this

Offline

#23 2015-03-21 08:03:18

super_g2
Idea's master ;)
Registered: 2013-05-29
Posts: 116
Website

Re: Teamspeak Integration

Angrytoilet wrote:
super_g2 wrote:

please, have a look at the line "    require_once("opt_classes/ts3.class.php"); "
is this file "ts3.class.php" located in the opt_casses directory ?
if not, stop lloking for another issue, it's because of this smile

You have to create the ts3.class.php file and place it in a directory, then the require_once statement needs to be well typed smile


in not soo many words .....
can we get a directory breakdown since it is clearly not a default setup with the current directory tree.  Please.

1/ Create a new folder called "opt_classes" inside the libs/lgsl/
2/ put the ts3.class.php file inside of this folder
Code of this file :

<?PHP

/**
 * @author      Par0noid Solutions <par0noid@gmx.de>
 * @package     ts3admin
 * @version     0.6.6
 * @copyright   Copyright (c) 2009-2012, Stefan Z.
 * @link        http://ts3admin.info
 * @link        http://par0noid.info
**/
class ts3admin {

	private $runtime = array('socket' => '', 'selected' => false, 'host' => '', 'queryport' => '10011', 'timeout' => 2, 'debug' => array(), 'fileSocket' => '');

	function channelList($params = '') {
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
		if(!empty($params)) { $params = ' '.$params; }
		
		return $this->getData('multi', 'channellist'.$params);
	}

	function clientInfo($clid) {
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
		return $this->getData('array', 'clientinfo clid='.$clid);
	}


	function clientList($params = '') {
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
		
		if(!empty($params)) { $params = ' '.$params; }
		
		return $this->getData('multi', 'clientlist'.$params);
	}

	function selectServer($value, $type = 'port', $virtual = false) {
		if(in_array($type, array('port', 'serverId'))) {
			if($type == 'port') {
				if($virtual) { $virtual = ' -virtual'; }else{ $virtual = ''; }
				$res = $this->getData('boolean', 'use port='.$value.$virtual);
				if($res['success']) {
					$this->runtime['selected'] = true;
				}
				return $res;
			}else{
				$res = $this->getData('boolean', 'use sid='.$value);
				if($res['success']) {
					$this->runtime['selected'] = true;
				}
				return $res;
			}
		}else{
			return $this->generateOutput(false, array('Error: wrong value type'), false);
		}
	}

	function serverInfo() {
		if(!$this->runtime['selected']) { return $this->checkSelected(); }
		return $this->getData('array', 'serverinfo');
	}

	function __construct($host, $queryport, $timeout = 2) {
		if($queryport >= 1 and $queryport <= 65536) {
			if($timeout >= 1) {
				$this->runtime['host'] = $host;
				$this->runtime['queryport'] = $queryport;
				$this->runtime['timeout'] = $timeout;
			}else{
			}
		}else{
		}
	}

	private function isConnected() {
		if(empty($this->runtime['socket'])) {
			return false;
		}else{
			return true;
		}
	}

	private function generateOutput($success, $errors, $data) {
		return array('success' => $success, 'errors' => $errors, 'data' => $data);
	}

 	private function unEscapeText($text) {
 		$escapedChars = array("\t", "\v", "\r", "\n", "\f", "\s", "\p", "\/");
 		$unEscapedChars = array('', '', '', '', '', ' ', '|', '/');
		$text = str_replace($escapedChars, $unEscapedChars, $text);
		return $text;
	}

	public function connect() {
		if($this->isConnected()) { 
			return $this->generateOutput(false, array('Error: the script is already connected!'), false);
		}
		$socket = @fsockopen($this->runtime['host'], $this->runtime['queryport'], $errnum, $errstr, $this->runtime['timeout']);

		if(!$socket) {
			return $this->generateOutput(false, array('Error: connection failed!', 'Server returns: '.$errstr), false);
		}else{
			if(strpos(fgets($socket), 'TS3') !== false) {
				$tmpVar = fgets($socket);
				$this->runtime['socket'] = $socket;
				return $this->generateOutput(true, array(), true);
			}else{
				return $this->generateOutput(false, array('Error: host isn\'t a ts3 instance!'), false);
			}
		}
	}

	private function executeCommand($command, $tracert) {
		if(!$this->isConnected()) {
			return $this->generateOutput(false, array('Error: script isn\'t connected to server'), false);
		}
		
		$data = '';

		
		$splittedCommand = str_split($command, 1024);
		
		$splittedCommand[(count($splittedCommand) - 1)] .= "\n";
		
		foreach($splittedCommand as $commandPart) {
			fputs($this->runtime['socket'], $commandPart);
		}

		do {
			$data .= fgets($this->runtime['socket'], 4096);
			
			if(strpos($data, 'error id=3329 msg=connection') !== false) {
				$this->runtime['socket'] = '';
				return $this->generateOutput(false, array('You got banned from server. Connection closed.'), false);
			}
			
		} while(strpos($data, 'msg=') === false or strpos($data, 'error id=') === false);

		if(strpos($data, 'error id=0 msg=ok') === false) {
			$splittedResponse = explode('error id=', $data);
			$chooseEnd = count($splittedResponse) - 1;
			
			$cutIdAndMsg = explode(' msg=', $splittedResponse[$chooseEnd]);
			
			
			return $this->generateOutput(false, array('ErrorID: '.$cutIdAndMsg[0].' | Message: '.$this->unEscapeText($cutIdAndMsg[1])), false);
		}else{
			return $this->generateOutput(true, array(), $data);
		}
	}

	private function getData($mode, $command) {
	
		$validModes = array('boolean', 'array', 'multi', 'plain');
	
		if(!in_array($mode, $validModes)) {
			return $this->generateOutput(false, array('Error: '.$mode.' is an invalid mode'), false);
		}
		
		if(empty($command)) {
			return $this->generateOutput(false, array('Error: you have to enter a command'), false);
		}
		
		$fetchData = $this->executeCommand($command, debug_backtrace());
		
		
		$fetchData['data'] = str_replace(array('error id=0 msg=ok', chr('01')), '', $fetchData['data']);
		
		
		if($fetchData['success']) {
			if($mode == 'boolean') {
				return $this->generateOutput(true, array(), true);
			}
			
			if($mode == 'array') {
				if(empty($fetchData['data'])) { return $this->generateOutput(true, array(), array()); }
				$datasets = explode(' ', $fetchData['data']);
				
				$output = array();
				
				foreach($datasets as $dataset) {
					$dataset = explode('=', $dataset);
					
					if(count($dataset) > 2) {
						for($i = 2; $i < count($dataset); $i++) {
							$dataset[1] .= '='.$dataset[$i];
						}
						$output[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);
					}else{
						if(count($dataset) == 1) {
							$output[$this->unEscapeText($dataset[0])] = '';
						}else{
							$output[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);
						}
						
					}
				}
				return $this->generateOutput(true, array(), $output);
			}
			if($mode == 'multi') {
				if(empty($fetchData['data'])) { return $this->generateOutput(true, array(), array()); }
				$datasets = explode('|', $fetchData['data']);
				
				$output = array();
				
				foreach($datasets as $datablock) {
					$datablock = explode(' ', $datablock);
					
					$tmpArray = array();
					
					foreach($datablock as $dataset) {
						$dataset = explode('=', $dataset);
						if(count($dataset) > 2) {
							for($i = 2; $i < count($dataset); $i++) {
								$dataset[1] .= '='.$dataset[$i];
							}
							$tmpArray[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);
						}else{
							if(count($dataset) == 1) {
								$tmpArray[$this->unEscapeText($dataset[0])] = '';
							}else{
								$tmpArray[$this->unEscapeText($dataset[0])] = $this->unEscapeText($dataset[1]);
							}
						}					
					}
					$output[] = $tmpArray;
				}
				return $this->generateOutput(true, array(), $output);
			}
			if($mode == 'plain') {
				return $fetchData;
			}
		}else{
			return $this->generateOutput(false, $fetchData['errors'], false);
		}
	}
}

?>

3/ add in the file /libs/lgls/lgsl_protocol.php the following informations (see http://board.bgpanel.net/viewtopic.php?pid=851#p851)
4/ It must work fine now

Is it ok for you ? I can't be clearer than I do. xD

Offline

#24 2015-03-21 16:29:01

wizYq
Member
Registered: 2013-07-08
Posts: 97

Re: Teamspeak Integration

thanks, will give it a go.

some advice, don't be such a sarcastic prick. you will go further in life.

edit: did everything as you stated. panel is not showing any of my servers or graph or anything now.
and yes... i have servers on my panel AND THEY ARE RUNNING.
but this ts3 code breaks everything.

v7thf5.jpg

Last edited by wizYq (2015-03-21 16:57:32)

Offline

#25 2015-03-21 17:07:25

Angrytoilet
Member
From: Dalls, Texas
Registered: 2015-02-04
Posts: 100
Website

Re: Teamspeak Integration

That is EXACTLY what i was getting as well.  And, if you go ahead and attempt "add server" ts3 isnt even on that list lol.

I would say, "code fail" at this point.

This is another reason why i have the post in the ideas section for adding our own list, or, even better, the panel pulls the LGSM git repos online (or looks for updates).  Since all voice servers are listed on that CURRENT one, it would be magical

Offline

Board footer

Powered by FluxBB