Client
Client
Base server-side client connection abstraction.
class Client extends \Hazaar\Warlock\Protocol\WebSockets implements \Hazaar\Warlock\Interface\ClientExtends: Hazaar\Warlock\Protocol\WebSockets
Implements: Hazaar\Warlock\Interface\Client
Properties
address
public string $addressType: string
port
public int $portType: int
id
Unique client ID assigned by the server.
public string $idType: string
options
Any options passed to the client on creation.
public array $options = array (
'auth' => true,
'authMethod' => 'basic',
'authDb' => NULL,
'authScript' => NULL,
)Type: array
type
Current logical client type.
public ClientType $type = 'ClientType'Type: Hazaar\Warlock\Enum\ClientType
status
The current status of the client.
public ClientStatus $status = 'ClientStatus'Type: Hazaar\Warlock\Enum\ClientStatus
stream
public mixed $streamType: mixed
closing
Indicates websocket close handshake state.
public bool $closingType: bool
frameBuffer
public string $frameBufferType: string
payloadBuffer
public string $payloadBufferType: string
name
Human-readable client name label.
public string $nameType: string
username
public string $usernameType: string
role
What this client may do once authenticated.
public ClientRole $role = 'ClientRole'Type: Hazaar\Warlock\Server\Enum\ClientRole
The none, list and basic auth methods give an authenticated client ADMIN. The script method gives it USER unless the script returns 'admin' or sets this to ClientRole::ADMIN.
allowSubscribe
public array $allowSubscribeType: array
allowTrigger
public array $allowTriggerType: array
since
Connection establishment timestamp.
public int $sinceType: int
lastContact
Last contact timestamp from client traffic.
public int $lastContactType: int
ping
public array $ping = array (
'attempts' => 0,
'last' => 0,
'retry' => 5,
'retries' => 3,
)Type: array
offset
Any detected time offset. This doesn't need to be exact so we don't bother worrying about latency.
public int $offsetType: int
subscriptions
This is an array of eventID and stream pairs.
public array $subscriptionsType: array
start
Process start timestamp inherited from server runtime.
protected int $startType: int
main
Owning server instance.
protected Main $mainType: Hazaar\Warlock\Server\Main
headers
Any headers sent by the client during handshake will be stored here.
private array $headersType: array
Methods
__construct
public __construct(Main $main, mixed $stream, ?array $options): voidParameters
| Parameter | Type | Description |
|---|---|---|
$main | Hazaar\Warlock\Server\Main | |
$stream | mixed | |
$options | array |
__destruct
public __destruct(): voidgetTypeFromHandshake
public getTypeFromHandshake(string $request): ClientTypeReturns: Hazaar\Warlock\Enum\ClientType
Parameters
| Parameter | Type | Description |
|---|---|---|
$request | string |
initiateHandshake
Initiates the handshake for an agent client.
public initiateHandshake(string $request, array $headers): voidParameters
| Parameter | Type | Description |
|---|---|---|
$request | string | the request string from the client |
$headers | array | reference to an array where headers will be stored |
recv
public recv(string $buf): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$buf | string |
send
public send(PacketType $command, mixed $payload): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$command | Hazaar\Warlock\Enum\PacketType | |
$payload | mixed |
disconnect
Process a stream client disconnect.
public disconnect(): boolReturns: bool
authorised
public authorised(): boolReturns: bool
commandUnsubscribe
public commandUnsubscribe(string $eventID): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$eventID | string |
commandTrigger
public commandTrigger(string $eventID, mixed $data, bool $echoClient = true): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$eventID | string | |
$data | mixed | |
$echoClient | bool |
sendEvent
public sendEvent(string $eventID, string $triggerID, mixed $data): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$eventID | string | |
$triggerID | string | |
$data | mixed |
ping
public ping(): boolReturns: bool
pong
public pong(): voidReturns: void
getHeader
public getHeader(string $name): ?stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string |
parseBasicAuth
Extracts the credentials from an Authorization: Basic header value.
public parseBasicAuth(?string $authorization): ?arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$authorization | string |
authenticate
Authenticates the client with the configured client auth method and updates its status.
public authenticate(string $username, string $password): boolReturns: bool
The authenticated username is the one supplied, unless it was empty and the auth script set $client->username itself (e.g. from a session cookie). An exception from the auth backend counts as a failure so a broken auth script can't take down the server.
Parameters
| Parameter | Type | Description |
|---|---|---|
$username | string | |
$password | string |
checkRequestURL
Overridden method from WebSocket class to check the requested WebSocket URL is valid.
protected checkRequestURL(string $url): array|boolReturns: array|bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$url | string |
httpResponse
Generate an HTTP response message.
protected httpResponse(int $code, ?string $body, array $headers): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$code | int | HTTP response code |
$body | string | The response body |
$headers | array | Additional headers |
write
protected write(string $frame): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$frame | string |
processFrame
Processes a client data frame.
protected processFrame(string $frameBuffer): mixedReturns: mixed
Parameters
| Parameter | Type | Description |
|---|---|---|
$frameBuffer | string |
processCommand
protected processCommand(PacketType $command, mixed $payload): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$command | Hazaar\Warlock\Enum\PacketType | |
$payload | mixed |
requireAuthorised
Refuses a command from a client that has not authenticated.
protected requireAuthorised(PacketType $command): voidReturns: void
With the none auth method every client is authorised on connect, so this only bites when client auth is enabled. The exception is turned into an ERROR packet by recv() so the client knows to AUTH first.
Parameters
| Parameter | Type | Description |
|---|---|---|
$command | Hazaar\Warlock\Enum\PacketType |
requireEventAllowed
Refuses an event ID that isn't in a client's allow-list.
protected requireEventAllowed(?array $allowed, string $eventID, string $action): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$allowed | array | the allow-list, or null to allow any event ID |
$eventID | string | |
$action | string |
commandAuthenticate
protected commandAuthenticate(\stdClass $payload): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$payload | stdClass |
commandStatus
protected commandStatus(?\stdClass $payload): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$payload | stdClass |
commandSubscribe
protected commandSubscribe(string $eventID, ?array $filter): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$eventID | string | |
$filter | array |
commandLog
protected commandLog(\stdClass $payload): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$payload | stdClass |
initiateWebSocketsHandshake
Initiates a WebSocket client handshake.
private initiateWebSocketsHandshake(array $headers): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$headers | array |
initiateRESTHandshake
Initiates a REST client handshake.
private initiateRESTHandshake(array $headers, string $body): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$headers | array | |
$body | string |
Generated by Hazaar API Doc Generator on Thu, 22 Oct 2026 05:05:31 +0000