2013-11-09 20:18:49 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Created by PhpStorm.
|
|
|
|
* User: Lukas
|
|
|
|
* Date: 09.11.13
|
|
|
|
* Time: 19:44
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace ManiaControl;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class playerHandler
|
|
|
|
* @package ManiaControl
|
|
|
|
*/
|
|
|
|
class playerHandler {
|
2013-11-09 23:01:54 +01:00
|
|
|
|
2013-11-09 20:18:49 +01:00
|
|
|
/**
|
|
|
|
* Private properties
|
|
|
|
*/
|
|
|
|
private $playerList;
|
|
|
|
private $mc;
|
|
|
|
|
2013-11-09 23:01:54 +01:00
|
|
|
/**
|
|
|
|
* Public properties
|
|
|
|
*/
|
|
|
|
public $rightLevels = array(0 => 'Player', 1 => 'Operator', 2 => 'Admin', 3 => 'MasterAdmin', 4 => 'MasterAdmin');
|
|
|
|
|
2013-11-09 20:18:49 +01:00
|
|
|
public function __construct(ManiaControl $mc){
|
|
|
|
$this->mc = $mc;
|
|
|
|
$this->playerList = array();
|
|
|
|
$this->mc->callbacks->registerCallbackHandler(Callbacks::CB_MP_PLAYERCONNECT, $this, 'playerConnect');
|
2013-11-09 22:08:06 +01:00
|
|
|
$this->mc->callbacks->registerCallbackHandler(Callbacks::CB_MP_PLAYERDISCONNECT, $this, 'playerDisconnect');
|
2013-11-09 20:18:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-11-09 23:01:54 +01:00
|
|
|
* initializes a Whole PlayerList
|
2013-11-09 20:18:49 +01:00
|
|
|
* @param $players
|
|
|
|
*/
|
|
|
|
public function addPlayerList($players){
|
|
|
|
foreach($players as $player){
|
|
|
|
$this->playerConnect(array($player['Login'], ''));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
2013-11-09 21:35:43 +01:00
|
|
|
* Handles a playerConnect
|
2013-11-09 20:18:49 +01:00
|
|
|
* @param $player
|
|
|
|
*/
|
|
|
|
public function playerConnect($player){
|
2013-11-09 22:08:06 +01:00
|
|
|
//TODO: Welcome Message?, on mc restart not all players listed, no relay support yet
|
2013-11-09 23:01:54 +01:00
|
|
|
//TODO: Add Rights
|
|
|
|
//TODO: Database
|
2013-11-09 20:18:49 +01:00
|
|
|
$this->mc->client->query('GetDetailedPlayerInfo', $player[0]);
|
|
|
|
$this->addPlayer(new Player($this->mc->client->getResponse()));
|
2013-11-09 21:35:43 +01:00
|
|
|
$player = $this->playerList[$player[0]];
|
|
|
|
if($player->pid != 0){ //Player 0 = server
|
2013-11-09 23:01:54 +01:00
|
|
|
$string = array(0 => 'New Player', 1 => 'Operator', 2 => 'Admin', 3 => 'MasterAdmin', 4 => 'MasterAdmin');
|
|
|
|
$this->mc->chat->sendChat('$ff0'.$string[$player->rightLevel].': '. $player->nickname . '$z $ff0Nation:$fff ' . $player->nation . ' $ff0Ladder: $fff' . $player->ladderrank);
|
2013-11-09 21:35:43 +01:00
|
|
|
}
|
|
|
|
}
|
2013-11-09 22:08:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles a playerDisconnect
|
|
|
|
* @param $player
|
|
|
|
*/
|
|
|
|
public function playerDisconnect($player){
|
|
|
|
$player = $this->removePlayer($player[0]);
|
|
|
|
$played = TOOLS::formatTime(time() - $player->created);
|
|
|
|
$this->mc->chat->sendChat($player->nickname . '$z $ff0has left the game. Played:$fff ' . $played);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a Player from the Playerlist
|
|
|
|
* @param $login
|
|
|
|
* @return null
|
|
|
|
*/
|
|
|
|
public function getPlayer($login){
|
|
|
|
if (isset($this->playerList[$login]))
|
|
|
|
return $this->playerList[$login];
|
|
|
|
else
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-11-09 20:18:49 +01:00
|
|
|
/**
|
|
|
|
* Adds a player to the PlayerList
|
|
|
|
* @param Player $player
|
|
|
|
* @return bool
|
|
|
|
*/
|
2013-11-09 22:08:06 +01:00
|
|
|
private function addPlayer(Player $player){
|
2013-11-09 20:18:49 +01:00
|
|
|
if($player != null){
|
2013-11-09 21:35:43 +01:00
|
|
|
$this->playerList[$player->login] = $player;
|
2013-11-09 20:18:49 +01:00
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2013-11-09 22:08:06 +01:00
|
|
|
/**
|
|
|
|
* Removes a Player from the PlayerList
|
|
|
|
* @param $login
|
|
|
|
* @return Player $player
|
|
|
|
*/
|
|
|
|
private function removePlayer($login){
|
|
|
|
if(isset($this->playerList[$login])){
|
|
|
|
$player = $this->playerList[$login];
|
|
|
|
unset($this->playerList[$login]);
|
|
|
|
} else {
|
|
|
|
$player = null;
|
|
|
|
}
|
|
|
|
return $player;
|
|
|
|
}
|
2013-11-09 20:18:49 +01:00
|
|
|
}
|