示例#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
        public virtual void Dispose()
        {
            foreach (var h in CallbackHandles)
            {
                h.Dispose();
            }
            CallbackHandles.Clear();

            if (Workshop != null)
            {
                Workshop.Dispose();
                Workshop = null;
            }

            if (Inventory != null)
            {
                Inventory.Dispose();
                Inventory = null;
            }

            if (Networking != null)
            {
                Networking.Dispose();
                Networking = null;
            }

            if (native != null)
            {
                native.Dispose();
                native = null;
            }

            System.Environment.SetEnvironmentVariable("SteamAppId", null);
            System.Environment.SetEnvironmentVariable("SteamGameId", null);
        }
        public virtual void Dispose()
        {
            foreach (var h in CallbackHandles)
            {
                h.Dispose();
            }
            CallbackHandles.Clear();

            if (Workshop != null)
            {
                Workshop.Dispose();
                Workshop = null;
            }

            if (Inventory != null)
            {
                Inventory.Dispose();
                Inventory = null;
            }

            if (Networking != null)
            {
                Networking.Dispose();
                Networking = null;
            }

            if (native != null)
            {
                native.Dispose();
                native = null;
            }
        }
示例#4
0
        public Client(uint appId)
        {
            Instance = this;
            native   = new Interop.NativeInterface();

            //
            // Get other interfaces
            //
            if (!native.InitClient(this))
            {
                native.Dispose();
                native   = null;
                Instance = null;
                return;
            }

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

            //
            // Client only interfaces
            //
            Voice             = new Voice(this);
            ServerList        = new ServerList(this);
            LobbyList         = new LobbyList(this);
            App               = new App(this);
            Stats             = new Stats(this);
            Achievements      = new Achievements(this);
            MicroTransactions = new MicroTransactions(this);
            User              = new User(this);
            RemoteStorage     = new RemoteStorage(this);

            Workshop.friends = Friends;

            Stats.UpdateStats();

            //
            // Cache common, unchanging info
            //
            AppId              = appId;
            Username           = native.friends.GetPersonaName();
            SteamId            = native.user.GetSteamID();
            BetaName           = native.apps.GetCurrentBetaName();
            OwnerSteamId       = native.apps.GetAppOwner();
            InstallFolder      = new DirectoryInfo(native.apps.GetAppInstallDir(AppId));
            BuildId            = native.apps.GetAppBuildId();
            CurrentLanguage    = native.apps.GetCurrentGameLanguage();
            AvailableLanguages = native.apps.GetAvailableGameLanguages().Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); // TODO: Assumed colon separated



            //
            // Run update, first call does some initialization
            //
            Update();
        }
示例#5
0
        public virtual void Dispose()
        {
            if (disposed)
            {
                return;
            }

            Callbacks.Clear();

            foreach (var h in CallbackHandles)
            {
                h.Dispose();
            }
            CallbackHandles.Clear();

            foreach (var h in CallResults)
            {
                h.Dispose();
            }
            CallResults.Clear();

            if (Workshop != null)
            {
                Workshop.Dispose();
                Workshop = null;
            }

            if (Inventory != null)
            {
                Inventory.Dispose();
                Inventory = null;
            }

            if (Networking != null)
            {
                Networking.Dispose();
                Networking = null;
            }

            if (native != null)
            {
                try
                {
                    native.Dispose();
                }
                catch (DllNotFoundException e)
                {
                    System.Diagnostics.Debug.WriteLine("Disposing SteamWorks NativeInterface failed (" + e.Message + ")\n" + e.StackTrace);
                }
                native = null;
            }

            System.Environment.SetEnvironmentVariable("SteamAppId", null);
            System.Environment.SetEnvironmentVariable("SteamGameId", null);
            disposed = true;
        }
示例#6
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();
        }
示例#7
0
        public Client(uint appId)
        {
            native = new Interop.NativeInterface();

            //
            // Get other interfaces
            //
            if (!native.InitClient(this))
            {
                native.Dispose();
                native = null;
                return;
            }

            //
            // Set up warning hook callback
            //
            // SteamAPIWarningMessageHook ptr = InternalOnWarning;
            // native.client.SetWarningMessageHook( Marshal.GetFunctionPointerForDelegate( ptr ) );

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

            //
            // Client only interfaces
            //
            Voice = new Voice(this);

            Workshop.friends = Friends;


            //
            // Cache common, unchanging info
            //
            AppId    = appId;
            Username = native.friends.GetPersonaName();
            SteamId  = native.user.GetSteamID();
            BetaName = native.apps.GetCurrentBetaName();

            //
            // Run update, first call does some initialization
            //
            Update();
        }
示例#8
0
        public Client(uint appId)
        {
            native = new Interop.NativeInterface();

            //
            // Get other interfaces
            //
            if (!native.InitClient(this))
            {
                native.Dispose();
                native = null;
                return;
            }

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

            //
            // Client only interfaces
            //
            Voice      = new Voice(this);
            ServerList = new ServerList(this);
            App        = new App(this);

            Workshop.friends = Friends;


            //
            // Cache common, unchanging info
            //
            AppId         = appId;
            Username      = native.friends.GetPersonaName();
            SteamId       = native.user.GetSteamID();
            BetaName      = native.apps.GetCurrentBetaName();
            OwnerSteamId  = native.apps.GetAppOwner();
            InstallFolder = new DirectoryInfo(native.apps.GetAppInstallDir(AppId));
            BuildId       = native.apps.GetAppBuildId();

            //
            // Run update, first call does some initialization
            //
            Update();
        }
示例#9
0
        public Server(uint appId, uint IpAddress, ushort GamePort, ushort QueryPort, bool Secure, string VersionString)
        {
            native = new Interop.NativeInterface();

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

            //
            // Set up warning hook callback
            //
            //  SteamAPIWarningMessageHook ptr = InternalOnWarning;
            //  var d = Marshal.GetFunctionPointerForDelegate( ptr );
            //   var rr = GCHandle.Alloc( d );
            // native.utils.SetWarningMessageHook( d );

            //
            // 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";

            //
            // Run update, first call does some initialization
            //
            Update();
        }
示例#10
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();
        }
示例#11
0
        public Client(uint appId) : base(appId)
        {
            if (Instance != null)
            {
                throw new System.Exception("Only one Facepunch.Steamworks.Client can exist - dispose the old one before trying to create a new one.");
            }

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

            //
            // Get other interfaces
            //
            if (!native.InitClient(this))
            {
                native.Dispose();
                native   = null;
                Instance = null;
                return;
            }

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

            //
            // Register Callbacks
            //

            SteamNative.Callbacks.RegisterCallbacks(this);

            //
            // Client only interfaces
            //
            Voice             = new Voice(this);
            ServerList        = new ServerList(this);
            LobbyList         = new LobbyList(this);
            App               = new App(this);
            Stats             = new Stats(this);
            Achievements      = new Achievements(this);
            MicroTransactions = new MicroTransactions(this);
            User              = new User(this);
            RemoteStorage     = new RemoteStorage(this);

            Workshop.friends = Friends;

            Stats.UpdateStats();

            //
            // Cache common, unchanging info
            //
            AppId        = appId;
            Username     = native.friends.GetPersonaName();
            SteamId      = native.user.GetSteamID();
            BetaName     = native.apps.GetCurrentBetaName();
            OwnerSteamId = native.apps.GetAppOwner();
            var appInstallDir = native.apps.GetAppInstallDir(AppId);

            if (!String.IsNullOrEmpty(appInstallDir) && Directory.Exists(appInstallDir))
            {
                InstallFolder = new DirectoryInfo(appInstallDir);
            }
            BuildId            = native.apps.GetAppBuildId();
            CurrentLanguage    = native.apps.GetCurrentGameLanguage();
            AvailableLanguages = native.apps.GetAvailableGameLanguages().Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); // TODO: Assumed colon separated

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