2013-12-23 20:57:50 +01:00
< ? php
namespace ManiaControl\Players ;
2013-12-24 12:49:53 +01:00
use FML\Controls\Control ;
use FML\Controls\Frame ;
use FML\Controls\Labels\Label_Text ;
use FML\Controls\Quad ;
use FML\Controls\Quads\Quad_Icons64x64_1 ;
use FML\ManiaLink ;
2013-12-23 21:47:39 +01:00
use ManiaControl\Admin\AuthenticationManager ;
2013-12-24 12:49:53 +01:00
use ManiaControl\Formatter ;
2013-12-23 20:57:50 +01:00
use ManiaControl\ManiaControl ;
2013-12-24 12:49:53 +01:00
use ManiaControl\Manialinks\ManialinkManager ;
2013-12-23 20:57:50 +01:00
2013-12-24 13:09:39 +01:00
/**
* PlayerActions Class
*
* @ author steeffeen & kremsy
*/
2013-12-23 20:57:50 +01:00
class PlayerActions {
/**
* Constants
*/
2014-01-02 16:37:52 +01:00
const BLUE_TEAM = 0 ;
const RED_TEAM = 1 ;
const SPECTATOR_USER_SELECTABLE = 0 ;
const SPECTATOR_SPECTATOR = 1 ;
const SPECTATOR_PLAYER = 2 ;
2013-12-23 20:57:50 +01:00
const SPECTATOR_BUT_KEEP_SELECTABLE = 3 ;
2014-01-02 16:37:52 +01:00
2013-12-23 20:57:50 +01:00
/**
2013-12-31 16:01:22 +01:00
* Private Properties
2013-12-23 20:57:50 +01:00
*/
private $maniaControl = null ;
2013-12-31 16:01:22 +01:00
/**
* Create a PlayerActions Instance
*
* @ param ManiaControl $maniaControl
*/
2013-12-23 20:57:50 +01:00
public function __construct ( ManiaControl $maniaControl ) {
$this -> maniaControl = $maniaControl ;
}
/**
2013-12-31 16:01:22 +01:00
* Force a Player to a certain Team
*
* @ param string $adminLogin
* @ param string $targetLogin
2014-01-02 16:37:52 +01:00
* @ param int $teamId
2013-12-23 20:57:50 +01:00
*/
2013-12-31 16:01:22 +01:00
public function forcePlayerToTeam ( $adminLogin , $targetLogin , $teamId ) {
// TODO: get used by playercommands
2014-01-02 16:37:52 +01:00
$admin = $this -> maniaControl -> playerManager -> getPlayer ( $adminLogin );
2013-12-23 21:47:39 +01:00
$target = $this -> maniaControl -> playerManager -> getPlayer ( $targetLogin );
2014-01-02 16:37:52 +01:00
if ( ! $admin || ! $target ) {
return ;
}
2013-12-24 12:49:53 +01:00
$title = $this -> maniaControl -> authenticationManager -> getAuthLevelName ( $admin -> authLevel );
2014-01-02 16:37:52 +01:00
if ( $target -> isSpectator ) {
2013-12-31 16:01:22 +01:00
$success = $this -> maniaControl -> client -> query ( 'ForceSpectator' , $target -> login , self :: SPECTATOR_PLAYER );
2014-01-02 16:37:52 +01:00
if ( ! $success ) {
2013-12-23 21:47:39 +01:00
$this -> maniaControl -> chat -> sendError ( 'Error occurred: ' . $this -> maniaControl -> getClientErrorText (), $admin -> login );
return ;
}
}
2014-01-02 16:37:52 +01:00
2013-12-31 16:01:22 +01:00
$success = $this -> maniaControl -> client -> query ( 'ForcePlayerTeam' , $target -> login , $teamId );
2014-01-02 16:37:52 +01:00
if ( ! $success ) {
2013-12-23 21:47:39 +01:00
$this -> maniaControl -> chat -> sendError ( 'Error occurred: ' . $this -> maniaControl -> getClientErrorText (), $admin -> login );
return ;
}
2014-01-02 16:37:52 +01:00
2013-12-31 16:01:22 +01:00
$chatMessage = false ;
2014-01-02 16:37:52 +01:00
if ( $teamId == self :: BLUE_TEAM ) {
2013-12-31 16:01:22 +01:00
$chatMessage = $title . ' $<' . $admin -> nickname . '$> forced $<' . $target -> nickname . '$> into the Blue-Team!' ;
2014-01-02 16:37:52 +01:00
} else if ( $teamId == self :: RED_TEAM ) {
2013-12-31 16:01:22 +01:00
$chatMessage = $title . ' $<' . $admin -> nickname . '$> forced $<' . $target -> nickname . '$> into the Red-Team!' ;
2013-12-24 12:49:53 +01:00
}
2014-01-02 16:37:52 +01:00
if ( ! $chatMessage )
return ;
2013-12-31 16:01:22 +01:00
$this -> maniaControl -> chat -> sendInformation ( $chatMessage );
$this -> maniaControl -> log ( Formatter :: stripCodes ( $chatMessage ));
2013-12-23 20:57:50 +01:00
}
2014-01-02 16:37:52 +01:00
2013-12-23 20:57:50 +01:00
/**
2013-12-31 16:01:22 +01:00
* Force a Player to Spectator
*
* @ param string $adminLogin
* @ param string $targetLogin
2014-01-02 16:37:52 +01:00
* @ param int $spectatorState
2013-12-23 20:57:50 +01:00
*/
2013-12-31 16:01:22 +01:00
public function forcePlayerToSpectator ( $adminLogin , $targetLogin , $spectatorState = self :: SPECTATOR_BUT_KEEP_SELECTABLE ) {
// TODO: get used by playercommands
2014-01-02 16:37:52 +01:00
$admin = $this -> maniaControl -> playerManager -> getPlayer ( $adminLogin );
2013-12-23 21:47:39 +01:00
$target = $this -> maniaControl -> playerManager -> getPlayer ( $targetLogin );
2014-01-02 16:37:52 +01:00
$title = $this -> maniaControl -> authenticationManager -> getAuthLevelName ( $admin -> authLevel );
2013-12-31 16:01:22 +01:00
$success = $this -> maniaControl -> client -> query ( 'ForceSpectator' , $targetLogin , $spectatorState );
2014-01-02 16:37:52 +01:00
if ( ! $success ) {
2013-12-23 21:47:39 +01:00
$this -> maniaControl -> chat -> sendError ( 'Error occurred: ' . $this -> maniaControl -> getClientErrorText (), $admin -> login );
return ;
}
2014-01-02 16:37:52 +01:00
2013-12-31 16:01:22 +01:00
$chatMessage = $title . ' $<' . $admin -> nickname . '$> forced $<' . $target -> nickname . '$> to Spectator!' ;
$this -> maniaControl -> chat -> sendInformation ( $chatMessage );
$this -> maniaControl -> log ( Formatter :: stripCodes ( $chatMessage ));
2013-12-23 20:57:50 +01:00
}
2014-01-02 16:37:52 +01:00
/**
* UnMutes a Player
*
* @ param string $adminLogin
* @ param string $targetLogin
* @ param int $spectatorState
*/
public function unMutePlayer ( $adminLogin , $targetLogin ) {
// TODO: playercommand
$admin = $this -> maniaControl -> playerManager -> getPlayer ( $adminLogin );
$target = $this -> maniaControl -> playerManager -> getPlayer ( $targetLogin );
$title = $this -> maniaControl -> authenticationManager -> getAuthLevelName ( $admin -> authLevel );
$success = $this -> maniaControl -> client -> query ( 'UnIgnore' , $targetLogin );
var_dump ( $success );
var_dump ( $this -> maniaControl -> client -> getResponse ());
if ( ! $success ) {
$this -> maniaControl -> chat -> sendError ( 'Error occurred: ' . $this -> maniaControl -> getClientErrorText (), $admin -> login );
return ;
}
$chatMessage = $title . ' $<' . $admin -> nickname . '$> un-muted $<' . $target -> nickname . '$>!' ;
$this -> maniaControl -> chat -> sendInformation ( $chatMessage );
$this -> maniaControl -> log ( Formatter :: stripCodes ( $chatMessage ));
}
/**
* Mutes a Player
*
* @ param string $adminLogin
* @ param string $targetLogin
* @ param int $spectatorState
*/
public function mutePlayer ( $adminLogin , $targetLogin ) {
// TODO: playercommand
$admin = $this -> maniaControl -> playerManager -> getPlayer ( $adminLogin );
$target = $this -> maniaControl -> playerManager -> getPlayer ( $targetLogin );
$title = $this -> maniaControl -> authenticationManager -> getAuthLevelName ( $admin -> authLevel );
$success = $this -> maniaControl -> client -> query ( 'Ignore' , $targetLogin );
if ( ! $success ) {
$this -> maniaControl -> chat -> sendError ( 'Error occurred: ' . $this -> maniaControl -> getClientErrorText (), $admin -> login );
return ;
}
$chatMessage = $title . ' $<' . $admin -> nickname . '$> muted $<' . $target -> nickname . '$>!' ;
$this -> maniaControl -> chat -> sendInformation ( $chatMessage );
$this -> maniaControl -> log ( Formatter :: stripCodes ( $chatMessage ));
}
2013-12-23 21:47:39 +01:00
/**
* Warn a Player
2013-12-31 16:01:22 +01:00
*
* @ param string $adminLogin
* @ param string $targetLogin
2013-12-23 21:47:39 +01:00
*/
2013-12-31 16:01:22 +01:00
public function warnPlayer ( $adminLogin , $targetLogin ) {
// TODO: chatcommand
2014-01-02 16:37:52 +01:00
$admin = $this -> maniaControl -> playerManager -> getPlayer ( $adminLogin );
2013-12-24 12:49:53 +01:00
$target = $this -> maniaControl -> playerManager -> getPlayer ( $targetLogin );
2014-01-02 16:37:52 +01:00
$title = $this -> maniaControl -> authenticationManager -> getAuthLevelName ( $admin -> authLevel );
2013-12-24 12:49:53 +01:00
// display warning message
$message = ' $s $f00This is an administrative warning . { br }{ br } $gWhatever you wrote or you have done is against { br } our server\ ' s policy .
{ br } Not respecting other players , or { br } using offensive language might result in a { br } $f00kick , or ban $ff0the next time .
{ br }{ br } $gThe server administrators . ' ;
$message = preg_split ( '/{br}/' , $message );
2014-01-02 16:37:52 +01:00
$width = 80 ;
$height = 50 ;
$quadStyle = $this -> maniaControl -> manialinkManager -> styleManager -> getDefaultMainWindowStyle ();
2013-12-29 10:19:39 +01:00
$quadSubstyle = $this -> maniaControl -> manialinkManager -> styleManager -> getDefaultMainWindowSubStyle ();
2014-01-02 16:37:52 +01:00
2013-12-24 12:49:53 +01:00
$maniaLink = new ManiaLink ( ManialinkManager :: MAIN_MLID );
2014-01-02 16:37:52 +01:00
2013-12-31 16:01:22 +01:00
// mainframe
2013-12-24 12:49:53 +01:00
$frame = new Frame ();
$maniaLink -> add ( $frame );
2013-12-31 16:01:22 +01:00
$frame -> setSize ( $width , $height );
2013-12-24 12:49:53 +01:00
$frame -> setPosition ( 0 , 10 );
2014-01-02 16:37:52 +01:00
2013-12-31 16:01:22 +01:00
// Background Quad
2013-12-24 12:49:53 +01:00
$backgroundQuad = new Quad ();
$frame -> add ( $backgroundQuad );
2013-12-31 16:01:22 +01:00
$backgroundQuad -> setSize ( $width , $height );
2013-12-24 12:49:53 +01:00
$backgroundQuad -> setStyles ( $quadStyle , $quadSubstyle );
2014-01-02 16:37:52 +01:00
2013-12-24 12:49:53 +01:00
// Add Close Quad (X)
$closeQuad = new Quad_Icons64x64_1 ();
$frame -> add ( $closeQuad );
$closeQuad -> setPosition ( $width * 0.473 , $height * 0.457 , 3 );
$closeQuad -> setSize ( 6 , 6 );
$closeQuad -> setSubStyle ( Quad_Icons64x64_1 :: SUBSTYLE_QuitRace );
$closeQuad -> setAction ( ManialinkManager :: ACTION_CLOSEWIDGET );
2014-01-02 16:37:52 +01:00
2013-12-31 16:01:22 +01:00
// Headline Label
2013-12-24 12:49:53 +01:00
$label = new Label_Text ();
$frame -> add ( $label );
$label -> setHAlign ( Control :: CENTER );
$label -> setX ( 0 );
$label -> setY ( $height / 2 - 5 );
$label -> setStyle ( Label_Text :: STYLE_TextCardMedium );
$label -> setTextSize ( 4 );
$label -> setText ( 'Administrative Warning' );
$label -> setTextColor ( 'F00' );
2014-01-02 16:37:52 +01:00
2013-12-24 12:49:53 +01:00
$y = $height / 2 - 15 ;
2014-01-02 16:37:52 +01:00
foreach ( $message as & $line ) {
2013-12-31 16:01:22 +01:00
// Warn Labels
2013-12-24 12:49:53 +01:00
$label = new Label_Text ();
$frame -> add ( $label );
$label -> setHAlign ( Control :: CENTER );
2013-12-31 16:01:22 +01:00
// $label->setX(-$width / 2 + 5);
2013-12-24 12:49:53 +01:00
$label -> setX ( 0 );
$label -> setY ( $y );
$label -> setStyle ( Label_Text :: STYLE_TextCardMedium );
$label -> setTextSize ( 1.6 );
$label -> setText ( $line );
$label -> setTextColor ( 'FF0' );
$y -= 4 ;
}
2014-01-02 16:37:52 +01:00
2013-12-31 16:01:22 +01:00
// Display manialink
2013-12-24 12:49:53 +01:00
$this -> maniaControl -> manialinkManager -> displayWidget ( $maniaLink , $target );
2014-01-02 16:37:52 +01:00
2013-12-31 16:01:22 +01:00
$chatMessage = $title . ' $<' . $admin -> nickname . '$> warned $<' . $target -> nickname . '$>!' ;
$this -> maniaControl -> chat -> sendInformation ( $chatMessage );
$this -> maniaControl -> log ( Formatter :: stripCodes ( $chatMessage ));
2013-12-23 20:57:50 +01:00
}
2013-12-23 21:47:39 +01:00
/**
* Kicks a Player
2013-12-31 16:01:22 +01:00
*
* @ param string $adminLogin
* @ param string $targetLogin
2013-12-23 21:47:39 +01:00
* @ param string $message
*/
2013-12-31 16:01:22 +01:00
public function kickPlayer ( $adminLogin , $targetLogin , $message = '' ) {
2014-01-02 16:37:52 +01:00
$admin = $this -> maniaControl -> playerManager -> getPlayer ( $adminLogin );
2013-12-23 21:47:39 +01:00
$target = $this -> maniaControl -> playerManager -> getPlayer ( $targetLogin );
2014-01-02 16:37:52 +01:00
$title = $this -> maniaControl -> authenticationManager -> getAuthLevelName ( $admin -> authLevel );
if ( $target -> isFakePlayer ()) {
2013-12-29 13:18:27 +01:00
$success = $this -> maniaControl -> client -> query ( 'DisconnectFakePlayer' , $target -> login );
2014-01-02 16:37:52 +01:00
} else {
2013-12-31 16:01:22 +01:00
$success = $this -> maniaControl -> client -> query ( 'Kick' , $target -> login , $message );
}
2014-01-02 16:37:52 +01:00
if ( ! $success ) {
2013-12-23 21:47:39 +01:00
$this -> maniaControl -> chat -> sendError ( 'Error occurred: ' . $this -> maniaControl -> getClientErrorText (), $admin -> login );
return ;
}
2014-01-02 16:37:52 +01:00
2013-12-31 16:01:22 +01:00
$chatMessage = $title . ' $<' . $admin -> nickname . '$> kicked $<' . $target -> nickname . '$>!' ;
$this -> maniaControl -> chat -> sendInformation ( $chatMessage );
$this -> maniaControl -> log ( Formatter :: stripCodes ( $chatMessage ));
2013-12-23 20:57:50 +01:00
}
2013-12-23 21:47:39 +01:00
/**
* Bans a Player
2013-12-31 16:01:22 +01:00
*
* @ param string $adminLogin
* @ param string $targetLogin
2013-12-23 21:47:39 +01:00
* @ param string $message
*/
2013-12-31 16:01:22 +01:00
public function banPlayer ( $adminLogin , $targetLogin , $message = '' ) {
2014-01-02 16:37:52 +01:00
$admin = $this -> maniaControl -> playerManager -> getPlayer ( $adminLogin );
2013-12-23 21:47:39 +01:00
$target = $this -> maniaControl -> playerManager -> getPlayer ( $targetLogin );
2014-01-02 16:37:52 +01:00
$title = $this -> maniaControl -> authenticationManager -> getAuthLevelName ( $admin -> authLevel );
2013-12-31 16:50:05 +01:00
$success = $this -> maniaControl -> client -> query ( 'Ban' , $target -> login , $message );
2014-01-02 16:37:52 +01:00
if ( ! $success ) {
2013-12-23 21:47:39 +01:00
$this -> maniaControl -> chat -> sendError ( 'Error occurred: ' . $this -> maniaControl -> getClientErrorText (), $admin -> login );
return ;
}
2014-01-02 16:37:52 +01:00
2013-12-31 16:01:22 +01:00
$chatMessage = $title . ' $<' . $admin -> nickname . '$> banned $<' . $target -> nickname . '$>!' ;
$this -> maniaControl -> chat -> sendInformation ( $chatMessage );
$this -> maniaControl -> log ( Formatter :: stripCodes ( $chatMessage ));
2013-12-23 20:57:50 +01:00
}
2013-12-26 11:25:10 +01:00
/**
2013-12-31 16:01:22 +01:00
* Grands the Player an Authorization Level
*
* @ param string $adminLogin
* @ param string $targetLogin
2014-01-02 16:37:52 +01:00
* @ param int $authLevel
2013-12-26 11:25:10 +01:00
*/
2013-12-31 16:01:22 +01:00
public function grandAuthLevel ( $adminLogin , $targetLogin , $authLevel ) {
2014-01-02 16:37:52 +01:00
$admin = $this -> maniaControl -> playerManager -> getPlayer ( $adminLogin );
2013-12-26 11:25:10 +01:00
$target = $this -> maniaControl -> playerManager -> getPlayer ( $targetLogin );
2014-01-02 16:37:52 +01:00
$title = $this -> maniaControl -> authenticationManager -> getAuthLevelName ( $admin -> authLevel );
if ( $this -> maniaControl -> authenticationManager -> checkRight ( $target , $authLevel )) {
$this -> maniaControl -> chat -> sendError ( 'This Player is already ' . $this -> maniaControl -> authenticationManager -> getAuthLevelName ( $target -> authLevel ), $admin -> login );
2013-12-26 11:25:10 +01:00
return ;
}
2014-01-02 16:37:52 +01:00
2013-12-30 22:36:20 +01:00
$authLevelName = $this -> maniaControl -> authenticationManager -> getAuthLevelName ( $authLevel );
2014-01-02 16:37:52 +01:00
if ( $this -> maniaControl -> authenticationManager -> checkRight ( $admin , $authLevel ) <= $this -> maniaControl -> authenticationManager -> checkRight ( $target , $authLevel )) {
2013-12-30 22:36:20 +01:00
$this -> maniaControl -> chat -> sendError ( 'You don\'t have the permission to add a ' . $authLevelName . '!' , $admin -> login );
return ;
}
2014-01-02 16:37:52 +01:00
2013-12-26 11:25:10 +01:00
$success = $this -> maniaControl -> authenticationManager -> grantAuthLevel ( $target , $authLevel );
2014-01-02 16:37:52 +01:00
if ( ! $success ) {
2013-12-26 11:25:10 +01:00
$this -> maniaControl -> chat -> sendError ( 'Error occurred: ' . $this -> maniaControl -> getClientErrorText (), $admin -> login );
return ;
}
2014-01-02 16:37:52 +01:00
2013-12-31 16:01:22 +01:00
$chatMessage = $title . ' $<' . $admin -> nickname . '$> added $<' . $target -> nickname . '$> as $< ' . $authLevelName . '$>!' ;
$this -> maniaControl -> chat -> sendInformation ( $chatMessage );
$this -> maniaControl -> log ( Formatter :: stripCodes ( $chatMessage ));
2013-12-26 11:25:10 +01:00
}
/**
2013-12-31 16:01:22 +01:00
* Revokes all Rights from the Player
*
* @ param string $adminLogin
* @ param string $targetLogin
2013-12-26 11:25:10 +01:00
*/
2013-12-31 16:01:22 +01:00
public function revokeAuthLevel ( $adminLogin , $targetLogin ) {
2014-01-02 16:37:52 +01:00
$admin = $this -> maniaControl -> playerManager -> getPlayer ( $adminLogin );
2013-12-26 11:25:10 +01:00
$target = $this -> maniaControl -> playerManager -> getPlayer ( $targetLogin );
2014-01-02 16:37:52 +01:00
$title = $this -> maniaControl -> authenticationManager -> getAuthLevelName ( $admin -> authLevel );
if ( $this -> maniaControl -> authenticationManager -> checkRight ( $target , AuthenticationManager :: AUTH_LEVEL_MASTERADMIN )) {
2013-12-26 11:25:10 +01:00
$this -> maniaControl -> chat -> sendError ( 'MasterAdmins can\'t be removed ' , $admin -> login );
return ;
}
2014-01-02 16:37:52 +01:00
2013-12-26 11:25:10 +01:00
$success = $this -> maniaControl -> authenticationManager -> grantAuthLevel ( $target , AuthenticationManager :: AUTH_LEVEL_PLAYER );
2014-01-02 16:37:52 +01:00
if ( ! $success ) {
2013-12-26 11:25:10 +01:00
$this -> maniaControl -> chat -> sendError ( 'Error occurred: ' . $this -> maniaControl -> getClientErrorText (), $admin -> login );
return ;
}
2014-01-02 16:37:52 +01:00
2013-12-31 16:01:22 +01:00
$chatMessage = $title . ' $<' . $admin -> nickname . '$> revokes the Rights of $<' . $target -> nickname . '$>!' ;
$this -> maniaControl -> chat -> sendInformation ( $chatMessage );
$this -> maniaControl -> log ( Formatter :: stripCodes ( $chatMessage ));
2013-12-26 11:25:10 +01:00
}
2014-01-02 16:37:52 +01:00
/**
* Checks if a Player is Muted
*
* @ param $login
* @ return bool
*/
public function isPlayerMuted ( $login ) {
$this -> maniaControl -> client -> query ( 'GetIgnoreList' , 100 , 0 );
foreach ( $this -> maniaControl -> client -> getResponse () as $ignoredPlayers ) {
if ( $ignoredPlayers [ " Login " ] == $login )
return true ;
}
return false ;
}
2013-12-31 16:01:22 +01:00
}