From 44bc21f3d16cb11140b9d444caea145fd9f0c054 Mon Sep 17 00:00:00 2001 From: beu Date: Sat, 15 Mar 2025 13:13:43 +0100 Subject: [PATCH] separate setpoints command for teams --- Beu/MoreModesTools.php | 169 ++++++++++++++++++------- MatchManagerSuite/MatchManagerCore.php | 109 +++++++++++----- 2 files changed, 197 insertions(+), 81 deletions(-) diff --git a/Beu/MoreModesTools.php b/Beu/MoreModesTools.php index ba5f119..9a2c438 100644 --- a/Beu/MoreModesTools.php +++ b/Beu/MoreModesTools.php @@ -20,7 +20,7 @@ class MoreModesTools implements CommandListener, Plugin { * Constants */ const PLUGIN_ID = 164; - const PLUGIN_VERSION = 1.1; + const PLUGIN_VERSION = 1.2; const PLUGIN_NAME = 'MoreModesTools'; const PLUGIN_AUTHOR = 'Beu'; @@ -82,7 +82,8 @@ class MoreModesTools implements CommandListener, Plugin { $this->maniaControl->getCommandManager()->registerCommandListener('endround', $this, 'onCommandEndRound', true, 'End the round'); $this->maniaControl->getCommandManager()->registerCommandListener(['endwu', 'endwarmup'], $this, 'onCommandEndWarmUp', true, 'End the WarmUp'); $this->maniaControl->getCommandManager()->registerCommandListener(['extendwu', 'extendwarmup'], $this, 'onCommandExtendWarmUp', true, 'If the warm up has a time limit, increase it'); - $this->maniaControl->getCommandManager()->registerCommandListener('setpoints', $this, 'onCommandSetPoints', true, 'Set Points for a player or a team'); + $this->maniaControl->getCommandManager()->registerCommandListener('setpoints', $this, 'onCommandSetPoints', true, 'Set Points for a player'); + $this->maniaControl->getCommandManager()->registerCommandListener('setteampoints', $this, 'onCommandSetPoints', true, 'Set Points for a team'); return true; } @@ -147,7 +148,6 @@ class MoreModesTools implements CommandListener, Plugin { $text = $chat[1][2]; $text = explode(" ", $text); if (is_numeric($text[1])) { - var_dump($text[1]); $this->maniaControl->getModeScriptEventManager()->triggerModeScriptEvent("Trackmania.WarmUp.Extend", [ strval(intval($text[1]) * 1000)]); $this->maniaControl->getChat()->sendSuccessToAdmins('Extend Warmup Sent'); } else { @@ -156,60 +156,131 @@ class MoreModesTools implements CommandListener, Plugin { } /** - * Send SetPoints + * Command //setpoints for admin * - * @param array $chat + * @param array $chatCallback * @param \ManiaControl\Players\Player $player */ - public function onCommandSetPoints(Array $chat, Player $player) { - $text = $chat[1][2]; + public function onCommandSetPoints(array $chatCallback, Player $adminplayer) { + $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('$<$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('$<$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('Team ' . $text[1] . ' now has $<$ff0' . $text[2] . '$> points!'); + if (count($text) < 3) { + $this->maniaControl->getChat()->sendError('Missing parameters. Eg: //matchsetpoints ', $adminplayer); + return; + } + + $target = $text[1]; + $matchpoints = $text[2]; + $mappoints = ''; + $roundpoints = ''; + + if (!is_numeric($matchpoints)) { + $this->maniaControl->getChat()->sendError('Invalid argument: Match points', $adminplayer); + return; + } + + if (isset($text[3])) { + $mappoints = $text[3]; + if (!is_numeric($mappoints)) { + $this->maniaControl->getChat()->sendError('Invalid argument: Map points', $adminplayer); + return; + } + } + + if (isset($text[4])) { + $roundpoints = $text[4]; + if (!is_numeric($roundpoints)) { + $this->maniaControl->getChat()->sendError('Invalid argument: Round points', $adminplayer); + return; + } + } + + $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, $roundpoints, $mappoints, $matchpoints); + $this->maniaControl->getChat()->sendSuccess('Player $<$ff0' . $player->nickname . '$> now has $<$ff0' . $matchpoints . '$> points!'); } else { - $mysqli = $this->maniaControl->getDatabase()->getMysqli(); - - $query = $mysqli->prepare('SELECT login FROM `' . PlayerManager::TABLE_PLAYERS . '` WHERE nickname LIKE ?'); - $query->bind_param('s', $text[1]); - if (!$query->execute()) { - trigger_error('Error executing MySQL query: ' . $query->error); - return; - } - $result = $query->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)) { - $playerpoints = $this->maniaControl->getPlayerManager()->getPlayer($login, true); - if ($player) { - $this->maniaControl->getModeScriptEventManager()->setTrackmaniaPlayerPoints($playerpoints, "", "", $text[2]); - $this->maniaControl->getChat()->sendSuccess('Player $<$ff0' . $playerpoints->nickname . '$> now has $<$ff0' . $text[2] . '$> points!'); - } else { - $this->maniaControl->getChat()->sendError('Player ' . $text[1] . " isn't connected", $player); - } - } else { - $this->maniaControl->getChat()->sendError('Player ' . $text[1] . " doesn't exist", $player); - } + $this->maniaControl->getChat()->sendError('Player ' . $target . " isn't connected", $adminplayer); } } else { - $this->maniaControl->getChat()->sendError($this->chatprefix . 'Missing or invalid parameters', $player); + $this->maniaControl->getChat()->sendError('Player ' . $target . " doesn't exist", $adminplayer); + } + } + + /** + * Command //setteampoints for admin + * + * @param array $chatCallback + * @param Player $adminplayer + */ + public function onCommandSetTeamPoints(array $chatCallback, Player $adminplayer) { + $text = $chatCallback[1][2]; + $text = explode(" ", $text); + + if (count($text) < 3) { + $this->maniaControl->getChat()->sendError('Missing parameters. Eg: //matchsetteampoints ', $adminplayer); + return; + } + + $target = $text[1]; + $matchpoints = $text[2]; + $mappoints = ''; + $roundpoints = ''; + + if (!is_numeric($matchpoints)) { + $this->maniaControl->getChat()->sendError('Invalid argument: Match points', $adminplayer); + return; + } + + if (isset($text[3])) { + $mappoints = $text[3]; + if (!is_numeric($mappoints)) { + $this->maniaControl->getChat()->sendError('Invalid argument: Map points', $adminplayer); + return; + } + } + + if (isset($text[4])) { + $roundpoints = $text[4]; + if (!is_numeric($roundpoints)) { + $this->maniaControl->getChat()->sendError('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('$<$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('$<$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('Team ' . $target . ' now has $<$ff0' . $matchpoints . '$> points!'); + } else { + $this->maniaControl->getChat()->sendError('Can\'t find team: ' . $target, $adminplayer); } } } diff --git a/MatchManagerSuite/MatchManagerCore.php b/MatchManagerSuite/MatchManagerCore.php index 8db692f..d0a4666 100644 --- a/MatchManagerSuite/MatchManagerCore.php +++ b/MatchManagerSuite/MatchManagerCore.php @@ -458,6 +458,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen $this->maniaControl->getCommandManager()->registerCommandListener('matchendround', $this, 'onCommandMatchEndRound', true, 'Force end a round during a match'); $this->maniaControl->getCommandManager()->registerCommandListener('matchendwu', $this, 'onCommandMatchEndWU', true, 'Force end a WU during a match'); $this->maniaControl->getCommandManager()->registerCommandListener('matchsetpoints', $this, 'onCommandSetPoints', true, 'Sets points to a player.'); + $this->maniaControl->getCommandManager()->registerCommandListener('matchsetteampoints', $this, 'onCommandSetTeamPoints', true, 'Sets points to a team.'); $this->maniaControl->getCommandManager()->registerCommandListener(array('matchpause','pause'), $this, 'onCommandSetPause', true, 'Set pause during a match. [time] in seconds can be added to force another value'); $this->maniaControl->getCommandManager()->registerCommandListener(array('matchendpause','endpause'), $this, 'onCommandUnsetPause', true, 'End the pause during a match.'); @@ -2181,7 +2182,81 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen $text = explode(" ", $text); if (count($text) < 3) { - $this->maniaControl->getChat()->sendError($this->chatprefix . 'Missing parameters. Eg: //matchsetpoints ', $adminplayer); + $this->maniaControl->getChat()->sendError($this->chatprefix . 'Missing parameters. Eg: //matchsetpoints ', $adminplayer); + return; + } + + $target = $text[1]; + $matchpoints = $text[2]; + $mappoints = ''; + $roundpoints = ''; + + 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; + } + } + + $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, $roundpoints, $mappoints, $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); + } + } + + public function onCommandSetTeamPoints(array $chatCallback, Player $adminplayer) { + $authLevel = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_MATCH_AUTHLEVEL); + if (!$this->maniaControl->getAuthenticationManager()->checkRight($adminplayer, AuthenticationManager::getAuthLevel($authLevel))) { + $this->maniaControl->getAuthenticationManager()->sendNotAllowed($adminplayer); + return; + } + + $text = $chatCallback[1][2]; + $text = explode(" ", $text); + + if (count($text) < 3) { + $this->maniaControl->getChat()->sendError($this->chatprefix . 'Missing parameters. Eg: //matchsetteampoints ', $adminplayer); return; } @@ -2221,37 +2296,7 @@ class MatchManagerCore implements CallbackListener, CommandListener, TimerListen $this->maniaControl->getModeScriptEventManager()->setTrackmaniaTeamPoints($target, $roundpoints, $mappoints, $matchpoints); $this->maniaControl->getChat()->sendSuccess($this->chatprefix . 'Team ' . $target . ' now has $<$ff0' . $matchpoints . '$> points!'); } else { - $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, $roundpoints, $mappoints, $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); - } + $this->maniaControl->getChat()->sendError($this->chatprefix . 'Can\'t find team: ' . $target, $adminplayer); } }