added authlevel button functions
This commit is contained in:
		| @@ -55,7 +55,7 @@ abstract class Formatter { | |||||||
| 	/** | 	/** | ||||||
| 	 *  Strip all codes except colors from the string | 	 *  Strip all codes except colors from the string | ||||||
| 	 */ | 	 */ | ||||||
| 	public static function stripCodesWithoutColors($string) { | 	public static function stripCodesWithoutColors($string) { //Todo don't remove $i, $s | ||||||
| 		$string = preg_replace('/(?<!\$)((?:\$\$)*)\$[^$0-9a-hlp]/iu', '$1', $string); | 		$string = preg_replace('/(?<!\$)((?:\$\$)*)\$[^$0-9a-hlp]/iu', '$1', $string); | ||||||
| 		$string = self::stripLinks($string); | 		$string = self::stripLinks($string); | ||||||
| 		return $string; | 		return $string; | ||||||
| @@ -70,7 +70,7 @@ abstract class Formatter { | |||||||
| 	public static function stripCodes($string) { | 	public static function stripCodes($string) { | ||||||
| 		$string = preg_replace('/(?<!\$)((?:\$\$)*)\$[^$0-9a-hlp]/iu', '$1', $string); | 		$string = preg_replace('/(?<!\$)((?:\$\$)*)\$[^$0-9a-hlp]/iu', '$1', $string); | ||||||
| 		$string = self::stripLinks($string); | 		$string = self::stripLinks($string); | ||||||
| 		//$string = self::stripColors($string); | 		$string = self::stripColors($string); | ||||||
| 		return $string; | 		return $string; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -43,11 +43,10 @@ class Player { | |||||||
| 		} | 		} | ||||||
| 		$this->pid = $rpcInfos['PlayerId']; | 		$this->pid = $rpcInfos['PlayerId']; | ||||||
| 		$this->login = $rpcInfos['Login']; | 		$this->login = $rpcInfos['Login']; | ||||||
| 		$this->nickname = Formatter::stripCodesWithoutColors($rpcInfos['NickName']); | 		$this->nickname = Formatter::stripCodesWithoutColors($rpcInfos['NickName']); //TODO don't remove $s, $i | ||||||
| 		$this->path = $rpcInfos['Path']; | 		$this->path = $rpcInfos['Path']; | ||||||
| 		$this->language = $rpcInfos['Language']; | 		$this->language = $rpcInfos['Language']; | ||||||
| 		$this->avatar = $rpcInfos['Avatar']['FileName']; | 		$this->avatar = $rpcInfos['Avatar']['FileName']; | ||||||
| 		 |  | ||||||
| 		$this->allies = $rpcInfos['Allies']; | 		$this->allies = $rpcInfos['Allies']; | ||||||
| 		$this->clubLink = $rpcInfos['ClubLink']; | 		$this->clubLink = $rpcInfos['ClubLink']; | ||||||
| 		$this->teamId = $rpcInfos['TeamId']; | 		$this->teamId = $rpcInfos['TeamId']; | ||||||
|   | |||||||
| @@ -225,4 +225,63 @@ class PlayerActions { | |||||||
| 		// log console message | 		// log console message | ||||||
| 		$this->maniaControl->log($title .' ' . Formatter::stripCodes($admin->nickname) . ' banned player '. Formatter::stripCodes($target->nickname)); | 		$this->maniaControl->log($title .' ' . Formatter::stripCodes($admin->nickname) . ' banned player '. Formatter::stripCodes($target->nickname)); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Grands Player an authorization level | ||||||
|  | 	 * @param $adminLogin | ||||||
|  | 	 * @param $targetLogin | ||||||
|  | 	 * @param $authLevel | ||||||
|  | 	 */ | ||||||
|  | 	public function grandAuthLevel($adminLogin, $targetLogin, $authLevel){ | ||||||
|  | 		$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); | ||||||
|  | 		$target = $this->maniaControl->playerManager->getPlayer($targetLogin); | ||||||
|  | 		$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); | ||||||
|  | 		//TODO check for bot | ||||||
|  | 		if($this->maniaControl->authenticationManager->checkRight($target,$authLevel)){ | ||||||
|  | 			$this->maniaControl->chat->sendError('This admin is already ' . $this->maniaControl->authenticationManager->getAuthLevelName($target->authLevel), $admin->login); | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		$success = $this->maniaControl->authenticationManager->grantAuthLevel($target, $authLevel); | ||||||
|  |  | ||||||
|  | 		if (!$success) { | ||||||
|  | 			$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		$authLevelName = $this->maniaControl->authenticationManager->getAuthLevelName($authLevel); | ||||||
|  |  | ||||||
|  | 		$this->maniaControl->chat->sendInformation($title . ' $<' . $admin->nickname . '$> added $<' . $target->nickname . '$> as $< ' . $authLevelName. '$>!'); | ||||||
|  |  | ||||||
|  | 		// log console message | ||||||
|  | 		$this->maniaControl->log($title .' ' . Formatter::stripCodes($admin->nickname) . ' added player '. Formatter::stripCodes($target->nickname) . ' as ' . $authLevelName); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Revokes all rights from a Admin | ||||||
|  | 	 * @param $adminLogin | ||||||
|  | 	 * @param $targetLogin | ||||||
|  | 	 */ | ||||||
|  | 	public function revokeAuthLevel($adminLogin, $targetLogin){ | ||||||
|  | 		$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); | ||||||
|  | 		$target = $this->maniaControl->playerManager->getPlayer($targetLogin); | ||||||
|  | 		$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); | ||||||
|  |  | ||||||
|  | 		if($this->maniaControl->authenticationManager->checkRight($target,AuthenticationManager::AUTH_LEVEL_MASTERADMIN)){ | ||||||
|  | 			$this->maniaControl->chat->sendError('MasterAdmins can\'t be removed ', $admin->login); | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		$success = $this->maniaControl->authenticationManager->grantAuthLevel($target, AuthenticationManager::AUTH_LEVEL_PLAYER); | ||||||
|  |  | ||||||
|  | 		if (!$success) { | ||||||
|  | 			$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		$this->maniaControl->chat->sendInformation($title . ' $<' . $admin->nickname . '$> revokes $<' . $target->nickname . '$> rights!'); | ||||||
|  |  | ||||||
|  | 		// log console message | ||||||
|  | 		$this->maniaControl->log($title .' ' . Formatter::stripCodes($admin->nickname) . ' revokes '. Formatter::stripCodes($target->nickname) . ' rights'); | ||||||
|  | 	} | ||||||
| }  | }  | ||||||
| @@ -45,6 +45,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { | |||||||
| 	const ACTION_ADD_AS_MASTER = 'PlayerList.PlayerAddAsMaster'; | 	const ACTION_ADD_AS_MASTER = 'PlayerList.PlayerAddAsMaster'; | ||||||
| 	const ACTION_ADD_AS_ADMIN = 'PlayerList.PlayerAddAsAdmin'; | 	const ACTION_ADD_AS_ADMIN = 'PlayerList.PlayerAddAsAdmin'; | ||||||
| 	const ACTION_ADD_AS_MOD  = 'PlayerList.PlayerAddAsModerator'; | 	const ACTION_ADD_AS_MOD  = 'PlayerList.PlayerAddAsModerator'; | ||||||
|  | 	const ACTION_REVOKE_RIGHTS = 'PlayerList.RevokeRights'; | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * Private properties | 	 * Private properties | ||||||
| @@ -310,11 +311,12 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { | |||||||
| 		//todo all configurable or as constants | 		//todo all configurable or as constants | ||||||
| 		$x = $this->width / 2 + 2.5; | 		$x = $this->width / 2 + 2.5; | ||||||
| 		$width = 35; | 		$width = 35; | ||||||
| 		$height = $this->height * 0.6; | 		$height = $this->height * 0.7; | ||||||
| 		$hAlign = Control::LEFT; | 		$hAlign = Control::LEFT; | ||||||
| 		$style = Label_Text::STYLE_TextCardSmall; | 		$style = Label_Text::STYLE_TextCardSmall; | ||||||
| 		$textSize = 1.5; | 		$textSize = 1.5; | ||||||
| 		$textColor = 'FFF'; | 		$textColor = 'FFF'; | ||||||
|  | 		$quadWidth = $width - 7; | ||||||
|  |  | ||||||
| 		//mainframe | 		//mainframe | ||||||
| 		$frame = new Frame(); | 		$frame = new Frame(); | ||||||
| @@ -322,7 +324,6 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { | |||||||
| 		$frame->setSize($width,$height); | 		$frame->setSize($width,$height); | ||||||
| 		$frame->setPosition($x + $width / 2, 0); | 		$frame->setPosition($x + $width / 2, 0); | ||||||
|  |  | ||||||
|  |  | ||||||
| 		// Add Close Quad (X) | 		// Add Close Quad (X) | ||||||
| 		$closeQuad = new Quad_Icons64x64_1(); | 		$closeQuad = new Quad_Icons64x64_1(); | ||||||
| 		$frame->add($closeQuad); | 		$frame->add($closeQuad); | ||||||
| @@ -370,7 +371,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { | |||||||
| 		$quad->setX(0); | 		$quad->setX(0); | ||||||
| 		$quad->setY($y); | 		$quad->setY($y); | ||||||
| 		$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCard); | 		$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCard); | ||||||
| 		$quad->setSize($width - 10,5); | 		$quad->setSize($quadWidth, 5); | ||||||
| 		$quad->setAction(self::ACTION_WARN_PLAYER . "." .$login); | 		$quad->setAction(self::ACTION_WARN_PLAYER . "." .$login); | ||||||
|  |  | ||||||
| 		$label = new Label_Button(); | 		$label = new Label_Button(); | ||||||
| @@ -390,7 +391,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { | |||||||
| 		$quad->setX(0); | 		$quad->setX(0); | ||||||
| 		$quad->setY($y); | 		$quad->setY($y); | ||||||
| 		$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCard); | 		$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCard); | ||||||
| 		$quad->setSize($width - 10,5); | 		$quad->setSize($quadWidth, 5); | ||||||
| 		$quad->setAction(self::ACTION_KICK_PLAYER . "." .$login); | 		$quad->setAction(self::ACTION_KICK_PLAYER . "." .$login); | ||||||
|  |  | ||||||
| 		$label = new Label_Button(); | 		$label = new Label_Button(); | ||||||
| @@ -410,7 +411,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { | |||||||
| 		$quad->setX(0); | 		$quad->setX(0); | ||||||
| 		$quad->setY($y); | 		$quad->setY($y); | ||||||
| 		$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCard); | 		$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCard); | ||||||
| 		$quad->setSize($width - 10,5); | 		$quad->setSize($quadWidth, 5); | ||||||
| 		$quad->setAction(self::ACTION_BAN_PLAYER . "." .$login); | 		$quad->setAction(self::ACTION_BAN_PLAYER . "." .$login); | ||||||
|  |  | ||||||
| 		$label = new Label_Button(); | 		$label = new Label_Button(); | ||||||
| @@ -430,7 +431,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { | |||||||
| 		$quad->setX(0); | 		$quad->setX(0); | ||||||
| 		$quad->setY($y); | 		$quad->setY($y); | ||||||
| 		$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCard); | 		$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCard); | ||||||
| 		$quad->setSize($width - 10,5); | 		$quad->setSize($quadWidth, 5); | ||||||
| 		$quad->setAction(self::ACTION_ADD_AS_MASTER . "." .$login); | 		$quad->setAction(self::ACTION_ADD_AS_MASTER . "." .$login); | ||||||
|  |  | ||||||
| 		$label = new Label_Button(); | 		$label = new Label_Button(); | ||||||
| @@ -440,7 +441,9 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { | |||||||
| 		$label->setY($y); | 		$label->setY($y); | ||||||
| 		$label->setStyle($style); | 		$label->setStyle($style); | ||||||
| 		$label->setTextSize($textSize); | 		$label->setTextSize($textSize); | ||||||
|  |  | ||||||
| 		$label->setText("Add MasterAdmin"); | 		$label->setText("Add MasterAdmin"); | ||||||
|  |  | ||||||
| 		$label->setTextColor($textColor); | 		$label->setTextColor($textColor); | ||||||
|  |  | ||||||
| 		$y -= 5; | 		$y -= 5; | ||||||
| @@ -450,7 +453,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { | |||||||
| 		$quad->setX(0); | 		$quad->setX(0); | ||||||
| 		$quad->setY($y); | 		$quad->setY($y); | ||||||
| 		$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCard); | 		$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCard); | ||||||
| 		$quad->setSize($width - 10,5); | 		$quad->setSize($quadWidth, 5); | ||||||
| 		$quad->setAction(self::ACTION_ADD_AS_ADMIN . "." .$login); | 		$quad->setAction(self::ACTION_ADD_AS_ADMIN . "." .$login); | ||||||
|  |  | ||||||
| 		$label = new Label_Button(); | 		$label = new Label_Button(); | ||||||
| @@ -470,7 +473,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { | |||||||
| 		$quad->setX(0); | 		$quad->setX(0); | ||||||
| 		$quad->setY($y); | 		$quad->setY($y); | ||||||
| 		$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCard); | 		$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCard); | ||||||
| 		$quad->setSize($width - 10,5); | 		$quad->setSize($quadWidth, 5); | ||||||
| 		$quad->setAction(self::ACTION_ADD_AS_MOD . "." .$login); | 		$quad->setAction(self::ACTION_ADD_AS_MOD . "." .$login); | ||||||
|  |  | ||||||
| 		$label = new Label_Button(); | 		$label = new Label_Button(); | ||||||
| @@ -483,6 +486,29 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { | |||||||
| 		$label->setText("Add Moderator"); | 		$label->setText("Add Moderator"); | ||||||
| 		$label->setTextColor($textColor); | 		$label->setTextColor($textColor); | ||||||
|  |  | ||||||
|  |  | ||||||
|  | 		if($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)){ | ||||||
|  | 			$y -= 5; | ||||||
|  | 			//Revoke Rights | ||||||
|  | 			$quad = new Quad_BgsPlayerCard(); | ||||||
|  | 			$frame->add($quad); | ||||||
|  | 			$quad->setX(0); | ||||||
|  | 			$quad->setY($y); | ||||||
|  | 			$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCard); | ||||||
|  | 			$quad->setSize($quadWidth, 5); | ||||||
|  | 			$quad->setAction(self::ACTION_REVOKE_RIGHTS . "." .$login); | ||||||
|  |  | ||||||
|  | 			$label = new Label_Button(); | ||||||
|  | 			$frame->add($label); | ||||||
|  | 			$label->setAlign(Control::CENTER,Control::CENTER); | ||||||
|  | 			$label->setX(0); | ||||||
|  | 			$label->setY($y); | ||||||
|  | 			$label->setStyle($style); | ||||||
|  | 			$label->setTextSize($textSize); | ||||||
|  | 			$label->setText("Revoke Rights"); | ||||||
|  | 			$label->setTextColor($textColor); | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 		//render and display xml | 		//render and display xml | ||||||
| 		$this->maniaControl->manialinkManager->displayWidget($maniaLink, $caller); | 		$this->maniaControl->manialinkManager->displayWidget($maniaLink, $caller); | ||||||
|  |  | ||||||
| @@ -540,17 +566,19 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { | |||||||
| 				$player = $this->maniaControl->playerManager->getPlayer($callback[1][1]); | 				$player = $this->maniaControl->playerManager->getPlayer($callback[1][1]); | ||||||
| 				$this->advancedPlayerWidget($callback, $player, $actionArray[2]); | 				$this->advancedPlayerWidget($callback, $player, $actionArray[2]); | ||||||
| 				break; | 				break; | ||||||
|  | 			case self::ACTION_ADD_AS_MASTER: | ||||||
|  | 				$this->maniaControl->playerManager->playerActions->grandAuthLevel($callback[1][1], $actionArray[2], AuthenticationManager::AUTH_LEVEL_SUPERADMIN); | ||||||
|  | 				break; | ||||||
|  | 			case self::ACTION_ADD_AS_ADMIN: | ||||||
|  | 				$this->maniaControl->playerManager->playerActions->grandAuthLevel($callback[1][1], $actionArray[2], AuthenticationManager::AUTH_LEVEL_ADMIN); | ||||||
|  | 				break; | ||||||
|  | 			case self::ACTION_ADD_AS_MOD: | ||||||
|  | 				$this->maniaControl->playerManager->playerActions->grandAuthLevel($callback[1][1], $actionArray[2], AuthenticationManager::AUTH_LEVEL_OPERATOR); | ||||||
|  | 				break; | ||||||
|  | 			case self::ACTION_REVOKE_RIGHTS: | ||||||
|  | 				$this->maniaControl->playerManager->playerActions->revokeAuthLevel($callback[1][1], $actionArray[2]); | ||||||
|  | 				break; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  |  | ||||||
| 		/* |  | ||||||
| 		$addMaster = (strpos($actionId, self::ACTION_ADD_AS_MASTER) === 0); |  | ||||||
| 		$addAdmin = (strpos($actionId, self::ACTION_ADD_AS_ADMIN) === 0); |  | ||||||
| 		$addModerator = (strpos($actionId, self::ACTION_ADD_AS_MOD) === 0); |  | ||||||
| 		*/ |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| @@ -563,6 +591,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { | |||||||
| 				$player = $this->maniaControl->playerManager->getPlayer($login); | 				$player = $this->maniaControl->playerManager->getPlayer($login); | ||||||
| 				if($player != null) | 				if($player != null) | ||||||
| 					$this->showPlayerList($player); | 					$this->showPlayerList($player); | ||||||
|  | 				else | ||||||
|  | 					unset($this->playersListShown[$login]); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user