Advertisement
Guest User

Untitled

a guest
Sep 28th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. <?php namespace migrate;
  2.  
  3. use pocketmine\plugin\PluginBase;
  4. use pocketmine\utils\Config;
  5. use pocketmine\Player;
  6.  
  7. use pocketmine\event\Listener;
  8. use pocketmine\event\server\DataPacketReceiveEvent;
  9. use pocketmine\network\mcpe\protocol\ModalFormResponsePacket;
  10.  
  11. class Migrate extends PluginBase implements Listener{
  12.  
  13. public $pureperms;
  14. public $simpleauth;
  15.  
  16. public $pudir;
  17. public $sudir;
  18.  
  19. public function onEnable(){
  20. $this->pureperms = $this->getServer()->getPluginManager()->getPlugin("PurePerms");
  21. $this->simpleauth = $this->getServer()->getPluginManager()->getPlugin("SimpleAuth");
  22. if($this->pureperms == null || $this->simpleauth == null){
  23. $this->getLogger()->error("This plugin requires the following plugins: PurePerms, SimpleAuth. One or more not found. Disabling plugin.");
  24. $this->getServer()->getPluginManager()->disablePlugin($this);
  25. return;
  26. }
  27.  
  28. @mkdir($this->getDataFolder());
  29. if(!file_exists($this->getDataFolder() . "IMPORTANT")){
  30. file_put_contents($this->getDataFolder() . "IMPORTANT", "Do not remove this file! Removing this will restart the migration process.\nThis migration plugin was made by your bae, Shane Malin (mal0ne_23)\nin return for $50\nDo not distribute, cunt. <3");
  31. $p = $this->pureperms->getDataFolder() . "players/";
  32.  
  33. $this->pudir = $this->pureperms->getDataFolder() . "old/";
  34. @mkdir($this->pudir);
  35. try{
  36. $file_names = scandir($p);
  37. if(is_array($file_names)) foreach($file_names as $file) if($file != "." && $file != "..") rename($p . $file, $this->pudir . $file);
  38. }catch(\Exception $e){
  39. //fuck this
  40. }
  41.  
  42. $s = $this->simpleauth->getDataFolder();
  43. $this->sudir = $s . "old/";
  44. @mkdir($this->sudir);
  45. $keys = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9","_"];
  46. foreach($keys as $key){
  47. $ldir = $s . $key . "/";
  48. try{
  49. $file_names = scandir($ldir);
  50. if(is_array($file_names)) foreach($file_names as $file) if($file != "." && $file != "..") rename($ldir . $file, $this->sudir . $file);
  51. }catch(\Exception $e){
  52. //bullshit
  53. }
  54. }
  55. }
  56.  
  57. $this->getServer()->getCommandMap()->register("migrate", new MigrateCommand($this, "migrate", "Migrate your account!"));
  58. }
  59.  
  60. public function loginCorrect($username, $password){
  61. if(!$this->canMigrate($username)) return false;
  62.  
  63. $password = $this->hash($username, $password);
  64.  
  65. $authfile = new Config($this->sudir . $username . ".yml", Config::YAML);
  66. $all = $authfile->getAll();
  67.  
  68. $hash = $all["hash"];
  69. return hash_equals($hash, $password);
  70. }
  71.  
  72. public function hash($salt, $password){
  73. return bin2hex(hash("sha512", $password . $salt, true) ^ hash("whirlpool", $salt . $password, true));
  74. }
  75.  
  76. public function canMigrate($username){
  77. if(!file_exists($this->pudir . $username . ".yml")) return false;
  78. if(!file_exists($this->sudir . $username . ".yml")) return false;
  79.  
  80. $authfile = new Config($this->sudir . $username . ".yml", Config::YAML);
  81. $all = $authfile->getAll();
  82. if(!isset($all["hash"])) return false;
  83.  
  84. $file = new Config($this->pudir . $username . ".yml", Config::YAML);
  85. return $file->get("canmigrate", true) ?? true;
  86. }
  87.  
  88. public function setCanMigrate($username, $can = false){
  89. $file = new Config($this->sudir . $username . ".yml", Config::YAML);
  90. $file->set("canmigrate", $can);
  91. $file->save();
  92. }
  93.  
  94. public function migrate(Player $player, $username){
  95. $this->setCanMigrate($username);
  96.  
  97. $pfile = new Config($this->pudir . $username . ".yml", Config::YAML);
  98. $group = $pfile->get("group");
  99. $this->pureperms->getUserDataMgr()->setGroup($player, $this->pureperms->getGroup($group) ?? $this->pureperms->getDefaultGroup(null), null);
  100. }
  101.  
  102. public function onDpr(DataPacketReceiveEvent $e){
  103. $player = $e->getPlayer();
  104. $packet = $e->getPacket();
  105.  
  106. if($packet instanceof ModalFormResponsePacket){
  107. if($packet->formId == 420){ //lel
  108. $data = json_decode(json_encode($packet->formData), true);
  109. if($data == null) return;
  110. $username = $data[0];
  111. $password = $data[1];
  112. }
  113. }
  114. }
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement