Compare commits
2 Commits
293d5cf88f
...
3bddeb2308
Author | SHA1 | Date | |
---|---|---|---|
3bddeb2308 | |||
6a2b384648 |
@ -23,7 +23,7 @@ class GuestlistManager implements CommandListener, CallbackListener, TimerListen
|
||||
* Constants
|
||||
*/
|
||||
const PLUGIN_ID = 154;
|
||||
const PLUGIN_VERSION = 2.0;
|
||||
const PLUGIN_VERSION = 2.1;
|
||||
const PLUGIN_NAME = 'Guestlist Manager';
|
||||
const PLUGIN_AUTHOR = 'Beu';
|
||||
|
||||
@ -100,6 +100,9 @@ class GuestlistManager implements CommandListener, CallbackListener, TimerListen
|
||||
$this->maniaControl->getCommandManager()->registerCommandListener(['glload', 'loadgl'], $this, 'handleLoad', true, 'Load the guestlist file');
|
||||
$this->maniaControl->getCommandManager()->registerCommandListener(['glclear', 'glclean', 'cleangl'], $this, 'handleClear', true, 'Clear the guestlist');
|
||||
$this->maniaControl->getCommandManager()->registerCommandListener(['glkickall'], $this, 'handleKickAll', true, 'Kick non-guestlisted players');
|
||||
$this->maniaControl->getCommandManager()->registerCommandListener(['glinfo'], $this, 'handleInfo', true, 'Get guestlist info');
|
||||
$this->maniaControl->getCommandManager()->registerCommandListener(['gllist'], $this, 'handleList', true, 'List all guestlisted players');
|
||||
|
||||
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(AuthenticationManager::CB_AUTH_LEVEL_CHANGED, $this, 'handleAuthLevelChanged');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
|
||||
@ -409,6 +412,121 @@ class GuestlistManager implements CommandListener, CallbackListener, TimerListen
|
||||
$this->maniaControl->getChat()->sendSuccess($kicked . ' players kicked', $player);
|
||||
}
|
||||
|
||||
/**
|
||||
* handle Info command
|
||||
*
|
||||
* @param array $chat
|
||||
* @param \ManiaControl\Players\Player $player
|
||||
*/
|
||||
public function handleInfo(Array $chat, Player $player) {
|
||||
$guests = array_column($this->maniaControl->getClient()->getGuestList(), 'login');
|
||||
$players = $this->maniaControl->getPlayerManager()->getPlayers(true);
|
||||
$spectators = $this->maniaControl->getPlayerManager()->getSpectators();
|
||||
|
||||
$nbPlayersConnected = 0;
|
||||
$nbSpectatorsConnected = 0;
|
||||
$nbSpectatorsConnected = 0;
|
||||
$nbPerRole[0] = 0;
|
||||
$nbPerRoleConnected[0] = 0;
|
||||
|
||||
foreach ($guests as $login) {
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
||||
|
||||
if ($player === null) {
|
||||
$nbPerRole[0]++;
|
||||
} else {
|
||||
$players = array_filter($players, function($obj) use ($player) {
|
||||
return $obj !== $player;
|
||||
});
|
||||
|
||||
$spectators = array_filter($spectators, function($obj) use ($player) {
|
||||
return $obj !== $player;
|
||||
});
|
||||
|
||||
|
||||
if (!array_key_exists($player->authLevel, $nbPerRole)) {
|
||||
$nbPerRole[$player->authLevel] = 0;
|
||||
$nbPerRoleConnected[$player->authLevel] = 0;
|
||||
}
|
||||
$nbPerRole[$player->authLevel]++;
|
||||
if ($player->isConnected) {
|
||||
$nbPerRoleConnected[$player->authLevel]++;
|
||||
if ($player->isSpectator) $nbSpectatorsConnected++;
|
||||
else $nbPlayersConnected++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$message = '================ Guestlist info ================';
|
||||
$message .= PHP_EOL . '$<$ee0' . count($guests) . '$> guests in the guestlist. Type //gllist to get the list';
|
||||
$message .= PHP_EOL . '====== Connected on the server:';
|
||||
$message .= PHP_EOL . 'Guestlisted: $<$ee0'. $nbPlayersConnected . '$> players - $<$ee0'. $nbSpectatorsConnected .'$> spectators';
|
||||
$message .= PHP_EOL . 'Not guestlisted: $<$ee0'. count($players) . '$> players - $<$ee0'. count($spectators) .'$> spectators';
|
||||
|
||||
$message .= PHP_EOL . '====== Per role:';
|
||||
ksort($nbPerRole);
|
||||
ksort($nbPerRoleConnected);
|
||||
$part1 = PHP_EOL . 'Connected: ';
|
||||
$part2 = PHP_EOL . 'Disconnected: ';
|
||||
foreach ($nbPerRole as $authLevel => $count) {
|
||||
$part1 .= '$<$ee0'. $nbPerRoleConnected[$authLevel] .'$> '. $this->maniaControl->getAuthenticationManager()->getAuthLevelName($authLevel) .'s - ';
|
||||
$part2 .= '$<$ee0'. $count - $nbPerRoleConnected[$authLevel] .'$> '. $this->maniaControl->getAuthenticationManager()->getAuthLevelName($authLevel) .'s - ';
|
||||
}
|
||||
|
||||
$message .= substr($part1, 0, -3) . substr($part2, 0, -3);
|
||||
|
||||
|
||||
$this->maniaControl->getChat()->sendSuccess($message, $player);
|
||||
}
|
||||
|
||||
/**
|
||||
* handle List command
|
||||
*
|
||||
* @param array $chat
|
||||
* @param \ManiaControl\Players\Player $player
|
||||
*/
|
||||
public function handleList(Array $chat, Player $player) {
|
||||
$guests = array_column($this->maniaControl->getClient()->getGuestList(), 'login');
|
||||
|
||||
$logins = [];
|
||||
$names = [];
|
||||
$connectedNames = [];
|
||||
|
||||
foreach ($guests as $login) {
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
||||
|
||||
if ($player === null || $player->nickname === '') {
|
||||
$logins[] = $login;
|
||||
} else {
|
||||
$names[] = $player->nickname;
|
||||
if ($player->isConnected) {
|
||||
$connectedNames[] = $player->nickname;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
natcasesort($logins);
|
||||
natcasesort($names);
|
||||
|
||||
$message = '================ Guestlist list ================'. PHP_EOL;
|
||||
$message .= '====== Known players:'. PHP_EOL;
|
||||
foreach ($names as $name) {
|
||||
if (in_array($name, $connectedNames)) {
|
||||
$message .= '$<$1c0' . $name . '$> ';
|
||||
} else {
|
||||
$message .= '$<$c00' . $name . '$> ';
|
||||
}
|
||||
}
|
||||
|
||||
$message .= PHP_EOL .'====== Unknown players:'. PHP_EOL;
|
||||
|
||||
foreach ($logins as $login) {
|
||||
$message .= '$<$c00' . $login . '$> ';
|
||||
}
|
||||
|
||||
$this->maniaControl->getChat()->sendSuccess($message, $player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Kick non-guestlist players from the server
|
||||
*
|
||||
|
@ -38,7 +38,7 @@ use ManiaControl\Callbacks\TimerListener; // for pause
|
||||
class MatchManagerCore implements CallbackListener, CommandListener, TimerListener, CommunicationListener, Plugin {
|
||||
|
||||
const PLUGIN_ID = 152;
|
||||
const PLUGIN_VERSION = 5.4;
|
||||
const PLUGIN_VERSION = 5.5;
|
||||
const PLUGIN_NAME = 'MatchManager Core';
|
||||
const PLUGIN_AUTHOR = 'Beu';
|
||||
|
||||
@ -2032,51 +2032,78 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
|
||||
$text = $chatCallback[1][2];
|
||||
$text = explode(" ", $text);
|
||||
|
||||
if (isset($text[1]) && isset($text[2]) && is_numeric($text[2]) && $text[2] >= 0 ) {
|
||||
if (strcasecmp($text[1], "Blue") == 0 || $text[1] == "0") {
|
||||
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints("0", "", $text[2], $text[2]);
|
||||
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . '$<$00fBlue$> Team now has $<$ff0' . $text[2] . '$> points!');
|
||||
} elseif (strcasecmp($text[1], "Red") == 0 || $text[1] == "1") {
|
||||
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints("1", "", $text[2] , $text[2]);
|
||||
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . '$<$f00Red$> Team now has $<$ff0' . $text[2] . '$> points!');
|
||||
} elseif (is_numeric($text[1])) { //TODO: add support of name of teams (need update from NADEO)
|
||||
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints($text[1], "", $text[2] , $text[2]);
|
||||
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Team ' . $text[1] . ' now has $<$ff0' . $text[2] . '$> points!');
|
||||
} else {
|
||||
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
||||
$stmt = $mysqli->prepare('SELECT login FROM `' . PlayerManager::TABLE_PLAYERS . '` WHERE nickname LIKE ?');
|
||||
$stmt->bind_param('s', $text[1]);
|
||||
if (count($text) < 3) {
|
||||
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Missing parameters. Eg: //matchsetpoints <Team Name or id / Player Name or Login> <Match points> <Map Points (optional)> <Round Points (optional)>', $adminplayer);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$stmt->execute()) {
|
||||
Logger::logError('Error executing MySQL query: '. $stmt->error);
|
||||
}
|
||||
$target = $text[1];
|
||||
$matchpoints = $text[2];
|
||||
$mappoints = '';
|
||||
$roundpoints = '';
|
||||
|
||||
$result = $stmt->get_result();
|
||||
$array = mysqli_fetch_array($result);
|
||||
|
||||
if (isset($array[0])) {
|
||||
$login = $array[0];
|
||||
} elseif (strlen($text[1]) == 22) {
|
||||
$login = $text[1];
|
||||
}
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error, E_USER_ERROR);
|
||||
}
|
||||
|
||||
if (isset($login)) {
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($login,true);
|
||||
if ($player) {
|
||||
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaPlayerPoints($player, "", "", $text[2]);
|
||||
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Player $<$ff0' . $player->nickname . '$> now has $<$ff0' . $text[2] . '$> points!');
|
||||
} else {
|
||||
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Player ' . $text[1] . " isn't connected", $adminplayer);
|
||||
}
|
||||
} else {
|
||||
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Player ' . $text[1] . " doesn't exist", $adminplayer);
|
||||
}
|
||||
if (!is_numeric($matchpoints)) {
|
||||
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Invalid argument: Match points', $adminplayer);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($text[3])) {
|
||||
$mappoints = $text[3];
|
||||
if (!is_numeric($mappoints)) {
|
||||
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Invalid argument: Map points', $adminplayer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($text[4])) {
|
||||
$roundpoints = $text[4];
|
||||
if (!is_numeric($roundpoints)) {
|
||||
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Invalid argument: Round points', $adminplayer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (strcasecmp($target, "Blue") == 0 || $target == "0") {
|
||||
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints("0", $roundpoints, $mappoints, $matchpoints);
|
||||
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . '$<$00fBlue$> Team now has $<$ff0' . $matchpoints . '$> points!');
|
||||
} elseif (strcasecmp($target, "Red") == 0 || $target == "1") {
|
||||
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints("1", $roundpoints, $mappoints, $matchpoints);
|
||||
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . '$<$f00Red$> Team now has $<$ff0' . $matchpoints . '$> points!');
|
||||
} elseif (is_numeric($target)) { //TODO: add support of name of teams (need update from NADEO)
|
||||
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints($target, $roundpoints, $mappoints, $matchpoints);
|
||||
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Team ' . $target . ' now has $<$ff0' . $matchpoints . '$> points!');
|
||||
} else {
|
||||
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Missing or invalid parameters', $adminplayer);
|
||||
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
||||
$stmt = $mysqli->prepare('SELECT login FROM `' . PlayerManager::TABLE_PLAYERS . '` WHERE nickname LIKE ?');
|
||||
$stmt->bind_param('s', $target);
|
||||
|
||||
if (!$stmt->execute()) {
|
||||
Logger::logError('Error executing MySQL query: '. $stmt->error);
|
||||
}
|
||||
|
||||
$result = $stmt->get_result();
|
||||
$array = mysqli_fetch_array($result);
|
||||
|
||||
if (isset($array[0])) {
|
||||
$login = $array[0];
|
||||
} elseif (strlen($target) == 22) {
|
||||
$login = $target;
|
||||
}
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error, E_USER_ERROR);
|
||||
}
|
||||
|
||||
if (isset($login)) {
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($login,true);
|
||||
if ($player) {
|
||||
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaPlayerPoints($player, "", "", $matchpoints);
|
||||
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Player $<$ff0' . $player->nickname . '$> now has $<$ff0' . $matchpoints . '$> points!');
|
||||
} else {
|
||||
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Player ' . $target . " isn't connected", $adminplayer);
|
||||
}
|
||||
} else {
|
||||
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Player ' . $target . " doesn't exist", $adminplayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user