Skip to content

Commit

Permalink
Merge pull request #8 from NewboO/callbacks-update
Browse files Browse the repository at this point in the history
Adding new callbacks
  • Loading branch information
satanasdiabolo committed May 5, 2014
2 parents 825715f + 60fb935 commit dc2dd07
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 115 deletions.
80 changes: 17 additions & 63 deletions ManiaLive/Data/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,9 @@ function onPostLoop()
if($this->currentVote instanceof Vote && $this->currentVote->status != Vote::STATE_NEW) $this->currentVote = null;
}

function onRun()
{

}

function onPreLoop()
{

}

function onTerminate()
{

}
function onRun() {}
function onPreLoop() {}
function onTerminate() {}

function onPlayerConnect($login, $isSpectator)
{
Expand Down Expand Up @@ -218,20 +207,9 @@ function onPlayerDisconnect($login, $disconnectionReason)
else if(isset($this->spectators[$login])) $this->spectators[$login]->isConnected = false;
}

function onPlayerChat($playerUid, $login, $text, $isRegistredCmd)
{

}

function onPlayerManialinkPageAnswer($playerUid, $login, $answer, array $entries)
{

}

function onEcho($internal, $public)
{

}
function onPlayerChat($playerUid, $login, $text, $isRegistredCmd) {}
function onPlayerManialinkPageAnswer($playerUid, $login, $answer, array $entries) {}
function onEcho($internal, $public) {}

function onServerStart()
{
Expand All @@ -247,15 +225,8 @@ function onServerStart()
}
}

function onServerStop()
{

}

function onBeginMatch()
{

}
function onServerStop() {}
function onBeginMatch() {}

function onEndMatch($rankings, $winnerTeamOrMap)
{
Expand Down Expand Up @@ -304,10 +275,7 @@ function onEndMap($rankings, $map, $wasWarmUp, $matchContinuesOnNextMap, $restar
}
}

function onBeginRound()
{

}
function onBeginRound() {}

function onEndRound()
{
Expand Down Expand Up @@ -467,20 +435,9 @@ function onPlayerFinish($playerUid, $login, $timeOrScore)
}
}

function onPlayerIncoherence($playerUid, $login)
{

}

function onBillUpdated($billId, $state, $stateName, $transactionId)
{

}

function onTunnelDataReceived($playerUid, $login, $data)
{

}
function onPlayerIncoherence($playerUid, $login) {}
function onBillUpdated($billId, $state, $stateName, $transactionId) {}
function onTunnelDataReceived($playerUid, $login, $data) {}

function onMapListModified($curMapIndex, $nextMapIndex, $isListModified)
{
Expand Down Expand Up @@ -552,10 +509,7 @@ function onPlayerInfoChanged($playerInfo)
}
}

function onManualFlowControlTransition($transition)
{

}
function onManualFlowControlTransition($transition) {}

function onVoteUpdated($stateName, $login, $cmdName, $cmdParam)
{
Expand All @@ -566,10 +520,7 @@ function onVoteUpdated($stateName, $login, $cmdName, $cmdParam)
$this->currentVote->cmdParam = $cmdParam;
}

function onModeScriptCallback($param1, $param2)
{

}
function onModeScriptCallback($param1, $param2) {}

function onPlayerAlliesChanged($login)
{
Expand All @@ -583,6 +534,9 @@ function onPlayerAlliesChanged($login)
}
}

function onLoadData($type, $id) {}
function onSaveData($type, $id) {}

/**
* Give a Player Object for the corresponding login
* @param string $login
Expand Down
12 changes: 7 additions & 5 deletions ManiaLive/DedicatedApi/Callback/Adapter.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* ManiaLive - TrackMania dedicated server manager in PHP
*
*
* @copyright Copyright (c) 2009-2011 NADEO (http://www.nadeo.com)
* @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
* @version $Revision$:
Expand All @@ -12,7 +12,7 @@
namespace ManiaLive\DedicatedApi\Callback;

abstract class Adapter implements Listener
{
{
function onPlayerConnect($login, $isSpectator) {}
function onPlayerDisconnect($login, $disconnectionReason) {}
function onPlayerChat($playerUid, $login, $text, $isRegistredCmd) {}
Expand All @@ -29,15 +29,17 @@ function onEndRound() {}
function onStatusChanged($statusCode, $statusName) {}
function onPlayerCheckpoint($playerUid, $login, $timeOrScore, $curLap, $checkpointIndex) {}
function onPlayerFinish($playerUid, $login, $timeOrScore) {}
function onPlayerIncoherence($playerUid, $login) {}
function onPlayerIncoherence($playerUid, $login) {}
function onBillUpdated($billId, $state, $stateName, $transactionId) {}
function onTunnelDataReceived($playerUid, $login, $data) {}
function onMapListModified($curMapIndex, $nextMapIndex, $isListModified) {}
function onTunnelDataReceived($playerUid, $login, $data) {}
function onMapListModified($curMapIndex, $nextMapIndex, $isListModified) {}
function onPlayerInfoChanged($playerInfo) {}
function onManualFlowControlTransition($transition) {}
function onVoteUpdated($stateName, $login, $cmdName, $cmdParam) {}
function onModeScriptCallback($param1, $param2) {}
function onPlayerAlliesChanged($login) {}
function onLoadData($type, $id) {}
function onSaveData($type, $id) {}
}

?>
20 changes: 12 additions & 8 deletions ManiaLive/DedicatedApi/Callback/Event.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* ManiaLive - TrackMania dedicated server manager in PHP
*
*
* @copyright Copyright (c) 2009-2011 NADEO (http://www.nadeo.com)
* @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
* @version $Revision$:
Expand Down Expand Up @@ -39,28 +39,30 @@ class Event extends \ManiaLive\Event\Event
const ON_MODE_SCRIPT_CALLBACK = 0x800000;
const ON_MODE_SCRIPT_CALLBACK_ARRAY = 0x800000;
const ON_PLAYER_ALLIES_CHANGED = 0x1000000;

const ON_LOAD_DATA = 0x2000000;
const ON_SAVE_DATA = 0x4000000;

static private $rc;
protected $params;

function __construct($method, $params = array())
{
parent::__construct(self::getOnWhat($method));
$this->params = $params;
}

function fireDo($listener)
{
$p = $this->params;
// Explicit calls are always *a lot* faster than using call_user_func() even if longer to write
switch($this->onWhat)
{
case self::ON_PLAYER_CONNECT: $listener->onPlayerConnect($p[0], $p[1]); break;
case self::ON_PLAYER_DISCONNECT:
case self::ON_PLAYER_DISCONNECT:
if(count($p) == 1)
$listener->onPlayerDisconnect($p[0], '');
$listener->onPlayerDisconnect($p[0], '');
else
$listener->onPlayerDisconnect($p[0], $p[1]);
$listener->onPlayerDisconnect($p[0], $p[1]);
break;
case self::ON_PLAYER_CHAT: $listener->onPlayerChat($p[0], $p[1], $p[2], $p[3]); break;
case self::ON_PLAYER_MANIALINK_PAGE_ANSWER: $listener->onPlayerManialinkPageAnswer($p[0], $p[1], $p[2], $p[3]); break;
Expand Down Expand Up @@ -97,9 +99,11 @@ function fireDo($listener)
case self::ON_VOTE_UPDATED: $listener->onVoteUpdated($p[0], $p[1], $p[2], $p[3]); break;
case self::ON_MODE_SCRIPT_CALLBACK: $listener->onModeScriptCallback($p[0], $p[1]); break;
case self::ON_PLAYER_ALLIES_CHANGED: $listener->onPlayerAlliesChanged($p[0]);break;
case self::ON_LOAD_DATA: $listener->onLoadData($p[0], $p[1]);break;
case self::ON_SAVE_DATA: $listener->onSaveData($p[0], $p[1]);break;
}
}

private static function getOnWhat($method)
{
$constName = 'ON_'.strtoupper(preg_replace('/([a-z])([A-Z])/', '$1_$2', $method));
Expand Down
28 changes: 21 additions & 7 deletions ManiaLive/DedicatedApi/Callback/Listener.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* ManiaLive - TrackMania dedicated server manager in PHP
*
*
* @copyright Copyright (c) 2009-2011 NADEO (http://www.nadeo.com)
* @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
* @version $Revision$:
Expand Down Expand Up @@ -74,7 +74,7 @@ function onBeginMatch();
* int NbrLapsFinished;
* double LadderScore;
* ]
* }
* }
* @param SPlayerRanking[] $rankings
* @param int|SMapInfo $winnerTeamOrMap Winner team if API version >= 2012-06-19, else the map
*/
Expand Down Expand Up @@ -131,7 +131,7 @@ function onPlayerFinish($playerUid, $login, $timeOrScore);
* @param int $playerUid
* @param string $login
*/
function onPlayerIncoherence($playerUid, $login);
function onPlayerIncoherence($playerUid, $login);
/**
* Method called when a bill is updated
* @param int $billId
Expand All @@ -146,14 +146,14 @@ function onBillUpdated($billId, $state, $stateName, $transactionId);
* @param string $login
* @param base64 $data
*/
function onTunnelDataReceived($playerUid, $login, $data);
function onTunnelDataReceived($playerUid, $login, $data);
/**
* Method called when the map list is modified
* @param int $curMapIndex
* @param int $nextMapIndex
* @param bool $isListModified
*/
function onMapListModified($curMapIndex, $nextMapIndex, $isListModified);
function onMapListModified($curMapIndex, $nextMapIndex, $isListModified);
/**
* Method called when player info changed
* @param SPlayerInfo $playerInfo
Expand All @@ -173,16 +173,30 @@ function onManualFlowControlTransition($transition);
*/
function onVoteUpdated($stateName, $login, $cmdName, $cmdParam);
/**
* @param string
* @param string
* @param string
*/
function onModeScriptCallback($param1, $param2);

/**
* Method called when the player in parameter has changed its allies
* @param string $login
*/
function onPlayerAlliesChanged($login);

/**
* You must answer this callback by calling SetScriptCloudVariables for given object.
* @param string $type
* @param int $id
*/
function onLoadData($type, $id);

/**
* You must answer this callback by calling GetScriptCloudVariables for given object.
* @param string $type
* @param int $id
*/
function onSaveData($type, $id);
}

?>
2 changes: 2 additions & 0 deletions ManiaLive/Features/ChatCommand/Interpreter.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ function onManualFlowControlTransition($transition) {}
function onVoteUpdated($stateName, $login, $cmdName, $cmdParam) {}
function onModeScriptCallback($param1, $param2) {}
function onPlayerAlliesChanged($login) {}
function onLoadData($type, $id) {}
function onSaveData($type, $id) {}
}

class CommandAlreadyRegisteredException extends \Exception {}
Expand Down
10 changes: 6 additions & 4 deletions ManiaLive/Features/EchoHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class EchoHandler extends \ManiaLib\Utils\Singleton implements Listener
private $connection;
/** @var string */
private $identifier;

protected function __construct()
{
$this->identifier = 'ManiaLive '.\ManiaLive\Application\VERSION;
Expand All @@ -35,13 +35,13 @@ protected function __construct()
);
Dispatcher::register(Event::getClass(), $this, Event::ON_ECHO);
}

public function onEcho($internal, $public)
{
$call = explode(':', substr($internal, 1), 2);
if(isset($call[1]) && $call[1] != $this->identifier)
return;

if(substr($internal, 0, 1) == '?')
{
switch($call[0])
Expand All @@ -55,7 +55,7 @@ public function onEcho($internal, $public)
}
}
}

public function onBeginMap($map, $warmUp, $matchContinuation) {}
public function onBeginMatch() {}
public function onBeginRound() {}
Expand All @@ -80,6 +80,8 @@ public function onStatusChanged($statusCode, $statusName) {}
public function onTunnelDataReceived($playerUid, $login, $data) {}
public function onVoteUpdated($stateName, $login, $cmdName, $cmdParam) {}
public function onPlayerAlliesChanged($login) {}
public function onLoadData($type, $id) {}
public function onSaveData($type, $id) {}
}

?>
Loading

0 comments on commit dc2dd07

Please sign in to comment.