コード例 #1
0
        public static bool CreateServer(Networking.GameServer server, bool isPublic)
        {
            Instance.isInitialized = true;

            ServerInit options = new ServerInit("Barotrauma", "Barotrauma")
            {
                GamePort  = (ushort)server.Port,
                QueryPort = (ushort)server.QueryPort
            };

            //options.QueryShareGamePort();

            instance.server = new Server(AppID, options, isPublic);
            if (!instance.server.IsValid)
            {
                instance.server.Dispose();
                instance.server = null;
                DebugConsole.ThrowError("Initializing Steam server failed.");
                return(false);
            }

            RefreshServerDetails(server);

            instance.server.Auth.OnAuthChange = server.OnAuthChange;
            Instance.server.LogOnAnonymous();

            return(true);
        }
コード例 #2
0
        public static bool RefreshServerDetails(Networking.GameServer server)
        {
            if (instance?.server == null || !instance.isInitialized)
            {
                return(false);
            }

            // These server state variables may be changed at any time.  Note that there is no longer a mechanism
            // to send the player count.  The player count is maintained by steam and you should use the player
            // creation/authentication functions to maintain your player count.
            instance.server.ServerName = server.Name;
            instance.server.MaxPlayers = server.ServerSettings.MaxPlayers;
            instance.server.Passworded = server.ServerSettings.HasPassword;
            instance.server.MapName    = GameMain.NetLobbyScreen?.SelectedSub?.DisplayName ?? "";
            Instance.server.SetKey("message", GameMain.Server.ServerSettings.ServerMessageText);
            Instance.server.SetKey("version", GameMain.Version.ToString());
            Instance.server.SetKey("contentpackage", string.Join(",", GameMain.Config.SelectedContentPackages.Select(cp => cp.Name)));
            Instance.server.SetKey("contentpackagehash", string.Join(",", GameMain.Config.SelectedContentPackages.Select(cp => cp.MD5hash.Hash)));
            Instance.server.SetKey("contentpackageurl", string.Join(",", GameMain.Config.SelectedContentPackages.Select(cp => cp.SteamWorkshopUrl ?? "")));
            Instance.server.SetKey("usingwhitelist", (server.ServerSettings.Whitelist != null && server.ServerSettings.Whitelist.Enabled).ToString());
            Instance.server.SetKey("modeselectionmode", server.ServerSettings.ModeSelectionMode.ToString());
            Instance.server.SetKey("subselectionmode", server.ServerSettings.SubSelectionMode.ToString());
            Instance.server.SetKey("voicechatenabled", server.ServerSettings.VoiceChatEnabled.ToString());
            Instance.server.SetKey("allowspectating", server.ServerSettings.AllowSpectating.ToString());
            Instance.server.SetKey("allowrespawn", server.ServerSettings.AllowRespawn.ToString());
            Instance.server.SetKey("traitors", server.ServerSettings.TraitorsEnabled.ToString());
            Instance.server.SetKey("gamestarted", server.GameStarted.ToString());
            Instance.server.SetKey("gamemode", server.ServerSettings.GameModeIdentifier);

            instance.server.DedicatedServer = true;

            return(true);
        }
コード例 #3
0
        public static bool RefreshServerDetails(Networking.GameServer server)
        {
            if (!isInitialized || !Steamworks.SteamServer.IsValid)
            {
                return(false);
            }

            var contentPackages = GameMain.Config.AllEnabledPackages.Where(cp => cp.HasMultiplayerIncompatibleContent);

            // These server state variables may be changed at any time.  Note that there is no longer a mechanism
            // to send the player count.  The player count is maintained by steam and you should use the player
            // creation/authentication functions to maintain your player count.
            Steamworks.SteamServer.ServerName = server.ServerName;
            Steamworks.SteamServer.MaxPlayers = server.ServerSettings.MaxPlayers;
            Steamworks.SteamServer.Passworded = server.ServerSettings.HasPassword;
            Steamworks.SteamServer.MapName    = GameMain.NetLobbyScreen?.SelectedSub?.DisplayName ?? "";
            Steamworks.SteamServer.SetKey("haspassword", server.ServerSettings.HasPassword.ToString());
            Steamworks.SteamServer.SetKey("message", GameMain.Server.ServerSettings.ServerMessageText);
            Steamworks.SteamServer.SetKey("version", GameMain.Version.ToString());
            //Steamworks.SteamServer.SetKey("playercount", GameMain.Server.ConnectedClients.Count.ToString());
            if (GameMain.Server.ConnectedClients.Count == 0)
            {
                Steamworks.SteamServer.SetKey("playercount", GameMain.Server.ConnectedClients.Count.ToString());
            }
            else
            {
                Steamworks.SteamServer.SetKey("playercount", (GameMain.Server.ConnectedClients.Count + 2).ToString());
            }

            Steamworks.SteamServer.SetKey("contentpackage", string.Join(",", contentPackages.Select(cp => cp.Name)));
            Steamworks.SteamServer.SetKey("contentpackagehash", string.Join(",", contentPackages.Select(cp => cp.MD5hash.Hash)));
            Steamworks.SteamServer.SetKey("contentpackageid", string.Join(",", contentPackages.Select(cp => cp.SteamWorkshopId)));
            Steamworks.SteamServer.SetKey("usingwhitelist", (server.ServerSettings.Whitelist != null && server.ServerSettings.Whitelist.Enabled).ToString());
            Steamworks.SteamServer.SetKey("modeselectionmode", server.ServerSettings.ModeSelectionMode.ToString());
            Steamworks.SteamServer.SetKey("subselectionmode", server.ServerSettings.SubSelectionMode.ToString());
            Steamworks.SteamServer.SetKey("voicechatenabled", server.ServerSettings.VoiceChatEnabled.ToString());
            Steamworks.SteamServer.SetKey("allowspectating", server.ServerSettings.AllowSpectating.ToString());
            Steamworks.SteamServer.SetKey("allowrespawn", server.ServerSettings.AllowRespawn.ToString());
            Steamworks.SteamServer.SetKey("traitors", server.ServerSettings.TraitorsEnabled.ToString());
            Steamworks.SteamServer.SetKey("gamestarted", server.GameStarted.ToString());
            Steamworks.SteamServer.SetKey("gamemode", server.ServerSettings.GameModeIdentifier);
            Steamworks.SteamServer.SetKey("playstyle", server.ServerSettings.PlayStyle.ToString());

            Steamworks.SteamServer.DedicatedServer = true;

            return(true);
        }