protected override void OnReceiveData(byte[] data, ProductUserId clientUserId, int channel) { if (ignoreAllMessages) { return; } if (epicToMirrorIds.TryGetValue(clientUserId, out ulong connectionId)) { transport.OnCommonDataReceived.Invoke(connectionId, data, channel); //OnReceivedData.Invoke(connectionId, data, channel); } else { SocketId socketId; epicToSocketIds.TryGetValue(clientUserId, out socketId); CloseP2PSessionWithUser(clientUserId, socketId); string productId; clientUserId.ToString(out productId); Debug.LogError("Data received from epic client thats not known " + productId); transport.OnCommonErrored.Invoke(0, new Exception("ERROR Unknown product ID")); } }
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; } }
protected override void OnReceiveData(byte[] data, ProductUserId clientUserId, int channel) { if (epicToMirrorIds.TryGetValue(clientUserId, out int connectionId)) { OnReceivedData.Invoke(connectionId, data, channel); } else { CloseP2PSessionWithUser(clientUserId); string productId; clientUserId.ToString(out productId); Debug.LogError("Data received from epic client thats not known " + productId); OnReceivedError.Invoke(-1, new Exception("ERROR Unknown product ID")); } }
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; } }