Esempio n. 1
0
        public static LegacyClient CreateClient(FizzySteamworks transport, string host)
        {
            LegacyClient c = new LegacyClient(transport);

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


            try
            {
#if UNITY_SERVER
                InteropHelp.TestIfAvailableGameServer();
#else
                InteropHelp.TestIfAvailableClient();
#endif
                c.Connect(host);
            }
            catch
            {
                Debug.LogError("SteamWorks not initialized.");
                c.OnConnectionFailed(CSteamID.Nil);
            }

            return(c);
        }
Esempio n. 2
0
        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();
            }
        }
Esempio n. 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!");
            }
        }
Esempio n. 4
0
        public static LegacyClient CreateClient(FizzySteamworks transport, string host)
        {
            LegacyClient c = new LegacyClient(transport);

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

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

            return(c);
        }