cherry pick maniaplanet lib 6.1
This commit is contained in:
@ -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)
|
||||
{
|
||||
return array_map(get_called_class().'::extractProperty', $array, array_fill(0, count($array), $property));
|
||||
if (!is_array($array)) {
|
||||
return $array;
|
||||
}
|
||||
|
||||
$object = new static;
|
||||
foreach ($array as $key => $value) {
|
||||
$object->{lcfirst($key)} = $value;
|
||||
}
|
||||
return $object;
|
||||
}
|
||||
|
||||
static protected function extractProperty($element, $property)
|
||||
public static function getPropertyFromArray($array, $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 array_map(get_called_class() . '::extractProperty', $array, array_fill(0, count($array), $property));
|
||||
}
|
||||
|
||||
protected static function extractProperty($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;
|
||||
}
|
||||
}
|
||||
|
@ -10,11 +10,11 @@ namespace Maniaplanet\DedicatedServer\Structures;
|
||||
class Bill extends AbstractStructure
|
||||
{
|
||||
const STATE_CREATING_TRANSACTION = 1;
|
||||
const STATE_ISSUED = 2;
|
||||
const STATE_VALIDATING_PAYMENT = 3;
|
||||
const STATE_PAYED = 4;
|
||||
const STATE_REFUSED = 5;
|
||||
const STATE_ERROR = 6;
|
||||
const STATE_ISSUED = 2;
|
||||
const STATE_VALIDATING_PAYMENT = 3;
|
||||
const STATE_PAYED = 4;
|
||||
const STATE_REFUSED = 5;
|
||||
const STATE_ERROR = 6;
|
||||
|
||||
/** @var int */
|
||||
public $state;
|
||||
|
@ -12,13 +12,13 @@ class GameInfos extends AbstractStructure
|
||||
/**
|
||||
* Game Modes
|
||||
*/
|
||||
const GAMEMODE_SCRIPT = 0;
|
||||
const GAMEMODE_ROUNDS = 1;
|
||||
const GAMEMODE_SCRIPT = 0;
|
||||
const GAMEMODE_ROUNDS = 1;
|
||||
const GAMEMODE_TIMEATTACK = 2;
|
||||
const GAMEMODE_TEAM = 3;
|
||||
const GAMEMODE_LAPS = 4;
|
||||
const GAMEMODE_CUP = 5;
|
||||
const GAMEMODE_STUNTS = 6;
|
||||
const GAMEMODE_TEAM = 3;
|
||||
const GAMEMODE_LAPS = 4;
|
||||
const GAMEMODE_CUP = 5;
|
||||
const GAMEMODE_STUNTS = 6;
|
||||
|
||||
/** @var int */
|
||||
public $gameMode;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
32
libs/Maniaplanet/DedicatedServer/Structures/PlayerInfo.php
Executable file → Normal file
32
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,26 +63,26 @@ class PlayerInfo extends Player
|
||||
/**
|
||||
* @return PlayerInfo
|
||||
*/
|
||||
static public function fromArray($array)
|
||||
public static function fromArray($array)
|
||||
{
|
||||
$object = parent::fromArray($array);
|
||||
|
||||
//Detail flags
|
||||
$object->forceSpectator = $object->flags % 10; // 0, 1 or 2
|
||||
$object->isReferee = (bool) (intval($object->flags / 10) % 10);
|
||||
$object->isPodiumReady = (bool) (intval($object->flags / 100) % 10);
|
||||
$object->isUsingStereoscopy = (bool) (intval($object->flags / 1000) % 10);
|
||||
$object->isManagedByAnOtherServer = (bool) (intval($object->flags / 10000) % 10);
|
||||
$object->isServer = (bool) (intval($object->flags / 100000) % 10);
|
||||
$object->hasPlayerSlot = (bool) (intval($object->flags / 1000000) % 10);
|
||||
$object->isBroadcasting = (bool) (intval($object->flags / 10000000) % 10);
|
||||
$object->hasJoinedGame = (bool) (intval($object->flags / 100000000) % 10);
|
||||
$object->forceSpectator = $object->flags % 10; // 0, 1 or 2
|
||||
$object->isReferee = (bool)(intval($object->flags / 10) % 10);
|
||||
$object->isPodiumReady = (bool)(intval($object->flags / 100) % 10);
|
||||
$object->isUsingStereoscopy = (bool)(intval($object->flags / 1000) % 10);
|
||||
$object->isManagedByAnOtherServer = (bool)(intval($object->flags / 10000) % 10);
|
||||
$object->isServer = (bool)(intval($object->flags / 100000) % 10);
|
||||
$object->hasPlayerSlot = (bool)(intval($object->flags / 1000000) % 10);
|
||||
$object->isBroadcasting = (bool)(intval($object->flags / 10000000) % 10);
|
||||
$object->hasJoinedGame = (bool)(intval($object->flags / 100000000) % 10);
|
||||
//Details spectatorStatus
|
||||
$object->spectator = (bool) ($object->spectatorStatus % 10);
|
||||
$object->temporarySpectator = (bool) (intval($object->spectatorStatus / 10) % 10);
|
||||
$object->pureSpectator = (bool) (intval($object->spectatorStatus / 100) % 10);
|
||||
$object->autoTarget = (bool) (intval($object->spectatorStatus / 1000) % 10);
|
||||
$object->currentTargetId = intval($object->spectatorStatus / 10000);
|
||||
$object->spectator = (bool)($object->spectatorStatus % 10);
|
||||
$object->temporarySpectator = (bool)(intval($object->spectatorStatus / 10) % 10);
|
||||
$object->pureSpectator = (bool)(intval($object->spectatorStatus / 100) % 10);
|
||||
$object->autoTarget = (bool)(intval($object->spectatorStatus / 1000) % 10);
|
||||
$object->currentTargetId = intval($object->spectatorStatus / 10000);
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -9,13 +9,13 @@ namespace Maniaplanet\DedicatedServer\Structures;
|
||||
|
||||
class Status extends AbstractStructure
|
||||
{
|
||||
const UNKNOWN = 0;
|
||||
const WAITING = 1;
|
||||
const LAUNCHING = 2;
|
||||
const UNKNOWN = 0;
|
||||
const WAITING = 1;
|
||||
const LAUNCHING = 2;
|
||||
const SYNCHRONIZATION = 3;
|
||||
const PLAY = 4;
|
||||
const EXITING = 6;
|
||||
const LOCAL = 7;
|
||||
const PLAY = 4;
|
||||
const EXITING = 6;
|
||||
const LOCAL = 7;
|
||||
|
||||
/** @var int */
|
||||
public $code;
|
||||
|
@ -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;
|
||||
|
@ -9,15 +9,15 @@ namespace Maniaplanet\DedicatedServer\Structures;
|
||||
|
||||
class VoteRatio extends AbstractStructure
|
||||
{
|
||||
const COMMAND_DEFAULT = '*';
|
||||
const COMMAND_DEFAULT = '*';
|
||||
const COMMAND_SCRIPT_SETTINGS = 'SetModeScriptSettingsAndCommands';
|
||||
const COMMAND_NEXT_MAP = 'NextMap';
|
||||
const COMMAND_JUMP_MAP = 'JumpToMapIdent';
|
||||
const COMMAND_SET_NEXT_MAP = 'SetNextMapIdent';
|
||||
const COMMAND_RESTART_MAP = 'RestartMap';
|
||||
const COMMAND_TEAM_BALANCE = 'AutoTeamBalance';
|
||||
const COMMAND_KICK = 'Kick';
|
||||
const COMMAND_BAN = 'Ban';
|
||||
const COMMAND_NEXT_MAP = 'NextMap';
|
||||
const COMMAND_JUMP_MAP = 'JumpToMapIdent';
|
||||
const COMMAND_SET_NEXT_MAP = 'SetNextMapIdent';
|
||||
const COMMAND_RESTART_MAP = 'RestartMap';
|
||||
const COMMAND_TEAM_BALANCE = 'AutoTeamBalance';
|
||||
const COMMAND_KICK = 'Kick';
|
||||
const COMMAND_BAN = 'Ban';
|
||||
|
||||
/** @var string '*' for default */
|
||||
public $command;
|
||||
|
Reference in New Issue
Block a user