Skip to content

Latest commit

 

History

History
132 lines (98 loc) · 3.28 KB

File metadata and controls

132 lines (98 loc) · 3.28 KB

Agent Constants

EasyLibrary Agent exposes official constants for standard strings used by the bridge. Use them instead of raw strings whenever a value is part of the public API.

Constants improve autocomplete, reduce typos and make plugin code easier to audit.

Constant classes

imperazim\agent\constant\AgentChannels
imperazim\agent\constant\AgentTargetTypes
imperazim\agent\constant\AgentRpcMethods
imperazim\agent\constant\AgentNetworkFlags
imperazim\agent\constant\AgentDeliveryStates
imperazim\agent\constant\AgentServerStates
imperazim\agent\constant\AgentComputeMethods
imperazim\agent\constant\AgentComputeStates

Channels

use imperazim\agent\constant\AgentChannels;

AgentChannels::NETWORK_BROADCAST;
AgentChannels::NETWORK_NOTICE;
AgentChannels::NETWORK_STAFF_ALERT;
AgentChannels::NETWORK_MAINTENANCE;
AgentChannels::NETWORK_TITLE;
AgentChannels::NETWORK_ACTIONBAR;
AgentChannels::NETWORK_COMMAND;
AgentChannels::AGENT_DIAGNOSTIC;
AgentChannels::AGENT_TEST;
AgentChannels::RPC_REQUEST;
AgentChannels::RPC_RESPONSE;

Custom plugin channels are still allowed for PubSub:

AgentPubSubAPI::toNetwork('myplugin.cache.invalidate', 'invalidate');

Use a namespace prefix owned by your plugin to avoid collisions.

Target types

use imperazim\agent\constant\AgentTargetTypes;

AgentTargetTypes::NETWORK;
AgentTargetTypes::SERVER;
AgentTargetTypes::GROUP;
AgentTargetTypes::TYPE;
AgentTargetTypes::TAG;
AgentTargetTypes::TARGET_KEY;

RPC methods

use imperazim\agent\constant\AgentRpcMethods;

AgentRpcMethods::SERVER_PING;
AgentRpcMethods::SERVER_STATUS;
AgentRpcMethods::SERVER_INFO;
AgentRpcMethods::SERVER_PLAYERS;
AgentRpcMethods::SERVER_PLAYERS_LIST;
AgentRpcMethods::SERVER_TPS;
AgentRpcMethods::SERVER_MEMORY;
AgentRpcMethods::SERVER_WORLDS;
AgentRpcMethods::SERVER_FLAGS;
AgentRpcMethods::SERVER_KV_GET;
AgentRpcMethods::RPC_METHODS;

RPC methods are allowlisted by config. Do not build method names dynamically unless your own service layer explicitly validates them.

Network flags

use imperazim\agent\constant\AgentNetworkFlags;

AgentNetworkFlags::MAINTENANCE;
AgentNetworkFlags::DOUBLE_XP;
AgentNetworkFlags::EVENT_ACTIVE;

Plugins may use custom flag names when they own the contract:

AgentFlagsAPI::set('lumen.double_drops', true, 3600, 'Weekend event');

For shared/common flags, prefer constants.

Compute methods

Compute methods are stricter than PubSub channels. Use constants from AgentComputeMethods and keep the Agent Go allowlist aligned.

use imperazim\agent\constant\AgentComputeMethods;

AgentComputeMethods::PING;
AgentComputeMethods::ECHO;
AgentComputeMethods::MATH_BASIC;
AgentComputeMethods::JSON_DIFF;
AgentComputeMethods::REGION_INTERSECTS;
AgentComputeMethods::LEADERBOARD_SORT;

Do not accept arbitrary user input as a compute method.

States

Use state constants when comparing delivery, server or compute state values.

use imperazim\agent\constant\AgentDeliveryStates;
use imperazim\agent\constant\AgentServerStates;
use imperazim\agent\constant\AgentComputeStates;

AgentDeliveryStates::COMPLETE;
AgentServerStates::ONLINE;
AgentComputeStates::FAILED;

Related docs