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