[Xaseco] Teamspeak 3 plugin 0.6 updated at 14.3.2011

Discuss everything about Xymph's Aseco flavoured server control scripts for TM Forever / classic TMN and for TM² Canyon.

Moderators: Xymph, TM-Patrol

reaby
smooth traffic navigator
smooth traffic navigator
Posts: 214
Joined: 02 Jul 2009 21:24
Owned TM-games: TMUF

Re: [Xaseco] Teamspeak 3 plugin 0.2 updated at 27.2.2010

Post by reaby » 04 Mar 2010 19:58

Aha. I'll try to fix later this week.

nocturne
solid chaser
solid chaser
Posts: 1390
Joined: 08 Jun 2007 18:48
Owned TM-games: all
Contact:

Re: [Xaseco] Teamspeak 3 plugin 0.2 updated at 27.2.2010

Post by nocturne » 04 Mar 2010 23:15

Edit: Code no longer applicable/necessary. Refer to the download in the first post of this thread.

I took a quick look... the code hurt my eyes too much.. Either it was all pieced together from various other scripts, or the author just can't decide on the tab/bracket format they prefer.

I cleaned it up a bit, tweaking various things as I went along. There seemed to be some leftovers from other scripts, references to functions that weren't included.

No idea if this works, but here goes:

Code: Select all

<?php
require_once('includes/xmlparser.inc.php');
require_once("includes/tsstatus.php");

Aseco::registerEvent('onStartup', 'ts3_startup');
Aseco::registerEvent('onNewChallenge', 'ts3_panel_on');
Aseco::registerEvent('onPlayerConnect', 'ts3_panel_on');
Aseco::registerEvent('onEverySecond', 'ts3_update');
Aseco::registerEvent('onPlayerManialinkPageAnswer', 'ts3_mania_event');

global $aseco, $ts3, $ts3_counter, $ts3_settings;

// Initialize


function ts3_startup($aseco, $command) {
   global $aseco, $ts3, $ts3_counter, $ts3_settings;
   
   $ts3_counter = 0;
   $ts3 = new Teamspeak3();
   
   // load config
   $xml_parser = new Examsly();
   if ($settings = $xml_parser->parseXml('teamspeak3.xml')) {
      $ts3_settings = array();
      $ts3_settings['server_addr'] = $settings['SETTINGS']['SERVER'][0];
      $ts3_settings['serverport'] = $settings['SETTINGS']['SERVERPORT'][0];
      $ts3_settings['queryport'] = $settings['SETTINGS']['QUERYPORT'][0];
      $ts3_settings['update_interval'] = $settings['SETTINGS']['UPDATE_INTERVAL'][0];
   } else {
      // could not parse XML file
      trigger_error('[plugin.teamspeak3.php] Could not read/parse setttings file version.xml!', E_USER_WARNING);
      return false;
   }

   $ts3->Aseco = $aseco;
   $ts3->Start();
   $ts3->visibility = true;
}



function ts3_update($aseco, $command) {
   global $ts3, $ts3_counter, $ts3_settings;

   $time = time();
   if ($time >= $ts3_counter) {         // working with actual time tends to be more reliable than counters..
      $ts3->tsstatus->update();
      if ($ts3->visibility) {$ts3->panel_on();}
      $ts3_counter = $time + $ts3_settings['update_interval'];
   }
}



function ts3_panel_on($aseco, $command) {
   global $ts3;
   $ts3->visibility = true;
   $ts3->panel_on();
}



function ts3_panel_off($aseco, $command) {
   global $ts3;
   $ts3->visibility = false;
   $ts3->panel_off();
}


function ts3_mania_event($aseco, $command) {
   global $ts3;
   $login = $command[1];
   $action = $command[2];
   if ($action == $ts3->manialinkID+1) {
      $ts3->info_on($login);
   }

   if ($action == $ts3->manialinkID+2) {
      $ts3->info_off($login);
   }

}

// Teamspeak3 Class  -- as if it wasn't obvious enough, %D
class Teamspeak3 {
   public $aseco;
   public $tsstatus;      // pretty sure it shouldn't be 'tsStatus'
   //   public $Server;         // is this even used..?  what is it for?
   //   public $ts3_settings;   // this was there before...  dunno the purpose
   public $manialinkID = 35790;
   public $visibility = true;

//   function updateServerData() {      // this one still confuses the hell out of me..  it's never called, and references a third-party script that's not included
//      $stats = $this->ts3->queryTeamspeakServerEx($this->Server);
//      if ($stats['queryerror'] == 0) { $this->tsStats = $stats; } else { print "Plugin Teamspeak2: connection error\n"; }
//      $this->panel_on();
//   }

   function Start() {
      global $ts3_settings;

      //if ( empty($ts3_server_addr) || empty($ts3_serverport) || empty($ts3_queryport) || empty($ts3_update_interval) ) { trigger_error('[plugin.teamspeak3.php] empty values on version.xml, check configuration!', E_USER_WARNING); return false; }
      $this->tsstatus = new TSStatus($ts3_settings['server_addr'], $ts3_settings['queryport'], $ts3_settings['serverport']);
      $this->tsstatus->update();
   }

   function panel_off() {
      $xml = '<?xml version="1.0" encoding="UTF-8"?><manialinks><manialink id='.$this->manialinkID.'></manialink></manialinks>';
      $this->Aseco->addCall('SendDisplayManialinkPage', array($xml, 0, false));
   }

   function panel_on() {
      $xml = '<?xml version="1.0" encoding="UTF-8"?>
      <manialinks>
         <manialink id="'.$this->manialinkID.'">
            <frame posn="-64 45 0">
               <quad sizen="3 3" posn="0 0 0.001" image="http://koti.mbnet.fi/reaby/xaseco/images/ts3logo.jpg" action="'.($this->manialinkID+1).'" />
            </frame>
            <frame posn="-61 45 0">
               <quad sizen="6 3" posn="0 0 0.001" style="BgRaceScore2" substyle="BgScores" action="'.($this->manialinkID+1).'"/>
               <format textsize="1"/>';
      $i = 0; 
      unset($message);
      $users = $this->tsstatus->_serverDatas['virtualserver_clientsonline'] - 1;
      $max = $this->tsstatus->_serverDatas['virtualserver_maxclients'];

      //$message[] = "\$fff TeamSpeak2 status";
      $message[] = "\$fff ".$users." / ".$max;

      foreach ($message as $info) {    
         $y=-2*$i-0.9;
         $xml .= '<label sizen="30 2" halign="left" posn="1 '.$y.' 0.1" text="'.$info.'"/>';
         $i++;
      }
      $xml .='';
      $xml .='
            </frame>
         </manialink>
      </manialinks>';

      $this->Aseco->addCall('SendDisplayManialinkPage', array($xml, 0, false));
   }




   function info_on($login) {
      global $ts3_settings;

      $player = $this->Aseco->server->players->getPlayer($login);
      $style = $player->style;   
      $widths[0] = 1.5;      
      $header = "Teamspeak 3 Status";
      $button = "Close";
      $hsize = $style['HEADER'][0]['TEXTSIZE'][0];
      $bsize = $style['BODY'][0]['TEXTSIZE'][0];
      $lines = 23;
	  $stats = array();

      // build manialink header & window
      $xml = '<?xml version="1.0" encoding="UTF-8"?>
            <manialinks>
               <manialink id="'.($this->manialinkID+4).'">
                  <frame pos="' . ($widths[0]/2) . ' 0.47 0">' .
                     '<quad size="' . $widths[0] . ' ' . (0.11+$hsize+$lines*$bsize) .
                     '" style="' . $style['WINDOW'][0]['STYLE'][0] .
                     '" substyle="' . $style['WINDOW'][0]['SUBSTYLE'][0] . '"/>' . LF;

      // add header and optional icon
      $xml .= '<quad pos="-' . ($widths[0]/2) . ' -0.01 -0.1" size="' . ($widths[0]-0.02) . ' ' . $hsize .
            '" halign="center" style="' . $style['HEADER'][0]['STYLE'][0] .
            '" substyle="' . $style['HEADER'][0]['SUBSTYLE'][0] . '"/>' . LF;
      $isize = $hsize;
      $xml .= '<quad pos="-0.055 -0.045 -0.2" size="' . $isize . ' ' . $isize .
            '" halign="center" valign="center" image="http://koti.mbnet.fi/reaby/xaseco/images/ts3logo.jpg" />' . LF;
      $xml .= '<label pos="-0.10 -0.025 -0.2" size="' . ($widths[0]-0.12) . ' ' . $hsize .
            '" halign="left" style="' . $style['HEADER'][0]['TEXTSTYLE'][0] .
            '" text="' . htmlspecialchars(validateUTF8String($header)) . '"/>' . LF;

      // add body
      $xml .= '<quad pos="-' . ($widths[0]/2) . ' -' . (0.02+$hsize) .
            ' -0.1" size="' . ($widths[0]-0.02) . ' ' . (0.02+$lines*$bsize) .
            '" halign="center" style="' . $style['BODY'][0]['STYLE'][0] .
            '" substyle="' . $style['BODY'][0]['SUBSTYLE'][0] . '"/>' . LF;

      //Throw some text
      $cnt = 1; 
      unset($message);
      $users = $this->tsstatus->_serverDatas['virtualserver_clientsonline'];
	  $users = $users - 1;
      $max = $this->tsstatus->_serverDatas['virtualserver_maxclients'];
   //   $channels = $stats["serverinfo"]["server_currentchannels"];            // umm... think this is from a different script
      $channels = 0;
      foreach ($this->tsstatus->_channelDatas as $channel) {$channels++;}

      $message[] .= "\$fff Server: ".$ts3_settings['server_addr'];
      $message[] .= "\$fff Users: ".$users." / ".$max;
      $message[] .= "\$fff Channels: ".$channels;

      foreach ($message as $info) {    
         $xml .= '<label pos="-0.025 -' . ($hsize-0.008+$cnt*$bsize) .
               ' -0.2" size="' . ($widths[0]-0.04) . ' ' . (0.02+$bsize) .
               '" halign="left" style="' . $style['BODY'][0]['TEXTSTYLE'][0] .
               '" text="' . htmlspecialchars(validateUTF8String($info)) . '"/>' . LF; 
         $cnt++;
      }
      //join server button
      $xml .='<frame  pos="-' . ($widths[0]/2) . ' -' . ($hsize-0.008+20*$bsize) .' -0.1">';

      $cnt+1;
      $xml .='<label posn="-29 0 0.3" style="CardButtonMedium" text="Join server" url="http://koti.mbnet.fi/reaby/xaseco/ts/gateway3.php?server='.$ts3_settings['server_addr'].'&port='.$ts3_settings['serverport'].'" addplayerid="1"/>';
      //$xml .='<label posn="-29 0 0.3" style="CardButtonMedium" text="Join server" url="http://koti.mbnet.fi/reaby/xaseco/ts/gateway.php?value=Inputvalue" />';
      $xml .='</frame>';

      //draw Teamspeak channelbox
      $xml .='
      <frame  pos="-0.825 -' . ($hsize-0.008+1*$bsize) .' 0.1">
      <quad sizen="40 58" posn="0 0 0.001" style="BgsPlayerCard" substyle="BgPlayerName"/>';

      foreach ($this->tsstatus->_channelDatas as $data) {
            $stats[$data["cid"]]["name"] = $data["channel_name"];
         }

      foreach ($this->tsstatus->_userDatas as $data) {
         if (!strstr($data['client_nickname'],"Unknown")) {
            $stats[$data["cid"]]["players"][] = array("name" => $data['client_nickname']);
         }   
      }

      unset($cnt);
      $cnt = 1; 
      $xml .='<format textsize="1" />';

      foreach ($stats as $info) {
         if ($cnt > 20) break;
         $xml .= '<label pos="-0.025 -' . (0.01+$cnt*0.03) . ' -0.2" halign="left" text="$090' . htmlspecialchars(validateUTF8String($info['name'])) . '"/>' . LF; 
         $cnt++;

         if ( count($info['players']) > 0 ) {
            foreach ($info['players'] as $players) {
               $xml .= '<label pos="-0.045 -' . (0.01+$cnt*0.03) . ' -0.2" halign="left" text="' . htmlspecialchars(validateUTF8String($players['name'])) . '"/>' . LF; 
               //      $xml .= '<quad sizen="1.2 1.2" pos="-0.025 -' . (0.01+$cnt*0.03) . ' -0.2" image="http://koti.mbnet.fi/reaby/xaseco/images/player_'.$players['image'] .'.jpg" />';
               $cnt++;
            }
         }
      }


      $xml .='</frame>';

      // add button (action "0" = close) & footer
      $xml .= '<quad pos="-' . ($widths[0]/2) . ' -' . (0.04+$hsize+$lines*$bsize) .
            ' -0.2" size="0.06 0.06" halign="center" style="Icons64x64_1" substyle="Close" action="'.($this->manialinkID+2).'"/>' . LF;
      $xml .= '</frame>';
      $xml = str_replace('{#black}', $style['WINDOW'][0]['BLACKCOLOR'][0], $xml);   

      $xml .='
            </manialink>
            </manialinks>';

      $this->Aseco->addCall('SendDisplayManialinkPageToLogin', array($login, $xml, 0, false));   
   }

   function info_off($login) {
      $xml = '<?xml version="1.0" encoding="UTF-8"?><manialinks><manialink id='.($this->manialinkID+4).'></manialink></manialinks>';
      $this->Aseco->addCall('SendDisplayManialinkPageToLogin', array($login, $xml, 0, false));
   }
} 
?>
Last edited by nocturne on 15 Mar 2010 04:51, edited 3 times in total.

User avatar
Ant
TM-Patrol
TM-Patrol
Posts: 1845
Joined: 01 Dec 2007 17:04
Owned TM-games: TMN, TMUF, TM Wii
Location: London, England
Contact:

Re: [Xaseco] Teamspeak 3 plugin 0.2 updated at 27.2.2010

Post by Ant » 05 Mar 2010 01:10

Cheers for that man, but when I use that code, XAseco crashes when it tries to load the teamspeak3 plugin.

Assembler Maniac
Pit Crew
Pit Crew
Posts: 1493
Joined: 03 Jun 2006 13:24
Owned TM-games: TMU
Contact:

Re: [Xaseco] Teamspeak 3 plugin 0.2 updated at 27.2.2010

Post by Assembler Maniac » 05 Mar 2010 05:27

XXX-Ant wrote:Cheers for that man, but when I use that code, XAseco crashes when it tries to load the teamspeak3 plugin.
You do realize that showing something like an error message would be extremely helpful in finding the problem, right?

User avatar
Ant
TM-Patrol
TM-Patrol
Posts: 1845
Joined: 01 Dec 2007 17:04
Owned TM-games: TMN, TMUF, TM Wii
Location: London, England
Contact:

Re: [Xaseco] Teamspeak 3 plugin 0.2 updated at 27.2.2010

Post by Ant » 05 Mar 2010 18:20

I do yes, but there is no error message, it stops dead at the plugin - i.e the plugin loading is the last entry in the logfile and XAseco doesn't load anymore from there, and therefore doesn't start up. So it crashes at the plugin with no error output.

nocturne
solid chaser
solid chaser
Posts: 1390
Joined: 08 Jun 2007 18:48
Owned TM-games: all
Contact:

Re: [Xaseco] Teamspeak 3 plugin 0.2 updated at 27.2.2010

Post by nocturne » 05 Mar 2010 19:41

Usually just forget a semicolon somewhere... I'll double check it.

User avatar
svens
speedy pilot
speedy pilot
Posts: 304
Joined: 05 Dec 2009 23:30
Owned TM-games: TMUF, TMS, TMO
Location: Bern, CH
Contact:

Re: [Xaseco] Teamspeak 3 plugin 0.2 updated at 27.2.2010

Post by svens » 05 Mar 2010 19:49

After a quick php -l check, line 179:

Code: Select all

      foreach ($this->tsstatus->_channelDatas as $channel) {$channels++};
Semicolon missing in the loop. As you said :).

Code: Select all

      foreach ($this->tsstatus->_channelDatas as $channel) {$channels++;};
Diff (don't mind the file names):
--- ts3o.php 2010-03-05 20:51:56.000000000 +0100
+++ ts3.php 2010-03-05 20:48:50.000000000 +0100
@@ -176,7 +176,7 @@
$max = $this->tsstatus->_serverDatas['virtualserver_maxclients'];
// $channels = $stats["serverinfo"]["server_currentchannels"]; // umm... think this is from a different script
$channels = 0;
- foreach ($this->tsstatus->_channelDatas as $channel) {$channels++};
+ foreach ($this->tsstatus->_channelDatas as $channel) {$channels++;};

$message[] .= "\$fff Server: ".$ts3_settings['server_addr'];
$message[] .= "\$fff Users: ".$users." / ".$max;

nocturne
solid chaser
solid chaser
Posts: 1390
Joined: 08 Jun 2007 18:48
Owned TM-games: all
Contact:

Re: [Xaseco] Teamspeak 3 plugin 0.2 updated at 27.2.2010

Post by nocturne » 05 Mar 2010 20:33

Yep, just fixed the code above... it's always a damn semicolon.. :roflol:

Also changed a few other things above, I think... redundancy issues.

Also..
svens wrote:

Code: Select all

      foreach ($this->tsstatus->_channelDatas as $channel) {$channels++;};
Don't need a semicolon after the loop..

Code: Select all

      foreach ($this->tsstatus->_channelDatas as $channel) {$channels++;}
Edit: Oh, btw... I don't know what the issue was about the player count, so I just forced it to subtract one from the count... that work..?

User avatar
Ant
TM-Patrol
TM-Patrol
Posts: 1845
Joined: 01 Dec 2007 17:04
Owned TM-games: TMN, TMUF, TM Wii
Location: London, England
Contact:

Re: [Xaseco] Teamspeak 3 plugin 0.2 updated at 27.2.2010

Post by Ant » 05 Mar 2010 23:00

Yes it all works nicely now, thanks very much lads :1

The only issue I have with it now, is the update interval, as I said before it still only updates the number of people in the TS server on the icon when the next map loads and not after 30 seconds like I have specified in the xml.

Any ideas on that ??

User avatar
Jelle Mees
smooth traffic navigator
smooth traffic navigator
Posts: 274
Joined: 02 May 2006 08:49
Owned TM-games: TMUF
Location: Belgium ( Limburg )
Contact:

Re: [Xaseco] Teamspeak 3 plugin 0.2 updated at 27.2.2010

Post by Jelle Mees » 05 Mar 2010 23:44

Is it like this in open-source communities? Instead of supporting the guy who released the code you take over and rewrite it? Don't get me rong, I know you are doing it to do good...
ImageImage
Image

User avatar
Ant
TM-Patrol
TM-Patrol
Posts: 1845
Joined: 01 Dec 2007 17:04
Owned TM-games: TMN, TMUF, TM Wii
Location: London, England
Contact:

Re: [Xaseco] Teamspeak 3 plugin 0.2 updated at 27.2.2010

Post by Ant » 06 Mar 2010 00:06

Well i'm sure he won't mind as long as it works nicely - I don't think anything bad was intended here. Also, I think a lot of this code came from the ts2 plugin - unless he wrote that too, cos I can't remember where/who it came from now, but thanks reaby for this plugin originally man - you are doin good work :1

User avatar
svens
speedy pilot
speedy pilot
Posts: 304
Joined: 05 Dec 2009 23:30
Owned TM-games: TMUF, TMS, TMO
Location: Bern, CH
Contact:

Re: [Xaseco] Teamspeak 3 plugin 0.2 updated at 27.2.2010

Post by svens » 06 Mar 2010 00:40

Jelle Mees wrote:Is it like this in open-source communities? Instead of supporting the guy who released the code you take over and rewrite it? Don't get me rong, I know you are doing it to do good...
Well this is the way open source works.. You share your code, others contribute to it and share their modifications too.
What I'd really like to see in the community would be some kind of version control.. Just posting in the same thread leads to many different versions of the same plugin and this decreases maintainability.

Sorry for OT btw.

User avatar
Jelle Mees
smooth traffic navigator
smooth traffic navigator
Posts: 274
Joined: 02 May 2006 08:49
Owned TM-games: TMUF
Location: Belgium ( Limburg )
Contact:

Re: [Xaseco] Teamspeak 3 plugin 0.2 updated at 27.2.2010

Post by Jelle Mees » 06 Mar 2010 00:48

svens wrote:
Jelle Mees wrote:Is it like this in open-source communities? Instead of supporting the guy who released the code you take over and rewrite it? Don't get me rong, I know you are doing it to do good...
Well this is the way open source works.. You share your code, others contribute to it and share their modifications too.
What I'd really like to see in the community would be some kind of version control.. Just posting in the same thread leads to many different versions of the same plugin and this decreases maintainability.

Sorry for OT btw.
That was my point. I think it's better that people who want to support the original writer, that they PM improvements to the code and that the author just gives credit to those who helped on the update. On the other hand, I always look in the first post to see if a script got updated by the original coder.
ImageImage
Image

nocturne
solid chaser
solid chaser
Posts: 1390
Joined: 08 Jun 2007 18:48
Owned TM-games: all
Contact:

Re: [Xaseco] Teamspeak 3 plugin 0.2 updated at 27.2.2010

Post by nocturne » 06 Mar 2010 08:00

Well, it's not exactly like I claimed ownership nor took any credit for a damn thing. Any code I post is usually upon request, or to help out members of the LR community. Throughout my code postings, you'd be hard pressed to find any mention of myself, let alone vainly naming my plugins after myself. Not to mention I don't have two huge annoying links to my servers in my sig.. :lol:

As for how the opensource community should work... I always thought it was all about the free exchange of knowledge, and not worrying about assuming credit for anything contributed.

As for concerns about stating author and version, and the redundancy of posting different versions of plugins within threads... well, that's always going to be an issue. One of the reasons I like Aseco's class based plugin system is the clear definition of author and version, and the ability to explicitly require specific plugin versions for interoperability. Lacking that, comments work well enough. I didn't add any heading comments above because there were none previously, but you'll see plenty of comments throughout the plugin, left for the author to sort through when they get back to it, or to any able others willing to contribute.

As for the update function, I'm pretty sure I know the issue... There's a call to refresh the info, but no actual call to refresh the manialink display.

Edit: Think I may have fixed the update issue... hopefully just calling $ts3->panel_on() works. Updated code above.

User avatar
Ant
TM-Patrol
TM-Patrol
Posts: 1845
Joined: 01 Dec 2007 17:04
Owned TM-games: TMN, TMUF, TM Wii
Location: London, England
Contact:

Re: [Xaseco] Teamspeak 3 plugin 0.2 updated at 27.2.2010

Post by Ant » 06 Mar 2010 16:13

nocturne wrote:Edit: Think I may have fixed the update issue... hopefully just calling $ts3->panel_on() works. Updated code above.
Cheers man, the whole plugin works like a charm now. :mrgreen:

Post Reply