GetUsername() ), $this->GetWhitelistedNames() ); } private $RCon = null; private function GetRCon() { if ( $this->RCon == null ) $this->RCon = new Rcon( $this->GetDomain(), $this->GetPort(), $this->GetPassword(), 1500 ); return $this->RCon; } public function Unlock( MinecraftUser $user, bool $keepOpen = false ): bool { $rcon = $this->GetRCon(); if ( !$rcon->isConnected() ) $rcon->connect(); $rcon->sendCommand( 'whitelist add ' . $user->GetUsername() ); $res = $rcon->getResponse(); if ( !$keepOpen ) $rcon->disconnect(); return $this->IsUnlocked( $user ); } public function Lock( MinecraftUser $user, bool $keepOpen = false ): bool { $rcon = $this->GetRCon(); if ( !$rcon->isConnected() ) $rcon->connect(); $rcon->sendCommand( 'whitelist remove ' . $user->GetUsername() ); $res = $rcon->getResponse(); if ( !$keepOpen ) $rcon->disconnect(); return !$this->IsUnlocked( $user ); } public function GetWhitelistedNames( bool $keepOpen = false ) { // There are 1 whitelisted players: DragonSkills99 $rcon = $this->GetRCon(); if ( !$rcon->isConnected() ) $rcon->connect(); $rcon->sendCommand( 'whitelist list' ); $res = $rcon->getResponse(); if ( !$keepOpen ) $rcon->disconnect(); if ( nocase_compare( 'There are no whitelisted players', trim( $res ) ) ) return []; preg_match( '/^There are [0-9]+ whitelisted players: (.*)/', trim( $res ), $m ); if ( !isset( $m[ 1 ] ) ) return []; $players = explode( ', ', strtolower( $m[ 1 ] ) ); if ( trim( $players[ 0 ] ) == '' ) return []; else return $players; } public function ClearWhitelist( int $tries = 3 ) { $rcon = $this->GetRCon(); $players = $this->GetWhitelistedNames( true ); if ( !count( $players ) ) { $rcon->disconnect(); return true; } foreach ( $players as $player ) { $rcon->sendCommand( "whitelist remove $player" ); } $nplayers = $this->GetWhitelistedNames( true ); if ( count( $nplayers ) ) { if ( $tries > 0 ) $this->ClearWhitelist( $tries - 1 ); else { $rcon->disconnect(); return false; } } $rcon->disconnect(); return true; } }