player actions and commands improved
This commit is contained in:
parent
50906f1856
commit
ae8dc2aed5
@ -22,8 +22,8 @@ class PlayerActions {
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
const BLUE_TEAM = 0;
|
||||
const RED_TEAM = 1;
|
||||
const TEAM_BLUE = 0;
|
||||
const TEAM_RED = 1;
|
||||
const SPECTATOR_USER_SELECTABLE = 0;
|
||||
const SPECTATOR_SPECTATOR = 1;
|
||||
const SPECTATOR_PLAYER = 2;
|
||||
@ -43,6 +43,33 @@ class PlayerActions {
|
||||
$this->maniaControl = $maniaControl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force a Player to Play
|
||||
*
|
||||
* @param string $adminLogin
|
||||
* @param string $targetLogin
|
||||
* @param int $type
|
||||
*/
|
||||
public function forcePlayerToPlay($adminLogin, $targetLogin, $type = 2) {
|
||||
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
|
||||
if (!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
|
||||
return;
|
||||
}
|
||||
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
|
||||
if (!$target) return;
|
||||
|
||||
$success = $this->maniaControl->client->query('ForceSpectator', $target->login, ($type != 1 ? 0 : 2));
|
||||
if (!$success) {
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
|
||||
return;
|
||||
}
|
||||
|
||||
// Announce force
|
||||
$chatMessage = '$<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> to Play!';
|
||||
$this->maniaControl->chat->sendInformation($chatMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force a Player to a certain Team
|
||||
*
|
||||
@ -51,10 +78,13 @@ class PlayerActions {
|
||||
* @param int $teamId
|
||||
*/
|
||||
public function forcePlayerToTeam($adminLogin, $targetLogin, $teamId) {
|
||||
// TODO: get used by playercommands
|
||||
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
|
||||
if (!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
|
||||
return;
|
||||
}
|
||||
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
|
||||
if (!$admin || !$target) return;
|
||||
if (!$target) return;
|
||||
|
||||
if ($target->isSpectator) {
|
||||
$success = $this->maniaControl->client->query('ForceSpectator', $target->login, self::SPECTATOR_PLAYER);
|
||||
@ -72,10 +102,10 @@ class PlayerActions {
|
||||
|
||||
$chatMessage = false;
|
||||
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
|
||||
if ($teamId == self::BLUE_TEAM) {
|
||||
if ($teamId == self::TEAM_BLUE) {
|
||||
$chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Blue-Team!';
|
||||
}
|
||||
else if ($teamId == self::RED_TEAM) {
|
||||
else if ($teamId == self::TEAM_RED) {
|
||||
$chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Red-Team!';
|
||||
}
|
||||
if (!$chatMessage) return;
|
||||
@ -92,7 +122,6 @@ class PlayerActions {
|
||||
* @param bool $releaseSlot
|
||||
*/
|
||||
public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE, $releaseSlot = true) {
|
||||
// TODO: get used by playercommands
|
||||
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
|
||||
if (!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
|
||||
|
@ -44,8 +44,9 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
|
||||
$this->maniaControl->commandManager->registerCommandListener('kick', $this, 'command_Kick', true);
|
||||
$this->maniaControl->commandManager->registerCommandListener('forcespec', $this, 'command_ForceSpectator', true);
|
||||
$this->maniaControl->commandManager->registerCommandListener('forcespectator', $this, 'command_ForceSpectator', true);
|
||||
$this->maniaControl->commandManager->registerCommandListener('forceplay', $this, 'command_ForcePlayer', true);
|
||||
$this->maniaControl->commandManager->registerCommandListener('forceplayer', $this, 'command_ForcePlayer', true);
|
||||
$this->maniaControl->commandManager->registerCommandListener('forceplay', $this, 'command_ForcePlay', true);
|
||||
$this->maniaControl->commandManager->registerCommandListener('forceblue', $this, 'command_ForceBlue', true);
|
||||
$this->maniaControl->commandManager->registerCommandListener('forcered', $this, 'command_ForceRed', true);
|
||||
$this->maniaControl->commandManager->registerCommandListener('addbot', $this, 'command_AddFakePlayers', true);
|
||||
$this->maniaControl->commandManager->registerCommandListener('removebot', $this, 'command_RemoveFakePlayers', true);
|
||||
$this->maniaControl->commandManager->registerCommandListener('addbots', $this, 'command_AddFakePlayers', true);
|
||||
@ -192,35 +193,65 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_ForcePlayer(array $chat, Player $player) {
|
||||
public function command_ForcePlay(array $chat, Player $player) {
|
||||
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
$params = explode(' ', $chat[1][2]);
|
||||
if (!isset($params[1])) {
|
||||
$this->maniaControl->chat->sendUsageInfo('Usage example: //forceplay login', $player->login);
|
||||
return;
|
||||
}
|
||||
$target = $params[1];
|
||||
$target = $this->maniaControl->playerManager->getPlayer($target);
|
||||
if (!$target) {
|
||||
$this->maniaControl->chat->sendError("Invalid player login.", $player->login);
|
||||
$this->maniaControl->chat->sendUsageInfo("No Login given! Example: '//forceplay login'", $player->login);
|
||||
return;
|
||||
}
|
||||
$targetLogin = $params[1];
|
||||
|
||||
$type = 2;
|
||||
if (isset($params[2]) && is_numeric($params[2])) {
|
||||
$type = intval($params[2]);
|
||||
}
|
||||
$success = $this->maniaControl->client->query('ForceSpectator', $target->login, 2);
|
||||
if (!$success) {
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
|
||||
$this->maniaControl->playerManager->playerActions->forcePlayerToPlay($player->login, $targetLogin, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle //forceblue command
|
||||
*
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_ForceBlue(array $chat, Player $player) {
|
||||
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
if ($type != 1) {
|
||||
$this->maniaControl->client->query('ForceSpectator', $target->login, 0);
|
||||
$params = explode(' ', $chat[1][2]);
|
||||
if (!isset($params[1])) {
|
||||
$this->maniaControl->chat->sendUsageInfo("No Login given! Example: '//forceblue login'", $player->login);
|
||||
return;
|
||||
}
|
||||
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> forced $<' . $target->nickname . '$> to player!');
|
||||
$targetLogin = $params[1];
|
||||
|
||||
$this->maniaControl->playerManager->playerActions->forcePlayerToTeam($player->login, $targetLogin, PlayerActions::TEAM_BLUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle //forcered command
|
||||
*
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
*/
|
||||
public function command_ForceRed(array $chat, Player $player) {
|
||||
if (!$this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
$params = explode(' ', $chat[1][2]);
|
||||
if (!isset($params[1])) {
|
||||
$this->maniaControl->chat->sendUsageInfo("No Login given! Example: '//forcered login'", $player->login);
|
||||
return;
|
||||
}
|
||||
$targetLogin = $params[1];
|
||||
|
||||
$this->maniaControl->playerManager->playerActions->forcePlayerToTeam($player->login, $targetLogin, PlayerActions::TEAM_RED);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user