applied common formatting
This commit is contained in:
		@@ -1,13 +1,14 @@
 | 
				
			|||||||
<?php
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace ManiaControl\Bills;
 | 
					namespace ManiaControl\Bills;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use ManiaControl\Players\Player;
 | 
					use ManiaControl\Players\Player;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * ManiaControl BillData Structure
 | 
					 * ManiaControl BillData Structure
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author kremsy
 | 
					 * @author    ManiaControl Team <mail@maniacontrol.com>
 | 
				
			||||||
 * @copyright ManiaControl Copyright © 2014 ManiaControl Team
 | 
					 * @copyright 2014 ManiaControl Team
 | 
				
			||||||
 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
					 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class BillData {
 | 
					class BillData {
 | 
				
			||||||
@@ -23,6 +24,7 @@ class BillData {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Construct new BillData
 | 
						 * Construct new BillData
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
	 * @param mixed  $function
 | 
						 * @param mixed  $function
 | 
				
			||||||
	 * @param Player $player
 | 
						 * @param Player $player
 | 
				
			||||||
	 * @param int    $amount
 | 
						 * @param int    $amount
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,8 +11,8 @@ use Maniaplanet\DedicatedServer\Structures\Bill;
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * ManiaControl Bill-Manager
 | 
					 * ManiaControl Bill-Manager
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author    kremsy
 | 
					 * @author    ManiaControl Team <mail@maniacontrol.com>
 | 
				
			||||||
 * @copyright ManiaControl Copyright © 2014 ManiaControl Team
 | 
					 * @copyright 2014 ManiaControl Team
 | 
				
			||||||
 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
					 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class BillManager implements CallbackListener {
 | 
					class BillManager implements CallbackListener {
 | 
				
			||||||
@@ -103,7 +103,7 @@ class BillManager implements CallbackListener {
 | 
				
			|||||||
		$billData = $this->openBills[$billId];
 | 
							$billData = $this->openBills[$billId];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/** @var BillData $billData */
 | 
							/** @var BillData $billData */
 | 
				
			||||||
		switch($callback[1][1]) {
 | 
							switch ($callback[1][1]) {
 | 
				
			||||||
			case Bill::STATE_PAYED:
 | 
								case Bill::STATE_PAYED:
 | 
				
			||||||
				if ($billData->pay) {
 | 
									if ($billData->pay) {
 | 
				
			||||||
					call_user_func($billData->function, $billData, self::PAYED_FROM_SERVER);
 | 
										call_user_func($billData->function, $billData, self::PAYED_FROM_SERVER);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,14 +2,13 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace ManiaControl;
 | 
					namespace ManiaControl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
 | 
					 | 
				
			||||||
use Maniaplanet\DedicatedServer\Xmlrpc\LoginUnknownException;
 | 
					use Maniaplanet\DedicatedServer\Xmlrpc\LoginUnknownException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Chat Utility Class
 | 
					 * Chat Utility Class
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author steeffeen & kremsy
 | 
					 * @author    ManiaControl Team <mail@maniacontrol.com>
 | 
				
			||||||
 * @copyright ManiaControl Copyright © 2014 ManiaControl Team
 | 
					 * @copyright 2014 ManiaControl Team
 | 
				
			||||||
 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
					 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class Chat {
 | 
					class Chat {
 | 
				
			||||||
@@ -44,19 +43,16 @@ class Chat {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Get prefix
 | 
						 * Send an information message to the given login
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
 | 
						 * @param string      $message
 | 
				
			||||||
 | 
						 * @param string      $login
 | 
				
			||||||
	 * @param string|bool $prefix
 | 
						 * @param string|bool $prefix
 | 
				
			||||||
	 * @return string
 | 
						 * @return bool
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	private function getPrefix($prefix) {	
 | 
						public function sendInformation($message, $login = null, $prefix = true) {
 | 
				
			||||||
		if (is_string($prefix)) {
 | 
							$format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_INFORMATION);
 | 
				
			||||||
			return $prefix;
 | 
							return $this->sendChat($format . $message, $login);
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if ($prefix === true) {
 | 
					 | 
				
			||||||
			return $this->maniaControl->settingManager->getSetting($this, self::SETTING_PREFIX);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return '';
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
@@ -81,25 +77,28 @@ class Chat {
 | 
				
			|||||||
			if (is_object($login) && property_exists($login, 'login')) {
 | 
								if (is_object($login) && property_exists($login, 'login')) {
 | 
				
			||||||
				$login = $login->login;
 | 
									$login = $login->login;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			try{
 | 
								try {
 | 
				
			||||||
				$this->maniaControl->client->chatSendServerMessage($chatMessage, $login);
 | 
									$this->maniaControl->client->chatSendServerMessage($chatMessage, $login);
 | 
				
			||||||
			} catch(LoginUnknownException $e){
 | 
								} catch (LoginUnknownException $e) {
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Send an information message to the given login
 | 
						 * Get prefix
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
	 * @param string      $message
 | 
					 | 
				
			||||||
	 * @param string      $login
 | 
					 | 
				
			||||||
	 * @param string|bool $prefix
 | 
						 * @param string|bool $prefix
 | 
				
			||||||
	 * @return bool
 | 
						 * @return string
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function sendInformation($message, $login = null, $prefix = true) {
 | 
						private function getPrefix($prefix) {
 | 
				
			||||||
		$format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_INFORMATION);
 | 
							if (is_string($prefix)) {
 | 
				
			||||||
		return $this->sendChat($format . $message, $login);
 | 
								return $prefix;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if ($prefix === true) {
 | 
				
			||||||
 | 
								return $this->maniaControl->settingManager->getSetting($this, self::SETTING_PREFIX);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return '';
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
@@ -115,19 +114,6 @@ class Chat {
 | 
				
			|||||||
		return $this->sendChat($format . $message, $login);
 | 
							return $this->sendChat($format . $message, $login);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Send an Error Message to the Chat
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @param string      $message
 | 
					 | 
				
			||||||
	 * @param string      $login
 | 
					 | 
				
			||||||
	 * @param string|bool $prefix
 | 
					 | 
				
			||||||
	 * @return bool
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public function sendError($message, $login = null, $prefix = true) {
 | 
					 | 
				
			||||||
		$format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_ERROR);
 | 
					 | 
				
			||||||
		return $this->sendChat($format . $message, $login);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Send the Exception Information to the Chat
 | 
						 * Send the Exception Information to the Chat
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
@@ -141,6 +127,19 @@ class Chat {
 | 
				
			|||||||
		return $this->sendError($message, $login);
 | 
							return $this->sendError($message, $login);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Send an Error Message to the Chat
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @param string      $message
 | 
				
			||||||
 | 
						 * @param string      $login
 | 
				
			||||||
 | 
						 * @param string|bool $prefix
 | 
				
			||||||
 | 
						 * @return bool
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function sendError($message, $login = null, $prefix = true) {
 | 
				
			||||||
 | 
							$format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_ERROR);
 | 
				
			||||||
 | 
							return $this->sendChat($format . $message, $login);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Send an usage info message to the given login
 | 
						 * Send an usage info message to the given login
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,8 +5,8 @@ namespace ManiaControl;
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * Utility Class offering Methods to convert and use ManiaPlanet Colors
 | 
					 * Utility Class offering Methods to convert and use ManiaPlanet Colors
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author steeffeen
 | 
					 * @author    ManiaControl Team <mail@maniacontrol.com>
 | 
				
			||||||
 * @copyright ManiaControl Copyright © 2014 ManiaControl Team
 | 
					 * @copyright 2014 ManiaControl Team
 | 
				
			||||||
 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
					 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
abstract class ColorUtil {
 | 
					abstract class ColorUtil {
 | 
				
			||||||
@@ -47,9 +47,9 @@ abstract class ColorUtil {
 | 
				
			|||||||
			$value = 1.;
 | 
								$value = 1.;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		$value *= 15.;
 | 
							$value *= 15.;
 | 
				
			||||||
		$value = (int) round($value);
 | 
							$value = (int)round($value);
 | 
				
			||||||
		if ($value < 10) {
 | 
							if ($value < 10) {
 | 
				
			||||||
			return (string) $value;
 | 
								return (string)$value;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		$codes = array(10 => 'a', 11 => 'b', 12 => 'c', 13 => 'd', 14 => 'e', 15 => 'f');
 | 
							$codes = array(10 => 'a', 11 => 'b', 12 => 'c', 13 => 'd', 14 => 'e', 15 => 'f');
 | 
				
			||||||
		return $codes[$value];
 | 
							return $codes[$value];
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,8 +5,8 @@ namespace ManiaControl;
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * Command Line Helper Class
 | 
					 * Command Line Helper Class
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author steeffeen & kremsy
 | 
					 * @author    ManiaControl Team <mail@maniacontrol.com>
 | 
				
			||||||
 * @copyright ManiaControl Copyright © 2014 ManiaControl Team
 | 
					 * @copyright 2014 ManiaControl Team
 | 
				
			||||||
 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
					 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class CommandLineHelper {
 | 
					class CommandLineHelper {
 | 
				
			||||||
@@ -19,7 +19,7 @@ class CommandLineHelper {
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	public static function getParameter($paramName) {
 | 
						public static function getParameter($paramName) {
 | 
				
			||||||
		global $argv;
 | 
							global $argv;
 | 
				
			||||||
		$paramName = (string) $paramName;
 | 
							$paramName = (string)$paramName;
 | 
				
			||||||
		foreach ($argv as $arg) {
 | 
							foreach ($argv as $arg) {
 | 
				
			||||||
			$parts = explode('=', $arg, 2);
 | 
								$parts = explode('=', $arg, 2);
 | 
				
			||||||
			if (count($parts) < 2) {
 | 
								if (count($parts) < 2) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,8 +8,8 @@ use ManiaControl\Players\Player;
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * Interface for Configurator Menus
 | 
					 * Interface for Configurator Menus
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author steeffeen & kremsy
 | 
					 * @author    ManiaControl Team <mail@maniacontrol.com>
 | 
				
			||||||
 * @copyright ManiaControl Copyright © 2014 ManiaControl Team
 | 
					 * @copyright 2014 ManiaControl Team
 | 
				
			||||||
 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
					 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
interface ConfiguratorMenu {
 | 
					interface ConfiguratorMenu {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,8 +8,8 @@ use ManiaControl\ManiaControl;
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * Database Connection Class
 | 
					 * Database Connection Class
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author steeffeen & kremsy
 | 
					 * @author    ManiaControl Team <mail@maniacontrol.com>
 | 
				
			||||||
 * @copyright ManiaControl Copyright © 2014 ManiaControl Team
 | 
					 * @copyright 2014 ManiaControl Team
 | 
				
			||||||
 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
					 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class Database implements TimerListener {
 | 
					class Database implements TimerListener {
 | 
				
			||||||
@@ -49,10 +49,10 @@ class Database implements TimerListener {
 | 
				
			|||||||
			trigger_error("Invalid database configuration (pass).", E_USER_ERROR);
 | 
								trigger_error("Invalid database configuration (pass).", E_USER_ERROR);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$host = (string) $host[0];
 | 
							$host = (string)$host[0];
 | 
				
			||||||
		$port = (int) $port[0];
 | 
							$port = (int)$port[0];
 | 
				
			||||||
		$user = (string) $user[0];
 | 
							$user = (string)$user[0];
 | 
				
			||||||
		$pass = (string) $pass[0];
 | 
							$pass = (string)$pass[0];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Enable mysqli Reconnect
 | 
							// Enable mysqli Reconnect
 | 
				
			||||||
		ini_set('mysqli.reconnect', 'on');
 | 
							ini_set('mysqli.reconnect', 'on');
 | 
				
			||||||
@@ -74,26 +74,6 @@ class Database implements TimerListener {
 | 
				
			|||||||
		$this->migrationHelper = new MigrationHelper($maniaControl);
 | 
							$this->migrationHelper = new MigrationHelper($maniaControl);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Check if Connection still exists every 5 seconds
 | 
					 | 
				
			||||||
	 * 
 | 
					 | 
				
			||||||
	 * @param $time
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public function checkConnection($time) {
 | 
					 | 
				
			||||||
		if (!$this->mysqli->ping()) {
 | 
					 | 
				
			||||||
			$this->maniaControl->quit("The MySQL server has gone away");
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Destruct database connection
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public function __destruct() {
 | 
					 | 
				
			||||||
		if ($this->mysqli) {
 | 
					 | 
				
			||||||
			$this->mysqli->close();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Connect to the defined database (create it if needed)
 | 
						 * Connect to the defined database (create it if needed)
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
@@ -105,11 +85,13 @@ class Database implements TimerListener {
 | 
				
			|||||||
			trigger_error("Invalid database configuration (database).", E_USER_ERROR);
 | 
								trigger_error("Invalid database configuration (database).", E_USER_ERROR);
 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		$dbName = (string) $dbName[0];
 | 
							$dbName = (string)$dbName[0];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Try to connect
 | 
							// Try to connect
 | 
				
			||||||
		$result = $this->mysqli->select_db($dbName);
 | 
							$result = $this->mysqli->select_db($dbName);
 | 
				
			||||||
		if ($result) return true;
 | 
							if ($result) {
 | 
				
			||||||
 | 
								return true;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Create database
 | 
							// Create database
 | 
				
			||||||
		$databaseQuery     = "CREATE DATABASE ?;";
 | 
							$databaseQuery     = "CREATE DATABASE ?;";
 | 
				
			||||||
@@ -171,4 +153,24 @@ class Database implements TimerListener {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Check if Connection still exists every 5 seconds
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @param $time
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function checkConnection($time) {
 | 
				
			||||||
 | 
							if (!$this->mysqli->ping()) {
 | 
				
			||||||
 | 
								$this->maniaControl->quit("The MySQL server has gone away");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Destruct database connection
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function __destruct() {
 | 
				
			||||||
 | 
							if ($this->mysqli) {
 | 
				
			||||||
 | 
								$this->mysqli->close();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,14 +2,14 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace ManiaControl\Database;
 | 
					namespace ManiaControl\Database;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use ManiaControl\Settings\SettingManager;
 | 
					 | 
				
			||||||
use ManiaControl\ManiaControl;
 | 
					use ManiaControl\ManiaControl;
 | 
				
			||||||
 | 
					use ManiaControl\Settings\SettingManager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Database Migration Assistant
 | 
					 * Database Migration Assistant
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author steeffeen
 | 
					 * @author    ManiaControl Team <mail@maniacontrol.com>
 | 
				
			||||||
 * @copyright ManiaControl Copyright © 2014 ManiaControl Team
 | 
					 * @copyright 2014 ManiaControl Team
 | 
				
			||||||
 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
					 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class MigrationHelper {
 | 
					class MigrationHelper {
 | 
				
			||||||
@@ -68,6 +68,6 @@ class MigrationHelper {
 | 
				
			|||||||
		if (is_object($class)) {
 | 
							if (is_object($class)) {
 | 
				
			||||||
			return get_class($class);
 | 
								return get_class($class);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return (string) $class;
 | 
							return (string)$class;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,8 +8,8 @@ use ManiaControl\Update\UpdateManager;
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * Error and Exception Manager Class
 | 
					 * Error and Exception Manager Class
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author steeffeen & kremsy
 | 
					 * @author    ManiaControl Team <mail@maniacontrol.com>
 | 
				
			||||||
 * @copyright ManiaControl Copyright © 2014 ManiaControl Team
 | 
					 * @copyright 2014 ManiaControl Team
 | 
				
			||||||
 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
					 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class ErrorHandler {
 | 
					class ErrorHandler {
 | 
				
			||||||
@@ -64,16 +64,14 @@ class ErrorHandler {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			if ($this->maniaControl->server) {
 | 
								if ($this->maniaControl->server) {
 | 
				
			||||||
				$error['ServerLogin'] = $this->maniaControl->server->login;
 | 
									$error['ServerLogin'] = $this->maniaControl->server->login;
 | 
				
			||||||
			}
 | 
								} else {
 | 
				
			||||||
			else {
 | 
					 | 
				
			||||||
				$error['ServerLogin'] = '';
 | 
									$error['ServerLogin'] = '';
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if ($this->maniaControl->settingManager && $this->maniaControl->updateManager) {
 | 
								if ($this->maniaControl->settingManager && $this->maniaControl->updateManager) {
 | 
				
			||||||
				$error['UpdateChannel']       = $this->maniaControl->settingManager->getSetting($this->maniaControl->updateManager, UpdateManager::SETTING_UPDATECHECK_CHANNEL);
 | 
									$error['UpdateChannel']       = $this->maniaControl->settingManager->getSetting($this->maniaControl->updateManager, UpdateManager::SETTING_UPDATECHECK_CHANNEL);
 | 
				
			||||||
				$error['ManiaControlVersion'] = $this->maniaControl->updateManager->getNightlyBuildDate();
 | 
									$error['ManiaControlVersion'] = $this->maniaControl->updateManager->getNightlyBuildDate();
 | 
				
			||||||
			}
 | 
								} else {
 | 
				
			||||||
			else {
 | 
					 | 
				
			||||||
				$error['UpdateChannel']       = '';
 | 
									$error['UpdateChannel']       = '';
 | 
				
			||||||
				$error['ManiaControlVersion'] = ManiaControl::VERSION;
 | 
									$error['ManiaControlVersion'] = ManiaControl::VERSION;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@@ -86,8 +84,7 @@ class ErrorHandler {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			if (!json_decode($success)) {
 | 
								if (!json_decode($success)) {
 | 
				
			||||||
				logMessage("Exception-Report failed!");
 | 
									logMessage("Exception-Report failed!");
 | 
				
			||||||
			}
 | 
								} else {
 | 
				
			||||||
			else {
 | 
					 | 
				
			||||||
				logMessage("Exception successfully reported!");
 | 
									logMessage("Exception successfully reported!");
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -100,6 +97,28 @@ class ErrorHandler {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Test if ManiaControl should restart automatically
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @return bool
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						private function shouldRestart() {
 | 
				
			||||||
 | 
							if (!$this->maniaControl || !$this->maniaControl->settingManager) {
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							$setting = $this->maniaControl->settingManager->getSetting($this, self::SETTING_RESTART_ON_EXCEPTION, true);
 | 
				
			||||||
 | 
							return $setting;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Triggers a Debug Notice to the ManiaControl Website
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @param $message
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function triggerDebugNotice($message) {
 | 
				
			||||||
 | 
							$this->errorHandler(self::MC_DEBUG_NOTICE, $message);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Error Handler
 | 
						 * Error Handler
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
@@ -136,16 +155,14 @@ class ErrorHandler {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			if ($this->maniaControl->server) {
 | 
								if ($this->maniaControl->server) {
 | 
				
			||||||
				$error['ServerLogin'] = $this->maniaControl->server->login;
 | 
									$error['ServerLogin'] = $this->maniaControl->server->login;
 | 
				
			||||||
			}
 | 
								} else {
 | 
				
			||||||
			else {
 | 
					 | 
				
			||||||
				$error['ServerLogin'] = '';
 | 
									$error['ServerLogin'] = '';
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if ($this->maniaControl->settingManager && $this->maniaControl->updateManager) {
 | 
								if ($this->maniaControl->settingManager && $this->maniaControl->updateManager) {
 | 
				
			||||||
				$error['UpdateChannel']       = $this->maniaControl->settingManager->getSetting($this->maniaControl->updateManager, UpdateManager::SETTING_UPDATECHECK_CHANNEL);
 | 
									$error['UpdateChannel']       = $this->maniaControl->settingManager->getSetting($this->maniaControl->updateManager, UpdateManager::SETTING_UPDATECHECK_CHANNEL);
 | 
				
			||||||
				$error['ManiaControlVersion'] = ManiaControl::VERSION . '#' . $this->maniaControl->updateManager->getNightlyBuildDate();
 | 
									$error['ManiaControlVersion'] = ManiaControl::VERSION . '#' . $this->maniaControl->updateManager->getNightlyBuildDate();
 | 
				
			||||||
			}
 | 
								} else {
 | 
				
			||||||
			else {
 | 
					 | 
				
			||||||
				$error['UpdateChannel']       = '';
 | 
									$error['UpdateChannel']       = '';
 | 
				
			||||||
				$error['ManiaControlVersion'] = ManiaControl::VERSION;
 | 
									$error['ManiaControlVersion'] = ManiaControl::VERSION;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@@ -158,8 +175,7 @@ class ErrorHandler {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			if (!json_decode($success)) {
 | 
								if (!json_decode($success)) {
 | 
				
			||||||
				logMessage("Error-Report failed!");
 | 
									logMessage("Error-Report failed!");
 | 
				
			||||||
			}
 | 
								} else {
 | 
				
			||||||
			else {
 | 
					 | 
				
			||||||
				logMessage("Error successfully reported!");
 | 
									logMessage("Error successfully reported!");
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -180,15 +196,6 @@ class ErrorHandler {
 | 
				
			|||||||
		return ($errorNumber === E_USER_ERROR || $errorNumber === E_USER_WARNING || $errorNumber === E_USER_NOTICE || $errorNumber === E_USER_DEPRECATED);
 | 
							return ($errorNumber === E_USER_ERROR || $errorNumber === E_USER_WARNING || $errorNumber === E_USER_NOTICE || $errorNumber === E_USER_DEPRECATED);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Triggers a Debug Notice to the ManiaControl Website
 | 
					 | 
				
			||||||
	 * 
 | 
					 | 
				
			||||||
	 * @param $message
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public function triggerDebugNotice($message) {
 | 
					 | 
				
			||||||
		$this->errorHandler(self::MC_DEBUG_NOTICE, $message);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Get the Prefix for the given Error Level
 | 
						 * Get the Prefix for the given Error Level
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
@@ -229,29 +236,6 @@ class ErrorHandler {
 | 
				
			|||||||
		return "[PHP {$errorLevel}]";
 | 
							return "[PHP {$errorLevel}]";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Test if ManiaControl should stop its Execution
 | 
					 | 
				
			||||||
	 * 
 | 
					 | 
				
			||||||
	 * @param int $errorNumber
 | 
					 | 
				
			||||||
	 * @return bool
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	private function shouldStopExecution($errorNumber) {
 | 
					 | 
				
			||||||
		return ($errorNumber === E_ERROR || $errorNumber === E_USER_ERROR || $errorNumber === E_FATAL);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Test if ManiaControl should restart automatically
 | 
					 | 
				
			||||||
	 * 
 | 
					 | 
				
			||||||
	 * @return bool
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	private function shouldRestart() {
 | 
					 | 
				
			||||||
		if (!$this->maniaControl || !$this->maniaControl->settingManager) {
 | 
					 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		$setting = $this->maniaControl->settingManager->getSetting($this, self::SETTING_RESTART_ON_EXCEPTION, true);
 | 
					 | 
				
			||||||
		return $setting;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Parse the Debug Backtrace into a String for the Error Report
 | 
						 * Parse the Debug Backtrace into a String for the Error Report
 | 
				
			||||||
	 * return string
 | 
						 * return string
 | 
				
			||||||
@@ -282,4 +266,14 @@ class ErrorHandler {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		return $traceString;
 | 
							return $traceString;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Test if ManiaControl should stop its Execution
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @param int $errorNumber
 | 
				
			||||||
 | 
						 * @return bool
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						private function shouldStopExecution($errorNumber) {
 | 
				
			||||||
 | 
							return ($errorNumber === E_ERROR || $errorNumber === E_USER_ERROR || $errorNumber === E_FATAL);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
} 
 | 
					} 
 | 
				
			||||||
@@ -11,8 +11,8 @@ use ManiaControl\ManiaControl;
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * Asynchronous File Reader
 | 
					 * Asynchronous File Reader
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author kremsy
 | 
					 * @author    ManiaControl Team <mail@maniacontrol.com>
 | 
				
			||||||
 * @copyright ManiaControl Copyright © 2014 ManiaControl Team
 | 
					 * @copyright 2014 ManiaControl Team
 | 
				
			||||||
 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
					 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class AsynchronousFileReader {
 | 
					class AsynchronousFileReader {
 | 
				
			||||||
@@ -35,13 +35,13 @@ class AsynchronousFileReader {
 | 
				
			|||||||
	 * Appends the Data
 | 
						 * Appends the Data
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function appendData() {
 | 
						public function appendData() {
 | 
				
			||||||
		foreach($this->requests as $key => $request) {
 | 
							foreach ($this->requests as $key => $request) {
 | 
				
			||||||
			/** @var Request $request */
 | 
								/** @var Request $request */
 | 
				
			||||||
			try {
 | 
								try {
 | 
				
			||||||
				if ($request->socketPerform()) {
 | 
									if ($request->socketPerform()) {
 | 
				
			||||||
					$request->socketSelect();
 | 
										$request->socketSelect();
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			} catch(Exception $e) {
 | 
								} catch (Exception $e) {
 | 
				
			||||||
				if ($e->getMessage() == "Cannot perform if there are no requests in queue.") {
 | 
									if ($e->getMessage() == "Cannot perform if there are no requests in queue.") {
 | 
				
			||||||
					unset($this->requests[$key]);
 | 
										unset($this->requests[$key]);
 | 
				
			||||||
				} else {
 | 
									} else {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,13 +1,14 @@
 | 
				
			|||||||
<?php
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace ManiaControl\Files;
 | 
					namespace ManiaControl\Files;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use ManiaControl\ManiaControl;
 | 
					use ManiaControl\ManiaControl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Backup Utility Class
 | 
					 * Backup Utility Class
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author ManiaControl Team
 | 
					 * @author    ManiaControl Team <mail@maniacontrol.com>
 | 
				
			||||||
 * @copyright ManiaControl Copyright © 2014 ManiaControl Team
 | 
					 * @copyright 2014 ManiaControl Team
 | 
				
			||||||
 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
					 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
abstract class BackupUtil {
 | 
					abstract class BackupUtil {
 | 
				
			||||||
@@ -25,7 +26,7 @@ abstract class BackupUtil {
 | 
				
			|||||||
		$backupFolder   = self::getBackupFolder();
 | 
							$backupFolder   = self::getBackupFolder();
 | 
				
			||||||
		$backupFileName = $backupFolder . 'backup_' . ManiaControl::VERSION . '_' . date('y-m-d') . '_' . time() . '.zip';
 | 
							$backupFileName = $backupFolder . 'backup_' . ManiaControl::VERSION . '_' . date('y-m-d') . '_' . time() . '.zip';
 | 
				
			||||||
		$backupZip      = new \ZipArchive();
 | 
							$backupZip      = new \ZipArchive();
 | 
				
			||||||
		if ($backupZip->open($backupFileName, \ZipArchive::CREATE) !== TRUE) {
 | 
							if ($backupZip->open($backupFileName, \ZipArchive::CREATE) !== true) {
 | 
				
			||||||
			trigger_error("Couldn't create Backup Zip!");
 | 
								trigger_error("Couldn't create Backup Zip!");
 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -39,29 +40,6 @@ abstract class BackupUtil {
 | 
				
			|||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Perform a Backup of the Plugins
 | 
					 | 
				
			||||||
	 * 
 | 
					 | 
				
			||||||
	 * @return bool
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public static function performPluginsBackup() {
 | 
					 | 
				
			||||||
		$backupFolder = self::getBackupFolder();
 | 
					 | 
				
			||||||
		$backupFileName = $backupFolder . 'backup_plugins_' . date('y-m-d') . '_' . time() . '.zip';
 | 
					 | 
				
			||||||
		$backupZip = new \ZipArchive();
 | 
					 | 
				
			||||||
		if ($backupZip->open($backupFileName, \ZipArchive::CREATE) !== TRUE) {
 | 
					 | 
				
			||||||
			trigger_error("Couldn't create Backup Zip!");
 | 
					 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		$excludes = array('.', '..');
 | 
					 | 
				
			||||||
		$pathInfo = pathInfo(ManiaControlDir . '/plugins');
 | 
					 | 
				
			||||||
		$parentPath = $pathInfo['dirname'] . '/';
 | 
					 | 
				
			||||||
		$dirName = $pathInfo['basename'];
 | 
					 | 
				
			||||||
		$backupZip->addEmptyDir($dirName);
 | 
					 | 
				
			||||||
		self::zipDirectory($backupZip, ManiaControlDir . '/plugins', strlen($parentPath), $excludes);
 | 
					 | 
				
			||||||
		$backupZip->close();
 | 
					 | 
				
			||||||
		return true;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Get the Backup Folder Path and create it if necessary
 | 
						 * Get the Backup Folder Path and create it if necessary
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
@@ -109,4 +87,27 @@ abstract class BackupUtil {
 | 
				
			|||||||
		closedir($folderHandle);
 | 
							closedir($folderHandle);
 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Perform a Backup of the Plugins
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @return bool
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public static function performPluginsBackup() {
 | 
				
			||||||
 | 
							$backupFolder   = self::getBackupFolder();
 | 
				
			||||||
 | 
							$backupFileName = $backupFolder . 'backup_plugins_' . date('y-m-d') . '_' . time() . '.zip';
 | 
				
			||||||
 | 
							$backupZip      = new \ZipArchive();
 | 
				
			||||||
 | 
							if ($backupZip->open($backupFileName, \ZipArchive::CREATE) !== true) {
 | 
				
			||||||
 | 
								trigger_error("Couldn't create Backup Zip!");
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							$excludes   = array('.', '..');
 | 
				
			||||||
 | 
							$pathInfo   = pathInfo(ManiaControlDir . '/plugins');
 | 
				
			||||||
 | 
							$parentPath = $pathInfo['dirname'] . '/';
 | 
				
			||||||
 | 
							$dirName    = $pathInfo['basename'];
 | 
				
			||||||
 | 
							$backupZip->addEmptyDir($dirName);
 | 
				
			||||||
 | 
							self::zipDirectory($backupZip, ManiaControlDir . '/plugins', strlen($parentPath), $excludes);
 | 
				
			||||||
 | 
							$backupZip->close();
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,14 +2,14 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace ManiaControl\Files;
 | 
					namespace ManiaControl\Files;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use ManiaControl\ManiaControl;
 | 
					 | 
				
			||||||
use ManiaControl\Formatter;
 | 
					use ManiaControl\Formatter;
 | 
				
			||||||
 | 
					use ManiaControl\ManiaControl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Files Utility Class
 | 
					 * Files Utility Class
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author steeffeen & kremsy
 | 
					 * @author    ManiaControl Team <mail@maniacontrol.com>
 | 
				
			||||||
 * @copyright ManiaControl Copyright © 2014 ManiaControl Team
 | 
					 * @copyright 2014 ManiaControl Team
 | 
				
			||||||
 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
					 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
abstract class FileUtil {
 | 
					abstract class FileUtil {
 | 
				
			||||||
@@ -100,6 +100,16 @@ abstract class FileUtil {
 | 
				
			|||||||
		return $fileName;
 | 
							return $fileName;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Delete the Temporary Folder if it's empty
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @return bool
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public static function removeTempFolder() {
 | 
				
			||||||
 | 
							$tempFolder = self::getTempFolder(false);
 | 
				
			||||||
 | 
							return @rmdir($tempFolder);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Get the Temporary Folder and create it if necessary
 | 
						 * Get the Temporary Folder and create it if necessary
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
@@ -114,16 +124,6 @@ abstract class FileUtil {
 | 
				
			|||||||
		return $tempFolder;
 | 
							return $tempFolder;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Delete the Temporary Folder if it's empty
 | 
					 | 
				
			||||||
	 * 
 | 
					 | 
				
			||||||
	 * @return bool
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public static function removeTempFolder() {
 | 
					 | 
				
			||||||
		$tempFolder = self::getTempFolder(false);
 | 
					 | 
				
			||||||
		return @rmdir($tempFolder);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Check if ManiaControl has sufficient Access to write to Files in the given Directories
 | 
						 * Check if ManiaControl has sufficient Access to write to Files in the given Directories
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,8 +5,8 @@ namespace ManiaControl;
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * Class offering Methods to format Texts and Values
 | 
					 * Class offering Methods to format Texts and Values
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author steeffeen & kremsy
 | 
					 * @author    ManiaControl Team <mail@maniacontrol.com>
 | 
				
			||||||
 * @copyright ManiaControl Copyright © 2014 ManiaControl Team
 | 
					 * @copyright 2014 ManiaControl Team
 | 
				
			||||||
 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
					 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
abstract class Formatter {
 | 
					abstract class Formatter {
 | 
				
			||||||
@@ -68,7 +68,7 @@ abstract class Formatter {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		$a = array(12 * 30 * 24 * 60 * 60 => 'year', 30 * 24 * 60 * 60 => 'month', 24 * 60 * 60 => 'day', 60 * 60 => 'hour', 60 => 'minute', 1 => 'second');
 | 
							$a = array(12 * 30 * 24 * 60 * 60 => 'year', 30 * 24 * 60 * 60 => 'month', 24 * 60 * 60 => 'day', 60 * 60 => 'hour', 60 => 'minute', 1 => 'second');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		foreach($a as $secs => $str) {
 | 
							foreach ($a as $secs => $str) {
 | 
				
			||||||
			$d = $etime / $secs;
 | 
								$d = $etime / $secs;
 | 
				
			||||||
			if ($d >= 1) {
 | 
								if ($d >= 1) {
 | 
				
			||||||
				$r = round($d);
 | 
									$r = round($d);
 | 
				
			||||||
@@ -111,6 +111,16 @@ abstract class Formatter {
 | 
				
			|||||||
		return $string;
 | 
							return $string;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Remove Links from the String
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @param string $string
 | 
				
			||||||
 | 
						 * @return string
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public static function stripLinks($string) {
 | 
				
			||||||
 | 
							return preg_replace('/(?<!\$)((?:\$\$)*)\$[hlp](?:\[.*?\])?(.*?)(?:\$[hlp]|(\$z)|$)/iu', '$1$2$3', $string);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Remove all Codes from the String
 | 
						 * Remove all Codes from the String
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
@@ -124,16 +134,6 @@ abstract class Formatter {
 | 
				
			|||||||
		return $string;
 | 
							return $string;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Remove Links from the String
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @param string $string
 | 
					 | 
				
			||||||
	 * @return string
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public static function stripLinks($string) {
 | 
					 | 
				
			||||||
		return preg_replace('/(?<!\$)((?:\$\$)*)\$[hlp](?:\[.*?\])?(.*?)(?:\$[hlp]|(\$z)|$)/iu', '$1$2$3', $string);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Remove Colors from the String
 | 
						 * Remove Colors from the String
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,6 +11,7 @@ use ManiaControl\Callbacks\TimerManager;
 | 
				
			|||||||
use ManiaControl\Commands\CommandListener;
 | 
					use ManiaControl\Commands\CommandListener;
 | 
				
			||||||
use ManiaControl\Commands\CommandManager;
 | 
					use ManiaControl\Commands\CommandManager;
 | 
				
			||||||
use ManiaControl\Configurators\Configurator;
 | 
					use ManiaControl\Configurators\Configurator;
 | 
				
			||||||
 | 
					use ManiaControl\Database\Database;
 | 
				
			||||||
use ManiaControl\Files\AsynchronousFileReader;
 | 
					use ManiaControl\Files\AsynchronousFileReader;
 | 
				
			||||||
use ManiaControl\Files\FileUtil;
 | 
					use ManiaControl\Files\FileUtil;
 | 
				
			||||||
use ManiaControl\Manialinks\ManialinkManager;
 | 
					use ManiaControl\Manialinks\ManialinkManager;
 | 
				
			||||||
@@ -26,7 +27,6 @@ use Maniaplanet\DedicatedServer\Connection;
 | 
				
			|||||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
 | 
					use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
 | 
				
			||||||
use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
 | 
					use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
 | 
				
			||||||
use Maniaplanet\DedicatedServer\Xmlrpc\TransportException;
 | 
					use Maniaplanet\DedicatedServer\Xmlrpc\TransportException;
 | 
				
			||||||
use ManiaControl\Database\Database;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
require_once __DIR__ . '/Libs/Maniaplanet/DedicatedServer/Connection.php';
 | 
					require_once __DIR__ . '/Libs/Maniaplanet/DedicatedServer/Connection.php';
 | 
				
			||||||
require_once __DIR__ . '/Libs/GbxDataFetcher/gbxdatafetcher.inc.php';
 | 
					require_once __DIR__ . '/Libs/GbxDataFetcher/gbxdatafetcher.inc.php';
 | 
				
			||||||
@@ -37,8 +37,8 @@ require_once __DIR__ . '/Libs/curl-easy/autoload.php';
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * ManiaControl Server Controller for ManiaPlanet Server
 | 
					 * ManiaControl Server Controller for ManiaPlanet Server
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author ManiaControl Team
 | 
					 * @author    ManiaControl Team <mail@maniacontrol.com>
 | 
				
			||||||
 * @copyright ManiaControl Copyright © 2014 ManiaControl Team
 | 
					 * @copyright 2014 ManiaControl Team
 | 
				
			||||||
 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
					 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class ManiaControl implements CommandListener, TimerListener {
 | 
					class ManiaControl implements CommandListener, TimerListener {
 | 
				
			||||||
@@ -66,7 +66,6 @@ class ManiaControl implements CommandListener, TimerListener {
 | 
				
			|||||||
	public $config = null;
 | 
						public $config = null;
 | 
				
			||||||
	public $configurator = null;
 | 
						public $configurator = null;
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @var Connection $client
 | 
						 * @var Connection $client
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public $client = null;
 | 
						public $client = null;
 | 
				
			||||||
@@ -137,6 +136,19 @@ class ManiaControl implements CommandListener, TimerListener {
 | 
				
			|||||||
		$this->errorHandler->init();
 | 
							$this->errorHandler->init();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Print a message to console and log
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @param string $message
 | 
				
			||||||
 | 
						 * @param bool   $stripCodes
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function log($message, $stripCodes = false) {
 | 
				
			||||||
 | 
							if ($stripCodes) {
 | 
				
			||||||
 | 
								$message = Formatter::stripCodes($message);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							logMessage($message);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Load the Config XML-File
 | 
						 * Load the Config XML-File
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
@@ -163,41 +175,6 @@ class ManiaControl implements CommandListener, TimerListener {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Print a message to console and log
 | 
					 | 
				
			||||||
	 * 
 | 
					 | 
				
			||||||
	 * @param string $message
 | 
					 | 
				
			||||||
	 * @param bool $stripCodes
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public function log($message, $stripCodes = false) {
 | 
					 | 
				
			||||||
		if ($stripCodes) {
 | 
					 | 
				
			||||||
			$message = Formatter::stripCodes($message);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		logMessage($message);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Get the Operating System on which ManiaControl is running
 | 
					 | 
				
			||||||
	 * 
 | 
					 | 
				
			||||||
	 * @param string $compareOS
 | 
					 | 
				
			||||||
	 * @return string
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public function getOS($compareOS = null) {
 | 
					 | 
				
			||||||
		$windows = defined('PHP_WINDOWS_VERSION_MAJOR');
 | 
					 | 
				
			||||||
		if ($compareOS) {
 | 
					 | 
				
			||||||
			// Return bool whether OS equals $compareOS
 | 
					 | 
				
			||||||
			if ($compareOS == self::OS_WIN) {
 | 
					 | 
				
			||||||
				return $windows;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			return !$windows;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		// Return OS
 | 
					 | 
				
			||||||
		if ($windows) {
 | 
					 | 
				
			||||||
			return self::OS_WIN;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return self::OS_UNIX;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Handle Version Command
 | 
						 * Handle Version Command
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
@@ -223,6 +200,60 @@ class ManiaControl implements CommandListener, TimerListener {
 | 
				
			|||||||
		$this->restart("ManiaControl Restart requested by '{$player->login}'!");
 | 
							$this->restart("ManiaControl Restart requested by '{$player->login}'!");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Restart ManiaControl
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @param string $message
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function restart($message = null) {
 | 
				
			||||||
 | 
							// Shutdown callback
 | 
				
			||||||
 | 
							$this->callbackManager->triggerCallback(CallbackManager::CB_ONSHUTDOWN);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Announce restart
 | 
				
			||||||
 | 
							$this->chat->sendInformation('Restarting ManiaControl...');
 | 
				
			||||||
 | 
							if ($message) {
 | 
				
			||||||
 | 
								$this->log($message);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Hide widgets
 | 
				
			||||||
 | 
							$this->client->sendHideManialinkPage();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$this->log('Restarting ManiaControl!');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Execute start script in background
 | 
				
			||||||
 | 
							// TODO: restart the .php script itself ($_SERVER['scriptname'] or something + $argv)
 | 
				
			||||||
 | 
							if ($this->getOS(self::OS_UNIX)) {
 | 
				
			||||||
 | 
								$command = 'sh ' . escapeshellarg(ManiaControlDir . '/ManiaControl.sh') . ' > /dev/null &';
 | 
				
			||||||
 | 
								exec($command);
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								$command = escapeshellarg(ManiaControlDir . "\ManiaControl.bat");
 | 
				
			||||||
 | 
								system($command); // TODO, windows stucks here as long controller is running
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							exit();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Get the Operating System on which ManiaControl is running
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @param string $compareOS
 | 
				
			||||||
 | 
						 * @return string
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function getOS($compareOS = null) {
 | 
				
			||||||
 | 
							$windows = defined('PHP_WINDOWS_VERSION_MAJOR');
 | 
				
			||||||
 | 
							if ($compareOS) {
 | 
				
			||||||
 | 
								// Return bool whether OS equals $compareOS
 | 
				
			||||||
 | 
								if ($compareOS == self::OS_WIN) {
 | 
				
			||||||
 | 
									return $windows;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								return !$windows;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							// Return OS
 | 
				
			||||||
 | 
							if ($windows) {
 | 
				
			||||||
 | 
								return self::OS_WIN;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return self::OS_UNIX;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Handle //shutdown command
 | 
						 * Handle //shutdown command
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
@@ -266,8 +297,7 @@ class ManiaControl implements CommandListener, TimerListener {
 | 
				
			|||||||
				$this->client->sendHideManialinkPage();
 | 
									$this->client->sendHideManialinkPage();
 | 
				
			||||||
				// Close the client connection
 | 
									// Close the client connection
 | 
				
			||||||
				$this->client->delete($this->server->ip, $this->server->port);
 | 
									$this->client->delete($this->server->ip, $this->server->port);
 | 
				
			||||||
			}
 | 
								} catch (TransportException $e) {
 | 
				
			||||||
			catch (TransportException $e) {
 | 
					 | 
				
			||||||
				$this->errorHandler->triggerDebugNotice($e->getMessage() . " File: " . $e->getFile() . " Line: " . $e->getLine());
 | 
									$this->errorHandler->triggerDebugNotice($e->getMessage() . " File: " . $e->getFile() . " Line: " . $e->getLine());
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -287,36 +317,10 @@ class ManiaControl implements CommandListener, TimerListener {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Restart ManiaControl
 | 
						 * Collect Garbage
 | 
				
			||||||
	 * 
 | 
					 | 
				
			||||||
	 * @param string $message
 | 
					 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function restart($message = null) {
 | 
						public function collectGarbage() {
 | 
				
			||||||
		// Shutdown callback
 | 
							gc_collect_cycles();
 | 
				
			||||||
		$this->callbackManager->triggerCallback(CallbackManager::CB_ONSHUTDOWN);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		// Announce restart
 | 
					 | 
				
			||||||
		$this->chat->sendInformation('Restarting ManiaControl...');
 | 
					 | 
				
			||||||
		if ($message) {
 | 
					 | 
				
			||||||
			$this->log($message);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		// Hide widgets
 | 
					 | 
				
			||||||
		$this->client->sendHideManialinkPage();
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		$this->log('Restarting ManiaControl!');
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		// Execute start script in background
 | 
					 | 
				
			||||||
		// TODO: restart the .php script itself ($_SERVER['scriptname'] or something + $argv)
 | 
					 | 
				
			||||||
		if ($this->getOS(self::OS_UNIX)) {
 | 
					 | 
				
			||||||
			$command = 'sh ' . escapeshellarg(ManiaControlDir . '/ManiaControl.sh') . ' > /dev/null &';
 | 
					 | 
				
			||||||
			exec($command);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		else {
 | 
					 | 
				
			||||||
			$command = escapeshellarg(ManiaControlDir . "\ManiaControl.bat");
 | 
					 | 
				
			||||||
			system($command); // TODO, windows stucks here as long controller is running
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		exit();
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
@@ -368,8 +372,7 @@ class ManiaControl implements CommandListener, TimerListener {
 | 
				
			|||||||
			try {
 | 
								try {
 | 
				
			||||||
				// Manager callbacks
 | 
									// Manager callbacks
 | 
				
			||||||
				$this->callbackManager->manageCallbacks();
 | 
									$this->callbackManager->manageCallbacks();
 | 
				
			||||||
			}
 | 
								} catch (TransportException $e) {
 | 
				
			||||||
			catch (TransportException $e) {
 | 
					 | 
				
			||||||
				$this->log("Connection interrupted!");
 | 
									$this->log("Connection interrupted!");
 | 
				
			||||||
				// TODO remove
 | 
									// TODO remove
 | 
				
			||||||
				if ($this->errorHandler) {
 | 
									if ($this->errorHandler) {
 | 
				
			||||||
@@ -384,7 +387,7 @@ class ManiaControl implements CommandListener, TimerListener {
 | 
				
			|||||||
			// Yield for next tick
 | 
								// Yield for next tick
 | 
				
			||||||
			$loopEnd = microtime(true);
 | 
								$loopEnd = microtime(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$sleepTime = (int) (2000 - ($loopEnd - $loopStart) * 1000000);
 | 
								$sleepTime = (int)(2000 - ($loopEnd - $loopStart) * 1000000);
 | 
				
			||||||
			if ($sleepTime > 0) {
 | 
								if ($sleepTime > 0) {
 | 
				
			||||||
				usleep($sleepTime);
 | 
									usleep($sleepTime);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@@ -394,13 +397,6 @@ class ManiaControl implements CommandListener, TimerListener {
 | 
				
			|||||||
		$this->quit();
 | 
							$this->quit();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Collect Garbage
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public function collectGarbage() {
 | 
					 | 
				
			||||||
		gc_collect_cycles();
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Connect to ManiaPlanet server
 | 
						 * Connect to ManiaPlanet server
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
@@ -412,8 +408,7 @@ class ManiaControl implements CommandListener, TimerListener {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		try {
 | 
							try {
 | 
				
			||||||
			$this->client = Connection::factory($this->server->config->host, $this->server->config->port, self::CONNECT_TIMEOUT, $this->server->config->login, $this->server->config->pass);
 | 
								$this->client = Connection::factory($this->server->config->host, $this->server->config->port, self::CONNECT_TIMEOUT, $this->server->config->login, $this->server->config->pass);
 | 
				
			||||||
		}
 | 
							} catch (Exception $e) {
 | 
				
			||||||
		catch (Exception $e) {
 | 
					 | 
				
			||||||
			trigger_error("Couldn't authenticate on server with user '{$this->server->config->login}'! " . $e->getMessage(), E_USER_ERROR);
 | 
								trigger_error("Couldn't authenticate on server with user '{$this->server->config->login}'! " . $e->getMessage(), E_USER_ERROR);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -425,8 +420,7 @@ class ManiaControl implements CommandListener, TimerListener {
 | 
				
			|||||||
			if (!$this->server->waitForStatus(4)) {
 | 
								if (!$this->server->waitForStatus(4)) {
 | 
				
			||||||
				trigger_error("Server couldn't get ready!", E_USER_ERROR);
 | 
									trigger_error("Server couldn't get ready!", E_USER_ERROR);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							} catch (Exception $e) {
 | 
				
			||||||
		catch (Exception $e) {
 | 
					 | 
				
			||||||
			// TODO remove
 | 
								// TODO remove
 | 
				
			||||||
			if ($this->errorHandler) {
 | 
								if ($this->errorHandler) {
 | 
				
			||||||
				$this->errorHandler->triggerDebugNotice("Fatal Exception: " . $e->getMessage() . " Trace: " . $e->getTraceAsString());
 | 
									$this->errorHandler->triggerDebugNotice("Fatal Exception: " . $e->getMessage() . " Trace: " . $e->getTraceAsString());
 | 
				
			||||||
@@ -447,8 +441,7 @@ class ManiaControl implements CommandListener, TimerListener {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		try {
 | 
							try {
 | 
				
			||||||
			$scriptSettings = $this->client->getModeScriptSettings();
 | 
								$scriptSettings = $this->client->getModeScriptSettings();
 | 
				
			||||||
		}
 | 
							} catch (NotInScriptModeException $e) {
 | 
				
			||||||
		catch (NotInScriptModeException $e) {
 | 
					 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -459,8 +452,7 @@ class ManiaControl implements CommandListener, TimerListener {
 | 
				
			|||||||
		$scriptSettings['S_UseScriptCallbacks'] = true;
 | 
							$scriptSettings['S_UseScriptCallbacks'] = true;
 | 
				
			||||||
		try {
 | 
							try {
 | 
				
			||||||
			$this->client->setModeScriptSettings($scriptSettings);
 | 
								$this->client->setModeScriptSettings($scriptSettings);
 | 
				
			||||||
		}
 | 
							} catch (Exception $e) {
 | 
				
			||||||
		catch (Exception $e) {
 | 
					 | 
				
			||||||
			// TODO temp added 19.04.2014
 | 
								// TODO temp added 19.04.2014
 | 
				
			||||||
			$this->errorHandler->triggerDebugNotice("Exception line 437 ManiaControl.php " . $e->getMessage());
 | 
								$this->errorHandler->triggerDebugNotice("Exception line 437 ManiaControl.php " . $e->getMessage());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,8 +7,8 @@ use ManiaControl\ManiaControl;
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * Interface for ManiaControl Plugins
 | 
					 * Interface for ManiaControl Plugins
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author steeffeen & kremsy
 | 
					 * @author    ManiaControl Team <mail@maniacontrol.com>
 | 
				
			||||||
 * @copyright ManiaControl Copyright © 2014 ManiaControl Team
 | 
					 * @copyright 2014 ManiaControl Team
 | 
				
			||||||
 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
					 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
interface Plugin {
 | 
					interface Plugin {
 | 
				
			||||||
@@ -24,19 +24,6 @@ interface Plugin {
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	public static function prepare(ManiaControl $maniaControl);
 | 
						public static function prepare(ManiaControl $maniaControl);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Load the plugin
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @param \ManiaControl\ManiaControl $maniaControl
 | 
					 | 
				
			||||||
	 * @return bool
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public function load(ManiaControl $maniaControl);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Unload the plugin and its Resources
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public function unload();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Get plugin id
 | 
						 * Get plugin id
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
@@ -71,4 +58,17 @@ interface Plugin {
 | 
				
			|||||||
	 * @return string
 | 
						 * @return string
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public static function getDescription();
 | 
						public static function getDescription();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Load the plugin
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @param \ManiaControl\ManiaControl $maniaControl
 | 
				
			||||||
 | 
						 * @return bool
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function load(ManiaControl $maniaControl);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Unload the plugin and its Resources
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function unload();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,8 +21,8 @@ use ManiaControl\Players\Player;
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * Configurator for enabling and disabling Plugins
 | 
					 * Configurator for enabling and disabling Plugins
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author steeffeen
 | 
					 * @author    ManiaControl Team <mail@maniacontrol.com>
 | 
				
			||||||
 * @copyright ManiaControl Copyright © 2014 ManiaControl Team
 | 
					 * @copyright 2014 ManiaControl Team
 | 
				
			||||||
 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
					 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class PluginInstallMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAnswerListener {
 | 
					class PluginInstallMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAnswerListener {
 | 
				
			||||||
@@ -107,12 +107,12 @@ class PluginInstallMenu implements CallbackListener, ConfiguratorMenu, Manialink
 | 
				
			|||||||
			$pluginClasses = $this->maniaControl->pluginManager->getPluginClasses();
 | 
								$pluginClasses = $this->maniaControl->pluginManager->getPluginClasses();
 | 
				
			||||||
			$pluginIds     = array();
 | 
								$pluginIds     = array();
 | 
				
			||||||
			/** @var Plugin $class */
 | 
								/** @var Plugin $class */
 | 
				
			||||||
			foreach($pluginClasses as $class) {
 | 
								foreach ($pluginClasses as $class) {
 | 
				
			||||||
				$pluginIds[] = $class::getId();
 | 
									$pluginIds[] = $class::getId();
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			foreach($pluginList as $plugin) {
 | 
								foreach ($pluginList as $plugin) {
 | 
				
			||||||
				if(!in_array($plugin->id, $pluginIds)) {
 | 
									if (!in_array($plugin->id, $pluginIds)) {
 | 
				
			||||||
					if (!isset($pageFrame)) {
 | 
										if (!isset($pageFrame)) {
 | 
				
			||||||
						$pageFrame = new Frame();
 | 
											$pageFrame = new Frame();
 | 
				
			||||||
						$frame->add($pageFrame);
 | 
											$frame->add($pageFrame);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,16 +3,16 @@
 | 
				
			|||||||
namespace ManiaControl\Plugins;
 | 
					namespace ManiaControl\Plugins;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use ManiaControl\Callbacks\CallbackListener;
 | 
					use ManiaControl\Callbacks\CallbackListener;
 | 
				
			||||||
use ManiaControl\ManiaControl;
 | 
					 | 
				
			||||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
 | 
					 | 
				
			||||||
use ManiaControl\Callbacks\TimerListener;
 | 
					use ManiaControl\Callbacks\TimerListener;
 | 
				
			||||||
use ManiaControl\Commands\CommandListener;
 | 
					use ManiaControl\Commands\CommandListener;
 | 
				
			||||||
 | 
					use ManiaControl\ManiaControl;
 | 
				
			||||||
 | 
					use ManiaControl\Manialinks\ManialinkPageAnswerListener;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Class managing Plugins
 | 
					 * Class managing Plugins
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author steeffeen & kremsy
 | 
					 * @author    ManiaControl Team <mail@maniacontrol.com>
 | 
				
			||||||
 * @copyright ManiaControl Copyright © 2014 ManiaControl Team
 | 
					 * @copyright 2014 ManiaControl Team
 | 
				
			||||||
 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
					 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class PluginManager {
 | 
					class PluginManager {
 | 
				
			||||||
@@ -76,14 +76,64 @@ class PluginManager {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Check if the plugin is running
 | 
						 * Deactivate the plugin with the given class
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
	 * @param string $pluginClass
 | 
						 * @param string $pluginClass
 | 
				
			||||||
	 * @return bool
 | 
						 * @return bool
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function isPluginActive($pluginClass) {
 | 
						public function deactivatePlugin($pluginClass) {
 | 
				
			||||||
		$pluginClass = $this->getPluginClass($pluginClass);
 | 
							$pluginClass = $this->getPluginClass($pluginClass);
 | 
				
			||||||
		return isset($this->activePlugins[$pluginClass]);
 | 
							if (!$this->isPluginActive($pluginClass)) {
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							$plugin = $this->activePlugins[$pluginClass];
 | 
				
			||||||
 | 
							/**
 | 
				
			||||||
 | 
							 * @var Plugin $plugin
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							$plugin->unload();
 | 
				
			||||||
 | 
							unset($this->activePlugins[$pluginClass]);
 | 
				
			||||||
 | 
							if ($plugin instanceof CallbackListener) {
 | 
				
			||||||
 | 
								$this->maniaControl->callbackManager->unregisterCallbackListener($plugin);
 | 
				
			||||||
 | 
								$this->maniaControl->callbackManager->unregisterScriptCallbackListener($plugin);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if ($plugin instanceof CommandListener) {
 | 
				
			||||||
 | 
								$this->maniaControl->commandManager->unregisterCommandListener($plugin);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if ($plugin instanceof ManialinkPageAnswerListener) {
 | 
				
			||||||
 | 
								$this->maniaControl->manialinkManager->unregisterManialinkPageAnswerListener($plugin);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if ($plugin instanceof TimerListener) {
 | 
				
			||||||
 | 
								$this->maniaControl->timerManager->unregisterTimerListenings($plugin);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							$this->savePluginStatus($pluginClass, false);
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Get the Class of the Plugin
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @param mixed $pluginClass
 | 
				
			||||||
 | 
						 * @return string
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public static function getPluginClass($pluginClass) {
 | 
				
			||||||
 | 
							$pluginClass = self::getClass($pluginClass);
 | 
				
			||||||
 | 
							if (!self::isPluginClass($pluginClass)) {
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return $pluginClass;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Get the Class of the Object
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @param mixed $object
 | 
				
			||||||
 | 
						 * @return string
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						private static function getClass($object) {
 | 
				
			||||||
 | 
							if (is_object($object)) {
 | 
				
			||||||
 | 
								return get_class($object);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return (string)$object;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
@@ -104,95 +154,46 @@ class PluginManager {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Add the class to array of loaded plugin classes
 | 
						 * Check if the plugin is running
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
	 * @param string $pluginClass
 | 
						 * @param string $pluginClass
 | 
				
			||||||
	 * @return bool
 | 
						 * @return bool
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function addPluginClass($pluginClass) {
 | 
						public function isPluginActive($pluginClass) {
 | 
				
			||||||
		$pluginClass = $this->getPluginClass($pluginClass);
 | 
							$pluginClass = $this->getPluginClass($pluginClass);
 | 
				
			||||||
		if (in_array($pluginClass, $this->pluginClasses)) {
 | 
							return isset($this->activePlugins[$pluginClass]);
 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if (!$this->isPluginClass($pluginClass)) {
 | 
					 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		array_push($this->pluginClasses, $pluginClass);
 | 
					 | 
				
			||||||
		sort($this->pluginClasses);
 | 
					 | 
				
			||||||
		return true;
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Activate and start the plugin with the given name
 | 
						 * Save plugin status in database
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
	 * @param string $pluginClass
 | 
						 * @param string $className
 | 
				
			||||||
	 * @param string $adminLogin
 | 
						 * @param bool   $active
 | 
				
			||||||
	 * @return bool
 | 
						 * @return bool
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function activatePlugin($pluginClass, $adminLogin = null) {
 | 
						private function savePluginStatus($className, $active) {
 | 
				
			||||||
		if (!is_string($pluginClass)) {
 | 
							$mysqli            = $this->maniaControl->database->mysqli;
 | 
				
			||||||
 | 
							$pluginStatusQuery = "INSERT INTO `" . self::TABLE_PLUGINS . "` (
 | 
				
			||||||
 | 
									`className`,
 | 
				
			||||||
 | 
									`active`
 | 
				
			||||||
 | 
									) VALUES (
 | 
				
			||||||
 | 
									?, ?
 | 
				
			||||||
 | 
									) ON DUPLICATE KEY UPDATE
 | 
				
			||||||
 | 
									`active` = VALUES(`active`);";
 | 
				
			||||||
 | 
							$pluginStatement   = $mysqli->prepare($pluginStatusQuery);
 | 
				
			||||||
 | 
							if ($mysqli->error) {
 | 
				
			||||||
 | 
								trigger_error($mysqli->error);
 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (!$this->isPluginClass($pluginClass)) {
 | 
							$activeInt = ($active ? 1 : 0);
 | 
				
			||||||
 | 
							$pluginStatement->bind_param('si', $className, $activeInt);
 | 
				
			||||||
 | 
							$pluginStatement->execute();
 | 
				
			||||||
 | 
							if ($pluginStatement->error) {
 | 
				
			||||||
 | 
								trigger_error($pluginStatement->error);
 | 
				
			||||||
 | 
								$pluginStatement->close();
 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if ($this->isPluginActive($pluginClass)) {
 | 
							$pluginStatement->close();
 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		$plugin = new $pluginClass();
 | 
					 | 
				
			||||||
		/**
 | 
					 | 
				
			||||||
		 *
 | 
					 | 
				
			||||||
		 * @var Plugin $plugin
 | 
					 | 
				
			||||||
		 */
 | 
					 | 
				
			||||||
		$this->activePlugins[$pluginClass] = $plugin;
 | 
					 | 
				
			||||||
		$this->savePluginStatus($pluginClass, true);
 | 
					 | 
				
			||||||
		try {
 | 
					 | 
				
			||||||
			$plugin->load($this->maniaControl);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		catch (\Exception $e) {
 | 
					 | 
				
			||||||
			$this->maniaControl->chat->sendError('Error while plugin activating ' . $pluginClass . ': ' . $e->getMessage(), $adminLogin);
 | 
					 | 
				
			||||||
			$this->maniaControl->log('Error while plugin activation: ' . $pluginClass . ': ' . $e->getMessage());
 | 
					 | 
				
			||||||
			unset($this->activePlugins[$pluginClass]);
 | 
					 | 
				
			||||||
			$this->savePluginStatus($pluginClass, false);
 | 
					 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		$this->savePluginStatus($pluginClass, true);
 | 
					 | 
				
			||||||
		return true;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Deactivate the plugin with the given class
 | 
					 | 
				
			||||||
	 * 
 | 
					 | 
				
			||||||
	 * @param string $pluginClass
 | 
					 | 
				
			||||||
	 * @return bool
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public function deactivatePlugin($pluginClass) {
 | 
					 | 
				
			||||||
		$pluginClass = $this->getPluginClass($pluginClass);
 | 
					 | 
				
			||||||
		if (!$this->isPluginActive($pluginClass)) {
 | 
					 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		$plugin = $this->activePlugins[$pluginClass];
 | 
					 | 
				
			||||||
		/**
 | 
					 | 
				
			||||||
		 *
 | 
					 | 
				
			||||||
		 * @var Plugin $plugin
 | 
					 | 
				
			||||||
		 */
 | 
					 | 
				
			||||||
		$plugin->unload();
 | 
					 | 
				
			||||||
		unset($this->activePlugins[$pluginClass]);
 | 
					 | 
				
			||||||
		if ($plugin instanceof CallbackListener) {
 | 
					 | 
				
			||||||
			$this->maniaControl->callbackManager->unregisterCallbackListener($plugin);
 | 
					 | 
				
			||||||
			$this->maniaControl->callbackManager->unregisterScriptCallbackListener($plugin);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if ($plugin instanceof CommandListener) {
 | 
					 | 
				
			||||||
			$this->maniaControl->commandManager->unregisterCommandListener($plugin);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if ($plugin instanceof ManialinkPageAnswerListener) {
 | 
					 | 
				
			||||||
			$this->maniaControl->manialinkManager->unregisterManialinkPageAnswerListener($plugin);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if ($plugin instanceof TimerListener) {
 | 
					 | 
				
			||||||
			$this->maniaControl->timerManager->unregisterTimerListenings($plugin);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		$this->savePluginStatus($pluginClass, false);
 | 
					 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -265,66 +266,21 @@ class PluginManager {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Returns a Plugin if it is activated
 | 
						 * Add the class to array of loaded plugin classes
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
	 * @param string $pluginClass
 | 
						 * @param string $pluginClass
 | 
				
			||||||
	 * @return Plugin
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public function getPlugin($pluginClass) {
 | 
					 | 
				
			||||||
		if ($this->isPluginActive($pluginClass)) {
 | 
					 | 
				
			||||||
			return $this->activePlugins[$pluginClass];
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return null;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Get all declared plugin class names
 | 
					 | 
				
			||||||
	 * 
 | 
					 | 
				
			||||||
	 * @return array
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public function getPluginClasses() {
 | 
					 | 
				
			||||||
		return $this->pluginClasses;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Get all active plugins
 | 
					 | 
				
			||||||
	 * 
 | 
					 | 
				
			||||||
	 * @return array
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public function getActivePlugins() {
 | 
					 | 
				
			||||||
		return $this->activePlugins;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Save plugin status in database
 | 
					 | 
				
			||||||
	 * 
 | 
					 | 
				
			||||||
	 * @param string $className
 | 
					 | 
				
			||||||
	 * @param bool $active
 | 
					 | 
				
			||||||
	 * @return bool
 | 
						 * @return bool
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	private function savePluginStatus($className, $active) {
 | 
						public function addPluginClass($pluginClass) {
 | 
				
			||||||
		$mysqli = $this->maniaControl->database->mysqli;
 | 
							$pluginClass = $this->getPluginClass($pluginClass);
 | 
				
			||||||
		$pluginStatusQuery = "INSERT INTO `" . self::TABLE_PLUGINS . "` (
 | 
							if (in_array($pluginClass, $this->pluginClasses)) {
 | 
				
			||||||
				`className`,
 | 
					 | 
				
			||||||
				`active`
 | 
					 | 
				
			||||||
				) VALUES (
 | 
					 | 
				
			||||||
				?, ?
 | 
					 | 
				
			||||||
				) ON DUPLICATE KEY UPDATE
 | 
					 | 
				
			||||||
				`active` = VALUES(`active`);";
 | 
					 | 
				
			||||||
		$pluginStatement = $mysqli->prepare($pluginStatusQuery);
 | 
					 | 
				
			||||||
		if ($mysqli->error) {
 | 
					 | 
				
			||||||
			trigger_error($mysqli->error);
 | 
					 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		$activeInt = ($active ? 1 : 0);
 | 
							if (!$this->isPluginClass($pluginClass)) {
 | 
				
			||||||
		$pluginStatement->bind_param('si', $className, $activeInt);
 | 
					 | 
				
			||||||
		$pluginStatement->execute();
 | 
					 | 
				
			||||||
		if ($pluginStatement->error) {
 | 
					 | 
				
			||||||
			trigger_error($pluginStatement->error);
 | 
					 | 
				
			||||||
			$pluginStatement->close();
 | 
					 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		$pluginStatement->close();
 | 
							array_push($this->pluginClasses, $pluginClass);
 | 
				
			||||||
 | 
							sort($this->pluginClasses);
 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -365,6 +321,74 @@ class PluginManager {
 | 
				
			|||||||
		return $active;
 | 
							return $active;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Activate and start the plugin with the given name
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @param string $pluginClass
 | 
				
			||||||
 | 
						 * @param string $adminLogin
 | 
				
			||||||
 | 
						 * @return bool
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function activatePlugin($pluginClass, $adminLogin = null) {
 | 
				
			||||||
 | 
							if (!is_string($pluginClass)) {
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (!$this->isPluginClass($pluginClass)) {
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if ($this->isPluginActive($pluginClass)) {
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							$plugin = new $pluginClass();
 | 
				
			||||||
 | 
							/**
 | 
				
			||||||
 | 
							 * @var Plugin $plugin
 | 
				
			||||||
 | 
							 */
 | 
				
			||||||
 | 
							$this->activePlugins[$pluginClass] = $plugin;
 | 
				
			||||||
 | 
							$this->savePluginStatus($pluginClass, true);
 | 
				
			||||||
 | 
							try {
 | 
				
			||||||
 | 
								$plugin->load($this->maniaControl);
 | 
				
			||||||
 | 
							} catch (\Exception $e) {
 | 
				
			||||||
 | 
								$this->maniaControl->chat->sendError('Error while plugin activating ' . $pluginClass . ': ' . $e->getMessage(), $adminLogin);
 | 
				
			||||||
 | 
								$this->maniaControl->log('Error while plugin activation: ' . $pluginClass . ': ' . $e->getMessage());
 | 
				
			||||||
 | 
								unset($this->activePlugins[$pluginClass]);
 | 
				
			||||||
 | 
								$this->savePluginStatus($pluginClass, false);
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$this->savePluginStatus($pluginClass, true);
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Returns a Plugin if it is activated
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @param string $pluginClass
 | 
				
			||||||
 | 
						 * @return Plugin
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function getPlugin($pluginClass) {
 | 
				
			||||||
 | 
							if ($this->isPluginActive($pluginClass)) {
 | 
				
			||||||
 | 
								return $this->activePlugins[$pluginClass];
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return null;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Get all declared plugin class names
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @return array
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function getPluginClasses() {
 | 
				
			||||||
 | 
							return $this->pluginClasses;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Get all active plugins
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @return array
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function getActivePlugins() {
 | 
				
			||||||
 | 
							return $this->activePlugins;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Fetch the Plugins List from the ManiaControl Website
 | 
						 * Fetch the Plugins List from the ManiaControl Website
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
@@ -373,36 +397,9 @@ class PluginManager {
 | 
				
			|||||||
	public function fetchPluginList($function) {
 | 
						public function fetchPluginList($function) {
 | 
				
			||||||
		$url = ManiaControl::URL_WEBSERVICE . 'plugins';
 | 
							$url = ManiaControl::URL_WEBSERVICE . 'plugins';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$this->maniaControl->fileReader->loadFile($url, function ($dataJson, $error) use(&$function) {
 | 
							$this->maniaControl->fileReader->loadFile($url, function ($dataJson, $error) use (&$function) {
 | 
				
			||||||
			$data = json_decode($dataJson);
 | 
								$data = json_decode($dataJson);
 | 
				
			||||||
			call_user_func($function, $data, $error);
 | 
								call_user_func($function, $data, $error);
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Get the Class of the Plugin
 | 
					 | 
				
			||||||
	 * 
 | 
					 | 
				
			||||||
	 * @param mixed $pluginClass
 | 
					 | 
				
			||||||
	 * @return string
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public static function getPluginClass($pluginClass) {
 | 
					 | 
				
			||||||
		$pluginClass = self::getClass($pluginClass);
 | 
					 | 
				
			||||||
		if (!self::isPluginClass($pluginClass)) {
 | 
					 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return $pluginClass;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Get the Class of the Object
 | 
					 | 
				
			||||||
	 * 
 | 
					 | 
				
			||||||
	 * @param mixed $object
 | 
					 | 
				
			||||||
	 * @return string
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	private static function getClass($object) {
 | 
					 | 
				
			||||||
		if (is_object($object)) {
 | 
					 | 
				
			||||||
			return get_class($object);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return (string) $object;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,8 +8,8 @@ use FML\Controls\Frame;
 | 
				
			|||||||
use FML\Controls\Label;
 | 
					use FML\Controls\Label;
 | 
				
			||||||
use FML\Controls\Labels\Label_Button;
 | 
					use FML\Controls\Labels\Label_Button;
 | 
				
			||||||
use FML\Controls\Labels\Label_Text;
 | 
					use FML\Controls\Labels\Label_Text;
 | 
				
			||||||
use FML\Controls\Quads\Quad_Icons128x32_1;
 | 
					 | 
				
			||||||
use FML\Controls\Quads\Quad_Icons128x128_1;
 | 
					use FML\Controls\Quads\Quad_Icons128x128_1;
 | 
				
			||||||
 | 
					use FML\Controls\Quads\Quad_Icons128x32_1;
 | 
				
			||||||
use FML\Controls\Quads\Quad_Icons64x64_1;
 | 
					use FML\Controls\Quads\Quad_Icons64x64_1;
 | 
				
			||||||
use FML\Script\Features\Paging;
 | 
					use FML\Script\Features\Paging;
 | 
				
			||||||
use FML\Script\Script;
 | 
					use FML\Script\Script;
 | 
				
			||||||
@@ -25,8 +25,8 @@ use ManiaControl\Players\Player;
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * Configurator for enabling and disabling Plugins
 | 
					 * Configurator for enabling and disabling Plugins
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author ManiaControl Team
 | 
					 * @author    ManiaControl Team <mail@maniacontrol.com>
 | 
				
			||||||
 * @copyright ManiaControl Copyright © 2014 ManiaControl Team
 | 
					 * @copyright 2014 ManiaControl Team
 | 
				
			||||||
 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
					 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAnswerListener {
 | 
					class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAnswerListener {
 | 
				
			||||||
@@ -62,13 +62,6 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
 | 
				
			|||||||
		$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
 | 
							$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * @see \ManiaControl\Configurators\ConfiguratorMenu::getTitle()
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public function getTitle() {
 | 
					 | 
				
			||||||
		return 'Plugins';
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Returns Back to the Plugins
 | 
						 * Returns Back to the Plugins
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
@@ -78,6 +71,13 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
 | 
				
			|||||||
		$this->maniaControl->configurator->reopenMenu($player, $menuId);
 | 
							$this->maniaControl->configurator->reopenMenu($player, $menuId);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * @see \ManiaControl\Configurators\ConfiguratorMenu::getTitle()
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function getTitle() {
 | 
				
			||||||
 | 
							return 'Plugins';
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
 | 
						 * @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
@@ -128,7 +128,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
 | 
				
			|||||||
			$y                    = 0;
 | 
								$y                    = 0;
 | 
				
			||||||
			$index                = 1;
 | 
								$index                = 1;
 | 
				
			||||||
			$settingHeight        = 5.;
 | 
								$settingHeight        = 5.;
 | 
				
			||||||
			foreach($settings as $setting) {
 | 
								foreach ($settings as $setting) {
 | 
				
			||||||
				if (!isset($pageFrame)) {
 | 
									if (!isset($pageFrame)) {
 | 
				
			||||||
					$pageFrame = new Frame();
 | 
										$pageFrame = new Frame();
 | 
				
			||||||
					$frame->add($pageFrame);
 | 
										$frame->add($pageFrame);
 | 
				
			||||||
@@ -244,11 +244,11 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
 | 
				
			|||||||
		$y             = 0.;
 | 
							$y             = 0.;
 | 
				
			||||||
		$pluginUpdates = $this->maniaControl->updateManager->pluginUpdateManager->getPluginsUpdates();
 | 
							$pluginUpdates = $this->maniaControl->updateManager->pluginUpdateManager->getPluginsUpdates();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		usort($pluginClasses, function($a, $b) {
 | 
							usort($pluginClasses, function ($a, $b) {
 | 
				
			||||||
			return strcmp($a::getName(), $b::getName());
 | 
								return strcmp($a::getName(), $b::getName());
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		foreach($pluginClasses as $index => $pluginClass) {
 | 
							foreach ($pluginClasses as $index => $pluginClass) {
 | 
				
			||||||
			/** @var Plugin $pluginClass */
 | 
								/** @var Plugin $pluginClass */
 | 
				
			||||||
			if (!isset($pageFrame)) {
 | 
								if (!isset($pageFrame)) {
 | 
				
			||||||
				$pageFrame = new Frame();
 | 
									$pageFrame = new Frame();
 | 
				
			||||||
@@ -340,7 +340,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($pluginUpdates != false) {
 | 
							if ($pluginUpdates != false) {
 | 
				
			||||||
			$updatePluginsButton = new Label_Button();
 | 
								$updatePluginsButton = new Label_Button();
 | 
				
			||||||
			$frame->add($updatePluginsButton);
 | 
								$frame->add($updatePluginsButton);
 | 
				
			||||||
			$updatePluginsButton->setHAlign(Control::RIGHT);
 | 
								$updatePluginsButton->setHAlign(Control::RIGHT);
 | 
				
			||||||
@@ -349,48 +349,13 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
 | 
				
			|||||||
			$updatePluginsButton->setZ(2);
 | 
								$updatePluginsButton->setZ(2);
 | 
				
			||||||
			$updatePluginsButton->setWidth(10);
 | 
								$updatePluginsButton->setWidth(10);
 | 
				
			||||||
			$updatePluginsButton->setStyle($updatePluginsButton::STYLE_CardButtonSmallS);
 | 
								$updatePluginsButton->setStyle($updatePluginsButton::STYLE_CardButtonSmallS);
 | 
				
			||||||
			$updatePluginsButton->setText(count($pluginUpdates).' update(s)');
 | 
								$updatePluginsButton->setText(count($pluginUpdates) . ' update(s)');
 | 
				
			||||||
			$updatePluginsButton->setAction(self::ACTION_UPDATEPLUGINS);
 | 
								$updatePluginsButton->setAction(self::ACTION_UPDATEPLUGINS);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return $frame;
 | 
							return $frame;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public function saveConfigData(array $configData, Player $player) {
 | 
					 | 
				
			||||||
		if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS)) {
 | 
					 | 
				
			||||||
			$this->maniaControl->authenticationManager->sendNotAllowed($player);
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0) {
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		$maniaControlSettings = $this->maniaControl->settingManager->getSettings();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		foreach($configData[3] as $setting) {
 | 
					 | 
				
			||||||
			$settingName = substr($setting['Name'], $prefixLength + 1);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if(!isset($maniaControlSettings[$settingName]))
 | 
					 | 
				
			||||||
				continue;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			$oldSetting = $maniaControlSettings[$settingName];
 | 
					 | 
				
			||||||
			if ($setting['Value'] == $oldSetting->value || $oldSetting->type == 'bool') {
 | 
					 | 
				
			||||||
				continue;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, $setting['Value']);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		//Reopen the Menu
 | 
					 | 
				
			||||||
		$menuId = $this->maniaControl->configurator->getMenuId($this->getTitle());
 | 
					 | 
				
			||||||
		$this->maniaControl->configurator->reopenMenu($player, $menuId);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Handle PlayerManialinkPageAnswer callback
 | 
						 * Handle PlayerManialinkPageAnswer callback
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
@@ -456,7 +421,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Toggles a Boolean Value
 | 
						 * Toggle a Boolean Value
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
	 * @param        $setting
 | 
						 * @param        $setting
 | 
				
			||||||
	 * @param Player $player
 | 
						 * @param Player $player
 | 
				
			||||||
@@ -481,4 +446,40 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
 | 
				
			|||||||
			$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, "1");
 | 
								$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, "1");
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function saveConfigData(array $configData, Player $player) {
 | 
				
			||||||
 | 
							if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS)) {
 | 
				
			||||||
 | 
								$this->maniaControl->authenticationManager->sendNotAllowed($player);
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0) {
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$maniaControlSettings = $this->maniaControl->settingManager->getSettings();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							foreach ($configData[3] as $setting) {
 | 
				
			||||||
 | 
								$settingName = substr($setting['Name'], $prefixLength + 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (!isset($maniaControlSettings[$settingName])) {
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								$oldSetting = $maniaControlSettings[$settingName];
 | 
				
			||||||
 | 
								if ($setting['Value'] == $oldSetting->value || $oldSetting->type == 'bool') {
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								$this->maniaControl->settingManager->setSetting($oldSetting->class, $oldSetting->setting, $setting['Value']);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Reopen the Menu
 | 
				
			||||||
 | 
							$menuId = $this->maniaControl->configurator->getMenuId($this->getTitle());
 | 
				
			||||||
 | 
							$this->maniaControl->configurator->reopenMenu($player, $menuId);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,8 +11,8 @@ use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * ManiaControl Chat-Message Plugin
 | 
					 * ManiaControl Chat-Message Plugin
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author    kremsy
 | 
					 * @author    kremsy <kremsy@maniacontrol.com>
 | 
				
			||||||
 * @copyright ManiaControl Copyright © 2014 ManiaControl Team
 | 
					 * @copyright 2014 ManiaControl Team
 | 
				
			||||||
 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
					 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class ChatMessagePlugin implements CommandListener, Plugin {
 | 
					class ChatMessagePlugin implements CommandListener, Plugin {
 | 
				
			||||||
@@ -43,6 +43,51 @@ class ChatMessagePlugin implements CommandListener, Plugin {
 | 
				
			|||||||
		//do nothing
 | 
							//do nothing
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Get plugin id
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @return int
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public static function getId() {
 | 
				
			||||||
 | 
							return self::PLUGIN_ID;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Get Plugin Name
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @return string
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public static function getName() {
 | 
				
			||||||
 | 
							return self::PLUGIN_NAME;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Get Plugin Version
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @return float,,
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public static function getVersion() {
 | 
				
			||||||
 | 
							return self::PLUGIN_VERSION;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Get Plugin Author
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @return string
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public static function getAuthor() {
 | 
				
			||||||
 | 
							return self::PLUGIN_AUTHOR;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Get Plugin Description
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @return string
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public static function getDescription() {
 | 
				
			||||||
 | 
							return "Plugin offers various Chat-Commands like /gg /hi /afk /rq...";
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Load the plugin
 | 
						 * Load the plugin
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
@@ -113,6 +158,30 @@ class ChatMessagePlugin implements CommandListener, Plugin {
 | 
				
			|||||||
		$this->maniaControl->chat->sendChat($msg, null, false);
 | 
							$this->maniaControl->chat->sendChat($msg, null, false);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Checks if a Player is in the PlayerList and returns the nickname if he is, can be called per login, pid or nickname or lj for
 | 
				
			||||||
 | 
						 * (last joined)
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @param $login
 | 
				
			||||||
 | 
						 * @return mixed
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						private function getTarget($login) {
 | 
				
			||||||
 | 
							/** @var Player $player */
 | 
				
			||||||
 | 
							$player = null;
 | 
				
			||||||
 | 
							foreach ($this->maniaControl->playerManager->getPlayers() as $player) {
 | 
				
			||||||
 | 
								if ($login == $player->login || $login == $player->pid || $login == $player->nickname) {
 | 
				
			||||||
 | 
									return $player->nickname;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if ($player && $login == 'lj') {
 | 
				
			||||||
 | 
								return $player->nickname;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//returns the text given if nothing matches
 | 
				
			||||||
 | 
							return $login;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Bye Message
 | 
						 * Bye Message
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
@@ -314,7 +383,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
 | 
				
			|||||||
		$message = '$39F Thanks for Playing, see you around!$z';
 | 
							$message = '$39F Thanks for Playing, see you around!$z';
 | 
				
			||||||
		try {
 | 
							try {
 | 
				
			||||||
			$this->maniaControl->client->kick($player->login, $message);
 | 
								$this->maniaControl->client->kick($player->login, $message);
 | 
				
			||||||
		} catch(Exception $e) {
 | 
							} catch (Exception $e) {
 | 
				
			||||||
			$this->maniaControl->errorHandler->triggerDebugNotice("ChatMessagePlugin Debug Line 316: " . $e->getMessage());
 | 
								$this->maniaControl->errorHandler->triggerDebugNotice("ChatMessagePlugin Debug Line 316: " . $e->getMessage());
 | 
				
			||||||
			// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
 | 
								// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
 | 
				
			||||||
			$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
 | 
								$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
 | 
				
			||||||
@@ -335,7 +404,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
 | 
				
			|||||||
		$message = '$39F Thanks for Playing, please come back soon!$z ';
 | 
							$message = '$39F Thanks for Playing, please come back soon!$z ';
 | 
				
			||||||
		try {
 | 
							try {
 | 
				
			||||||
			$this->maniaControl->client->kick($player->login, $message);
 | 
								$this->maniaControl->client->kick($player->login, $message);
 | 
				
			||||||
		} catch(Exception $e) {
 | 
							} catch (Exception $e) {
 | 
				
			||||||
			$this->maniaControl->errorHandler->triggerDebugNotice("ChatMessagePlugin Debug Line " . $e->getLine() . ": " . $e->getMessage());
 | 
								$this->maniaControl->errorHandler->triggerDebugNotice("ChatMessagePlugin Debug Line " . $e->getLine() . ": " . $e->getMessage());
 | 
				
			||||||
			// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
 | 
								// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
 | 
				
			||||||
			$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
 | 
								$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
 | 
				
			||||||
@@ -361,7 +430,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
 | 
				
			|||||||
			// force into spec
 | 
								// force into spec
 | 
				
			||||||
			try {
 | 
								try {
 | 
				
			||||||
				$this->maniaControl->client->forceSpectator($player->login, 3);
 | 
									$this->maniaControl->client->forceSpectator($player->login, 3);
 | 
				
			||||||
			} catch(Exception $e) {
 | 
								} catch (Exception $e) {
 | 
				
			||||||
				$this->maniaControl->errorHandler->triggerDebugNotice("ChatMessagePlugin Debug Line " . $e->getLine() . ": " . $e->getMessage());
 | 
									$this->maniaControl->errorHandler->triggerDebugNotice("ChatMessagePlugin Debug Line " . $e->getLine() . ": " . $e->getMessage());
 | 
				
			||||||
				// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
 | 
									// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
 | 
				
			||||||
				$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
 | 
									$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
 | 
				
			||||||
@@ -371,7 +440,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
 | 
				
			|||||||
			// free player slot
 | 
								// free player slot
 | 
				
			||||||
			try {
 | 
								try {
 | 
				
			||||||
				$this->maniaControl->client->spectatorReleasePlayerSlot($player->login);
 | 
									$this->maniaControl->client->spectatorReleasePlayerSlot($player->login);
 | 
				
			||||||
			} catch(Exception $e) {
 | 
								} catch (Exception $e) {
 | 
				
			||||||
				if ($e->getMessage() != 'The player is not a spectator') {
 | 
									if ($e->getMessage() != 'The player is not a spectator') {
 | 
				
			||||||
					$this->maniaControl->errorHandler->triggerDebugNotice("ChatMessagePlugin Debug Line " . $e->getLine() . ": " . $e->getMessage());
 | 
										$this->maniaControl->errorHandler->triggerDebugNotice("ChatMessagePlugin Debug Line " . $e->getLine() . ": " . $e->getMessage());
 | 
				
			||||||
					// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
 | 
										// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
 | 
				
			||||||
@@ -380,73 +449,4 @@ class ChatMessagePlugin implements CommandListener, Plugin {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Checks if a Player is in the PlayerList and returns the nickname if he is, can be called per login, pid or nickname or lj for
 | 
					 | 
				
			||||||
	 * (last joined)
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @param $login
 | 
					 | 
				
			||||||
	 * @return mixed
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	private function getTarget($login) {
 | 
					 | 
				
			||||||
		/** @var Player $player */
 | 
					 | 
				
			||||||
		$player = null;
 | 
					 | 
				
			||||||
		foreach($this->maniaControl->playerManager->getPlayers() as $player) {
 | 
					 | 
				
			||||||
			if ($login == $player->login || $login == $player->pid || $login == $player->nickname) {
 | 
					 | 
				
			||||||
				return $player->nickname;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if ($player && $login == 'lj') {
 | 
					 | 
				
			||||||
			return $player->nickname;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		//returns the text given if nothing matches
 | 
					 | 
				
			||||||
		return $login;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Get plugin id
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @return int
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public static function getId() {
 | 
					 | 
				
			||||||
		return self::PLUGIN_ID;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Get Plugin Name
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @return string
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public static function getName() {
 | 
					 | 
				
			||||||
		return self::PLUGIN_NAME;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Get Plugin Version
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @return float,,
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public static function getVersion() {
 | 
					 | 
				
			||||||
		return self::PLUGIN_VERSION;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Get Plugin Author
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @return string
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public static function getAuthor() {
 | 
					 | 
				
			||||||
		return self::PLUGIN_AUTHOR;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Get Plugin Description
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @return string
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public static function getDescription() {
 | 
					 | 
				
			||||||
		return "Plugin offers various Chat-Commands like /gg /hi /afk /rq...";
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -12,7 +12,6 @@ use FML\Controls\Quads\Quad_BgsPlayerCard;
 | 
				
			|||||||
use FML\Controls\Quads\Quad_Icons128x128_1;
 | 
					use FML\Controls\Quads\Quad_Icons128x128_1;
 | 
				
			||||||
use FML\ManiaLink;
 | 
					use FML\ManiaLink;
 | 
				
			||||||
use FML\Script\Features\Paging;
 | 
					use FML\Script\Features\Paging;
 | 
				
			||||||
 | 
					 | 
				
			||||||
use ManiaControl\Admin\AuthenticationManager;
 | 
					use ManiaControl\Admin\AuthenticationManager;
 | 
				
			||||||
use ManiaControl\Bills\BillManager;
 | 
					use ManiaControl\Bills\BillManager;
 | 
				
			||||||
use ManiaControl\Callbacks\CallbackListener;
 | 
					use ManiaControl\Callbacks\CallbackListener;
 | 
				
			||||||
@@ -28,8 +27,8 @@ use ManiaControl\Statistics\StatisticManager;
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * ManiaControl Donation Plugin
 | 
					 * ManiaControl Donation Plugin
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author kremsy and steeffeen
 | 
					 * @author    ManiaControl Team <mail@maniacontrol.com>
 | 
				
			||||||
 * @copyright ManiaControl Copyright © 2014 ManiaControl Team
 | 
					 * @copyright 2014 ManiaControl Team
 | 
				
			||||||
 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
					 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class DonationPlugin implements CallbackListener, CommandListener, Plugin {
 | 
					class DonationPlugin implements CallbackListener, CommandListener, Plugin {
 | 
				
			||||||
@@ -70,52 +69,6 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
 | 
				
			|||||||
		//do nothing
 | 
							//do nothing
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * @see \ManiaControl\Plugins\Plugin::load()
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public function load(ManiaControl $maniaControl) {
 | 
					 | 
				
			||||||
		$this->maniaControl = $maniaControl;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Register for commands
 | 
					 | 
				
			||||||
		$this->maniaControl->commandManager->registerCommandListener('donate', $this, 'command_Donate', false, 'Donate some planets to the server.');
 | 
					 | 
				
			||||||
		$this->maniaControl->commandManager->registerCommandListener('pay', $this, 'command_Pay', true, 'Pays planets from the server to a player.');
 | 
					 | 
				
			||||||
		$this->maniaControl->commandManager->registerCommandListener('planets', $this, 'command_GetPlanets', true, 'Checks the planets-balance of the server.');
 | 
					 | 
				
			||||||
		$this->maniaControl->commandManager->registerCommandListener('topdons', $this, 'command_TopDons', false, 'Provides an overview of who dontated the most planets.');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Register for callbacks
 | 
					 | 
				
			||||||
		$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
 | 
					 | 
				
			||||||
		$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Define player stats
 | 
					 | 
				
			||||||
		$this->maniaControl->statisticManager->defineStatMetaData(self::STAT_PLAYER_DONATIONS);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_ACTIVATED, true);
 | 
					 | 
				
			||||||
		$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_POSX, 156.);
 | 
					 | 
				
			||||||
		$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_POSY, -31.4);
 | 
					 | 
				
			||||||
		$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_WIDTH, 6);
 | 
					 | 
				
			||||||
		$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_HEIGHT, 6);
 | 
					 | 
				
			||||||
		$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATION_VALUES, "20,50,100,500,1000,2000");
 | 
					 | 
				
			||||||
		$this->maniaControl->settingManager->initSetting($this, self::SETTING_MIN_AMOUNT_SHOWN, 100);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Register Stat in Simple StatsList
 | 
					 | 
				
			||||||
		$this->maniaControl->statisticManager->simpleStatsList->registerStat(self::STAT_PLAYER_DONATIONS, 90, "DP", 15);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		$this->displayWidget();
 | 
					 | 
				
			||||||
		return true;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * @see \ManiaControl\Plugins\Plugin::unload()
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public function unload() {
 | 
					 | 
				
			||||||
		$emptyManialink = new ManiaLink(self::MLID_DONATE_WIDGET);
 | 
					 | 
				
			||||||
		$this->maniaControl->manialinkManager->sendManialink($emptyManialink);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		$this->maniaControl->callbackManager->unregisterCallbackListener($this);
 | 
					 | 
				
			||||||
		$this->maniaControl->commandManager->unregisterCommandListener($this);
 | 
					 | 
				
			||||||
		unset($this->maniaControl);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * @see \ManiaControl\Plugins\Plugin::getId()
 | 
						 * @see \ManiaControl\Plugins\Plugin::getId()
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
@@ -151,6 +104,40 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
 | 
				
			|||||||
		return 'Plugin offering commands like /donate, /pay and /planets and a donation widget.';
 | 
							return 'Plugin offering commands like /donate, /pay and /planets and a donation widget.';
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * @see \ManiaControl\Plugins\Plugin::load()
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function load(ManiaControl $maniaControl) {
 | 
				
			||||||
 | 
							$this->maniaControl = $maniaControl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Register for commands
 | 
				
			||||||
 | 
							$this->maniaControl->commandManager->registerCommandListener('donate', $this, 'command_Donate', false, 'Donate some planets to the server.');
 | 
				
			||||||
 | 
							$this->maniaControl->commandManager->registerCommandListener('pay', $this, 'command_Pay', true, 'Pays planets from the server to a player.');
 | 
				
			||||||
 | 
							$this->maniaControl->commandManager->registerCommandListener('planets', $this, 'command_GetPlanets', true, 'Checks the planets-balance of the server.');
 | 
				
			||||||
 | 
							$this->maniaControl->commandManager->registerCommandListener('topdons', $this, 'command_TopDons', false, 'Provides an overview of who dontated the most planets.');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Register for callbacks
 | 
				
			||||||
 | 
							$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
 | 
				
			||||||
 | 
							$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Define player stats
 | 
				
			||||||
 | 
							$this->maniaControl->statisticManager->defineStatMetaData(self::STAT_PLAYER_DONATIONS);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_ACTIVATED, true);
 | 
				
			||||||
 | 
							$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_POSX, 156.);
 | 
				
			||||||
 | 
							$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_POSY, -31.4);
 | 
				
			||||||
 | 
							$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_WIDTH, 6);
 | 
				
			||||||
 | 
							$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATE_WIDGET_HEIGHT, 6);
 | 
				
			||||||
 | 
							$this->maniaControl->settingManager->initSetting($this, self::SETTING_DONATION_VALUES, "20,50,100,500,1000,2000");
 | 
				
			||||||
 | 
							$this->maniaControl->settingManager->initSetting($this, self::SETTING_MIN_AMOUNT_SHOWN, 100);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Register Stat in Simple StatsList
 | 
				
			||||||
 | 
							$this->maniaControl->statisticManager->simpleStatsList->registerStat(self::STAT_PLAYER_DONATIONS, 90, "DP", 15);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$this->displayWidget();
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Display the Widget
 | 
						 * Display the Widget
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
@@ -160,35 +147,6 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Handle ManialinkPageAnswer Callback
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @param array $callback
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public function handleManialinkPageAnswer(array $callback) {
 | 
					 | 
				
			||||||
		$actionId    = $callback[1][2];
 | 
					 | 
				
			||||||
		$boolSetting = (strpos($actionId, self::ACTION_DONATE_VALUE) === 0);
 | 
					 | 
				
			||||||
		if (!$boolSetting) {
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		$login       = $callback[1][1];
 | 
					 | 
				
			||||||
		$player      = $this->maniaControl->playerManager->getPlayer($login);
 | 
					 | 
				
			||||||
		$actionArray = explode(".", $callback[1][2]);
 | 
					 | 
				
			||||||
		$this->handleDonation($player, intval($actionArray[2]));
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Handle PlayerConnect callback
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @param Player $player
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public function handlePlayerConnect(Player $player) {
 | 
					 | 
				
			||||||
		// Display Map Widget
 | 
					 | 
				
			||||||
		if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_DONATE_WIDGET_ACTIVATED)) {
 | 
					 | 
				
			||||||
			$this->displayDonateWidget($player->login);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Displays the Donate Widget
 | 
						 * Displays the Donate Widget
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
@@ -207,7 +165,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
 | 
				
			|||||||
		$itemMarginFactorY = 1.2;
 | 
							$itemMarginFactorY = 1.2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//If game is shootmania lower the icons position by 20
 | 
							//If game is shootmania lower the icons position by 20
 | 
				
			||||||
		if($this->maniaControl->mapManager->getCurrentMap()->getGame() == 'sm') {
 | 
							if ($this->maniaControl->mapManager->getCurrentMap()->getGame() == 'sm') {
 | 
				
			||||||
			$posY -= $shootManiaOffset;
 | 
								$posY -= $shootManiaOffset;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -269,7 +227,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		// Add items
 | 
							// Add items
 | 
				
			||||||
		$x = -2;
 | 
							$x = -2;
 | 
				
			||||||
		foreach(array_reverse($valueArray) as $value) {
 | 
							foreach (array_reverse($valueArray) as $value) {
 | 
				
			||||||
			$label = new Label_Button();
 | 
								$label = new Label_Button();
 | 
				
			||||||
			$popoutFrame->add($label);
 | 
								$popoutFrame->add($label);
 | 
				
			||||||
			$label->setX($x);
 | 
								$label->setX($x);
 | 
				
			||||||
@@ -288,6 +246,98 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
 | 
				
			|||||||
		$this->maniaControl->manialinkManager->sendManialink($maniaLink, $login);
 | 
							$this->maniaControl->manialinkManager->sendManialink($maniaLink, $login);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * @see \ManiaControl\Plugins\Plugin::unload()
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function unload() {
 | 
				
			||||||
 | 
							$emptyManialink = new ManiaLink(self::MLID_DONATE_WIDGET);
 | 
				
			||||||
 | 
							$this->maniaControl->manialinkManager->sendManialink($emptyManialink);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$this->maniaControl->callbackManager->unregisterCallbackListener($this);
 | 
				
			||||||
 | 
							$this->maniaControl->commandManager->unregisterCommandListener($this);
 | 
				
			||||||
 | 
							unset($this->maniaControl);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Handle ManialinkPageAnswer Callback
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @param array $callback
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function handleManialinkPageAnswer(array $callback) {
 | 
				
			||||||
 | 
							$actionId    = $callback[1][2];
 | 
				
			||||||
 | 
							$boolSetting = (strpos($actionId, self::ACTION_DONATE_VALUE) === 0);
 | 
				
			||||||
 | 
							if (!$boolSetting) {
 | 
				
			||||||
 | 
								return;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							$login       = $callback[1][1];
 | 
				
			||||||
 | 
							$player      = $this->maniaControl->playerManager->getPlayer($login);
 | 
				
			||||||
 | 
							$actionArray = explode(".", $callback[1][2]);
 | 
				
			||||||
 | 
							$this->handleDonation($player, intval($actionArray[2]));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Handle a Player Donation
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @param Player $player
 | 
				
			||||||
 | 
						 * @param int    $amount
 | 
				
			||||||
 | 
						 * @param string $receiver
 | 
				
			||||||
 | 
						 * @param string $receiverName
 | 
				
			||||||
 | 
						 * @return bool
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						private function handleDonation(Player $player, $amount, $receiver = '', $receiverName = null) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (!$receiverName) {
 | 
				
			||||||
 | 
								$serverName = $this->maniaControl->client->getServerName();
 | 
				
			||||||
 | 
								$message    = 'Donate ' . $amount . ' Planets to $<' . $serverName . '$>?';
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								$message = 'Donate ' . $amount . ' Planets to $<' . $receiverName . '$>?';
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							//Send and Handle the Bill
 | 
				
			||||||
 | 
							$self = $this;
 | 
				
			||||||
 | 
							$this->maniaControl->billManager->sendBill(function ($data, $status) use (&$self, &$player, $amount, $receiver) {
 | 
				
			||||||
 | 
								switch ($status) {
 | 
				
			||||||
 | 
									case BillManager::DONATED_TO_SERVER:
 | 
				
			||||||
 | 
										if ($self->maniaControl->settingManager->getSetting($self, DonationPlugin::SETTING_ANNOUNCE_SERVERDONATION, true) && $amount >= $self->maniaControl->settingManager->getSetting($self, DonationPlugin::SETTING_MIN_AMOUNT_SHOWN, true)) {
 | 
				
			||||||
 | 
											$login   = null;
 | 
				
			||||||
 | 
											$message = '$<' . $player->nickname . '$> donated ' . $amount . ' Planets! Thanks.';
 | 
				
			||||||
 | 
										} else {
 | 
				
			||||||
 | 
											$login   = $player->login;
 | 
				
			||||||
 | 
											$message = 'Donation successful! Thanks.';
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										$self->maniaControl->chat->sendSuccess($message, $login);
 | 
				
			||||||
 | 
										$self->maniaControl->statisticManager->insertStat(DonationPlugin::STAT_PLAYER_DONATIONS, $player, $self->maniaControl->server->index, $amount);
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									case BillManager::DONATED_TO_RECEIVER:
 | 
				
			||||||
 | 
										$message = "Successfully donated {$amount} to '{$receiver}'!";
 | 
				
			||||||
 | 
										$self->maniaControl->chat->sendSuccess($message, $player->login);
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									case BillManager::PLAYER_REFUSED_DONATION:
 | 
				
			||||||
 | 
										$message = 'Transaction cancelled.';
 | 
				
			||||||
 | 
										$self->maniaControl->chat->sendError($message, $player->login);
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									case BillManager::ERROR_WHILE_TRANSACTION:
 | 
				
			||||||
 | 
										$message = $data;
 | 
				
			||||||
 | 
										$self->maniaControl->chat->sendError($message, $player->login);
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}, $player, $amount, $message);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Handle PlayerConnect callback
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @param Player $player
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function handlePlayerConnect(Player $player) {
 | 
				
			||||||
 | 
							// Display Map Widget
 | 
				
			||||||
 | 
							if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_DONATE_WIDGET_ACTIVATED)) {
 | 
				
			||||||
 | 
								$this->displayDonateWidget($player->login);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Handle /donate command
 | 
						 * Handle /donate command
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
@@ -320,54 +370,14 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Handle a Player Donation
 | 
						 * Send an usage example for /donate to the player
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
	 * @param Player $player
 | 
						 * @param Player $player
 | 
				
			||||||
	 * @param int    $amount
 | 
						 * @return boolean
 | 
				
			||||||
	 * @param string $receiver
 | 
					 | 
				
			||||||
	 * @param string $receiverName
 | 
					 | 
				
			||||||
	 * @return bool
 | 
					 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	private function handleDonation(Player $player, $amount, $receiver = '', $receiverName = null) {
 | 
						private function sendDonateUsageExample(Player $player) {
 | 
				
			||||||
 | 
							$message = "Usage Example: '/donate 100'";
 | 
				
			||||||
		if (!$receiverName) {
 | 
							return $this->maniaControl->chat->sendChat($message, $player->login);
 | 
				
			||||||
			$serverName = $this->maniaControl->client->getServerName();
 | 
					 | 
				
			||||||
			$message    = 'Donate ' . $amount . ' Planets to $<' . $serverName . '$>?';
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			$message = 'Donate ' . $amount . ' Planets to $<' . $receiverName . '$>?';
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		//Send and Handle the Bill
 | 
					 | 
				
			||||||
		$self = $this;
 | 
					 | 
				
			||||||
		$this->maniaControl->billManager->sendBill(function ($data, $status) use (&$self, &$player, $amount, $receiver) {
 | 
					 | 
				
			||||||
			switch($status) {
 | 
					 | 
				
			||||||
				case BillManager::DONATED_TO_SERVER:
 | 
					 | 
				
			||||||
					if ($self->maniaControl->settingManager->getSetting($self, DonationPlugin::SETTING_ANNOUNCE_SERVERDONATION, true) && $amount >= $self->maniaControl->settingManager->getSetting($self, DonationPlugin::SETTING_MIN_AMOUNT_SHOWN, true)) {
 | 
					 | 
				
			||||||
						$login   = null;
 | 
					 | 
				
			||||||
						$message = '$<' . $player->nickname . '$> donated ' . $amount . ' Planets! Thanks.';
 | 
					 | 
				
			||||||
					} else {
 | 
					 | 
				
			||||||
						$login = $player->login;
 | 
					 | 
				
			||||||
						$message = 'Donation successful! Thanks.';
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
					$self->maniaControl->chat->sendSuccess($message, $login);
 | 
					 | 
				
			||||||
					$self->maniaControl->statisticManager->insertStat(DonationPlugin::STAT_PLAYER_DONATIONS, $player, $self->maniaControl->server->index, $amount);
 | 
					 | 
				
			||||||
					break;
 | 
					 | 
				
			||||||
				case BillManager::DONATED_TO_RECEIVER:
 | 
					 | 
				
			||||||
					$message = "Successfully donated {$amount} to '{$receiver}'!";
 | 
					 | 
				
			||||||
					$self->maniaControl->chat->sendSuccess($message, $player->login);
 | 
					 | 
				
			||||||
					break;
 | 
					 | 
				
			||||||
				case BillManager::PLAYER_REFUSED_DONATION:
 | 
					 | 
				
			||||||
					$message = 'Transaction cancelled.';
 | 
					 | 
				
			||||||
					$self->maniaControl->chat->sendError($message, $player->login);
 | 
					 | 
				
			||||||
					break;
 | 
					 | 
				
			||||||
				case BillManager::ERROR_WHILE_TRANSACTION:
 | 
					 | 
				
			||||||
					$message = $data;
 | 
					 | 
				
			||||||
					$self->maniaControl->chat->sendError($message, $player->login);
 | 
					 | 
				
			||||||
					break;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}, $player, $amount, $message);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		return true;
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
@@ -402,7 +412,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		$self = $this;
 | 
							$self = $this;
 | 
				
			||||||
		$this->maniaControl->billManager->sendPlanets(function ($data, $status) use (&$self, &$player, $amount, $receiver) {
 | 
							$this->maniaControl->billManager->sendPlanets(function ($data, $status) use (&$self, &$player, $amount, $receiver) {
 | 
				
			||||||
			switch($status) {
 | 
								switch ($status) {
 | 
				
			||||||
				case BillManager::PAYED_FROM_SERVER:
 | 
									case BillManager::PAYED_FROM_SERVER:
 | 
				
			||||||
					$message = "Successfully payed out {$amount} to '{$receiver}'!";
 | 
										$message = "Successfully payed out {$amount} to '{$receiver}'!";
 | 
				
			||||||
					$self->maniaControl->chat->sendSuccess($message, $player->login);
 | 
										$self->maniaControl->chat->sendSuccess($message, $player->login);
 | 
				
			||||||
@@ -421,6 +431,17 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
 | 
				
			|||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Send an usage example for /pay to the player
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @param Player $player
 | 
				
			||||||
 | 
						 * @return boolean
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						private function sendPayUsageExample(Player $player) {
 | 
				
			||||||
 | 
							$message = "Usage Example: '/pay 100 login'";
 | 
				
			||||||
 | 
							return $this->maniaControl->chat->sendChat($message, $player->login);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Handle //getplanets command
 | 
						 * Handle //getplanets command
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
@@ -438,28 +459,6 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
 | 
				
			|||||||
		return $this->maniaControl->chat->sendInformation($message, $player->login);
 | 
							return $this->maniaControl->chat->sendInformation($message, $player->login);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Send an usage example for /donate to the player
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @param Player $player
 | 
					 | 
				
			||||||
	 * @return boolean
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	private function sendDonateUsageExample(Player $player) {
 | 
					 | 
				
			||||||
		$message = "Usage Example: '/donate 100'";
 | 
					 | 
				
			||||||
		return $this->maniaControl->chat->sendChat($message, $player->login);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Send an usage example for /pay to the player
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @param Player $player
 | 
					 | 
				
			||||||
	 * @return boolean
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	private function sendPayUsageExample(Player $player) {
 | 
					 | 
				
			||||||
		$message = "Usage Example: '/pay 100 login'";
 | 
					 | 
				
			||||||
		return $this->maniaControl->chat->sendChat($message, $player->login);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Handles the /topdons command
 | 
						 * Handles the /topdons command
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
@@ -477,7 +476,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
 | 
				
			|||||||
	 * @return null
 | 
						 * @return null
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	private function showTopDonsList(Player $player) {
 | 
						private function showTopDonsList(Player $player) {
 | 
				
			||||||
		$query = "SELECT * FROM `".StatisticManager::TABLE_STATISTICS."` WHERE `statId` = 3 ORDER BY `value` DESC LIMIT 0, 100";
 | 
							$query  = "SELECT * FROM `" . StatisticManager::TABLE_STATISTICS . "` WHERE `statId` = 3 ORDER BY `value` DESC LIMIT 0, 100";
 | 
				
			||||||
		$mysqli = $this->maniaControl->database->mysqli;
 | 
							$mysqli = $this->maniaControl->database->mysqli;
 | 
				
			||||||
		$result = $mysqli->query($query);
 | 
							$result = $mysqli->query($query);
 | 
				
			||||||
		if ($mysqli->error) {
 | 
							if ($mysqli->error) {
 | 
				
			||||||
@@ -516,7 +515,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
 | 
				
			|||||||
		$i          = 1;
 | 
							$i          = 1;
 | 
				
			||||||
		$y          = $y - 10;
 | 
							$y          = $y - 10;
 | 
				
			||||||
		$pageFrames = array();
 | 
							$pageFrames = array();
 | 
				
			||||||
		while($donator = $result->fetch_object()) {
 | 
							while ($donator = $result->fetch_object()) {
 | 
				
			||||||
			if (!isset($pageFrame)) {
 | 
								if (!isset($pageFrame)) {
 | 
				
			||||||
				$pageFrame = new Frame();
 | 
									$pageFrame = new Frame();
 | 
				
			||||||
				$frame->add($pageFrame);
 | 
									$frame->add($pageFrame);
 | 
				
			||||||
 
 | 
				
			|||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -24,8 +24,8 @@ use ManiaControl\Plugins\Plugin;
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * ManiaControl Widget Plugin
 | 
					 * ManiaControl Widget Plugin
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @author    steeffeen and kremsy
 | 
					 * @author    ManiaControl Team <mail@maniacontrol.com>
 | 
				
			||||||
 * @copyright ManiaControl Copyright © 2014 ManiaControl Team
 | 
					 * @copyright 2014 ManiaControl Team
 | 
				
			||||||
 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
					 * @license   http://www.gnu.org/licenses/ GNU General Public License, Version 3
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
 | 
					class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
 | 
				
			||||||
@@ -88,6 +88,51 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
 | 
				
			|||||||
		//do nothing
 | 
							//do nothing
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Get plugin id
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @return int
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public static function getId() {
 | 
				
			||||||
 | 
							return self::PLUGIN_ID;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Get Plugin Name
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @return string
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public static function getName() {
 | 
				
			||||||
 | 
							return self::PLUGIN_NAME;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Get Plugin Version
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @return float,,
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public static function getVersion() {
 | 
				
			||||||
 | 
							return self::PLUGIN_VERSION;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Get Plugin Author
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @return string
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public static function getAuthor() {
 | 
				
			||||||
 | 
							return self::PLUGIN_AUTHOR;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Get Plugin Description
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @return string
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public static function getDescription() {
 | 
				
			||||||
 | 
							return 'Plugin offers some Widgets';
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Load the plugin
 | 
						 * Load the plugin
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
@@ -135,19 +180,6 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
 | 
				
			|||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Unload the plugin and its resources
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public function unload() {
 | 
					 | 
				
			||||||
		$this->closeWidget(self::MLID_CLOCKWIDGET);
 | 
					 | 
				
			||||||
		$this->closeWidget(self::MLID_SERVERINFOWIDGET);
 | 
					 | 
				
			||||||
		$this->closeWidget(self::MLID_MAPWIDGET);
 | 
					 | 
				
			||||||
		$this->closeWidget(self::MLID_NEXTMAPWIDGET);
 | 
					 | 
				
			||||||
		$this->maniaControl->callbackManager->unregisterCallbackListener($this);
 | 
					 | 
				
			||||||
		$this->maniaControl->timerManager->unregisterTimerListenings($this);
 | 
					 | 
				
			||||||
		unset($this->maniaControl);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Display the Widgets
 | 
						 * Display the Widgets
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
@@ -316,7 +348,7 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
 | 
				
			|||||||
		/**
 | 
							/**
 | 
				
			||||||
		 * @var Player $player
 | 
							 * @var Player $player
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		foreach($players as $player) {
 | 
							foreach ($players as $player) {
 | 
				
			||||||
			if ($player->isSpectator) {
 | 
								if ($player->isSpectator) {
 | 
				
			||||||
				$spectatorCount++;
 | 
									$spectatorCount++;
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
@@ -381,16 +413,16 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Handle on Begin Map
 | 
						 * Unload the plugin and its resources
 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @param Map $map
 | 
					 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function handleOnBeginMap(Map $map) {
 | 
						public function unload() {
 | 
				
			||||||
		// Display Map Widget
 | 
							$this->closeWidget(self::MLID_CLOCKWIDGET);
 | 
				
			||||||
		if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED)) {
 | 
							$this->closeWidget(self::MLID_SERVERINFOWIDGET);
 | 
				
			||||||
			$this->displayMapWidget();
 | 
							$this->closeWidget(self::MLID_MAPWIDGET);
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		$this->closeWidget(self::MLID_NEXTMAPWIDGET);
 | 
							$this->closeWidget(self::MLID_NEXTMAPWIDGET);
 | 
				
			||||||
 | 
							$this->maniaControl->callbackManager->unregisterCallbackListener($this);
 | 
				
			||||||
 | 
							$this->maniaControl->timerManager->unregisterTimerListenings($this);
 | 
				
			||||||
 | 
							unset($this->maniaControl);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
@@ -403,6 +435,19 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
 | 
				
			|||||||
		$this->maniaControl->manialinkManager->sendManialink($emptyManialink);
 | 
							$this->maniaControl->manialinkManager->sendManialink($emptyManialink);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * Handle on Begin Map
 | 
				
			||||||
 | 
						 *
 | 
				
			||||||
 | 
						 * @param Map $map
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						public function handleOnBeginMap(Map $map) {
 | 
				
			||||||
 | 
							// Display Map Widget
 | 
				
			||||||
 | 
							if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED)) {
 | 
				
			||||||
 | 
								$this->displayMapWidget();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							$this->closeWidget(self::MLID_NEXTMAPWIDGET);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Handle on End Map
 | 
						 * Handle on End Map
 | 
				
			||||||
	 *
 | 
						 *
 | 
				
			||||||
@@ -541,49 +586,4 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
 | 
				
			|||||||
			$this->displayServerInfoWidget();
 | 
								$this->displayServerInfoWidget();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Get plugin id
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @return int
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public static function getId() {
 | 
					 | 
				
			||||||
		return self::PLUGIN_ID;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Get Plugin Name
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @return string
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public static function getName() {
 | 
					 | 
				
			||||||
		return self::PLUGIN_NAME;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Get Plugin Version
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @return float,,
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public static function getVersion() {
 | 
					 | 
				
			||||||
		return self::PLUGIN_VERSION;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Get Plugin Author
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @return string
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public static function getAuthor() {
 | 
					 | 
				
			||||||
		return self::PLUGIN_AUTHOR;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/**
 | 
					 | 
				
			||||||
	 * Get Plugin Description
 | 
					 | 
				
			||||||
	 *
 | 
					 | 
				
			||||||
	 * @return string
 | 
					 | 
				
			||||||
	 */
 | 
					 | 
				
			||||||
	public static function getDescription() {
 | 
					 | 
				
			||||||
		return 'Plugin offers some Widgets';
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user