Example #1
0
        protected override void OnReceiveInternalData(InternalMessages type, ProductUserId clientUserId) {
            switch (type) {
                case InternalMessages.CONNECT:
                    if (epicToMirrorIds.Count >= maxConnections) {
                        SendInternal(clientUserId, InternalMessages.DISCONNECT);
                        return;
                    }

                    SendInternal(clientUserId, InternalMessages.ACCEPT_CONNECT);

                    int connectionId = nextConnectionID++;
                    epicToMirrorIds.Add(clientUserId, connectionId);
                    OnConnected.Invoke(connectionId);
                    Debug.Log($"Client with Product User ID {clientUserId} connected. Assigning connection id {connectionId}");
                    break;
                case InternalMessages.DISCONNECT:
                    if (epicToMirrorIds.TryGetValue(clientUserId, out int connId)) {
                        OnDisconnected.Invoke(connId);
                        CloseP2PSessionWithUser(clientUserId);
                        epicToMirrorIds.Remove(clientUserId);
                        Debug.Log($"Client with Product User ID {clientUserId} disconnected.");
                    } else {
                        OnReceivedError.Invoke(-1, new Exception("ERROR Unknown Product User ID"));
                    }

                    break;
                default:
                    Debug.Log("Received unknown message type");
                    break;
            }
        }
Example #2
0
        protected override void OnReceiveInternalData(InternalMessages type, ProductUserId clientUserId, SocketId socketId)
        {
            if (ignoreAllMessages)
            {
                return;
            }

            switch (type)
            {
            case InternalMessages.CONNECT:
                if (epicToMirrorIds.Count >= maxConnections)
                {
                    Debug.LogError("Reached max connections");
                    //CloseP2PSessionWithUser(clientUserId, socketId);
                    SendInternal(clientUserId, socketId, InternalMessages.DISCONNECT);
                    return;
                }

                SendInternal(clientUserId, socketId, InternalMessages.ACCEPT_CONNECT);

                int connectionId = nextConnectionID++;
                epicToMirrorIds.Add(clientUserId, connectionId);
                epicToSocketIds.Add(clientUserId, socketId);
                Debug.LogError("Adding new connection with ID: " + connectionId);
                OnConnected.Invoke(connectionId);

                string clientUserIdString;
                clientUserId.ToString(out clientUserIdString);
                Debug.Log($"Client with Product User ID {clientUserIdString} connected. Assigning connection id {connectionId}");
                break;

            case InternalMessages.DISCONNECT:
                if (epicToMirrorIds.TryGetValue(clientUserId, out int connId))
                {
                    OnDisconnected.Invoke(connId);
                    //CloseP2PSessionWithUser(clientUserId, socketId);
                    epicToMirrorIds.Remove(clientUserId);
                    epicToSocketIds.Remove(clientUserId);
                    Debug.LogError($"Client with Product User ID {clientUserId} disconnected.");
                }
                else
                {
                    OnReceivedError.Invoke(-1, new Exception("ERROR Unknown Product User ID"));
                }

                break;

            default:
                Debug.Log("Received unknown message type");
                break;
            }
        }
Example #3
0
        protected override void OnReceiveInternalData(InternalMessages type, ProductUserId clientUserId, SocketId socketId, byte[] payload = null)
        {
            if (ignoreAllMessages)
            {
                return;
            }

            switch (type)
            {
            case InternalMessages.CONNECT:
                if (epicToMirrorIds.Count >= maxConnections)
                {
                    Debug.LogError("Reached max connections");
                    //CloseP2PSessionWithUser(clientUserId, socketId);
                    SendInternal(clientUserId, socketId, InternalMessages.DISCONNECT);
                    return;
                }

                SendInternal(clientUserId, socketId, InternalMessages.ACCEPT_CONNECT);

                ulong connectionId = nextConnectionID++;
                epicToMirrorIds.Add(clientUserId, connectionId);
                epicToSocketIds.Add(clientUserId, socketId);
                transport.OnCommonConnected.Invoke(connectionId);
                //OnConnected.Invoke(connectionId);

                string clientUserIdString;
                clientUserId.ToString(out clientUserIdString);
                Debug.Log($"Client with Product User ID {clientUserIdString} connected. Assigning connection id {connectionId}");
                break;

            case InternalMessages.DISCONNECT:
                if (epicToMirrorIds.TryGetValue(clientUserId, out ulong connId))
                {
                    transport.OnCommonDisconnected.Invoke(connId);
                    //OnDisconnected.Invoke(connId);
                    //CloseP2PSessionWithUser(clientUserId, socketId);
                    epicToMirrorIds.Remove(clientUserId);
                    epicToSocketIds.Remove(clientUserId);
                    clientUserId.ToString(out string clientUserIdstr);
                    Debug.Log($"Client with Product User ID {clientUserIdstr} disconnected.");
                }
                else
                {
                    transport.OnCommonErrored.Invoke(0, new Exception("ERROR Unknown Product User ID"));
                }

                break;

            case InternalMessages.PING:
                if (payload[1] == 0)
                {
                    payload[1] = 0xff;
                    SendInternal(clientUserId, socketId, payload);
                }
                else
                {
                    float sendTime = BitConverter.ToSingle(payload, 2);
                    pings[epicToMirrorIds[clientUserId]] = (ulong)((Time.realtimeSinceStartup - sendTime) / 1000.0f);
                }
                break;

            default:
                Debug.Log("Received unknown message type");
                break;
            }
        }