improved player actions

This commit is contained in:
kremsy 2013-12-23 21:47:39 +01:00
parent 28a9054c0d
commit b72e036cf7
4 changed files with 85 additions and 21 deletions

View File

@ -3,6 +3,7 @@
namespace ManiaControl\Players; namespace ManiaControl\Players;
use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
class PlayerActions { class PlayerActions {
@ -28,32 +29,97 @@ class PlayerActions {
/** /**
* Forces a Player to a certain team * Forces a Player to a certain team
* @param $adminLogin * @param $adminLogin
* @param $login * @param $targetLogin
* @param $teamId * @param $teamId
*/ */
public function forcePlayerToTeam($adminLogin, $login, $teamId){ public function forcePlayerToTeam($adminLogin, $targetLogin, $teamId){ //TODO get used by playercommands
$this->maniaControl->client->query('ForcePlayerTeam', $login, $teamId); //TODO bestätigung und chatnachricht $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
if($target->isSpectator){
$success = $this->maniaControl->client->query('ForceSpectator', $targetLogin, self::SPECTATOR_PLAYER);
if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return;
}
}
$success = $this->maniaControl->client->query('ForcePlayerTeam', $targetLogin, $teamId); //TODO bestätigung und chatnachricht
if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return;
}
if($teamId == self::BLUE_TEAM)
$this->maniaControl->chat->sendInformation('$<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Blue-Team!');
else if($teamId == self::RED_TEAM)
$this->maniaControl->chat->sendInformation('$<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Red-Team!');
} }
/** /**
* Forces a Player to spectator * Forces a Player to spectator
* @param $adminLogin * @param $adminLogin
* @param $login * @param $targetLogin
* @param int $spectatorState * @param int $spectatorState
*/ */
public function forcePlayerToSpectator($adminLogin, $login, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE){ public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE){ //TODO get used by playercommands
$this->maniaControl->client->query('ForceSpectator', $login, $spectatorState); //TODO bestätigung und chatnachricht $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$success = $this->maniaControl->client->query('ForceSpectator', $targetLogin, $spectatorState); //TODO bestätigung und chatnachricht
if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return;
}
$this->maniaControl->chat->sendInformation('$<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> to spectator!'); //TODO add admin title
} }
/**
* Warn a Player
* @param $adminLogin
* @param $login
* @param string $message
*/
public function warnPlayer($adminLogin, $login, $message = ''){ public function warnPlayer($adminLogin, $login, $message = ''){
} }
public function kickPlayer($adminLogin, $login, $message = ''){
/**
* Kicks a Player
* @param $adminLogin
* @param $targetLogin
* @param string $message
*/
public function kickPlayer($adminLogin, $targetLogin, $message = ''){
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$success = $this->maniaControl->client->query('Kick', $target->login, $message); //TODO bestätigung und chatnachricht
if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return;
}
$this->maniaControl->chat->sendInformation('$<' . $admin->nickname . '$> kicked $<' . $target->nickname . '$>!'); //TODO add admin title
} }
public function banPlayer($adminLogin, $login, $message = ''){ /**
* Bans a Player
* @param $adminLogin
* @param $targetLogin
* @param string $message
*/
public function banPlayer($adminLogin, $targetLogin, $message = ''){
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$success = $this->maniaControl->client->query('Ban', $target->login, $message); //TODO bestätigung und chatnachricht
if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return;
}
$this->maniaControl->chat->sendInformation('$<' . $admin->nickname . '$> banned $<' . $target->nickname . '$>!'); //TODO add admin title
} }
} }

View File

@ -92,12 +92,8 @@ class PlayerCommands implements CommandListener {
if (isset($params[2])) { if (isset($params[2])) {
$message = $params[2]; $message = $params[2];
} }
$success = $this->maniaControl->client->query('Kick', $target->login, $message);
if (!$success) { $this->maniaControl->playerManager->playerActions->kickPlayer($player->login, $target, $message);
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
return;
}
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> kicked $<' . $target->nickname . '$>!');
} }
/** /**

View File

@ -38,12 +38,12 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener {
const ACTION_PLAYER_ADV = 'PlayerList.PlayerAdvancedActions'; const ACTION_PLAYER_ADV = 'PlayerList.PlayerAdvancedActions';
const ACTION_CLOSE_PLAYER_ADV = 'PlayerList.ClosePlayerAdvWidget'; const ACTION_CLOSE_PLAYER_ADV = 'PlayerList.ClosePlayerAdvWidget';
const ACTION_WARN_PLAYER = ' PlayerList.WarnPlayer'; const ACTION_WARN_PLAYER = 'PlayerList.WarnPlayer';
const ACTION_KICK_PLAYER = ' PlayerList.KickPlayer'; const ACTION_KICK_PLAYER = 'PlayerList.KickPlayer';
const ACTION_BAN_PLAYER = ' PlayerList.BanPlayer'; const ACTION_BAN_PLAYER = 'PlayerList.BanPlayer';
const ACTION_ADD_AS_MASTER = ' PlayerList.PlayerAddAsMaster'; const ACTION_ADD_AS_MASTER = 'PlayerList.PlayerAddAsMaster';
const ACTION_ADD_AS_ADMIN = ' PlayerList.PlayerAddAsAdmin'; const ACTION_ADD_AS_ADMIN = 'PlayerList.PlayerAddAsAdmin';
const ACTION_ADD_AS_MOD = ' PlayerList.PlayerAddAsModerator'; const ACTION_ADD_AS_MOD = 'PlayerList.PlayerAddAsModerator';
/** /**
* Private properties * Private properties

View File

@ -176,8 +176,10 @@ class PlayerManager implements CallbackListener {
* @param array $callback * @param array $callback
*/ */
public function playerInfoChanged(array $callback){ public function playerInfoChanged(array $callback){
//TODO something on playerjoin not working here (maybe because it get called before player join
$player = $this->getPlayer($callback[1][0]['Login']); $player = $this->getPlayer($callback[1][0]['Login']);
if($player == null)
return;
$player->teamId = $callback[1][0]["TeamId"]; $player->teamId = $callback[1][0]["TeamId"];
$player->isSpectator = $callback[1][0]["SpectatorStatus"]; $player->isSpectator = $callback[1][0]["SpectatorStatus"];
$player->ladderRank = $callback[1][0]["LadderRanking"]; $player->ladderRank = $callback[1][0]["LadderRanking"];