diff --git a/src/Socialbox/Classes/StandardMethods/Core/GetSelf.php b/src/Socialbox/Classes/StandardMethods/Core/GetSelf.php index d5c4a0b..bd2ec5b 100644 --- a/src/Socialbox/Classes/StandardMethods/Core/GetSelf.php +++ b/src/Socialbox/Classes/StandardMethods/Core/GetSelf.php @@ -2,18 +2,14 @@ namespace Socialbox\Classes\StandardMethods\Core; - use InvalidArgumentException; use Socialbox\Abstracts\Method; - use Socialbox\Enums\ReservedUsernames; use Socialbox\Enums\StandardError; use Socialbox\Exceptions\DatabaseOperationException; - use Socialbox\Exceptions\Standard\MissingRpcArgumentException; use Socialbox\Exceptions\Standard\StandardRpcException; use Socialbox\Interfaces\SerializableInterface; + use Socialbox\Managers\PeerInformationManager; use Socialbox\Objects\ClientRequest; - use Socialbox\Objects\PeerAddress; use Socialbox\Objects\RpcRequest; - use Socialbox\Socialbox; class GetSelf extends Method { @@ -23,6 +19,14 @@ */ public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface { - + try + { + $selfPeer = $request->getPeer(); + return $rpcRequest->produceResponse($selfPeer->toStandardPeer(PeerInformationManager::getFields($selfPeer))); + } + catch (DatabaseOperationException $e) + { + throw new StandardRpcException('Unable to resolve self peer', StandardError::INTERNAL_SERVER_ERROR, $e); + } } } \ No newline at end of file diff --git a/src/Socialbox/Objects/RpcRequest.php b/src/Socialbox/Objects/RpcRequest.php index a5a6013..a785d83 100644 --- a/src/Socialbox/Objects/RpcRequest.php +++ b/src/Socialbox/Objects/RpcRequest.php @@ -4,6 +4,7 @@ use InvalidArgumentException; use Socialbox\Classes\Logger; + use Socialbox\Classes\Utilities; use Socialbox\Enums\StandardError; use Socialbox\Enums\StandardMethods; use Socialbox\Exceptions\Standard\StandardRpcException; @@ -19,16 +20,21 @@ * Constructs the object from an array of data. * * @param string|StandardMethods $method The method of the request. - * @param string|null $id The ID of the request. + * @param string|null $id The ID of the request. If 'RANDOM' a random crc32 hash will be used. * @param array|null $parameters The parameters of the request. */ - public function __construct(string|StandardMethods $method, ?string $id, ?array $parameters=null) + public function __construct(string|StandardMethods $method, ?string $id='RANDOM', ?array $parameters=null) { if($method instanceof StandardMethods) { $method = $method->value; } + if($id === 'RANDOM') + { + $id = Utilities::randomCrc32();; + } + $this->method = $method; $this->parameters = $parameters; $this->id = $id;