applied common formatting
This commit is contained in:
parent
d52423b737
commit
ba720f46bf
@ -1,13 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Bills;
|
||||
|
||||
use ManiaControl\Players\Player;
|
||||
|
||||
/**
|
||||
* ManiaControl BillData Structure
|
||||
*
|
||||
* @author kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class BillData {
|
||||
@ -23,6 +24,7 @@ class BillData {
|
||||
|
||||
/**
|
||||
* Construct new BillData
|
||||
*
|
||||
* @param mixed $function
|
||||
* @param Player $player
|
||||
* @param int $amount
|
||||
|
@ -11,8 +11,8 @@ use Maniaplanet\DedicatedServer\Structures\Bill;
|
||||
/**
|
||||
* ManiaControl Bill-Manager
|
||||
*
|
||||
* @author kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class BillManager implements CallbackListener {
|
||||
|
@ -2,14 +2,13 @@
|
||||
|
||||
namespace ManiaControl;
|
||||
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\LoginUnknownException;
|
||||
|
||||
/**
|
||||
* Chat Utility Class
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
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
|
||||
* @return string
|
||||
* @return bool
|
||||
*/
|
||||
private function getPrefix($prefix) {
|
||||
if (is_string($prefix)) {
|
||||
return $prefix;
|
||||
}
|
||||
if ($prefix === true) {
|
||||
return $this->maniaControl->settingManager->getSetting($this, self::SETTING_PREFIX);
|
||||
}
|
||||
return '';
|
||||
public function sendInformation($message, $login = null, $prefix = true) {
|
||||
$format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_INFORMATION);
|
||||
return $this->sendChat($format . $message, $login);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,16 +86,19 @@ class Chat {
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an information message to the given login
|
||||
* Get prefix
|
||||
*
|
||||
* @param string $message
|
||||
* @param string $login
|
||||
* @param string|bool $prefix
|
||||
* @return bool
|
||||
* @return string
|
||||
*/
|
||||
public function sendInformation($message, $login = null, $prefix = true) {
|
||||
$format = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FORMAT_INFORMATION);
|
||||
return $this->sendChat($format . $message, $login);
|
||||
private function getPrefix($prefix) {
|
||||
if (is_string($prefix)) {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
@ -141,6 +127,19 @@ class Chat {
|
||||
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
|
||||
*
|
||||
|
@ -5,8 +5,8 @@ namespace ManiaControl;
|
||||
/**
|
||||
* Utility Class offering Methods to convert and use ManiaPlanet Colors
|
||||
*
|
||||
* @author steeffeen
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
abstract class ColorUtil {
|
||||
|
@ -5,8 +5,8 @@ namespace ManiaControl;
|
||||
/**
|
||||
* Command Line Helper Class
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class CommandLineHelper {
|
||||
|
@ -8,8 +8,8 @@ use ManiaControl\Players\Player;
|
||||
/**
|
||||
* Interface for Configurator Menus
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
interface ConfiguratorMenu {
|
||||
|
@ -8,8 +8,8 @@ use ManiaControl\ManiaControl;
|
||||
/**
|
||||
* Database Connection Class
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class Database implements TimerListener {
|
||||
@ -74,26 +74,6 @@ class Database implements TimerListener {
|
||||
$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)
|
||||
*
|
||||
@ -109,7 +89,9 @@ class Database implements TimerListener {
|
||||
|
||||
// Try to connect
|
||||
$result = $this->mysqli->select_db($dbName);
|
||||
if ($result) return true;
|
||||
if ($result) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Create database
|
||||
$databaseQuery = "CREATE DATABASE ?;";
|
||||
@ -171,4 +153,24 @@ class Database implements TimerListener {
|
||||
}
|
||||
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;
|
||||
|
||||
use ManiaControl\Settings\SettingManager;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Settings\SettingManager;
|
||||
|
||||
/**
|
||||
* Database Migration Assistant
|
||||
*
|
||||
* @author steeffeen
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class MigrationHelper {
|
||||
|
@ -8,8 +8,8 @@ use ManiaControl\Update\UpdateManager;
|
||||
/**
|
||||
* Error and Exception Manager Class
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class ErrorHandler {
|
||||
@ -64,16 +64,14 @@ class ErrorHandler {
|
||||
|
||||
if ($this->maniaControl->server) {
|
||||
$error['ServerLogin'] = $this->maniaControl->server->login;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error['ServerLogin'] = '';
|
||||
}
|
||||
|
||||
if ($this->maniaControl->settingManager && $this->maniaControl->updateManager) {
|
||||
$error['UpdateChannel'] = $this->maniaControl->settingManager->getSetting($this->maniaControl->updateManager, UpdateManager::SETTING_UPDATECHECK_CHANNEL);
|
||||
$error['ManiaControlVersion'] = $this->maniaControl->updateManager->getNightlyBuildDate();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error['UpdateChannel'] = '';
|
||||
$error['ManiaControlVersion'] = ManiaControl::VERSION;
|
||||
}
|
||||
@ -86,8 +84,7 @@ class ErrorHandler {
|
||||
|
||||
if (!json_decode($success)) {
|
||||
logMessage("Exception-Report failed!");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
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
|
||||
*
|
||||
@ -136,16 +155,14 @@ class ErrorHandler {
|
||||
|
||||
if ($this->maniaControl->server) {
|
||||
$error['ServerLogin'] = $this->maniaControl->server->login;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error['ServerLogin'] = '';
|
||||
}
|
||||
|
||||
if ($this->maniaControl->settingManager && $this->maniaControl->updateManager) {
|
||||
$error['UpdateChannel'] = $this->maniaControl->settingManager->getSetting($this->maniaControl->updateManager, UpdateManager::SETTING_UPDATECHECK_CHANNEL);
|
||||
$error['ManiaControlVersion'] = ManiaControl::VERSION . '#' . $this->maniaControl->updateManager->getNightlyBuildDate();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$error['UpdateChannel'] = '';
|
||||
$error['ManiaControlVersion'] = ManiaControl::VERSION;
|
||||
}
|
||||
@ -158,8 +175,7 @@ class ErrorHandler {
|
||||
|
||||
if (!json_decode($success)) {
|
||||
logMessage("Error-Report failed!");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
@ -229,29 +236,6 @@ class ErrorHandler {
|
||||
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
|
||||
* return string
|
||||
@ -282,4 +266,14 @@ class ErrorHandler {
|
||||
}
|
||||
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
|
||||
*
|
||||
* @author kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class AsynchronousFileReader {
|
||||
|
@ -1,13 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Files;
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
|
||||
/**
|
||||
* Backup Utility Class
|
||||
*
|
||||
* @author ManiaControl Team
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
abstract class BackupUtil {
|
||||
@ -25,7 +26,7 @@ abstract class BackupUtil {
|
||||
$backupFolder = self::getBackupFolder();
|
||||
$backupFileName = $backupFolder . 'backup_' . ManiaControl::VERSION . '_' . date('y-m-d') . '_' . time() . '.zip';
|
||||
$backupZip = new \ZipArchive();
|
||||
if ($backupZip->open($backupFileName, \ZipArchive::CREATE) !== TRUE) {
|
||||
if ($backupZip->open($backupFileName, \ZipArchive::CREATE) !== true) {
|
||||
trigger_error("Couldn't create Backup Zip!");
|
||||
return false;
|
||||
}
|
||||
@ -39,29 +40,6 @@ abstract class BackupUtil {
|
||||
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
|
||||
*
|
||||
@ -109,4 +87,27 @@ abstract class BackupUtil {
|
||||
closedir($folderHandle);
|
||||
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;
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Formatter;
|
||||
use ManiaControl\ManiaControl;
|
||||
|
||||
/**
|
||||
* Files Utility Class
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
abstract class FileUtil {
|
||||
@ -100,6 +100,16 @@ abstract class FileUtil {
|
||||
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
|
||||
*
|
||||
@ -114,16 +124,6 @@ abstract class FileUtil {
|
||||
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
|
||||
*
|
||||
|
@ -5,8 +5,8 @@ namespace ManiaControl;
|
||||
/**
|
||||
* Class offering Methods to format Texts and Values
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
abstract class Formatter {
|
||||
@ -111,6 +111,16 @@ abstract class Formatter {
|
||||
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
|
||||
*
|
||||
@ -124,16 +134,6 @@ abstract class Formatter {
|
||||
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
|
||||
*
|
||||
|
@ -11,6 +11,7 @@ use ManiaControl\Callbacks\TimerManager;
|
||||
use ManiaControl\Commands\CommandListener;
|
||||
use ManiaControl\Commands\CommandManager;
|
||||
use ManiaControl\Configurators\Configurator;
|
||||
use ManiaControl\Database\Database;
|
||||
use ManiaControl\Files\AsynchronousFileReader;
|
||||
use ManiaControl\Files\FileUtil;
|
||||
use ManiaControl\Manialinks\ManialinkManager;
|
||||
@ -26,7 +27,6 @@ use Maniaplanet\DedicatedServer\Connection;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\TransportException;
|
||||
use ManiaControl\Database\Database;
|
||||
|
||||
require_once __DIR__ . '/Libs/Maniaplanet/DedicatedServer/Connection.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
|
||||
*
|
||||
* @author ManiaControl Team
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class ManiaControl implements CommandListener, TimerListener {
|
||||
@ -66,7 +66,6 @@ class ManiaControl implements CommandListener, TimerListener {
|
||||
public $config = null;
|
||||
public $configurator = null;
|
||||
/**
|
||||
*
|
||||
* @var Connection $client
|
||||
*/
|
||||
public $client = null;
|
||||
@ -137,6 +136,19 @@ class ManiaControl implements CommandListener, TimerListener {
|
||||
$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
|
||||
*/
|
||||
@ -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
|
||||
*
|
||||
@ -223,6 +200,60 @@ class ManiaControl implements CommandListener, TimerListener {
|
||||
$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
|
||||
*
|
||||
@ -266,8 +297,7 @@ class ManiaControl implements CommandListener, TimerListener {
|
||||
$this->client->sendHideManialinkPage();
|
||||
// Close the client connection
|
||||
$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());
|
||||
}
|
||||
}
|
||||
@ -287,36 +317,10 @@ class ManiaControl implements CommandListener, TimerListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Restart ManiaControl
|
||||
*
|
||||
* @param string $message
|
||||
* Collect Garbage
|
||||
*/
|
||||
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();
|
||||
public function collectGarbage() {
|
||||
gc_collect_cycles();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -368,8 +372,7 @@ class ManiaControl implements CommandListener, TimerListener {
|
||||
try {
|
||||
// Manager callbacks
|
||||
$this->callbackManager->manageCallbacks();
|
||||
}
|
||||
catch (TransportException $e) {
|
||||
} catch (TransportException $e) {
|
||||
$this->log("Connection interrupted!");
|
||||
// TODO remove
|
||||
if ($this->errorHandler) {
|
||||
@ -394,13 +397,6 @@ class ManiaControl implements CommandListener, TimerListener {
|
||||
$this->quit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect Garbage
|
||||
*/
|
||||
public function collectGarbage() {
|
||||
gc_collect_cycles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to ManiaPlanet server
|
||||
*/
|
||||
@ -412,8 +408,7 @@ class ManiaControl implements CommandListener, TimerListener {
|
||||
|
||||
try {
|
||||
$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);
|
||||
}
|
||||
|
||||
@ -425,8 +420,7 @@ class ManiaControl implements CommandListener, TimerListener {
|
||||
if (!$this->server->waitForStatus(4)) {
|
||||
trigger_error("Server couldn't get ready!", E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
// TODO remove
|
||||
if ($this->errorHandler) {
|
||||
$this->errorHandler->triggerDebugNotice("Fatal Exception: " . $e->getMessage() . " Trace: " . $e->getTraceAsString());
|
||||
@ -447,8 +441,7 @@ class ManiaControl implements CommandListener, TimerListener {
|
||||
|
||||
try {
|
||||
$scriptSettings = $this->client->getModeScriptSettings();
|
||||
}
|
||||
catch (NotInScriptModeException $e) {
|
||||
} catch (NotInScriptModeException $e) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -459,8 +452,7 @@ class ManiaControl implements CommandListener, TimerListener {
|
||||
$scriptSettings['S_UseScriptCallbacks'] = true;
|
||||
try {
|
||||
$this->client->setModeScriptSettings($scriptSettings);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
// TODO temp added 19.04.2014
|
||||
$this->errorHandler->triggerDebugNotice("Exception line 437 ManiaControl.php " . $e->getMessage());
|
||||
|
||||
|
@ -7,8 +7,8 @@ use ManiaControl\ManiaControl;
|
||||
/**
|
||||
* Interface for ManiaControl Plugins
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
interface Plugin {
|
||||
@ -24,19 +24,6 @@ interface Plugin {
|
||||
*/
|
||||
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
|
||||
*
|
||||
@ -71,4 +58,17 @@ interface Plugin {
|
||||
* @return string
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @author steeffeen
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class PluginInstallMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAnswerListener {
|
||||
|
@ -3,16 +3,16 @@
|
||||
namespace ManiaControl\Plugins;
|
||||
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
use ManiaControl\Callbacks\TimerListener;
|
||||
use ManiaControl\Commands\CommandListener;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
|
||||
/**
|
||||
* Class managing Plugins
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class PluginManager {
|
||||
@ -76,14 +76,64 @@ class PluginManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the plugin is running
|
||||
* Deactivate the plugin with the given class
|
||||
*
|
||||
* @param string $pluginClass
|
||||
* @return bool
|
||||
*/
|
||||
public function isPluginActive($pluginClass) {
|
||||
public function deactivatePlugin($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
|
||||
* @return bool
|
||||
*/
|
||||
public function addPluginClass($pluginClass) {
|
||||
public function isPluginActive($pluginClass) {
|
||||
$pluginClass = $this->getPluginClass($pluginClass);
|
||||
if (in_array($pluginClass, $this->pluginClasses)) {
|
||||
return false;
|
||||
}
|
||||
if (!$this->isPluginClass($pluginClass)) {
|
||||
return false;
|
||||
}
|
||||
array_push($this->pluginClasses, $pluginClass);
|
||||
sort($this->pluginClasses);
|
||||
return true;
|
||||
return isset($this->activePlugins[$pluginClass]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate and start the plugin with the given name
|
||||
* Save plugin status in database
|
||||
*
|
||||
* @param string $pluginClass
|
||||
* @param string $adminLogin
|
||||
* @param string $className
|
||||
* @param bool $active
|
||||
* @return bool
|
||||
*/
|
||||
public function activatePlugin($pluginClass, $adminLogin = null) {
|
||||
if (!is_string($pluginClass)) {
|
||||
private function savePluginStatus($className, $active) {
|
||||
$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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
$pluginStatement->close();
|
||||
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
|
||||
* @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
|
||||
*/
|
||||
private function savePluginStatus($className, $active) {
|
||||
$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);
|
||||
public function addPluginClass($pluginClass) {
|
||||
$pluginClass = $this->getPluginClass($pluginClass);
|
||||
if (in_array($pluginClass, $this->pluginClasses)) {
|
||||
return false;
|
||||
}
|
||||
$activeInt = ($active ? 1 : 0);
|
||||
$pluginStatement->bind_param('si', $className, $activeInt);
|
||||
$pluginStatement->execute();
|
||||
if ($pluginStatement->error) {
|
||||
trigger_error($pluginStatement->error);
|
||||
$pluginStatement->close();
|
||||
if (!$this->isPluginClass($pluginClass)) {
|
||||
return false;
|
||||
}
|
||||
$pluginStatement->close();
|
||||
array_push($this->pluginClasses, $pluginClass);
|
||||
sort($this->pluginClasses);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -365,6 +321,74 @@ class PluginManager {
|
||||
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
|
||||
*
|
||||
@ -378,31 +402,4 @@ class PluginManager {
|
||||
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\Labels\Label_Button;
|
||||
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_Icons128x32_1;
|
||||
use FML\Controls\Quads\Quad_Icons64x64_1;
|
||||
use FML\Script\Features\Paging;
|
||||
use FML\Script\Script;
|
||||
@ -25,8 +25,8 @@ use ManiaControl\Players\Player;
|
||||
/**
|
||||
* Configurator for enabling and disabling Plugins
|
||||
*
|
||||
* @author ManiaControl Team
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getTitle()
|
||||
*/
|
||||
public function getTitle() {
|
||||
return 'Plugins';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Back to the Plugins
|
||||
*/
|
||||
@ -78,6 +71,13 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
$this->maniaControl->configurator->reopenMenu($player, $menuId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getTitle()
|
||||
*/
|
||||
public function getTitle() {
|
||||
return 'Plugins';
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::getMenu()
|
||||
*/
|
||||
@ -356,41 +356,6 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
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
|
||||
*
|
||||
@ -456,7 +421,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles a Boolean Value
|
||||
* Toggle a Boolean Value
|
||||
*
|
||||
* @param $setting
|
||||
* @param Player $player
|
||||
@ -481,4 +446,40 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
$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
|
||||
*
|
||||
* @author kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author kremsy <kremsy@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class ChatMessagePlugin implements CommandListener, Plugin {
|
||||
@ -43,6 +43,51 @@ class ChatMessagePlugin implements CommandListener, Plugin {
|
||||
//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
|
||||
*
|
||||
@ -113,6 +158,30 @@ class ChatMessagePlugin implements CommandListener, Plugin {
|
||||
$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
|
||||
*
|
||||
@ -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\ManiaLink;
|
||||
use FML\Script\Features\Paging;
|
||||
|
||||
use ManiaControl\Admin\AuthenticationManager;
|
||||
use ManiaControl\Bills\BillManager;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
@ -28,8 +27,8 @@ use ManiaControl\Statistics\StatisticManager;
|
||||
/**
|
||||
* ManiaControl Donation Plugin
|
||||
*
|
||||
* @author kremsy and steeffeen
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||
@ -70,52 +69,6 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||
//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()
|
||||
*/
|
||||
@ -151,6 +104,40 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||
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
|
||||
*/
|
||||
@ -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
|
||||
*
|
||||
@ -289,34 +247,32 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle /donate command
|
||||
*
|
||||
* @param array $chatCallback
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
* @see \ManiaControl\Plugins\Plugin::unload()
|
||||
*/
|
||||
public function command_Donate(array $chatCallback, Player $player) {
|
||||
$text = $chatCallback[1][2];
|
||||
$params = explode(' ', $text);
|
||||
if (count($params) < 2) {
|
||||
$this->sendDonateUsageExample($player);
|
||||
return false;
|
||||
}
|
||||
$amount = (int)$params[1];
|
||||
if (!$amount || $amount <= 0) {
|
||||
$this->sendDonateUsageExample($player);
|
||||
return false;
|
||||
}
|
||||
if (count($params) >= 3) {
|
||||
$receiver = $params[2];
|
||||
$receiverPlayer = $this->maniaControl->playerManager->getPlayer($receiver);
|
||||
$receiverName = ($receiverPlayer ? $receiverPlayer->nickname : $receiver);
|
||||
} else {
|
||||
$receiver = '';
|
||||
$receiverName = $this->maniaControl->client->getServerName();
|
||||
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);
|
||||
}
|
||||
|
||||
return $this->handleDonation($player, $amount, $receiver, $receiverName);
|
||||
/**
|
||||
* 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]));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -370,6 +326,60 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||
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
|
||||
*
|
||||
* @param array $chatCallback
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
*/
|
||||
public function command_Donate(array $chatCallback, Player $player) {
|
||||
$text = $chatCallback[1][2];
|
||||
$params = explode(' ', $text);
|
||||
if (count($params) < 2) {
|
||||
$this->sendDonateUsageExample($player);
|
||||
return false;
|
||||
}
|
||||
$amount = (int)$params[1];
|
||||
if (!$amount || $amount <= 0) {
|
||||
$this->sendDonateUsageExample($player);
|
||||
return false;
|
||||
}
|
||||
if (count($params) >= 3) {
|
||||
$receiver = $params[2];
|
||||
$receiverPlayer = $this->maniaControl->playerManager->getPlayer($receiver);
|
||||
$receiverName = ($receiverPlayer ? $receiverPlayer->nickname : $receiver);
|
||||
} else {
|
||||
$receiver = '';
|
||||
$receiverName = $this->maniaControl->client->getServerName();
|
||||
}
|
||||
|
||||
return $this->handleDonation($player, $amount, $receiver, $receiverName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle //pay command
|
||||
*
|
||||
@ -421,6 +431,17 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||
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
|
||||
*
|
||||
@ -438,28 +459,6 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||
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
|
||||
*
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -24,8 +24,8 @@ use ManiaControl\Plugins\Plugin;
|
||||
/**
|
||||
* ManiaControl Widget Plugin
|
||||
*
|
||||
* @author steeffeen and kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
@ -88,6 +88,51 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
//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
|
||||
*
|
||||
@ -135,19 +180,6 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
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
|
||||
*/
|
||||
@ -381,16 +413,16 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle on Begin Map
|
||||
*
|
||||
* @param Map $map
|
||||
* Unload the plugin and its resources
|
||||
*/
|
||||
public function handleOnBeginMap(Map $map) {
|
||||
// Display Map Widget
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED)) {
|
||||
$this->displayMapWidget();
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -403,6 +435,19 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
$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
|
||||
*
|
||||
@ -541,49 +586,4 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
$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';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user