Пример #1
0
        public static NextServer CreateServer(FizzySteamworks transport, int maxConnections)
        {
            NextServer s = new NextServer(maxConnections);

            s.OnConnected     += (id) => transport.OnServerConnected.Invoke(id);
            s.OnDisconnected  += (id) => transport.OnServerDisconnected.Invoke(id);
            s.OnReceivedData  += (id, data, ch) => transport.OnServerDataReceived.Invoke(id, new ArraySegment <byte>(data), ch);
            s.OnReceivedError += (id, exception) => transport.OnServerError.Invoke(id, exception);

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

            s.Host();

            return(s);
        }
Пример #2
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);
        }
Пример #3
0
        private void Awake()
        {
            const string fileName = "steam_appid.txt";

            if (File.Exists(fileName))
            {
                string content = File.ReadAllText(fileName);
                if (content != SteamAppID)
                {
                    File.WriteAllText(fileName, SteamAppID.ToString());
                    Debug.Log($"Updating {fileName}. Previous: {content}, new SteamAppID {SteamAppID}");
                }
            }
            else
            {
                File.WriteAllText(fileName, SteamAppID.ToString());
                Debug.Log($"New {fileName} written with SteamAppID {SteamAppID}");
            }

            if (UseNextGenSteamNetworking)
            {
                SteamNetworkingUtils.InitRelayNetworkAccess();
            }

            Debug.Assert(Channels != null && Channels.Length > 0, "No channel configured for FizzySteamworks.");

            Invoke(nameof(FetchSteamID), 1f);
        }
Пример #4
0
        ///// Methods /////

        //private string _test = string.Empty;

        private void Awake()
        {
            if (SteamClient.IsValid)
            {
                return;
            }

            Dispatch.OnException = (e) =>
            {
                UnityEngine.Debug.LogError(e.Message);
                UnityEngine.Debug.Log(e.StackTrace);
            };

            //Steamworks.Dispatch.OnDebugCallback = (type, str, server) =>
            //{
            //    UnityEngine.Debug.Log($"[Callback {type} {(server ? "server" : "client")}]");
            //    UnityEngine.Debug.Log($"{str}");
            //};

            //SteamNetworkingUtils.DebugLevel = NetDebugOutput.Everything;
            //SteamNetworkingUtils.OnDebugOutput += (e1, e2) =>
            //{
            //    UnityEngine.Debug.Log(e1 + ":" + e2);
            //    _test += e1 + "::" + e2 + "\n";
            //};

            //Steamworks.Dispatch.OnDebugCallback = (type, str, server) =>
            //{
            //    UnityEngine.Debug.Log($"[Callback {type} {(server ? "server" : "client")}]");
            //    UnityEngine.Debug.Log(str);
            //    UnityEngine.Debug.Log($"");

            //    _test += $"[Callback {type} {(server ? "server" : "client")}]\n";
            //    _test += $"{str}\n";
            //    _test += $"\n\n";
            //};

            try
            {
                SteamClient.Init(Structure.AppId);
            }
            catch (System.Exception e)
            {
                ExceptionMessage = e.ToString();
                Debug.LogError(e.ToString());
                return;
            }

            if (!SteamApps.IsSubscribedToApp(Structure.AppId))
            {
                Application.Quit();
            }

            SteamNetworkingUtils.InitRelayNetworkAccess();

            Initialized = true;
        }
Пример #5
0
        private void FetchSteamID()
        {
            if (SteamManager.Initialized)
            {
                if (UseNextGenSteamNetworking)
                {
                    SteamNetworkingUtils.InitRelayNetworkAccess();
                }

                SteamUserID = SteamUser.GetSteamID().m_SteamID;
            }
        }
Пример #6
0
        public void Startup()
        {
            InitializeModules();
            SetupLobby();

            SteamNetworkingUtils.InitRelayNetworkAccess();
            isInitialized = true;

            Started?.Invoke();
            isRunning = true;
            Debug.Log("Server Started");
        }
Пример #7
0
        private void FetchSteamID()
        {
            if (SteamClient.IsValid)
            {
                if (UseNextGenSteamNetworking)
                {
                    SteamNetworkingUtils.InitRelayNetworkAccess();
                }

                SteamUserID = SteamClient.SteamId;
            }
        }
        public SteamSocket(SteamOptions options, bool isServer)
        {
            Debug.Log("Starting up FizzySteam Socket...");

            if (options.useSteamRelay)
            {
                SteamNetworkingUtils.InitRelayNetworkAccess();
            }

            _steamOptions       = options;
            _isServer           = isServer;
            _steamSocketManager = new SteamSocketManager(options, isServer);
        }
Пример #9
0
        private void InitRelayNetworkAccess()
        {
            try
            {
                if (UseNextGenSteamNetworking)
                {
#if UNITY_SERVER
                    SteamGameServerNetworkingUtils.InitRelayNetworkAccess();
#else
                    SteamNetworkingUtils.InitRelayNetworkAccess();
#endif
                }
            }
            catch { }
        }
Пример #10
0
        public override void ServerStart()
        {
            try
            {
#if UNITY_SERVER
                SteamGameServerNetworkingUtils.InitRelayNetworkAccess();
#else
                SteamNetworkingUtils.InitRelayNetworkAccess();
#endif


                InitRelayNetworkAccess();

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

                if (!ServerActive())
                {
                    if (UseNextGenSteamNetworking)
                    {
                        Debug.Log($"Starting server [SteamSockets].");
                        server = NextServer.CreateServer(this, NetworkManager.singleton.maxConnections);
                    }
                    else
                    {
                        Debug.Log($"Starting server [DEPRECATED SteamNetworking]. Relay enabled: {AllowSteamRelay}");
#if UNITY_SERVER
                        SteamGameServerNetworking.AllowP2PPacketRelay(AllowSteamRelay);
#else
                        SteamNetworking.AllowP2PPacketRelay(AllowSteamRelay);
#endif
                        server = LegacyServer.CreateServer(this, NetworkManager.singleton.maxConnections);
                    }
                }
                else
                {
                    Debug.LogError("Server already started!");
                }
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
                return;
            }
        }
Пример #11
0
        public override bool Available()
        {
            try
            {
#if UNITY_SERVER
                SteamGameServerNetworkingUtils.InitRelayNetworkAccess();
#else
                SteamNetworkingUtils.InitRelayNetworkAccess();
#endif
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #12
0
    // Token: 0x06000981 RID: 2433 RVA: 0x00045C30 File Offset: 0x00043E30
    private static void RegisterGlobalCallbacks()
    {
        if (ZSteamSocket.m_statusChanged == null)
        {
            ZSteamSocket.m_statusChanged = Callback <SteamNetConnectionStatusChangedCallback_t> .Create(new Callback <SteamNetConnectionStatusChangedCallback_t> .DispatchDelegate(ZSteamSocket.OnStatusChanged));

            GCHandle gchandle  = GCHandle.Alloc(30000f, GCHandleType.Pinned);
            GCHandle gchandle2 = GCHandle.Alloc(1, GCHandleType.Pinned);
            GCHandle gchandle3 = GCHandle.Alloc(153600, GCHandleType.Pinned);
            SteamNetworkingUtils.SetConfigValue(ESteamNetworkingConfigValue.k_ESteamNetworkingConfig_TimeoutConnected, ESteamNetworkingConfigScope.k_ESteamNetworkingConfig_Global, IntPtr.Zero, ESteamNetworkingConfigDataType.k_ESteamNetworkingConfig_Float, gchandle.AddrOfPinnedObject());
            SteamNetworkingUtils.SetConfigValue(ESteamNetworkingConfigValue.k_ESteamNetworkingConfig_IP_AllowWithoutAuth, ESteamNetworkingConfigScope.k_ESteamNetworkingConfig_Global, IntPtr.Zero, ESteamNetworkingConfigDataType.k_ESteamNetworkingConfig_Int32, gchandle2.AddrOfPinnedObject());
            SteamNetworkingUtils.SetConfigValue(ESteamNetworkingConfigValue.k_ESteamNetworkingConfig_SendRateMin, ESteamNetworkingConfigScope.k_ESteamNetworkingConfig_Global, IntPtr.Zero, ESteamNetworkingConfigDataType.k_ESteamNetworkingConfig_Int32, gchandle3.AddrOfPinnedObject());
            SteamNetworkingUtils.SetConfigValue(ESteamNetworkingConfigValue.k_ESteamNetworkingConfig_SendRateMax, ESteamNetworkingConfigScope.k_ESteamNetworkingConfig_Global, IntPtr.Zero, ESteamNetworkingConfigDataType.k_ESteamNetworkingConfig_Int32, gchandle3.AddrOfPinnedObject());
            gchandle.Free();
            gchandle2.Free();
            gchandle3.Free();
        }
    }
Пример #13
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();
            }
        }