Compare commits

..

No commits in common. "3bddeb230888cf46764c8e73e172f028fe3fcdbd" and "293d5cf88ffc720ecbee8ef9a804917dfb0d00ca" have entirely different histories.

2 changed files with 45 additions and 190 deletions

View File

@ -23,7 +23,7 @@ class GuestlistManager implements CommandListener, CallbackListener, TimerListen
* Constants * Constants
*/ */
const PLUGIN_ID = 154; const PLUGIN_ID = 154;
const PLUGIN_VERSION = 2.1; const PLUGIN_VERSION = 2.0;
const PLUGIN_NAME = 'Guestlist Manager'; const PLUGIN_NAME = 'Guestlist Manager';
const PLUGIN_AUTHOR = 'Beu'; const PLUGIN_AUTHOR = 'Beu';
@ -100,9 +100,6 @@ class GuestlistManager implements CommandListener, CallbackListener, TimerListen
$this->maniaControl->getCommandManager()->registerCommandListener(['glload', 'loadgl'], $this, 'handleLoad', true, 'Load the guestlist file'); $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(['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(['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(AuthenticationManager::CB_AUTH_LEVEL_CHANGED, $this, 'handleAuthLevelChanged');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); $this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
@ -412,121 +409,6 @@ class GuestlistManager implements CommandListener, CallbackListener, TimerListen
$this->maniaControl->getChat()->sendSuccess($kicked . ' players kicked', $player); $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 * Kick non-guestlist players from the server
* *

View File

@ -38,7 +38,7 @@ use ManiaControl\Callbacks\TimerListener; // for pause
class MatchManagerCore implements CallbackListener, CommandListener, TimerListener, CommunicationListener, Plugin { class MatchManagerCore implements CallbackListener, CommandListener, TimerListener, CommunicationListener, Plugin {
const PLUGIN_ID = 152; const PLUGIN_ID = 152;
const PLUGIN_VERSION = 5.5; const PLUGIN_VERSION = 5.4;
const PLUGIN_NAME = 'MatchManager Core'; const PLUGIN_NAME = 'MatchManager Core';
const PLUGIN_AUTHOR = 'Beu'; const PLUGIN_AUTHOR = 'Beu';
@ -2032,50 +2032,20 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
$text = $chatCallback[1][2]; $text = $chatCallback[1][2];
$text = explode(" ", $text); $text = explode(" ", $text);
if (count($text) < 3) { if (isset($text[1]) && isset($text[2]) && is_numeric($text[2]) && $text[2] >= 0 ) {
$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); if (strcasecmp($text[1], "Blue") == 0 || $text[1] == "0") {
return; $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") {
$target = $text[1]; $this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints("1", "", $text[2] , $text[2]);
$matchpoints = $text[2]; $this->maniaControl->getChat()->sendSuccess($this->chatprefix . '$<$f00Red$> Team now has $<$ff0' . $text[2] . '$> points!');
$mappoints = ''; } elseif (is_numeric($text[1])) { //TODO: add support of name of teams (need update from NADEO)
$roundpoints = ''; $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!');
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 { } else {
$mysqli = $this->maniaControl->getDatabase()->getMysqli(); $mysqli = $this->maniaControl->getDatabase()->getMysqli();
$stmt = $mysqli->prepare('SELECT login FROM `' . PlayerManager::TABLE_PLAYERS . '` WHERE nickname LIKE ?'); $stmt = $mysqli->prepare('SELECT login FROM `' . PlayerManager::TABLE_PLAYERS . '` WHERE nickname LIKE ?');
$stmt->bind_param('s', $target); $stmt->bind_param('s', $text[1]);
if (!$stmt->execute()) { if (!$stmt->execute()) {
Logger::logError('Error executing MySQL query: '. $stmt->error); Logger::logError('Error executing MySQL query: '. $stmt->error);
@ -2086,8 +2056,8 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
if (isset($array[0])) { if (isset($array[0])) {
$login = $array[0]; $login = $array[0];
} elseif (strlen($target) == 22) { } elseif (strlen($text[1]) == 22) {
$login = $target; $login = $text[1];
} }
if ($mysqli->error) { if ($mysqli->error) {
trigger_error($mysqli->error, E_USER_ERROR); trigger_error($mysqli->error, E_USER_ERROR);
@ -2096,14 +2066,17 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen
if (isset($login)) { if (isset($login)) {
$player = $this->maniaControl->getPlayerManager()->getPlayer($login,true); $player = $this->maniaControl->getPlayerManager()->getPlayer($login,true);
if ($player) { if ($player) {
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaPlayerPoints($player, "", "", $matchpoints); $this->maniaControl->getModeScriptEventManager()->setTrackmaniaPlayerPoints($player, "", "", $text[2]);
$this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Player $<$ff0' . $player->nickname . '$> now has $<$ff0' . $matchpoints . '$> points!'); $this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Player $<$ff0' . $player->nickname . '$> now has $<$ff0' . $text[2] . '$> points!');
} else { } else {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Player ' . $target . " isn't connected", $adminplayer); $this->maniaControl->getChat()->sendError($this->chatprefix . 'Player ' . $text[1] . " isn't connected", $adminplayer);
} }
} else { } else {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Player ' . $target . " doesn't exist", $adminplayer); $this->maniaControl->getChat()->sendError($this->chatprefix . 'Player ' . $text[1] . " doesn't exist", $adminplayer);
} }
} }
} else {
$this->maniaControl->getChat()->sendError($this->chatprefix . 'Missing or invalid parameters', $adminplayer);
}
} }
} }