2014-05-04 15:47:02 +02:00
|
|
|
<?php
|
2014-05-07 21:42:23 +02:00
|
|
|
|
2014-05-04 15:47:02 +02:00
|
|
|
namespace TheM;
|
2014-05-07 21:42:23 +02:00
|
|
|
|
2014-05-04 15:47:02 +02:00
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
2014-05-17 14:36:25 +02:00
|
|
|
use ManiaControl\Callbacks\CallbackManager;
|
|
|
|
use ManiaControl\Callbacks\Callbacks;
|
2014-05-04 15:47:02 +02:00
|
|
|
use ManiaControl\Commands\CommandListener;
|
|
|
|
use ManiaControl\ManiaControl;
|
|
|
|
use ManiaControl\Players\Player;
|
|
|
|
use ManiaControl\Players\PlayerManager;
|
|
|
|
use ManiaControl\Plugins\Plugin;
|
2014-05-08 19:58:12 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\FaultException;
|
2014-05-17 14:36:25 +02:00
|
|
|
use ManiaControl\Settings\SettingManager;
|
2014-05-04 15:47:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Dynamic Pointlimit plugin
|
|
|
|
* Based on the Linearmode plugin for MPAseco by kremsy
|
|
|
|
*
|
|
|
|
* @author TheM
|
|
|
|
*/
|
|
|
|
class DynamicPointlimitPlugin implements CallbackListener, CommandListener, Plugin {
|
|
|
|
/**
|
|
|
|
* Constants
|
|
|
|
*/
|
|
|
|
const ID = 21;
|
2014-05-04 15:49:18 +02:00
|
|
|
const VERSION = 0.11;
|
2014-05-04 15:47:02 +02:00
|
|
|
|
|
|
|
const DYNPNT_MULTIPLIER = 'Pointlimit multiplier';
|
|
|
|
const DYNPNT_OFFSET = 'Pointlimit offset';
|
|
|
|
const DYNPNT_MIN = 'Minimum pointlimit';
|
|
|
|
const DYNPNT_MAX = 'Maximum pointlimit';
|
|
|
|
const ACCEPT_OTHER_MODES = 'Activate in Other mode as Royal';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepares the Plugin
|
|
|
|
*
|
|
|
|
* @param ManiaControl $maniaControl
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public static function prepare(ManiaControl $maniaControl) {
|
|
|
|
$maniaControl->settingManager->initSetting(get_class(), self::ACCEPT_OTHER_MODES, false);
|
|
|
|
$maniaControl->settingManager->initSetting(get_class(), self::DYNPNT_MULTIPLIER, 10);
|
|
|
|
$maniaControl->settingManager->initSetting(get_class(), self::DYNPNT_OFFSET, 0);
|
|
|
|
$maniaControl->settingManager->initSetting(get_class(), self::DYNPNT_MIN, 30);
|
|
|
|
$maniaControl->settingManager->initSetting(get_class(), self::DYNPNT_MAX, 200);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private properties
|
|
|
|
*/
|
|
|
|
/** @var ManiaControl $maniaControl */
|
|
|
|
private $maniaControl = null;
|
2014-05-17 14:36:25 +02:00
|
|
|
// Added to check if status of player changed
|
|
|
|
private $specStatus = array();
|
2014-05-04 15:47:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load the plugin
|
|
|
|
*
|
|
|
|
* @param \ManiaControl\ManiaControl $maniaControl
|
|
|
|
* @throws \Exception
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function load(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
|
|
|
|
2014-05-13 16:03:26 +02:00
|
|
|
$allowOthers = $this->maniaControl->settingManager->getSettingValue($this, self::ACCEPT_OTHER_MODES);
|
2014-05-04 15:47:02 +02:00
|
|
|
if (!$allowOthers && $this->maniaControl->server->titleId != 'SMStormRoyal@nadeolabs') {
|
|
|
|
$error = 'This plugin only supports Royal (check Settings)!';
|
|
|
|
throw new \Exception($error);
|
|
|
|
}
|
2014-05-08 20:51:28 +02:00
|
|
|
|
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'changePointlimit');
|
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'changePointlimit');
|
2014-05-17 14:36:25 +02:00
|
|
|
// added to check if player enters or leaves specmode
|
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERINFOCHANGED, $this, 'checkStatus');
|
|
|
|
// added to check if scriptsettings have changed and act on it.
|
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'handleSettingChangedCallback');
|
|
|
|
// Added to add additional pointslimit check on beginning of the round.
|
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_MODESCRIPTCALLBACK, $this, 'handleCallbacks');
|
|
|
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_MODESCRIPTCALLBACKARRAY, $this, 'handleCallbacks');
|
|
|
|
|
|
|
|
// Added to fill variable with current player status
|
|
|
|
foreach($this->maniaControl->playerManager->getPlayers() as $player) {
|
|
|
|
if ($player->isSpectator) {
|
|
|
|
$this->specStatus[$player->login]=1;
|
|
|
|
} else {
|
|
|
|
$this->specStatus[$player->login]=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->changePointlimit();
|
2014-05-04 15:47:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unload the plugin and its resources
|
|
|
|
*/
|
|
|
|
public function unload() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get plugin id
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public static function getId() {
|
|
|
|
return self::ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Plugin Name
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function getName() {
|
|
|
|
return 'Dynamic Pointlimit Plugin';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Plugin Version
|
|
|
|
*
|
|
|
|
* @return float
|
|
|
|
*/
|
|
|
|
public static function getVersion() {
|
|
|
|
return self::VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Plugin Author
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function getAuthor() {
|
|
|
|
return 'TheM';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Plugin Description
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function getDescription() {
|
|
|
|
return 'Plugin offers a dynamic pointlimit according to the amount of players on the server.';
|
|
|
|
}
|
2014-05-17 14:36:25 +02:00
|
|
|
|
|
|
|
// Handle Beginround
|
|
|
|
public function handleCallbacks(array $callback) {
|
|
|
|
$callbackName = $callback[1][0];
|
|
|
|
switch($callbackName) {
|
|
|
|
|
|
|
|
// ROYAL
|
|
|
|
case 'LibXmlRpc_BeginRound':
|
|
|
|
|
|
|
|
$this->changePointlimit();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle scriptsettings changes
|
|
|
|
public function handleSettingChangedCallback($settingClass) {
|
|
|
|
if ($settingClass !== get_class()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->changePointlimit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// on player info changed, this checks to see if it is about the spectator status
|
|
|
|
public function checkStatus(array $callback) {
|
|
|
|
$specStatus = (int)$callback[1][0]['SpectatorStatus'];
|
|
|
|
$login = $callback[1][0]['Login'];
|
|
|
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
|
|
|
|
|
|
|
if($this->specStatus[$login] != $specStatus)
|
|
|
|
{
|
|
|
|
$this->changePointlimit();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-05-04 15:47:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function called on player connect and disconnect, changing the pointlimit.
|
|
|
|
*
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
2014-05-17 14:36:25 +02:00
|
|
|
public function changePointlimit() {
|
2014-05-04 15:47:02 +02:00
|
|
|
$numberOfPlayers = 0;
|
|
|
|
$numberOfSpectators = 0;
|
2014-05-17 14:36:25 +02:00
|
|
|
|
2014-05-04 15:47:02 +02:00
|
|
|
|
|
|
|
/** @var Player $player */
|
|
|
|
foreach($this->maniaControl->playerManager->getPlayers() as $player) {
|
|
|
|
if ($player->isSpectator) {
|
2014-05-17 14:36:25 +02:00
|
|
|
$this->specStatus[$player->login]=1; // used for player status changes
|
2014-05-04 15:47:02 +02:00
|
|
|
$numberOfSpectators++;
|
|
|
|
} else {
|
|
|
|
$numberOfPlayers++;
|
2014-05-17 14:36:25 +02:00
|
|
|
$this->specStatus[$player->login]=0; // used for player status changes
|
2014-05-04 15:47:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-13 16:03:26 +02:00
|
|
|
$pointlimit = ($numberOfPlayers * $this->maniaControl->settingManager->getSettingValue($this, self::DYNPNT_MULTIPLIER)) + $this->maniaControl->settingManager->getSettingValue($this, self::DYNPNT_OFFSET);
|
2014-05-04 15:47:02 +02:00
|
|
|
|
2014-05-13 16:03:26 +02:00
|
|
|
$min_value = $this->maniaControl->settingManager->getSettingValue($this, self::DYNPNT_MIN);
|
|
|
|
$max_value = $this->maniaControl->settingManager->getSettingValue($this, self::DYNPNT_MAX);
|
2014-05-04 15:47:02 +02:00
|
|
|
if ($pointlimit < $min_value) {
|
|
|
|
$pointlimit = $min_value;
|
|
|
|
}
|
|
|
|
if ($pointlimit > $max_value) {
|
|
|
|
$pointlimit = $max_value;
|
|
|
|
}
|
2014-05-17 14:36:25 +02:00
|
|
|
// added to only change the pointlimit if it needs changing
|
|
|
|
$setting = $this->maniaControl->client->getModeScriptSettings(); // get current pointlimit
|
|
|
|
$old = $setting['S_MapPointsLimit'];
|
|
|
|
|
|
|
|
if ( $old != $pointlimit)
|
|
|
|
{
|
|
|
|
try{
|
|
|
|
$this->maniaControl->client->setModeScriptSettings(array('S_MapPointsLimit' => $pointlimit));
|
|
|
|
}catch(FaultException $e){
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->maniaControl->chat->sendChat('$<$fffPointlimit changed to : $> '.$pointlimit ." (was $old)"); // notice about pointlimit change
|
2014-05-08 19:58:12 +02:00
|
|
|
}
|
|
|
|
|
2014-05-04 15:47:02 +02:00
|
|
|
}
|
2014-05-17 14:36:25 +02:00
|
|
|
}
|