示例#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();
        }
示例#2
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();
        }