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."); } }
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; }
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; }
protected void Dispose() { EOSSDKComponent.GetP2PInterface().RemoveNotifyPeerConnectionRequest(incomingNotificationId); EOSSDKComponent.GetP2PInterface().RemoveNotifyPeerConnectionClosed(outgoingNotificationId); transport.ResetIgnoreMessagesAtStartUpTimer(); }
protected void CloseP2PSessionWithUser(ProductUserId clientUserID) => EOSSDKComponent.GetP2PInterface().CloseConnection( new CloseConnectionOptions() { LocalUserId = EOSSDKComponent.LocalUserProductId, RemoteUserId = clientUserID, SocketId = new SocketId() { SocketName = SOCKET_ID } });
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 });
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 }); }
private IEnumerator ChangeRelayStatus() { while (!EOSSDKComponent.Initialized) { yield return(null); } SetRelayControlOptions setRelayControlOptions = new SetRelayControlOptions(); setRelayControlOptions.RelayControl = relayControl; EOSSDKComponent.GetP2PInterface().SetRelayControl(setRelayControlOptions); }
void Awake() { // Prevent multiple instances if (instance != null) { Destroy(gameObject); return; } instance = this; if (!delayedInitialization) { Initialize(); } }
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!"); } }
private void Update() { if (EOSSDKComponent.Initialized) { EOSSDKComponent.Tick(); } if (client != null && client.isConnecting) { client.ReceiveData(); } if (server != null) { server.ReceiveData(); } }
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!"); } }
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); }
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); } }
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."); } }
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(); } }
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(); } }
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."); }
protected override void OnNewConnection(OnIncomingConnectionRequestInfo result) => EOSSDKComponent.GetP2PInterface().AcceptConnection( new AcceptConnectionOptions() { LocalUserId = EOSSDKComponent.LocalUserProductId, RemoteUserId = result.RemoteUserId, SocketId = new SocketId() { SocketName = SOCKET_ID } });