Esempio n. 1
0
        protected override void OnNewConnection(OnIncomingConnectionRequestInfo result)
        {
            if (ignoreAllMessages)
            {
                return;
            }

            if (deadSockets.Contains(result.SocketId.SocketName))
            {
                Debug.LogError("Received incoming connection request from dead socket");
                return;
            }

            if (hostProductId == result.RemoteUserId)
            {
                EOSSDKComponent.GetP2PInterface().AcceptConnection(
                    new AcceptConnectionOptions()
                {
                    LocalUserId  = EOSSDKComponent.LocalUserProductId,
                    RemoteUserId = result.RemoteUserId,
                    SocketId     = result.SocketId
                });
            }
            else
            {
                Debug.LogError("P2P Acceptance Request from unknown host ID.");
            }
        }
Esempio n. 2
0
        protected Common(EosTransport transport)
        {
            channels = transport.Channels;

            deadSockets = new List <string>();

            AddNotifyPeerConnectionRequestOptions addNotifyPeerConnectionRequestOptions = new AddNotifyPeerConnectionRequestOptions();

            addNotifyPeerConnectionRequestOptions.LocalUserId = EOSSDKComponent.LocalUserProductId;
            addNotifyPeerConnectionRequestOptions.SocketId    = null;

            OnIncomingConnectionRequest += OnNewConnection;
            OnRemoteConnectionClosed    += OnConnectFail;

            incomingNotificationId = EOSSDKComponent.GetP2PInterface().AddNotifyPeerConnectionRequest(addNotifyPeerConnectionRequestOptions,
                                                                                                      null, OnIncomingConnectionRequest);

            AddNotifyPeerConnectionClosedOptions addNotifyPeerConnectionClosedOptions = new AddNotifyPeerConnectionClosedOptions();

            addNotifyPeerConnectionClosedOptions.LocalUserId = EOSSDKComponent.LocalUserProductId;
            addNotifyPeerConnectionClosedOptions.SocketId    = null;

            outgoingNotificationId = EOSSDKComponent.GetP2PInterface().AddNotifyPeerConnectionClosed(addNotifyPeerConnectionClosedOptions,
                                                                                                     null, OnRemoteConnectionClosed);

            if (outgoingNotificationId == 0 || incomingNotificationId == 0)
            {
                Debug.LogError("Couldn't bind notifications with P2P interface");
            }

            this.transport = transport;
        }
Esempio n. 3
0
        protected Common(EosTransport transport)
        {
            channels = transport.Channels;

            AddNotifyPeerConnectionRequestOptions addNotifyPeerConnectionRequestOptions = new AddNotifyPeerConnectionRequestOptions();

            addNotifyPeerConnectionRequestOptions.LocalUserId = EOSSDKComponent.LocalUserProductId;
            SocketId socketId = new SocketId();

            socketId.SocketName = SOCKET_ID;
            addNotifyPeerConnectionRequestOptions.SocketId = socketId;

            OnIncomingConnectionRequest += OnNewConnection;
            OnRemoteConnectionClosed    += OnConnectFail;

            EOSSDKComponent.GetP2PInterface().AddNotifyPeerConnectionRequest(addNotifyPeerConnectionRequestOptions,
                                                                             null, OnIncomingConnectionRequest);

            AddNotifyPeerConnectionClosedOptions addNotifyPeerConnectionClosedOptions = new AddNotifyPeerConnectionClosedOptions();

            addNotifyPeerConnectionClosedOptions.LocalUserId = EOSSDKComponent.LocalUserProductId;
            addNotifyPeerConnectionClosedOptions.SocketId    = socketId;

            EOSSDKComponent.GetP2PInterface().AddNotifyPeerConnectionClosed(addNotifyPeerConnectionClosedOptions,
                                                                            null, OnRemoteConnectionClosed);

            this.transport = transport;
        }
Esempio n. 4
0
        protected void Dispose()
        {
            EOSSDKComponent.GetP2PInterface().RemoveNotifyPeerConnectionRequest(incomingNotificationId);
            EOSSDKComponent.GetP2PInterface().RemoveNotifyPeerConnectionClosed(outgoingNotificationId);

            transport.ResetIgnoreMessagesAtStartUpTimer();
        }
Esempio n. 5
0
 protected void CloseP2PSessionWithUser(ProductUserId clientUserID) => EOSSDKComponent.GetP2PInterface().CloseConnection(
     new CloseConnectionOptions()
 {
     LocalUserId  = EOSSDKComponent.LocalUserProductId,
     RemoteUserId = clientUserID,
     SocketId     = new SocketId()
     {
         SocketName = SOCKET_ID
     }
 });
Esempio n. 6
0
 protected void Send(ProductUserId host, SocketId socketId, byte[] msgBuffer, byte channel) =>
 EOSSDKComponent.GetP2PInterface().SendPacket(new SendPacketOptions()
 {
     AllowDelayedDelivery = true,
     Channel      = channel,
     Data         = msgBuffer,
     LocalUserId  = EOSSDKComponent.LocalUserProductId,
     Reliability  = channels[channel],
     RemoteUserId = host,
     SocketId     = socketId
 });
Esempio n. 7
0
 protected void SendInternal(ProductUserId target, SocketId socketId, InternalMessages type)
 {
     EOSSDKComponent.GetP2PInterface().SendPacket(new SendPacketOptions()
     {
         AllowDelayedDelivery = true,
         Channel      = (byte)internal_ch,
         Data         = new byte[] { (byte)type },
         LocalUserId  = EOSSDKComponent.LocalUserProductId,
         Reliability  = PacketReliability.ReliableOrdered,
         RemoteUserId = target,
         SocketId     = socketId
     });
 }
Esempio n. 8
0
        private IEnumerator ChangeRelayStatus()
        {
            while (!EOSSDKComponent.Initialized)
            {
                yield return(null);
            }

            SetRelayControlOptions setRelayControlOptions = new SetRelayControlOptions();

            setRelayControlOptions.RelayControl = relayControl;

            EOSSDKComponent.GetP2PInterface().SetRelayControl(setRelayControlOptions);
        }
Esempio n. 9
0
        void Awake()
        {
            // Prevent multiple instances
            if (instance != null)
            {
                Destroy(gameObject);
                return;
            }
            instance = this;

            if (!delayedInitialization)
            {
                Initialize();
            }
        }
Esempio n. 10
0
        public override void ClientConnect(string address)
        {
            if (!EOSSDKComponent.Initialized)
            {
                Debug.LogError("EOS not initialized. Client could not be started.");
                OnClientDisconnected.Invoke();
                return;
            }

            StartCoroutine("FetchEpicAccountId");

            if (ServerActive())
            {
                Debug.LogError("Transport already running as server!");
                return;
            }

            if (!ClientActive() || client.Error)
            {
                Debug.Log($"Starting client, target address {address}.");

                //client = Client.CreateClient(this, address);
                activeNode = client;

                if (EOSSDKComponent.CollectPlayerMetrics)
                {
                    // Start Metrics colletion session
                    BeginPlayerSessionOptions sessionOptions = new BeginPlayerSessionOptions();
                    sessionOptions.AccountId      = EOSSDKComponent.LocalUserAccountId;
                    sessionOptions.ControllerType = UserControllerType.Unknown;
                    sessionOptions.DisplayName    = EOSSDKComponent.DisplayName;
                    sessionOptions.GameSessionId  = null;
                    sessionOptions.ServerIp       = null;
                    Result result = EOSSDKComponent.GetMetricsInterface().BeginPlayerSession(sessionOptions);

                    if (result == Result.Success)
                    {
                        Debug.Log("Started Metric Session");
                    }
                }
            }
            else
            {
                Debug.LogError("Client already running!");
            }
        }
Esempio n. 11
0
        private void Update()
        {
            if (EOSSDKComponent.Initialized)
            {
                EOSSDKComponent.Tick();
            }

            if (client != null && client.isConnecting)
            {
                client.ReceiveData();
            }

            if (server != null)
            {
                server.ReceiveData();
            }
        }
Esempio n. 12
0
        public override void ServerStart()
        {
            if (!EOSSDKComponent.Initialized)
            {
                Debug.LogError("EOS not initialized. Server could not be started.");
                return;
            }

            StartCoroutine("FetchEpicAccountId");

            if (ClientActive())
            {
                Debug.LogError("Transport already running as client!");
                return;
            }

            if (!ServerActive())
            {
                Debug.Log("Starting server.");

                //server = Server.CreateServer(this, maxConnections);
                activeNode = server;

                if (EOSSDKComponent.CollectPlayerMetrics)
                {
                    // Start Metrics colletion session
                    BeginPlayerSessionOptions sessionOptions = new BeginPlayerSessionOptions();
                    sessionOptions.AccountId      = EOSSDKComponent.LocalUserAccountId;
                    sessionOptions.ControllerType = UserControllerType.Unknown;
                    sessionOptions.DisplayName    = EOSSDKComponent.DisplayName;
                    sessionOptions.GameSessionId  = null;
                    sessionOptions.ServerIp       = null;
                    Result result = EOSSDKComponent.GetMetricsInterface().BeginPlayerSession(sessionOptions);

                    if (result == Result.Success)
                    {
                        Debug.Log("Started Metric Session");
                    }
                }
            }
            else
            {
                Debug.LogError("Server already started!");
            }
        }
Esempio n. 13
0
        private bool Receive(out ProductUserId clientProductUserId, out SocketId socketId, out byte[] receiveBuffer, byte channel)
        {
            Result result = EOSSDKComponent.GetP2PInterface().ReceivePacket(new ReceivePacketOptions()
            {
                LocalUserId      = EOSSDKComponent.LocalUserProductId,
                MaxDataSizeBytes = P2PInterface.MaxPacketSize,
                RequestedChannel = channel
            }, out clientProductUserId, out socketId, out channel, out receiveBuffer);

            if (result == Result.Success)
            {
                return(true);
            }

            receiveBuffer       = null;
            clientProductUserId = null;
            return(false);
        }
Esempio n. 14
0
        protected void Send(ProductUserId host, SocketId socketId, byte[] msgBuffer, byte channel)
        {
            Result result = EOSSDKComponent.GetP2PInterface().SendPacket(new SendPacketOptions()
            {
                AllowDelayedDelivery = true,
                Channel      = channel,
                Data         = msgBuffer,
                LocalUserId  = EOSSDKComponent.LocalUserProductId,
                Reliability  = channels[channel],
                RemoteUserId = host,
                SocketId     = socketId
            });

            if (result != Result.Success)
            {
                Debug.LogError("Send failed " + result);
            }
        }
Esempio n. 15
0
 protected override void OnNewConnection(OnIncomingConnectionRequestInfo result)
 {
     if (hostProductId == result.RemoteUserId)
     {
         EOSSDKComponent.GetP2PInterface().AcceptConnection(
             new AcceptConnectionOptions()
         {
             LocalUserId  = EOSSDKComponent.LocalUserProductId,
             RemoteUserId = result.RemoteUserId,
             SocketId     = new SocketId()
             {
                 SocketName = SOCKET_ID
             }
         });
     }
     else
     {
         Debug.LogError("P2P Acceptance Request from unknown host ID.");
     }
 }
Esempio n. 16
0
        private void Awake()
        {
            // Initialize Java version of the SDK with a reference to the VM with JNI
            // See https://eoshelp.epicgames.com/s/question/0D54z00006ufJBNCA2/cant-get-createdeviceid-to-work-in-unity-android-c-sdk?language=en_US
            if (Application.platform == RuntimePlatform.Android)
            {
                AndroidJavaClass  unityPlayer  = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
                AndroidJavaObject activity     = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity");
                AndroidJavaObject context      = activity.Call <AndroidJavaObject>("getApplicationContext");
                AndroidJavaClass  EOS_SDK_JAVA = new AndroidJavaClass("com.epicgames.mobile.eossdk.EOSSDK");
                EOS_SDK_JAVA.CallStatic("init", context);
            }

            // Prevent multiple instances
            if (instance != null)
            {
                Destroy(gameObject);
                return;
            }

            instance = this;

#if UNITY_EDITOR
            var libraryPath = "Assets/Mirror/Runtime/Transport/EpicOnlineTransport/EOSSDK/" + Config.LibraryName;

            libraryPointer = LoadLibrary(libraryPath);
            if (libraryPointer == IntPtr.Zero)
            {
                throw new Exception("Failed to load library" + libraryPath);
            }

            Bindings.Hook(libraryPointer, GetProcAddress);
#endif

            if (!delayedInitialization)
            {
                Initialize();
            }
        }
        public override void ClientEarlyUpdate()
        {
            EOSSDKComponent.Tick();

            if (activeNode != null)
            {
                ignoreCachedMessagesTimer += Time.deltaTime;

                if (ignoreCachedMessagesTimer <= ignoreCachedMessagesAtStartUpInSeconds)
                {
                    activeNode.ignoreAllMessages = true;
                }
                else
                {
                    activeNode.ignoreAllMessages = false;

                    if (client != null && !client.isConnecting)
                    {
                        if (EOSSDKComponent.Initialized)
                        {
                            client.Connect(client.hostAddress);
                        }
                        else
                        {
                            Debug.LogError("EOS not initialized");
                            client.EosNotInitialized();
                        }

                        client.isConnecting = true;
                    }
                }
            }

            if (enabled)
            {
                activeNode?.ReceiveData();
            }
        }
Esempio n. 18
0
        public override void ServerEarlyUpdate()
        {
            EOSSDKComponent.Tick();

            if (activeNode != null)
            {
                ignoreCachedMessagesTimer += Time.deltaTime;

                if (ignoreCachedMessagesTimer <= ignoreCachedMessagesAtStartUpInSeconds)
                {
                    activeNode.ignoreAllMessages = true;
                }
                else
                {
                    activeNode.ignoreAllMessages = false;
                }
            }

            if (enabled)
            {
                activeNode?.ReceiveData();
            }
        }
Esempio n. 19
0
        public override void Shutdown()
        {
            if (EOSSDKComponent.CollectPlayerMetrics)
            {
                // Stop Metrics collection session
                EndPlayerSessionOptions endSessionOptions = new EndPlayerSessionOptions();
                endSessionOptions.AccountId = EOSSDKComponent.LocalUserAccountId;
                Result result = EOSSDKComponent.GetMetricsInterface().EndPlayerSession(endSessionOptions);

                if (result == Result.Success)
                {
                    Debug.LogError("Stopped Metric Session");
                }
            }

            server?.Shutdown();
            client?.Disconnect();

            server     = null;
            client     = null;
            activeNode = null;
            Debug.Log("Transport shut down.");
        }
Esempio n. 20
0
 protected override void OnNewConnection(OnIncomingConnectionRequestInfo result) => EOSSDKComponent.GetP2PInterface().AcceptConnection(
     new AcceptConnectionOptions() {
         LocalUserId = EOSSDKComponent.LocalUserProductId,
         RemoteUserId = result.RemoteUserId,
         SocketId = new SocketId() { SocketName = SOCKET_ID }
     });