Compare commits
27 Commits
52945ac7f7
...
master
Author | SHA1 | Date | |
---|---|---|---|
6913609475
|
|||
a42c12ace8
|
|||
a769fec577
|
|||
271395edfa
|
|||
aefff423f7
|
|||
827e59ff93
|
|||
f15fc201d2
|
|||
7a8d9f2b0b | |||
03a991cd50 | |||
84e7e5fb17 | |||
d8f93a3a31 | |||
7ded2c6ffc | |||
356cab4869 | |||
04a35dc47f | |||
cfa42acd24 | |||
43cc088fa6 | |||
e6444a5a47 | |||
a6875cabc8 | |||
bfa3fdce60 | |||
9331e22a54 | |||
9c114cd13b | |||
c8bbb3d7c6 | |||
3044e466b9 | |||
fb36146cf6 | |||
601e3d7431 | |||
39db992394 | |||
40c33de0c8 |
@ -1,3 +1,10 @@
|
||||
###v0.258###
|
||||
#Changes
|
||||
- MC compatibility with MX v2 api
|
||||
###v0.257###
|
||||
#Changes
|
||||
- MC now supports php 8.0 and 8.1
|
||||
|
||||
###v0.255###
|
||||
#Additions
|
||||
- added optional descriptions to Settings (but no MC-settings have descriptions yet)
|
||||
|
@ -56,7 +56,7 @@ class AuthCommands implements CommandListener, UsageInformationAble {
|
||||
|
||||
$text = $chatCallback[1][2];
|
||||
$commandParts = explode(' ', $text);
|
||||
if (!array_key_exists(1, $commandParts)) {
|
||||
if (!array_key_exists(1, $commandParts) || $commandParts[1] === "") {
|
||||
$message = $this->maniaControl->getChat()->formatMessage(
|
||||
'Usage Example: %s %s',
|
||||
$commandParts[0],
|
||||
@ -68,12 +68,10 @@ class AuthCommands implements CommandListener, UsageInformationAble {
|
||||
|
||||
$target = $this->maniaControl->getPlayerManager()->getPlayer($commandParts[1]);
|
||||
if (!$target) {
|
||||
$message = $this->maniaControl->getChat()->formatMessage(
|
||||
'Player %s not found!',
|
||||
$commandParts[1]
|
||||
);
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
return;
|
||||
// It's not needed to save the player, it will be done by the grantAuthLevel function
|
||||
$target = new Player($this->maniaControl, false);
|
||||
$target->login = $commandParts[1];
|
||||
$target->nickname = $commandParts[1];
|
||||
}
|
||||
|
||||
$success = $this->maniaControl->getAuthenticationManager()->grantAuthLevel($target, $targetAuthLevel);
|
||||
|
@ -15,7 +15,7 @@ abstract class AutoLoader {
|
||||
* Register the Auto Loader
|
||||
*/
|
||||
public static function register() {
|
||||
spl_autoload_register(array(get_class(), 'autoload'));
|
||||
spl_autoload_register(array(get_called_class(), 'autoload'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -176,7 +176,7 @@ class CallbackManager implements UsageInformationAble {
|
||||
/**
|
||||
* Remove the Callback Listener from the given Listeners Array
|
||||
*
|
||||
* @param Listening[] $listeningsArray
|
||||
* @param Listening[][] $listeningsArray
|
||||
* @param CallbackListener $listener
|
||||
* @return bool
|
||||
*/
|
||||
|
@ -161,7 +161,7 @@ class HelpManager implements CommandListener, CallbackListener, ManialinkPageAns
|
||||
* @param Player $player
|
||||
* @return string
|
||||
*/
|
||||
private function parseHelpList(array $commands, $isHelpAll = false, Player $player = null) {
|
||||
private function parseHelpList(array $commands, $isHelpAll = false, ?Player $player = null) {
|
||||
$showCommands = array();
|
||||
$registeredMethods = array();
|
||||
$message = '';
|
||||
|
@ -188,7 +188,7 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
||||
* @param Player $player
|
||||
* @return \FML\ManiaLink
|
||||
*/
|
||||
private function buildManialink($menuIdShown = 0, Player $player = null) {
|
||||
private function buildManialink($menuIdShown = 0, ?Player $player = null) {
|
||||
$menuPosX = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_POSX);
|
||||
$menuPosY = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_POSY);
|
||||
$menuWidth = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MENU_WIDTH);
|
||||
|
@ -618,6 +618,7 @@ class GameModeSettings implements ConfiguratorMenu, CallbackListener, Communicat
|
||||
|
||||
// Trigger own callback
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_GAMEMODESETTING_CHANGED, $settingName, $settingValue);
|
||||
Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') changed the gamemode setting "'. $settingName .'" to "'. $settingValue .'"');
|
||||
|
||||
$settingIndex++;
|
||||
}
|
||||
@ -627,7 +628,6 @@ class GameModeSettings implements ConfiguratorMenu, CallbackListener, Communicat
|
||||
|
||||
$chatMessage .= '!';
|
||||
$this->maniaControl->getChat()->sendInformation($chatMessage);
|
||||
Logger::logInfo($chatMessage, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ use FML\Script\Script;
|
||||
use ManiaControl\Admin\AuthenticationManager;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\Logger;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Settings\Setting;
|
||||
@ -528,6 +529,7 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
|
||||
$setting->value = $settingData['Value'];
|
||||
}
|
||||
$this->maniaControl->getSettingManager()->saveSetting($setting);
|
||||
Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') changed the setting "'. $setting->class . '\\\\' . $setting->setting .'" to "'. $setting->value .'"');
|
||||
}
|
||||
|
||||
$this->maniaControl->getChat()->sendSuccess('Settings saved!', $player);
|
||||
|
@ -44,6 +44,9 @@ class Database implements TimerListener {
|
||||
// Enable mysqli Reconnect
|
||||
ini_set('mysqli.reconnect', 'on');
|
||||
|
||||
// Change error report mechanism -> used to set compatibility to php < 8.1
|
||||
mysqli_report(MYSQLI_REPORT_OFF);
|
||||
|
||||
// Open database connection
|
||||
$this->loadConfig();
|
||||
$this->mysqli = @new \mysqli($this->config->host, $this->config->user, $this->config->pass, null, $this->config->port);
|
||||
@ -220,7 +223,7 @@ class Database implements TimerListener {
|
||||
* Check whether the Database Connection is still open
|
||||
*/
|
||||
public function checkConnection() {
|
||||
if (!$this->getMysqli() || !@$this->getMysqli()->ping()) {
|
||||
if (!$this->getMysqli() || !$this->getMysqli()->query('DO 1')) {
|
||||
$this->maniaControl->quit('The MySQL Server has gone away!', true);
|
||||
}
|
||||
}
|
||||
|
@ -136,6 +136,31 @@ class AsyncHttpRequest implements UsageInformationAble {
|
||||
$this->processRequest($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Carry out a PutData Request
|
||||
*/
|
||||
public function putData() {
|
||||
array_push($this->headers, 'Content-Type: ' . $this->contentType);
|
||||
array_push($this->headers, 'Keep-Alive: timeout=600, max=2000');
|
||||
array_push($this->headers, 'Connection: Keep-Alive');
|
||||
array_push($this->headers, 'Expect:');
|
||||
array_push($this->headers, 'Accept-Charset: utf-8');
|
||||
|
||||
$content = $this->content;
|
||||
if ($this->compression) {
|
||||
$content = gzencode($this->content);
|
||||
array_push($this->headers, 'Content-Encoding: gzip');
|
||||
}
|
||||
|
||||
|
||||
$request = $this->newRequest($this->url, $this->timeout);
|
||||
$request->getOptions()->set(CURLOPT_CUSTOMREQUEST, 'PUT')// patch method
|
||||
->set(CURLOPT_POSTFIELDS, $content)// put content field
|
||||
->set(CURLOPT_HTTPHEADER, $this->headers) // headers
|
||||
;
|
||||
|
||||
$this->processRequest($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the Request
|
||||
|
@ -59,6 +59,7 @@ abstract class FileUtil {
|
||||
$fileName = Formatter::utf8($fileName);
|
||||
$fileName = preg_replace('/[^0-9A-Za-z\-\+\.\_\ ]/', '', $fileName);
|
||||
$fileName = preg_replace('/ /', '_', $fileName);
|
||||
$fileName = str_replace(["'", "+"], '', $fileName);
|
||||
return $fileName;
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener,
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const VERSION = '0.256';
|
||||
const VERSION = '0.258';
|
||||
const ISTRACKMANIACONTROL = True;
|
||||
const API_VERSION = '2038-01-19';
|
||||
const MIN_DEDIVERSION = '2020-07-01_00_00';
|
||||
@ -299,7 +299,6 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener,
|
||||
}
|
||||
|
||||
// Delete client
|
||||
Connection::delete($this->getClient());
|
||||
$this->client = null;
|
||||
}
|
||||
|
||||
@ -548,7 +547,7 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener,
|
||||
* @param Player $player
|
||||
*/
|
||||
public function commandVersion(array $chatCallback, Player $player) {
|
||||
$message = 'This server is using TrackManiaControl v' . ManiaControl::VERSION . '!';
|
||||
$message = 'This server is using TrackManiaControl v' . ManiaControl::VERSION . ' with PHP '. phpversion() .'!';
|
||||
$this->getChat()->sendInformation($message, $player);
|
||||
}
|
||||
|
||||
@ -722,7 +721,7 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener,
|
||||
Logger::log("Connecting to Server at {$serverConfig->host}:{$serverConfig->port}...");
|
||||
|
||||
try {
|
||||
$this->client = Connection::factory($serverConfig->host, $serverConfig->port, self::SCRIPT_TIMEOUT, $serverConfig->user, $serverConfig->pass, self::API_VERSION);
|
||||
$this->client = new Connection($serverConfig->host, $serverConfig->port, self::SCRIPT_TIMEOUT, $serverConfig->user, $serverConfig->pass, self::API_VERSION);
|
||||
} catch (TransportException $exception) {
|
||||
$message = "Couldn't connect to the server: '{$exception->getMessage()}'";
|
||||
$this->quit($message, true);
|
||||
|
@ -44,7 +44,7 @@ class MXMapInfo {
|
||||
} else {
|
||||
$this->dir = 'maps';
|
||||
$this->id = $mx->MapID;
|
||||
$this->uid = isset($mx->MapUID) ? $mx->MapUID : '';
|
||||
$this->uid = isset($mx->TrackUID) ? $mx->TrackUID : ''; // TODO: fix when migrating to new api; TrackUID is equal to MapUID
|
||||
}
|
||||
|
||||
if (!isset($mx->GbxMapName) || $mx->GbxMapName === '?') {
|
||||
|
@ -23,7 +23,7 @@ class ManiaExchangeManager implements UsageInformationAble {
|
||||
* Constants
|
||||
* @deprecated SEARCH Constants
|
||||
*/
|
||||
//Search orders (prior parameter) https://api.mania-exchange.com/documents/enums#orderings
|
||||
//Search orders (prior parameter) https://api2.mania.exchange/documents/enums#orderings
|
||||
const SEARCH_ORDER_NONE = -1;
|
||||
const SEARCH_ORDER_TRACK_NAME = 0;
|
||||
const SEARCH_ORDER_AUTHOR = 1;
|
||||
@ -190,7 +190,7 @@ class ManiaExchangeManager implements UsageInformationAble {
|
||||
|
||||
}
|
||||
// compile search URL
|
||||
$url = "https://{$titlePrefix}/api/maps/get_map_info/multi/{$string}";
|
||||
$url = 'https://' . $titlePrefix . "/api/maps/get_map_info/multi/{$string}";
|
||||
|
||||
/*if ($key = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KEY)) {
|
||||
$url .= "&key=" . $key;
|
||||
@ -300,7 +300,7 @@ class ManiaExchangeManager implements UsageInformationAble {
|
||||
|
||||
}
|
||||
// compile search URL
|
||||
$url = "https://{$titlePrefix}/api/maps/get_map_info/multi/{$mapId}";
|
||||
$url = 'https://' . $titlePrefix . '/api/maps/get_map_info/multi/' . $mapId;
|
||||
|
||||
/*if ($key = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KEY)) {
|
||||
$url .= "&key=" . $key;
|
||||
|
@ -18,7 +18,7 @@ use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
|
||||
class ManiaExchangeMapSearch implements UsageInformationAble {
|
||||
use UsageInformationTrait;
|
||||
|
||||
//Search orders (prior parameter) https://api.mania-exchange.com/documents/enums#orderings
|
||||
//Search orders (prior parameter) https://api2.mania.exchange/documents/enums#orderings
|
||||
const SEARCH_ORDER_NONE = -1;
|
||||
const SEARCH_ORDER_TRACK_NAME = 0;
|
||||
const SEARCH_ORDER_AUTHOR = 1;
|
||||
@ -41,7 +41,7 @@ class ManiaExchangeMapSearch implements UsageInformationAble {
|
||||
const SEARCH_ORDER_ONLINE_RATING_LTH = 26;
|
||||
const SEARCH_ORDER_ONLINE_RATING_HTL = 27;
|
||||
|
||||
//Special Search Orders (mode parameter): https://api.mania-exchange.com/documents/enums#modes
|
||||
//Special Search Orders (mode parameter): https://api2.mania.exchange/documents/enums#modes
|
||||
const SEARCH_ORDER_SPECIAL_DEFAULT = 0;
|
||||
const SEARCH_ORDER_SPECIAL_USER_TRACKS = 1;
|
||||
const SEARCH_ORDER_SPECIAL_LATEST_TRACKS = 2;
|
||||
|
@ -75,7 +75,7 @@ class CustomUIManager implements CallbackListener, TimerListener, UsageInformati
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function updateManialink(Player $player = null) {
|
||||
public function updateManialink(?Player $player = null) {
|
||||
$this->maniaControl->getManialinkManager()->sendManialink($this->customUI, $player);
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace ManiaControl\Maps;
|
||||
|
||||
use finfo;
|
||||
use ZipArchive;
|
||||
use FML\Controls\Frame;
|
||||
use FML\Controls\Label;
|
||||
use FML\Controls\Entry;
|
||||
@ -13,6 +15,7 @@ use FML\Controls\Quads\Quad_UIConstruction_Buttons;
|
||||
use FML\Controls\Quads\Quad_UIConstructionBullet_Buttons;
|
||||
use FML\ManiaLink;
|
||||
use FML\Script\Features\Paging;
|
||||
use ManiaControl\Admin\AuthenticationManager;
|
||||
use ManiaControl\Files\AsyncHttpRequest;
|
||||
use ManiaControl\Files\FileUtil;
|
||||
use ManiaControl\Logger;
|
||||
@ -42,6 +45,7 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
|
||||
const ACTION_INSPECT_FILE = 'MapsDirBrowser.InspectFile.';
|
||||
const ACTION_ADD_FILE = 'MapsDirBrowser.AddFile.';
|
||||
const ACTION_ERASE_FILE = 'MapsDirBrowser.EraseFile.';
|
||||
const ACTION_CREATE_FOLDER = 'MapsDirBrowser.CreateFolder';
|
||||
const ACTION_DOWNLOAD_FILE = 'MapsDirBrowser.DownloadFile';
|
||||
const WIDGET_NAME = 'MapsDirBrowser.Widget';
|
||||
const CACHE_FOLDER_PATH = 'FolderPath';
|
||||
@ -68,6 +72,7 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
|
||||
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerRegexListener($this->buildActionRegex(self::ACTION_INSPECT_FILE), $this, 'handleInspectFile');
|
||||
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerRegexListener($this->buildActionRegex(self::ACTION_ADD_FILE), $this, 'handleAddFile');
|
||||
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerRegexListener($this->buildActionRegex(self::ACTION_ERASE_FILE), $this, 'handleEraseFile');
|
||||
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerRegexListener($this->buildActionRegex(self::ACTION_CREATE_FOLDER), $this, 'handleCreateFolder');
|
||||
$this->maniaControl->getManialinkManager()->registerManialinkPageAnswerRegexListener($this->buildActionRegex(self::ACTION_DOWNLOAD_FILE), $this, 'handleDownloadFile');
|
||||
}
|
||||
|
||||
@ -140,7 +145,7 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
|
||||
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
|
||||
|
||||
$innerWidth = $width - 2;
|
||||
$innerHeigth = $height - 22;
|
||||
$innerHeigth = $height - 27;
|
||||
|
||||
$lineHeight = 4.;
|
||||
|
||||
@ -181,12 +186,12 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
|
||||
|
||||
$tooltipLabel = new Label();
|
||||
$repositionnedFrame->addChild($tooltipLabel);
|
||||
$tooltipLabel->setPosition(3, $height * -1 + 10);
|
||||
$tooltipLabel->setPosition(3, $height * -1 + 15);
|
||||
$tooltipLabel->setSize($width * 0.8, 5);
|
||||
$tooltipLabel->setHorizontalAlign($tooltipLabel::LEFT);
|
||||
$tooltipLabel->setTextSize(1);
|
||||
|
||||
// Download button
|
||||
// Back button
|
||||
$backButton = new Label_Button();
|
||||
$repositionnedFrame->addChild($backButton);
|
||||
$backButton->setStyle($backButton::STYLE_CardMain_Quit);
|
||||
@ -194,23 +199,59 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
|
||||
$backButton->setScale(0.5);
|
||||
$backButton->setText('Back');
|
||||
$backButton->setPosition(3, $height * -1 + 5);
|
||||
$backButton->setSize(5, 10);
|
||||
$backButton->setAction(MapCommands::ACTION_OPEN_MAPLIST);
|
||||
|
||||
// Create folder button
|
||||
$label = new Label_Text();
|
||||
$repositionnedFrame->addChild($label);
|
||||
$label->setPosition(25, $height * -1 + 5);
|
||||
$label->setPosition($width - 113, $height * -1 + 10);
|
||||
$label->setSize(25, 5);
|
||||
$label->setHorizontalAlign($label::LEFT);
|
||||
$label->setTextSize(1);
|
||||
$label->setText('Download from URL: ');
|
||||
$label->setText('Create folder: ');
|
||||
$label->setAreaFocusColor("00000000");
|
||||
$label->setAreaColor("00000000");
|
||||
|
||||
$entry = new Entry();
|
||||
$repositionnedFrame->addChild($entry);
|
||||
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
||||
$entry->setHorizontalAlign($entry::LEFT);
|
||||
$entry->setPosition(53, $height * -1 + 5);
|
||||
$entry->setPosition($width - 95, $height * -1 + 10);
|
||||
$entry->setTextSize(1);
|
||||
$entry->setSize($width * 0.35, 4);
|
||||
$entry->setName("Value");
|
||||
$entry->setSize(50, 4);
|
||||
$entry->setName("Name");
|
||||
|
||||
//Search for Map-Name
|
||||
$createFolderButton = $this->maniaControl->getManialinkManager()->getElementBuilder()->buildRoundTextButton(
|
||||
'Create',
|
||||
18,
|
||||
5,
|
||||
self::ACTION_CREATE_FOLDER
|
||||
);
|
||||
$repositionnedFrame->addChild($createFolderButton);
|
||||
$createFolderButton->setPosition($width - 27 - 18/2, $height * -1 + 10);
|
||||
|
||||
// Download button
|
||||
$label = new Label_Text();
|
||||
$repositionnedFrame->addChild($label);
|
||||
$label->setPosition($width - 122, $height * -1 + 5);
|
||||
$label->setSize(27, 5);
|
||||
$label->setHorizontalAlign($label::LEFT);
|
||||
$label->setTextSize(1);
|
||||
$label->setText('Download from URL: ');
|
||||
$label->setAreaFocusColor("00000000");
|
||||
$label->setAreaColor("00000000");
|
||||
$label->addTooltipLabelFeature($tooltipLabel, 'Support Map.Gbx and Zip files');
|
||||
|
||||
$entry = new Entry();
|
||||
$repositionnedFrame->addChild($entry);
|
||||
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
||||
$entry->setHorizontalAlign($entry::LEFT);
|
||||
$entry->setPosition($width - 95, $height * -1 + 5);
|
||||
$entry->setTextSize(1);
|
||||
$entry->setSize(50, 4);
|
||||
$entry->setName("URL");
|
||||
|
||||
//Search for Map-Name
|
||||
$downloadButton = $this->maniaControl->getManialinkManager()->getElementBuilder()->buildRoundTextButton(
|
||||
@ -220,7 +261,7 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
|
||||
self::ACTION_DOWNLOAD_FILE
|
||||
);
|
||||
$repositionnedFrame->addChild($downloadButton);
|
||||
$downloadButton->setPosition(53 + 18 / 2 + $width * 0.35, $height * -1 + 5);
|
||||
$downloadButton->setPosition($width - 27 - 18/2, $height * -1 + 5);
|
||||
|
||||
$mapFiles = $this->scanMapFiles($folderPath);
|
||||
|
||||
@ -282,7 +323,7 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
|
||||
$nameLabel->setAction(self::ACTION_OPEN_FOLDER . substr($shortFilePath, 0, -1))->addTooltipLabelFeature($tooltipLabel, 'Open folder ' . $fileName);
|
||||
} else {
|
||||
// File
|
||||
$nameLabel->setAction(self::ACTION_INSPECT_FILE . $fileName)->addTooltipLabelFeature($tooltipLabel, 'Inspect file ' . $fileName);
|
||||
$nameLabel->setAction(self::ACTION_INSPECT_FILE . base64_encode($fileName))->addTooltipLabelFeature($tooltipLabel, 'Inspect file ' . $fileName);
|
||||
|
||||
if ($canAddMaps) {
|
||||
// 'Add' button
|
||||
@ -291,7 +332,7 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
|
||||
$addButton->setX($width - 5);
|
||||
$addButton->setSize(4, 4);
|
||||
$addButton->setSubStyle($addButton::SUBSTYLE_NewBullet);
|
||||
$addButton->setAction(self::ACTION_ADD_FILE . $fileName);
|
||||
$addButton->setAction(self::ACTION_ADD_FILE . base64_encode($fileName));
|
||||
$addButton->addTooltipLabelFeature($tooltipLabel, 'Add map ' . $fileName);
|
||||
}
|
||||
|
||||
@ -302,7 +343,7 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
|
||||
$eraseButton->setX($width - 10);
|
||||
$eraseButton->setSize(4, 4);
|
||||
$eraseButton->setSubStyle($eraseButton::SUBSTYLE_Erase);
|
||||
$eraseButton->setAction(self::ACTION_ERASE_FILE . $fileName);
|
||||
$eraseButton->setAction(self::ACTION_ERASE_FILE . base64_encode($fileName));
|
||||
$eraseButton->addTooltipLabelFeature($tooltipLabel, 'Erase file ' . $fileName);
|
||||
}
|
||||
}
|
||||
@ -417,9 +458,23 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
|
||||
*/
|
||||
public function handleInspectFile(array $actionCallback, Player $player) {
|
||||
$actionName = $actionCallback[1][2];
|
||||
$fileName = substr($actionName, strlen(self::ACTION_INSPECT_FILE));
|
||||
// TODO: show inspect file view
|
||||
var_dump($fileName);
|
||||
$fileName = base64_decode(substr($actionName, strlen(self::ACTION_INSPECT_FILE)));
|
||||
$folderPath = $player->getCache($this, self::CACHE_FOLDER_PATH);
|
||||
$filePath = $folderPath . $fileName;
|
||||
|
||||
$mapsFolder = $this->maniaControl->getServer()->getDirectory()->getMapsFolder();
|
||||
$relativeFilePath = substr($filePath, strlen($mapsFolder));
|
||||
|
||||
try {
|
||||
$message = '';
|
||||
$infos = $this->maniaControl->getClient()->getMapInfo($relativeFilePath);
|
||||
foreach ($infos as $key => $value) {
|
||||
$message .= '$<$0c0' . $key .':$> '. $value . PHP_EOL;
|
||||
}
|
||||
$this->maniaControl->getChat()->sendChat($message, $player->login, false);
|
||||
} catch (\Throwable $th) {
|
||||
$this->maniaControl->getChat()->sendError("can't fetch map info: ". $th->getMessage(), $player->login);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -429,8 +484,13 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handleAddFile(array $actionCallback, Player $player) {
|
||||
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
|
||||
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
|
||||
$actionName = $actionCallback[1][2];
|
||||
$fileName = substr($actionName, strlen(self::ACTION_ADD_FILE));
|
||||
$fileName = base64_decode(substr($actionName, strlen(self::ACTION_ADD_FILE)));
|
||||
$folderPath = $player->getCache($this, self::CACHE_FOLDER_PATH);
|
||||
$filePath = $folderPath . $fileName;
|
||||
|
||||
@ -475,7 +535,7 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
|
||||
$map
|
||||
);
|
||||
$this->maniaControl->getChat()->sendSuccess($message);
|
||||
Logger::logInfo($message, true);
|
||||
Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') added the map file "'. $filePath .'"');
|
||||
|
||||
// Queue requested Map
|
||||
$this->maniaControl->getMapManager()->getMapQueue()->addMapToMapQueue($player, $map);
|
||||
@ -488,16 +548,33 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handleEraseFile(array $actionCallback, Player $player) {
|
||||
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_ERASE_MAP)) {
|
||||
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
|
||||
$actionName = $actionCallback[1][2];
|
||||
$fileName = substr($actionName, strlen(self::ACTION_ERASE_FILE));
|
||||
$fileName = base64_decode(substr($actionName, strlen(self::ACTION_ERASE_FILE)));
|
||||
$folderPath = $player->getCache($this, self::CACHE_FOLDER_PATH);
|
||||
$filePath = $folderPath . $fileName;
|
||||
|
||||
$maps = $this->maniaControl->getMapManager()->getMaps();
|
||||
$mapsFolder = $this->maniaControl->getServer()->getDirectory()->getMapsFolder();
|
||||
$filteredMaps = array_filter($maps, function ($item) use ($mapsFolder, $filePath) {
|
||||
return ($mapsFolder . $item->fileName === $filePath);
|
||||
});
|
||||
foreach ($filteredMaps as $map) {
|
||||
Logger::log('Map "'. $filePath .'" loaded by the server, removing it from the playlist before erasing the file');
|
||||
$this->maniaControl->getMapManager()->removeMap($player, $map->uid);
|
||||
}
|
||||
|
||||
if (@unlink($filePath)) {
|
||||
$message = $this->maniaControl->getChat()->formatMessage(
|
||||
'Erased %s!',
|
||||
$fileName
|
||||
);
|
||||
$this->maniaControl->getChat()->sendSuccess($message, $player);
|
||||
Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') erased the map file "'. $filePath .'"');
|
||||
$this->showManiaLink($player);
|
||||
} else {
|
||||
$message = $this->maniaControl->getChat()->formatMessage(
|
||||
@ -508,7 +585,38 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle 'CreateFolder' page action
|
||||
*
|
||||
* @param array $actionCallback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handleCreateFolder(array $actionCallback, Player $player) {
|
||||
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
|
||||
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
|
||||
$name = trim($actionCallback[1][3][0]["Value"]);
|
||||
|
||||
var_dump($actionCallback);
|
||||
if ($name === "") return;
|
||||
|
||||
$folderPath = $player->getCache($this, self::CACHE_FOLDER_PATH);
|
||||
if (mkdir($folderPath . $name, 755, true)) {
|
||||
$message = "Successfully created directory ". $name;
|
||||
$this->maniaControl->getChat()->sendSuccess($message, $player);
|
||||
Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') created the folder "'. $folderPath .'"');
|
||||
|
||||
$this->showManiaLink($player, $name);
|
||||
} else {
|
||||
$message = "Failed to create directory ". $name;
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
Logger::logError(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') encountered an error when creating the folder "'. $folderPath .'".');
|
||||
|
||||
$this->showManiaLink($player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle 'handleDownloadFile' page action
|
||||
@ -517,7 +625,8 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handleDownloadFile(array $actionCallback, Player $player) {
|
||||
$url = trim($actionCallback[1][3][0]["Value"]);
|
||||
$url = trim($actionCallback[1][3][1]["Value"]);
|
||||
if ($url === "") return;
|
||||
$folderPath = $player->getCache($this, self::CACHE_FOLDER_PATH);
|
||||
if (filter_var($url, FILTER_VALIDATE_URL)) {
|
||||
|
||||
@ -526,11 +635,37 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
|
||||
if (!$file || $error) {
|
||||
$message = "Impossible to download the file: " . $error;
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
Logger::logError($message);
|
||||
Logger::logError(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') encountered an error during the download of the zip file "'. $url .'": '. $error);
|
||||
return;
|
||||
}
|
||||
$filePath = "";
|
||||
|
||||
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
||||
if ($finfo->buffer($file) === "application/zip") {
|
||||
$zip = new ZipArchive();
|
||||
|
||||
// Create a temporary file
|
||||
$tempFile = tempnam(sys_get_temp_dir(), 'zip');
|
||||
file_put_contents($tempFile, $file);
|
||||
|
||||
$open = $zip->open($tempFile);
|
||||
|
||||
if ($open === true) {
|
||||
$zip->extractTo($folderPath);
|
||||
$zip->close();
|
||||
$message = "Successfully extracted zip archive from ". $url;
|
||||
$this->maniaControl->getChat()->sendSuccess($message, $player);
|
||||
Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') downloaded the zip file "'. $url .'"');
|
||||
} else {
|
||||
$message = "Cannot extract archive from ". $url;
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
Logger::logError(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') encountered an error when downloading the zip file "'. $url .'": Cannot extract the archive');
|
||||
}
|
||||
// Clean up the temporary file
|
||||
unlink($tempFile);
|
||||
} else {
|
||||
$fileName = "";
|
||||
|
||||
$contentdispositionheader = "";
|
||||
foreach ($headers as $key => $value) {
|
||||
if (strtolower($key) === "content-disposition") {
|
||||
@ -559,44 +694,44 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
|
||||
$attributes[trim($key)] = trim($value);
|
||||
}
|
||||
|
||||
$attrNames = ['filename*' => true, 'filename' => false];
|
||||
$filename = null;
|
||||
$isUtf8 = false;
|
||||
foreach ($attrNames as $attrName => $utf8) {
|
||||
if (!empty($attributes[$attrName])) {
|
||||
$filename = trim($attributes[$attrName]);
|
||||
$isUtf8 = $utf8;
|
||||
break;
|
||||
$fileName = null;
|
||||
|
||||
if (array_key_exists('filename*', $attributes)) {
|
||||
$fileName = trim($attributes['filename*']);
|
||||
|
||||
// remove prefix if needed
|
||||
if (strpos(strtolower($fileName), "utf-8''") === 0) {
|
||||
$fileName = substr($fileName, strlen("utf-8''"));
|
||||
}
|
||||
} else if (array_key_exists('filename', $attributes)) {
|
||||
$fileName = trim($attributes['filename']);
|
||||
}
|
||||
|
||||
if ($filename !== null) {
|
||||
if ($isUtf8 && strpos(strtolower($filename), "utf-8''") === 0 && $filename = substr($filename, strlen("utf-8''"))) {
|
||||
$filePath = $folderPath . FileUtil::getClearedFileName(rawurldecode($filename));
|
||||
}
|
||||
if (substr($filename, 0, 1) === '"' && substr($filename, -1, 1) === '"') {
|
||||
$filePath = $folderPath . substr($filename, 1, -1);
|
||||
} else {
|
||||
$filePath = $folderPath . $filename;
|
||||
if ($fileName !== null) {
|
||||
if (substr($fileName, 0, 1) === '"' && substr($fileName, -1, 1) === '"') {
|
||||
$fileName = substr($fileName, 1, -1);
|
||||
}
|
||||
|
||||
$filePath = $folderPath . FileUtil::getClearedFileName($fileName);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->isMapFileName($filePath)) {
|
||||
$message = "File is not a map: " . $filename;
|
||||
$message = "File is not a map: " . $fileName;
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
Logger::logError($message);
|
||||
Logger::logError(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') encountered an error when downloadeding the map file "'. $fileName .'": File is not a map');
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$path = parse_url($url, PHP_URL_PATH);
|
||||
|
||||
// extracted basename
|
||||
$filePath = $folderPath . basename($path);
|
||||
$fileName = basename($path);
|
||||
|
||||
if (!$this->isMapFileName($filePath)) {
|
||||
$filePath .= ".Map.Gbx";
|
||||
if (!$this->isMapFileName($fileName)) {
|
||||
$fileName .= ".Map.Gbx";
|
||||
}
|
||||
$filePath = $folderPath . $fileName;
|
||||
}
|
||||
|
||||
if ($filePath != "") {
|
||||
@ -609,13 +744,19 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
|
||||
}
|
||||
$bytes = file_put_contents($filePath, $file);
|
||||
if (!$bytes || $bytes <= 0) {
|
||||
$message = "Impossible to determine filename";
|
||||
$message = "Failed to write file " . $filePath;
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
Logger::logError($message);
|
||||
Logger::logError(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') encountered an error when downloadeding the map file "'. $fileName .'": Failed to write the file');
|
||||
return;
|
||||
}
|
||||
|
||||
$message = "Successfully downloaded the map ". $fileName;
|
||||
$this->maniaControl->getChat()->sendSuccess($message, $player);
|
||||
Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') downloaded the map file "'. $filePath .'"');
|
||||
}
|
||||
$this->showManiaLink($player, $folderPath);
|
||||
}
|
||||
|
||||
$this->showManiaLink($player);
|
||||
});
|
||||
|
||||
$asyncHttpRequest->getData();
|
||||
|
@ -214,7 +214,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
||||
return;
|
||||
}
|
||||
|
||||
$params = explode(' ', $chatCallback[1][2], 2);
|
||||
$params = explode(' ', trim($chatCallback[1][2]), 2);
|
||||
if (count($params) < 2) {
|
||||
$message = $this->maniaControl->getChat()->formatMessage(
|
||||
'Usage example: %s',
|
||||
|
@ -135,7 +135,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
|
||||
$width = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsWidth();
|
||||
$height = $this->maniaControl->getManialinkManager()->getStyleManager()->getListWidgetsHeight();
|
||||
$buttonY = $height * -0.5 + 10;
|
||||
$buttonY = $height * -0.5 + 5;
|
||||
|
||||
if ($pageIndex < 0) {
|
||||
$pageIndex = (int) $player->getCache($this, self::CACHE_CURRENT_PAGE);
|
||||
@ -178,7 +178,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
self::ACTION_CLEAR_MAPQUEUE
|
||||
);
|
||||
$frame->addChild($clearMapQueueButton);
|
||||
$clearMapQueueButton->setPosition($width * 0.5 - 5 - 30/2, $buttonY);
|
||||
$clearMapQueueButton->setPosition($width * 0.5 - 30/2 - 27, $buttonY);
|
||||
}
|
||||
|
||||
if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_CHECK_UPDATE)) {
|
||||
@ -190,7 +190,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
$this->maniaControl->getManialinkManager()->getIconManager()->getIcon(IconManager::MX_ICON_GREEN)
|
||||
);
|
||||
$frame->addChild($mxCheckForUpdatesButton);
|
||||
$mxCheckForUpdatesButton->setPosition($width * 0.5 - 5 - 30 - 5 - 36/2, $buttonY);
|
||||
$mxCheckForUpdatesButton->setPosition($width * 0.5 - 36/2 - 57, $buttonY);
|
||||
}
|
||||
|
||||
if ($this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
|
||||
@ -201,7 +201,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
DirectoryBrowser::ACTION_SHOW
|
||||
);
|
||||
$frame->addChild($browserButton);
|
||||
$browserButton->setPosition($width * -0.5 + 36 / 2, $buttonY);
|
||||
$browserButton->setPosition($width * -0.5 + 36 / 2 + 5, $buttonY);
|
||||
}
|
||||
|
||||
// Headline
|
||||
@ -224,6 +224,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
||||
|
||||
// Predefine description Label
|
||||
$descriptionLabel = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultDescriptionLabel();
|
||||
$descriptionLabel->setY($height * -0.5 + 12);
|
||||
$frame->addChild($descriptionLabel);
|
||||
|
||||
$queuedMaps = $this->maniaControl->getMapManager()->getMapQueue()->getQueuedMapsRanking();
|
||||
|
@ -195,7 +195,7 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
|
||||
* @param string $uid
|
||||
*/
|
||||
public function updateMap($admin, $uid) {
|
||||
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_ADD_MAP)) return;
|
||||
if ($admin !== null && !$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_ADD_MAP)) return;
|
||||
|
||||
$this->updateMapTimestamp($uid);
|
||||
|
||||
@ -227,7 +227,7 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
|
||||
*
|
||||
* @param ?Setting $setting
|
||||
*/
|
||||
public function updateSettings(Setting $setting = null) {
|
||||
public function updateSettings(?Setting $setting = null) {
|
||||
if (!isset($setting) || !$setting->belongsToClass($this)) return;
|
||||
|
||||
if ($setting->setting === self::SETTING_ENABLE_MX) {
|
||||
@ -274,7 +274,7 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
|
||||
* @return bool
|
||||
*/
|
||||
public function removeMap($admin, $uid, $eraseFile = false, $message = true) {
|
||||
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_REMOVE_MAP)) return;
|
||||
if ($admin !== null && !$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_REMOVE_MAP)) return;
|
||||
|
||||
if (!isset($this->maps[$uid])) {
|
||||
if ($admin) {
|
||||
@ -378,7 +378,7 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
|
||||
public function addMapFromMx($mapId, $login, $update = false) {
|
||||
if (is_numeric($mapId)) {
|
||||
// Check if map exists
|
||||
$this->maniaControl->getMapManager()->getMXManager()->fetchMapInfo($mapId, function (MXMapInfo $mapInfo = null) use (
|
||||
$this->maniaControl->getMapManager()->getMXManager()->fetchMapInfo($mapId, function (?MXMapInfo $mapInfo = null) use (
|
||||
&$login, &$update
|
||||
) {
|
||||
if (!$mapInfo || !isset($mapInfo->uploaded)) {
|
||||
|
@ -115,7 +115,7 @@ class MapQueue implements CallbackListener, CommandListener, UsageInformationAbl
|
||||
*
|
||||
* @param Player $admin |null
|
||||
*/
|
||||
public function clearMapQueue(Player $admin = null) {
|
||||
public function clearMapQueue(?Player $admin = null) {
|
||||
if ($admin && !$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_CLEAR_MAPQUEUE)) {
|
||||
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
|
||||
return;
|
||||
|
@ -400,7 +400,7 @@ class PluginManager {
|
||||
return false;
|
||||
}
|
||||
array_push($this->pluginClasses, $pluginClass);
|
||||
sort($this->pluginClasses);
|
||||
natcasesort($this->pluginClasses);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
usort($pluginClasses, function ($pluginClassA, $pluginClassB) {
|
||||
/** @var Plugin $pluginClassA */
|
||||
/** @var Plugin $pluginClassB */
|
||||
return strcmp($pluginClassA::getName(), $pluginClassB::getName());
|
||||
return strcasecmp($pluginClassA::getName(), $pluginClassB::getName());
|
||||
});
|
||||
|
||||
$repositionnedFrame = new Frame();
|
||||
@ -169,6 +169,26 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
$repositionnedFrame->addChild($pagesFrame);
|
||||
$pagesFrame->setY(-1);
|
||||
|
||||
$descriptionLabel = new Label();
|
||||
$repositionnedFrame->addChild($descriptionLabel);
|
||||
$descriptionLabel->setAlign($descriptionLabel::LEFT, $descriptionLabel::TOP);
|
||||
$descriptionLabel->setPosition(3, $height * -1 + 16);
|
||||
$descriptionLabel->setSize($width - 30, 20);
|
||||
$descriptionLabel->setTextSize(1);
|
||||
$descriptionLabel->setTranslate(true);
|
||||
$descriptionLabel->setVisible(false);
|
||||
$descriptionLabel->setMaxLines(5);
|
||||
$descriptionLabel->setLineSpacing(1);
|
||||
|
||||
$tooltip = new Label();
|
||||
$repositionnedFrame->addChild($tooltip);
|
||||
$tooltip->setAlign($descriptionLabel::LEFT, $descriptionLabel::TOP);
|
||||
$tooltip->setPosition(3, $height * -1 + 5);
|
||||
$tooltip->setSize($width - 30, 5);
|
||||
$tooltip->setTextSize(1);
|
||||
$tooltip->setTranslate(true);
|
||||
$tooltip->setVisible(false);
|
||||
|
||||
$index = 0;
|
||||
$pageFrame = null;
|
||||
foreach ($pluginClasses as $pluginClass) {
|
||||
@ -188,7 +208,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
|
||||
$activeQuad = new Quad_Icons64x64_1();
|
||||
$pluginFrame->addChild($activeQuad);
|
||||
$activeQuad->setPosition(2.5, -0.1, 1);
|
||||
$activeQuad->setPosition(5, 0, 1);
|
||||
$activeQuad->setSize($entryHeight * 0.9, $entryHeight * 0.9);
|
||||
if ($active) {
|
||||
$activeQuad->setSubStyle($activeQuad::SUBSTYLE_LvlGreen);
|
||||
@ -199,44 +219,38 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
$nameLabel = new Label_Text();
|
||||
$pluginFrame->addChild($nameLabel);
|
||||
$nameLabel->setHorizontalAlign($nameLabel::LEFT);
|
||||
$nameLabel->setX(5);
|
||||
$nameLabel->setX(7.5);
|
||||
$nameLabel->setSize($width - 50, $entryHeight);
|
||||
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
|
||||
$nameLabel->setTextSize(2);
|
||||
$nameLabel->setText($pluginClass::getName());
|
||||
|
||||
$descriptionLabel = new Label();
|
||||
$pageFrame->addChild($descriptionLabel);
|
||||
$descriptionLabel->setAlign($descriptionLabel::LEFT, $descriptionLabel::TOP);
|
||||
$descriptionLabel->setPosition(3, $height * -1 + 16);
|
||||
$descriptionLabel->setSize($width - 30, 20);
|
||||
$descriptionLabel->setTextSize(1);
|
||||
$descriptionLabel->setTranslate(true);
|
||||
$descriptionLabel->setVisible(false);
|
||||
$descriptionLabel->setMaxLines(5);
|
||||
$descriptionLabel->setLineSpacing(1);
|
||||
$description = "Author: {$pluginClass::getAuthor()}\nVersion: {$pluginClass::getVersion()}\nDesc: {$pluginClass::getDescription()}";
|
||||
$nameLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
|
||||
$quad = new Quad_Icons128x32_1();
|
||||
$pluginFrame->addChild($quad);
|
||||
$quad->setSubStyle($quad::SUBSTYLE_Settings);
|
||||
$quad->setX($width - 45);
|
||||
$quad->setX($width - 37);
|
||||
$quad->setZ(1);
|
||||
$quad->setSize(5, 5);
|
||||
$quad->setAction(self::ACTION_PREFIX_SETTINGS . $pluginClass);
|
||||
$quad->addTooltipLabelFeature($tooltip, "Open settings of ". $pluginClass::getName());
|
||||
|
||||
$statusChangeButton = new Label_Button();
|
||||
$pluginFrame->addChild($statusChangeButton);
|
||||
$statusChangeButton->setHorizontalAlign($statusChangeButton::RIGHT);
|
||||
$statusChangeButton->setX($width - 6);
|
||||
$statusChangeButton->setStyle($statusChangeButton::STYLE_CardButtonSmall);
|
||||
$statusChangeButton->setStyle($statusChangeButton::STYLE_CardButtonSmallS);
|
||||
if ($active) {
|
||||
$statusChangeButton->setText('Deactivate');
|
||||
$statusChangeButton->setAction(self::ACTION_PREFIX_DISABLEPLUGIN . $pluginClass);
|
||||
$statusChangeButton->addTooltipLabelFeature($tooltip, "Deactivate plugin ". $pluginClass::getName());
|
||||
|
||||
} else {
|
||||
$statusChangeButton->setText('Activate');
|
||||
$statusChangeButton->setAction(self::ACTION_PREFIX_ENABLEPLUGIN . $pluginClass);
|
||||
$statusChangeButton->addTooltipLabelFeature($tooltip, "Activate plugin ". $pluginClass::getName());
|
||||
}
|
||||
|
||||
if ($pluginUpdates && array_key_exists($pluginClass::getId(), $pluginUpdates)) {
|
||||
@ -386,7 +400,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
$entry->setPosition($innerWidth - $valueWidth / 2, 0);
|
||||
$entry->setSize($valueWidth, $settingHeight * 0.9);
|
||||
$entry->setTextSize(1);
|
||||
$entry->setMaxLength(1000);
|
||||
$entry->setMaxLength(1000); // Actions are limited to 1024 chars per field
|
||||
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
||||
$entry->setName(self::ACTION_PREFIX_SETTING . $setting->index);
|
||||
$entry->setDefault($setting->value);
|
||||
@ -622,6 +636,8 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
|
||||
$setting->value = $settingData['Value'];
|
||||
}
|
||||
$this->maniaControl->getSettingManager()->saveSetting($setting);
|
||||
Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') changed the setting "'. $setting->class . '\\\\' . $setting->setting .'" to "'. $setting->value .'"');
|
||||
|
||||
}
|
||||
|
||||
$this->maniaControl->getChat()->sendSuccess('Plugin Settings saved!', $player);
|
||||
|
@ -418,6 +418,7 @@ class ServerOptionsMenu implements CallbackListener, ConfiguratorMenu, TimerList
|
||||
$success = $this->applyNewServerOptions($newServerOptions, $player);
|
||||
if ($success) {
|
||||
$this->maniaControl->getChat()->sendSuccess('Server Options saved!', $player);
|
||||
Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') changed Server Options');
|
||||
} else {
|
||||
$this->maniaControl->getChat()->sendError('Server Options saving failed!', $player);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ use ManiaControl\Admin\AuthenticationManager;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\TimerListener;
|
||||
use ManiaControl\Configurator\ConfiguratorMenu;
|
||||
use ManiaControl\Logger;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Players\Player;
|
||||
use Maniaplanet\DedicatedServer\Structures\VoteRatio;
|
||||
@ -166,6 +167,7 @@ class VoteRatiosMenu implements CallbackListener, ConfiguratorMenu, TimerListene
|
||||
$success = $this->maniaControl->getClient()->setCallVoteRatios($newVoteRatios);
|
||||
if ($success) {
|
||||
$this->maniaControl->getChat()->sendSuccess('Vote Ratios saved!', $player);
|
||||
Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') changed the Vote Ratios');
|
||||
} else {
|
||||
$this->maniaControl->getChat()->sendError('Vote Ratios saving failed!', $player);
|
||||
}
|
||||
|
@ -118,6 +118,15 @@ class SettingManager implements CallbackListener, UsageInformationAble {
|
||||
trigger_error($mysqli->error, E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
// Grow the default value
|
||||
$mysqli->query("ALTER TABLE `" . self::TABLE_SETTINGS . "` MODIFY `default` VARCHAR(1000);");
|
||||
if ($mysqli->error) {
|
||||
// If not Duplicate
|
||||
if ($mysqli->errno !== 1060) {
|
||||
trigger_error($mysqli->error, E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -448,6 +457,10 @@ class SettingManager implements CallbackListener, UsageInformationAble {
|
||||
$this->clearStorage();
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->disableCache && $setting->linked && isset($this->storedSettings[$setting->class . $setting->setting])) {
|
||||
unset($this->storedSettings[$setting->class . $setting->setting]);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -68,7 +68,7 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function checkPluginsUpdate(Player $player = null) {
|
||||
public function checkPluginsUpdate(?Player $player = null) {
|
||||
$message = 'Checking Plugins for newer Versions...';
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendInformation($message, $player);
|
||||
@ -165,7 +165,7 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function performPluginsUpdate(Player $player = null) {
|
||||
public function performPluginsUpdate(?Player $player = null) {
|
||||
$pluginsUpdates = $this->getPluginsUpdates();
|
||||
if (empty($pluginsUpdates)) {
|
||||
$message = 'There are no Plugin Updates available!';
|
||||
@ -241,7 +241,7 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
|
||||
* @param Player $player
|
||||
* @param bool $update
|
||||
*/
|
||||
private function installPlugin(PluginUpdateData $pluginUpdateData, Player $player = null, $update = false) {
|
||||
private function installPlugin(PluginUpdateData $pluginUpdateData, ?Player $player = null, $update = false) {
|
||||
if ($player && !$this->maniaControl->getAuthenticationManager()->checkPermission($player, InstallMenu::SETTING_PERMISSION_INSTALL_PLUGINS))
|
||||
{
|
||||
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
||||
|
@ -64,7 +64,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener,
|
||||
|
||||
// Settings
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_ENABLE_UPDATECHECK, true);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_AUTO_UPDATE, true);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_AUTO_UPDATE, false);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_UPDATECHECK_INTERVAL, 1);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_UPDATECHECK_CHANNEL, $this->getUpdateChannels());
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PERFORM_BACKUPS, true);
|
||||
@ -130,7 +130,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener,
|
||||
*
|
||||
* @param UpdateData $coreUpdateData
|
||||
*/
|
||||
public function setCoreUpdateData(UpdateData $coreUpdateData = null) {
|
||||
public function setCoreUpdateData(?UpdateData $coreUpdateData = null) {
|
||||
$this->coreUpdateData = $coreUpdateData;
|
||||
}
|
||||
|
||||
@ -189,7 +189,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener,
|
||||
*
|
||||
* @param UpdateData $updateData
|
||||
*/
|
||||
public function handleUpdateCheck(UpdateData $updateData = null) {
|
||||
public function handleUpdateCheck(?UpdateData $updateData = null) {
|
||||
if (!$this->checkUpdateData($updateData)) {
|
||||
// No new update available
|
||||
return;
|
||||
@ -218,7 +218,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener,
|
||||
* @param UpdateData $updateData
|
||||
* @return bool
|
||||
*/
|
||||
public function checkUpdateData(UpdateData $updateData = null) {
|
||||
public function checkUpdateData(?UpdateData $updateData = null) {
|
||||
if (!$updateData || !$updateData->url) {
|
||||
// Data corrupted
|
||||
return false;
|
||||
@ -268,7 +268,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener,
|
||||
* @param UpdateData $updateData
|
||||
* @return bool
|
||||
*/
|
||||
public function checkUpdateDataBuildVersion(UpdateData $updateData = null) {
|
||||
public function checkUpdateDataBuildVersion(?UpdateData $updateData = null) {
|
||||
if (!$updateData) {
|
||||
// Data corrupted
|
||||
return false;
|
||||
@ -310,7 +310,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener,
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
*/
|
||||
public function performCoreUpdate(Player $player = null) {
|
||||
public function performCoreUpdate(?Player $player = null) {
|
||||
if (!$this->coreUpdateData) {
|
||||
$message = 'Update failed: No update Data available!';
|
||||
if ($player) {
|
||||
@ -490,7 +490,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener,
|
||||
return;
|
||||
}
|
||||
|
||||
$this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$player) {
|
||||
$this->checkCoreUpdateAsync(function (?UpdateData $updateData = null) use (&$player) {
|
||||
if (!$this->checkUpdateData($updateData)) {
|
||||
$this->maniaControl->getChat()->sendInformation('No Update available!', $player);
|
||||
return;
|
||||
@ -516,7 +516,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener,
|
||||
);
|
||||
$this->maniaControl->getChat()->sendInformation($message, $player);
|
||||
} else {
|
||||
$message = $this->maniaControl->getChat()->formatMesssage(
|
||||
$message = $this->maniaControl->getChat()->formatMessage(
|
||||
'New Nightly Build (%s) available! (Current Build: %s)',
|
||||
$updateData->releaseDate,
|
||||
$buildDate
|
||||
@ -524,14 +524,14 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener,
|
||||
$this->maniaControl->getChat()->sendSuccess($message, $player);
|
||||
}
|
||||
} else {
|
||||
$message = $this->maniaControl->getChat()->formatMesssage(
|
||||
$message = $this->maniaControl->getChat()->formatMessage(
|
||||
'New Nightly Build (%s) available!',
|
||||
$updateData->releaseDate
|
||||
);
|
||||
$this->maniaControl->getChat()->sendSuccess($message, $player);
|
||||
}
|
||||
} else {
|
||||
$message = $this->maniaControl->getChat()->formatMesssage(
|
||||
$message = $this->maniaControl->getChat()->formatMessage(
|
||||
'Update for Version %s available!',
|
||||
$updateData->version
|
||||
);
|
||||
@ -563,7 +563,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener,
|
||||
* @param null $player
|
||||
*/
|
||||
private function checkAndHandleCoreUpdate($player = null) {
|
||||
$this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$player) {
|
||||
$this->checkCoreUpdateAsync(function (?UpdateData $updateData = null) use (&$player) {
|
||||
if (!$updateData) {
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendError('Update is currently not possible!', $player);
|
||||
|
@ -107,6 +107,16 @@ class SystemUtil {
|
||||
Logger::log($message . 'FOUND!');
|
||||
}
|
||||
|
||||
// Check for Xml
|
||||
$message = 'Checking for installed xml ... ';
|
||||
if (!extension_loaded('SimpleXML')) {
|
||||
Logger::log($message . 'NOT FOUND!');
|
||||
Logger::log(" -- You don't have xml installed! Check: https://www.php.net/manual/en/xml.setup.php");
|
||||
$success = false;
|
||||
} else {
|
||||
Logger::log($message . 'FOUND!');
|
||||
}
|
||||
|
||||
if (!$success) {
|
||||
// Missing requirements
|
||||
self::quit();
|
||||
|
@ -22,7 +22,7 @@ abstract class WebReader {
|
||||
* @param callable $function
|
||||
* @return Response
|
||||
*/
|
||||
public static function getUrl($url, callable $function = null) {
|
||||
public static function getUrl($url, ?callable $function = null) {
|
||||
$request = static::newRequest($url);
|
||||
$response = $request->send();
|
||||
if ($function) {
|
||||
@ -73,7 +73,7 @@ abstract class WebReader {
|
||||
* @param callable $function
|
||||
* @return Response
|
||||
*/
|
||||
public static function postUrl($url, $content = null, callable $function = null) {
|
||||
public static function postUrl($url, $content = null, ?callable $function = null) {
|
||||
$request = static::newRequest($url);
|
||||
$request->getOptions()->set(CURLOPT_POST, true); // post method
|
||||
if ($content) {
|
||||
|
@ -38,7 +38,7 @@ class CheckBox implements Renderable, ScriptFeatureable
|
||||
* @param bool $default (optional) Default value
|
||||
* @param Quad $quad (optional) CheckBox quad
|
||||
*/
|
||||
public function __construct($name = null, $default = null, Quad $quad = null)
|
||||
public function __construct($name = null, $default = null, ?Quad $quad = null)
|
||||
{
|
||||
$this->feature = new CheckBoxFeature();
|
||||
if ($name) {
|
||||
|
@ -39,7 +39,7 @@ class ValuePicker implements Renderable, ScriptFeatureable
|
||||
* @param string $default (optional) Default value
|
||||
* @param Label $label (optional) ValuePicker label
|
||||
*/
|
||||
public function __construct($name = null, array $values = null, $default = null, Label $label = null)
|
||||
public function __construct($name = null, ?array $values = null, $default = null, ?Label $label = null)
|
||||
{
|
||||
$this->feature = new ValuePickerFeature();
|
||||
if ($name) {
|
||||
|
@ -191,7 +191,7 @@ class Audio extends Control implements Playable, Scriptable
|
||||
/**
|
||||
* @see Scriptable::setScriptAction()
|
||||
*/
|
||||
public function setScriptAction($scriptAction, array $scriptActionParameters = null)
|
||||
public function setScriptAction($scriptAction, ?array $scriptActionParameters = null)
|
||||
{
|
||||
$this->scriptAction = (string)$scriptAction;
|
||||
$this->setScriptActionParameters($scriptActionParameters);
|
||||
@ -209,7 +209,7 @@ class Audio extends Control implements Playable, Scriptable
|
||||
/**
|
||||
* @see Scriptable::setScriptActionParameters()
|
||||
*/
|
||||
public function setScriptActionParameters(array $scriptActionParameters = null)
|
||||
public function setScriptActionParameters(?array $scriptActionParameters = null)
|
||||
{
|
||||
$this->scriptActionParameters = $scriptActionParameters;
|
||||
return $this;
|
||||
|
@ -273,7 +273,7 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF
|
||||
/**
|
||||
* @see Scriptable::setScriptAction()
|
||||
*/
|
||||
public function setScriptAction($scriptAction, array $scriptActionParameters = null)
|
||||
public function setScriptAction($scriptAction, ?array $scriptActionParameters = null)
|
||||
{
|
||||
$this->scriptAction = (string)$scriptAction;
|
||||
$this->setScriptActionParameters($scriptActionParameters);
|
||||
@ -291,7 +291,7 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF
|
||||
/**
|
||||
* @see Scriptable::setScriptActionParameters()
|
||||
*/
|
||||
public function setScriptActionParameters(array $scriptActionParameters = null)
|
||||
public function setScriptActionParameters(?array $scriptActionParameters = null)
|
||||
{
|
||||
$this->scriptActionParameters = $scriptActionParameters;
|
||||
return $this;
|
||||
|
@ -103,7 +103,7 @@ class Frame extends Control implements Container
|
||||
* @deprecated Use Style
|
||||
* @see Style
|
||||
*/
|
||||
public function setFormat(Format $format = null)
|
||||
public function setFormat(?Format $format = null)
|
||||
{
|
||||
$this->format = $format;
|
||||
return $this;
|
||||
|
@ -138,7 +138,7 @@ class Frame3d extends Frame implements Scriptable
|
||||
/**
|
||||
* @see Scriptable::setScriptAction()
|
||||
*/
|
||||
public function setScriptAction($scriptAction, array $scriptActionParameters = null)
|
||||
public function setScriptAction($scriptAction, ?array $scriptActionParameters = null)
|
||||
{
|
||||
$this->scriptAction = (string)$scriptAction;
|
||||
$this->setScriptActionParameters($scriptActionParameters);
|
||||
@ -156,7 +156,7 @@ class Frame3d extends Frame implements Scriptable
|
||||
/**
|
||||
* @see Scriptable::setScriptActionParameters()
|
||||
*/
|
||||
public function setScriptActionParameters(array $scriptActionParameters = null)
|
||||
public function setScriptActionParameters(?array $scriptActionParameters = null)
|
||||
{
|
||||
$this->scriptActionParameters = $scriptActionParameters;
|
||||
return $this;
|
||||
|
@ -467,7 +467,7 @@ class Label extends Control implements Actionable, Linkable, NewLineable, MultiL
|
||||
/**
|
||||
* @see Scriptable::setScriptAction()
|
||||
*/
|
||||
public function setScriptAction($scriptAction, array $scriptActionParameters = null)
|
||||
public function setScriptAction($scriptAction, ?array $scriptActionParameters = null)
|
||||
{
|
||||
$this->scriptAction = (string)$scriptAction;
|
||||
$this->setScriptActionParameters($scriptActionParameters);
|
||||
@ -485,7 +485,7 @@ class Label extends Control implements Actionable, Linkable, NewLineable, MultiL
|
||||
/**
|
||||
* @see Scriptable::setScriptActionParameters()
|
||||
*/
|
||||
public function setScriptActionParameters(array $scriptActionParameters = null)
|
||||
public function setScriptActionParameters(?array $scriptActionParameters = null)
|
||||
{
|
||||
$this->scriptActionParameters = $scriptActionParameters;
|
||||
return $this;
|
||||
|
@ -579,7 +579,7 @@ class Quad extends Control implements Actionable, BackgroundColorable, BgColorab
|
||||
/**
|
||||
* @see Scriptable::setScriptAction()
|
||||
*/
|
||||
public function setScriptAction($scriptAction, array $scriptActionParameters = null)
|
||||
public function setScriptAction($scriptAction, ?array $scriptActionParameters = null)
|
||||
{
|
||||
$this->scriptAction = (string)$scriptAction;
|
||||
$this->setScriptActionParameters($scriptActionParameters);
|
||||
@ -597,7 +597,7 @@ class Quad extends Control implements Actionable, BackgroundColorable, BgColorab
|
||||
/**
|
||||
* @see Scriptable::setScriptActionParameters()
|
||||
*/
|
||||
public function setScriptActionParameters(array $scriptActionParameters = null)
|
||||
public function setScriptActionParameters(?array $scriptActionParameters = null)
|
||||
{
|
||||
$this->scriptActionParameters = $scriptActionParameters;
|
||||
return $this;
|
||||
|
@ -281,7 +281,7 @@ class TextEdit extends Control implements MultiLineable, Scriptable, Styleable,
|
||||
/**
|
||||
* @see Scriptable::setScriptAction()
|
||||
*/
|
||||
public function setScriptAction($scriptAction, array $scriptActionParameters = null)
|
||||
public function setScriptAction($scriptAction, ?array $scriptActionParameters = null)
|
||||
{
|
||||
$this->scriptAction = (string)$scriptAction;
|
||||
$this->setScriptActionParameters($scriptActionParameters);
|
||||
@ -299,7 +299,7 @@ class TextEdit extends Control implements MultiLineable, Scriptable, Styleable,
|
||||
/**
|
||||
* @see Scriptable::setScriptActionParameters()
|
||||
*/
|
||||
public function setScriptActionParameters(array $scriptActionParameters = null)
|
||||
public function setScriptActionParameters(?array $scriptActionParameters = null)
|
||||
{
|
||||
$this->scriptActionParameters = $scriptActionParameters;
|
||||
return $this;
|
||||
|
@ -191,7 +191,7 @@ class Video extends Control implements Playable, Scriptable
|
||||
/**
|
||||
* @see Scriptable::setScriptAction()
|
||||
*/
|
||||
public function setScriptAction($scriptAction, array $scriptActionParameters = null)
|
||||
public function setScriptAction($scriptAction, ?array $scriptActionParameters = null)
|
||||
{
|
||||
$this->scriptAction = (string)$scriptAction;
|
||||
$this->setScriptActionParameters($scriptActionParameters);
|
||||
@ -209,7 +209,7 @@ class Video extends Control implements Playable, Scriptable
|
||||
/**
|
||||
* @see Scriptable::setScriptActionParameters()
|
||||
*/
|
||||
public function setScriptActionParameters(array $scriptActionParameters = null)
|
||||
public function setScriptActionParameters(?array $scriptActionParameters = null)
|
||||
{
|
||||
$this->scriptActionParameters = $scriptActionParameters;
|
||||
return $this;
|
||||
|
@ -41,7 +41,7 @@ class FrameModel implements Container, Identifiable, Renderable
|
||||
* @param Renderable[] $children Children
|
||||
* @return static
|
||||
*/
|
||||
public static function create($modelId = null, array $children = null)
|
||||
public static function create($modelId = null, ?array $children = null)
|
||||
{
|
||||
return new static($modelId, $children);
|
||||
}
|
||||
@ -53,7 +53,7 @@ class FrameModel implements Container, Identifiable, Renderable
|
||||
* @param string $modelId Model id
|
||||
* @param Renderable[] $children Children
|
||||
*/
|
||||
public function __construct($modelId = null, array $children = null)
|
||||
public function __construct($modelId = null, ?array $children = null)
|
||||
{
|
||||
if ($modelId) {
|
||||
$this->setId($modelId);
|
||||
@ -176,7 +176,7 @@ class FrameModel implements Container, Identifiable, Renderable
|
||||
* @deprecated Use Style
|
||||
* @see Style
|
||||
*/
|
||||
public function setFormat(Format $format = null)
|
||||
public function setFormat(?Format $format = null)
|
||||
{
|
||||
$this->format = $format;
|
||||
return $this;
|
||||
|
@ -96,7 +96,7 @@ class ManiaLink
|
||||
* @param Renderable[] $children (optional) Children
|
||||
* @return static
|
||||
*/
|
||||
public static function create($maniaLinkId = null, $version = null, $name = null, array $children = null)
|
||||
public static function create($maniaLinkId = null, $version = null, $name = null, ?array $children = null)
|
||||
{
|
||||
return new static($maniaLinkId, $version, $name, $children);
|
||||
}
|
||||
@ -110,7 +110,7 @@ class ManiaLink
|
||||
* @param string $name (optional) Name
|
||||
* @param Renderable[] $children (optional) Children
|
||||
*/
|
||||
public function __construct($maniaLinkId = null, $version = null, $name = null, array $children = null)
|
||||
public function __construct($maniaLinkId = null, $version = null, $name = null, ?array $children = null)
|
||||
{
|
||||
if (is_string($version) && (!$name || is_array($name)) && !$children) {
|
||||
// backwards-compatibility (version has been introduced later, if it's a string it's supposed to be the name)
|
||||
@ -418,7 +418,7 @@ class ManiaLink
|
||||
* @param Dico $dico Dictionary
|
||||
* @return static
|
||||
*/
|
||||
public function setDico(Dico $dico = null)
|
||||
public function setDico(?Dico $dico = null)
|
||||
{
|
||||
$this->dico = $dico;
|
||||
return $this;
|
||||
@ -445,7 +445,7 @@ class ManiaLink
|
||||
* @param Stylesheet $stylesheet Stylesheet
|
||||
* @return static
|
||||
*/
|
||||
public function setStylesheet(Stylesheet $stylesheet = null)
|
||||
public function setStylesheet(?Stylesheet $stylesheet = null)
|
||||
{
|
||||
$this->stylesheet = $stylesheet;
|
||||
return $this;
|
||||
@ -489,7 +489,7 @@ class ManiaLink
|
||||
* @param Script $script Script
|
||||
* @return static
|
||||
*/
|
||||
public function setScript(Script $script = null)
|
||||
public function setScript(?Script $script = null)
|
||||
{
|
||||
$this->script = $script;
|
||||
return $this;
|
||||
|
@ -29,7 +29,7 @@ class ManiaLinks
|
||||
* @param ManiaLink[] $children ManiaLink children
|
||||
* @return static
|
||||
*/
|
||||
public static function create(array $children = null)
|
||||
public static function create(?array $children = null)
|
||||
{
|
||||
return new static($children);
|
||||
}
|
||||
@ -40,7 +40,7 @@ class ManiaLinks
|
||||
* @api
|
||||
* @param ManiaLink[] $children ManiaLink children
|
||||
*/
|
||||
public function __construct(array $children = null)
|
||||
public function __construct(?array $children = null)
|
||||
{
|
||||
if ($children) {
|
||||
$this->setChildren($children);
|
||||
@ -162,7 +162,7 @@ class ManiaLinks
|
||||
* @param CustomUI $customUI CustomUI object
|
||||
* @return static
|
||||
*/
|
||||
public function setCustomUI(CustomUI $customUI = null)
|
||||
public function setCustomUI(?CustomUI $customUI = null)
|
||||
{
|
||||
$this->customUI = $customUI;
|
||||
return $this;
|
||||
|
@ -41,7 +41,7 @@ class ActionTrigger extends ScriptFeature
|
||||
* @param Control $control (optional) Action Control
|
||||
* @param string $labelName (optional) Script label name
|
||||
*/
|
||||
public function __construct($actionName = null, Control $control = null, $labelName = ScriptLabel::MOUSECLICK)
|
||||
public function __construct($actionName = null, ?Control $control = null, $labelName = ScriptLabel::MOUSECLICK)
|
||||
{
|
||||
if ($actionName) {
|
||||
$this->setActionName($actionName);
|
||||
@ -96,7 +96,7 @@ class ActionTrigger extends ScriptFeature
|
||||
* @param Control $control Action Control
|
||||
* @return static
|
||||
*/
|
||||
public function setControl(Control $control = null)
|
||||
public function setControl(?Control $control = null)
|
||||
{
|
||||
if ($control) {
|
||||
$control->checkId();
|
||||
|
@ -66,7 +66,7 @@ class CheckBoxFeature extends ScriptFeature
|
||||
* @param Entry $entry (optional) Hidden Entry
|
||||
* @param bool $default (optional) Default value
|
||||
*/
|
||||
public function __construct(Quad $quad = null, Entry $entry = null, $default = null)
|
||||
public function __construct(?Quad $quad = null, ?Entry $entry = null, $default = null)
|
||||
{
|
||||
if ($quad) {
|
||||
$this->setQuad($quad);
|
||||
|
@ -41,7 +41,7 @@ class Clock extends ScriptFeature
|
||||
* @param bool $showSeconds (optional) Show the seconds
|
||||
* @param bool $showFullDate (optional) Show the date
|
||||
*/
|
||||
public function __construct(Label $label = null, $showSeconds = true, $showFullDate = false)
|
||||
public function __construct(?Label $label = null, $showSeconds = true, $showFullDate = false)
|
||||
{
|
||||
if ($label) {
|
||||
$this->setLabel($label);
|
||||
|
@ -41,7 +41,7 @@ class ControlScript extends ScriptFeature
|
||||
* @param string $scriptText (optional) Script text
|
||||
* @param string $labelName (optional) Script Label name
|
||||
*/
|
||||
public function __construct(Control $control = null, $scriptText = null, $labelName = ScriptLabel::MOUSECLICK)
|
||||
public function __construct(?Control $control = null, $scriptText = null, $labelName = ScriptLabel::MOUSECLICK)
|
||||
{
|
||||
if ($control) {
|
||||
$this->setControl($control);
|
||||
|
@ -35,7 +35,7 @@ class EntrySubmit extends ScriptFeature
|
||||
* @param Entry $entry (optional) Entry Control
|
||||
* @param string $url (optional) Submit url
|
||||
*/
|
||||
public function __construct(Entry $entry = null, $url = null)
|
||||
public function __construct(?Entry $entry = null, $url = null)
|
||||
{
|
||||
if ($entry) {
|
||||
$this->setEntry($entry);
|
||||
|
@ -54,7 +54,7 @@ class GraphCurve extends ScriptFeature
|
||||
* @param Graph $graph (optional) Graph
|
||||
* @param array[] $points (optional) Points
|
||||
*/
|
||||
public function __construct(Graph $graph = null, array $points = null)
|
||||
public function __construct(?Graph $graph = null, ?array $points = null)
|
||||
{
|
||||
if ($graph) {
|
||||
$this->setGraph($graph);
|
||||
@ -200,7 +200,7 @@ class GraphCurve extends ScriptFeature
|
||||
* @param float[] $color (optional) Color
|
||||
* @return static
|
||||
*/
|
||||
public function setColor(array $color = null)
|
||||
public function setColor(?array $color = null)
|
||||
{
|
||||
$this->color = $color;
|
||||
return $this;
|
||||
|
@ -38,7 +38,7 @@ class GraphSettings extends ScriptFeature
|
||||
* @api
|
||||
* @param Graph $graph (optional) Graph
|
||||
*/
|
||||
public function __construct(Graph $graph = null)
|
||||
public function __construct(?Graph $graph = null)
|
||||
{
|
||||
if ($graph) {
|
||||
$this->setGraph($graph);
|
||||
|
@ -35,7 +35,7 @@ class MapInfo extends ScriptFeature
|
||||
* @param Control $control (optional) Map Info Control
|
||||
* @param string $labelName (optional) Script Label name
|
||||
*/
|
||||
public function __construct(Control $control = null, $labelName = ScriptLabel::MOUSECLICK)
|
||||
public function __construct(?Control $control = null, $labelName = ScriptLabel::MOUSECLICK)
|
||||
{
|
||||
if ($control) {
|
||||
$this->setControl($control);
|
||||
|
@ -40,7 +40,7 @@ class Menu extends ScriptFeature
|
||||
* @param Control $control (optional) Toggled Menu Control
|
||||
* @param bool $isStartElement (optional) Whether the Menu should start with the given Element
|
||||
*/
|
||||
public function __construct(Control $item = null, Control $control = null, $isStartElement = true)
|
||||
public function __construct(?Control $item = null, ?Control $control = null, $isStartElement = true)
|
||||
{
|
||||
if ($item && $control) {
|
||||
$this->addItem($item, $control, $isStartElement);
|
||||
@ -116,7 +116,7 @@ class Menu extends ScriptFeature
|
||||
* @param MenuElement $startElement Start Element
|
||||
* @return static
|
||||
*/
|
||||
public function setStartElement(MenuElement $startElement = null)
|
||||
public function setStartElement(?MenuElement $startElement = null)
|
||||
{
|
||||
$this->startElement = $startElement;
|
||||
if ($startElement && !in_array($startElement, $this->elements, true)) {
|
||||
|
@ -32,7 +32,7 @@ class MenuElement
|
||||
* @param Control $item (optional) Item Control in the Menu bar
|
||||
* @param Control $control (optional) Toggled Menu Control
|
||||
*/
|
||||
public function __construct(Control $item = null, Control $control = null)
|
||||
public function __construct(?Control $item = null, ?Control $control = null)
|
||||
{
|
||||
if ($item) {
|
||||
$this->setItem($item);
|
||||
|
@ -73,7 +73,7 @@ class Paging extends ScriptFeature
|
||||
* @param PagingPage[] $pages (optional) Pages
|
||||
* @param PagingButton[] $buttons (optional) Pageing Buttons
|
||||
*/
|
||||
public function __construct(Label $label = null, array $pages = null, array $buttons = null)
|
||||
public function __construct(?Label $label = null, ?array $pages = null, ?array $buttons = null)
|
||||
{
|
||||
if ($label) {
|
||||
$this->setLabel($label);
|
||||
|
@ -32,7 +32,7 @@ class PagingButton
|
||||
* @param Control $control (optional) Paging Control
|
||||
* @param int $pagingCount (optional) Number of browsed pages per click
|
||||
*/
|
||||
public function __construct(Control $control = null, $pagingCount = 1)
|
||||
public function __construct(?Control $control = null, $pagingCount = 1)
|
||||
{
|
||||
if ($control) {
|
||||
$this->setControl($control);
|
||||
|
@ -31,7 +31,7 @@ class PagingPage
|
||||
* @param Control $control (optional) Page Control
|
||||
* @param int $pageNumber (optional) Number of the Page
|
||||
*/
|
||||
public function __construct(Control $control = null, $pageNumber = null)
|
||||
public function __construct(?Control $control = null, $pageNumber = null)
|
||||
{
|
||||
if ($control) {
|
||||
$this->setControl($control);
|
||||
|
@ -46,7 +46,7 @@ class PlayerProfile extends ScriptFeature
|
||||
* @param Control $control (optional) Profile Control
|
||||
* @param string $labelName (optional) Script Label name
|
||||
*/
|
||||
public function __construct($login = null, Control $control = null, $labelName = ScriptLabel::MOUSECLICK, $titleId = "Trackmania")
|
||||
public function __construct($login = null, ?Control $control = null, $labelName = ScriptLabel::MOUSECLICK, $titleId = "Trackmania")
|
||||
{
|
||||
if ($login) {
|
||||
$this->setLogin($login);
|
||||
|
@ -27,7 +27,7 @@ class Preload extends ScriptFeature
|
||||
* @api
|
||||
* @param string[] $imageUrls (optional) Image urls
|
||||
*/
|
||||
public function __construct(array $imageUrls = null)
|
||||
public function __construct(?array $imageUrls = null)
|
||||
{
|
||||
if ($imageUrls) {
|
||||
$this->setImageUrls($imageUrls);
|
||||
|
@ -40,7 +40,7 @@ class RadioButtonGroupFeature extends ScriptFeature
|
||||
* @api
|
||||
* @param Entry $entry (optional) Hidden Entry
|
||||
*/
|
||||
public function __construct(Entry $entry = null)
|
||||
public function __construct(?Entry $entry = null)
|
||||
{
|
||||
if ($entry) {
|
||||
$this->setEntry($entry);
|
||||
|
@ -54,8 +54,8 @@ class Toggle extends ScriptFeature
|
||||
* @param bool $onlyHide (optional) If it should only hide the Control but not toggle
|
||||
*/
|
||||
public function __construct(
|
||||
Control $togglingControl = null,
|
||||
Control $toggledControl = null,
|
||||
?Control $togglingControl = null,
|
||||
?Control $toggledControl = null,
|
||||
$labelName = ScriptLabel::MOUSECLICK,
|
||||
$onlyShow = false,
|
||||
$onlyHide = false
|
||||
|
@ -54,7 +54,7 @@ class Tooltip extends ScriptFeature
|
||||
* @param bool $invert (optional) If the visibility toggling should be inverted
|
||||
* @param string $text (optional) Text to display if the TooltipControl is a Label
|
||||
*/
|
||||
public function __construct(Control $hoverControl = null, Control $tooltipControl = null, $stayOnClick = null, $invert = null, $text = null)
|
||||
public function __construct(?Control $hoverControl = null, ?Control $tooltipControl = null, $stayOnClick = null, $invert = null, $text = null)
|
||||
{
|
||||
if ($hoverControl) {
|
||||
$this->setHoverControl($hoverControl);
|
||||
|
@ -85,7 +85,7 @@ class UISound extends ScriptFeature
|
||||
* @param int $variant (optional) Sound variant
|
||||
* @param string $labelName (optional) Script Label name
|
||||
*/
|
||||
public function __construct($soundName = null, Control $control = null, $variant = 0, $labelName = ScriptLabel::MOUSECLICK)
|
||||
public function __construct($soundName = null, ?Control $control = null, $variant = 0, $labelName = ScriptLabel::MOUSECLICK)
|
||||
{
|
||||
if ($soundName) {
|
||||
$this->setSoundName($soundName);
|
||||
@ -143,7 +143,7 @@ class UISound extends ScriptFeature
|
||||
* @param Control $control (optional) Sound Control
|
||||
* @return static
|
||||
*/
|
||||
public function setControl(Control $control = null)
|
||||
public function setControl(?Control $control = null)
|
||||
{
|
||||
if ($control) {
|
||||
$control->checkId();
|
||||
|
@ -56,7 +56,7 @@ class ValuePickerFeature extends ScriptFeature
|
||||
* @param string[] $values (optional) Possible values
|
||||
* @param string $default (optional) Default value
|
||||
*/
|
||||
public function __construct(Label $label = null, Entry $entry = null, array $values = null, $default = null)
|
||||
public function __construct(?Label $label = null, ?Entry $entry = null, ?array $values = null, $default = null)
|
||||
{
|
||||
if ($label) {
|
||||
$this->setLabel($label);
|
||||
|
@ -150,7 +150,7 @@ class Stylesheet
|
||||
* @param Mood $mood Mood
|
||||
* @return static
|
||||
*/
|
||||
public function setMood(Mood $mood = null)
|
||||
public function setMood(?Mood $mood = null)
|
||||
{
|
||||
$this->mood = $mood;
|
||||
return $this;
|
||||
|
@ -90,6 +90,6 @@ interface Container
|
||||
* @deprecated Use Style
|
||||
* @see Style
|
||||
*/
|
||||
public function setFormat(Format $format = null);
|
||||
public function setFormat(?Format $format = null);
|
||||
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ interface Scriptable
|
||||
* @param string[] $scriptActionParameters (optional) Script action parameters
|
||||
* @return static
|
||||
*/
|
||||
public function setScriptAction($scriptAction, array $scriptActionParameters = null);
|
||||
public function setScriptAction($scriptAction, ?array $scriptActionParameters = null);
|
||||
|
||||
/**
|
||||
* Get script action parameters
|
||||
@ -62,6 +62,6 @@ interface Scriptable
|
||||
* @param string[] $scriptActionParameters (optional) Script action parameters
|
||||
* @return static
|
||||
*/
|
||||
public function setScriptActionParameters(array $scriptActionParameters = null);
|
||||
public function setScriptActionParameters(?array $scriptActionParameters = null);
|
||||
|
||||
}
|
||||
|
2272
libs/Maniaplanet/DedicatedServer/Connection.php
Executable file → Normal file
2272
libs/Maniaplanet/DedicatedServer/Connection.php
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
@ -9,46 +9,52 @@ namespace Maniaplanet\DedicatedServer\Structures;
|
||||
|
||||
abstract class AbstractStructure
|
||||
{
|
||||
static public function fromArray($array)
|
||||
public static function fromArrayOfArray($array)
|
||||
{
|
||||
if(!is_array($array))
|
||||
if (!is_array($array)) {
|
||||
return $array;
|
||||
|
||||
$object = new static;
|
||||
foreach($array as $key => $value)
|
||||
$object->{lcfirst($key)} = $value;
|
||||
return $object;
|
||||
}
|
||||
|
||||
static public function fromArrayOfArray($array)
|
||||
{
|
||||
if(!is_array($array))
|
||||
return $array;
|
||||
|
||||
$result = array();
|
||||
foreach($array as $key => $value)
|
||||
$result = [];
|
||||
foreach ($array as $key => $value) {
|
||||
$result[$key] = static::fromArray($value);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
static public function getPropertyFromArray($array, $property)
|
||||
public static function fromArray($array)
|
||||
{
|
||||
if (!is_array($array)) {
|
||||
return $array;
|
||||
}
|
||||
|
||||
$object = new static;
|
||||
foreach ($array as $key => $value) {
|
||||
$object->{lcfirst($key)} = $value;
|
||||
}
|
||||
return $object;
|
||||
}
|
||||
|
||||
public static function getPropertyFromArray($array, $property)
|
||||
{
|
||||
return array_map(get_called_class() . '::extractProperty', $array, array_fill(0, count($array), $property));
|
||||
}
|
||||
|
||||
static protected function extractProperty($element, $property)
|
||||
protected static function extractProperty($element, $property)
|
||||
{
|
||||
if(!is_a($element, get_called_class()) || !property_exists($element, $property))
|
||||
if (!is_a($element, get_called_class()) || !property_exists($element, $property)) {
|
||||
throw new \InvalidArgumentException('property ' . $property . ' does not exists in class: ' . get_called_class());
|
||||
}
|
||||
|
||||
return $element->$property;
|
||||
}
|
||||
|
||||
function toArray()
|
||||
{
|
||||
$out = array();
|
||||
foreach(get_object_vars($this) as $key => $value)
|
||||
$out = [];
|
||||
foreach (get_object_vars($this) as $key => $value) {
|
||||
$out[ucfirst($key)] = $value;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class NetworkStats extends AbstractStructure
|
||||
/** @var PlayerNetInfo[] */
|
||||
public $playerNetInfos;
|
||||
|
||||
static public function fromArray($array)
|
||||
public static function fromArray($array)
|
||||
{
|
||||
$object = parent::fromArray($array);
|
||||
$object->playerNetInfos = PlayerNetInfo::fromArrayOfArray($object->playerNetInfos);
|
||||
|
1
libs/Maniaplanet/DedicatedServer/Structures/Player.php
Executable file → Normal file
1
libs/Maniaplanet/DedicatedServer/Structures/Player.php
Executable file → Normal file
@ -4,6 +4,7 @@
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
|
||||
*/
|
||||
|
||||
namespace Maniaplanet\DedicatedServer\Structures;
|
||||
|
||||
class Player extends AbstractStructure
|
||||
|
@ -46,10 +46,22 @@ class PlayerDetailedInfo extends Player
|
||||
/** @var string */
|
||||
public $broadcasterLogin;
|
||||
/** @var string[] */
|
||||
public $allies = array();
|
||||
public $allies = [];
|
||||
/** @var string */
|
||||
public $clubLink;
|
||||
|
||||
/**
|
||||
* @return PlayerDetailedInfo
|
||||
*/
|
||||
public static function fromArray($array)
|
||||
{
|
||||
$object = parent::fromArray($array);
|
||||
$object->avatar = FileDesc::fromArray($object->avatar);
|
||||
$object->skins = Skin::fromArrayOfArray($object->skins);
|
||||
$object->ladderStats = LadderStats::fromArray($object->ladderStats);
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
@ -57,16 +69,4 @@ class PlayerDetailedInfo extends Player
|
||||
{
|
||||
return explode('|', $this->path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PlayerDetailedInfo
|
||||
*/
|
||||
static public function fromArray($array)
|
||||
{
|
||||
$object = parent::fromArray($array);
|
||||
$object->avatar = FileDesc::fromArray($object->avatar);
|
||||
$object->skins = Skin::fromArrayOfArray($object->skins);
|
||||
$object->ladderStats = LadderStats::fromArray($object->ladderStats);
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
|
4
libs/Maniaplanet/DedicatedServer/Structures/PlayerInfo.php
Executable file → Normal file
4
libs/Maniaplanet/DedicatedServer/Structures/PlayerInfo.php
Executable file → Normal file
@ -20,7 +20,7 @@ class PlayerInfo extends Player
|
||||
/** @var bool */
|
||||
public $isInOfficialMode;
|
||||
/** @var int */
|
||||
public $ladderScore;
|
||||
public $ladderScore; // TODO CHECK IF EXISTS
|
||||
/** @var int */
|
||||
public $ladderRanking;
|
||||
/** @var int */
|
||||
@ -63,7 +63,7 @@ class PlayerInfo extends Player
|
||||
/**
|
||||
* @return PlayerInfo
|
||||
*/
|
||||
static public function fromArray($array)
|
||||
public static function fromArray($array)
|
||||
{
|
||||
$object = parent::fromArray($array);
|
||||
|
||||
|
@ -18,9 +18,9 @@ class ScriptInfo extends AbstractStructure
|
||||
/** @var string */
|
||||
public $version;
|
||||
/** @var ScriptSettings[] */
|
||||
public $paramDescs = array();
|
||||
public $paramDescs = [];
|
||||
/** @var Command[] */
|
||||
public $commandDescs = array();
|
||||
public $commandDescs = [];
|
||||
|
||||
/**
|
||||
* @return ScriptInfo
|
||||
|
@ -27,7 +27,7 @@ class ServerOptions extends AbstractStructure
|
||||
* @internal
|
||||
* @return bool
|
||||
*/
|
||||
function isValid()
|
||||
public function isValid(): bool
|
||||
{
|
||||
return is_string($this->name)
|
||||
&& is_string($this->comment)
|
||||
@ -41,15 +41,16 @@ class ServerOptions extends AbstractStructure
|
||||
* @internal
|
||||
* @return mixed[]
|
||||
*/
|
||||
function toSetterArray()
|
||||
public function toSetterArray()
|
||||
{
|
||||
$out = array();
|
||||
foreach(get_object_vars($this) as $key => $value)
|
||||
{
|
||||
if(substr($key, 0, 7) == 'current' || $value === null)
|
||||
$out = [];
|
||||
foreach (get_object_vars($this) as $key => $value) {
|
||||
if (str_starts_with($key, 'current') || $value === null) {
|
||||
continue;
|
||||
if($key == 'nextUseChangingValidationSeed')
|
||||
}
|
||||
if ($key === 'nextUseChangingValidationSeed') {
|
||||
$key = 'useChangingValidationSeed';
|
||||
}
|
||||
$out[ucfirst($key)] = $value;
|
||||
}
|
||||
return $out;
|
||||
|
28
libs/Maniaplanet/DedicatedServer/Structures/ServerPlugin.php
Executable file
28
libs/Maniaplanet/DedicatedServer/Structures/ServerPlugin.php
Executable file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* ManiaPlanet dedicated server Xml-RPC client
|
||||
*
|
||||
* @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
|
||||
*/
|
||||
|
||||
namespace Maniaplanet\DedicatedServer\Structures;
|
||||
|
||||
class ServerPlugin extends AbstractStructure
|
||||
{
|
||||
/** @var string */
|
||||
public $name;
|
||||
/** @var string[] */
|
||||
public $settingsValues;
|
||||
/** @var ScriptSettings[] */
|
||||
public $settingsDesc = array();
|
||||
|
||||
/**
|
||||
* @return ScriptInfo
|
||||
*/
|
||||
public static function fromArray($array)
|
||||
{
|
||||
$object = parent::fromArray($array);
|
||||
$object->settingsDesc = ScriptSettings::fromArrayOfArray($object->paramDescs);
|
||||
return $object;
|
||||
}
|
||||
}
|
@ -27,7 +27,7 @@ class Vote extends AbstractStructure
|
||||
* @param string $cmdName
|
||||
* @param mixed[] $cmdParam
|
||||
*/
|
||||
function __construct($cmdName='', $cmdParam=array())
|
||||
function __construct($cmdName = '', $cmdParam = [])
|
||||
{
|
||||
$this->cmdName = $cmdName;
|
||||
$this->cmdParam = $cmdParam;
|
||||
|
@ -7,4 +7,6 @@
|
||||
|
||||
namespace Maniaplanet\DedicatedServer\Xmlrpc;
|
||||
|
||||
class Exception extends \Exception {}
|
||||
class Exception extends \Exception
|
||||
{
|
||||
}
|
||||
|
@ -7,8 +7,10 @@
|
||||
|
||||
namespace Maniaplanet\DedicatedServer\Xmlrpc;
|
||||
|
||||
class FaultException extends Exception {
|
||||
static function create($faultString, $faultCode) {
|
||||
class FaultException extends Exception
|
||||
{
|
||||
static function create($faultString, $faultCode)
|
||||
{
|
||||
switch ($faultString) {
|
||||
case 'Password incorrect.':
|
||||
case 'Permission denied.':
|
||||
@ -31,6 +33,7 @@ class FaultException extends Exception {
|
||||
case 'Already waiting for a vote.':
|
||||
case 'You must stop server first.':
|
||||
return new LockedFeatureException($faultString, $faultCode);
|
||||
case 'Can\'t kick server.':
|
||||
case 'Login or Uid unknown.':
|
||||
case 'Login unknown.':
|
||||
case 'Payer login unknown.':
|
||||
@ -110,44 +113,58 @@ class FaultException extends Exception {
|
||||
}
|
||||
}
|
||||
|
||||
class AuthenticationException extends FaultException {
|
||||
class AuthenticationException extends FaultException
|
||||
{
|
||||
}
|
||||
|
||||
class UnavailableFeatureException extends FaultException {
|
||||
class UnavailableFeatureException extends FaultException
|
||||
{
|
||||
}
|
||||
|
||||
class LockedFeatureException extends FaultException {
|
||||
class LockedFeatureException extends FaultException
|
||||
{
|
||||
}
|
||||
|
||||
class UnknownPlayerException extends FaultException {
|
||||
class UnknownPlayerException extends FaultException
|
||||
{
|
||||
}
|
||||
|
||||
class PlayerStateException extends FaultException {
|
||||
class PlayerStateException extends FaultException
|
||||
{
|
||||
}
|
||||
|
||||
class AlreadyInListException extends FaultException {
|
||||
class AlreadyInListException extends FaultException
|
||||
{
|
||||
}
|
||||
|
||||
class NotInListException extends FaultException {
|
||||
class NotInListException extends FaultException
|
||||
{
|
||||
}
|
||||
|
||||
class IndexOutOfBoundException extends FaultException {
|
||||
class IndexOutOfBoundException extends FaultException
|
||||
{
|
||||
}
|
||||
|
||||
class NextMapException extends FaultException {
|
||||
class NextMapException extends FaultException
|
||||
{
|
||||
}
|
||||
|
||||
class ChangeInProgressException extends FaultException {
|
||||
class ChangeInProgressException extends FaultException
|
||||
{
|
||||
}
|
||||
|
||||
class InvalidMapException extends FaultException {
|
||||
class InvalidMapException extends FaultException
|
||||
{
|
||||
}
|
||||
|
||||
class GameModeException extends FaultException {
|
||||
class GameModeException extends FaultException
|
||||
{
|
||||
}
|
||||
|
||||
class ServerOptionsException extends FaultException {
|
||||
class ServerOptionsException extends FaultException
|
||||
{
|
||||
}
|
||||
|
||||
class FileException extends FaultException {
|
||||
class FileException extends FaultException
|
||||
{
|
||||
}
|
||||
|
@ -9,18 +9,18 @@ namespace Maniaplanet\DedicatedServer\Xmlrpc;
|
||||
|
||||
class GbxRemote
|
||||
{
|
||||
const MAX_REQUEST_SIZE = 0x200000; // 2MB
|
||||
const MAX_REQUEST_SIZE = 0x400000; // 4MB
|
||||
const MAX_RESPONSE_SIZE = 0x400000; // 4MB
|
||||
|
||||
public static $received;
|
||||
public static $sent;
|
||||
|
||||
private $socket;
|
||||
private $readTimeout = array('sec' => 30, 'usec' => 0);
|
||||
private $writeTimeout = array('sec' => 30, 'usec' => 0);
|
||||
private $readTimeout = ['sec' => 5, 'usec' => 0];
|
||||
private $writeTimeout = ['sec' => 5, 'usec' => 0];
|
||||
private $requestHandle;
|
||||
private $callbacksBuffer = array();
|
||||
private $multicallBuffer = array();
|
||||
private $callbacksBuffer = [];
|
||||
private $multicallBuffer = [];
|
||||
private $lastNetworkActivity = 0;
|
||||
|
||||
/**
|
||||
@ -34,25 +34,99 @@ class GbxRemote
|
||||
$this->connect($host, $port, $timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $host
|
||||
* @param int $port
|
||||
* @param int $timeout
|
||||
* @throws TransportException
|
||||
*/
|
||||
private function connect($host, $port, $timeout)
|
||||
{
|
||||
$this->socket = @fsockopen($host, $port, $errno, $errstr, $timeout);
|
||||
if (!$this->socket) {
|
||||
throw new TransportException('Cannot open socket', TransportException::NOT_INITIALIZED);
|
||||
}
|
||||
|
||||
stream_set_read_buffer($this->socket, 0);
|
||||
stream_set_write_buffer($this->socket, 0);
|
||||
|
||||
// handshake
|
||||
$header = $this->read(15);
|
||||
if ($header === false) {
|
||||
if (!is_resource($this->socket)) {
|
||||
$this->onIoFailure('socket closed during handshake');
|
||||
}
|
||||
$this->onIoFailure(sprintf('during handshake (%s)', socket_strerror(socket_last_error())));
|
||||
}
|
||||
|
||||
extract(unpack('Vsize/a*protocol', $header));
|
||||
/** @var $size int */
|
||||
/** @var $protocol string */
|
||||
if ($size != 11 || $protocol != 'GBXRemote 2') {
|
||||
throw new TransportException('Wrong protocol header', TransportException::WRONG_PROTOCOL);
|
||||
}
|
||||
$this->lastNetworkActivity = time();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $size
|
||||
* @return boolean|string
|
||||
*/
|
||||
private function read($size)
|
||||
{
|
||||
@stream_set_timeout($this->socket, $this->readTimeout['sec'], $this->readTimeout['usec']);
|
||||
|
||||
$data = '';
|
||||
while (strlen($data) < $size) {
|
||||
$buf = @fread($this->socket, $size - strlen($data));
|
||||
if ($buf === '' || $buf === false) {
|
||||
return false;
|
||||
}
|
||||
$data .= $buf;
|
||||
}
|
||||
|
||||
self::$received += $size;
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $when
|
||||
* @throws TransportException
|
||||
*/
|
||||
private function onIoFailure($when)
|
||||
{
|
||||
$meta = stream_get_meta_data($this->socket);
|
||||
if ($meta['timed_out']) {
|
||||
throw new TransportException('Connection timed out ' . $when, TransportException::TIMED_OUT);
|
||||
}
|
||||
throw new TransportException('Connection interrupted ' . $when, TransportException::INTERRUPTED);
|
||||
}
|
||||
|
||||
function __destruct()
|
||||
{
|
||||
$this->terminate();
|
||||
}
|
||||
|
||||
public function terminate()
|
||||
{
|
||||
if ($this->socket) {
|
||||
fclose($this->socket);
|
||||
$this->socket = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change timeouts
|
||||
* @param int $read read timeout (in ms), 0 to leave unchanged
|
||||
* @param int $write write timeout (in ms), 0 to leave unchanged
|
||||
*/
|
||||
function setTimeouts($read=0, $write=0)
|
||||
{
|
||||
if($read)
|
||||
public function setTimeouts($read = 0, $write = 0)
|
||||
{
|
||||
if ($read) {
|
||||
$this->readTimeout['sec'] = (int)($read / 1000);
|
||||
$this->readTimeout['usec'] = ($read % 1000) * 1000;
|
||||
}
|
||||
if($write)
|
||||
{
|
||||
if ($write) {
|
||||
$this->writeTimeout['sec'] = (int)($write / 1000);
|
||||
$this->writeTimeout['usec'] = ($write % 1000) * 1000;
|
||||
}
|
||||
@ -68,39 +142,49 @@ class GbxRemote
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $host
|
||||
* @param int $port
|
||||
* @param int $timeout
|
||||
* @throws TransportException
|
||||
*/
|
||||
private function connect($host, $port, $timeout)
|
||||
private function assertConnected()
|
||||
{
|
||||
$this->socket = @fsockopen($host, $port, $errno, $errstr, $timeout);
|
||||
if(!$this->socket)
|
||||
throw new TransportException('Cannot open socket', TransportException::NOT_INITIALIZED);
|
||||
|
||||
stream_set_read_buffer($this->socket, 0);
|
||||
stream_set_write_buffer($this->socket, 0);
|
||||
|
||||
// handshake
|
||||
$header = $this->read(15);
|
||||
if($header === false)
|
||||
$this->onIoFailure(sprintf('during handshake (%s)', socket_strerror(socket_last_error($this->socket))));
|
||||
|
||||
extract(unpack('Vsize/a*protocol', $header));
|
||||
/** @var $size int */
|
||||
/** @var $protocol string */
|
||||
if($size != 11 || $protocol != 'GBXRemote 2')
|
||||
throw new TransportException('Wrong protocol header', TransportException::WRONG_PROTOCOL);
|
||||
$this->lastNetworkActivity = time();
|
||||
if (!$this->socket) {
|
||||
throw new TransportException('Connection not initialized', TransportException::NOT_INITIALIZED);
|
||||
}
|
||||
}
|
||||
|
||||
function terminate()
|
||||
/**
|
||||
* @param string $method
|
||||
* @param mixed[] $args
|
||||
*/
|
||||
function addCall($method, $args)
|
||||
{
|
||||
if($this->socket)
|
||||
$this->multicallBuffer[] = [
|
||||
'methodName' => $method,
|
||||
'params' => $args
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
function multiquery()
|
||||
{
|
||||
fclose($this->socket);
|
||||
$this->socket = null;
|
||||
switch (count($this->multicallBuffer)) {
|
||||
case 0:
|
||||
return [];
|
||||
case 1:
|
||||
$call = array_shift($this->multicallBuffer);
|
||||
return [$this->query($call['methodName'], $call['params'])];
|
||||
default:
|
||||
$result = $this->query('system.multicall', [$this->multicallBuffer]);
|
||||
foreach ($result as &$value) {
|
||||
if (isset($value['faultCode'])) {
|
||||
$value = FaultException::create($value['faultString'], $value['faultCode']);
|
||||
} else {
|
||||
$value = $value[0];
|
||||
}
|
||||
}
|
||||
$this->multicallBuffer = [];
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,19 +194,19 @@ class GbxRemote
|
||||
* @return mixed
|
||||
* @throws MessageException
|
||||
*/
|
||||
function query($method, $args=array())
|
||||
function query($method, $args = [])
|
||||
{
|
||||
$this->assertConnected();
|
||||
$xml = Request::encode($method, $args);
|
||||
|
||||
if(strlen($xml) > self::MAX_REQUEST_SIZE-8)
|
||||
{
|
||||
if($method != 'system.multicall' || count($args[0]) < 2)
|
||||
if (strlen($xml) > self::MAX_REQUEST_SIZE - 8) {
|
||||
if ($method != 'system.multicall' || count($args[0]) < 2) {
|
||||
throw new MessageException('Request too large', MessageException::REQUEST_TOO_LARGE);
|
||||
}
|
||||
|
||||
$mid = count($args[0]) >> 1;
|
||||
$res1 = $this->query('system.multicall', array(array_slice($args[0], 0, $mid)));
|
||||
$res2 = $this->query('system.multicall', array(array_slice($args[0], $mid)));
|
||||
$res1 = $this->query('system.multicall', [array_slice($args[0], 0, $mid)]);
|
||||
$res2 = $this->query('system.multicall', [array_slice($args[0], $mid)]);
|
||||
return array_merge($res1, $res2);
|
||||
}
|
||||
|
||||
@ -131,60 +215,40 @@ class GbxRemote
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @param mixed[] $args
|
||||
*/
|
||||
function addCall($method, $args)
|
||||
{
|
||||
$this->multicallBuffer[] = array(
|
||||
'methodName' => $method,
|
||||
'params' => $args
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
function multiquery()
|
||||
{
|
||||
switch(count($this->multicallBuffer))
|
||||
{
|
||||
case 0:
|
||||
return array();
|
||||
case 1:
|
||||
$call = array_shift($this->multicallBuffer);
|
||||
return array($this->query($call['methodName'], $call['params']));
|
||||
default:
|
||||
$result = $this->query('system.multicall', array($this->multicallBuffer));
|
||||
foreach($result as &$value)
|
||||
if(isset($value['faultCode']))
|
||||
$value = FaultException::create($value['faultString'], $value['faultCode']);
|
||||
else
|
||||
$value = $value[0];
|
||||
$this->multicallBuffer = array();
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed[]
|
||||
*/
|
||||
function getCallbacks()
|
||||
{
|
||||
$this->assertConnected();
|
||||
$this->flush();
|
||||
$cb = $this->callbacksBuffer;
|
||||
$this->callbacksBuffer = array();
|
||||
return $cb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $xml
|
||||
* @throws TransportException
|
||||
*/
|
||||
private function assertConnected()
|
||||
private function writeMessage($xml)
|
||||
{
|
||||
if(!$this->socket)
|
||||
throw new TransportException('Connection not initialized', TransportException::NOT_INITIALIZED);
|
||||
if ($this->requestHandle == (int)0xffffffff) {
|
||||
$this->requestHandle = (int)0x80000000;
|
||||
}
|
||||
$data = pack('V2', strlen($xml), ++$this->requestHandle) . $xml;
|
||||
if (!$this->write($data)) {
|
||||
$this->onIoFailure('while writing');
|
||||
}
|
||||
$this->lastNetworkActivity = time();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $data
|
||||
* @return boolean
|
||||
*/
|
||||
private function write($data)
|
||||
{
|
||||
@stream_set_timeout($this->socket, $this->writeTimeout['sec'], $this->writeTimeout['usec']);
|
||||
self::$sent += strlen($data);
|
||||
|
||||
while (strlen($data) > 0) {
|
||||
$written = @fwrite($this->socket, $data);
|
||||
if ($written === 0 || $written === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = substr($data, $written);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -194,18 +258,17 @@ class GbxRemote
|
||||
*/
|
||||
private function flush($waitResponse = false)
|
||||
{
|
||||
$r = array($this->socket);
|
||||
while($waitResponse || @stream_select($r, $w, $e, 0) > 0)
|
||||
{
|
||||
$r = [$this->socket];
|
||||
while ($waitResponse || @stream_select($r, $w, $e, 0) > 0) {
|
||||
list($handle, $xml) = $this->readMessage();
|
||||
list($type, $value) = Request::decode($xml);
|
||||
switch($type)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'fault':
|
||||
throw FaultException::create($value['faultString'], $value['faultCode']);
|
||||
case 'response':
|
||||
if($handle == $this->requestHandle)
|
||||
if ($handle == $this->requestHandle) {
|
||||
return $value;
|
||||
}
|
||||
break;
|
||||
case 'call':
|
||||
$this->callbacksBuffer[] = $value;
|
||||
@ -221,92 +284,40 @@ class GbxRemote
|
||||
private function readMessage()
|
||||
{
|
||||
$header = $this->read(8);
|
||||
if($header === false)
|
||||
if ($header === false) {
|
||||
$this->onIoFailure('while reading header');
|
||||
}
|
||||
|
||||
extract(unpack('Vsize/Vhandle', $header));
|
||||
/** @var $size int */
|
||||
/** @var $handle int */
|
||||
if($size == 0 || $handle == 0)
|
||||
if ($size == 0 || $handle == 0) {
|
||||
throw new TransportException('Incorrect header', TransportException::PROTOCOL_ERROR);
|
||||
}
|
||||
|
||||
if($size > self::MAX_RESPONSE_SIZE)
|
||||
if ($size > self::MAX_RESPONSE_SIZE) {
|
||||
throw new MessageException('Response too large', MessageException::RESPONSE_TOO_LARGE);
|
||||
}
|
||||
|
||||
$data = $this->read($size);
|
||||
if($data === false)
|
||||
if ($data === false) {
|
||||
$this->onIoFailure('while reading data');
|
||||
}
|
||||
|
||||
$this->lastNetworkActivity = time();
|
||||
return array($handle, $data);
|
||||
return [$handle, $data];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $xml
|
||||
* @throws TransportException
|
||||
* @return mixed[]
|
||||
*/
|
||||
private function writeMessage($xml)
|
||||
function getCallbacks()
|
||||
{
|
||||
if($this->requestHandle == (int) 0xffffffff)
|
||||
$this->requestHandle = (int) 0x80000000;
|
||||
$data = pack('V2', strlen($xml), ++$this->requestHandle).$xml;
|
||||
if(!$this->write($data))
|
||||
$this->onIoFailure('while writing');
|
||||
$this->lastNetworkActivity = time();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $size
|
||||
* @return boolean|string
|
||||
*/
|
||||
private function read($size)
|
||||
{
|
||||
@stream_set_timeout($this->socket, $this->readTimeout['sec'], $this->readTimeout['usec']);
|
||||
|
||||
$data = '';
|
||||
while(strlen($data) < $size)
|
||||
{
|
||||
$buf = @fread($this->socket, $size - strlen($data));
|
||||
if($buf === '' || $buf === false)
|
||||
return false;
|
||||
$data .= $buf;
|
||||
}
|
||||
|
||||
self::$received += $size;
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $data
|
||||
* @return boolean
|
||||
*/
|
||||
private function write($data)
|
||||
{
|
||||
@stream_set_timeout($this->socket, $this->writeTimeout['sec'], $this->writeTimeout['usec']);
|
||||
self::$sent += strlen($data);
|
||||
|
||||
while(strlen($data) > 0)
|
||||
{
|
||||
$written = @fwrite($this->socket, $data);
|
||||
if($written === 0 || $written === false)
|
||||
return false;
|
||||
|
||||
$data = substr($data, $written);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $when
|
||||
* @throws TransportException
|
||||
*/
|
||||
private function onIoFailure($when)
|
||||
{
|
||||
$meta = stream_get_meta_data($this->socket);
|
||||
if($meta['timed_out'])
|
||||
throw new TransportException('Connection timed out '.$when, TransportException::TIMED_OUT);
|
||||
throw new TransportException('Connection interrupted '.$when, TransportException::INTERRUPTED);
|
||||
$this->assertConnected();
|
||||
$this->flush();
|
||||
$cb = $this->callbacksBuffer;
|
||||
$this->callbacksBuffer = [];
|
||||
return $cb;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,15 +7,14 @@
|
||||
|
||||
namespace Maniaplanet\DedicatedServer\Xmlrpc;
|
||||
|
||||
if(extension_loaded('xmlrpc'))
|
||||
{
|
||||
if (extension_loaded('xmlrpc')) {
|
||||
abstract class Request
|
||||
{
|
||||
private static $options = array(
|
||||
private static $options = [
|
||||
'encoding' => 'utf-8',
|
||||
'escaping' => 'markup',
|
||||
'verbosity' => 'no_white_space'
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
@ -25,8 +24,9 @@ if(extension_loaded('xmlrpc'))
|
||||
static function encode($method, $args, $escape = true)
|
||||
{
|
||||
$opts = self::$options;
|
||||
if(!$escape)
|
||||
$opts['escaping'] = array();
|
||||
if (!$escape) {
|
||||
$opts['escaping'] = [];
|
||||
}
|
||||
return xmlrpc_encode_request($method, $args, $opts);
|
||||
}
|
||||
|
||||
@ -38,21 +38,20 @@ if(extension_loaded('xmlrpc'))
|
||||
static function decode($message)
|
||||
{
|
||||
$value = xmlrpc_decode_request($message, $method, 'utf-8');
|
||||
if($value === null)
|
||||
if ($value === null) {
|
||||
throw new ParseException();
|
||||
}
|
||||
|
||||
if($method === null)
|
||||
{
|
||||
if(is_array($value) && xmlrpc_is_fault($value))
|
||||
return array('fault', $value);
|
||||
return array('response', $value);
|
||||
if ($method === null) {
|
||||
if (is_array($value) && xmlrpc_is_fault($value)) {
|
||||
return ['fault', $value];
|
||||
}
|
||||
return array('call', array($method, $value));
|
||||
return ['response', $value];
|
||||
}
|
||||
return ['call', [$method, $value]];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
abstract class Request
|
||||
{
|
||||
const DATE_FORMAT = 'Ymd\TH:i:s';
|
||||
@ -65,12 +64,14 @@ else
|
||||
static function encode($method, $args, $escape = true)
|
||||
{
|
||||
$xml = '<?xml version="1.0" encoding="utf-8"?><methodCall><methodName>' . self::escape($method, $escape) . '</methodName>';
|
||||
if(!$args)
|
||||
if (!$args) {
|
||||
return $xml . '<params/></methodCall>';
|
||||
}
|
||||
|
||||
$xml .= '<params>';
|
||||
foreach($args as $arg)
|
||||
foreach ($args as $arg) {
|
||||
$xml .= '<param><value>' . self::encodeValue($arg, $escape) . '</value></param>';
|
||||
}
|
||||
return $xml . '</params></methodCall>';
|
||||
}
|
||||
|
||||
@ -80,8 +81,7 @@ else
|
||||
*/
|
||||
private static function encodeValue($v, $escape = true)
|
||||
{
|
||||
switch(gettype($v))
|
||||
{
|
||||
switch (gettype($v)) {
|
||||
case 'boolean':
|
||||
return '<boolean>' . ((int)$v) . '</boolean>';
|
||||
case 'integer':
|
||||
@ -89,36 +89,41 @@ else
|
||||
case 'double':
|
||||
return '<double>' . $v . '</double>';
|
||||
case 'string':
|
||||
case 'NULL':
|
||||
if(!$v)
|
||||
if (strlen($v) === 0) {
|
||||
return '<string/>';
|
||||
}
|
||||
return '<string>' . self::escape($v, $escape) . '</string>';
|
||||
case 'NULL':
|
||||
return '<string/>';
|
||||
case 'object':
|
||||
if($v instanceof Base64)
|
||||
{
|
||||
if(!$v->scalar)
|
||||
if ($v instanceof Base64) {
|
||||
if (!$v->scalar) {
|
||||
return '<base64/>';
|
||||
}
|
||||
return '<base64>' . base64_encode($v->scalar) . '</base64>';
|
||||
}
|
||||
if($v instanceof \DateTime)
|
||||
if ($v instanceof \DateTime) {
|
||||
return '<dateTime.iso8601>' . $v->format(self::DATE_FORMAT) . '</dateTime.iso8601>';
|
||||
}
|
||||
$v = get_object_vars($v);
|
||||
// fallthrough
|
||||
case 'array':
|
||||
// empty array case
|
||||
if(!$v)
|
||||
if (!$v) {
|
||||
return '<array><data/></array>';
|
||||
}
|
||||
$return = '';
|
||||
// pure array case
|
||||
if(array_keys($v) === range(0, count($v) - 1))
|
||||
{
|
||||
foreach($v as $item)
|
||||
if (array_keys($v) === range(0, count($v) - 1)) {
|
||||
foreach ($v as $item) {
|
||||
$return .= '<value>' . self::encodeValue($item, $escape) . '</value>';
|
||||
}
|
||||
return '<array><data>' . $return . '</data></array>';
|
||||
}
|
||||
// else it's a struct
|
||||
foreach($v as $name => $value)
|
||||
foreach ($v as $name => $value) {
|
||||
$return .= '<member><name>' . self::escape($name, $escape) . '</name><value>' . self::encodeValue($value, $escape) . '</value></member>';
|
||||
}
|
||||
return '<struct>' . $return . '</struct>';
|
||||
}
|
||||
return '';
|
||||
@ -131,8 +136,9 @@ else
|
||||
*/
|
||||
private static function escape($str, $escape = true)
|
||||
{
|
||||
if($escape)
|
||||
if ($escape) {
|
||||
return '<![CDATA[' . str_replace(']]>', ']]]]><![CDATA[>', $str) . ']]>';
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
@ -144,19 +150,21 @@ else
|
||||
static function decode($message)
|
||||
{
|
||||
$xml = @simplexml_load_string($message);
|
||||
if(!$xml)
|
||||
if (!$xml) {
|
||||
throw new ParseException();
|
||||
|
||||
if($xml->getName() == 'methodResponse')
|
||||
{
|
||||
if($xml->fault)
|
||||
return array('fault', self::decodeValue($xml->fault->value));
|
||||
return array('response', self::decodeValue($xml->params->param->value));
|
||||
}
|
||||
$params = array();
|
||||
foreach($xml->params->param as $param)
|
||||
|
||||
if ($xml->getName() == 'methodResponse') {
|
||||
if ($xml->fault) {
|
||||
return ['fault', self::decodeValue($xml->fault->value)];
|
||||
}
|
||||
return ['response', self::decodeValue($xml->params->param->value)];
|
||||
}
|
||||
$params = [];
|
||||
foreach ($xml->params->param as $param) {
|
||||
$params[] = self::decodeValue($param->value);
|
||||
return array('call', array((string) $xml->methodName, $params));
|
||||
}
|
||||
return ['call', [(string)$xml->methodName, $params]];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -167,8 +175,7 @@ else
|
||||
{
|
||||
$elt = $elt->children();
|
||||
$elt = $elt[0];
|
||||
switch($elt->getName())
|
||||
{
|
||||
switch ($elt->getName()) {
|
||||
case 'boolean':
|
||||
return (bool)(int)$elt;
|
||||
case 'i4':
|
||||
@ -183,18 +190,22 @@ else
|
||||
case 'dateTime.iso8601':
|
||||
return \DateTime::createFromFormat(self::DATE_FORMAT, (string)$elt);
|
||||
case 'array':
|
||||
$arr = array();
|
||||
foreach($elt->data->value as $v)
|
||||
$arr = [];
|
||||
foreach ($elt->data->value as $v) {
|
||||
$arr[] = self::decodeValue($v);
|
||||
}
|
||||
return $arr;
|
||||
case 'struct':
|
||||
$struct = array();
|
||||
foreach($elt as $member)
|
||||
$struct = [];
|
||||
foreach ($elt as $member) {
|
||||
$struct[(string)$member->name] = self::decodeValue($member->value);
|
||||
}
|
||||
return $struct;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ParseException extends Exception {}
|
||||
class ParseException extends Exception
|
||||
{
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class ExtEventLoop implements LoopInterface
|
||||
private $writeListeners = [];
|
||||
private $running;
|
||||
|
||||
public function __construct(EventBaseConfig $config = null)
|
||||
public function __construct(?EventBaseConfig $config = null)
|
||||
{
|
||||
$this->eventBase = new EventBase($config);
|
||||
$this->nextTickQueue = new NextTickQueue($this);
|
||||
|
@ -160,7 +160,7 @@ class ContainerAwareEventDispatcher extends EventDispatcher
|
||||
*
|
||||
* @throws \InvalidArgumentException if the service is not defined
|
||||
*/
|
||||
public function dispatch($eventName, Event $event = null)
|
||||
public function dispatch($eventName, ?Event $event = null)
|
||||
{
|
||||
$this->lazyLoad($eventName);
|
||||
|
||||
|
@ -40,7 +40,7 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
* @param Stopwatch $stopwatch A Stopwatch instance
|
||||
* @param LoggerInterface $logger A LoggerInterface instance
|
||||
*/
|
||||
public function __construct(EventDispatcherInterface $dispatcher, Stopwatch $stopwatch, LoggerInterface $logger = null)
|
||||
public function __construct(EventDispatcherInterface $dispatcher, Stopwatch $stopwatch, ?LoggerInterface $logger = null)
|
||||
{
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->stopwatch = $stopwatch;
|
||||
@ -110,7 +110,7 @@ class TraceableEventDispatcher implements TraceableEventDispatcherInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function dispatch($eventName, Event $event = null)
|
||||
public function dispatch($eventName, ?Event $event = null)
|
||||
{
|
||||
if (null === $event) {
|
||||
$event = new Event();
|
||||
|
@ -27,7 +27,7 @@ class WrappedListener
|
||||
private $stopwatch;
|
||||
private $dispatcher;
|
||||
|
||||
public function __construct($listener, $name, Stopwatch $stopwatch, EventDispatcherInterface $dispatcher = null)
|
||||
public function __construct($listener, $name, Stopwatch $stopwatch, ?EventDispatcherInterface $dispatcher = null)
|
||||
{
|
||||
$this->listener = $listener;
|
||||
$this->name = $name;
|
||||
|
@ -37,7 +37,7 @@ class EventDispatcher implements EventDispatcherInterface
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function dispatch($eventName, Event $event = null)
|
||||
public function dispatch($eventName, ?Event $event = null)
|
||||
{
|
||||
if (null === $event) {
|
||||
$event = new Event();
|
||||
|
@ -35,7 +35,7 @@ interface EventDispatcherInterface
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function dispatch($eventName, Event $event = null);
|
||||
public function dispatch($eventName, ?Event $event = null);
|
||||
|
||||
/**
|
||||
* Adds an event listener that listens on the specified events.
|
||||
|
@ -38,7 +38,7 @@ class ImmutableEventDispatcher implements EventDispatcherInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function dispatch($eventName, Event $event = null)
|
||||
public function dispatch($eventName, ?Event $event = null)
|
||||
{
|
||||
return $this->dispatcher->dispatch($eventName, $event);
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ class RecordWidget {
|
||||
* @param \ManiaControl\Players\Player|null $player
|
||||
* @return \FML\Controls\Frame
|
||||
*/
|
||||
public function generateRecordLineFrame($record, Player $player = null) {
|
||||
public function generateRecordLineFrame($record, ?Player $player = null) {
|
||||
$width = $this->width;
|
||||
$lineHeight = $this->lineHeight;
|
||||
$largeNumberDiff = 0;
|
||||
@ -92,6 +92,7 @@ class RecordWidget {
|
||||
$recordFrame->addChild($quad);
|
||||
$quad->setStyles(Quad_Bgs1InRace::STYLE, Quad_Bgs1InRace::SUBSTYLE_BgCardList);
|
||||
$quad->setSize($width, $lineHeight);
|
||||
$quad->setZ(-1);
|
||||
}
|
||||
|
||||
return $recordFrame;
|
||||
@ -105,7 +106,7 @@ class RecordWidget {
|
||||
* @param \ManiaControl\Players\Player|null $player
|
||||
* @return \FML\Controls\Frame
|
||||
*/
|
||||
public function generateRecordsFrame($records, $limit, Player $player = null) {
|
||||
public function generateRecordsFrame($records, $limit, ?Player $player = null) {
|
||||
$lineHeight = $this->lineHeight;
|
||||
|
||||
$frame = new Frame();
|
||||
|
@ -83,7 +83,7 @@ class DedimaniaPlugin implements CallbackListener, CallQueueListener, CommandLis
|
||||
public static function prepare(ManiaControl $maniaControl) {
|
||||
$servers = $maniaControl->getServer()->getAllServers();
|
||||
foreach ($servers as $server) {
|
||||
$maniaControl->getSettingManager()->initSetting(get_class(), self::SETTING_DEDIMANIA_CODE . $server->login . '$l', '');
|
||||
$maniaControl->getSettingManager()->initSetting(get_called_class(), self::SETTING_DEDIMANIA_CODE . $server->login . '$l', '');
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,7 +156,7 @@ class DedimaniaPlugin implements CallbackListener, CallQueueListener, CommandLis
|
||||
|
||||
$this->recordWidget = new RecordWidget($this->maniaControl);
|
||||
|
||||
if ($this->maniaControl->getServer()->getGameMode() == 0) {
|
||||
if (true/*$this->maniaControl->getServer()->getGameMode() == 0*/) {
|
||||
$gameMode = $this->maniaControl->getClient()->getScriptName()['CurrentValue'];
|
||||
$this->isMultilap = ($gameMode == 'Laps.Script.txt' || $this->maniaControl->getMapManager()->getCurrentMap()->nbLaps > 0);
|
||||
$this->isRounds = ($gameMode == 'Rounds.Script.txt');
|
||||
|
@ -52,11 +52,11 @@ class DynamicPointLimitPlugin implements CallbackListener, CommandListener, Plug
|
||||
* @see \ManiaControl\Plugins\Plugin::prepare()
|
||||
*/
|
||||
public static function prepare(ManiaControl $maniaControl) {
|
||||
$maniaControl->getSettingManager()->initSetting(get_class(), self::SETTING_POINT_LIMIT_MULTIPLIER, 10);
|
||||
$maniaControl->getSettingManager()->initSetting(get_class(), self::SETTING_POINT_LIMIT_OFFSET, 0);
|
||||
$maniaControl->getSettingManager()->initSetting(get_class(), self::SETTING_MIN_POINT_LIMIT, 30);
|
||||
$maniaControl->getSettingManager()->initSetting(get_class(), self::SETTING_MAX_POINT_LIMIT, 200);
|
||||
$maniaControl->getSettingManager()->initSetting(get_class(), self::SETTING_ACCEPT_OTHER_MODES, false);
|
||||
$maniaControl->getSettingManager()->initSetting(get_called_class(), self::SETTING_POINT_LIMIT_MULTIPLIER, 10);
|
||||
$maniaControl->getSettingManager()->initSetting(get_called_class(), self::SETTING_POINT_LIMIT_OFFSET, 0);
|
||||
$maniaControl->getSettingManager()->initSetting(get_called_class(), self::SETTING_MIN_POINT_LIMIT, 30);
|
||||
$maniaControl->getSettingManager()->initSetting(get_called_class(), self::SETTING_MAX_POINT_LIMIT, 200);
|
||||
$maniaControl->getSettingManager()->initSetting(get_called_class(), self::SETTING_ACCEPT_OTHER_MODES, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,7 +79,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
* @see \ManiaControl\Plugins\Plugin::prepare()
|
||||
*/
|
||||
public static function prepare(ManiaControl $maniaControl) {
|
||||
$thisClass = get_class();
|
||||
$thisClass = get_called_class();
|
||||
$maniaControl->getSettingManager()->initSetting($thisClass, self::SETTING_MX_KARMA_ACTIVATED, true);
|
||||
$maniaControl->getSettingManager()->initSetting($thisClass, self::SETTING_MX_KARMA_IMPORTING, true);
|
||||
$maniaControl->getSettingManager()->initSetting($thisClass, self::SETTING_WIDGET_DISPLAY_MX, true);
|
||||
@ -343,7 +343,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
/**
|
||||
* Fetch the mxKarmaVotes for the current map
|
||||
*/
|
||||
public function getMxKarmaVotes(Player $player = null) {
|
||||
public function getMxKarmaVotes(?Player $player = null) {
|
||||
if (!$this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MX_KARMA_ACTIVATED)) {
|
||||
return;
|
||||
}
|
||||
@ -901,7 +901,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
* @param Map $map
|
||||
* @param bool $forceBuild
|
||||
*/
|
||||
private function buildManialink(Map $map = null, $forceBuild = false) {
|
||||
private function buildManialink(?Map $map = null, $forceBuild = false) {
|
||||
if (!$forceBuild) {
|
||||
return;
|
||||
}
|
||||
@ -915,7 +915,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
|
||||
$quadStyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadStyle();
|
||||
$quadSubstyle = $this->maniaControl->getManialinkManager()->getStyleManager()->getDefaultQuadSubstyle();
|
||||
|
||||
$manialink = new ManiaLink(self::MLID_KARMA);
|
||||
$manialink = new ManiaLink(self::MLID_KARMA, 3);
|
||||
|
||||
$frame = new Frame();
|
||||
$manialink->addChild($frame);
|
||||
|
Reference in New Issue
Block a user