Esempio n. 1
0
        /// <summary>
        /// Initialize a Steam Server instance
        /// </summary>
        public Server(uint appId, ServerInit init)
        {
            if (Instance != null)
            {
                throw new System.Exception("Only one Facepunch.Steamworks.Server can exist - dispose the old one before trying to create a new one.");
            }

            Instance = this;
            native   = new Interop.NativeInterface();

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

            //
            // Get other interfaces
            //
            if (!native.InitServer(this, init.IpAddress, init.SteamPort, init.GamePort, init.QueryPort, init.Secure ? 3 : 2, init.VersionString))
            {
                native.Dispose();
                native   = null;
                Instance = null;
                return;
            }

            //
            // Setup interfaces that client and server both have
            //
            SetupCommonInterfaces();

            //
            // Cache common, unchanging info
            //
            AppId = appId;

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

            //
            // Child classes
            //
            Query = new ServerQuery(this);
            Stats = new ServerStats(this);
            Auth  = new ServerAuth(this);

            //
            // Run update, first call does some initialization
            //
            Update();
        }
Esempio n. 2
0
        /// <summary>
        /// Initialize a Steam Server instance
        /// </summary>
        /// <param name="appId">You game's AppId</param>
        /// <param name="IpAddress">The IP Address to bind to. Can be 0 to mean "any".</param>
        /// <param name="SteamPort">Port to talk to steam on, can be anything as long as it's not used.".</param>
        /// <param name="GamePort">The port you game listens to for connections.</param>
        /// <param name="QueryPort">The port Steam should use for server queries.</param>
        /// <param name="Secure">True if you want to use VAC</param>
        /// <param name="VersionString">A string defining version, ie "1001"</param>
        public Server(uint appId, uint IpAddress, ushort SteamPort, ushort GamePort, ushort QueryPort, bool Secure, string VersionString)
        {
            native = new Interop.NativeInterface();

            //
            // If we don't have a SteamPort defined, choose one at 'random'
            //
            if (SteamPort == 0)
            {
                SteamPort = (ushort)new Random().Next(10000, 60000);
            }


            //
            // Get other interfaces
            //
            if (!native.InitServer(this, IpAddress, SteamPort, GamePort, QueryPort, Secure ? 3 : 2, VersionString))
            {
                native.Dispose();
                native = null;
                return;
            }

            //
            // Setup interfaces that client and server both have
            //
            SetupCommonInterfaces();

            //
            // Cache common, unchanging info
            //
            AppId = appId;

            //
            // Initial settings
            //
            native.gameServer.EnableHeartbeats(true);
            MaxPlayers = 32;
            BotCount   = 0;
            MapName    = "unset";

            //
            // Child classes
            //
            Query = new ServerQuery(this);
            Stats = new ServerStats(this);
            Auth  = new ServerAuth(this);

            //
            // Run update, first call does some initialization
            //
            Update();
        }
Esempio n. 3
0
        /// <summary>
        /// Initialize a Steam Server instance
        /// </summary>
        public Server(uint appId, ServerInit init, bool isPublic) : base(appId)
        {
            if (Instance != null)
            {
                throw new System.Exception("Only one Facepunch.Steamworks.Server can exist - dispose the old one before trying to create a new one.");
            }

            Instance = this;
            native   = new Interop.NativeInterface();
            uint ipaddress = 0; // Any Port

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

            //
            // Get other interfaces
            //

            //kind of a hack:
            //use an invalid version number to hide private servers from the server list.
            //couldn't find a way to do it otherwise - using 1 as the eServerMode doesn't
            //seem to work, the server info is still returned by the API calls
            string versionString = isPublic ? init.VersionString : "-1";

            if (!native.InitServer(this, ipaddress, init.SteamPort, init.GamePort, init.QueryPort, isPublic ? (init.Secure ? 3 : 2) : 1,
                                   versionString))
            {
                native.Dispose();
                native   = null;
                Instance = null;
                return;
            }

            //
            // Register Callbacks
            //

            SteamNative.Callbacks.RegisterCallbacks(this);

            //
            // Setup interfaces that client and server both have
            //
            SetupCommonInterfaces();



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

            //
            // Child classes
            //
            Query = new ServerQuery(this);
            Stats = new ServerStats(this);
            Auth  = new ServerAuth(this);

            //
            // Run update, first call does some initialization
            //
            Update();
        }