123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using KairoEngine.Core;
- namespace KairoEngine.Multiplayer
- {
- public class ClientActivityMessages : MonoBehaviour
- {
- public ClientBehaviour client;
- public string activityMessageName = "client";
- private void Awake()
- {
- if(client == null) Debug.LogError("Missing ClientBehaviour script in ClientActivityMessages", this.gameObject);
- }
- private void Start()
- {
- if(client == null) return;
- GenericEvents.StartListening($"{client.eventStreamName}_Connecting", OnClientEvent);
- GenericEvents.StartListening($"{client.eventStreamName}_Connected", OnClientEvent);
- GenericEvents.StartListening($"{client.eventStreamName}_Disconected", OnClientEvent);
- GenericEvents.StartListening($"{client.eventStreamName}_ServerDisconnected", OnClientEvent);
- GenericEvents.StartListening($"{client.eventStreamName}_ErrorConnecting", OnClientEvent);
- NetMsgEvents.StartListening($"{client.eventStreamName}_InvalidOpCode", OnClientReceivedDataEvent);
- NetMsgEvents.StartListening($"{client.eventStreamName}_SendingDisconnectMessageToServer", OnClientReceivedDataEvent);
- NetMsgEvents.StartListening($"{client.eventStreamName}_ServerDisconnect", OnClientReceivedDataEvent);
- NetMsgEvents.StartListening($"{client.eventStreamName}_SendingHandshake", OnClientReceivedDataEvent);
- NetMsgEvents.StartListening($"{client.eventStreamName}_HandshakeAccepted", OnClientReceivedDataEvent);
- NetMsgEvents.StartListening($"{client.eventStreamName}_PeerConnected", OnClientReceivedDataEvent);
- NetMsgEvents.StartListening($"{client.eventStreamName}_PeerDisconnected", OnClientReceivedDataEvent);
- NetMsgEvents.StartListening($"{client.eventStreamName}_PingReceived", OnClientReceivedDataEvent);
- NetMsgEvents.StartListening($"{client.eventStreamName}_PongSent", OnClientReceivedDataEvent);
- }
- private void OnDestroy()
- {
- if(client == null) return;
- GenericEvents.StopListening($"{client.eventStreamName}_Connecting", OnClientEvent);
- GenericEvents.StopListening($"{client.eventStreamName}_Connected", OnClientEvent);
- GenericEvents.StopListening($"{client.eventStreamName}_Disconected", OnClientEvent);
- GenericEvents.StopListening($"{client.eventStreamName}_ServerDisconnected", OnClientEvent);
- GenericEvents.StopListening($"{client.eventStreamName}_ErrorConnecting", OnClientEvent);
- NetMsgEvents.StopListening($"{client.eventStreamName}_InvalidOpCode", OnClientReceivedDataEvent);
- NetMsgEvents.StopListening($"{client.eventStreamName}_SendingDisconnectMessageToServer", OnClientReceivedDataEvent);
- NetMsgEvents.StopListening($"{client.eventStreamName}_ServerDisconnect", OnClientReceivedDataEvent);
- NetMsgEvents.StopListening($"{client.eventStreamName}_SendingHandshake", OnClientReceivedDataEvent);
- NetMsgEvents.StopListening($"{client.eventStreamName}_HandshakeAccepted", OnClientReceivedDataEvent);
- NetMsgEvents.StopListening($"{client.eventStreamName}_PingReceived", OnClientReceivedDataEvent);
- NetMsgEvents.StopListening($"{client.eventStreamName}_PongSent", OnClientReceivedDataEvent);
- }
- public void OnClientEvent(string text)
- {
- ActivityMessageEvents.Send(text, "", client.eventStreamName, activityMessageName, null, 0f, true, false, null, "", "", "");
- }
- public void OnClientReceivedDataEvent(string text, int clientId, uint code, NetMsg netMsg)
- {
- ActivityMessageEvents.Send(text, "", client.eventStreamName, activityMessageName, null, 0f, true, false, null, "", "", "");
- }
- }
- }
|