Bram Matthys [Mon, 8 May 2023 06:27:26 +0000 (08:27 +0200)]
Return from $rpc->eventloop() after 2 seconds instead of 10.
This so keepalive-like packets can be sent to the browser by the webpanel
every 2 seconds instead of 10 seconds (for better explanation see webpanel)
This fix-for-endless-exception used <1ms while it should use <1s.
Also, I wonder if the fix is still needed as i (accidentally)
updated the websocket library today.
query(): handle replies for different id, for errors too. Fixes 6.0.7 issue
due to recent change with set_issuer (as this method did not exist in
UnrealIRCd version 6.0.7 it would cause an error later on).
Update composer dependencies. End users need to run 'composer install'.
This so 02da13a9d49686e9a6c6254c7318e3e145debbf3 actually works
(set "issuer" in UnrealIRCd\Connection options to save 1 round trip).
Note: if end-user forgets to call 'composer install' then this means
set by is not logged now.
On new connection, call rpc.set_issuer but don't wait for the reply.
This to speed up connection time a bit.
Related changes:
* query() now has an extra argument $no_wait which defaults to false
(and is set to true for rpc.set_issuer call if $options["issuer"]
is set in new UnrealIRCd\Connection.
* query() now waits for the reply for the correct id.
Allow setting "issuer" in UnrealIRCd\Connection options to save 1 round trip.
Without it, we will still do a ping-pong to force the connection.
With issuer, we don't need that ping-pong.
Add a timer. Requires UnrealIRCd 6.1.0+
@param timer_id Name of the timer (so you can .del_timer later)
@param every_msec Every -this- milliseconds the command must be executed
@param method The JSON-RPC method to execute (lowlevel name, eg "stats.get")
@param params Parameters to the JSON-RPC call that will be executed, can be NULL
@param id Set JSON-RPC id to be used in the timer, leave NULL for auto id.
@return stdClass|array|bool
Example usage would be:
$rpc->rpc()->add_timer("timer", 1000, "stats.get");
Workaround library bug in eventloop(). Apparently if there is little
activity and we catch the timeout once and we continue, then if there
is some other error like server killed or otherwise connection lost
then it will refire as a timeout, and this happens endlessly, so
resulting in 100% CPU loop.
We now detect it by (far) too little execution time, ah well, it is
a workaround that works :D.
So this should be safe now (was introduced a previous commit,
still the same code):
$rpc->eventloop() will return NULL if there is no activity
for 10 seconds, so it is not entirely blocking. You can safely
re-run $rpc->eventloop(); if return value === NULL.
Bram Matthys [Mon, 27 Mar 2023 11:31:11 +0000 (13:31 +0200)]
User: add optional $object_detail_level argument to getAll() and get().
Similar to Channel getAll() and get() this specifies the amount of
detail that a server will return, see "Structure of a client object"
at https://www.unrealircd.org/docs/JSON-RPC:User
Only works in UnrealIRCd 6.0.8 or later, simply ignored in earlier versions.
If you only need a minimal amount of information, consider using a
lower object_detail_level. It saves both CPU and bandwidth.
In UnrealIRCd 6.0.8+ the user.get call returns the same information with
the default object_detail_level as in 6.0.7.
For the user.list call, UnrealIRCd 6.0.8 has a "breaking change":
the "channels" of the user are no longer returned with the default
object_detail_level value of 2. If you require that information, then
set object_detail_level to 4, like: $rpc->user()->getAll(4);
Bram Matthys [Mon, 27 Mar 2023 08:31:04 +0000 (10:31 +0200)]
Channel: add optional $object_detail_level argument to getAll() and get().
This decides the amount of detail that is returned, see under
"Structure of a channel" at https://www.unrealircd.org/docs/JSON-RPC:Channel
Only works in UnrealIRCd 6.0.8 or later, simply ignored in earlier versions.
Valerie Pond [Tue, 10 Jan 2023 05:08:49 +0000 (05:08 +0000)]
Add nameban to Connection.php and various bugfixes
In many cases on a failed lookup such as if a nick didn't exist, this threw an exception which halted things. Also in some cases there weren't bool checks when there needed to be for such catches
Bram Matthys [Mon, 9 Jan 2023 12:02:15 +0000 (13:02 +0100)]
Make the *.get/*.add/*.delete calls return the channel/user/.. directly.
So:
$user = $rpc->user()->get("Syzop");
if ($user->client->name == "Syzop")
..
Becomes:
$user = $rpc->user()->get("Syzop");
if ($user->name == "Syzop")
..
And:
$spamfilter = $rpc->spamfilter()->add(...etc...)
Then not dump $spamfilter->tkl but simply $spamfilter.
Bram Matthys [Sat, 7 Jan 2023 18:42:05 +0000 (19:42 +0100)]
Add all the new RPC calls in 6.0.6-git at the moment:
== channel ==
public function set_mode(string $channel, string $modes, string $parameters): stdClass|array|bool
public function set_topic(string $channel, string $topic,
string $set_by=null, string $set_at=null): stdClass|array|bool
public function kick(string $channel, string $nick, string $reason): stdClass|array|bool
See also https://www.unrealircd.org/docs/JSON-RPC:Channel
== user ==
public function set_nick(string $nick, string $newnick): stdClass|array|bool
public function set_username(string $nick, string $username): stdClass|array|bool
public function set_realname(string $nick, string $realname): stdClass|array|bool
public function set_vhost(string $nick, string $vhost): stdClass|array|bool
public function set_mode(string $nick, string $mode, bool $hidden = false): stdClass|array|bool
public function set_snomask(string $nick, string $snomask, bool $hidden = false): stdClass|array|bool
public function set_oper(string $nick, string $oper_account, string $oper_class,
string $class = null, string $modes = null,
string $snomask = null, string $vhost = null): stdClass|array|bool
public function join(string $nick, string $channel,
string $key = null, bool $force = false): stdClass|array|bool
public function part(string $nick, string $channel, bool $force = false): stdClass|array|bool
public function quit(string $nick, string $reason): stdClass|array|bool
public function kill(string $nick, string $reason): stdClass|array|bool
See also https://www.unrealircd.org/docs/JSON-RPC:User
Bram Matthys [Fri, 6 Jan 2023 14:24:17 +0000 (15:24 +0100)]
Don't use arrays in parameters but use explicit options everwhere.
For example in ServerBan, from:
public function add(string $user, array $params): stdClass;
To:
public function add(string $name, string $type, string $duration, string $reason): stdClass;
As the whole point of having these PHP functions is that it is immediately
transparent which things you need to pass.
Bram Matthys [Fri, 6 Jan 2023 14:06:13 +0000 (15:06 +0100)]
Major API break:
* Change all the ->get() to ->getAll()
and all the ->show() to ->get()
.. eg for User, Channel, etc.
* You now only create an API connection once, as it was always
intended:
$rpc = new UnrealIRCd\Connection(..)
* You can then either use the non-connection classes like this:
$user = new User($rpc);
$result = $user->getAll();
Or simply use this style:
$result = $rpc->user()->getAll();
* More breakage to come