public static void Shutdown()
        {
            Dispatch.ShutdownServer();

            ShutdownInterfaces();
            SteamGameServer.Shutdown();
        }
        public static void Shutdown()
        {
            Internal = null;

            ShutdownInterfaces();
            SteamGameServer.Shutdown();
        }
 public static void Shutdown()
 {
     Event.DisposeAllServer();
     SteamServer.initialized = false;
     SteamServer._internal   = null;
     SteamServer.ShutdownInterfaces();
     SteamNetworkingUtils.Shutdown();
     SteamNetworkingSockets.Shutdown();
     SteamInventory.Shutdown();
     SteamGameServer.Shutdown();
 }
Beispiel #4
0
 public static void Update()
 {
     try
     {
         SteamGameServer.RunCallbacks();
     }
     catch (System.Exception)
     {
         // TODO - error outputs
     }
 }
Beispiel #5
0
 /// <summary>
 /// Run the callbacks. This is also called in Async callbacks.
 /// </summary>
 public static void RunCallbacks()
 {
     try
     {
         SteamGameServer.RunCallbacks();
     }
     catch (System.Exception e)
     {
         OnCallbackException?.Invoke(e);
     }
 }
        public static void Shutdown()
        {
            Event.DisposeAllServer();

            initialized = false;

            _internal = null;

            SteamServerInventory.Shutdown();

            SteamGameServer.Shutdown();
        }
        public void InitServer()
        {
            HSteamUser hSteamUser = SteamGameServer.GetHSteamUser();

            this.Self = SteamInternal.FindOrCreateGameServerInterface(hSteamUser, this.InterfaceName);
            if (this.Self == IntPtr.Zero)
            {
                throw new Exception(String.Concat("Couldn't find server interface ", this.InterfaceName));
            }
            this.VTable = Marshal.ReadIntPtr(this.Self, 0);
            if (this.Self == IntPtr.Zero)
            {
                throw new Exception(String.Concat("Invalid VTable for server ", this.InterfaceName));
            }
            this.InitInternals();
            SteamServer.WatchInterface(this);
        }
 public static void RunCallbacks()
 {
     try
     {
         SteamGameServer.RunCallbacks();
     }
     catch (Exception exception1)
     {
         Exception          exception           = exception1;
         Action <Exception> onCallbackException = SteamServer.OnCallbackException;
         if (onCallbackException != null)
         {
             onCallbackException(exception);
         }
         else
         {
         }
     }
 }
        public virtual void InitServer()
        {
            var user = SteamGameServer.GetHSteamUser();

            Self = SteamInternal.FindOrCreateGameServerInterface(user, InterfaceName);

            if (Self == IntPtr.Zero)
            {
                throw new System.Exception($"Couldn't find server interface {InterfaceName}");
            }

            VTable = Marshal.ReadIntPtr(Self, 0);
            if (Self == IntPtr.Zero)
            {
                throw new System.Exception($"Invalid VTable for server {InterfaceName}");
            }

            InitInternals();
        }
Beispiel #10
0
        public SteamInterface(bool server = false)
        {
            //
            // If teh client isn't initialized but the server is,
            // try to open this interface in server mode
            //
            if (!SteamClient.IsValid && SteamServer.IsValid)
            {
                server = true;
            }

            var hUser = server ?
                        SteamGameServer.GetHSteamUser() :
                        SteamAPI.GetHSteamUser();

            if (hUser == 0)
            {
                throw new System.Exception("Steamworks is uninitialized");
            }

            Self = server ?
                   SteamInternal.FindOrCreateGameServerInterface(hUser, InterfaceName) :
                   SteamInternal.FindOrCreateUserInterface(hUser, InterfaceName);

            if (Self == IntPtr.Zero)
            {
                throw new System.Exception($"Couldn't find interface {InterfaceName} (server:{server})");
            }


            VTable = Marshal.ReadIntPtr(Self, 0);
            if (Self == IntPtr.Zero)
            {
                throw new System.Exception($"Invalid VTable for {InterfaceName}");
            }

            InitInternals();
        }
        /// <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();
            }
        }
 /// <summary>
 /// Run the callbacks. This is also called in Async callbacks.
 /// </summary>
 public static void RunCallbacks()
 {
     SteamGameServer.RunCallbacks();
 }