]> jfr.im git - irc/unrealircd/unrealircd-rpc-php.git/blame - README.md
Return from $rpc->eventloop() after 2 seconds instead of 10.
[irc/unrealircd/unrealircd-rpc-php.git] / README.md
CommitLineData
562c96c0
BM
1UnrealIRCd RPC
2==============
3
4This allows PHP scripts to control [UnrealIRCd](https://www.unrealircd.org/)
5via the [JSON-RPC interface](https://www.unrealircd.org/docs/JSON-RPC).
6
13d5df3b
BM
7This library is used by the
8[UnrealIRCd webpanel](https://github.com/unrealircd/unrealircd-webpanel/).
f228c2d5 9
66eda38d 10If you are interested in helping out or would like to discuss API
13d5df3b 11capabilities, join us at `#unreal-webpanel` at `irc.unrealircd.org`
66eda38d
BM
12(IRC with TLS on port 6697).
13
562c96c0
BM
14Installation
15------------
16```bash
27d8a778 17composer require unrealircd/unrealircd-rpc:dev-main
562c96c0
BM
18```
19
66eda38d
BM
20UnrealIRCd setup
21-----------------
13d5df3b
BM
22UnrealIRCd 6.0.6 or later is needed and you need to enable
23[JSON-RPC](https://www.unrealircd.org/docs/JSON-RPC) in it.
f228c2d5 24After doing that, be sure to rehash the IRCd.
66eda38d 25
562c96c0
BM
26Usage
27-----
e3d9bcad 28For this example, create a file like `src/rpctest.php` with:
562c96c0
BM
29```php
30<?php
31 require dirname(__DIR__) . '/vendor/autoload.php';
32
66eda38d 33 use UnrealIRCd\Connection;
562c96c0 34
66eda38d 35 $api_login = 'api:apiPASSWORD'; // same as in the rpc-user block in UnrealIRCd
562c96c0 36
c2f6f705 37 $rpc = new UnrealIRCd\Connection("wss://127.0.0.1:8600/",
562c96c0
BM
38 $api_login,
39 Array("tls_verify"=>FALSE));
40
66eda38d 41 $bans = $rpc->serverban()->getAll();
93f8a3ee 42 foreach ($bans as $ban)
66eda38d
BM
43 echo "There's a $ban->type on $ban->name\n";
44
45 $users = $rpc->user()->getAll();
93f8a3ee 46 foreach ($users as $user)
66eda38d
BM
47 echo "User $user->name\n";
48
49 $channels = $rpc->channel()->getAll();
93f8a3ee 50 foreach ($channels as $channel)
66eda38d 51 echo "Channel $channel->name ($channel->num_users user[s])\n";
562c96c0 52```
1ba139aa 53Then, run it on the command line with `php src/rpctest.php`
e3d9bcad 54
66eda38d
BM
55If the example does not work, then make sure you have configured your
56UnrealIRCd correctly, with the same API username and password you use
1ba139aa 57here, with an allowed IP, and changing the `wss://127.0.0.1:8600/` too
66eda38d 58if needed.