-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.php
More file actions
244 lines (220 loc) · 7.43 KB
/
setup.php
File metadata and controls
244 lines (220 loc) · 7.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
const SERVERS = [
"lobby" => 19191,
"prison" => 19192,
"skyblock" => 19193,
"kitpvp" => 19194,
"factions" => 19195,
"survival" => 19196,
"creative" => 19197,
"clean" => 19198];
const PRISON = "prison";
const SKYBLOCK = "skyblock";
const LOBBY = "lobby";
const KITPVP = "kitpvp";
const FACTIONS = "factions";
const SURVIVAL = "survival";
const CREATIVE = "creative";
const SITE = "http://primegames.net/NxiDUSvqqqqrr/";
function write(string $line): void {
echo $line;
}
function writeln(string $line): void {
echo $line . PHP_EOL;
}
function doTask(string $message, Closure $task): void {
write("> " . $message . " ... ");
try {
$task();
} catch(RuntimeException $e) {
writeln("Error: " . $e->getMessage());
die;
}
writeln("done!");
}
function download(string $source, string $destination): void{
$context = stream_context_create(["ssl" => [
"verify_peer" => false,
"verify_peer_name" => false
]]);
if(!copy($source, $destination, $context)) {
throw new RuntimeException("Failed to download file from $source");
}
}
function syncRepo(string $addr, string $output) : void{
if(!is_dir($output)){
@unlink($output);
doTask("Cloning git repository $addr into $output", static function() use ($addr, $output){
$result = 0;
passthru("git clone --quiet $addr \"$output\"", $result);
if($result !== 0){
throw new RuntimeException("Failed to clone repo");
}
});
}else{
doTask("Updating repository $output", static function() use ($output){
$result = 0;
passthru("git -C \"$output\" fetch --quiet", $result);
if($result !== 0){
throw new RuntimeException("Failed to fetch repository branches for repository $output");
}
passthru("git -C \"$output\" merge --quiet --ff-only FETCH_HEAD", $result);
if($result !== 0) {
throw new RuntimeException("Failed to integrate remote changes cleanly for repository $output, please update manually");
}
});
}
}
writeln("--- PrimeGames Developer Environment Setup ---");
$opts = getopt("", [
"pm",
"plugins",
"worlds",
"virions",
"bin",
"all"]);
//download pmmp php binary
if(isset($opts["all"]) or isset($opts["bin"])) {
if(is_dir(getcwd() . "/bin")) {
unlink(getcwd() . "/bin");
}
shell_exec(getcwd() . "/.bindownload.sh");
}
if(isset($opts["pm"])){
if(is_file(__DIR__ . "/servers/" . "/PocketMine-MP.phar")){
unlink(__DIR__ . "/servers/" . "/PocketMine-MP.phar");
}
foreach(SERVERS as $SERVER => $PORT){
if(is_file(__DIR__ . "/servers/" . $SERVER . "/PocketMine-MP.phar")){
unlink(__DIR__ . "/servers/" . $SERVER . "/PocketMine-MP.phar");
}
}
}
@mkdir(__DIR__ . "/servers");
if(isset($opts["pm"]) or isset($opts["all"])) {
doTask("Downloading PocketMine-MP.phar", static function() {
$pmCurl = curl_init();
curl_setopt_array($pmCurl, array(
CURLOPT_URL => "https://update.pmmp.io/api/?channel=stable",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache"
),
));
$response = curl_exec($pmCurl);
$err = curl_error($pmCurl);
curl_close($pmCurl);
$response = json_decode($response, true);
download($response["download_url"], getcwd() . "/servers/PocketMine-MP.phar");
});
}
const PLUGINS = [
// "Creative",
"Factions",
"Lobby",
"KitPvP",
"Primer",
"Prison",
"SkyBlock",
"Survival",
"CustomEnchants",
"PureEntitiesX"];
if(isset($opts["plugins"]) or isset($opts["all"])) { //
writeln("> Cloning plugin repositories");
@mkdir(__DIR__ . "/plugins");
foreach(PLUGINS as $p) {
//TODO: we'll probably need access tokens here for non-windows platforms
syncRepo("https://github.com/PrimeGamesDevTeam/$p.git", __DIR__ . "/plugins/$p");
}
}
if(isset($opts["worlds"]) or isset($opts["all"])) {
writeln(PHP_EOL . "> Setting up worlds. This may take a few minutes ... ");
@mkdir(__DIR__ . "/server/worlds");
writeln("");
$globalWorlds = [
PRISON => [
"prisonspawn",
"pvpmine",
"jailbreak",
"aresmine",
"irismine",
"hadesmine",
"poseidonmine",
"zeusmine",
"titanmine",
"deathmatch"],
SKYBLOCK => [
"skyblock",
"skyblockpvp"],
FACTIONS => [
"factions",
"factionswild"],
SURVIVAL => ["survivalspawn",
"survivalcave",
"survivalmine",
"survivalnether",
"survivalbaarn"],
CREATIVE => ["creative"],
LOBBY => ["lobby"],
KITPVP => ["kitpvp"]];
foreach(range("A", "Z") as $mineDesignator) {
array_push($globalWorlds[PRISON], "Mine$mineDesignator");
}
foreach($globalWorlds as $gamemode => $worlds) {
if(!is_dir(__DIR__ . "/servers/$gamemode")) {
mkdir(__DIR__ . "/servers/$gamemode");
}
if(!is_dir(__DIR__ . "/servers/$gamemode/plugins")) {
mkdir(__DIR__ . "/servers/$gamemode/plugins");
}
if(!is_dir(__DIR__ . "/servers/$gamemode/worlds")) {
mkdir(__DIR__ . "/servers/$gamemode/worlds");
}
}
foreach($globalWorlds as $gamemode => $worlds) {
$worldDir = getcwd() . "/servers/$gamemode/worlds/";
if(is_array($worlds) || is_object($worlds)) {
foreach($worlds as $world) {
if(is_dir($worldDir . $world) and is_file($worldDir . $world . DIRECTORY_SEPARATOR . "level.dat")) {
continue;
}
doTask("Downloading $world.zip", static function() use ($worldDir, $world) {
download(SITE . "$world.zip", $worldDir . "$world.zip");
write("Unpacking archive ... ");
$zip = new ZipArchive();
$res = $zip->open($worldDir . "$world.zip");
if($res === false) {
throw new RuntimeException("Damaged or corrupted file $world.zip");
}
@mkdir($worldDir . $world);
$zip->extractTo($worldDir);
$zip->close();
unlink($worldDir . "$world.zip");
});
}
}
}
}
writeln("--- Setup Completed ---");