This repository was archived by the owner on Nov 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRunnable.php
More file actions
181 lines (159 loc) · 4.8 KB
/
Runnable.php
File metadata and controls
181 lines (159 loc) · 4.8 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
<?php
declare(strict_types=1);
namespace Runnable {
use BaseClassLoader;
use client\Client;
use client\RakNetPool;
use pocketmine\entity\Attribute;
use pocketmine\network\mcpe\protocol\PacketPool;
use pocketmine\utils\Terminal;
use function cli_set_process_title;
use function define;
use function getcwd;
use function ini_set;
use function realpath;
info('Load MSClient..');
info('Setting client...');
@define('CLIENTPATH', realpath(getcwd()) . DIRECTORY_SEPARATOR);
@define('CLIENTNAME', 'MSClient v1.0');
@define("ENDIANNESS", (pack("d", 1) === "\77\360\0\0\0\0\0\0" ? 0 : 1));
@define("INT32_MASK", is_int(0xffffffff) ? 0xffffffff : -1);
@cli_set_process_title(CLIENTNAME);
@ini_set('memory_limit', '-1');
assert_options(ASSERT_ACTIVE, 1);
assert_options(ASSERT_WARNING, 1);
assert_options(ASSERT_QUIET_EVAL, 1);
info('Run class loader..');
if (!is_file(CLIENTPATH . "spl/ClassLoader.php")) {
echo "[CRITICAL] Unable to find the client-SPL library." . PHP_EOL;
echo "[CRITICAL] Please use provided builds or clone the repository recursively." . PHP_EOL;
exit(1);
}
require_once(CLIENTPATH . "spl/ClassLoader.php");
require_once(CLIENTPATH . "spl/BaseClassLoader.php");
$autoloader = new BaseClassLoader();
$autoloader->addPath(CLIENTPATH);
$autoloader->register(true);
info('Init all classes..');
RakNetPool::init();
PacketPool::init();
Attribute::init();
Terminal::init();
info('Started client!');
$client = new Client();
while (true) $client->tick();
}
namespace {
/**
* @param string $text
*/
function send(string $text)
{
echo colorize('%purple%LOG%gray% > %white%' . $text . '%reset%') . PHP_EOL;
}
/**
* @param string $text
*/
function debug(string $text)
{
echo colorize('%gray%DEBUG%gray% > %white%' . $text . '%reset%') . PHP_EOL;
}
/**
* @param string $text
*/
function info(string $text)
{
echo colorize('%aqua%INFO%gray% > %white%' . $text . '%reset%') . PHP_EOL;
}
/**
* @param string $text
*/
function error(string $text)
{
echo colorize('%red%ERROR%gray% > %white%' . $text . '%reset%') . PHP_EOL;
}
/**
* @param string $type
* @param string $text
*/
function mess(string $type, string $text)
{
$array = explode("\n", $text);
foreach ($array as $mess) if (preg_replace('/\s+/', '', $mess) !== '') echo colorize('%aqua%' . $type . '%gray% > %white%' . $mess . '%reset%') . PHP_EOL;
}
/**
* @param string $text
* @return mixed|string
*
* https://en.wikipedia.org/wiki/ANSI_escape_code
* ESC[ 38:5:⟨n⟩ m - Select foreground color
* ESC[ 48:5:⟨n⟩ m - Select background color
*/
function colorize(string $text)
{
$text = str_replace('%aqua%', "\e[38;5;87m", $text);
$text = str_replace('%white%', "\x1b[38;5;231m", $text);
$text = str_replace('%red%', "\x1b[38;5;9m", $text);
$text = str_replace('%reset%', "\x1b[m", $text);
$text = str_replace('%gray%', "\x1b[38;5;145m", $text);
$text = str_replace('%purple%', "\x1b[38;5;127m", $text);
$text = str_replace('%green%', "\x1b[38;5;83m", $text);
return $text;
}
/**
* Shutdown client
*/
function shutdown()
{
gc_collect_cycles();
@kill(getmypid());
}
/**
* @param $pid
*/
function kill($pid)
{
switch (getOS()) {
case "win":
exec("taskkill.exe /F /PID " . ((int)$pid) . " > NUL");
break;
case "mac":
case "linux":
default:
if (function_exists("posix_kill")) {
posix_kill($pid, SIGKILL);
} else {
exec("kill -9 " . ((int)$pid) . " > /dev/null 2>&1");
}
}
}
/**
* @param bool $recalculate
* @return string
*/
function getOS(bool $recalculate = false): string
{
$os = "other";
if ($recalculate) {
$uname = php_uname("s");
if (stripos($uname, "Darwin") !== false) {
if (strpos(php_uname("m"), "iP") === 0) {
$os = "ios";
} else {
$os = "mac";
}
} elseif (stripos($uname, "Win") !== false or $uname === "Msys") {
$os = "win";
} elseif (stripos($uname, "Linux") !== false) {
if (@file_exists("/system/build.prop")) {
$os = "android";
} else {
$os = "linux";
}
} elseif (stripos($uname, "BSD") !== false or $uname === "DragonFly") {
$os = "bsd";
}
}
return $os;
}
}