]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace UnrealIRCd; | |
4 | ||
5 | use Exception; | |
6 | use stdClass; | |
7 | ||
8 | class Rpc | |
9 | { | |
10 | ||
11 | public Connection $connection; | |
12 | ||
13 | public function __construct(Connection $conn) | |
14 | { | |
15 | $this->connection = $conn; | |
16 | } | |
17 | ||
18 | /** | |
19 | * Get information on all RPC modules loaded. | |
20 | * | |
21 | * @return stdClass|array|bool | |
22 | */ | |
23 | public function info(string $nick, string $reason): stdClass|array|bool | |
24 | { | |
25 | return $this->connection->query('rpc.info'); | |
26 | } | |
27 | ||
28 | /** | |
29 | * Set the name of the issuer that will make all the following RPC request | |
30 | * (eg. name of logged in user on a webpanel). Requires UnreaIRCd 6.0.8+. | |
31 | * @return stdClass|array|bool | |
32 | */ | |
33 | public function set_issuer(string $name): stdClass|array|bool | |
34 | { | |
35 | return $this->connection->query('rpc.set_issuer', [ | |
36 | 'name' => $name, | |
37 | ]); | |
38 | } | |
39 | ||
40 | /** | |
41 | * Add a timer. Requires UnrealIRCd 6.1.0+ | |
42 | * @param timer_id Name of the timer (so you can .del_timer later) | |
43 | * @param every_msec Every -this- milliseconds the command must be executed | |
44 | * @param method The JSON-RPC method to execute (lowlevel name, eg "stats.get") | |
45 | * @param params Parameters to the JSON-RPC call that will be executed, can be NULL | |
46 | * @param id Set JSON-RPC id to be used in the timer, leave NULL for auto id. | |
47 | * @return stdClass|array|bool | |
48 | */ | |
49 | public function add_timer(string $timer_id, int $every_msec, string $method, array|null $params = null, $id = null): stdClass|array|bool | |
50 | { | |
51 | if ($id === null) | |
52 | $id = random_int(100000, 999999); /* above the regular query() ids */ | |
53 | ||
54 | $request = [ | |
55 | "jsonrpc" => "2.0", | |
56 | "method" => $method, | |
57 | "params" => $params, | |
58 | "id" => $id | |
59 | ]; | |
60 | ||
61 | return $this->connection->query('rpc.add_timer', [ | |
62 | 'timer_id' => $timer_id, | |
63 | 'every_msec' => $every_msec, | |
64 | 'request' => $request, | |
65 | ]); | |
66 | } | |
67 | ||
68 | /** | |
69 | * Delete a timer. Requires UnrealIRCd 6.1.0+ | |
70 | * @param timer_id Name of the timer that was added through del_timer earlier. | |
71 | * @return stdClass|array|bool | |
72 | */ | |
73 | public function del_timer(string $timer_id) | |
74 | { | |
75 | return $this->connection->query('rpc.del_timer', [ | |
76 | 'timer_id' => $timer_id, | |
77 | ]); | |
78 | } | |
79 | } |