prepare method

This commit is contained in:
kremsy 2014-01-27 20:39:10 +01:00 committed by Steffen Schröder
parent 053649600d
commit be86717c0b
13 changed files with 571 additions and 448 deletions

View File

@ -15,6 +15,14 @@ interface Plugin {
*/
const PLUGIN_INTERFACE = __CLASS__;
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
*/
public static function prepare(ManiaControl $maniaControl);
/**
* Load the plugin
*

View File

@ -30,6 +30,16 @@ class ChatMessagePlugin implements CommandListener, Plugin {
*/
private $maniaControl = null;
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
*/
public static function prepare(ManiaControl $maniaControl) {
// TODO: Implement prepare() method.
}
/**
* Load the plugin
*

View File

@ -1,8 +1,8 @@
<?php
use ManiaControl\FileUtil;
use ManiaControl\ManiaControl;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\FileUtil;
use ManiaControl\ManiaControl;
use ManiaControl\Plugins\Plugin;
/**
@ -31,7 +31,16 @@ class ChatlogPlugin implements CallbackListener, Plugin {
private $logServerMessages = true;
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
*/
public static function prepare(ManiaControl $maniaControl) {
// TODO: Implement prepare() method.
}
/**
* @see \ManiaControl\Plugins\Plugin::load()
*/
public function load(ManiaControl $maniaControl) {
@ -61,8 +70,7 @@ class ChatlogPlugin implements CallbackListener, Plugin {
$pIdPart = '_' . getmypid();
if ($dotIndex !== false && $dotIndex >= 0) {
$fileName = substr($fileName, 0, $dotIndex) . $pIdPart . substr($fileName, $dotIndex);
}
else {
} else {
$fileName .= $pIdPart;
}
}
@ -70,14 +78,12 @@ class ChatlogPlugin implements CallbackListener, Plugin {
$this->logServerMessages = $this->maniaControl->settingManager->getSetting($this, self::SETTING_LOGSERVERMESSAGES);
// Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this,
'handlePlayerChatCallback');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handlePlayerChatCallback');
return true;
}
/**
*
* @see \ManiaControl\Plugins\Plugin::unload()
*/
public function unload() {
@ -86,7 +92,6 @@ class ChatlogPlugin implements CallbackListener, Plugin {
}
/**
*
* @see \ManiaControl\Plugins\Plugin::getId()
*/
public static function getId() {
@ -94,7 +99,6 @@ class ChatlogPlugin implements CallbackListener, Plugin {
}
/**
*
* @see \ManiaControl\Plugins\Plugin::getName()
*/
public static function getName() {
@ -102,7 +106,6 @@ class ChatlogPlugin implements CallbackListener, Plugin {
}
/**
*
* @see \ManiaControl\Plugins\Plugin::getVersion()
*/
public static function getVersion() {
@ -110,7 +113,6 @@ class ChatlogPlugin implements CallbackListener, Plugin {
}
/**
*
* @see \ManiaControl\Plugins\Plugin::getAuthor()
*/
public static function getAuthor() {
@ -118,7 +120,6 @@ class ChatlogPlugin implements CallbackListener, Plugin {
}
/**
*
* @see \ManiaControl\Plugins\Plugin::getDescription()
*/
public static function getDescription() {

View File

@ -84,6 +84,16 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
/** @var Player $voter */
private $voter = null;
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
*/
public static function prepare(ManiaControl $maniaControl) {
// TODO: Implement prepare() method.
}
/**
* Load the plugin
*

View File

@ -43,6 +43,16 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
const SETTING_DONATION_VALUES = 'Donation Values';
const SETTING_MIN_AMOUNT_SHOWN = 'Minimum Donation amount to get shown';
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
*/
public static function prepare(ManiaControl $maniaControl) {
// TODO: Implement prepare() method.
}
/**
* Private properties
*/

View File

@ -27,6 +27,16 @@ class DynamicPointlimitPlugin implements CallbackListener, CommandListener, Plug
const DYNPNT_MIN = 'Minimum pointlimit';
const DYNPNT_MAX = 'Maximum pointlimit';
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
*/
public static function prepare(ManiaControl $maniaControl) {
// TODO: Implement prepare() method.
}
/**
* Private properties
*/

View File

@ -25,6 +25,16 @@ class EndurancePlugin implements CallbackListener, Plugin {
private $currentMap = null;
private $playerLapTimes = array();
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
*/
public static function prepare(ManiaControl $maniaControl) {
// TODO: Implement prepare() method.
}
/**
*
* @see \ManiaControl\Plugins\Plugin::load()

View File

@ -45,6 +45,16 @@ class KarmaPlugin implements CallbackListener, Plugin {
private $updateManialink = false;
private $manialink = null;
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
*/
public static function prepare(ManiaControl $maniaControl) {
// TODO: Implement prepare() method.
}
/**
*
* @see \ManiaControl\Plugins\Plugin::load()

View File

@ -45,6 +45,16 @@ class LocalRecordsPlugin implements CallbackListener, Plugin {
private $maniaControl = null;
private $updateManialink = false;
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
*/
public static function prepare(ManiaControl $maniaControl) {
// TODO: Implement prepare() method.
}
/**
*
* @see \ManiaControl\Plugins\Plugin::load()

View File

@ -29,6 +29,16 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
/** @var maniaControl $maniaControl */
private $maniaControl = null;
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
*/
public static function prepare(ManiaControl $maniaControl) {
// TODO: Implement prepare() method.
}
/**
*
* @see \ManiaControl\Plugins\Plugin::load()

View File

@ -45,6 +45,16 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
private $spectators = array();
private $showPlay = array();
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
*/
public static function prepare(ManiaControl $maniaControl) {
// TODO: Implement prepare() method.
}
/**
* Load the plugin
*

View File

@ -5,13 +5,12 @@ use FML\Controls\Labels\Label_Text;
use FML\Controls\Quad;
use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\ManiaLink;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player;
use ManiaControl\Plugins\Plugin;
@ -22,7 +21,6 @@ use ManiaControl\Plugins\Plugin;
*
* @author TheM
*/
class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPageAnswerListener, Plugin {
/**
* Constants
@ -53,6 +51,16 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag
private $refreshTime = 0;
private $refreshInterval = 90;
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
*/
public static function prepare(ManiaControl $maniaControl) {
// TODO: Implement prepare() method.
}
/**
* Load the plugin
*
@ -93,13 +101,13 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag
* @throws Exception
*/
private function checkConfig() {
if($this->maniaControl->settingManager->getSetting($this, self::TEAMSPEAK_SERVERHOST) == 'ts3.somehoster.com') {
if ($this->maniaControl->settingManager->getSetting($this, self::TEAMSPEAK_SERVERHOST) == 'ts3.somehoster.com') {
$error = 'Missing the required serverhost, please set it up before enabling the TeamSpeak plugin!';
throw new Exception($error);
}
$this->ts3_queryServer(); // Get latest information from the TeamSpeak server
if(!isset($this->serverData['channels']) || count($this->serverData['channels']) == 0) {
if (!isset($this->serverData['channels']) || count($this->serverData['channels']) == 0) {
$error = 'Could not make proper connections with the server!';
throw new Exception($error);
}
@ -226,7 +234,7 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag
$servername->setStyle($servername::STYLE_TextCardMedium);
$servername->setHAlign('left');
$servername->setTextSize(1);
$servername->setText('$oServername:$o '.$this->serverData['server']['virtualserver_name']);
$servername->setText('$oServername:$o ' . $this->serverData['server']['virtualserver_name']);
$servername->setTextColor('fff');
$serverversion = new Label_Text();
@ -236,7 +244,7 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag
$serverversion->setStyle($serverversion::STYLE_TextCardMedium);
$serverversion->setHAlign('left');
$serverversion->setTextSize(1);
$serverversion->setText('$oServerversion:$o '.$this->serverData['server']['virtualserver_version']);
$serverversion->setText('$oServerversion:$o ' . $this->serverData['server']['virtualserver_version']);
$serverversion->setTextColor('fff');
$clients = new Label_Text();
@ -246,7 +254,7 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag
$clients->setStyle($clients::STYLE_TextCardMedium);
$clients->setHAlign('left');
$clients->setTextSize(1);
$clients->setText('$oConnected clients:$o '.$this->serverData['server']['virtualserver_clientsonline'].'/'.$this->serverData['server']['virtualserver_maxclients']);
$clients->setText('$oConnected clients:$o ' . $this->serverData['server']['virtualserver_clientsonline'] . '/' . $this->serverData['server']['virtualserver_maxclients']);
$clients->setTextColor('fff');
$channels = new Label_Text();
@ -258,10 +266,12 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag
$channels->setTextSize(1);
$nochannels = 0;
foreach($this->serverData['channels'] as $channel) {
if($channel['channel_maxclients'] == 0 || strpos($channel['channel_name'], 'spacer') > 0) continue;
if ($channel['channel_maxclients'] == 0 || strpos($channel['channel_name'], 'spacer') > 0) {
continue;
}
$nochannels++;
}
$channels->setText('$oChannels:$o '.$nochannels);
$channels->setText('$oChannels:$o ' . $nochannels);
$channels->setTextColor('fff');
// Join button
@ -270,14 +280,14 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag
$joinbutton->setWidth(150);
$joinbutton->setY($height / 2 - 11.5);
$joinbutton->setStyle($joinbutton::STYLE_CardButtonSmallWide);
$joinbutton->setText('Join TeamSpeak: '.$this->maniaControl->settingManager->getSetting($this, self::TEAMSPEAK_SERVERHOST).':'.$this->maniaControl->settingManager->getSetting($this, self::TEAMSPEAK_SERVERPORT));
$joinbutton->setText('Join TeamSpeak: ' . $this->maniaControl->settingManager->getSetting($this, self::TEAMSPEAK_SERVERHOST) . ':' . $this->maniaControl->settingManager->getSetting($this, self::TEAMSPEAK_SERVERPORT));
$joinbutton->setTextColor('fff');
$url = 'ts3server://'. $this->maniaControl->settingManager->getSetting($this, self::TEAMSPEAK_SERVERHOST) .'/?port='. $this->maniaControl->settingManager->getSetting($this, self::TEAMSPEAK_SERVERPORT) .'&nickname='. rawurlencode(\ManiaControl\Formatter::stripCodes($player->nickname));
$url = 'ts3server://' . $this->maniaControl->settingManager->getSetting($this, self::TEAMSPEAK_SERVERHOST) . '/?port=' . $this->maniaControl->settingManager->getSetting($this, self::TEAMSPEAK_SERVERPORT) . '&nickname=' . rawurlencode(\ManiaControl\Formatter::stripCodes($player->nickname));
$joinbutton->setUrl($url);
$leftlistQuad = new Quad();
$frame->add($leftlistQuad);
$leftlistQuad->setSize((($width/2)-5), ($height-18));
$leftlistQuad->setSize((($width / 2) - 5), ($height - 18));
$leftlistQuad->setX(-36);
$leftlistQuad->setY($height / 2 - 46);
$leftlistQuad->setStyles($quadStyle, $quadSubstyle);
@ -288,36 +298,40 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag
$i = 0;
$startx = -69.5;
foreach($this->serverData['channels'] as $channel) {
if($channel['channel_maxclients'] == 0 || strpos($channel['channel_name'], 'spacer') > 0) continue;
if ($channel['channel_maxclients'] == 0 || strpos($channel['channel_name'], 'spacer') > 0) {
continue;
}
$channels[$i] = new Label_Text();
$frame->add($channels[$i]);
$y = 17.5+($i*2.5);
$y = 17.5 + ($i * 2.5);
$channels[$i]->setY($height / 2 - $y);
$x = $startx;
if($channel['pid'] != 0) {
$x = $startx+5;
if ($channel['pid'] != 0) {
$x = $startx + 5;
}
$channels[$i]->setX($x);
$channels[$i]->setStyle($channels[$i]::STYLE_TextCardMedium);
$channels[$i]->setHAlign('left');
$channels[$i]->setTextSize(1);
$channels[$i]->setScale(0.9);
if($channel['channel_flag_default'] == 1) $channel['total_clients'] = ($channel['total_clients']-1); // remove query client
$channels[$i]->setText('$o'.$channel['channel_name'].'$o ('.$channel['total_clients'].')');
if ($channel['channel_flag_default'] == 1) {
$channel['total_clients'] = ($channel['total_clients'] - 1);
} // remove query client
$channels[$i]->setText('$o' . $channel['channel_name'] . '$o (' . $channel['total_clients'] . ')');
$channels[$i]->setTextColor('fff');
$i++;
foreach($this->serverData['users'] as $user) {
if($user['cid'] == $channel['cid']) {
if ($user['cid'] == $channel['cid']) {
$users[$userid] = new Label_Text();
$frame->add($users[$userid]);
$y = 17.5+($i*2.5);
$y = 17.5 + ($i * 2.5);
$users[$userid]->setY($height / 2 - $y);
$x = $startx;
if($channel['pid'] != 0) {
$x = $startx+7;
if ($channel['pid'] != 0) {
$x = $startx + 7;
} else {
$x = $startx+2;
$x = $startx + 2;
}
$users[$userid]->setX($x);
$users[$userid]->setStyle($users[$userid]::STYLE_TextCardMedium);
@ -329,14 +343,14 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag
$userid++;
$i++;
if($i > 22) {
if ($i > 22) {
$i = 0;
$startx = 2.5;
}
}
}
if($i > 22) {
if ($i > 22) {
$i = 0;
$startx = 2.5;
}
@ -344,7 +358,7 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag
$rightlistQuad = new Quad();
$frame->add($rightlistQuad);
$rightlistQuad->setSize((($width/2)-5), ($height-18));
$rightlistQuad->setSize((($width / 2) - 5), ($height - 18));
$rightlistQuad->setX(36);
$rightlistQuad->setY($height / 2 - 46);
$rightlistQuad->setStyles($quadStyle, $quadSubstyle);
@ -354,16 +368,14 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag
/**
* TeamSpeak related functions
*
* The functions are based upon tsstatus.php from http://tsstatus.sebastien.me/
* and were optimized by SilentStorm.
*
* Functions originally from the TeamSpeakInfo plugin made by undef.de for XAseco(2) and MPAseco.
*/
public function ts3_queryServer() {
if(time() >= $this->refreshTime) {
$this->refreshTime = (time()+$this->refreshInterval);
if (time() >= $this->refreshTime) {
$this->refreshTime = (time() + $this->refreshInterval);
$queryhost = $this->maniaControl->settingManager->getSetting($this, self::TEAMSPEAK_QUERYHOST);
$host = $this->maniaControl->settingManager->getSetting($this, self::TEAMSPEAK_SERVERHOST);
@ -371,25 +383,25 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag
$host = ($queryhost != '') ? $queryhost : $host;
$socket = fsockopen($host, $this->maniaControl->settingManager->getSetting($this, self::TEAMSPEAK_QUERYPORT), $errno, $errstr, 2);
if($socket) {
if ($socket) {
socket_set_timeout($socket, 2);
$is_ts3 = trim(fgets($socket)) == 'TS3';
if(!$is_ts3) {
trigger_error('[TeamSpeakPlugin] Server at "'. $host .'" is not a Teamspeak3-Server or you have setup a bad query-port!', E_USER_WARNING);
if (!$is_ts3) {
trigger_error('[TeamSpeakPlugin] Server at "' . $host . '" is not a Teamspeak3-Server or you have setup a bad query-port!', E_USER_WARNING);
}
$queryuser = $this->maniaControl->settingManager->getSetting($this, self::TEAMSPEAK_QUERYUSER);
$querypass = $this->maniaControl->settingManager->getSetting($this, self::TEAMSPEAK_QUERYPASS);
if(($queryuser != '') && !is_numeric($queryuser) && $queryuser != false && ($querypass != '') && !is_numeric($querypass) && $querypass != false) {
$ret = $this->ts3_sendCommand($socket, 'login client_login_name='. $this->ts3_escape($queryuser) .' client_login_password='. $this->ts3_escape($querypass));
if(stripos($ret, "error id=0") === false) {
if (($queryuser != '') && !is_numeric($queryuser) && $queryuser != false && ($querypass != '') && !is_numeric($querypass) && $querypass != false) {
$ret = $this->ts3_sendCommand($socket, 'login client_login_name=' . $this->ts3_escape($queryuser) . ' client_login_password=' . $this->ts3_escape($querypass));
if (stripos($ret, "error id=0") === false) {
trigger_error("[TeamSpeakPlugin] Failed to authenticate with TS3 Server! Make sure you put the correct username & password in teamspeak.xml", E_USER_WARNING);
return;
}
}
$response = '';
$response .= $this->ts3_sendCommand($socket, 'use sid='.$this->maniaControl->settingManager->getSetting($this, self::TEAMSPEAK_SID));
$response .= $this->ts3_sendCommand($socket, 'use sid=' . $this->maniaControl->settingManager->getSetting($this, self::TEAMSPEAK_SID));
$this->ts3_sendCommand($socket, 'clientupdate client_nickname=' . $this->ts3_escape('ManiaControl Viewer'));
$response .= $this->ts3_sendCommand($socket, 'serverinfo');
$response .= $this->ts3_sendCommand($socket, 'channellist -topic -flags -voice -limits');
@ -399,7 +411,7 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag
fclose($socket);
$lines = explode("error id=0 msg=ok\n\r", $response);
if(count($lines) == 5) {
if (count($lines) == 5) {
$serverdata = $this->ts3_parseLine($lines[1]);
$this->serverData['server'] = $serverdata[0];
$this->serverData['channels'] = $this->ts3_parseLine($lines[2]);
@ -407,7 +419,7 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag
$users = $this->ts3_parseLine($lines[3]);
$this->serverData['users'] = array(); // reset userslist
foreach($users as $user) {
if($user['client_nickname'] != 'ManiaControl Viewer') {
if ($user['client_nickname'] != 'ManiaControl Viewer') {
$this->serverData['users'][] = $user;
}
}
@ -419,24 +431,25 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag
$this->serverData['server']['virtualserver_total_ping'] = intval($this->serverData['server']['virtualserver_total_ping']);
// Format the Date of server startup
$this->serverData['server']['virtualserver_uptime'] = date('Y-m-d H:i:s', (time() - $this->serverData['server']['virtualserver_uptime']) );
$this->serverData['server']['virtualserver_uptime'] = date('Y-m-d H:i:s', (time() - $this->serverData['server']['virtualserver_uptime']));
// Always subtract all Query Clients
$this->serverData['server']['virtualserver_clientsonline'] -= $this->serverData['server']['virtualserver_queryclientsonline'];
}
} else {
trigger_error("[TeamSpeakPlugin] Failed to connect with TS3 server; socket error: ". $errstr ." [". $errno ."]", E_USER_WARNING);
trigger_error("[TeamSpeakPlugin] Failed to connect with TS3 server; socket error: " . $errstr . " [" . $errno . "]", E_USER_WARNING);
}
}
}
/**
* TS Function to send a command to the TeamSpeak server.
*
* @param $socket
* @param $cmd
* @return string
*/
private function ts3_sendCommand ($socket, $cmd) {
private function ts3_sendCommand($socket, $cmd) {
fputs($socket, "$cmd\n");
@ -450,7 +463,7 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag
}*/
$info = array('timed_out' => false);
while (!feof($socket) && !$info['timed_out'] && strpos($response, 'error id=') === false) {
while(!feof($socket) && !$info['timed_out'] && strpos($response, 'error id=') === false) {
$response .= fread($socket, 1024);
$info = stream_get_meta_data($socket);
}
@ -460,10 +473,11 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag
/**
* TS Function used to parse lines in the serverresponse.
*
* @param $rawLine
* @return array
*/
private function ts3_parseLine ($rawLine) {
private function ts3_parseLine($rawLine) {
$datas = array();
$rawItems = explode('|', $rawLine);
@ -488,7 +502,7 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag
* @param $str
* @return mixed
*/
private function ts3_escape ($str) {
private function ts3_escape($str) {
return str_replace(array(chr(92), chr(47), chr(32), chr(124), chr(7), chr(8), chr(12), chr(10), chr(3), chr(9), chr(11)), array('\\\\', "\/", "\s", "\p", "\a", "\b", "\f", "\n", "\r", "\t", "\v"), $str);
}
@ -498,7 +512,8 @@ class TeamSpeakPlugin implements CallbackListener, CommandListener, ManialinkPag
* @param $str
* @return mixed
*/
private function ts3_unescape ($str) {
private function ts3_unescape($str) {
return str_replace(array('\\\\', "\/", "\s", "\p", "\a", "\b", "\f", "\n", "\r", "\t", "\v"), array(chr(92), chr(47), chr(32), chr(124), chr(7), chr(8), chr(12), chr(10), chr(3), chr(9), chr(11)), $str);
}
}

View File

@ -72,6 +72,15 @@ class WidgetPlugin implements CallbackListener, Plugin {
*/
private $maniaControl = null;
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
*/
public static function prepare(ManiaControl $maniaControl) {
// TODO: Implement prepare() method.
}
/**
* Load the plugin