12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using KairoEngine.Core;
- using KairoEngine.Multiplayer;
- namespace KairoEngine.Multiplayer
- {
- public class ServerActivityMessages : MonoBehaviour
- {
- public ServerBehaviour server;
- public string activityMessageName = "server";
- private void Awake()
- {
- if(server == null) Debug.LogError("Missing ServerBehaviour script in ServerActivityMessages", this.gameObject);
- }
- private void Start()
- {
- if(server == null) return;
- GenericEvents.StartListening($"{server.eventStreamName}_PortError", OnServerEvent);
- GenericEvents.StartListening($"{server.eventStreamName}_Listening", OnServerEvent);
- GenericEvents.StartListening($"{server.eventStreamName}_Stopped", OnServerEvent);
- GenericEvents.StartListening($"{server.eventStreamName}_ClientConnected", OnServerClientConnectedEvent);
- GenericEvents.StartListening($"{server.eventStreamName}_ClientDisconnected", OnServerEvent);
- NetMsgEvents.StartListening($"{server.eventStreamName}_InvalidOpCode", OnServerReceivedDataEvent);
- NetMsgEvents.StartListening($"{server.eventStreamName}_SendingDisconnectMessageToClient", OnServerReceivedDataEvent);
- NetMsgEvents.StartListening($"{server.eventStreamName}_ClientDisconnect", OnServerReceivedDataEvent);
- NetMsgEvents.StartListening($"{server.eventStreamName}_HandshakeReceived", OnServerReceivedDataEvent);
- NetMsgEvents.StartListening($"{server.eventStreamName}_AcceptingHandshake", OnServerReceivedDataEvent);
- }
- private void OnDestroy()
- {
- if(server == null) return;
- GenericEvents.StopListening($"{server.eventStreamName}_PortError", OnServerEvent);
- GenericEvents.StopListening($"{server.eventStreamName}_Listening", OnServerEvent);
- GenericEvents.StopListening($"{server.eventStreamName}_Stopped", OnServerEvent);
- GenericEvents.StopListening($"{server.eventStreamName}_ClientConnected", OnServerClientConnectedEvent);
- GenericEvents.StopListening($"{server.eventStreamName}_ClientDisconnected", OnServerEvent);
- NetMsgEvents.StopListening($"{server.eventStreamName}_InvalidOpCode", OnServerReceivedDataEvent);
- NetMsgEvents.StopListening($"{server.eventStreamName}_SendingDisconnectMessageToClient", OnServerReceivedDataEvent);
- NetMsgEvents.StopListening($"{server.eventStreamName}_ClientDisconnect", OnServerReceivedDataEvent);
- NetMsgEvents.StopListening($"{server.eventStreamName}_HandshakeReceived", OnServerReceivedDataEvent);
- NetMsgEvents.StopListening($"{server.eventStreamName}_AcceptingHandshake", OnServerReceivedDataEvent);
- }
- public void OnServerEvent(string text)
- {
- ActivityMessageEvents.Send(text, "", server.eventStreamName, activityMessageName, null, 0f, true, false, null, "", "", "");
- }
- public void OnServerReceivedDataEvent(string text, int clientId, uint code, NetMsg netMsg)
- {
- ActivityMessageEvents.Send(text, "", server.eventStreamName, activityMessageName, null, 0f, true, false, null, "", "", "");
- }
- public void OnServerClientConnectedEvent(string text, int connectionId)
- {
- ActivityMessageEvents.Send(text, "", server.eventStreamName, activityMessageName, null, 0f, true, false, null, "", "", "");
- }
- }
- }
|