applied common formatting
This commit is contained in:
@@ -7,9 +7,9 @@ use ManiaControl\Formatter;
|
||||
/**
|
||||
* Player Model Class
|
||||
*
|
||||
* @author kremsy & steeffeen
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class Player {
|
||||
/*
|
||||
@@ -72,7 +72,7 @@ class Player {
|
||||
$this->pid = $mpPlayer->playerId;
|
||||
$this->login = $mpPlayer->login;
|
||||
$this->nickname = Formatter::stripDirtyCodes($mpPlayer->nickName);
|
||||
$this->rawNickname = $mpPlayer->nickName;
|
||||
$this->rawNickname = $mpPlayer->nickName;
|
||||
$this->path = $mpPlayer->path;
|
||||
$this->language = $mpPlayer->language;
|
||||
$this->avatar = $mpPlayer->avatar['FileName'];
|
||||
|
@@ -21,8 +21,8 @@ use Maniaplanet\DedicatedServer\Xmlrpc\PlayerNotIgnoredException;
|
||||
/**
|
||||
* Player Actions Class
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class PlayerActions {
|
||||
@@ -70,50 +70,6 @@ class PlayerActions {
|
||||
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_FORCE_PLAYER_SPEC, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force a Player to Play
|
||||
*
|
||||
* @param string $adminLogin
|
||||
* @param string $targetLogin
|
||||
* @param bool $userIsAbleToSelect
|
||||
* @param bool $displayAnnouncement
|
||||
* @internal param int $type
|
||||
*/
|
||||
public function forcePlayerToPlay($adminLogin, $targetLogin, $userIsAbleToSelect = true, $displayAnnouncement = true) {
|
||||
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
|
||||
if (!$this->maniaControl->authenticationManager->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_PLAY)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
|
||||
return;
|
||||
}
|
||||
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
|
||||
if (!$target) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_PLAYER);
|
||||
} catch(FaultException $e) {
|
||||
//TODO exception 'There are too many players' appeared 28.04.2014, wait for more before add to faultexception
|
||||
$this->maniaControl->chat->sendException($e, $admin->login);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($userIsAbleToSelect) {
|
||||
try {
|
||||
$this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_USER_SELECTABLE);
|
||||
} catch(Exception $e) {
|
||||
$this->maniaControl->chat->sendException($e, $admin->login);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Announce force
|
||||
if ($displayAnnouncement) {
|
||||
$chatMessage = '$<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> to Play!';
|
||||
$this->maniaControl->chat->sendInformation($chatMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Force a Player to a certain Team
|
||||
*
|
||||
@@ -138,7 +94,7 @@ class PlayerActions {
|
||||
|
||||
try {
|
||||
$this->maniaControl->client->forcePlayerTeam($target->login, $teamId);
|
||||
} catch(NotInTeamModeException $e) {
|
||||
} catch (NotInTeamModeException $e) {
|
||||
$this->forcePlayerToPlay($adminLogin, $targetLogin);
|
||||
return;
|
||||
}
|
||||
@@ -157,6 +113,50 @@ class PlayerActions {
|
||||
$this->maniaControl->log($chatMessage, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Force a Player to Play
|
||||
*
|
||||
* @param string $adminLogin
|
||||
* @param string $targetLogin
|
||||
* @param bool $userIsAbleToSelect
|
||||
* @param bool $displayAnnouncement
|
||||
* @internal param int $type
|
||||
*/
|
||||
public function forcePlayerToPlay($adminLogin, $targetLogin, $userIsAbleToSelect = true, $displayAnnouncement = true) {
|
||||
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
|
||||
if (!$this->maniaControl->authenticationManager->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_PLAY)) {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
|
||||
return;
|
||||
}
|
||||
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
|
||||
if (!$target) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_PLAYER);
|
||||
} catch (FaultException $e) {
|
||||
//TODO exception 'There are too many players' appeared 28.04.2014, wait for more before add to faultexception
|
||||
$this->maniaControl->chat->sendException($e, $admin->login);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($userIsAbleToSelect) {
|
||||
try {
|
||||
$this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_USER_SELECTABLE);
|
||||
} catch (Exception $e) {
|
||||
$this->maniaControl->chat->sendException($e, $admin->login);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Announce force
|
||||
if ($displayAnnouncement) {
|
||||
$chatMessage = '$<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> to Play!';
|
||||
$this->maniaControl->chat->sendInformation($chatMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Force a Player to Spectator
|
||||
*
|
||||
@@ -179,7 +179,7 @@ class PlayerActions {
|
||||
|
||||
try {
|
||||
$this->maniaControl->client->forceSpectator($target->login, $spectatorState);
|
||||
} catch(Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$this->maniaControl->chat->sendException($e, $admin->login);
|
||||
return;
|
||||
}
|
||||
@@ -193,7 +193,7 @@ class PlayerActions {
|
||||
// Free player slot
|
||||
try {
|
||||
$this->maniaControl->client->spectatorReleasePlayerSlot($target->login);
|
||||
} catch(PlayerIsNotSpectatorException $e) {
|
||||
} catch (PlayerIsNotSpectatorException $e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,9 +217,9 @@ class PlayerActions {
|
||||
return;
|
||||
}
|
||||
|
||||
try{
|
||||
try {
|
||||
$this->maniaControl->client->unIgnore($targetLogin);
|
||||
}catch(PlayerNotIgnoredException $e){
|
||||
} catch (PlayerNotIgnoredException $e) {
|
||||
$this->maniaControl->chat->sendError("Player is not ignored!");
|
||||
return;
|
||||
}
|
||||
@@ -249,9 +249,9 @@ class PlayerActions {
|
||||
return;
|
||||
}
|
||||
|
||||
try{
|
||||
try {
|
||||
$this->maniaControl->client->ignore($targetLogin);
|
||||
}catch(PlayerAlreadyIgnoredException $e){
|
||||
} catch (PlayerAlreadyIgnoredException $e) {
|
||||
$this->maniaControl->chat->sendError("Player already ignored!");
|
||||
return;
|
||||
}
|
||||
@@ -322,7 +322,7 @@ class PlayerActions {
|
||||
$label->setTextColor('f00');
|
||||
|
||||
$y = $height / 2 - 15;
|
||||
foreach($message as $line) {
|
||||
foreach ($message as $line) {
|
||||
// Message lines
|
||||
$label = new Label_Text();
|
||||
$frame->add($label);
|
||||
@@ -368,7 +368,7 @@ class PlayerActions {
|
||||
} else {
|
||||
$this->maniaControl->client->kick($target->login, $message);
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$this->maniaControl->chat->sendException($e, $admin->login);
|
||||
return;
|
||||
}
|
||||
@@ -495,7 +495,7 @@ class PlayerActions {
|
||||
*/
|
||||
public function isPlayerMuted($login) {
|
||||
$ignoreList = $this->maniaControl->client->getIgnoreList(100, 0);
|
||||
foreach($ignoreList as $ignoredPlayers) {
|
||||
foreach ($ignoreList as $ignoredPlayers) {
|
||||
if ($ignoredPlayers->login == $login) {
|
||||
return true;
|
||||
}
|
||||
|
@@ -15,9 +15,9 @@ use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||
/**
|
||||
* Class offering various Admin Commands related to Players
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, CallbackListener {
|
||||
/*
|
||||
@@ -74,7 +74,7 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
|
||||
|
||||
/**
|
||||
* Handle TeamStatusChanged
|
||||
*
|
||||
*
|
||||
* @param bool $teamMode
|
||||
*/
|
||||
public function teamStatusChanged($teamMode) {
|
||||
@@ -103,7 +103,7 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
|
||||
|
||||
try {
|
||||
$this->maniaControl->client->autoTeamBalance();
|
||||
} catch(Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$this->maniaControl->errorHandler->triggerDebugNotice("PlayerCommands Debug Line 112: " . $e->getMessage());
|
||||
// TODO: only catch 'not in team mode' exception - throw others (like connection error)
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
||||
|
@@ -8,8 +8,8 @@ use ManiaControl\ManiaControl;
|
||||
/**
|
||||
* Player Data Manager
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class PlayerDataManager {
|
||||
@@ -42,6 +42,80 @@ class PlayerDataManager {
|
||||
$this->storeMetaData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize necessary database tables
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function initTables() {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$defaultType = "'" . self::TYPE_STRING . "'";
|
||||
$typeSet = $defaultType . ",'" . self::TYPE_INT . "','" . self::TYPE_REAL . "','" . self::TYPE_BOOL . "','" . self::TYPE_ARRAY . "'";
|
||||
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_PLAYERDATAMETADATA . "` (
|
||||
`dataId` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`class` varchar(100) NOT NULL,
|
||||
`dataName` varchar(100) NOT NULL,
|
||||
`type` set({$typeSet}) NOT NULL DEFAULT {$defaultType},
|
||||
`defaultValue` varchar(150) NOT NULL,
|
||||
`description` varchar(150) NOT NULL,
|
||||
PRIMARY KEY (`dataId`),
|
||||
UNIQUE KEY `name` (`class`, `dataName`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Player-Data MetaData' AUTO_INCREMENT=1;";
|
||||
$statement = $mysqli->prepare($query);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error, E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
$statement->execute();
|
||||
if ($statement->error) {
|
||||
trigger_error($statement->error, E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
$statement->close();
|
||||
|
||||
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_PLAYERDATA . "` (
|
||||
`index` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`serverIndex` int(11) NOT NULL,
|
||||
`playerId` int(11) NOT NULL,
|
||||
`dataId` int(11) NOT NULL,
|
||||
`value` varchar(150) NOT NULL,
|
||||
`changed` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`index`),
|
||||
UNIQUE KEY `unique` (`dataId`,`playerId`,`serverIndex`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Player Data' AUTO_INCREMENT=1;";
|
||||
$statement = $mysqli->prepare($query);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error, E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
$statement->execute();
|
||||
if ($statement->error) {
|
||||
trigger_error($statement->error, E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
$statement->close();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store Meta Data from the Database in the Ram
|
||||
*/
|
||||
private function storeMetaData() {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
|
||||
$query = "SELECT * FROM `" . self::TABLE_PLAYERDATAMETADATA . "`;";
|
||||
$result = $mysqli->query($query);
|
||||
if (!$result) {
|
||||
trigger_error($mysqli->error);
|
||||
return;
|
||||
}
|
||||
|
||||
while ($row = $result->fetch_object()) {
|
||||
$this->metaData[$row->class . $row->dataName] = $row;
|
||||
}
|
||||
$result->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys the stored PlayerData (Method get called by PlayerManager, so don't call it anywhere else)
|
||||
*
|
||||
@@ -95,31 +169,55 @@ class PlayerDataManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Store Meta Data from the Database in the Ram
|
||||
* Get Class Name of a Parameter
|
||||
*
|
||||
* @param mixed $param
|
||||
* @return string
|
||||
*/
|
||||
private function storeMetaData() {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
|
||||
$query = "SELECT * FROM `" . self::TABLE_PLAYERDATAMETADATA . "`;";
|
||||
$result = $mysqli->query($query);
|
||||
if (!$result) {
|
||||
trigger_error($mysqli->error);
|
||||
return;
|
||||
private function getClassName($param) {
|
||||
if (is_object($param)) {
|
||||
return get_class($param);
|
||||
}
|
||||
|
||||
while($row = $result->fetch_object()) {
|
||||
$this->metaData[$row->class . $row->dataName] = $row;
|
||||
if (is_string($param)) {
|
||||
return $param;
|
||||
}
|
||||
$result->close();
|
||||
trigger_error('Invalid class param. ' . $param);
|
||||
return (string)$param;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Type of a Parameter
|
||||
*
|
||||
* @param mixed $param
|
||||
* @return string
|
||||
*/
|
||||
private function getType($param) {
|
||||
if (is_int($param)) {
|
||||
return self::TYPE_INT;
|
||||
}
|
||||
if (is_real($param)) {
|
||||
return self::TYPE_REAL;
|
||||
}
|
||||
if (is_bool($param)) {
|
||||
return self::TYPE_BOOL;
|
||||
}
|
||||
if (is_string($param)) {
|
||||
return self::TYPE_STRING;
|
||||
}
|
||||
if (is_array($param)) {
|
||||
return self::TYPE_ARRAY;
|
||||
}
|
||||
trigger_error('Unsupported setting type. ' . print_r($param, true));
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Player Data
|
||||
*
|
||||
* @param mixed $object
|
||||
* @param string $dataName
|
||||
* @param Player $player
|
||||
* @param int $serverIndex
|
||||
* @param mixed $object
|
||||
* @param string $dataName
|
||||
* @param Player $player
|
||||
* @param int $serverIndex
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function getPlayerData($object, $dataName, Player $player, $serverIndex = -1) {
|
||||
@@ -172,10 +270,10 @@ class PlayerDataManager {
|
||||
/**
|
||||
* Set a PlayerData to a specific defined statMetaData
|
||||
*
|
||||
* @param mixed $object
|
||||
* @param string $dataName
|
||||
* @param Player $player
|
||||
* @param mixed $value
|
||||
* @param mixed $object
|
||||
* @param string $dataName
|
||||
* @param Player $player
|
||||
* @param mixed $value
|
||||
* @param int $serverIndex (let it empty if its global)
|
||||
* @return bool
|
||||
*/
|
||||
@@ -237,87 +335,6 @@ class PlayerDataManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize necessary database tables
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function initTables() {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$defaultType = "'" . self::TYPE_STRING . "'";
|
||||
$typeSet = $defaultType . ",'" . self::TYPE_INT . "','" . self::TYPE_REAL . "','" . self::TYPE_BOOL . "','" . self::TYPE_ARRAY . "'";
|
||||
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_PLAYERDATAMETADATA . "` (
|
||||
`dataId` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`class` varchar(100) NOT NULL,
|
||||
`dataName` varchar(100) NOT NULL,
|
||||
`type` set({$typeSet}) NOT NULL DEFAULT {$defaultType},
|
||||
`defaultValue` varchar(150) NOT NULL,
|
||||
`description` varchar(150) NOT NULL,
|
||||
PRIMARY KEY (`dataId`),
|
||||
UNIQUE KEY `name` (`class`, `dataName`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Player-Data MetaData' AUTO_INCREMENT=1;";
|
||||
$statement = $mysqli->prepare($query);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error, E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
$statement->execute();
|
||||
if ($statement->error) {
|
||||
trigger_error($statement->error, E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
$statement->close();
|
||||
|
||||
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_PLAYERDATA . "` (
|
||||
`index` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`serverIndex` int(11) NOT NULL,
|
||||
`playerId` int(11) NOT NULL,
|
||||
`dataId` int(11) NOT NULL,
|
||||
`value` varchar(150) NOT NULL,
|
||||
`changed` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`index`),
|
||||
UNIQUE KEY `unique` (`dataId`,`playerId`,`serverIndex`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Player Data' AUTO_INCREMENT=1;";
|
||||
$statement = $mysqli->prepare($query);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error, E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
$statement->execute();
|
||||
if ($statement->error) {
|
||||
trigger_error($statement->error, E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
$statement->close();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Type of a Parameter
|
||||
*
|
||||
* @param mixed $param
|
||||
* @return string
|
||||
*/
|
||||
private function getType($param) {
|
||||
if (is_int($param)) {
|
||||
return self::TYPE_INT;
|
||||
}
|
||||
if (is_real($param)) {
|
||||
return self::TYPE_REAL;
|
||||
}
|
||||
if (is_bool($param)) {
|
||||
return self::TYPE_BOOL;
|
||||
}
|
||||
if (is_string($param)) {
|
||||
return self::TYPE_STRING;
|
||||
}
|
||||
if (is_array($param)) {
|
||||
return self::TYPE_ARRAY;
|
||||
}
|
||||
trigger_error('Unsupported setting type. ' . print_r($param, true));
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cast a Setting to the given Type
|
||||
*
|
||||
@@ -344,21 +361,4 @@ class PlayerDataManager {
|
||||
trigger_error('Unsupported setting type. ' . print_r($type, true));
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Class Name of a Parameter
|
||||
*
|
||||
* @param mixed $param
|
||||
* @return string
|
||||
*/
|
||||
private function getClassName($param) {
|
||||
if (is_object($param)) {
|
||||
return get_class($param);
|
||||
}
|
||||
if (is_string($param)) {
|
||||
return $param;
|
||||
}
|
||||
trigger_error('Invalid class param. ' . $param);
|
||||
return (string)$param;
|
||||
}
|
||||
}
|
@@ -19,9 +19,9 @@ use Maniaplanet\DedicatedServer\Structures\Player;
|
||||
/**
|
||||
* Player Detailed Page
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class PlayerDetailed {
|
||||
/*
|
||||
@@ -230,7 +230,7 @@ class PlayerDetailed {
|
||||
$x = -$this->width / 2 + 52;
|
||||
$id = 1;
|
||||
|
||||
foreach($playerStats as $stat) {
|
||||
foreach ($playerStats as $stat) {
|
||||
$statProperties = $stat[0];
|
||||
$value = $stat[1];
|
||||
|
||||
|
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace ManiaControl\Players;
|
||||
|
||||
use Maniaplanet\DedicatedServer\Structures\Player;
|
||||
use MCTeam\CustomVotesPlugin;
|
||||
use FML\Controls\Control;
|
||||
use FML\Controls\Frame;
|
||||
use FML\Controls\Labels\Label_Button;
|
||||
@@ -24,14 +22,16 @@ use ManiaControl\Formatter;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Manialinks\ManialinkManager;
|
||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
use Maniaplanet\DedicatedServer\Structures\Player;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\LoginUnknownException;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\PlayerIsNotSpectatorException;
|
||||
use MCTeam\CustomVotesPlugin;
|
||||
|
||||
/**
|
||||
* PlayerList Widget Class
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class PlayerList implements ManialinkPageAnswerListener, CallbackListener, TimerListener {
|
||||
@@ -97,6 +97,39 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
$this->playersListShown[$player->login] = $showStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset the player if he opened another Main Widget
|
||||
*
|
||||
* @param Player $player
|
||||
* @param $openedWidget
|
||||
*/
|
||||
public function handleWidgetOpened(Player $player, $openedWidget) {
|
||||
//unset when another main widget got opened
|
||||
if ($openedWidget != 'PlayerList') {
|
||||
unset($this->playersListShown[$player->login]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the widget
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function closeWidget(Player $player) {
|
||||
unset($this->playersListShown[$player->login]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the player advanced widget widget
|
||||
*
|
||||
* @param array $callback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function closePlayerAdvancedWidget(array $callback, Player $player) {
|
||||
$this->playersListShown[$player->login] = self::SHOWN_MAIN_WINDOW;
|
||||
$this->showPlayerList($player); // overwrite the manialink
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the PlayerList Widget to the Player
|
||||
*
|
||||
@@ -116,8 +149,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
//create manialink
|
||||
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
||||
$script = $maniaLink->getScript();
|
||||
$paging = new Paging();
|
||||
$script->addFeature($paging);
|
||||
$paging = new Paging();
|
||||
$script->addFeature($paging);
|
||||
|
||||
// Main frame
|
||||
$frame = $this->maniaControl->manialinkManager->styleManager->getDefaultListFrame($script, $pagesId);
|
||||
@@ -145,7 +178,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
$i = 1;
|
||||
$y = $height / 2 - 10;
|
||||
$pageFrames = array();
|
||||
foreach($players as $listPlayer) {
|
||||
foreach ($players as $listPlayer) {
|
||||
/** @var Player $listPlayer * */
|
||||
if (!isset($pageFrame)) {
|
||||
$pageFrame = new Frame();
|
||||
@@ -155,7 +188,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
}
|
||||
array_push($pageFrames, $pageFrame);
|
||||
$y = $height / 2 - 10;
|
||||
$paging->addPage($pageFrame);
|
||||
$paging->addPage($pageFrame);
|
||||
}
|
||||
|
||||
$path = $listPlayer->getProvince();
|
||||
@@ -194,7 +227,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
$teamQuad->setZ(0.1);
|
||||
$teamQuad->setSize(3.8, 3.8);
|
||||
|
||||
switch($listPlayer->teamId) {
|
||||
switch ($listPlayer->teamId) {
|
||||
case 0:
|
||||
$teamQuad->setSubStyle($teamQuad::SUBSTYLE_1);
|
||||
break;
|
||||
@@ -222,7 +255,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
$countryQuad->setSize(4, 4);
|
||||
$countryQuad->setZ(1);
|
||||
|
||||
$countryQuad->addTooltipLabelFeature($descriptionLabel, '$<' . $listPlayer->nickname . '$> from ' . $listPlayer->path);
|
||||
$countryQuad->addTooltipLabelFeature($descriptionLabel, '$<' . $listPlayer->nickname . '$> from ' . $listPlayer->path);
|
||||
}
|
||||
|
||||
// Level Quad
|
||||
@@ -241,8 +274,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
$rightLabel->setText($this->maniaControl->authenticationManager->getAuthLevelAbbreviation($listPlayer->authLevel));
|
||||
$rightLabel->setTextColor("fff");
|
||||
|
||||
$description = $this->maniaControl->authenticationManager->getAuthLevelName($listPlayer) . " " . $listPlayer->nickname;
|
||||
$rightLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
$description = $this->maniaControl->authenticationManager->getAuthLevelName($listPlayer) . " " . $listPlayer->nickname;
|
||||
$rightLabel->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
|
||||
// Player Statistics
|
||||
$playerQuad = new Quad_Icons64x64_1();
|
||||
@@ -252,8 +285,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
$playerQuad->setSubStyle($playerQuad::SUBSTYLE_TrackInfo);
|
||||
$playerQuad->setSize(2.7, 2.7);
|
||||
$playerQuad->setAction(self::ACTION_OPEN_PLAYER_DETAILED . "." . $listPlayer->login);
|
||||
$description = 'View Statistics of $<'.$listPlayer->nickname. '$>';
|
||||
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
$description = 'View Statistics of $<' . $listPlayer->nickname . '$>';
|
||||
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
|
||||
// Camera Quad
|
||||
$playerQuad = new Quad_UIConstruction_Buttons();
|
||||
@@ -262,8 +295,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
$playerQuad->setZ(3);
|
||||
$playerQuad->setSubStyle($playerQuad::SUBSTYLE_Camera);
|
||||
$playerQuad->setSize(3.8, 3.8);
|
||||
$description = 'Spectate $<'.$listPlayer->nickname.'$>';
|
||||
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
$description = 'Spectate $<' . $listPlayer->nickname . '$>';
|
||||
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
$playerQuad->setAction(self::ACTION_SPECTATE_PLAYER . "." . $listPlayer->login);
|
||||
|
||||
// Player Profile Quad
|
||||
@@ -273,11 +306,11 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
$playerQuad->setZ(3);
|
||||
$playerQuad->setSubStyle($playerQuad::SUBSTYLE_Author);
|
||||
$playerQuad->setSize(3.8, 3.8);
|
||||
$playerQuad->addPlayerProfileFeature($listPlayer->login);
|
||||
$playerQuad->addPlayerProfileFeature($listPlayer->login);
|
||||
|
||||
// Description Label
|
||||
$description = 'View Player Profile of $<' . $listPlayer->nickname.'$>';
|
||||
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
$description = 'View Player Profile of $<' . $listPlayer->nickname . '$>';
|
||||
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
|
||||
if ($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
|
||||
// Further Player actions Quad
|
||||
@@ -290,8 +323,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
$playerQuad->setAction(self::ACTION_PLAYER_ADV . "." . $listPlayer->login);
|
||||
|
||||
// Description Label
|
||||
$description = 'Advanced Player Actions for $<' . $listPlayer->nickname.'$>';
|
||||
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
$description = 'Advanced Player Actions for $<' . $listPlayer->nickname . '$>';
|
||||
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
}
|
||||
|
||||
if ($this->maniaControl->server->isTeamMode()) {
|
||||
@@ -306,8 +339,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
$redQuad->setAction(self::ACTION_FORCE_RED . "." . $listPlayer->login);
|
||||
|
||||
// Force to Red-Team Description Label
|
||||
$description = 'Force $<' . $listPlayer->nickname . '$> to Red Team!';
|
||||
$redQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
$description = 'Force $<' . $listPlayer->nickname . '$> to Red Team!';
|
||||
$redQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
|
||||
// Force to Blue-Team Quad
|
||||
$blueQuad = new Quad_Emblems();
|
||||
@@ -319,8 +352,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
$blueQuad->setAction(self::ACTION_FORCE_BLUE . "." . $listPlayer->login);
|
||||
|
||||
// Force to Blue-Team Description Label
|
||||
$description = 'Force $<' . $listPlayer->nickname . '$> to Blue Team!';
|
||||
$blueQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
$description = 'Force $<' . $listPlayer->nickname . '$> to Blue Team!';
|
||||
$blueQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
|
||||
} else if ($this->maniaControl->pluginManager->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)) {
|
||||
// Kick Player Vote
|
||||
@@ -332,8 +365,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
$kickQuad->setSize(3.8, 3.8);
|
||||
$kickQuad->setAction(self::ACTION_KICK_PLAYER_VOTE . "." . $listPlayer->login);
|
||||
|
||||
$description = 'Start a Kick Vote on $<' . $listPlayer->nickname . '$>!';
|
||||
$kickQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
$description = 'Start a Kick Vote on $<' . $listPlayer->nickname . '$>!';
|
||||
$kickQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
}
|
||||
} else {
|
||||
if ($this->maniaControl->authenticationManager->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_PLAY)) {
|
||||
@@ -346,8 +379,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
$playQuad->setSize(3.8, 3.8);
|
||||
$playQuad->setAction(self::ACTION_FORCE_PLAY . "." . $listPlayer->login);
|
||||
|
||||
$description = 'Force $<' . $listPlayer->nickname . '$> to Play!';
|
||||
$playQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
$description = 'Force $<' . $listPlayer->nickname . '$> to Play!';
|
||||
$playQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,8 +395,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
$spectatorQuad->setAction(self::ACTION_FORCE_SPEC . "." . $listPlayer->login);
|
||||
|
||||
// Force to Spectator Description Label
|
||||
$description = 'Force $<' . $listPlayer->nickname . '$> to Spectator!';
|
||||
$spectatorQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
$description = 'Force $<' . $listPlayer->nickname . '$> to Spectator!';
|
||||
$spectatorQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
} else if ($this->maniaControl->pluginManager->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)) {
|
||||
// Force to Spectator Quad
|
||||
$spectatorQuad = new Quad_BgRaceScore2();
|
||||
@@ -375,8 +408,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
$spectatorQuad->setAction(self::ACTION_FORCE_SPEC_VOTE . "." . $listPlayer->login);
|
||||
|
||||
// Force to Spectator Description Label
|
||||
$description = 'Start a Vote to force $<' . $listPlayer->nickname . '$> to Spectator!';
|
||||
$spectatorQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
$description = 'Start a Vote to force $<' . $listPlayer->nickname . '$> to Spectator!';
|
||||
$spectatorQuad->addTooltipLabelFeature($descriptionLabel, $description);
|
||||
}
|
||||
|
||||
$y -= 4;
|
||||
@@ -396,20 +429,6 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $player, 'PlayerList');
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the Advanced Player Window
|
||||
*
|
||||
* @param Player $caller
|
||||
* @param $login
|
||||
*/
|
||||
public function advancedPlayerWidget(Player $caller, $login) {
|
||||
// Set status to target player login
|
||||
$this->playersListShown[$caller->login] = $login;
|
||||
|
||||
// Reopen playerlist
|
||||
$this->showPlayerList($caller);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extra window with special actions on players like warn,kick, ban, authorization levels...
|
||||
*
|
||||
@@ -610,39 +629,6 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
return $frame;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset the player if he opened another Main Widget
|
||||
*
|
||||
* @param Player $player
|
||||
* @param $openedWidget
|
||||
*/
|
||||
public function handleWidgetOpened(Player $player, $openedWidget) {
|
||||
//unset when another main widget got opened
|
||||
if ($openedWidget != 'PlayerList') {
|
||||
unset($this->playersListShown[$player->login]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the widget
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function closeWidget(Player $player) {
|
||||
unset($this->playersListShown[$player->login]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the player advanced widget widget
|
||||
*
|
||||
* @param array $callback
|
||||
* @param Player $player
|
||||
*/
|
||||
public function closePlayerAdvancedWidget(array $callback, Player $player) {
|
||||
$this->playersListShown[$player->login] = self::SHOWN_MAIN_WINDOW;
|
||||
$this->showPlayerList($player); // overwrite the manialink
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on ManialinkPageAnswer
|
||||
*
|
||||
@@ -659,12 +645,12 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
$adminLogin = $callback[1][1];
|
||||
$targetLogin = $actionArray[2];
|
||||
|
||||
switch($action) {
|
||||
switch ($action) {
|
||||
case self::ACTION_SPECTATE_PLAYER:
|
||||
try {
|
||||
$this->maniaControl->client->forceSpectator($adminLogin, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
|
||||
$this->maniaControl->client->forceSpectatorTarget($adminLogin, $targetLogin, 1);
|
||||
} catch(PlayerIsNotSpectatorException $e) {
|
||||
} catch (PlayerIsNotSpectatorException $e) {
|
||||
}
|
||||
break;
|
||||
case self::ACTION_OPEN_PLAYER_DETAILED:
|
||||
@@ -736,7 +722,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
try {
|
||||
$self->maniaControl->client->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
|
||||
$self->maniaControl->client->spectatorReleasePlayerSlot($target->login);
|
||||
} catch(PlayerIsNotSpectatorException $e) {
|
||||
} catch (PlayerIsNotSpectatorException $e) {
|
||||
}
|
||||
});
|
||||
break;
|
||||
@@ -760,20 +746,34 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
$message = '$39F You got kicked due a Public vote!$z ';
|
||||
try {
|
||||
$self->maniaControl->client->kick($target->login, $message);
|
||||
} catch(LoginUnknownException $e) {
|
||||
} catch (LoginUnknownException $e) {
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the Advanced Player Window
|
||||
*
|
||||
* @param Player $caller
|
||||
* @param $login
|
||||
*/
|
||||
public function advancedPlayerWidget(Player $caller, $login) {
|
||||
// Set status to target player login
|
||||
$this->playersListShown[$caller->login] = $login;
|
||||
|
||||
// Reopen playerlist
|
||||
$this->showPlayerList($caller);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reopen the widget on PlayerInfoChanged / Player Connect and Disconnect
|
||||
*
|
||||
* @param Player $player
|
||||
*/
|
||||
public function updateWidget(Player $player) {
|
||||
foreach($this->playersListShown as $login => $shown) {
|
||||
foreach ($this->playersListShown as $login => $shown) {
|
||||
if (!$shown) {
|
||||
continue;
|
||||
}
|
||||
|
@@ -14,8 +14,8 @@ use Maniaplanet\DedicatedServer\Xmlrpc\LoginUnknownException;
|
||||
/**
|
||||
* Class managing Players
|
||||
*
|
||||
* @author kremsy & steeffeen
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class PlayerManager implements CallbackListener, TimerListener {
|
||||
@@ -112,7 +112,7 @@ class PlayerManager implements CallbackListener, TimerListener {
|
||||
public function onInit() {
|
||||
// Add all players
|
||||
$players = $this->maniaControl->client->getPlayerList(300, 0, 2);
|
||||
foreach($players as $playerItem) {
|
||||
foreach ($players as $playerItem) {
|
||||
if ($playerItem->playerId <= 0) {
|
||||
continue;
|
||||
}
|
||||
@@ -141,183 +141,6 @@ class PlayerManager implements CallbackListener, TimerListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle playerConnect callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function playerConnect(array $callback) {
|
||||
$login = $callback[1][0];
|
||||
try {
|
||||
$playerInfo = $this->maniaControl->client->getDetailedPlayerInfo($login);
|
||||
$player = new Player($playerInfo);
|
||||
|
||||
$this->addPlayer($player);
|
||||
} catch(LoginUnknownException $e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle playerDisconnect callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function playerDisconnect(array $callback) {
|
||||
$login = $callback[1][0];
|
||||
$player = $this->removePlayer($login);
|
||||
if (!$player) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Trigger own callback
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERDISCONNECT, $player);
|
||||
|
||||
if ($player->isFakePlayer()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$played = Formatter::formatTimeH(time() - $player->joinTime);
|
||||
$logMessage = "Player left: {$player->login} / {$player->nickname} Playtime: {$played}";
|
||||
$this->maniaControl->log(Formatter::stripCodes($logMessage));
|
||||
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES)) {
|
||||
$this->maniaControl->chat->sendChat('$0f0$<$fff' . $player->nickname . '$> has left the game');
|
||||
}
|
||||
|
||||
//Destroys stored PlayerData, after all Disconnect Callbacks got Handled
|
||||
$this->playerDataManager->destroyPlayerData($player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update PlayerInfo
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function playerInfoChanged(array $callback) {
|
||||
$player = $this->getPlayer($callback[1][0]['Login']);
|
||||
if (!$player) {
|
||||
return;
|
||||
}
|
||||
|
||||
$player->ladderRank = $callback[1][0]["LadderRanking"];
|
||||
$player->teamId = $callback[1][0]["TeamId"];
|
||||
|
||||
//Check if the Player is in a Team, to notify if its a TeamMode or not
|
||||
if ($player->teamId != -1) {
|
||||
$this->maniaControl->server->setTeamMode(true);
|
||||
}
|
||||
|
||||
$prevJoinState = $player->hasJoinedGame;
|
||||
|
||||
$player->updatePlayerFlags($callback[1][0]["Flags"]);
|
||||
$player->updateSpectatorStatus($callback[1][0]["SpectatorStatus"]);
|
||||
|
||||
//Check if Player finished joining the game
|
||||
if ($player->hasJoinedGame && !$prevJoinState) {
|
||||
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()) {
|
||||
$string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0SuperAdmin', 4 => '$0f0MasterAdmin');
|
||||
$chatMessage = '$0f0' . $string[$player->authLevel] . ' $<$fff' . $player->nickname . '$> Nation: $<$fff' . $player->getCountry() . '$> joined!';
|
||||
$this->maniaControl->chat->sendChat($chatMessage);
|
||||
$this->maniaControl->chat->sendInformation('This server uses ManiaControl v' . ManiaControl::VERSION . '!', $player->login);
|
||||
}
|
||||
|
||||
$logMessage = "Player joined: {$player->login} / " . Formatter::stripCodes($player->nickname) . " Nation: " . $player->getCountry() . " IP: {$player->ipAddress}";
|
||||
$this->maniaControl->log($logMessage);
|
||||
|
||||
// Increment the Player Join Count
|
||||
$this->maniaControl->statisticManager->incrementStat(self::STAT_JOIN_COUNT, $player, $this->maniaControl->server->index);
|
||||
|
||||
// Trigger own PlayerJoined callback
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERCONNECT, $player);
|
||||
|
||||
}
|
||||
|
||||
// Trigger own callback
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERINFOCHANGED, $player);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all Players
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPlayers() {
|
||||
return $this->players;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Count of all Player
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPlayerCount() {
|
||||
$count = 0;
|
||||
foreach($this->players as $player) {
|
||||
/** @var Player $player */
|
||||
if (!$player->isSpectator) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Count of all Spectators
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getSpectatorCount() {
|
||||
$count = 0;
|
||||
foreach($this->players as $player) {
|
||||
/** @var Player $player */
|
||||
if ($player->isSpectator) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Player by his index
|
||||
*
|
||||
* @param $index
|
||||
* @param bool $connectedPlayersOnly
|
||||
* @return Player|null
|
||||
*/
|
||||
public function getPlayerByIndex($index, $connectedPlayersOnly = false) {
|
||||
foreach($this->players as $player) {
|
||||
/** @var Player $player */
|
||||
if ($player->index == $index) {
|
||||
return $player;
|
||||
}
|
||||
}
|
||||
|
||||
if ($connectedPlayersOnly) {
|
||||
return null;
|
||||
}
|
||||
//Player is not online -> get Player from Database
|
||||
return $this->getPlayerFromDatabaseByIndex($index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Player by Login
|
||||
*
|
||||
* @param string $login
|
||||
* @param bool $connectedPlayersOnly
|
||||
* @return Player
|
||||
*/
|
||||
public function getPlayer($login, $connectedPlayersOnly = false) {
|
||||
if (!isset($this->players[$login])) {
|
||||
if ($connectedPlayersOnly) {
|
||||
return null;
|
||||
}
|
||||
return $this->getPlayerFromDatabaseByLogin($login);
|
||||
}
|
||||
return $this->players[$login];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a player
|
||||
*
|
||||
@@ -330,99 +153,6 @@ class PlayerManager implements CallbackListener, TimerListener {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Player
|
||||
*
|
||||
* @param string $login
|
||||
* @param bool $savePlayedTime
|
||||
* @return Player $player
|
||||
*/
|
||||
private function removePlayer($login, $savePlayedTime = true) {
|
||||
if (!isset($this->players[$login])) {
|
||||
return null;
|
||||
}
|
||||
$player = $this->players[$login];
|
||||
unset($this->players[$login]);
|
||||
if ($savePlayedTime) {
|
||||
$this->updatePlayedTime($player);
|
||||
}
|
||||
return $player;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get's a Player out of the database
|
||||
*
|
||||
* @param $playerIndex
|
||||
* @return Player $player
|
||||
*/
|
||||
private function getPlayerFromDatabaseByIndex($playerIndex) {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
|
||||
if (!is_numeric($playerIndex)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$query = "SELECT * FROM `" . self::TABLE_PLAYERS . "` WHERE `index` = " . $playerIndex . ";";
|
||||
$result = $mysqli->query($query);
|
||||
if (!$result) {
|
||||
trigger_error($mysqli->error);
|
||||
return null;
|
||||
}
|
||||
|
||||
$row = $result->fetch_object();
|
||||
$result->close();
|
||||
|
||||
if (!isset($row)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$player = new Player(null);
|
||||
$player->index = $playerIndex;
|
||||
$player->login = $row->login;
|
||||
$player->rawNickname = $row->nickname;
|
||||
$player->nickname = Formatter::stripDirtyCodes($player->rawNickname);
|
||||
$player->path = $row->path;
|
||||
$player->authLevel = $row->authLevel;
|
||||
|
||||
return $player;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Player from the Database
|
||||
*
|
||||
* @param string $playerLogin
|
||||
* @return Player
|
||||
*/
|
||||
private function getPlayerFromDatabaseByLogin($playerLogin) {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
|
||||
$query = "SELECT * FROM `" . self::TABLE_PLAYERS . "` WHERE `login` LIKE '" . $mysqli->escape_string($playerLogin) . "';";
|
||||
$result = $mysqli->query($query);
|
||||
if (!$result) {
|
||||
trigger_error($mysqli->error);
|
||||
return null;
|
||||
}
|
||||
|
||||
$row = $result->fetch_object();
|
||||
$result->close();
|
||||
|
||||
if (!isset($row)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$player = new Player(null);
|
||||
$player->index = $row->index;
|
||||
$player->login = $row->login;
|
||||
$player->rawNickname = $row->nickname;
|
||||
$player->nickname = Formatter::stripDirtyCodes($player->rawNickname);
|
||||
$player->path = $row->path;
|
||||
$player->authLevel = $row->authLevel;
|
||||
|
||||
return $player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save player in Database and fill up Object Properties
|
||||
*
|
||||
@@ -481,6 +211,72 @@ class PlayerManager implements CallbackListener, TimerListener {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle playerConnect callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function playerConnect(array $callback) {
|
||||
$login = $callback[1][0];
|
||||
try {
|
||||
$playerInfo = $this->maniaControl->client->getDetailedPlayerInfo($login);
|
||||
$player = new Player($playerInfo);
|
||||
|
||||
$this->addPlayer($player);
|
||||
} catch (LoginUnknownException $e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle playerDisconnect callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function playerDisconnect(array $callback) {
|
||||
$login = $callback[1][0];
|
||||
$player = $this->removePlayer($login);
|
||||
if (!$player) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Trigger own callback
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERDISCONNECT, $player);
|
||||
|
||||
if ($player->isFakePlayer()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$played = Formatter::formatTimeH(time() - $player->joinTime);
|
||||
$logMessage = "Player left: {$player->login} / {$player->nickname} Playtime: {$played}";
|
||||
$this->maniaControl->log(Formatter::stripCodes($logMessage));
|
||||
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES)) {
|
||||
$this->maniaControl->chat->sendChat('$0f0$<$fff' . $player->nickname . '$> has left the game');
|
||||
}
|
||||
|
||||
//Destroys stored PlayerData, after all Disconnect Callbacks got Handled
|
||||
$this->playerDataManager->destroyPlayerData($player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Player
|
||||
*
|
||||
* @param string $login
|
||||
* @param bool $savePlayedTime
|
||||
* @return Player $player
|
||||
*/
|
||||
private function removePlayer($login, $savePlayedTime = true) {
|
||||
if (!isset($this->players[$login])) {
|
||||
return null;
|
||||
}
|
||||
$player = $this->players[$login];
|
||||
unset($this->players[$login]);
|
||||
if ($savePlayedTime) {
|
||||
$this->updatePlayedTime($player);
|
||||
}
|
||||
return $player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update total played time of the player
|
||||
*
|
||||
@@ -495,4 +291,205 @@ class PlayerManager implements CallbackListener, TimerListener {
|
||||
|
||||
return $this->maniaControl->statisticManager->insertStat(self::STAT_SERVERTIME, $player, $this->maniaControl->server->index, $playedTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update PlayerInfo
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function playerInfoChanged(array $callback) {
|
||||
$player = $this->getPlayer($callback[1][0]['Login']);
|
||||
if (!$player) {
|
||||
return;
|
||||
}
|
||||
|
||||
$player->ladderRank = $callback[1][0]["LadderRanking"];
|
||||
$player->teamId = $callback[1][0]["TeamId"];
|
||||
|
||||
//Check if the Player is in a Team, to notify if its a TeamMode or not
|
||||
if ($player->teamId != -1) {
|
||||
$this->maniaControl->server->setTeamMode(true);
|
||||
}
|
||||
|
||||
$prevJoinState = $player->hasJoinedGame;
|
||||
|
||||
$player->updatePlayerFlags($callback[1][0]["Flags"]);
|
||||
$player->updateSpectatorStatus($callback[1][0]["SpectatorStatus"]);
|
||||
|
||||
//Check if Player finished joining the game
|
||||
if ($player->hasJoinedGame && !$prevJoinState) {
|
||||
|
||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()) {
|
||||
$string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0SuperAdmin', 4 => '$0f0MasterAdmin');
|
||||
$chatMessage = '$0f0' . $string[$player->authLevel] . ' $<$fff' . $player->nickname . '$> Nation: $<$fff' . $player->getCountry() . '$> joined!';
|
||||
$this->maniaControl->chat->sendChat($chatMessage);
|
||||
$this->maniaControl->chat->sendInformation('This server uses ManiaControl v' . ManiaControl::VERSION . '!', $player->login);
|
||||
}
|
||||
|
||||
$logMessage = "Player joined: {$player->login} / " . Formatter::stripCodes($player->nickname) . " Nation: " . $player->getCountry() . " IP: {$player->ipAddress}";
|
||||
$this->maniaControl->log($logMessage);
|
||||
|
||||
// Increment the Player Join Count
|
||||
$this->maniaControl->statisticManager->incrementStat(self::STAT_JOIN_COUNT, $player, $this->maniaControl->server->index);
|
||||
|
||||
// Trigger own PlayerJoined callback
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERCONNECT, $player);
|
||||
|
||||
}
|
||||
|
||||
// Trigger own callback
|
||||
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERINFOCHANGED, $player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Player by Login
|
||||
*
|
||||
* @param string $login
|
||||
* @param bool $connectedPlayersOnly
|
||||
* @return Player
|
||||
*/
|
||||
public function getPlayer($login, $connectedPlayersOnly = false) {
|
||||
if (!isset($this->players[$login])) {
|
||||
if ($connectedPlayersOnly) {
|
||||
return null;
|
||||
}
|
||||
return $this->getPlayerFromDatabaseByLogin($login);
|
||||
}
|
||||
return $this->players[$login];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Player from the Database
|
||||
*
|
||||
* @param string $playerLogin
|
||||
* @return Player
|
||||
*/
|
||||
private function getPlayerFromDatabaseByLogin($playerLogin) {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
|
||||
$query = "SELECT * FROM `" . self::TABLE_PLAYERS . "` WHERE `login` LIKE '" . $mysqli->escape_string($playerLogin) . "';";
|
||||
$result = $mysqli->query($query);
|
||||
if (!$result) {
|
||||
trigger_error($mysqli->error);
|
||||
return null;
|
||||
}
|
||||
|
||||
$row = $result->fetch_object();
|
||||
$result->close();
|
||||
|
||||
if (!isset($row)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$player = new Player(null);
|
||||
$player->index = $row->index;
|
||||
$player->login = $row->login;
|
||||
$player->rawNickname = $row->nickname;
|
||||
$player->nickname = Formatter::stripDirtyCodes($player->rawNickname);
|
||||
$player->path = $row->path;
|
||||
$player->authLevel = $row->authLevel;
|
||||
|
||||
return $player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Players
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPlayers() {
|
||||
return $this->players;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Count of all Player
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPlayerCount() {
|
||||
$count = 0;
|
||||
foreach ($this->players as $player) {
|
||||
/** @var Player $player */
|
||||
if (!$player->isSpectator) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Count of all Spectators
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getSpectatorCount() {
|
||||
$count = 0;
|
||||
foreach ($this->players as $player) {
|
||||
/** @var Player $player */
|
||||
if ($player->isSpectator) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Player by his index
|
||||
*
|
||||
* @param $index
|
||||
* @param bool $connectedPlayersOnly
|
||||
* @return Player|null
|
||||
*/
|
||||
public function getPlayerByIndex($index, $connectedPlayersOnly = false) {
|
||||
foreach ($this->players as $player) {
|
||||
/** @var Player $player */
|
||||
if ($player->index == $index) {
|
||||
return $player;
|
||||
}
|
||||
}
|
||||
|
||||
if ($connectedPlayersOnly) {
|
||||
return null;
|
||||
}
|
||||
//Player is not online -> get Player from Database
|
||||
return $this->getPlayerFromDatabaseByIndex($index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get's a Player out of the database
|
||||
*
|
||||
* @param $playerIndex
|
||||
* @return Player $player
|
||||
*/
|
||||
private function getPlayerFromDatabaseByIndex($playerIndex) {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
|
||||
if (!is_numeric($playerIndex)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$query = "SELECT * FROM `" . self::TABLE_PLAYERS . "` WHERE `index` = " . $playerIndex . ";";
|
||||
$result = $mysqli->query($query);
|
||||
if (!$result) {
|
||||
trigger_error($mysqli->error);
|
||||
return null;
|
||||
}
|
||||
|
||||
$row = $result->fetch_object();
|
||||
$result->close();
|
||||
|
||||
if (!isset($row)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$player = new Player(null);
|
||||
$player->index = $playerIndex;
|
||||
$player->login = $row->login;
|
||||
$player->rawNickname = $row->nickname;
|
||||
$player->nickname = Formatter::stripDirtyCodes($player->rawNickname);
|
||||
$player->path = $row->path;
|
||||
$player->authLevel = $row->authLevel;
|
||||
|
||||
return $player;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user