]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace UnrealIRCd; | |
4 | ||
5 | use Exception; | |
6 | use stdClass; | |
7 | ||
8 | class ServerBan | |
9 | { | |
10 | ||
11 | public Connection $connection; | |
12 | ||
13 | public function __construct(Connection $conn) | |
14 | { | |
15 | $this->connection = $conn; | |
16 | } | |
17 | ||
18 | /** | |
19 | * Add a ban. | |
20 | * | |
21 | * @param string $user | |
22 | * @return stdClass|array|bool | |
23 | */ | |
24 | public function add(string $name, string $type, string $duration, string $reason): stdClass|array|bool | |
25 | { | |
26 | $response = $this->connection->query('server_ban.add', [ | |
27 | 'name' => $name, | |
28 | 'type' => $type, | |
29 | 'reason' => $reason, | |
30 | 'duration_string' => $duration ?? '1d', | |
31 | ]); | |
32 | ||
33 | if (is_bool($response)) | |
34 | return false; | |
35 | ||
36 | if (property_exists($response, 'tkl')) | |
37 | return $response->tkl; | |
38 | return FALSE; | |
39 | } | |
40 | ||
41 | /** | |
42 | * Delete a ban. | |
43 | * | |
44 | * @param string $name | |
45 | * @return stdClass|array|bool | |
46 | */ | |
47 | public function delete(string $name, string $type): stdClass|array|bool | |
48 | { | |
49 | $response = $this->connection->query('server_ban.del', [ | |
50 | 'name' => $name, | |
51 | 'type' => $type, | |
52 | ]); | |
53 | ||
54 | if (is_bool($response)) | |
55 | return false; | |
56 | ||
57 | if (property_exists($response, 'tkl')) | |
58 | return $response->tkl; | |
59 | return FALSE; | |
60 | } | |
61 | ||
62 | /** | |
63 | * Return a list of all bans. | |
64 | * | |
65 | * @return stdClass|array|bool | |
66 | * @throws Exception | |
67 | */ | |
68 | public function getAll(): stdClass|array|bool | |
69 | { | |
70 | $response = $this->connection->query('server_ban.list'); | |
71 | ||
72 | if (!is_bool($response)) { | |
73 | return $response->list; | |
74 | } | |
75 | ||
76 | throw new Exception('Invalid JSON Response from UnrealIRCd RPC.'); | |
77 | } | |
78 | ||
79 | /** | |
80 | * Get a specific ban. | |
81 | * | |
82 | * @return stdClass|array|bool | |
83 | * @throws Exception | |
84 | */ | |
85 | public function get(string $name, string $type): stdClass|array|bool | |
86 | { | |
87 | $response = $this->connection->query('server_ban.get', [ | |
88 | 'name' => $name, | |
89 | 'type' => $type | |
90 | ]); | |
91 | ||
92 | if (!is_bool($response)) { | |
93 | return $response->tkl; | |
94 | } | |
95 | ||
96 | return false; // didn't exist | |
97 | } | |
98 | } |