refactored some callback code in trackmania and removed some deprecates
This commit is contained in:
parent
b3707a47d1
commit
c3f5de1f29
@ -2,7 +2,6 @@
|
||||
|
||||
namespace ManiaControl\Callbacks;
|
||||
|
||||
use ManiaControl\Callbacks\Models\BaseCallback;
|
||||
use ManiaControl\General\UsageInformationAble;
|
||||
use ManiaControl\General\UsageInformationTrait;
|
||||
use ManiaControl\ManiaControl;
|
||||
@ -276,22 +275,16 @@ class CallbackManager implements UsageInformationAble {
|
||||
/**
|
||||
* Trigger a specific Callback
|
||||
*
|
||||
* @param mixed $callback
|
||||
* @param mixed $callbackName
|
||||
*/
|
||||
public function triggerCallback($callback) {
|
||||
if ($callback instanceof BaseCallback) {
|
||||
$callbackName = $callback->name;
|
||||
} else {
|
||||
$callbackName = $callback;
|
||||
}
|
||||
public function triggerCallback($callbackName) {
|
||||
|
||||
if (!$this->callbackListeningExists($callbackName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$params = func_get_args();
|
||||
if (!($callback instanceof BaseCallback)) {
|
||||
$params = array_slice($params, 1, null, true);
|
||||
}
|
||||
|
||||
foreach ($this->callbackListenings[$callbackName] as $listening) {
|
||||
/** @var Listening $listening */
|
||||
|
@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
// 22-3-2017 Added/Fixed TM Callback for WayPoint // Need to Add better checks eventually
|
||||
namespace ManiaControl\Callbacks;
|
||||
|
||||
/**
|
||||
@ -148,189 +147,14 @@ interface Callbacks {
|
||||
const TM_UIPROPERTIES = 'Trackmania.UI.Properties';
|
||||
const TM_POINTSREPARTITION = 'Trackmania.PointsRepartition';
|
||||
|
||||
//ManiaControl Specific TM Callbacks
|
||||
const TM_ONFINISHLINE = "ManiaControl.Trackmania.Event.OnFinishLine";
|
||||
const TM_ONLAPFINISH = "ManiaControl.Trackmania.Event.OnLapFinish";
|
||||
|
||||
//ManiaControl Callbacks
|
||||
/** BeginMap Callback: Map */
|
||||
const BEGINMAP = 'Callbacks.BeginMap';
|
||||
/** EndMap Callback: Map*/
|
||||
const ENDMAP = 'Callbacks.EndMap';
|
||||
|
||||
//OLD Callbacks
|
||||
/** BeginMatch Callback: MatchNumber
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const BEGINMATCH = 'Callbacks.BeginMatch';
|
||||
/** LoadingMap Callback: MapNumber
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const LOADINGMAP = 'Callbacks.LoadingMap';
|
||||
|
||||
/** BeginSubMatch Callback: SubmatchNumber
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const BEGINSUBMATCH = 'Callbacks.BeginSubmatch';
|
||||
/** BeginRound Callback: RoundNumber
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const BEGINROUND = 'Callbacks.BeginRound';
|
||||
/** BeginTurn Callback: TurnNumber
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const BEGINTURN = 'Callbacks.BeginTurn';
|
||||
/** BeginTurnStop Callback: TurnNumber
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const BEGINTURNSTOP = 'Callbacks.BeginTurnStop';
|
||||
/** BeginPlaying Callback
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const BEGINPLAYING = 'Callbacks.BeginPlaying';
|
||||
/** EndPlaying Callback
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const ENDPLAYING = 'Callbacks.EndPlaying';
|
||||
/** EndTurn Callback: TurnNumber
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const ENDTURN = 'Callbacks.EndTurn';
|
||||
/** EndTurnStop Callback: TurnNumber
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const ENDTURNSTOP = 'Callbacks.EndTurnStop';
|
||||
/** EndRound Callback: RoundNumber
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const ENDROUND = 'Callbacks.EndRound';
|
||||
/** EndRound Callback: RoundNumber
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const ENDROUNDSTOP = 'Callbacks.EndRoundStop';
|
||||
/** EndSubmatch Callback: SubmatchNumber
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const ENDSUBMATCH = 'Callbacks.EndSubmatch';
|
||||
|
||||
/** BeginPodium Callback
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const BEGINPODIUM = 'Callbacks.BeginPodium';
|
||||
/** EndPodium Callback
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const ENDPODIUM = 'Callbacks.EndPodium';
|
||||
/** UnloadingMap Callback
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const UNLOADINGMAP = 'Callbacks.UnloadingMap';
|
||||
/** EndMatch Callback: MatchNumber
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const ENDMATCH = 'Callbacks.EndMatch';
|
||||
|
||||
/** BeginWarmup Callback
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const BEGINWARMUP = 'Callbacks.BeginWarmUp';
|
||||
/** EndWarmup Callback
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const ENDWARMUP = 'Callbacks.EndWarmUp';
|
||||
|
||||
/** Scores Callback (returned after LibXmlRpc_PlayerRanking): Scores
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const SCORESREADY = 'Callbacks.ScoresReady';
|
||||
|
||||
/** Scores Callback (returned after LibXmlRpc_PlayerRanking in SM, or LibXmlRpc_TeamsScores in Trackmania): Scores
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const SCORES = 'Callbacks.Scores';
|
||||
|
||||
/** Rankings Callback
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const RANKINGS = 'Callbacks.Rankings';
|
||||
|
||||
/** PlayerRanking Callback, returned after LibXmlRpc_PlayerRanking
|
||||
* try to avoid to use this, just use the Get function of the RankingsManager instead
|
||||
* param1 Player $player
|
||||
* param2 int $rank
|
||||
* param3 int $currentPoints
|
||||
* param4 int AFKStatus
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const PLAYERRANKING = 'Callbacks.PlayerRanking';
|
||||
|
||||
/*
|
||||
* ShootMania Callbacks
|
||||
*/
|
||||
/** RankingsUpdated Callback: SortedRankings
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const RANKINGSUPDATED = 'Callbacks.RankingsUpdated';
|
||||
|
||||
/** Returns the AFKStatus of an Player, returned after param1 Scores
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const AFKSTATUS = 'Callbacks.AfkStatus';
|
||||
|
||||
/** OnPlayerRequestRespawn Callback: Player
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const ONPLAYERREQUESTRESPAWN = 'Callbacks.OnPlayerRequestRespawn';
|
||||
|
||||
/*
|
||||
* TrackMania Callbacks
|
||||
*/
|
||||
/** OnStartLine Callback
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const ONSTARTLINE = 'Callbacks.StartLine';
|
||||
/** OnWayPoint Callback
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const ONWAYPOINT = 'Callbacks.WayPoint';
|
||||
/** OnGiveUp Callback
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const ONGIVEUP = 'Callbacks.GiveUp';
|
||||
/** OnRespawn Callback
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const ONRESPAWN = 'Callbacks.Respawn';
|
||||
/** OnStunt Callback
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const ONSTUNT = 'Callbacks.Stunt';
|
||||
|
||||
}
|
||||
|
@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Callbacks\Models;
|
||||
|
||||
use ManiaControl\Players\Player;
|
||||
|
||||
/**
|
||||
* Base Model Class for Callbacks
|
||||
*
|
||||
* @deprecated
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014-2017 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
abstract class BaseCallback {
|
||||
/*
|
||||
* Public Properties
|
||||
*/
|
||||
public $name = null;
|
||||
public $rawCallback = null;
|
||||
public $isLegacyCallback = null;
|
||||
|
||||
public $pid = null;
|
||||
public $login = null;
|
||||
/** @var Player $player */
|
||||
public $player = null;
|
||||
|
||||
/**
|
||||
* Set the corresponding Player
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function setPlayer(Player $player) {
|
||||
$this->pid = $player->pid;
|
||||
$this->login = $player->login;
|
||||
$this->player = $player;
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Callbacks\Models;
|
||||
|
||||
use ManiaControl\Players\Player;
|
||||
|
||||
/**
|
||||
* Base Model Class for Callbacks
|
||||
*
|
||||
* @deprecated
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014-2017 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class RecordCallback extends BaseCallback {
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
const CHECKPOINT = 'RecordCallback.Checkpoint';
|
||||
const FINISH = 'RecordCallback.Finish';
|
||||
const LAPFINISH = 'RecordCallback.LapFinish';
|
||||
|
||||
/*
|
||||
* Public Properties
|
||||
*/
|
||||
public $time = null;
|
||||
/** @var Player $player */
|
||||
public $player = null;
|
||||
public $racetime = null;
|
||||
public $lapTime = null;
|
||||
public $stuntsscore = null;
|
||||
public $checkpointinrace = null;
|
||||
public $checkpointinlap = null;
|
||||
public $isendrace = null;
|
||||
public $isendlap = null;
|
||||
public $blockid = null;
|
||||
public $speed = null;
|
||||
public $distance = null;
|
||||
}
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace ManiaControl\Callbacks;
|
||||
|
||||
use ManiaControl\Callbacks\Models\RecordCallback;
|
||||
use ManiaControl\Callbacks\Structures\Common\BasePlayerTimeStructure;
|
||||
use ManiaControl\Callbacks\Structures\Common\UIPropertiesBaseStructure;
|
||||
use ManiaControl\Callbacks\Structures\ShootMania\OnActionCustomEventStructure;
|
||||
@ -157,79 +156,6 @@ class ShootManiaCallbacks implements CallbackListener {
|
||||
case Callbacks::SM_ROYAL_ROUNDWINNER:
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnRoyalRoundWinnerStructure($this->maniaControl, $data));
|
||||
break;
|
||||
|
||||
//Old Callbacks
|
||||
case 'LibXmlRpc_Rankings':
|
||||
$this->maniaControl->getServer()->getRankingManager()->updateRankings($data[0]);
|
||||
break;
|
||||
case 'LibAFK_IsAFK':
|
||||
$this->triggerAfkStatus($data[0]);
|
||||
break;
|
||||
case 'WarmUp_Status':
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::WARMUPSTATUS, $data[0]);
|
||||
break;
|
||||
case self::CB_TIMEATTACK_ONCHECKPOINT:
|
||||
$this->handleTimeAttackOnCheckpoint($name, $data);
|
||||
break;
|
||||
case self::CB_TIMEATTACK_ONFINISH:
|
||||
$this->handleTimeAttackOnFinish($name, $data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers the AFK Status of an Player
|
||||
*
|
||||
* @param string $login
|
||||
*/
|
||||
private function triggerAfkStatus($login) {
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::AFKSTATUS, $player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle TimeAttack OnCheckpoint Callback
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $data
|
||||
*/
|
||||
public function handleTimeAttackOnCheckpoint($name, array $data) {
|
||||
$login = $data[0];
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
||||
if (!$player) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Trigger checkpoint callback
|
||||
$checkpointCallback = new RecordCallback();
|
||||
$checkpointCallback->rawCallback = array($name, $data);
|
||||
$checkpointCallback->name = $checkpointCallback::CHECKPOINT;
|
||||
$checkpointCallback->setPlayer($player);
|
||||
$checkpointCallback->time = (int) $data[1];
|
||||
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback($checkpointCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle TimeAttack OnFinish Callback
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $data
|
||||
*/
|
||||
public function handleTimeAttackOnFinish($name, array $data) {
|
||||
$login = $data[0];
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
||||
if (!$player) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Trigger finish callback
|
||||
$finishCallback = new RecordCallback();
|
||||
$finishCallback->rawCallback = array($name, $data);
|
||||
$finishCallback->name = $finishCallback::FINISH;
|
||||
$finishCallback->setPlayer($player);
|
||||
$finishCallback->time = (int) $data[1];
|
||||
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback($finishCallback);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace ManiaControl\Callbacks\Structures\TrackMania;
|
||||
|
||||
|
||||
use ManiaControl\Callbacks\Models\RecordCallback;
|
||||
use ManiaControl\Callbacks\Structures\Common\BasePlayerTimeStructure;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Utils\Formatter;
|
||||
@ -27,6 +26,7 @@ class OnWayPointEventStructure extends BasePlayerTimeStructure {
|
||||
private $blockId;
|
||||
private $speed;
|
||||
private $distance;
|
||||
private $lapNumber;
|
||||
|
||||
/**
|
||||
* OnWayPointEventStructure constructor.
|
||||
@ -42,36 +42,16 @@ class OnWayPointEventStructure extends BasePlayerTimeStructure {
|
||||
$this->stuntsScore = $this->getPlainJsonObject()->stuntsscore;
|
||||
$this->checkPointInRace = (int) $this->getPlainJsonObject()->checkpointinrace;
|
||||
$this->checkPointInLap = (int) $this->getPlainJsonObject()->checkpointinlap;
|
||||
$this->isEndRace = $this->getPlainJsonObject()->isendrace;
|
||||
$this->isEndLap = $this->getPlainJsonObject()->isendlap;
|
||||
$this->isEndRace = Formatter::parseBoolean($this->getPlainJsonObject()->isendrace);
|
||||
$this->isEndLap = Formatter::parseBoolean($this->getPlainJsonObject()->isendlap);
|
||||
$this->blockId = $this->getPlainJsonObject()->blockid;
|
||||
$this->speed = $this->getPlainJsonObject()->speed;
|
||||
$this->distance = $this->getPlainJsonObject()->distance;
|
||||
|
||||
// Build callback //TODO remove the old lagacy stuff and update the uses to the new Structure
|
||||
$wayPointCallback = new RecordCallback();
|
||||
$wayPointCallback->rawCallback = $data;
|
||||
$wayPointCallback->setPlayer($this->getPlayer());
|
||||
$wayPointCallback->blockId = $this->blockId;
|
||||
$wayPointCallback->time = $this->raceTime;
|
||||
$wayPointCallback->checkpoint = $this->checkPointInRace;
|
||||
$wayPointCallback->isEndRace = Formatter::parseBoolean($this->isEndRace);
|
||||
$wayPointCallback->lapTime = $this->lapTime;
|
||||
$wayPointCallback->lapCheckpoint = $this->checkPointInLap;
|
||||
$wayPointCallback->lap = 0;
|
||||
$wayPointCallback->isEndLap = Formatter::parseBoolean($this->isEndLap);
|
||||
if ($wayPointCallback->checkpoint > 0) {
|
||||
if ($this->checkPointInRace > 0) {
|
||||
$currentMap = $this->maniaControl->getMapManager()->getCurrentMap();
|
||||
$wayPointCallback->lap += $wayPointCallback->checkpoint / $currentMap->nbCheckpoints;
|
||||
$this->lapNumber = intval($this->checkPointInRace / $currentMap->nbCheckpoints);
|
||||
}
|
||||
if ($wayPointCallback->isEndRace) {
|
||||
$wayPointCallback->name = $wayPointCallback::FINISH;
|
||||
} else if ($wayPointCallback->isEndLap) {
|
||||
$wayPointCallback->name = $wayPointCallback::LAPFINISH;
|
||||
} else {
|
||||
$wayPointCallback->name = $wayPointCallback::CHECKPOINT;
|
||||
}
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback($wayPointCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,4 +134,13 @@ class OnWayPointEventStructure extends BasePlayerTimeStructure {
|
||||
return $this->distance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Current Lap Number
|
||||
*
|
||||
* @return float|int
|
||||
*/
|
||||
public function getLapNumber() {
|
||||
return $this->lapNumber;
|
||||
}
|
||||
|
||||
}
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace ManiaControl\Callbacks;
|
||||
|
||||
use ManiaControl\Callbacks\Models\RecordCallback;
|
||||
use ManiaControl\Callbacks\Structures\Common\BasePlayerTimeStructure;
|
||||
use ManiaControl\Callbacks\Structures\Common\UIPropertiesBaseStructure;
|
||||
use ManiaControl\Callbacks\Structures\TrackMania\OnCommandStructure;
|
||||
@ -15,7 +14,6 @@ use ManiaControl\Callbacks\Structures\TrackMania\OnStuntEventStructure;
|
||||
use ManiaControl\Callbacks\Structures\TrackMania\OnWarmupStartEndRoundStructure;
|
||||
use ManiaControl\Callbacks\Structures\TrackMania\OnWayPointEventStructure;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Utils\Formatter;
|
||||
|
||||
/**
|
||||
* Class handling and parsing TrackMania Callbacks
|
||||
@ -75,7 +73,9 @@ class TrackManiaCallbacks implements CallbackListener {
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback($name, new BasePlayerTimeStructure($this->maniaControl, $data));
|
||||
break;
|
||||
case Callbacks::TM_ONWAYPOINT:
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnWayPointEventStructure($this->maniaControl, $data));
|
||||
$this->handleWayPointCallback(new OnWayPointEventStructure($this->maniaControl, $data));
|
||||
|
||||
//$this->maniaControl->getCallbackManager()->triggerCallback($name, $wayPointStructure);
|
||||
break;
|
||||
case Callbacks::TM_ONRESPAWN:
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback($name, new OnRespawnStructure($this->maniaControl, $data));
|
||||
@ -100,106 +100,18 @@ class TrackManiaCallbacks implements CallbackListener {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle OnWayPoint Callback
|
||||
* Trigger the three different Types of Callbacks
|
||||
*
|
||||
* @param array $callback
|
||||
* @param \ManiaControl\Callbacks\Structures\TrackMania\OnWayPointEventStructure $structure
|
||||
*/
|
||||
public function handleOnWayPointCallback(array $callback) {
|
||||
$login = $callback[0];
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
||||
if (!$player) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Build callback
|
||||
$wayPointCallback = new RecordCallback();
|
||||
$wayPointCallback->rawCallback = $callback;
|
||||
$wayPointCallback->setPlayer($player);
|
||||
$wayPointCallback->blockId = $callback[1];
|
||||
$wayPointCallback->time = (int) $callback[2];
|
||||
$wayPointCallback->checkpoint = (int) $callback[3];
|
||||
$wayPointCallback->isEndRace = Formatter::parseBoolean($callback[4]);
|
||||
$wayPointCallback->lapTime = (int) $callback[5];
|
||||
$wayPointCallback->lapCheckpoint = (int) $callback[6];
|
||||
$wayPointCallback->lap = 0;
|
||||
$wayPointCallback->isEndLap = Formatter::parseBoolean($callback[7]);
|
||||
|
||||
if ($wayPointCallback->checkpoint > 0) {
|
||||
$currentMap = $this->maniaControl->getMapManager()->getCurrentMap();
|
||||
$wayPointCallback->lap += $wayPointCallback->checkpoint / $currentMap->nbCheckpoints;
|
||||
}
|
||||
|
||||
if ($wayPointCallback->isEndRace) {
|
||||
$wayPointCallback->name = $wayPointCallback::FINISH;
|
||||
} else if ($wayPointCallback->isEndLap) {
|
||||
$wayPointCallback->name = $wayPointCallback::LAPFINISH;
|
||||
private function handleWayPointCallback(OnWayPointEventStructure $structure) {
|
||||
if ($structure->getIsEndRace()) {
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::TM_ONFINISHLINE, $structure);
|
||||
} else if ($structure->getIsEndLap()) {
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::TM_ONLAPFINISH, $structure);
|
||||
} else {
|
||||
$wayPointCallback->name = $wayPointCallback::CHECKPOINT;
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::TM_ONWAYPOINT, $structure);
|
||||
}
|
||||
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback($wayPointCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Hard-Coded Player Checkpoint Callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function handlePlayerCheckpointCallback(array $callback) {
|
||||
$data = $callback[1];
|
||||
$login = $data[1];
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
||||
if (!$player) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Build checkpoint callback
|
||||
$checkpointCallback = new RecordCallback();
|
||||
$checkpointCallback->isLegacyCallback = true;
|
||||
$checkpointCallback->rawCallback = $callback;
|
||||
$checkpointCallback->setPlayer($player);
|
||||
$checkpointCallback->time = (int) $data[2];
|
||||
$checkpointCallback->lap = (int) $data[3];
|
||||
$checkpointCallback->checkpoint = (int) $data[4];
|
||||
$checkpointCallback->lapCheckpoint = $checkpointCallback->checkpoint;
|
||||
|
||||
if ($checkpointCallback->lap > 0) {
|
||||
$currentMap = $this->maniaControl->getMapManager()->getCurrentMap();
|
||||
$checkpointCallback->lapCheckpoint -= $checkpointCallback->lap * $currentMap->nbCheckpoints;
|
||||
}
|
||||
|
||||
if ($checkpointCallback->lapCheckpoint === 0) {
|
||||
$checkpointCallback->name = $checkpointCallback::LAPFINISH;
|
||||
} else {
|
||||
$checkpointCallback->name = $checkpointCallback::CHECKPOINT;
|
||||
}
|
||||
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback($checkpointCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Hard-Coded Player Finish Callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function handlePlayerFinishCallback(array $callback) {
|
||||
$data = $callback[1];
|
||||
$login = $data[1];
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
||||
if (!$player) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Build finish callback
|
||||
$finishCallback = new RecordCallback();
|
||||
$finishCallback->name = $finishCallback::FINISH;
|
||||
$finishCallback->isLegacyCallback = true;
|
||||
$finishCallback->rawCallback = $callback;
|
||||
$finishCallback->setPlayer($player);
|
||||
$finishCallback->time = (int) $data[2];
|
||||
|
||||
$this->maniaControl->getCallbackManager()->triggerCallback($finishCallback);
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ use FML\Script\Features\Paging;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\Callbacks\Callbacks;
|
||||
use ManiaControl\Callbacks\Models\RecordCallback;
|
||||
use ManiaControl\Callbacks\Structures\TrackMania\OnWayPointEventStructure;
|
||||
use ManiaControl\Callbacks\TimerListener;
|
||||
use ManiaControl\Commands\CommandListener;
|
||||
use ManiaControl\Files\AsyncHttpRequest;
|
||||
@ -146,16 +146,16 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(RecordCallback::CHECKPOINT, $this, 'handleCheckpointCallback');
|
||||
//$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::TM_ONWAYPOINT, $this, 'handleCheckpointCallback');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(RecordCallback::LAPFINISH, $this, 'handleLapFinishCallback');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(RecordCallback::FINISH, $this, 'handleFinishCallback');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::TM_ONWAYPOINT, $this, 'handleCheckpointCallback');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::TM_ONFINISHLINE, $this, 'handleFinishCallback');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::TM_ONLAPFINISH, $this, 'handleFinishCallback');
|
||||
|
||||
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'updateEverySecond', 1000);
|
||||
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'handleEveryHalfMinute', 1000 * 30);
|
||||
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'updatePlayerList', 1000 * 60 * 3);
|
||||
|
||||
$this->maniaControl->getCommandManager()->registerCommandListener(array('dedirecs', 'dedirecords'), $this, 'showDediRecordsList', false, 'Shows a list of Dedimania records of the current map.');
|
||||
$this->maniaControl->getCommandManager()->registerCommandListener(array('dedirecs',
|
||||
'dedirecords'), $this, 'showDediRecordsList', false, 'Shows a list of Dedimania records of the current map.');
|
||||
|
||||
// Open session
|
||||
$serverInfo = $this->maniaControl->getServer()->getInfo();
|
||||
@ -463,17 +463,17 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
||||
}
|
||||
|
||||
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_ENABLE)) {
|
||||
$manialink = $this->buildManialink();
|
||||
$this->maniaControl->getManialinkManager()->sendManialink($manialink);
|
||||
$this->sendManialink();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build Manialink
|
||||
*
|
||||
* @return \FML\ManiaLink
|
||||
* Builds and Sends the Manialink
|
||||
*/
|
||||
private function buildManialink() {
|
||||
private function sendManialink() {
|
||||
if (!isset($this->dedimaniaData) || !isset($this->dedimaniaData->records)) {
|
||||
return null;
|
||||
}
|
||||
$records = $this->dedimaniaData->records;
|
||||
|
||||
$title = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_TITLE);
|
||||
@ -557,7 +557,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
||||
$timeLabel->setTextEmboss(true);
|
||||
}
|
||||
|
||||
return $manialink;
|
||||
$this->maniaControl->getManialinkManager()->sendManialink($manialink);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -662,8 +662,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
||||
}
|
||||
|
||||
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_ENABLE)) {
|
||||
$manialink = $this->buildManialink();
|
||||
$this->maniaControl->getManialinkManager()->sendManialink($manialink, $player->login);
|
||||
$this->sendManialink();
|
||||
}
|
||||
});
|
||||
|
||||
@ -863,23 +862,9 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
||||
/**
|
||||
* Handle Checkpoint Callback
|
||||
*
|
||||
* @param RecordCallback $callback
|
||||
* @param OnWayPointEventStructure $callback
|
||||
*/
|
||||
public function handleCheckpointCallback(RecordCallback $callback) {
|
||||
//var_dump($callback->lapTime); //FIXME, dedimania needs Finish as LastCp, or NbOfCheckpoints wrong?
|
||||
|
||||
if ($callback->isLegacyCallback || !$callback->lapTime) {
|
||||
return;
|
||||
}
|
||||
if (!isset($this->checkpoints[$callback->login])) {
|
||||
$this->checkpoints[$callback->login] = array();
|
||||
}
|
||||
$this->checkpoints[$callback->login][$callback->lapCheckpoint] = $callback->lapTime;
|
||||
}
|
||||
|
||||
/*public function handleCheckpointCallback(OnWayPointEventStructure $structure) {
|
||||
//var_dump($callback->lapTime); //new structure but that change isnt enough
|
||||
|
||||
public function handleCheckpointCallback(OnWayPointEventStructure $structure) {
|
||||
if (!$structure->getLapTime()) {
|
||||
return;
|
||||
}
|
||||
@ -889,30 +874,19 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
||||
$this->checkpoints[$login] = array();
|
||||
}
|
||||
$this->checkpoints[$login][$structure->getCheckPointInLap()] = $structure->getLapTime();
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Handle LapFinish Callback
|
||||
*
|
||||
* @param RecordCallback $callback
|
||||
*/
|
||||
public function handleLapFinishCallback(RecordCallback $callback) {
|
||||
$this->handleFinishCallback($callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Finish Callback
|
||||
*
|
||||
* @param RecordCallback $callback
|
||||
* @param OnWayPointEventStructure $callback
|
||||
*/
|
||||
public function handleFinishCallback(RecordCallback $callback) {
|
||||
public function handleFinishCallback(OnWayPointEventStructure $structure) {
|
||||
if (!isset($this->dedimaniaData)) {
|
||||
return;
|
||||
}
|
||||
if ($callback->isLegacyCallback) {
|
||||
return;
|
||||
}
|
||||
if ($callback->time <= 0) {
|
||||
|
||||
if ($structure->getRaceTime() <= 0) {
|
||||
// Invalid time
|
||||
return;
|
||||
}
|
||||
@ -926,15 +900,17 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
||||
return;
|
||||
}
|
||||
|
||||
$oldRecord = $this->getDedimaniaRecord($callback->login);
|
||||
if ($oldRecord->nullRecord || $oldRecord && $oldRecord->best > $callback->lapTime) {
|
||||
$player = $structure->getPlayer();
|
||||
|
||||
$oldRecord = $this->getDedimaniaRecord($player->login);
|
||||
if ($oldRecord->nullRecord || $oldRecord && $oldRecord->best > $structure->getLapTime()) {
|
||||
// Save time
|
||||
$newRecord = new RecordData(null);
|
||||
|
||||
$checkPoints = $this->getCheckpoints($callback->login);
|
||||
$checkPoints = $checkPoints . "," . $callback->lapTime;
|
||||
$checkPoints = $this->getCheckpoints($player->login);
|
||||
$checkPoints = $checkPoints . "," . $structure->getLapTime();
|
||||
|
||||
$newRecord->constructNewRecord($callback->login, $callback->player->nickname, $callback->lapTime, $checkPoints, true);
|
||||
$newRecord->constructNewRecord($player->login, $player->nickname, $structure->getLapTime(), $checkPoints, true);
|
||||
|
||||
if ($this->insertDedimaniaRecord($newRecord, $oldRecord)) {
|
||||
// Get newly saved record
|
||||
@ -956,9 +932,9 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
||||
// Only improved time
|
||||
$improvement = 'improved his/her';
|
||||
}
|
||||
$message = '$390$<$fff' . $callback->player->nickname . '$> ' . $improvement . ' $<$ff0' . $newRecord->rank . '.$> Dedimania Record: $<$fff' . Formatter::formatTime($newRecord->best) . '$>';
|
||||
$message = '$390$<$fff' . $player->nickname . '$> ' . $improvement . ' $<$ff0' . $newRecord->rank . '.$> Dedimania Record: $<$fff' . Formatter::formatTime($newRecord->best) . '$>';
|
||||
if (!$oldRecord->nullRecord) {
|
||||
$message .= ' ($<$ff0' . $oldRecord->rank . '.$> $<$fff-' . Formatter::formatTime(($oldRecord->best - $callback->lapTime)) . '$>)';
|
||||
$message .= ' ($<$ff0' . $oldRecord->rank . '.$> $<$fff-' . Formatter::formatTime(($oldRecord->best - $structure->getLapTime())) . '$>)';
|
||||
}
|
||||
$this->maniaControl->getChat()->sendInformation($message . '!');
|
||||
|
||||
@ -974,7 +950,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
|
||||
* @return RecordData $record
|
||||
*/
|
||||
private function getDedimaniaRecord($login) {
|
||||
if (!isset($this->dedimaniaData) || !$this->dedimaniaData->records) {
|
||||
if (!isset($this->dedimaniaData) || !isset($this->dedimaniaData->records)) {
|
||||
return new RecordData(null);
|
||||
}
|
||||
$records = $this->dedimaniaData->records;
|
||||
|
@ -12,7 +12,7 @@ use ManiaControl\Admin\AuthenticationManager;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\Callbacks\Callbacks;
|
||||
use ManiaControl\Callbacks\Models\RecordCallback;
|
||||
use ManiaControl\Callbacks\Structures\TrackMania\OnWayPointEventStructure;
|
||||
use ManiaControl\Callbacks\TimerListener;
|
||||
use ManiaControl\Commands\CommandListener;
|
||||
use ManiaControl\Logger;
|
||||
@ -135,9 +135,10 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(RecordCallback::CHECKPOINT, $this, 'handleCheckpointCallback');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(RecordCallback::LAPFINISH, $this, 'handleLapFinishCallback');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(RecordCallback::FINISH, $this, 'handleFinishCallback');
|
||||
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::TM_ONWAYPOINT, $this, 'handleCheckpointCallback');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::TM_ONFINISHLINE, $this, 'handleFinishCallback');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::TM_ONLAPFINISH, $this, 'handleFinishCallback');
|
||||
|
||||
$this->maniaControl->getCommandManager()->registerCommandListener(array('recs', 'records'), $this, 'showRecordsList', false, 'Shows a list of Local Records on the current map.');
|
||||
$this->maniaControl->getCommandManager()->registerCommandListener('delrec', $this, 'deleteRecord', true, 'Removes a record from the database.');
|
||||
@ -197,8 +198,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
|
||||
}
|
||||
|
||||
$this->updateManialink = false;
|
||||
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_ENABLE)
|
||||
) {
|
||||
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_WIDGET_ENABLE)) {
|
||||
$manialink = $this->buildManialink();
|
||||
$this->maniaControl->getManialinkManager()->sendManialink($manialink);
|
||||
}
|
||||
@ -343,8 +343,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
|
||||
}
|
||||
|
||||
switch ($setting->setting) {
|
||||
case self::SETTING_WIDGET_ENABLE:
|
||||
{
|
||||
case self::SETTING_WIDGET_ENABLE: {
|
||||
if ($setting->value) {
|
||||
$this->updateManialink = true;
|
||||
} else {
|
||||
@ -363,23 +362,12 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
|
||||
*
|
||||
* @param RecordCallback $callback
|
||||
*/
|
||||
public function handleCheckpointCallback(RecordCallback $callback) {
|
||||
if ($callback->isLegacyCallback) {
|
||||
return;
|
||||
public function handleCheckpointCallback(OnWayPointEventStructure $structure) {
|
||||
$playerLogin = $structure->getPlayer()->login;
|
||||
if (!isset($this->checkpoints[$playerLogin])) {
|
||||
$this->checkpoints[$playerLogin] = array();
|
||||
}
|
||||
if (!isset($this->checkpoints[$callback->login])) {
|
||||
$this->checkpoints[$callback->login] = array();
|
||||
}
|
||||
$this->checkpoints[$callback->login][$callback->lapCheckpoint] = $callback->lapTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle LapFinish Callback
|
||||
*
|
||||
* @param RecordCallback $callback
|
||||
*/
|
||||
public function handleLapFinishCallback(RecordCallback $callback) {
|
||||
$this->handleFinishCallback($callback);
|
||||
$this->checkpoints[$playerLogin][$structure->getCheckPointInLap()] = $structure->getLapTime();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -387,31 +375,30 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
|
||||
*
|
||||
* @param RecordCallback $callback
|
||||
*/
|
||||
public function handleFinishCallback(RecordCallback $callback) {
|
||||
if ($callback->isLegacyCallback) {
|
||||
return;
|
||||
}
|
||||
if ($callback->time <= 0) {
|
||||
public function handleFinishCallback(OnWayPointEventStructure $structure) {
|
||||
if ($structure->getRaceTime() <= 0) {
|
||||
// Invalid time
|
||||
return;
|
||||
}
|
||||
|
||||
$map = $this->maniaControl->getMapManager()->getCurrentMap();
|
||||
|
||||
$checkpointsString = $this->getCheckpoints($callback->player->login);
|
||||
$this->checkpoints[$callback->login] = array();
|
||||
$player = $structure->getPlayer();
|
||||
|
||||
$checkpointsString = $this->getCheckpoints($player->login);
|
||||
$this->checkpoints[$player->login] = array();
|
||||
|
||||
// Check old record of the player
|
||||
$oldRecord = $this->getLocalRecord($map, $callback->player);
|
||||
$oldRecord = $this->getLocalRecord($map, $player);
|
||||
if ($oldRecord) {
|
||||
if ($oldRecord->time < $callback->time) {
|
||||
if ($oldRecord->time < $structure->getRaceTime()) {
|
||||
// Not improved
|
||||
return;
|
||||
}
|
||||
if ($oldRecord->time == $callback->time) {
|
||||
if ($oldRecord->time == $structure->getRaceTime()) {
|
||||
// Same time
|
||||
// TODO: respect notify-settings
|
||||
$message = '$<$fff' . $callback->player->nickname . '$> equalized his/her $<$ff0' . $oldRecord->rank . '.$> Local Record: $<$fff' . Formatter::formatTime($oldRecord->time) . '$>!';
|
||||
$message = '$<$fff' . $player->nickname . '$> equalized his/her $<$ff0' . $oldRecord->rank . '.$> Local Record: $<$fff' . Formatter::formatTime($oldRecord->time) . '$>!';
|
||||
$this->maniaControl->getChat()->sendInformation('$3c0' . $message);
|
||||
return;
|
||||
}
|
||||
@ -426,8 +413,8 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
|
||||
`checkpoints`
|
||||
) VALUES (
|
||||
{$map->index},
|
||||
{$callback->player->index},
|
||||
{$callback->time},
|
||||
{$player->index},
|
||||
{$structure->getRaceTime()},
|
||||
'{$checkpointsString}'
|
||||
) ON DUPLICATE KEY UPDATE
|
||||
`time` = VALUES(`time`),
|
||||
@ -440,7 +427,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
|
||||
$this->updateManialink = true;
|
||||
|
||||
// Announce record
|
||||
$newRecord = $this->getLocalRecord($map, $callback->player);
|
||||
$newRecord = $this->getLocalRecord($map, $player);
|
||||
$improvedRank = (!$oldRecord || $newRecord->rank < $oldRecord->rank);
|
||||
|
||||
$notifyOnlyDriver = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_NOTIFY_ONLY_DRIVER);
|
||||
@ -450,7 +437,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
|
||||
if ($notifyOnlyDriver) {
|
||||
$message .= 'You';
|
||||
} else {
|
||||
$message .= '$<$fff' . $callback->player->nickname . '$>';
|
||||
$message .= '$<$fff' . $player->nickname . '$>';
|
||||
}
|
||||
$message .= ' ' . ($improvedRank ? 'gained' : 'improved') . ' the';
|
||||
$message .= ' $<$ff0' . $newRecord->rank . '.$> Local Record:';
|
||||
@ -465,7 +452,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
|
||||
}
|
||||
|
||||
if ($notifyOnlyDriver) {
|
||||
$this->maniaControl->getChat()->sendInformation($message, $callback->player);
|
||||
$this->maniaControl->getChat()->sendInformation($message, $player);
|
||||
} else if (!$notifyOnlyBestRecords || $newRecord->rank <= $notifyOnlyBestRecords) {
|
||||
$this->maniaControl->getChat()->sendInformation($message);
|
||||
}
|
||||
@ -632,8 +619,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
|
||||
* @param Player $player
|
||||
*/
|
||||
public function deleteRecord(array $chat, Player $player) {
|
||||
if (!$this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)
|
||||
) {
|
||||
if (!$this->maniaControl->getAuthenticationManager()->checkRight($player, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)) {
|
||||
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
@ -644,7 +630,7 @@ class LocalRecordsPlugin implements CallbackListener, CommandListener, TimerList
|
||||
return;
|
||||
}
|
||||
|
||||
$recordId = (int)$commandParts[1];
|
||||
$recordId = (int) $commandParts[1];
|
||||
$currentMap = $this->maniaControl->getMapManager()->getCurrentMap();
|
||||
$records = $this->getLocalRecords($currentMap);
|
||||
if (count($records) < $recordId) {
|
||||
|
Loading…
Reference in New Issue
Block a user