2014-05-03 21:57:38 +02:00
< ? php
namespace MCTeam ;
use ManiaControl\Commands\CommandListener ;
use ManiaControl\ManiaControl ;
use ManiaControl\Players\Player ;
use ManiaControl\Plugins\Plugin ;
2014-06-23 23:08:08 +02:00
use Maniaplanet\DedicatedServer\Xmlrpc\PlayerStateException ;
2014-05-13 17:59:37 +02:00
use Maniaplanet\DedicatedServer\Xmlrpc\UnknownPlayerException ;
2014-05-03 21:57:38 +02:00
/**
* ManiaControl Chat - Message Plugin
*
2014-05-03 23:49:58 +02:00
* @ author ManiaControl Team < mail @ maniacontrol . com >
2014-05-03 21:57:38 +02:00
* @ copyright 2014 ManiaControl Team
* @ license http :// www . gnu . org / licenses / GNU General Public License , Version 3
*/
class ChatMessagePlugin implements CommandListener , Plugin {
2014-05-03 23:49:58 +02:00
/*
2014-05-03 21:57:38 +02:00
* Constants
*/
const PLUGIN_ID = 4 ;
const PLUGIN_VERSION = 0.1 ;
const PLUGIN_NAME = 'ChatMessagePlugin' ;
const PLUGIN_AUTHOR = 'kremsy' ;
const SETTING_AFK_FORCE_SPEC = 'AFK command forces spec' ;
2014-05-03 23:49:58 +02:00
/*
2014-08-02 22:31:46 +02:00
* Private properties
2014-05-03 21:57:38 +02:00
*/
2014-05-03 23:49:58 +02:00
/** @var ManiaControl $maniaControl */
2014-05-03 21:57:38 +02:00
private $maniaControl = null ;
/**
2014-05-03 23:49:58 +02:00
* @ see \ManiaControl\Plugins\Plugin :: prepare ()
2014-05-03 21:57:38 +02:00
*/
public static function prepare ( ManiaControl $maniaControl ) {
}
/**
2014-05-03 23:49:58 +02:00
* @ see \ManiaControl\Plugins\Plugin :: getId ()
2014-05-03 21:57:38 +02:00
*/
public static function getId () {
return self :: PLUGIN_ID ;
}
/**
2014-05-03 23:49:58 +02:00
* @ see \ManiaControl\Plugins\Plugin :: getName ()
2014-05-03 21:57:38 +02:00
*/
public static function getName () {
return self :: PLUGIN_NAME ;
}
/**
2014-05-03 23:49:58 +02:00
* @ see \ManiaControl\Plugins\Plugin :: getVersion ()
2014-05-03 21:57:38 +02:00
*/
public static function getVersion () {
return self :: PLUGIN_VERSION ;
}
/**
2014-05-03 23:49:58 +02:00
* @ see \ManiaControl\Plugins\Plugin :: getAuthor ()
2014-05-03 21:57:38 +02:00
*/
public static function getAuthor () {
return self :: PLUGIN_AUTHOR ;
}
/**
2014-05-03 23:49:58 +02:00
* @ see \ManiaControl\Plugins\Plugin :: getDescription ()
2014-05-03 21:57:38 +02:00
*/
public static function getDescription () {
return " Plugin offers various Chat-Commands like /gg /hi /afk /rq... " ;
}
/**
2014-05-03 23:49:58 +02:00
* @ see \ManiaControl\Plugins\Plugin :: load ()
2014-05-03 21:57:38 +02:00
*/
public function load ( ManiaControl $maniaControl ) {
$this -> maniaControl = $maniaControl ;
2014-08-03 01:34:18 +02:00
// Chat commands
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( 'me' , $this , 'chat_me' , false , 'Can be used to express your feelings/ideas.' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( 'hi' , $this , 'chat_hi' , false , 'Writes an hello message to the chat.' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( array ( 'bb' , 'bye' ), $this , 'chat_bye' , false , 'Writes a goodbye message to the chat.' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( 'thx' , $this , 'chat_thx' , false , 'Writes a thanks message to the chat.' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( 'gg' , $this , 'chat_gg' , false , 'Writes a good game message to the chat.' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( 'gl' , $this , 'chat_gl' , false , 'Writes a good luck message to the chat.' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( 'hf' , $this , 'chat_hf' , false , 'Writes an have fun message to the chat.' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( 'glhf' , $this , 'chat_glhf' , false , 'Writes a good luck, have fun message to the chat.' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( 'ns' , $this , 'chat_ns' , false , 'Writes a nice shot message to the chat.' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( 'n1' , $this , 'chat_n1' , false , 'Writes a nice one message to the chat.' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( 'lol' , $this , 'chat_lol' , false , 'Writes a lol message to the chat.' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( 'lool' , $this , 'chat_lool' , false , 'Writes a lool message to the chat.' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( 'brb' , $this , 'chat_brb' , false , 'Writes a be right back message to the chat.' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( 'bgm' , $this , 'chat_bgm' , false , 'Writes a bad game for me message to the chat.' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( 'afk' , $this , 'chat_afk' , false , 'Writes an away from keyboard message to the chat.' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( array ( 'bm' , 'bootme' ), $this , 'chat_bootme' , false , 'Gets you away from this server quickly!' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( array ( 'rq' , 'ragequit' ), $this , 'chat_ragequit' , false , 'Gets you away from this server in rage!' );
2014-05-20 14:59:17 +02:00
//TODO block command listener for muted people
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getSettingManager () -> initSetting ( $this , self :: SETTING_AFK_FORCE_SPEC , true );
2014-05-03 21:57:38 +02:00
return true ;
}
/**
2014-05-03 23:49:58 +02:00
* @ see \ManiaControl\Plugins\Plugin :: unload ()
2014-05-03 21:57:38 +02:00
*/
public function unload () {
}
/**
* Builds a chat message starting with the player ' s nickname , can used to express emotions
*
* @ param array $chat
* @ param Player $player
*/
public function chat_me ( array $chat , Player $player ) {
$message = substr ( $chat [ 1 ][ 2 ], 4 );
$msg = '$<' . $player -> nickname . '$>$s$i$fa0 ' . $message ;
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendChat ( $msg , null , false );
2014-05-03 21:57:38 +02:00
}
/**
* Hello Message
*
* @ param array $chat
* @ param Player $player
*/
public function chat_hi ( array $chat , Player $player ) {
$command = explode ( " " , $chat [ 1 ][ 2 ]);
if ( isset ( $command [ 1 ])) {
$msg = '$ff0[$<' . $player -> nickname . '$>] $ff0$iHello $z$<' . $this -> getTarget ( $command [ 1 ]) . '$>$i!' ;
} else {
$msg = '$ff0[$<' . $player -> nickname . '$>] $ff0$iHello All!' ;
}
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendChat ( $msg , null , false );
2014-05-03 21:57:38 +02:00
}
/**
* Checks if a Player is in the PlayerList and returns the nickname if he is , can be called per login , pid or nickname or lj for
* ( last joined )
*
2014-05-13 16:40:05 +02:00
* @ param mixed $login
2014-05-03 21:57:38 +02:00
* @ return mixed
*/
private function getTarget ( $login ) {
$player = null ;
2014-08-13 11:14:29 +02:00
foreach ( $this -> maniaControl -> getPlayerManager () -> getPlayers () as $player ) {
2014-05-27 22:44:22 +02:00
if ( $login == $player || $login == $player -> login || $login == $player -> pid || $login == $player -> nickname ) {
2014-05-03 21:57:38 +02:00
return $player -> nickname ;
}
}
2014-06-14 14:32:29 +02:00
if ( $player && strtolower ( $login ) === 'lj' ) {
2014-05-03 21:57:38 +02:00
return $player -> nickname ;
}
//returns the text given if nothing matches
return $login ;
}
/**
* Bye Message
*
* @ param array $chat
* @ param Player $player
*/
public function chat_bye ( array $chat , Player $player ) {
$command = explode ( " " , $chat [ 1 ][ 2 ]);
if ( isset ( $command [ 1 ])) {
$msg = '$ff0[$<' . $player -> nickname . '$>] $ff0$iBye $z$<' . $this -> getTarget ( $command [ 1 ]) . '$>$i!' ;
} else {
$msg = '$ff0[$<' . $player -> nickname . '$>] $ff0$iI have to go... Bye All!' ;
}
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendChat ( $msg , null , false );
2014-05-03 21:57:38 +02:00
}
/**
* Thx Message
*
* @ param array $chat
* @ param Player $player
*/
public function chat_thx ( array $chat , Player $player ) {
$command = explode ( " " , $chat [ 1 ][ 2 ]);
if ( isset ( $command [ 1 ])) {
$msg = '$ff0[$<' . $player -> nickname . '$>] $ff0$iThanks $z$<' . $this -> getTarget ( $command [ 1 ]) . '$>$i!' ;
} else {
$msg = '$ff0[$<' . $player -> nickname . '$>] $ff0$iThanks All!' ;
}
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendChat ( $msg , null , false );
2014-05-03 21:57:38 +02:00
}
/**
* Good Game Message
*
* @ param array $chat
* @ param Player $player
*/
public function chat_gg ( array $chat , Player $player ) {
$command = explode ( " " , $chat [ 1 ][ 2 ]);
if ( isset ( $command [ 1 ])) {
2014-08-05 02:17:41 +02:00
$msg = '$ff0[' . $player -> getEscapedNickname () . '] $ff0$iGood Game $z$<' . $this -> getTarget ( $command [ 1 ]) . '$>$i!' ;
2014-05-03 21:57:38 +02:00
} else {
2014-08-03 01:34:18 +02:00
$msg = '$ff0[' . $player -> getEscapedNickname () . '] $ff0$iGood Game All!' ;
2014-05-03 21:57:38 +02:00
}
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendChat ( $msg , null , false );
2014-05-03 21:57:38 +02:00
}
/**
* Good Luck Message
*
* @ param array $chat
* @ param Player $player
*/
public function chat_gl ( array $chat , Player $player ) {
$command = explode ( " " , $chat [ 1 ][ 2 ]);
if ( isset ( $command [ 1 ])) {
$msg = '$ff0[$<' . $player -> nickname . '$>] $ff0$iGood Luck $z$<' . $this -> getTarget ( $command [ 1 ]) . '$>$i!' ;
} else {
$msg = '$ff0[$<' . $player -> nickname . '$>] $ff0$iGood Luck All!' ;
}
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendChat ( $msg , null , false );
2014-05-03 21:57:38 +02:00
}
/**
* Have Fun Message
*
* @ param array $chat
* @ param Player $player
*/
public function chat_hf ( array $chat , Player $player ) {
$command = explode ( " " , $chat [ 1 ][ 2 ]);
if ( isset ( $command [ 1 ])) {
2014-08-05 02:17:41 +02:00
$msg = '$ff0[' . $player -> getEscapedNickname () . '] $ff0$iHave Fun $z$<' . $this -> getTarget ( $command [ 1 ]) . '$>$i!' ;
2014-05-03 21:57:38 +02:00
} else {
2014-08-05 02:17:41 +02:00
$msg = '$ff0[' . $player -> getEscapedNickname () . '] $ff0$iHave Fun All!' ;
2014-05-03 21:57:38 +02:00
}
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendChat ( $msg , null , false );
2014-05-03 21:57:38 +02:00
}
/**
* Good Luck and Have Fun Message
*
* @ param array $chat
* @ param Player $player
*/
public function chat_glhf ( array $chat , Player $player ) {
$command = explode ( " " , $chat [ 1 ][ 2 ]);
if ( isset ( $command [ 1 ])) {
$msg = '$ff0[$<' . $player -> nickname . '$>] $ff0$iGood Luck and Have Fun $z$<' . $this -> getTarget ( $command [ 1 ]) . '$>$i!' ;
} else {
$msg = '$ff0[$<' . $player -> nickname . '$>] $ff0$iGood Luck and Have Fun All!' ;
}
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendChat ( $msg , null , false );
2014-05-03 21:57:38 +02:00
}
/**
* Nice Shot Message
*
* @ param array $chat
* @ param Player $player
*/
public function chat_ns ( array $chat , Player $player ) {
$command = explode ( " " , $chat [ 1 ][ 2 ]);
if ( isset ( $command [ 1 ])) {
$msg = '$ff0[$<' . $player -> nickname . '$>] $ff0$iNice Shot $z$<' . $this -> getTarget ( $command [ 1 ]) . '$>$i!' ;
} else {
$msg = '$ff0[$<' . $player -> nickname . '$>] $ff0$iNice Shot!' ;
}
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendChat ( $msg , null , false );
2014-05-03 21:57:38 +02:00
}
/**
* Nice one Message
*
* @ param array $chat
* @ param Player $player
*/
public function chat_n1 ( array $chat , Player $player ) {
$command = explode ( " " , $chat [ 1 ][ 2 ]);
if ( isset ( $command [ 1 ])) {
$msg = '$ff0[$<' . $player -> nickname . '$>] $ff0$iNice One $z$<' . $this -> getTarget ( $command [ 1 ]) . '$>$i!' ;
} else {
$msg = '$ff0[$<' . $player -> nickname . '$>] $ff0$iNice One!' ;
}
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendChat ( $msg , null , false );
2014-05-03 21:57:38 +02:00
}
/**
* Lol ! Message
*
* @ param array $chat
* @ param Player $player
*/
public function chat_lol ( array $chat , Player $player ) {
$msg = '$ff0[$<' . $player -> nickname . '$>] $ff0$iLoL!' ;
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendChat ( $msg , null , false );
2014-05-03 21:57:38 +02:00
}
/**
* LooOOooL ! Message
*
* @ param array $chat
* @ param Player $player
*/
public function chat_lool ( array $chat , Player $player ) {
$msg = '$ff0[$<' . $player -> nickname . '$>] $ff0$iLooOOooL!' ;
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendChat ( $msg , null , false );
2014-05-03 21:57:38 +02:00
}
/**
* Be right back Message
*
* @ param array $chat
* @ param Player $player
*/
public function chat_brb ( array $chat , Player $player ) {
$msg = '$ff0[$<' . $player -> nickname . '$>] $ff0$iBe Right Back!' ;
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendChat ( $msg , null , false );
2014-05-03 21:57:38 +02:00
}
/**
* Bad game for me Message
*
* @ param array $chat
* @ param Player $player
*/
public function chat_bgm ( array $chat , Player $player ) {
$msg = '$ff0[$<' . $player -> nickname . '$>] $ff0$iBad Game for me :(' ;
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendChat ( $msg , null , false );
2014-05-03 21:57:38 +02:00
}
/**
* Leave the server with an Bootme Message
*
* @ param array $chat
* @ param Player $player
*/
public function chat_bootme ( array $chat , Player $player ) {
$msg = '$i$ff0 $<' . $player -> nickname . '$>$s$39f chooses to boot back to the real world!' ;
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendChat ( $msg , null , true );
2014-05-03 21:57:38 +02:00
$message = '$39F Thanks for Playing, see you around!$z' ;
try {
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getClient () -> kick ( $player -> login , $message );
2014-06-22 18:24:31 +02:00
} catch ( UnknownPlayerException $exception ) {
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendException ( $exception , $player );
2014-05-03 21:57:38 +02:00
}
}
/**
* Leave the server with an Ragequit
*
* @ param array $chat
* @ param Player $player
*/
public function chat_ragequit ( array $chat , Player $player ) {
try {
2014-06-22 18:24:31 +02:00
$message = '$39F Thanks for Playing, please come back soon!$z ' ;
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getClient () -> kick ( $player -> login , $message );
2014-06-22 18:24:31 +02:00
$msg = '$i$ff0 $<' . $player -> nickname . '$>$s$f00 said: "@"#!" and ragequitted!' ;
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendChat ( $msg , null , true );
2014-05-13 17:59:37 +02:00
} catch ( UnknownPlayerException $e ) {
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendError ( 'Error occurred: ' . $e -> getMessage (), $player );
2014-05-03 21:57:38 +02:00
}
}
/**
* Afk Message and force player to spec
*
* @ param array $chat
* @ param Player $player
*/
public function chat_afk ( array $chat , Player $player ) {
$msg = '$ff0[$<' . $player -> nickname . '$>] $ff0$iAway From Keyboard!' ;
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendChat ( $msg , null , false );
2014-05-03 21:57:38 +02:00
2014-08-13 11:14:29 +02:00
if ( ! $this -> maniaControl -> getSettingManager () -> getSettingValue ( $this , self :: SETTING_AFK_FORCE_SPEC )
2014-08-05 02:17:41 +02:00
) {
2014-06-22 18:24:31 +02:00
return ;
}
if ( $player -> isSpectator ) {
return ;
}
2014-05-03 21:57:38 +02:00
2014-06-22 18:24:31 +02:00
try {
// Force into spec
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getClient () -> forceSpectator ( $player -> login , 3 );
2014-06-22 18:24:31 +02:00
// Free player slot
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getClient () -> spectatorReleasePlayerSlot ( $player -> login );
2014-06-22 18:24:31 +02:00
} catch ( UnknownPlayerException $exception ) {
2014-08-13 11:14:29 +02:00
$this -> maniaControl -> getChat () -> sendException ( $exception , $player );
2014-06-23 23:08:08 +02:00
} catch ( PlayerStateException $exception ) {
2014-05-03 21:57:38 +02:00
}
}
2014-06-22 18:24:31 +02:00
}