1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- 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);
- NetMsgEvents.StartListening($"{server.eventStreamName}_PingSent", OnServerReceivedDataEvent);
- NetMsgEvents.StartListening($"{server.eventStreamName}_PongReceived", 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);
- NetMsgEvents.StopListening($"{server.eventStreamName}_PingSent", OnServerReceivedDataEvent);
- NetMsgEvents.StopListening($"{server.eventStreamName}_PongReceived", 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, "", "", "");
- }
- }
- }
|