TrackManiaControl/application/core/Players/PlayerActions.php

125 lines
4.3 KiB
PHP
Raw Normal View History

2013-12-23 20:57:50 +01:00
<?php
namespace ManiaControl\Players;
2013-12-23 21:47:39 +01:00
use ManiaControl\Admin\AuthenticationManager;
2013-12-23 20:57:50 +01:00
use ManiaControl\ManiaControl;
class PlayerActions {
/**
* Constants
*/
const BLUE_TEAM = 0;
const RED_TEAM = 1;
const SPECTATOR_USER_SELECTABLE = 0;
const SPECTATOR_SPECTATOR = 1;
const SPECTATOR_PLAYER = 2;
const SPECTATOR_BUT_KEEP_SELECTABLE = 3;
/**
* Private properties
*/
private $maniaControl = null;
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
}
/**
* Forces a Player to a certain team
* @param $adminLogin
2013-12-23 21:47:39 +01:00
* @param $targetLogin
2013-12-23 20:57:50 +01:00
* @param $teamId
*/
2013-12-23 21:47:39 +01:00
public function forcePlayerToTeam($adminLogin, $targetLogin, $teamId){ //TODO get used by playercommands
$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!');
2013-12-23 20:57:50 +01:00
}
/**
* Forces a Player to spectator
* @param $adminLogin
2013-12-23 21:47:39 +01:00
* @param $targetLogin
2013-12-23 20:57:50 +01:00
* @param int $spectatorState
*/
2013-12-23 21:47:39 +01:00
public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE){ //TODO get used by playercommands
$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
2013-12-23 20:57:50 +01:00
}
2013-12-23 21:47:39 +01:00
/**
* Warn a Player
* @param $adminLogin
* @param $login
* @param string $message
*/
2013-12-23 20:57:50 +01:00
public function warnPlayer($adminLogin, $login, $message = ''){
}
2013-12-23 21:47:39 +01:00
/**
* 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
2013-12-23 20:57:50 +01:00
}
2013-12-23 21:47:39 +01:00
/**
* 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
2013-12-23 20:57:50 +01:00
2013-12-23 21:47:39 +01:00
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
2013-12-23 20:57:50 +01:00
}
}