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