This repository has been archived by the owner on Jun 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ServerAuth convert + Bug fixes for SimpleAuth converter + Czech trans…
…lations @lolmanz0 @SleepSpace9 @miguel456 Need to translate invalid-hash-algorithm.
- Loading branch information
Showing
11 changed files
with
150 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
namespace PiggyAuth\Converter; | ||
|
||
use pocketmine\utils\Config; | ||
|
||
class ServerAuthConverter implements Converter | ||
{ | ||
|
||
public function __construct($plugin) | ||
{ | ||
$this->plugin = $plugin; | ||
} | ||
|
||
public function convertFromSQLite3($file, $algorithm, $table) | ||
{ | ||
return false; | ||
} | ||
|
||
public function convertFromMySQL($host, $user, $password, $name, $port, $table, $algorithm) | ||
{ | ||
$credentials = $this->plugin->getConfig()->get("mysql"); | ||
$database = null; | ||
$algorithms = hash_algos(); | ||
if (in_array($algorithm, $algorithms)) { | ||
if ($credentials["host"] == $host && $credentials["user"] == $user && $credentials["password"] == $password && $credentials["name"] == $name && $credentials["port"] == $port) { | ||
$database = $this->plugin->database->db; | ||
} else { | ||
$database = new \mysqli($credentials["host"], $credentials["user"], $credentials["password"], $credentials["name"], $credentials["port"]); | ||
} | ||
$result = $database->query("SELECT * FROM " . $table); | ||
if ($result instanceof \mysqli_result) { | ||
while ($row = $result->fetch_assoc()) { | ||
if ($this->plugin->database->getOfflinePlayer($row["user"])) { | ||
$this->plugin->getLogger()->info(str_replace("{player}", $row["user"], $this->plugin->languagemanager->getMessageFromLanguage($this->plugin->languagemanager->getDefaultLanguage(), "player-account-already-exists"))); | ||
continue; | ||
} | ||
$this->plugin->database->insertDataWithoutPlayerObject($row["user"], $row["password"], "none", mt_rand(1000, 9999), "ServerAuth_" . $algorithm); | ||
} | ||
$result->free(); | ||
return true; | ||
} | ||
} else { | ||
$this->plugin->getLogger()->info(str_replace("{algorithms}", implode(", ", $algorithms), str_replace("{algorithm}", $algorithm, $this->plugin->languagemanager->getMessageFromLanguage($this->plugin->languagemanager->getDefaultLanguage(), "invalid-hash-algorithm")))); | ||
return false; | ||
} | ||
} | ||
|
||
public function convertFromYML($directoryname, $algorithm) | ||
{ | ||
$algorithms = hash_algos(); | ||
if (in_array($algorithm, $algorithms)) { | ||
if (is_dir($this->plugin->getDataFolder() . "convert/" . $directoryname . "/")) { | ||
$files = scandir($this->plugin->getDataFolder() . "convert/" . $directoryname . "/"); | ||
foreach ($files as $file) { | ||
if ($file !== "." && $file !== "..") { | ||
if (strpos($file, ".yml") !== false) { | ||
$yml = new Config($this->plugin->getDataFolder() . "convert/" . $directoryname . "/" . $file); | ||
$data = $yml->getAll(); | ||
$name = str_replace(".yml", "", $file); | ||
if ($this->plugin->database->getOfflinePlayer($name)) { | ||
$this->plugin->getLogger()->info(str_replace("{player}", $name, $this->plugin->languagemanager->getMessageFromLanguage($this->plugin->languagemanager->getDefaultLanguage(), "player-account-already-exists"))); | ||
continue; | ||
} | ||
$this->plugin->database->insertDataWithoutPlayerObject($name, $data["password"], "none", mt_rand(1000, 9999), "ServerAuth_" . $algorithm); | ||
} else { | ||
$this->plugin->getLogger()->info(str_replace("{file}", $file, $this->plugin->languagemanager->getMessageFromLanguage($this->plugin->languagemanager->getDefaultLanguage(), "file-not-yml"))); | ||
} | ||
} | ||
} | ||
} else { | ||
$this->plugin->getLogger()->info(str_replace("{file}", $directoryname, $this->plugin->languagemanager->getMessageFromLanguage($this->plugin->languagemanager->getDefaultLanguage(), "invalid-directory"))); | ||
return false; | ||
} | ||
} else { | ||
$this->plugin->getLogger()->info(str_replace("{algorithms}", implode(", ", $algorithms), str_replace("{algorithm}", $algorithm, $this->plugin->languagemanager->getMessageFromLanguage($this->plugin->languagemanager->getDefaultLanguage(), "invalid-hash-algorithm")))); | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters