-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAgentRpcExample.php
More file actions
37 lines (29 loc) · 1.03 KB
/
Copy pathAgentRpcExample.php
File metadata and controls
37 lines (29 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
declare(strict_types=1);
namespace imperazim\easylibrary\examples\agent;
use imperazim\agent\api\AgentRpcAPI;
use imperazim\agent\api\AgentRuntimeAPI;
use imperazim\agent\constant\AgentRpcMethods;
use imperazim\agent\event\AgentRpcResponseReceivedEvent;
use pocketmine\event\Listener;
final class AgentRpcExample implements Listener{
public function requestServerStatus(string $serverId) : int{
if(!AgentRuntimeAPI::isAvailable()){
return 0;
}
$response = AgentRpcAPI::toServer($serverId, AgentRpcMethods::SERVER_STATUS, [], 10);
return (int) ($response['request_id'] ?? 0);
}
public function onRpcResponse(AgentRpcResponseReceivedEvent $event) : void{
if($event->getMethod() !== AgentRpcMethods::SERVER_STATUS){
return;
}
if(!$event->isOk()){
$error = $event->getError();
// Store/report the failed response.
return;
}
$result = $event->getResult();
// Use server status result.
}
}