示例#1
0
        public static NextClient CreateClient(FizzySteamworks transport, string host)
        {
            NextClient c = new NextClient(transport);

            c.OnConnected    += () => transport.OnClientConnected.Invoke();
            c.OnDisconnected += () => transport.OnClientDisconnected.Invoke();
            c.OnReceivedData += (data, ch) => transport.OnClientDataReceived.Invoke(new ArraySegment <byte>(data), ch);

            try
            {
#if UNITY_SERVER
                SteamGameServerNetworkingUtils.InitRelayNetworkAccess();
#else
                SteamNetworkingUtils.InitRelayNetworkAccess();
#endif
                c.Connect(host);
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
                c.OnConnectionFailed();
            }

            return(c);
        }
        public override void ClientConnect(string address)
        {
            try
            {
#if UNITY_SERVER
                SteamGameServerNetworkingUtils.InitRelayNetworkAccess();
#else
                SteamNetworkingUtils.InitRelayNetworkAccess();
#endif

                InitRelayNetworkAccess();

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

                if (!ClientActive() || client.Error)
                {
                    if (UseNextGenSteamNetworking)
                    {
                        Debug.Log($"Starting client [SteamSockets], target address {address}.");
                        client = NextClient.CreateClient(this, address);
                    }
                    else
                    {
                        Debug.Log($"Starting client [DEPRECATED SteamNetworking], target address {address}. Relay enabled: {AllowSteamRelay}");
                        SteamNetworking.AllowP2PPacketRelay(AllowSteamRelay);
                        client = LegacyClient.CreateClient(this, address);
                    }
                }
                else
                {
                    Debug.LogError("Client already running!");
                }
            }
            catch (Exception ex)
            {
                Debug.LogError("Exception: " + ex.Message + ". Client could not be started.");
                OnClientDisconnected.Invoke();
            }
        }
示例#3
0
        public override void ClientConnect(string address)
        {
            if (!SteamClient.IsValid)
            {
                Debug.LogError("SteamWorks not initialized. Client could not be started.");
                OnClientDisconnected.Invoke();
                return;
            }

            if (address == SteamUserID.ToString())
            {
                Debug.Log("You can't connect to yourself.");
                return;
            }

            FetchSteamID();

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

            if (!ClientActive() || client.Error)
            {
                if (UseNextGenSteamNetworking)
                {
                    Debug.Log($"Starting client [SteamSockets], target address {address}.");
                    client = NextClient.CreateClient(this, address);
                }
                else
                {
                    Debug.Log($"Starting client [DEPRECATED SteamNetworking], target address {address}. Relay enabled: {AllowSteamRelay}");
                    SteamNetworking.AllowP2PPacketRelay(AllowSteamRelay);
                    client = LegacyClient.CreateClient(this, address);
                }
            }
            else
            {
                Debug.LogError("Client already running!");
            }
        }
示例#4
0
        public static NextClient CreateClient(FizzySteamworks transport, string host)
        {
            NextClient c = new NextClient(transport);

            c.OnConnected    += () => transport.OnClientConnected.Invoke();
            c.OnDisconnected += () => transport.OnClientDisconnected.Invoke();
            c.OnReceivedData += (data, ch) => transport.OnClientDataReceived.Invoke(new ArraySegment <byte>(data), ch);

            if (SteamManager.Initialized)
            {
                c.Connect(host);
            }
            else
            {
                Debug.LogError("SteamWorks not initialized");
                c.OnConnectionFailed();
            }

            return(c);
        }