Last active
August 29, 2015 14:23
-
-
Save PEMapModder/4665407af4a39e315ec0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <?php | |
| @define("STDIN", fopen("php://stdin", "rt")); | |
| function query($query){ | |
| echo $query; | |
| return trim(fgets($query)); | |
| } | |
| function out($message){ | |
| echo date("[H:i:s] ") . $message . PHP_EOL; | |
| } | |
| function quit($message, $code = 2){ | |
| out("Fatal: " . $message); | |
| exit($code); | |
| } | |
| function addPlayer($name, $data){ | |
| global $players; | |
| $data["name"] = $name; | |
| $players[$name] = $data; | |
| } | |
| $players = []; | |
| $path = query("Location of SimpleAuth players folder (relative to " . getcwd() . " or absolute): "); | |
| if(!is_dir($path)){ | |
| quit("$path is not a directory!"); | |
| } | |
| if(trim(basename($path), "/\\") !== "players") { | |
| quit("The SimpleAuth players folder is named 'players instead of '" . basename($path) . "'."); | |
| } | |
| chdir($path); | |
| foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(".")) as $file){ | |
| if(is_file($file) and substr($file, -4) !== ".yml"){ | |
| addPlayer(basename($file, ".yml"), yaml_parse(file_get_contents($file))); | |
| } | |
| } | |
| out("Finished loading database. Exporting to MySQL."); | |
| $db = new mysqli(query("MySQL host: "), query("MySQL username: "), query("MySQL password: "), query("MySQL database name: ")); | |
| out("Preparing database..."); | |
| $db->query("CREATE TABLE IF NOT EXISTS simpleauth_players(name VARCHAR(16) PRIMARY KEY,hash CHAR(128),registerdate INT,logindate INT,lastip VARCHAR(50));"); | |
| out("Preparing query..."); | |
| $query = "INSERT INTO simpleauth_players(name, registerdate, logindate, lastip, hash)VALUES"; | |
| $i = 0; | |
| $query .= implode(",", array_map(function($datum){ | |
| global $i; | |
| extract($datum); | |
| echo "[" . (++$i) . "] $name\r"; | |
| $name = $db->escape_string($name); | |
| $lastip = $db->escape_string($lastip); | |
| $hash = $db->escape_string($hash); | |
| return "('$name',$registerdate,$logindate,'$lastip','$hash')"; | |
| }, $players)); | |
| out("Sending a query of " . strlen($query) . " bytes to MySQL database..."); | |
| $r = $db->query($query); | |
| $db->close(); | |
| quit("Completed query with result: " . var_export($r, true), 1); |
Do you have time to fix this?
matthew@MineCraft2Matthew:~/Pocketmine/plugins/SimpleAuth$ php Port-SimpleAuth.php
Location of SimpleAuth players folder (relative to /home/matthew/Pocketmine/plugins/SimpleAuth or absolute): PHP Warning: fgets() expects parameter 1 to be resource, string given in /home/matthew/Pocketmine/plugins/SimpleAuth/Port-SimpleAuth.php on line 5
[16:55:47] Fatal: is not a directory!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thnx for making this
but i have error when i do php Port-SimpleAuth.php
i get this error:
PHP Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ',' or ';' in /home/matthew/Port-SimpleAuth.php on line 8