diff --git a/application/core/FML/Controls/Control.php b/application/core/FML/Controls/Control.php index 92c1f5bd..89efe0f7 100644 --- a/application/core/FML/Controls/Control.php +++ b/application/core/FML/Controls/Control.php @@ -83,7 +83,7 @@ abstract class Control implements Renderable { /** * Set x position * - * @param real $x + * @param float $x * @return \FML\Controls\Control */ public function setX($x) { @@ -94,7 +94,7 @@ abstract class Control implements Renderable { /** * Set y position * - * @param real $y + * @param float $y * @return \FML\Controls\Control */ public function setY($y) { @@ -105,7 +105,7 @@ abstract class Control implements Renderable { /** * Set z position * - * @param real $z + * @param float $z * @return \FML\Controls\Control */ public function setZ($z) { @@ -116,9 +116,9 @@ abstract class Control implements Renderable { /** * Set position * - * @param real $x - * @param real $y - * @param real $z + * @param float $x + * @param float $y + * @param float $z * @return \FML\Controls\Control */ public function setPosition($x, $y, $z = null) { @@ -133,7 +133,7 @@ abstract class Control implements Renderable { /** * Set width * - * @param real $width + * @param float $width * @return \FML\Controls\Control */ public function setWidth($width) { @@ -144,7 +144,7 @@ abstract class Control implements Renderable { /** * Set height * - * @param real $height + * @param float $height * @return \FML\Controls\Control */ public function setHeight($height) { @@ -155,8 +155,8 @@ abstract class Control implements Renderable { /** * Set size * - * @param real $width - * @param real $height + * @param float $width + * @param float $height * @return \FML\Controls\Control */ public function setSize($width, $height) { @@ -203,7 +203,7 @@ abstract class Control implements Renderable { /** * Set scale * - * @param real $scale + * @param float $scale * @return \FML\Controls\Control */ public function setScale($scale) { diff --git a/application/core/FML/Controls/Gauge.php b/application/core/FML/Controls/Gauge.php index c90119a4..8ac76d10 100644 --- a/application/core/FML/Controls/Gauge.php +++ b/application/core/FML/Controls/Gauge.php @@ -36,7 +36,7 @@ class Gauge extends Control implements Styleable { /** * Set ratio * - * @param real $ratio + * @param float $ratio * @return \FML\Controls\Gauge */ public function setRatio($ratio) { @@ -47,7 +47,7 @@ class Gauge extends Control implements Styleable { /** * Set grading * - * @param real $grading + * @param float $grading * @return \FML\Controls\Gauge */ public function setGrading($grading) { @@ -69,7 +69,7 @@ class Gauge extends Control implements Styleable { /** * Set rotation * - * @param real $rotation + * @param float $rotation * @return \FML\Controls\Gauge */ public function setRotation($rotation) { diff --git a/application/core/FML/Controls/Label.php b/application/core/FML/Controls/Label.php index 4138b774..0db0b120 100644 --- a/application/core/FML/Controls/Label.php +++ b/application/core/FML/Controls/Label.php @@ -2,6 +2,7 @@ namespace FML\Controls; +use FML\Types\Actionable; use FML\Types\Linkable; use FML\Types\NewLineable; use FML\Types\Scriptable; @@ -13,7 +14,7 @@ use FML\Types\TextFormatable; * * @author steeffeen */ -class Label extends Control implements Linkable, NewLineable, Scriptable, Styleable, TextFormatable { +class Label extends Control implements Actionable, Linkable, NewLineable, Scriptable, Styleable, TextFormatable { /** * Protected properties */ @@ -22,6 +23,7 @@ class Label extends Control implements Linkable, NewLineable, Scriptable, Stylea protected $textEmboss = 0; protected $translate = 0; protected $maxLines = 0; + protected $action = ''; protected $url = ''; protected $manialink = ''; protected $autoNewLine = 0; @@ -78,7 +80,7 @@ class Label extends Control implements Linkable, NewLineable, Scriptable, Stylea /** * Set translate - * + * * @param bool $translate * @return \FML\Controls\Label */ @@ -98,6 +100,16 @@ class Label extends Control implements Linkable, NewLineable, Scriptable, Stylea return $this; } + /** + * + * @see \FML\Types\Actionable::setAction() + * @return \FML\Controls\Label + */ + public function setAction($action) { + $this->action = $action; + return $this; + } + /** * * @see \FML\Types\Linkable::setUrl() @@ -209,6 +221,9 @@ class Label extends Control implements Linkable, NewLineable, Scriptable, Stylea if ($this->maxLines) { $xml->setAttribute('maxlines', $this->maxLines); } + if ($this->action) { + $xml->setAttribute('action', $this->action); + } if ($this->url) { $xml->setAttribute('url', $this->url); } diff --git a/application/core/FML/Controls/Quad.php b/application/core/FML/Controls/Quad.php index 7348c70f..0706771f 100644 --- a/application/core/FML/Controls/Quad.php +++ b/application/core/FML/Controls/Quad.php @@ -2,6 +2,7 @@ namespace FML\Controls; +use FML\Types\Actionable; use FML\Types\BgColorable; use FML\Types\Linkable; use FML\Types\Scriptable; @@ -13,7 +14,7 @@ use FML\Types\SubStyleable; * * @author steeffeen */ -class Quad extends Control implements BgColorable, Linkable, Scriptable, Styleable, SubStyleable { +class Quad extends Control implements Actionable, BgColorable, Linkable, Scriptable, Styleable, SubStyleable { /** * Protected properties */ @@ -21,6 +22,7 @@ class Quad extends Control implements BgColorable, Linkable, Scriptable, Styleab protected $imageFocus = ''; protected $colorize = ''; protected $modulizeColor = ''; + protected $action = ''; protected $bgColor = ''; protected $url = ''; protected $manialink = ''; @@ -83,6 +85,16 @@ class Quad extends Control implements BgColorable, Linkable, Scriptable, Styleab return $this; } + /** + * + * @see \FML\Types\Actionable::setAction() + * @return \FML\Controls\Quad + */ + public function setAction($action) { + $this->action = $action; + return $this; + } + /** * * @see \FML\Types\BgColorable::setBgColor() @@ -172,6 +184,9 @@ class Quad extends Control implements BgColorable, Linkable, Scriptable, Styleab if ($this->modulizeColor) { $xml->setAttribute('modulizecolor', $this->modulizeColor); } + if ($this->action) { + $xml->setAttribute('action', $this->action); + } if ($this->bgColor) { $xml->setAttribute('bgcolor', $this->bgColor); } diff --git a/application/core/FML/Types/Actionable.php b/application/core/FML/Types/Actionable.php new file mode 100644 index 00000000..5be9e87e --- /dev/null +++ b/application/core/FML/Types/Actionable.php @@ -0,0 +1,19 @@ + diff --git a/application/core/FML/Types/Playable.php b/application/core/FML/Types/Playable.php index d1651168..831e35b6 100644 --- a/application/core/FML/Types/Playable.php +++ b/application/core/FML/Types/Playable.php @@ -48,7 +48,7 @@ interface Playable { /** * Set volume * - * @param real $volume + * @param float $volume */ public function setVolume($volume); } diff --git a/application/core/ManiaControl.php b/application/core/ManiaControl.php index 9b1e0978..38bbc338 100644 --- a/application/core/ManiaControl.php +++ b/application/core/ManiaControl.php @@ -12,6 +12,7 @@ use ManiaControl\Players\Player; use ManiaControl\Players\PlayerManager; use ManiaControl\Plugins\PluginManager; use ManiaControl\Server\Server; +use ManiaControl\Manialinks\ManialinkManager; require_once __DIR__ . '/Callbacks/CallbackManager.php'; require_once __DIR__ . '/Commands/CommandManager.php'; @@ -21,7 +22,7 @@ require_once __DIR__ . '/Database.php'; require_once __DIR__ . '/FileUtil.php'; require_once __DIR__ . '/Formatter.php'; require_once __DIR__ . '/Manialinks/ManialinkIdHandler.php'; -require_once __DIR__ . '/Manialinks/ManialinkUtil.php'; +require_once __DIR__ . '/Manialinks/ManialinkManager.php'; require_once __DIR__ . '/Maps/Map.php'; require_once __DIR__ . '/Maps/MapManager.php'; require_once __DIR__ . '/Players/PlayerManager.php'; @@ -62,7 +63,7 @@ class ManiaControl implements CommandListener { public $client = null; public $commandManager = null; public $database = null; - public $manialinkIdHandler = null; + public $manialinkManager = null; public $mapManager = null; public $playerManager = null; public $pluginManager = null; @@ -80,7 +81,7 @@ class ManiaControl implements CommandListener { public function __construct() { $this->database = new Database($this); $this->callbackManager = new CallbackManager($this); - $this->manialinkIdHandler = new ManialinkIdHandler(); + $this->manialinkManager = new ManialinkManager($this); $this->settingManager = new SettingManager($this); $this->chat = new Chat($this); $this->commandManager = new CommandManager($this); diff --git a/application/core/Manialinks/ManialinkManager.php b/application/core/Manialinks/ManialinkManager.php new file mode 100644 index 00000000..aa4382f3 --- /dev/null +++ b/application/core/Manialinks/ManialinkManager.php @@ -0,0 +1,98 @@ +maniaControl = $maniaControl; + $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, + 'handleManialinkPageAnswer'); + } + + /** + * Register a new manialink page answer listener + * + * @param string $manialinkId + * @param ManialinkPageAnswerListener $listener + * @param string $method + * @return bool + */ + public function registerManialinkPageAnswerListener($manialinkId, ManialinkPageAnswerListener $listener, $method) { + if (!method_exists($listener, $method)) { + trigger_error("Given listener for manialinkId '{$manialinkId}' doesn't have callback method '{$method}'."); + return false; + } + if (!array_key_exists($manialinkId, $this->pageAnswerListeners) || !is_array($this->pageAnswerListeners[$manialinkId])) { + // Init listeners array + $this->pageAnswerListeners[$manialinkId] = array(); + } + // Register page answer listener + array_push($this->pageAnswerListeners[$manialinkId], array($listener, $method)); + return true; + } + + /** + * Handle ManialinkPageAnswer callback + * + * @param array $callback + */ + public function handleManialinkPageAnswer(array $callback) { + var_dump($callback); + } + + /** + * Send the given manialink to players + * + * @param string $manialinkText + * @param mixed $logins + * @param int $timeout + * @param bool $hideOnClick + * @return bool + */ + public function sendManialink($manialinkText, $logins = null, $timeout = 0, $hideOnClick = false) { + if (!$logins) { + return $this->maniaControl->client->query('SendDisplayManialinkPage', $manialinkText, $timeout, $hideOnClick); + } + if (is_string($logins)) { + return $this->maniaControl->client->query('SendDisplayManialinkPageToLogin', $logins, $manialinkText, $timeout, + $hideOnClick); + } + if (is_array($logins)) { + $success = true; + foreach ($logins as $login) { + $subSuccess = $this->maniaControl->client->query('SendDisplayManialinkPageToLogin', $login, $manialinkText, $timeout, + $hideOnClick); + if (!$subSuccess) { + $success = false; + } + } + return $success; + } + return false; + } +} + +?> diff --git a/application/core/Manialinks/ManialinkPageAnswerListener.php b/application/core/Manialinks/ManialinkPageAnswerListener.php new file mode 100644 index 00000000..0bef7bfc --- /dev/null +++ b/application/core/Manialinks/ManialinkPageAnswerListener.php @@ -0,0 +1,13 @@ + diff --git a/application/core/Manialinks/ManialinkUtil.php b/application/core/Manialinks/ManialinkUtil.php deleted file mode 100644 index e3f1fa1b..00000000 --- a/application/core/Manialinks/ManialinkUtil.php +++ /dev/null @@ -1,93 +0,0 @@ -query('SendDisplayManialinkPage', $manialinkText, $timeout, $hideOnClick); - } - if (is_string($logins)) { - return $client->query('SendDisplayManialinkPageToLogin', $logins, $manialinkText, $timeout, $hideOnClick); - } - if (is_array($logins)) { - $success = true; - foreach ($logins as $login) { - $subSuccess = $client->query('SendDisplayManialinkPageToLogin', $login, $manialinkText, $timeout, $hideOnClick); - if (!$subSuccess) { - $success = false; - } - } - return $success; - } - return false; - } - - /** - * Build new simple xml element - * - * @param string $name - * @param string $id - * @return \SimpleXMLElement - */ - public static function newManialinkXml($id = null) { - $xml = new \SimpleXMLElement(''); - $xml->addAttribute('version', '1'); - if ($id) { - $xml->addAttribute('id', $id); - } - return $xml; - } - - /** - * Add alignment attributes to an xml element - * - * @param \SimpleXMLElement $xml - * @param string $halign - * @param string $valign - */ - public static function addAlignment(\SimpleXMLElement $xml, $halign = 'center', $valign = 'center2') { - if (!property_exists($xml, 'halign')) { - $xml->addAttribute('halign', $halign); - } - if (!property_exists($xml, 'valign')) { - $xml->addAttribute('valign', $valign); - } - } - - /** - * Add translate attribute to an xml element - * - * @param \SimpleXMLElement $xml - * @param bool $translate - */ - public static function addTranslate(\SimpleXMLElement $xml, $translate = true) { - if (!property_exists($xml, 'translate')) { - $xml->addAttribute('translate', ($translate ? 1 : 0)); - } - } -} - -?> diff --git a/application/core/Settings/SettingConfigurator.php b/application/core/Settings/SettingConfigurator.php index d01f4122..4e880a5e 100644 --- a/application/core/Settings/SettingConfigurator.php +++ b/application/core/Settings/SettingConfigurator.php @@ -26,8 +26,6 @@ class SettingConfigurator implements CallbackListener { $this->maniaControl = $maniaControl; $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'onInit'); - - $this->maniaControl->manialinkIdHandler->reserveManiaLinkIds(100); } /** diff --git a/application/plugins/Chatlog.php b/application/plugins/Chatlog.php index b699da39..3939c389 100644 --- a/application/plugins/Chatlog.php +++ b/application/plugins/Chatlog.php @@ -15,7 +15,9 @@ class ChatlogPlugin extends Plugin implements CallbackListener { * Constants */ const VERSION = '1.0'; + const SETTING_FOLDERNAME = 'Log-Folder Name'; const SETTING_FILENAME = 'Log-File Name'; + const SETTING_USEPID = 'Use Process-Id for File Name'; const SETTING_LOGSERVERMESSAGES = 'Log Server Messages'; /** @@ -36,13 +38,35 @@ class ChatlogPlugin extends Plugin implements CallbackListener { $this->description = 'Plugin logging the chat messages of the server.'; // Init settings - $this->maniaControl->settingManager->initSetting($this, self::SETTING_FILENAME, 'chat.log'); + $this->maniaControl->settingManager->initSetting($this, self::SETTING_FOLDERNAME, 'logs'); + $this->maniaControl->settingManager->initSetting($this, self::SETTING_FILENAME, 'ChatLog.log'); + $this->maniaControl->settingManager->initSetting($this, self::SETTING_USEPID, false); $this->maniaControl->settingManager->initSetting($this, self::SETTING_LOGSERVERMESSAGES, true); // Get settings + $folderName = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FOLDERNAME); + $folderName = FileUtil::getClearedFileName($folderName); + $folderDir = ManiaControlDir . '/' . $folderName; + if (!is_dir($folderDir)) { + $success = mkdir($folderDir); + if (!$success) { + trigger_error("Couldn't create chat log folder '{$folderName}'."); + } + } $fileName = $this->maniaControl->settingManager->getSetting($this, self::SETTING_FILENAME); $fileName = FileUtil::getClearedFileName($fileName); - $this->fileName = ManiaControlDir . '/' . $fileName; + $usePId = $this->maniaControl->settingManager->getSetting($this, self::SETTING_USEPID); + if ($usePId) { + $dotIndex = strripos($fileName, '.'); + $pIdPart = '_' . getmypid(); + if ($dotIndex !== false && $dotIndex >= 0) { + $fileName = substr($fileName, 0, $dotIndex) . $pIdPart . substr($fileName, $dotIndex); + } + else { + $fileName .= $pIdPart; + } + } + $this->fileName = $folderDir . '/' . $fileName; $this->logServerMessages = $this->maniaControl->settingManager->getSetting($this, self::SETTING_LOGSERVERMESSAGES); // Register for callbacks diff --git a/application/plugins/Karma.php b/application/plugins/Karma.php index 3e46ed7e..c7095b40 100644 --- a/application/plugins/Karma.php +++ b/application/plugins/Karma.php @@ -121,7 +121,7 @@ class KarmaPlugin extends Plugin implements CallbackListener { // Send manialink $manialinkText = $this->manialink->render()->saveXML(); - ManialinkUtil::sendManialinkPage($this->maniaControl->client, $manialinkText, $login); + $this->maniaControl->manialinkManager->sendManialink($manialinkText, $login); } } diff --git a/application/plugins/LocalRecords.php b/application/plugins/LocalRecords.php index 9be9e098..e6b7b1f8 100644 --- a/application/plugins/LocalRecords.php +++ b/application/plugins/LocalRecords.php @@ -251,7 +251,7 @@ class LocalRecordsPlugin extends Plugin implements CallbackListener { $frame->add($titleLabel); // TODO: set translateable $titleLabel->setPosition(0, $line_height * -0.9); - $titleLabel->setSize($width); + $titleLabel->setWidth($width); $titleLabel->setStyle(Label_Text::STYLE_TextTitle1); $titleLabel->setTextSize(2); $titleLabel->setText($title);