public function read($params, AccountWriter $writer)
 {
     $args = new FormattedArgumentMap($params);
     $folder = $args->opt("i", "plugins/SimpleAuth");
     if (!is_dir($folder)) {
         throw new \InvalidArgumentException("Input database {$folder} not found or is not a directory");
     }
     $path = rtrim($folder, "/\\") . "/players.db";
     if (!is_file($path)) {
         return;
     }
     $this->setStatus("Opening database");
     $db = new \SQLite3($path);
     $result = $db->query("SELECT COUNT(*) AS cnt FROM players");
     $total = $result->fetchArray(SQLITE3_ASSOC)["cnt"];
     $result->finalize();
     $this->setStatus("Preparing data");
     $result = $db->query("SELECT name,registerdate,logindate,lastip,hash FROM players");
     $i = 0;
     while (is_array($row = $result->fetchArray(SQLITE3_ASSOC))) {
         $i++;
         $info = AccountInfo::defaultInstance($row["name"], $this->defaultOpts);
         $info->lastIp = $row["lastip"];
         $info->registerTime = $row["registerdate"];
         $info->lastLogin = $row["logindate"];
         $info->passwordHash = hex2bin($row["hash"]);
         $writer->write($info);
         $this->setProgress($i / $total);
     }
     $db->close();
 }
 public function read($params, AccountWriter $writer)
 {
     $args = new FormattedArgumentMap($params);
     $folder = $args->opt("i", "plugins/ServerAuth");
     if (!is_dir($folder)) {
         throw new \InvalidArgumentException("Input database {$folder} not found or is not a directory");
     }
     $folder = rtrim($folder, "/\\") . DIRECTORY_SEPARATOR;
     $configFile = $folder . "config.yml";
     if (($hashMethod = $args->opt("hash", null)) === null) {
         if (is_file($configFile)) {
             try {
                 $hashMethod = yaml_parse($configFile)["passwordHash"];
             } catch (\Exception $e) {
                 $hashMethod = "md5";
             }
         } else {
             $hashMethod = "md5";
         }
     }
     $users = $folder . "users/";
     $this->setStatus("Collecting files");
     $names = scandir($users);
     $namesCnt = count($names);
     $this->setStatus("Transferring data");
     foreach ($names as $i => $name) {
         $this->setStatus($i / $namesCnt);
         $file = $users . $name;
         if (!is_file($file) or !preg_match('@^[A-Za-z0-9_]{3,16}\\.yml$@', $name)) {
             continue;
         }
         $name = substr($file, 0, -4);
         $data = yaml_parse_file($file);
         $ai = AccountInfo::defaultInstance($name, $this->defaultOpts);
         $ai->passwordHash = "{IMPORTED}";
         $ai->lastIp = $data["ip"];
         $ai->registerTime = $data["firstlogin"];
         $ai->lastLogin = $data["lastlogin"];
         $ai->multiHash = ["saltless;" . $hashMethod => $data["password"], "nonhash:salt" => strtolower($name)];
         $writer->write($ai);
     }
 }
 public function read($params, AccountWriter $writer)
 {
     $args = new FormattedArgumentMap($params);
     $folder = $args->opt("i", "plugins/SimpleAuth");
     if (!is_dir($folder)) {
         throw new \InvalidArgumentException("Input database {$folder} not found or is not a directory");
     }
     $folder = rtrim($folder, DIRECTORY_SEPARATOR) . "/";
     $dir = $folder . "players/";
     $this->setStatus("Indexing accounts");
     $alphas = array_filter(scandir($dir), function ($alpha) use($dir) {
         return $alpha !== "." and strlen(rtrim($alpha, DIRECTORY_SEPARATOR)) === 1 and is_dir($dir . $alpha);
     });
     $alphaCnt = count($alphas);
     $this->setStatus("Transferring data");
     foreach ($alphas as $i => $alpha) {
         $base = $i / $alphaCnt;
         $subdir = $dir . rtrim($alpha, DIRECTORY_SEPARATOR) . "/";
         $names = scandir($subdir);
         $namesCnt = count($names);
         foreach ($names as $cnt => $name) {
             $this->setProgress($base + $cnt / $namesCnt / $alphaCnt);
             if (!preg_match('@^[A-za-z0-9_]{3,16}\\.yml$@', $name)) {
                 continue;
             }
             $data = yaml_parse_file($subdir . $name);
             $name = substr($name, 0, -4);
             if (!is_array($data)) {
                 continue;
             }
             $info = AccountInfo::defaultInstance($name, $this->defaultOpts);
             $info->passwordHash = hex2bin($data["hash"]);
             $info->lastIp = $data["lastip"];
             $info->registerTime = $data["registerdate"];
             $info->lastLogin = $data["logindate"];
             $writer->write($info);
         }
     }
     $this->setProgress(1.0);
 }
 public function read($params, AccountWriter $writer)
 {
     $args = new FormattedArgumentMap($params);
     $this->cred->host = $args->opt("h", $this->cred->host);
     $this->cred->username = $args->opt("u", $this->cred->username);
     $this->cred->password = $args->opt("p", $this->cred->password);
     $this->cred->schema = $args->opt("d", $this->cred->schema);
     $this->cred->schema = $args->opt("s", $this->cred->schema);
     $this->cred->port = (int) $args->opt("port", $this->cred->port);
     $this->cred->socket = $args->opt("socket", $this->cred->socket);
     $this->cred->socket = $args->opt("sk", $this->cred->socket);
     $this->setStatus("Connecting");
     $conn = MySQLDatabase::createMysqliInstance($this->cred);
     if (isset($conn->connect_error)) {
         throw new \InvalidArgumentException("Could not connect to {$this->cred}");
     }
     $this->setStatus("Preparing data");
     $result = $conn->query("SELECT name, registerdate, logindate, lastip, hash FROM simpleauth_players");
     $this->setStatus("Transferring data");
     if ($result instanceof \mysqli_result) {
         $this->setProgress(0.0);
         $rows = 0;
         while (is_array($row = $result->fetch_assoc())) {
             $info = AccountInfo::defaultInstance($row["name"], $this->defaultOpts);
             $info->registerTime = (int) $row["registerdate"];
             $info->lastLogin = (int) $row["logindate"];
             $info->lastIp = $result["lastip"];
             $info->passwordHash = hex2bin($result["hash"]);
             $writer->write($info);
             $this->setProgress(++$rows / $result->num_rows);
         }
         $result->close();
     } else {
         throw new \InvalidArgumentException("Not a SimpleAuth user database");
     }
 }
 public function read($params, AccountWriter $writer)
 {
     $args = new FormattedArgumentMap($params);
     $this->cred->host = $args->opt("h", $this->cred->host);
     $this->cred->username = $args->opt("u", $this->cred->username);
     $this->cred->password = $args->opt("p", $this->cred->password);
     $this->cred->schema = $args->opt("d", $this->cred->schema);
     $this->cred->schema = $args->opt("s", $this->cred->schema);
     $this->cred->port = (int) $args->opt("port", $this->cred->port);
     $this->cred->socket = $args->opt("socket", $this->cred->socket);
     $this->cred->socket = $args->opt("sk", $this->cred->socket);
     $this->setStatus("Connecting");
     $conn = MySQLDatabase::createMysqliInstance($this->cred);
     if (isset($conn->connect_error)) {
         throw new \InvalidArgumentException("Could not connect to {$this->cred}");
     }
     $prefix = $args->opt("prefix", null);
     $prefix = $args->opt("pfx", $prefix);
     if ($prefix === null) {
         $this->setStatus("Searching for tables");
         $result = $conn->query("SHOW TABLES LIKE '%serverauth%'");
         if ($result === false) {
             throw new \InvalidArgumentException("Could not search tables");
         }
         $prefixes = [];
         while (is_array($row = $result->fetch_array(MYSQLI_NUM))) {
             if (StringUtils::endsWith($row[0], "serverauth")) {
                 $prefix = substr($row[0], 0, -10);
                 if (isset($prefixes[$prefix])) {
                     $prefixes[$prefix]++;
                 } else {
                     $prefix[$prefix] = 1;
                 }
             } elseif (StringUtils::endsWith($row[0], "serverauthdata")) {
                 $prefix = substr($row[0], 0, -14);
                 if (isset($prefixes[$prefix])) {
                     $prefixes[$prefix]++;
                 } else {
                     $prefix[$prefix] = 1;
                 }
             }
         }
         $result->close();
         foreach ($prefixes as $prefix => $cnt) {
             if ($cnt === 2) {
                 $ok = true;
                 break;
             }
         }
         if (!isset($ok)) {
             throw new \RuntimeException("ServerAuth tables not found in {$this->cred}");
         }
     }
     $serverAuthTable = $prefix . "serverauth";
     $serverAuthDataTable = $prefix . "serverauthdata";
     $hashMethod = $args->opt("hash", null);
     if ($hashMethod === null) {
         $this->setStatus("Detecting hash algorithm");
         $result = $conn->query("SELECT password_hash FROM `{$serverAuthTable}`");
         $row = $result->fetch_assoc();
         if (!is_array($row)) {
             throw new \RuntimeException("Corrupted ServerAuth database: serverauth table empty");
         }
         $hashMethod = $row["password_hash"];
         if (!in_array($hashMethod, hash_algos())) {
             throw new \RuntimeException("ServerAuth database uses a hash algorithm not supported by PHP " . PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION . "." . PHP_RELEASE_VERSION . ". This may imply a corrupted database.");
         }
     }
     $this->setStatus("Preparing data for transfer");
     $result = $conn->query("SELECT user,password,ip,firstlogin,lastlogin FROM `{$serverAuthDataTable}`");
     $this->setStatus("Transferring");
     if ($result instanceof \mysqli_result) {
         $rows = 0;
         while (is_array($row = $result->fetch_assoc())) {
             $info = AccountInfo::defaultInstance($result["user"], $this->defaultOpts);
             $info->registerTime = (int) $result["firstlogin"];
             $info->lastLogin = (int) $result["lastlogin"];
             $info->lastIp = $result["ip"];
             $info->passwordHash = "{IMPORTED}";
             $info->multiHash = ["saltless;" . $hashMethod => $result["password"], "nonhash:salt" => strtolower($result["user"])];
             $writer->write($info);
             $this->setProgress(++$rows / $result->num_rows);
         }
         $result->close();
     } else {
         throw new \InvalidArgumentException("Not a SimpleAuth user database");
     }
 }