PageRenderTime 39ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/src/pocketmine/wizard/Installer.php

https://gitlab.com/Skull3x/GladiatorMine
PHP | 223 lines | 195 code | 6 blank | 22 comment | 1 complexity | 8c6c4e9d966210ee7b546e9c5e6f0b5a MD5 | raw file
  1. <?php
  2. /*
  3. *
  4. * ____ _ _ __ __ _ __ __ ____
  5. * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
  6. * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
  7. * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
  8. * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Lesser General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * @author PocketMine Team
  16. * @link http://www.pocketmine.net/
  17. *
  18. *
  19. */
  20. /**
  21. * Set-up wizard used on the first run
  22. * Can be disabled with --no-wizard
  23. */
  24. namespace pocketmine\wizard;
  25. use pocketmine\utils\Config;
  26. use pocketmine\utils\Utils;
  27. class Installer{
  28. const DEFAULT_NAME = "Minecraft: PE Server";
  29. const DEFAULT_PORT = 19132;
  30. const DEFAULT_MEMORY = 512;
  31. const DEFAULT_PLAYERS = 20;
  32. const DEFAULT_GAMEMODE = 0;
  33. private $lang;
  34. public function __construct(){
  35. echo "[*] Genisys set-up wizard\n";
  36. echo "[*] Please select a language:\n";
  37. foreach(InstallerLang::$languages as $short => $native){
  38. echo " $native => $short\n";
  39. }
  40. do{
  41. echo "[?] Language (eng): ";
  42. $lang = strtolower($this->getInput("eng"));
  43. if(!isset(InstallerLang::$languages[$lang])){
  44. echo "[!] Couldn't find the language\n";
  45. $lang = false;
  46. }
  47. }while($lang == false);
  48. $this->lang = new InstallerLang($lang);
  49. echo "[*] " . $this->lang->language_has_been_selected . "\n";
  50. if(!$this->showLicense()){
  51. @\pocketmine\kill(getmypid());
  52. exit(-1);
  53. }
  54. echo "[?] " . $this->lang->skip_installer . " (y/N): ";
  55. if(strtolower($this->getInput()) === "y"){
  56. return;
  57. }
  58. echo "\n";
  59. $this->welcome();
  60. $this->generateBaseConfig();
  61. $this->generateUserFiles();
  62. $this->networkFunctions();
  63. $this->endWizard();
  64. }
  65. public function getLang(){
  66. return $this->lang;
  67. }
  68. private function showLicense(){
  69. echo $this->lang->welcome_to_pocketmine . "\n";
  70. echo <<<LICENSE
  71. This program is free software: you can redistribute it and/or modify
  72. it under the terms of the GNU Lesser General Public License as published by
  73. the Free Software Foundation, either version 3 of the License, or
  74. (at your option) any later version.
  75. LICENSE;
  76. echo "\n[?] " . $this->lang->accept_license . " (y/N): ";
  77. if(strtolower($this->getInput("n")) != "y"){
  78. echo "[!] " . $this->lang->you_have_to_accept_the_license . "\n";
  79. sleep(5);
  80. return false;
  81. }
  82. return true;
  83. }
  84. private function welcome(){
  85. echo "[*] " . $this->lang->setting_up_server_now . "\n";
  86. echo "[*] " . $this->lang->default_values_info . "\n";
  87. echo "[*] " . $this->lang->server_properties . "\n";
  88. }
  89. private function generateBaseConfig(){
  90. $config = new Config(\pocketmine\DATA . "server.properties", Config::PROPERTIES);
  91. echo "[?] " . $this->lang->name_your_server . " (" . self::DEFAULT_NAME . "): ";
  92. $config->set("server-name", $this->getInput(self::DEFAULT_NAME));
  93. echo "[*] " . $this->lang->port_warning . "\n";
  94. do{
  95. echo "[?] " . $this->lang->server_port . " (" . self::DEFAULT_PORT . "): ";
  96. $port = (int) $this->getInput(self::DEFAULT_PORT);
  97. if($port <= 0 or $port > 65535){
  98. echo "[!] " . $this->lang->invalid_port . "\n";
  99. }
  100. }while($port <= 0 or $port > 65535);
  101. $config->set("server-port", $port);
  102. /*echo "[*] " . $this->lang->ram_warning . "\n";
  103. echo "[?] " . $this->lang->server_ram . " (" . self::DEFAULT_MEMORY . "): ";
  104. $config->set("memory-limit", ((int) $this->getInput(self::DEFAULT_MEMORY)) . "M");*/
  105. echo "[*] " . $this->lang->gamemode_info . "\n";
  106. do{
  107. echo "[?] " . $this->lang->default_gamemode . ": (" . self::DEFAULT_GAMEMODE . "): ";
  108. $gamemode = (int) $this->getInput(self::DEFAULT_GAMEMODE);
  109. }while($gamemode < 0 or $gamemode > 3);
  110. $config->set("gamemode", $gamemode);
  111. echo "[?] " . $this->lang->max_players . " (" . self::DEFAULT_PLAYERS . "): ";
  112. $config->set("max-players", (int) $this->getInput(self::DEFAULT_PLAYERS));
  113. echo "[*] " . $this->lang->spawn_protection_info . "\n";
  114. echo "[?] " . $this->lang->spawn_protection . " (Y/n): ";
  115. if(strtolower($this->getInput("y")) == "n"){
  116. $config->set("spawn-protection", -1);
  117. }else{
  118. $config->set("spawn-protection", 16);
  119. }
  120. $config->save();
  121. }
  122. private function generateUserFiles(){
  123. echo "[*] " . $this->lang->op_info . "\n";
  124. echo "[?] " . $this->lang->op_who . ": ";
  125. $op = strtolower($this->getInput(""));
  126. if($op === ""){
  127. echo "[!] " . $this->lang->op_warning . "\n";
  128. }else{
  129. $ops = new Config(\pocketmine\DATA . "ops.txt", Config::ENUM);
  130. $ops->set($op, true);
  131. $ops->save();
  132. }
  133. echo "[*] " . $this->lang->whitelist_info . "\n";
  134. echo "[?] " . $this->lang->whitelist_enable . " (y/N): ";
  135. $config = new Config(\pocketmine\DATA . "server.properties", Config::PROPERTIES);
  136. if(strtolower($this->getInput("n")) === "y"){
  137. echo "[!] " . $this->lang->whitelist_warning . "\n";
  138. $config->set("white-list", true);
  139. }else{
  140. $config->set("white-list", false);
  141. }
  142. $config->save();
  143. }
  144. private function networkFunctions(){
  145. $config = new Config(\pocketmine\DATA . "server.properties", Config::PROPERTIES);
  146. echo "[!] " . $this->lang->query_warning1 . "\n";
  147. echo "[!] " . $this->lang->query_warning2 . "\n";
  148. echo "[?] " . $this->lang->query_disable . " (y/N): ";
  149. if(strtolower($this->getInput("n")) === "y"){
  150. $config->set("enable-query", false);
  151. }else{
  152. $config->set("enable-query", true);
  153. }
  154. echo "[*] " . $this->lang->rcon_info . "\n";
  155. echo "[?] " . $this->lang->rcon_enable . " (y/N): ";
  156. if(strtolower($this->getInput("n")) === "y"){
  157. $config->set("enable-rcon", true);
  158. $password = substr(base64_encode(@Utils::getRandomBytes(20, false)), 3, 10);
  159. $config->set("rcon.password", $password);
  160. echo "[*] " . $this->lang->rcon_password . ": " . $password . "\n";
  161. }else{
  162. $config->set("enable-rcon", false);
  163. }
  164. /*echo "[*] " . $this->lang->usage_info . "\n";
  165. echo "[?] " . $this->lang->usage_disable . " (y/N): ";
  166. if(strtolower($this->getInput("n")) === "y"){
  167. $config->set("send-usage", false);
  168. }else{
  169. $config->set("send-usage", true);
  170. }*/
  171. $config->save();
  172. echo "[*] " . $this->lang->ip_get . "\n";
  173. $externalIP = Utils::getIP();
  174. $internalIP = gethostbyname(trim(`hostname`));
  175. echo "[!] " . $this->lang->get("ip_warning", ["{{EXTERNAL_IP}}", "{{INTERNAL_IP}}"], [$externalIP, $internalIP]) . "\n";
  176. echo "[!] " . $this->lang->ip_confirm;
  177. $this->getInput();
  178. }
  179. private function endWizard(){
  180. echo "[*] " . $this->lang->you_have_finished . "\n";
  181. echo "[*] " . $this->lang->pocketmine_plugins . "\n";
  182. echo "[*] " . $this->lang->pocketmine_will_start . "\n\n\n";
  183. sleep(4);
  184. }
  185. private function getInput($default = ""){
  186. $input = trim(fgets(STDIN));
  187. return $input === "" ? $default : $input;
  188. }
  189. }