2013-11-12 16:52:23 +01:00
< ? php
namespace ManiaControl\Maps ;
2014-01-05 00:43:46 +01:00
use FML\Controls\Quad ;
2014-01-04 18:18:46 +01:00
use FML\Controls\Quads\Quad_Icons64x64_1 ;
2014-01-05 01:29:49 +01:00
use FML\Controls\Quads\Quad_UIConstruction_Buttons ;
2014-05-27 23:18:56 +02:00
use ManiaControl\Admin\AuthenticationManager ;
2014-01-05 00:43:46 +01:00
use ManiaControl\Callbacks\CallbackListener ;
2014-05-02 17:50:30 +02:00
use ManiaControl\Callbacks\CallbackManager ;
2023-08-14 17:11:09 +02:00
use ManiaControl\Callbacks\Callbacks ;
2013-11-12 16:52:23 +01:00
use ManiaControl\Commands\CommandListener ;
2014-08-05 01:49:13 +02:00
use ManiaControl\Logger ;
2014-01-04 18:49:33 +01:00
use ManiaControl\ManiaControl ;
2020-05-11 17:14:10 +02:00
use ManiaControl\Manialinks\ElementBuilder ;
2014-01-05 00:43:46 +01:00
use ManiaControl\Manialinks\IconManager ;
2014-01-04 18:18:46 +01:00
use ManiaControl\Manialinks\ManialinkPageAnswerListener ;
2013-11-12 16:52:23 +01:00
use ManiaControl\Players\Player ;
2020-05-27 00:01:36 +02:00
use ManiaControl\Utils\DataUtil ;
2014-04-19 23:14:37 +02:00
use Maniaplanet\DedicatedServer\Xmlrpc\ChangeInProgressException ;
2014-04-27 01:47:51 +02:00
use Maniaplanet\DedicatedServer\Xmlrpc\FaultException ;
2013-11-12 16:52:23 +01:00
/**
2014-04-12 12:14:37 +02:00
* Class offering Commands to manage Maps
2013-11-12 16:52:23 +01:00
*
2014-05-02 17:50:30 +02:00
* @ author ManiaControl Team < mail @ maniacontrol . com >
2020-01-22 10:39:35 +01:00
* @ copyright 2014 - 2020 ManiaControl Team
2014-04-19 23:14:37 +02:00
* @ license http :// www . gnu . org / licenses / GNU General Public License , Version 3
2013-11-12 16:52:23 +01:00
*/
2014-01-05 13:32:59 +01:00
class MapCommands implements CommandListener , ManialinkPageAnswerListener , CallbackListener {
2014-04-12 12:14:37 +02:00
/*
2014-01-04 18:18:46 +01:00
* Constants
*/
2014-01-08 20:11:48 +01:00
const ACTION_OPEN_MAPLIST = 'MapCommands.OpenMapList' ;
const ACTION_OPEN_XLIST = 'MapCommands.OpenMXList' ;
const ACTION_RESTART_MAP = 'MapCommands.RestartMap' ;
const ACTION_SKIP_MAP = 'MapCommands.NextMap' ;
2014-05-01 00:31:38 +02:00
const ACTION_SHOW_AUTHOR = 'MapList.ShowAuthorList.' ;
2014-01-08 20:11:48 +01:00
2014-04-12 12:14:37 +02:00
/*
2014-07-25 16:28:47 +02:00
* Private properties
2013-11-12 16:52:23 +01:00
*/
2014-08-02 22:31:46 +02:00
/** @var ManiaControl $maniaControl */
2013-11-12 16:52:23 +01:00
private $maniaControl = null ;
/**
2014-07-25 16:28:47 +02:00
* Construct a new map commands instance
2013-11-12 16:52:23 +01:00
*
2014-07-25 16:28:47 +02:00
* @ param ManiaControl $maniaControl
2013-11-12 16:52:23 +01:00
*/
public function __construct ( ManiaControl $maniaControl ) {
$this -> maniaControl = $maniaControl ;
2014-01-08 20:11:48 +01:00
2014-08-03 01:34:18 +02:00
// Admin commands
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( array ( 'nextmap' , 'next' , 'skip' ), $this , 'command_NextMap' , true , 'Skips to the next map.' );
2020-04-26 09:47:33 +02:00
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( array ( 'restartmap' , 'resmap' , 'res' ), $this , 'command_RestartMap' , true , 'Restarts the current map.' );
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( array ( 'replaymap' , 'replay' ), $this , 'command_ReplayMap' , true , 'Replays the current map (after the end of the map).' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( array ( 'addmap' , 'add' ), $this , 'command_AddMap' , true , 'Adds map from ManiaExchange.' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( array ( 'removemap' , 'removethis' ), $this , 'command_RemoveMap' , true , 'Removes the current map.' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( array ( 'erasemap' , 'erasethis' ), $this , 'command_EraseMap' , true , 'Erases the current map.' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( array ( 'shufflemaps' , 'shuffle' ), $this , 'command_ShuffleMaps' , true , 'Shuffles the maplist.' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( array ( 'writemaplist' , 'wml' ), $this , 'command_WriteMapList' , true , 'Writes the current maplist to a file.' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( array ( 'readmaplist' , 'rml' ), $this , 'command_ReadMapList' , true , 'Loads a maplist into the server.' );
2014-08-03 01:34:18 +02:00
// Player commands
2020-05-27 00:01:36 +02:00
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( array ( 'nextmap' , 'next' ), $this , 'command_showNextMap' , false , 'Shows which map is next.' );
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( array ( 'maps' , 'list' ), $this , 'command_List' , false , 'Shows the current maplist (or variations).' );
$this -> maniaControl -> getCommandManager () -> registerCommandListener ( array ( 'xmaps' , 'xlist' ), $this , 'command_xList' , false , 'Shows maps from ManiaExchange.' );
2014-08-03 01:34:18 +02:00
// Callbacks
2023-08-14 17:11:09 +02:00
$this -> maniaControl -> getCallbackManager () -> registerCallbackListener ( Callbacks :: AFTERINIT , $this , 'handleAfterInit' );
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getCallbackManager () -> registerCallbackListener ( CallbackManager :: CB_MP_PLAYERMANIALINKPAGEANSWER , $this , 'handleManialinkPageAnswer' );
$this -> maniaControl -> getManialinkManager () -> registerManialinkPageAnswerListener ( self :: ACTION_OPEN_XLIST , $this , 'command_xList' );
$this -> maniaControl -> getManialinkManager () -> registerManialinkPageAnswerListener ( self :: ACTION_OPEN_MAPLIST , $this , 'command_List' );
$this -> maniaControl -> getManialinkManager () -> registerManialinkPageAnswerListener ( self :: ACTION_RESTART_MAP , $this , 'command_RestartMap' );
$this -> maniaControl -> getManialinkManager () -> registerManialinkPageAnswerListener ( self :: ACTION_SKIP_MAP , $this , 'command_NextMap' );
2014-01-05 00:43:46 +01:00
}
2023-08-14 17:11:09 +02:00
public function handleAfterInit () {
$this -> initActionsMenuButtons ();
}
2014-01-05 00:43:46 +01:00
/**
2014-01-05 13:32:59 +01:00
* Add all Actions Menu Buttons
2014-01-05 00:43:46 +01:00
*/
2014-01-05 13:32:59 +01:00
private function initActionsMenuButtons () {
// Menu Open xList
2023-08-14 17:11:09 +02:00
if ( $this -> maniaControl -> getMapManager () -> getMXManager () -> getStatus ()) {
$itemQuad = new Quad ();
$itemQuad -> setImageUrl ( $this -> maniaControl -> getManialinkManager () -> getIconManager () -> getIcon ( IconManager :: MX_ICON ));
$itemQuad -> setImageFocusUrl ( $this -> maniaControl -> getManialinkManager () -> getIconManager () -> getIcon ( IconManager :: MX_ICON_MOVER ));
$itemQuad -> setAction ( self :: ACTION_OPEN_XLIST );
$this -> maniaControl -> getActionsMenu () -> addPlayerMenuItem ( $itemQuad , 5 , 'Open MX List' );
}
2014-01-08 20:11:48 +01:00
2014-01-05 13:32:59 +01:00
// Menu Open List
2014-01-04 18:18:46 +01:00
$itemQuad = new Quad_Icons64x64_1 ();
2014-01-05 01:29:49 +01:00
$itemQuad -> setSubStyle ( $itemQuad :: SUBSTYLE_ToolRoot );
2014-01-04 18:18:46 +01:00
$itemQuad -> setAction ( self :: ACTION_OPEN_MAPLIST );
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getActionsMenu () -> addPlayerMenuItem ( $itemQuad , 10 , 'Open MapList' );
2014-01-08 20:11:48 +01:00
2014-01-05 13:32:59 +01:00
// Menu RestartMap
2014-01-05 01:29:49 +01:00
$itemQuad = new Quad_UIConstruction_Buttons ();
$itemQuad -> setSubStyle ( $itemQuad :: SUBSTYLE_Reload );
2014-01-04 18:49:33 +01:00
$itemQuad -> setAction ( self :: ACTION_RESTART_MAP );
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getActionsMenu () -> addAdminMenuItem ( $itemQuad , 10 , 'Restart Map' );
2014-01-08 20:11:48 +01:00
2014-01-05 13:32:59 +01:00
// Menu NextMap
2014-01-04 18:49:33 +01:00
$itemQuad = new Quad_Icons64x64_1 ();
$itemQuad -> setSubStyle ( $itemQuad :: SUBSTYLE_ArrowFastNext );
$itemQuad -> setAction ( self :: ACTION_SKIP_MAP );
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getActionsMenu () -> addAdminMenuItem ( $itemQuad , 20 , 'Skip Map' );
2014-01-05 00:43:46 +01:00
}
2014-01-05 13:32:59 +01:00
2014-01-14 20:35:31 +01:00
/**
2014-07-25 16:28:47 +02:00
* Show which map is the next
2014-01-14 20:35:31 +01:00
*
2014-05-20 14:59:17 +02:00
* @ param array $chatCallback
2014-01-14 20:35:31 +01:00
* @ param Player $player
*/
2014-05-13 22:54:26 +02:00
public function command_ShowNextMap ( array $chatCallback , Player $player ) {
2014-08-13 11:05:52 +02:00
$nextQueued = $this -> maniaControl -> getMapManager () -> getMapQueue () -> getNextQueuedMap ();
2014-03-31 21:41:05 +02:00
if ( $nextQueued ) {
2014-01-14 20:35:31 +01:00
/** @var Player $requester */
$requester = $nextQueued [ 0 ];
/** @var Map $map */
$map = $nextQueued [ 1 ];
2020-05-27 00:01:36 +02:00
$message = $this -> maniaControl -> getChat () -> formatMessage (
'Next Map is %s, requested by %s.' ,
$map ,
$requester
);
$this -> maniaControl -> getChat () -> sendInformation ( $message , $player );
2014-01-14 20:35:31 +01:00
} else {
2014-08-13 11:05:52 +02:00
$mapIndex = $this -> maniaControl -> getClient () -> getNextMapIndex ();
2020-05-27 00:01:36 +02:00
$map = $this -> maniaControl -> getMapManager () -> getMapByIndex ( $mapIndex );
$message = $this -> maniaControl -> getChat () -> formatMessage (
'Next Map is %s.' ,
$map
);
$this -> maniaControl -> getChat () -> sendInformation ( $message , $player );
2014-01-14 20:35:31 +01:00
}
}
2013-11-12 16:52:23 +01:00
/**
2014-07-05 12:19:38 +02:00
* Handle //removemap command
2013-11-12 16:52:23 +01:00
*
2014-05-20 14:59:17 +02:00
* @ param array $chatCallback
2014-05-13 22:54:26 +02:00
* @ param Player $player
2013-11-12 16:52:23 +01:00
*/
2014-05-13 22:54:26 +02:00
public function command_RemoveMap ( array $chatCallback , Player $player ) {
2017-03-29 19:54:50 +02:00
if ( ! $this -> maniaControl -> getAuthenticationManager () -> checkPermission ( $player , MapManager :: SETTING_PERMISSION_REMOVE_MAP )) {
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getAuthenticationManager () -> sendNotAllowed ( $player );
2013-12-15 09:00:30 +01:00
return ;
2013-11-12 16:52:23 +01:00
}
2020-05-27 00:01:36 +02:00
2014-08-13 11:05:52 +02:00
$map = $this -> maniaControl -> getMapManager () -> getCurrentMap ();
2014-01-28 16:54:23 +01:00
if ( ! $map ) {
2020-05-27 00:01:36 +02:00
$this -> maniaControl -> getChat () -> sendError ( 'Could not fetch current map to remove!' , $player );
2013-12-15 09:00:30 +01:00
return ;
2013-11-12 16:52:23 +01:00
}
2014-01-14 15:45:36 +01:00
2020-05-27 00:01:36 +02:00
// no chat message necessary, the MapManager will do that
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getMapManager () -> removeMap ( $player , $map -> uid );
2013-11-12 16:52:23 +01:00
}
2014-07-05 12:19:38 +02:00
/**
* Handle //erasemap command
*
* @ param array $chatCallback
* @ param Player $player
*/
public function command_EraseMap ( array $chatCallback , Player $player ) {
2017-03-29 19:54:50 +02:00
if ( ! $this -> maniaControl -> getAuthenticationManager () -> checkPermission ( $player , MapManager :: SETTING_PERMISSION_ERASE_MAP )) {
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getAuthenticationManager () -> sendNotAllowed ( $player );
2014-07-05 12:19:38 +02:00
return ;
}
2020-05-27 00:01:36 +02:00
2014-08-13 11:05:52 +02:00
$map = $this -> maniaControl -> getMapManager () -> getCurrentMap ();
2014-07-05 12:19:38 +02:00
if ( ! $map ) {
2020-05-27 00:01:36 +02:00
$this -> maniaControl -> getChat () -> sendError ( 'Could not fetch current map to erase!' , $player );
2014-07-05 12:19:38 +02:00
return ;
}
2020-05-27 00:01:36 +02:00
// no chat message necessary, the MapManager will do that
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getMapManager () -> removeMap ( $player , $map -> uid , true );
2014-07-05 12:19:38 +02:00
}
2013-11-12 16:52:23 +01:00
/**
2014-03-31 21:04:15 +02:00
* Handle shufflemaps command
2013-11-12 16:52:23 +01:00
*
2014-01-08 20:11:48 +01:00
* @ param array $chatCallback
2014-01-04 18:49:33 +01:00
* @ param \ManiaControl\Players\Player $player
2014-01-11 16:34:05 +01:00
*/
public function command_ShuffleMaps ( array $chatCallback , Player $player ) {
2017-03-29 19:54:50 +02:00
if ( ! $this -> maniaControl -> getAuthenticationManager () -> checkPermission ( $player , MapManager :: SETTING_PERMISSION_SHUFFLE_MAPS )) {
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getAuthenticationManager () -> sendNotAllowed ( $player );
2014-01-11 16:34:05 +01:00
return ;
}
2020-05-27 00:01:36 +02:00
// no chat message necessary, the MapManager will do that
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getMapManager () -> shuffleMapList ( $player );
2014-01-11 16:34:05 +01:00
}
/**
* Handle addmap command
*
* @ param array $chatCallback
* @ param \ManiaControl\Players\Player $player
2013-11-12 16:52:23 +01:00
*/
2013-11-27 02:42:39 +01:00
public function command_AddMap ( array $chatCallback , Player $player ) {
2017-03-29 19:54:50 +02:00
if ( ! $this -> maniaControl -> getAuthenticationManager () -> checkPermission ( $player , MapManager :: SETTING_PERMISSION_ADD_MAP )) {
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getAuthenticationManager () -> sendNotAllowed ( $player );
2013-12-15 09:00:30 +01:00
return ;
2013-11-12 16:52:23 +01:00
}
2020-05-27 00:01:36 +02:00
2013-11-27 02:42:39 +01:00
$params = explode ( ' ' , $chatCallback [ 1 ][ 2 ], 2 );
2014-01-28 16:54:23 +01:00
if ( count ( $params ) < 2 ) {
2020-05-27 00:01:36 +02:00
$message = $this -> maniaControl -> getChat () -> formatMessage (
'Usage example: %s' ,
'//addmap 1234'
);
$this -> maniaControl -> getChat () -> sendUsageInfo ( $message , $player );
2013-12-15 09:00:30 +01:00
return ;
2013-11-12 16:52:23 +01:00
}
2014-01-08 20:11:48 +01:00
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getMapManager () -> addMapFromMx ( $params [ 1 ], $player -> login );
2013-11-12 16:52:23 +01:00
}
/**
2014-01-06 18:50:26 +01:00
* Handle / nextmap Command
2013-11-12 16:52:23 +01:00
*
2014-01-08 20:11:48 +01:00
* @ param array $chat
2014-01-04 18:49:33 +01:00
* @ param \ManiaControl\Players\Player $player
2013-11-12 16:52:23 +01:00
*/
public function command_NextMap ( array $chat , Player $player ) {
2017-03-29 19:54:50 +02:00
if ( ! $this -> maniaControl -> getAuthenticationManager () -> checkPermission ( $player , MapManager :: SETTING_PERMISSION_SKIP_MAP )) {
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getAuthenticationManager () -> sendNotAllowed ( $player );
2013-12-15 09:00:30 +01:00
return ;
2013-11-12 16:52:23 +01:00
}
2014-05-09 11:58:33 +02:00
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getMapManager () -> getMapActions () -> skipMap ();
2014-05-09 11:58:33 +02:00
2020-05-27 00:01:36 +02:00
$message = $this -> maniaControl -> getChat () -> formatMessage (
'%s skipped the current Map!' ,
$player
);
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getChat () -> sendSuccess ( $message );
2014-08-05 02:08:41 +02:00
Logger :: logInfo ( $message , true );
2013-11-12 16:52:23 +01:00
}
/**
2013-12-15 09:00:30 +01:00
* Handle restartmap command
2013-11-12 16:52:23 +01:00
*
2014-01-08 20:11:48 +01:00
* @ param array $chat
2014-01-04 18:49:33 +01:00
* @ param \ManiaControl\Players\Player $player
2013-11-12 16:52:23 +01:00
*/
public function command_RestartMap ( array $chat , Player $player ) {
2017-03-29 19:54:50 +02:00
if ( ! $this -> maniaControl -> getAuthenticationManager () -> checkPermission ( $player , MapManager :: SETTING_PERMISSION_RESTART_MAP )) {
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getAuthenticationManager () -> sendNotAllowed ( $player );
2013-12-15 09:00:30 +01:00
return ;
2013-11-12 16:52:23 +01:00
}
2014-03-01 11:11:50 +01:00
2014-03-13 18:25:29 +01:00
try {
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getClient () -> restartMap ();
2014-05-02 17:50:30 +02:00
} catch ( ChangeInProgressException $e ) {
2020-05-27 00:01:36 +02:00
$this -> maniaControl -> getChat () -> sendException ( $e , $player );
return ;
2014-03-13 18:25:29 +01:00
}
2013-12-14 22:00:59 +01:00
2020-05-27 00:01:36 +02:00
$message = $this -> maniaControl -> getChat () -> formatMessage (
'%s restarted the current Map!' ,
$player
);
$this -> maniaControl -> getChat () -> sendSuccess ( $message );
Logger :: logInfo ( $message , true );
}
2017-03-29 19:54:50 +02:00
2014-04-27 00:55:39 +02:00
/**
* Handle replaymap command
*
* @ param array $chat
* @ param \ManiaControl\Players\Player $player
*/
public function command_ReplayMap ( array $chat , Player $player ) {
2017-03-29 19:54:50 +02:00
if ( ! $this -> maniaControl -> getAuthenticationManager () -> checkPermission ( $player , MapManager :: SETTING_PERMISSION_RESTART_MAP )) {
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getAuthenticationManager () -> sendNotAllowed ( $player );
2014-04-27 00:55:39 +02:00
return ;
}
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getMapManager () -> getMapQueue () -> addFirstMapToMapQueue ( $player , $this -> maniaControl -> getMapManager () -> getCurrentMap ());
2020-05-27 00:01:36 +02:00
$message = $this -> maniaControl -> getChat () -> formatMessage (
'%s queued the current Map to replay!' ,
$player
);
$this -> maniaControl -> getChat () -> sendSuccess ( $message );
Logger :: logInfo ( $message , true );
2014-04-27 00:55:39 +02:00
}
2014-04-27 01:47:51 +02:00
/**
* Handle writemaplist command
*
* @ param array $chat
* @ param \ManiaControl\Players\Player $player
*/
public function command_WriteMapList ( array $chat , Player $player ) {
2017-03-29 19:54:50 +02:00
if ( ! $this -> maniaControl -> getAuthenticationManager () -> checkRight ( $player , AuthenticationManager :: AUTH_LEVEL_SUPERADMIN )) {
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getAuthenticationManager () -> sendNotAllowed ( $player );
2014-04-27 01:47:51 +02:00
return ;
}
$chatCommand = explode ( ' ' , $chat [ 1 ][ 2 ]);
2020-05-27 00:01:36 +02:00
$maplist = 'MatchSettings' . DIRECTORY_SEPARATOR ;
2014-05-02 17:50:30 +02:00
if ( isset ( $chatCommand [ 1 ])) {
2020-05-27 00:01:36 +02:00
if ( ! DataUtil :: endsWith ( $chatCommand [ 1 ], '.txt' )) {
$maplist .= $chatCommand [ 1 ] . '.txt' ;
2014-04-27 01:47:51 +02:00
} else {
2020-05-27 00:01:36 +02:00
$maplist .= $chatCommand [ 1 ];
2014-04-27 01:47:51 +02:00
}
} else {
2020-05-27 00:01:36 +02:00
$maplist .= 'maplist.txt' ;
2014-04-27 01:47:51 +02:00
}
2014-04-27 01:48:54 +02:00
try {
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getClient () -> saveMatchSettings ( $maplist );
2014-05-02 17:50:30 +02:00
} catch ( FaultException $e ) {
2020-05-27 00:01:36 +02:00
$this -> maniaControl -> getChat () -> sendException ( $e , $player );
$message = $this -> maniaControl -> getChat () -> formatMessage (
'Cannot write maplist %s!' ,
$maplist
);
$this -> maniaControl -> getChat () -> sendError ( $message , $player );
return ;
2014-04-27 01:48:54 +02:00
}
2020-05-27 00:01:36 +02:00
$message = $this -> maniaControl -> getChat () -> formatMessage (
'Maplist %s written.' ,
$maplist
);
$this -> maniaControl -> getChat () -> sendSuccess ( $message , $player );
Logger :: logInfo ( $message , true );
2014-04-27 01:47:51 +02:00
}
/**
* Handle readmaplist command
*
* @ param array $chat
* @ param \ManiaControl\Players\Player $player
*/
public function command_ReadMapList ( array $chat , Player $player ) {
2017-03-29 19:54:50 +02:00
if ( ! $this -> maniaControl -> getAuthenticationManager () -> checkRight ( $player , AuthenticationManager :: AUTH_LEVEL_SUPERADMIN )) {
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getAuthenticationManager () -> sendNotAllowed ( $player );
2014-04-27 01:47:51 +02:00
return ;
}
$chatCommand = explode ( ' ' , $chat [ 1 ][ 2 ]);
2020-05-27 00:01:36 +02:00
$maplist = 'MatchSettings' . DIRECTORY_SEPARATOR ;
2014-05-02 17:50:30 +02:00
if ( isset ( $chatCommand [ 1 ])) {
2020-05-27 00:01:36 +02:00
if ( ! DataUtil :: endsWith ( $chatCommand [ 1 ], '.txt' )) {
$maplist .= $chatCommand [ 1 ] . '.txt' ;
2014-04-27 01:47:51 +02:00
} else {
2020-05-27 00:01:36 +02:00
$maplist .= $chatCommand [ 1 ];
2014-04-27 01:47:51 +02:00
}
} else {
2020-05-27 00:01:36 +02:00
$maplist .= 'maplist.txt' ;
2014-04-27 01:47:51 +02:00
}
try {
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getClient () -> loadMatchSettings ( $maplist );
2014-05-02 17:50:30 +02:00
} catch ( FaultException $e ) {
2020-05-27 00:01:36 +02:00
$this -> maniaControl -> getChat () -> sendException ( $e , $player );
$message = $this -> maniaControl -> getChat () -> formatMessage (
'Cannot load maplist %s!' ,
$maplist
);
$this -> maniaControl -> getChat () -> sendError ( $message , $player );
return ;
2014-04-27 01:47:51 +02:00
}
2020-05-27 00:01:36 +02:00
$message = $this -> maniaControl -> getChat () -> formatMessage (
'Maplist %s loaded.' ,
$maplist
);
$this -> maniaControl -> getMapManager () -> restructureMapList ();
$this -> maniaControl -> getChat () -> sendSuccess ( $message , $player );
Logger :: logInfo ( $message , true );
2014-04-27 01:47:51 +02:00
}
2014-05-02 16:13:45 +02:00
/**
* Handle ManialinkPageAnswer Callback
*
* @ param array $callback
*/
2014-05-01 00:31:38 +02:00
public function handleManialinkPageAnswer ( array $callback ) {
$actionId = $callback [ 1 ][ 2 ];
2014-05-02 17:50:30 +02:00
$login = $callback [ 1 ][ 1 ];
2014-08-13 11:05:52 +02:00
$player = $this -> maniaControl -> getPlayerManager () -> getPlayer ( $login );
2014-05-01 00:31:38 +02:00
if ( strstr ( $actionId , self :: ACTION_SHOW_AUTHOR )) {
$login = str_replace ( self :: ACTION_SHOW_AUTHOR , '' , $actionId );
$this -> showMapListAuthor ( $login , $player );
}
}
2014-05-02 17:50:30 +02:00
/**
* Show the Player a List of Maps from the given Author
*
* @ param string $author
* @ param Player $player
*/
private function showMapListAuthor ( $author , Player $player ) {
2014-08-13 11:05:52 +02:00
$maps = $this -> maniaControl -> getMapManager () -> getMaps ();
2014-05-02 17:50:30 +02:00
$mapList = array ();
/** @var Map $map */
foreach ( $maps as $map ) {
if ( $map -> authorLogin == $author ) {
2014-06-14 14:32:29 +02:00
array_push ( $mapList , $map );
2014-05-02 17:50:30 +02:00
}
}
2014-06-14 14:32:29 +02:00
if ( empty ( $mapList )) {
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getChat () -> sendError ( 'There are no maps to show!' , $player -> login );
2014-05-02 17:50:30 +02:00
return ;
}
2022-04-03 11:57:36 +02:00
$this -> maniaControl -> getMapManager () -> getMapList () -> showMapList ( $player , $mapList , - 1 , $author );
2014-05-02 17:50:30 +02:00
}
2013-12-15 09:00:30 +01:00
/**
2014-01-06 18:50:26 +01:00
* Handle / maps command
2013-12-15 09:00:30 +01:00
*
2014-01-08 20:11:48 +01:00
* @ param array $chatCallback
2014-01-04 18:49:33 +01:00
* @ param Player $player
2013-12-15 09:00:30 +01:00
*/
public function command_List ( array $chatCallback , Player $player ) {
2014-04-29 15:20:20 +02:00
$chatCommands = explode ( ' ' , $chatCallback [ 1 ][ 2 ]);
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getMapManager () -> getMapList () -> playerCloseWidget ( $player );
2014-06-14 14:32:29 +02:00
2014-05-02 17:50:30 +02:00
if ( isset ( $chatCommands [ 1 ])) {
2014-06-14 14:32:29 +02:00
$listParam = strtolower ( $chatCommands [ 1 ]);
switch ( $listParam ) {
case 'best' :
$this -> showMapListKarma ( true , $player );
break ;
case 'worst' :
$this -> showMapListKarma ( false , $player );
break ;
case 'newest' :
$this -> showMapListDate ( true , $player );
break ;
case 'oldest' :
$this -> showMapListDate ( false , $player );
break ;
case 'author' :
if ( isset ( $chatCommands [ 2 ])) {
$this -> showMaplistAuthor ( $chatCommands [ 2 ], $player );
} else {
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getChat () -> sendError ( 'Missing Author Login!' , $player );
2014-06-14 14:32:29 +02:00
}
break ;
default :
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getMapManager () -> getMapList () -> showMapList ( $player );
2014-06-14 14:32:29 +02:00
break ;
2014-04-29 15:20:20 +02:00
}
} else {
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getMapManager () -> getMapList () -> showMapList ( $player );
2014-04-29 15:20:20 +02:00
}
}
2014-05-02 16:13:45 +02:00
/**
* Show a Karma based MapList
*
2014-05-02 17:50:30 +02:00
* @ param bool $best
2014-05-02 16:13:45 +02:00
* @ param Player $player
*/
private function showMapListKarma ( $best , Player $player ) {
2014-04-29 15:20:20 +02:00
/** @var \MCTeam\KarmaPlugin $karmaPlugin */
2020-05-11 17:14:10 +02:00
$karmaPlugin = $this -> maniaControl -> getPluginManager () -> getPlugin ( ElementBuilder :: DEFAULT_KARMA_PLUGIN );
2015-01-21 17:47:29 +01:00
2014-05-02 17:50:30 +02:00
if ( $karmaPlugin ) {
2017-05-11 22:35:16 +02:00
$displayMxKarma = $this -> maniaControl -> getSettingManager () -> getSettingValue ( $karmaPlugin , $karmaPlugin :: SETTING_WIDGET_DISPLAY_MX );
2015-01-21 17:47:29 +01:00
//Sort by Mx Karma in Maplist
if ( $displayMxKarma ) { //TODO
//Sort by Local Karma in Maplist
} else {
}
2014-08-13 11:05:52 +02:00
$maps = $this -> maniaControl -> getMapManager () -> getMaps ();
2014-04-29 15:20:20 +02:00
$mapList = array ();
2014-05-02 17:50:30 +02:00
foreach ( $maps as $map ) {
if ( $map instanceof Map ) {
2017-03-29 19:54:50 +02:00
if ( $this -> maniaControl -> getSettingManager () -> getSettingValue ( $karmaPlugin , $karmaPlugin :: SETTING_NEWKARMA ) === true ) {
2014-05-02 17:50:30 +02:00
$karma = $karmaPlugin -> getMapKarma ( $map );
2014-04-30 14:45:56 +02:00
$map -> karma = round ( $karma * 100. );
} else {
$votes = $karmaPlugin -> getMapVotes ( $map );
2014-05-02 17:50:30 +02:00
$min = 0 ;
$plus = 0 ;
foreach ( $votes as $vote ) {
if ( isset ( $vote -> vote )) {
2014-06-14 14:32:29 +02:00
if ( $vote -> vote !== 0.5 ) {
2014-05-02 17:50:30 +02:00
if ( $vote -> vote < 0.5 ) {
$min = $min + $vote -> count ;
2014-04-30 14:45:56 +02:00
} else {
2014-05-02 17:50:30 +02:00
$plus = $plus + $vote -> count ;
2014-04-30 14:45:56 +02:00
}
2014-04-29 15:20:20 +02:00
}
}
}
2014-05-02 17:50:30 +02:00
$map -> karma = $plus - $min ;
2014-04-29 15:20:20 +02:00
}
$mapList [] = $map ;
}
}
2014-06-14 15:48:27 +02:00
usort ( $mapList , function ( Map $mapA , Map $mapB ) {
return ( $mapA -> karma - $mapB -> karma );
});
2014-05-02 17:50:30 +02:00
if ( $best ) {
2014-04-29 15:20:20 +02:00
$mapList = array_reverse ( $mapList );
}
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getMapManager () -> getMapList () -> showMapList ( $player , $mapList );
2014-04-29 15:20:20 +02:00
} else {
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getChat () -> sendError ( 'KarmaPlugin is not enabled!' , $player -> login );
2014-04-29 15:20:20 +02:00
}
}
2014-05-02 16:13:45 +02:00
/**
* Show a Date based MapList
*
2014-05-02 17:50:30 +02:00
* @ param bool $newest
2014-05-02 16:13:45 +02:00
* @ param Player $player
*/
private function showMapListDate ( $newest , Player $player ) {
2014-08-13 11:05:52 +02:00
$maps = $this -> maniaControl -> getMapManager () -> getMaps ();
2014-04-29 15:20:20 +02:00
2014-06-14 15:48:27 +02:00
usort ( $maps , function ( Map $mapA , Map $mapB ) {
return ( $mapA -> index - $mapB -> index );
2014-04-29 15:20:20 +02:00
});
2014-05-02 17:50:30 +02:00
if ( $newest ) {
2014-04-29 15:20:20 +02:00
$maps = array_reverse ( $maps );
}
2014-08-13 11:05:52 +02:00
$this -> maniaControl -> getMapManager () -> getMapList () -> showMapList ( $player , $maps );
2013-12-14 22:00:59 +01:00
}
2013-12-15 11:29:49 +01:00
/**
* Handle ManiaExchange list command
2014-01-04 18:49:33 +01:00
*
2014-01-08 20:11:48 +01:00
* @ param array $chatCallback
2013-12-15 11:29:49 +01:00
* @ param Player $player
*/
public function command_xList ( array $chatCallback , Player $player ) {
2017-03-29 19:54:50 +02:00
$this -> maniaControl -> getMapManager () -> getMXList () -> showListCommand ( $chatCallback , $player );
2013-12-15 11:29:49 +01:00
}
2013-11-12 16:52:23 +01:00
}