Пример #1
0
        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();
        }
Пример #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();
        }
Пример #3
0
        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();
        }
Пример #4
0
 internal static async void RunCallbacksAsync()
 {
     while (SteamServer.IsValid)
     {
         SteamServer.RunCallbacks();
         await Task.Delay(16);
     }
 }
Пример #5
0
 public static void Shutdown()
 {
     Event.DisposeAllServer();
     SteamServer.initialized = false;
     SteamServer._internal   = null;
     SteamServer.ShutdownInterfaces();
     SteamNetworkingUtils.Shutdown();
     SteamNetworkingSockets.Shutdown();
     SteamInventory.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 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();
            SteamServer.WatchInterface(this);
        }
Пример #8
0
        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();
        }
        public async Task BeginAuthSession()
        {
            var          stopwatch = System.Diagnostics.Stopwatch.StartNew();
            bool         finished  = false;
            string       failed    = null;
            AuthResponse response  = AuthResponse.AuthTicketInvalidAlreadyUsed;

            //
            // Clientside calls this function, gets ticket
            //
            var clientTicket = SteamUser.GetAuthSessionTicket();

            //
            // The client sends this data to the server along with their steamid
            //
            var ticketData    = clientTicket.Data;
            var clientSteamId = SteamClient.SteamId;

            //
            // Server listens to auth responses from Gabe
            //
            SteamServer.OnValidateAuthTicketResponse += (steamid, ownerid, rsponse) =>
            {
                finished = true;
                response = rsponse;

                if (steamid == 0)
                {
                    failed = $"steamid is 0! {steamid} != {ownerid} ({rsponse})";
                }

                if (ownerid == 0)
                {
                    failed = $"ownerid is 0! {steamid} != {ownerid} ({rsponse})";
                }

                if (steamid != ownerid)
                {
                    failed = $"Steamid and Ownerid are different! {steamid} != {ownerid} ({rsponse})";
                }
            };

            //
            // Server gets the ticket, starts authing
            //
            if (!SteamServer.BeginAuthSession(ticketData, clientSteamId))
            {
                Assert.Fail("BeginAuthSession returned false, called bullshit without even having to check with Gabe");
            }

            //
            // Wait for that to go through steam
            //
            while (!finished)
            {
                if (stopwatch.Elapsed.TotalSeconds > 5)
                {
                    throw new System.Exception("Took too long waiting for AuthSessionResponse.OK");
                }

                await Task.Delay(10);
            }

            Assert.AreEqual(response, AuthResponse.OK);

            if (failed != null)
            {
                Assert.Fail(failed);
            }

            finished  = false;
            stopwatch = System.Diagnostics.Stopwatch.StartNew();

            //
            // The client is leaving, and now wants to cancel the ticket
            //

            Assert.AreNotEqual(0, clientTicket.Handle);
            clientTicket.Cancel();

            //
            // We should get another callback
            //
            while (!finished)
            {
                if (stopwatch.Elapsed.TotalSeconds > 5)
                {
                    throw new System.Exception("Took too long waiting for AuthSessionResponse.AuthTicketCanceled");
                }

                await Task.Delay(10);
            }

            if (failed != null)
            {
                Assert.Fail(failed);
            }

            //Assert.AreEqual( response, AuthResponse.AuthTicketCanceled );
        }
Пример #10
0
 public static void LogOnAnonymous()
 {
     SteamServer.Internal.LogOnAnonymous();
     SteamServer.ForceHeartbeat();
 }