public static void Init(AppId appid, SteamServerInit init)
        {
            uint num = 0;

            if (init.SteamPort == 0)
            {
                init = init.WithRandomSteamPort();
            }
            if (init.IpAddress != null)
            {
                num = init.IpAddress.IpToInt32();
            }
            Environment.SetEnvironmentVariable("SteamAppId", appid.ToString());
            Environment.SetEnvironmentVariable("SteamGameId", appid.ToString());
            int num1 = (init.Secure ? 3 : 2);

            if (!SteamInternal.GameServer_Init(num, init.SteamPort, init.GamePort, init.QueryPort, num1, init.VersionString))
            {
                throw new Exception(String.Format("InitGameServer returned false ({0},{1},{2},{3},{4},\"{5}\")", new Object[] { num, init.SteamPort, init.GamePort, init.QueryPort, num1, init.VersionString }));
            }
            SteamServer.initialized         = true;
            SteamServer.AutomaticHeartbeats = true;
            SteamServer.MaxPlayers          = 32;
            SteamServer.BotCount            = 0;
            SteamServer.Product             = String.Format("{0}", appid.Value);
            SteamServer.ModDir          = init.ModDir;
            SteamServer.GameDescription = init.GameDescription;
            SteamServer.Passworded      = false;
            SteamServer.DedicatedServer = init.DedicatedServer;
            SteamServer.InstallEvents();
            SteamServer.RunCallbacksAsync();
        }
Example #2
0
        public static void AssemblyInit(TestContext context)
        {
            Steamworks.SteamClient.OnCallbackException = (e) =>
            {
                Console.Error.WriteLine(e.Message);
                Console.Error.WriteLine(e.StackTrace);
                Assert.Fail(e.Message);
            };

            //
            // Init Client
            //
            Steamworks.SteamClient.Init(252490);

            //
            // Init Server
            //
            var serverInit = new SteamServerInit("rust", "Rusty Mode")
            {
                GamePort  = 28015,
                Secure    = true,
                QueryPort = 28016
            };

            Steamworks.SteamServer.Init(252490, serverInit);

            SteamServer.LogOnAnonymous();
        }
        public static void AssemblyInit(TestContext context)
        {
            Steamworks.Dispatch.OnDebugCallback = (type, str, server) =>
            {
                Console.WriteLine($"[Callback {type} {(server ? "server" : "client")}]");
                Console.WriteLine(str);
                Console.WriteLine($"");
            };

            Steamworks.Dispatch.OnException = (e) =>
            {
                Console.Error.WriteLine(e.Message);
                Console.Error.WriteLine(e.StackTrace);
                Assert.Fail(e.Message);
            };

            //
            // Init Client
            //
            Steamworks.SteamClient.Init(252490);

            //
            // Init Server
            //
            var serverInit = new SteamServerInit("rust", "Rusty Mode")
            {
                GamePort  = 28015,
                Secure    = true,
                QueryPort = 28016
            };

            Steamworks.SteamServer.Init(252490, serverInit);

            SteamServer.LogOnAnonymous();
        }
        /// <summary>
        /// Initialize the steam server.
        /// If asyncCallbacks is false you need to call RunCallbacks manually every frame.
        /// </summary>
        public static void Init(AppId appid, SteamServerInit init, bool asyncCallbacks = true)
        {
            uint ipaddress = 0;             // Any Port

            if (init.SteamPort == 0)
            {
                init = init.WithRandomSteamPort();
            }

            if (init.IpAddress != null)
            {
                ipaddress = Utility.IpToInt32(init.IpAddress);
            }

            System.Environment.SetEnvironmentVariable("SteamAppId", appid.ToString());
            System.Environment.SetEnvironmentVariable("SteamGameId", appid.ToString());
            var secure = (int)(init.Secure ? 3 : 2);

            //
            // Get other interfaces
            //
            if (!SteamInternal.GameServer_Init(ipaddress, init.SteamPort, init.GamePort, init.QueryPort, secure, init.VersionString))
            {
                throw new System.Exception($"InitGameServer returned false ({ipaddress},{init.SteamPort},{init.GamePort},{init.QueryPort},{secure},\"{init.VersionString}\")");
            }

            initialized = true;

            //
            // Initial settings
            //
            AutomaticHeartbeats = true;
            MaxPlayers          = 32;
            BotCount            = 0;
            Product             = $"{appid.Value}";
            ModDir          = init.ModDir;
            GameDescription = init.GameDescription;
            Passworded      = false;
            DedicatedServer = init.DedicatedServer;

            InstallEvents();

            if (asyncCallbacks)
            {
                RunCallbacksAsync();
            }
        }
        public static void AssemblyInit(TestContext context)
        {
            //
            // Init Client
            //
            Steamworks.SteamClient.Init(252490);

            //
            // Init Server
            //
            var serverInit = new SteamServerInit("rust", "Rusty Mode")
            {
                GamePort  = 28015,
                Secure    = true,
                QueryPort = 28016
            };

            Steamworks.SteamServer.Init(252490, serverInit);

            SteamServer.LogOnAnonymous();
        }
Example #6
0
        public static void Init(AppId appid, SteamServerInit init)
        {
            uint ipaddress = 0;             // Any Port

            if (init.SteamPort == 0)
            {
                init = init.WithRandomSteamPort();
            }

            if (init.IpAddress != null)
            {
                ipaddress = Utility.IpToInt32(init.IpAddress);
            }

            //
            // Get other interfaces
            //
            if (!SteamInternal.GameServer_Init(ipaddress, init.SteamPort, init.GamePort, init.QueryPort, (int)(init.Secure ? 3 : 2), init.VersionString))
            {
                throw new System.Exception("InitGameServer returned false");
            }

            initialized = true;

            //
            // Initial settings
            //
            Internal.EnableHeartbeats(true);
            MaxPlayers      = 32;
            BotCount        = 0;
            Product         = $"{appid.Value}";
            ModDir          = init.ModDir;
            GameDescription = init.GameDescription;
            Passworded      = false;
            DedicatedServer = true;

            InstallEvents();

            RunCallbacksAsync();
        }
        /// <summary>
        /// Initialize the steam server.
        /// If <paramref name="asyncCallbacks"/> is <see langword="false"/> you need to call <see cref="RunCallbacks"/> manually every frame.
        /// </summary>
        public static void Init(AppId appid, SteamServerInit init, bool asyncCallbacks = true)
        {
            if (IsValid)
            {
                throw new System.Exception("Calling SteamServer.Init but is already initialized");
            }

            uint ipaddress = 0;             // Any Port

            if (init.IpAddress != null)
            {
                ipaddress = Utility.IpToInt32(init.IpAddress);
            }

            System.Environment.SetEnvironmentVariable("SteamAppId", appid.ToString());
            System.Environment.SetEnvironmentVariable("SteamGameId", appid.ToString());
            var secure = (int)(init.Secure ? 3 : 2);

            //
            // Get other interfaces
            //
            if (!SteamInternal.GameServer_Init(ipaddress, 0, init.GamePort, init.QueryPort, secure, init.VersionString))
            {
                throw new System.Exception($"InitGameServer returned false ({ipaddress},{0},{init.GamePort},{init.QueryPort},{secure},\"{init.VersionString}\")");
            }

            //
            // Dispatch is responsible for pumping the
            // event loop.
            //
            Dispatch.Init();
            Dispatch.ServerPipe = SteamGameServer.GetHSteamPipe();

            AddInterface <SteamServer>();
            AddInterface <SteamUtils>();
            AddInterface <SteamNetworking>();
            AddInterface <SteamServerStats>();
            //AddInterface<ISteamHTTP>();
            AddInterface <SteamInventory>();
            AddInterface <SteamUGC>();
            AddInterface <SteamApps>();

            AddInterface <SteamNetworkingUtils>();
            AddInterface <SteamNetworkingSockets>();

            //
            // Initial settings
            //
            AdvertiseServer = true;
            MaxPlayers      = 32;
            BotCount        = 0;
            Product         = $"{appid.Value}";
            ModDir          = init.ModDir;
            GameDescription = init.GameDescription;
            Passworded      = false;
            DedicatedServer = init.DedicatedServer;

            if (asyncCallbacks)
            {
                //
                // This will keep looping in the background every 16 ms
                // until we shut down.
                //
                Dispatch.LoopServerAsync();
            }
        }
        /// <summary>
        /// Initialize the steam server.
        /// If asyncCallbacks is false you need to call RunCallbacks manually every frame.
        /// </summary>
        public static void Init(AppId appid, SteamServerInit init, bool asyncCallbacks = true)
        {
            uint ipaddress = 0;             // Any Port

            if (init.SteamPort == 0)
            {
                init = init.WithRandomSteamPort();
            }

            if (init.IpAddress != null)
            {
                ipaddress = Utility.IpToInt32(init.IpAddress);
            }

            System.Environment.SetEnvironmentVariable("SteamAppId", appid.ToString());
            System.Environment.SetEnvironmentVariable("SteamGameId", appid.ToString());
            var secure = (int)(init.Secure ? 3 : 2);

            //
            // Get other interfaces
            //
            if (!SteamInternal.GameServer_Init(ipaddress, init.SteamPort, init.GamePort, init.QueryPort, secure, init.VersionString))
            {
                throw new System.Exception($"InitGameServer returned false ({ipaddress},{init.SteamPort},{init.GamePort},{init.QueryPort},{secure},\"{init.VersionString}\")");
            }

            //
            // Dispatch is responsible for pumping the
            // event loop.
            //
            Dispatch.Init();
            Dispatch.ServerPipe = SteamGameServer.GetHSteamPipe();
            Console.WriteLine($"Dispatch.ServerPipe = {Dispatch.ServerPipe.Value}");

            AddInterface <SteamServer>();
            AddInterface <SteamNetworkingUtils>();
            AddInterface <SteamNetworkingSockets>();

            //
            // Initial settings
            //
            AutomaticHeartbeats = true;
            MaxPlayers          = 32;
            BotCount            = 0;
            Product             = $"{appid.Value}";
            ModDir          = init.ModDir;
            GameDescription = init.GameDescription;
            Passworded      = false;
            DedicatedServer = init.DedicatedServer;

            InstallEvents();

            if (asyncCallbacks)
            {
                //
                // This will keep looping in the background every 16 ms
                // until we shut down.
                //
                Dispatch.LoopServerAsync();
            }
        }