dedimania coding improvements
This commit is contained in:
parent
e8c649664a
commit
ddc3f98715
@ -7,7 +7,7 @@ use ManiaControl\Players\Player;
|
|||||||
use Maniaplanet\DedicatedServer\Structures\Version;
|
use Maniaplanet\DedicatedServer\Structures\Version;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ManiaControl Dedimania Plugin DataStructure
|
* ManiaControl Dedimania Plugin Data Structure
|
||||||
*
|
*
|
||||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
@ -105,7 +105,6 @@ class DedimaniaData {
|
|||||||
* @param DedimaniaPlayer $player
|
* @param DedimaniaPlayer $player
|
||||||
*/
|
*/
|
||||||
public function addPlayer(DedimaniaPlayer $player) {
|
public function addPlayer(DedimaniaPlayer $player) {
|
||||||
/** @var DedimaniaPlayer $player */
|
|
||||||
$this->players[$player->login] = $player;
|
$this->players[$player->login] = $player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
namespace MCTeam\Dedimania;
|
namespace MCTeam\Dedimania;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ManiaControl Dedimania-Plugin Player DataStructure
|
* ManiaControl Dedimania Plugin Player Data Structure
|
||||||
*
|
*
|
||||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
@ -21,28 +21,16 @@ class DedimaniaPlayer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new Dedimania Player Model
|
* Construct a new Dedimania Player Model
|
||||||
* @param mixed$player
|
*
|
||||||
|
* @param mixed $player
|
||||||
*/
|
*/
|
||||||
public function __construct($player) {
|
public function __construct($player) {
|
||||||
if (!$player) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->login = $player['Login'];
|
$this->login = $player['Login'];
|
||||||
$this->maxRank = $player['MaxRank'];
|
$this->maxRank = $player['MaxRank'];
|
||||||
|
if (isset($player['Banned'])) {
|
||||||
$this->banned = $player['Banned'];
|
$this->banned = $player['Banned'];
|
||||||
$this->optionsEnabled = $player['OptionsEnabled'];
|
$this->optionsEnabled = $player['OptionsEnabled'];
|
||||||
$this->options = $player['Options'];
|
$this->options = $player['Options'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct a new Player by its login and maxRank
|
|
||||||
*
|
|
||||||
* @param string $login
|
|
||||||
* @param int $maxRank
|
|
||||||
*/
|
|
||||||
public function constructNewPlayer($login, $maxRank) {
|
|
||||||
$this->login = $login;
|
|
||||||
$this->maxRank = $maxRank;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -112,7 +112,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
|||||||
* @see \ManiaControl\Plugins\Plugin::getDescription()
|
* @see \ManiaControl\Plugins\Plugin::getDescription()
|
||||||
*/
|
*/
|
||||||
public static function getDescription() {
|
public static function getDescription() {
|
||||||
return "Dedimania Plugin for Trackmania";
|
return "Dedimania Plugin for TrackMania";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -143,6 +143,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
|||||||
$this->maniaControl->timerManager->registerTimerListening($this, 'updateEverySecond', 1000);
|
$this->maniaControl->timerManager->registerTimerListening($this, 'updateEverySecond', 1000);
|
||||||
$this->maniaControl->timerManager->registerTimerListening($this, 'handleEveryMinute', 1000 * 60);
|
$this->maniaControl->timerManager->registerTimerListening($this, 'handleEveryMinute', 1000 * 60);
|
||||||
$this->maniaControl->timerManager->registerTimerListening($this, 'updatePlayerList', 1000 * 60 * 3);
|
$this->maniaControl->timerManager->registerTimerListening($this, 'updatePlayerList', 1000 * 60 * 3);
|
||||||
|
|
||||||
$this->maniaControl->commandManager->registerCommandListener(array('dedirecs', 'dedirecords'), $this, 'showDediRecordsList', false, 'Shows a list of Dedimania records of the current map.');
|
$this->maniaControl->commandManager->registerCommandListener(array('dedirecs', 'dedirecords'), $this, 'showDediRecordsList', false, 'Shows a list of Dedimania records of the current map.');
|
||||||
|
|
||||||
// Open session
|
// Open session
|
||||||
@ -154,7 +155,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
|||||||
}
|
}
|
||||||
|
|
||||||
$dedimaniaCode = $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_DEDIMANIA_CODE . $serverInfo->login . '$l');
|
$dedimaniaCode = $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_DEDIMANIA_CODE . $serverInfo->login . '$l');
|
||||||
if ($dedimaniaCode == '') {
|
if (!$dedimaniaCode) {
|
||||||
throw new \Exception("No Dedimania Code Specified, check the settings!");
|
throw new \Exception("No Dedimania Code Specified, check the settings!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,28 +170,27 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
|||||||
private function openDedimaniaSession() {
|
private function openDedimaniaSession() {
|
||||||
$content = $this->encode_request(self::DEDIMANIA_OPENSESSION, array($this->dedimaniaData->toArray()));
|
$content = $this->encode_request(self::DEDIMANIA_OPENSESSION, array($this->dedimaniaData->toArray()));
|
||||||
|
|
||||||
$self = $this;
|
$this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) {
|
||||||
$this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) use (&$self) {
|
$this->maniaControl->log("Try to connect on Dedimania");
|
||||||
$self->maniaControl->log("Try to connect on Dedimania");
|
|
||||||
|
|
||||||
if (!$data || $error) {
|
if (!$data || $error) {
|
||||||
$self->maniaControl->log("Dedimania Error: '{$error}'");
|
$this->maniaControl->log("Dedimania Error: '{$error}'");
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $self->decode($data);
|
$data = $this->decode($data);
|
||||||
if (is_array($data)) {
|
if (is_array($data)) {
|
||||||
foreach ($data as $index => $methodResponse) {
|
foreach ($data as $index => $methodResponse) {
|
||||||
if (xmlrpc_is_fault($methodResponse)) {
|
if (xmlrpc_is_fault($methodResponse)) {
|
||||||
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_OPENSESSION);
|
$this->handleXmlRpcFault($methodResponse, self::DEDIMANIA_OPENSESSION);
|
||||||
} else if ($index <= 0) {
|
} else if ($index <= 0) {
|
||||||
$responseData = $methodResponse[0];
|
$responseData = $methodResponse[0];
|
||||||
$self->dedimaniaData->sessionId = $responseData['SessionId'];
|
$this->dedimaniaData->sessionId = $responseData['SessionId'];
|
||||||
if ($self->dedimaniaData->sessionId != '') {
|
if ($this->dedimaniaData->sessionId) {
|
||||||
$self->maniaControl->log("Dedimania connection successfully established.");
|
$this->maniaControl->log("Dedimania connection successfully established.");
|
||||||
$self->fetchDedimaniaRecords();
|
$this->fetchDedimaniaRecords();
|
||||||
$self->init = true;
|
$this->init = true;
|
||||||
} else {
|
} else {
|
||||||
$self->maniaControl->log("Error while opening Dedimania Connection");
|
$this->maniaControl->log("Error while opening Dedimania Connection");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -277,8 +277,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
|||||||
$self->dedimaniaData->serverMaxRank = $responseData['ServerMaxRank'];
|
$self->dedimaniaData->serverMaxRank = $responseData['ServerMaxRank'];
|
||||||
|
|
||||||
foreach ($responseData['Players'] as $player) {
|
foreach ($responseData['Players'] as $player) {
|
||||||
$dediPlayer = new DedimaniaPlayer(null);
|
$dediPlayer = new DedimaniaPlayer($player);
|
||||||
$dediPlayer->constructNewPlayer($player['Login'], $player['MaxRank']);
|
|
||||||
$self->dedimaniaData->addPlayer($dediPlayer);
|
$self->dedimaniaData->addPlayer($dediPlayer);
|
||||||
}
|
}
|
||||||
foreach ($responseData['Records'] as $key => $record) {
|
foreach ($responseData['Records'] as $key => $record) {
|
||||||
@ -517,7 +516,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
|||||||
* Checks If a Dedimania Session exists, if not create a new oen
|
* Checks If a Dedimania Session exists, if not create a new oen
|
||||||
*/
|
*/
|
||||||
private function checkDedimaniaSession() {
|
private function checkDedimaniaSession() {
|
||||||
if ($this->dedimaniaData->sessionId == '') {
|
if (!$this->dedimaniaData->sessionId) {
|
||||||
$this->openDedimaniaSession();
|
$this->openDedimaniaSession();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -552,7 +551,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
|||||||
/**
|
/**
|
||||||
* Handle PlayerConnect callback
|
* Handle PlayerConnect callback
|
||||||
*
|
*
|
||||||
* @param \ManiaControl\Players\Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public function handlePlayerConnect(Player $player) {
|
public function handlePlayerConnect(Player $player) {
|
||||||
// Send Dedimania request
|
// Send Dedimania request
|
||||||
@ -561,7 +560,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
|||||||
|
|
||||||
$self = $this;
|
$self = $this;
|
||||||
$this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) use (&$self, &$player) {
|
$this->maniaControl->fileReader->postData(self::DEDIMANIA_URL, function ($data, $error) use (&$self, &$player) {
|
||||||
if ($error != '') {
|
if ($error) {
|
||||||
$self->maniaControl->log("Dedimania Error: " . $error);
|
$self->maniaControl->log("Dedimania Error: " . $error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -572,10 +571,11 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
|||||||
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERCONNECT);
|
$self->handleXmlRpcFault($methodResponse, self::DEDIMANIA_PLAYERCONNECT);
|
||||||
} else if ($index <= 0) {
|
} else if ($index <= 0) {
|
||||||
$responseData = $methodResponse[0];
|
$responseData = $methodResponse[0];
|
||||||
$self->dedimaniaData->addPlayer(new DedimaniaPlayer($responseData));
|
$dediPlayer = new DedimaniaPlayer($responseData);
|
||||||
|
$self->dedimaniaData->addPlayer($dediPlayer);
|
||||||
|
|
||||||
//Fetch records if he is the first who joined the server
|
// Fetch records if he is the first who joined the server
|
||||||
if (count($self->maniaControl->playerManager->getPlayers()) == 1) {
|
if ($self->maniaControl->playerManager->getPlayerCount(false) === 1) {
|
||||||
$self->fetchDedimaniaRecords(true);
|
$self->fetchDedimaniaRecords(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -853,7 +853,6 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
|||||||
return $record;
|
return $record;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RecordData(null);
|
return new RecordData(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ namespace MCTeam\Dedimania;
|
|||||||
use ManiaControl\Utils\Formatter;
|
use ManiaControl\Utils\Formatter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ManiaControl Dedimania-Plugin Record DataStructure
|
* ManiaControl Dedimania Plugin Record Data Structure
|
||||||
*
|
*
|
||||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright 2014 ManiaControl Team
|
* @copyright 2014 ManiaControl Team
|
||||||
|
Loading…
Reference in New Issue
Block a user