forked from UltimaPHP/UltimaPHP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.core.php
138 lines (121 loc) · 4.19 KB
/
command.core.php
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
<?php
/**
* Ultima PHP - OpenSource Ultima Online Server written in PHP
* Version: 0.1 - Pre Alpha
*/
class Command {
/* Server variables */
static $list = [
'i' => [
'minPlevel' => 6,
],
'm' => [
'minPlevel' => 6,
],
'r' => [
'minPlevel' => 6,
],
'mapdump' => [
'minPlevel' => 6,
],
'color' => [
'minPlevel' => 2,
],
'tele' => [
'minPlevel' => 2,
],
'invis' => [
'minPlevel' => 4,
],
'where' => [
'minPlevel' => 1,
],
'sysmessage' => [
'minPlevel' => 2,
],
'emote' => [
'minPlevel' => 2,
],
'sendpacket' => [
'minPlevel' => 7,
],
'info' => [
'minPlevel' => 4,
],
'sound' => [
'minPlevel' => 2,
],
'music' => [
'minPlevel' => 2,
],
'update' => [
'minPlevel' => 2,
],
];
static $commandAlias = [
'add' => 'i',
'addchar' => 'm',
'remove' => 'r',
'go' => 'tele',
'sysm' => 'sysmessage',
'hide' => 'invis',
];
public function __construct() {
foreach (glob(UltimaPHP::$basedir . 'core/commands/*.command.php') as $file) {
if (!require_once ($file)) {
UltimaPHP::setStatus(UltimaPHP::STATUS_FILE_READ_FAIL, [$file]);
UltimaPHP::stop();
}
}
}
public static function threatCommand($client = null, $command = null, $sentFrom = null, $ignorePlevel = false) {
if ($client === null || $command === null) {
return false;
}
$tmp = explode(" ", $command);
$command = strtolower(substr($tmp[0], 1));
$tmp = array_slice($tmp, 1);
$args = (count($tmp) > 0 ? explode(",", implode(" ", $tmp)) : []);
return self::runCommand($client, $command, $args, $sentFrom, $ignorePlevel);
}
public static function runCommand($client = null, $command = null, $args = [], $sentFrom = null, $ignorePlevel = false) {
if ($client === null) {
return false;
}
if (!isset($command)) {
new SysmessageCommand($client, ["Sorry, but no command was received from client."]);
return false;
}
if (isset(self::$commandAlias[$command])) {
$command = self::$commandAlias[$command];
}
/* Check if there is an X before the command, meaning that the command will run in other player/object/mobile */
if (!isset(self::$list[$command]) && substr($command, 0, 1) == "x") {
new SysmessageCommand($client, ["Where do you want to execute this command?"]);
UltimaPHP::$socketClients[$client]['account']->player->attachTarget($client, ['method' => "GeneralCommandCallback", 'args' => ['command' => substr($command, 1), 'args' => $args]]);
return true;
}
if (!isset(self::$list[$command])) {
new SysmessageCommand($client, ["Sorry, the command you are trying to run was not been found."]);
return false;
}
if ($sentFrom !== null) {
if (!$ignorePlevel && self::$list[$command]['minPlevel'] > UltimaPHP::$socketClients[$sentFrom]['account']->plevel) {
new SysmessageCommand($client, ["Sorry, but you can't run this command, your account have no rights to do that."]);
return false;
}
} else {
if (!$ignorePlevel && self::$list[$command]['minPlevel'] > UltimaPHP::$socketClients[$client]['account']->plevel) {
new SysmessageCommand($client, ["Sorry, but you can't run this command, your account have no rights to do that."]);
return false;
}
}
$cmd = ucfirst($command) . "Command";
if (!class_exists($cmd)) {
new SysmessageCommand($client, ["Sorry, something strange happend... the command exists, but no class found for it."]);
return false;
}
new $cmd($client, $args);
return true;
}
}