EntityMessageHandler
A class in Root.Township, Alta.Networking.
Routes an entity's network messages: sends them to the players the entity is spawned for, and calls the registered handler for each incoming EntityMessageType. Get it from NetworkEntity.MessageHandler; MethodSync uses it underneath.
- Listed in Networking and servers
- Documented in Entity sync
Constructors
| Member | What it is |
|---|---|
EntityMessageHandler(INetworkEntity networkEntity) | Creates an EntityMessageHandler from networkEntity. |
Fields
3 private and internal fields
| Member | What it is |
|---|---|
private INetworkEntity entity | Private: the entity these messages belong to. |
private static Logger logger | Private: logger for send and handle failures. |
private Dictionary<EntityMessageType, SerializeMethod> messageHandlers | Private: handler per message type. |
Methods
| Member | What it is |
|---|---|
SerializeMethod ClearHandler(EntityMessageType message) | Removes the handler for a message type and returns it, or null if there was none. |
void HandleMessage(EntityMessageType type, IPlayer player, Stream stream) | Calls the handler for an incoming message. Unknown types and exceptions are logged, not thrown. |
void HandlersGUI() | Empty in this build. |
void SendToChunks(EntityMessageType messageType, SerializeMethod handler, ConnectionChannel channel = null, params IPlayer[] except) | Sends a message to every player the entity is spawned for, minus except. On a client it also sends it to the server. |
void SendToPlayer(IPlayer player, EntityMessageType messageType, SerializeMethod handler, ConnectionChannel channel = null) | Sends a message to one player. Does nothing (with a warning) if the entity is not sending messages. |
void SetHandler(EntityMessageType messageType, SerializeMethod handler) | Sets the handler for a message type, replacing any other. A null handler is refused with an error. |
1 private and internal method
| Member | What it is |
|---|---|
private bool HasHandler(EntityMessageType message) | Private: whether a handler is set for a message type. |
Used in
Members of other types that take, return or hold a EntityMessageHandler: