예제 #1
0
 private void Awake()
 {
     _instance = this;
     m_backend = new ConsoleBackend(consoleOptions.LogHandler, consoleOptions);
     m_gui     = new ConsoleGui(m_backend, consoleOptions);
     ConsoleGui.OnStateChanged += x => OnStateChanged(x);
 }
예제 #2
0
        private void Awake()
        {
            if (!_instance)
            {
                _instance = this;
            }
            else
            {
                Destroy(this.gameObject);
            }

            DontDestroyOnLoad(this.gameObject);
            var evsys = GameObject.FindObjectOfType <EventSystem>();

            if (!evsys)
            {
                Debug.LogError("UnityEvent System not found in scene, manually add it.");
                Debug.Break();
            }
            DestroyChildren(transform);
            GameObject prefab = Resources.Load <GameObject>("BeastConsole/ConsoleGui");

            m_consoleRoot = GameObject.Instantiate(prefab);
            m_consoleRoot.transform.SetParent(transform);

            m_backend = new ConsoleBackend();
            ConsoleGui gui = m_consoleRoot.GetComponentInChildren <ConsoleGui>();

            gui.Initialize(m_backend, consoleOptions);
        }
예제 #3
0
        /// <summary>
        ///		Call this when the server is started
        /// </summary>
        internal static void OnStartServer(TCNetworkManager workingNetManager)
        {
            serverOnlineFilePath = $"{Game.GetGameExecutePath()}/{ServerOnlineFile}";

            if (File.Exists(serverOnlineFilePath))
            {
                throw new Exception("Server is already online!");
            }

            netManager = workingNetManager;

            Logger.Info("Starting server...");

            //Set what network address to use and start to advertise the server on lan
            netManager.networkAddress = NetHelper.LocalIpAddress();
            netManager.gameDiscovery.AdvertiseServer();

            //Start ping service
            PingManager.ServerSetup();

            //Run the server autoexec config
            ConsoleBackend.ExecuteFile("server-autoexec");

            SetupServerConfig();

            //Create server online file
            try
            {
                serverOnlineFileStream = File.Create(serverOnlineFilePath, 128, FileOptions.DeleteOnClose);
                serverOnlineFileStream.Write(ServerOnlineFileMessage, 0, ServerOnlineFileMessage.Length);
                serverOnlineFileStream.Flush();
                File.SetAttributes(serverOnlineFilePath, FileAttributes.Hidden);
            }
            catch (IOException ex)
            {
                Logger.Error(ex, "An error occurred while setting up the server!");
                netManager.StopHost();

                return;
            }

            Logger.Info("Server has started and is running on '{Address}' with max connections of {MaxPlayers}!",
                        netManager.networkAddress, netManager.maxConnections);
        }
예제 #4
0
        public static void ConsoleConVarListToMarkdown()
        {
            Dictionary <ConVar, FieldInfo> conVars = ConsoleBackend.GetConVars();

            if (conVars == null)
            {
                Debug.LogError("Console system doesn't have any commands! Either its not active or something went wrong.");
                return;
            }

            MarkdownTableGenerator generator = new MarkdownTableGenerator("ConVar List", "Command", "Summary", "Graphics Only");

            foreach (ConVar command in conVars.Keys)
            {
                generator.AddOption($"`{command.Name}`", command.Summary, command.GraphicsOnly ? "✔" : "❌");
            }

            generator.SaveMarkdown("convar-list");
        }
예제 #5
0
        internal ConsoleGui(ConsoleBackend backend, Options options)
        {
            skin = options.skin;

            greycolorstr          = ConsoleUtility.ToHex(options.colors.suggestionGreyed);
            suggestionStyle       = skin.customStyles.Where(x => x.name == "suggestion").FirstOrDefault();
            suggestionActiveStyle = skin.customStyles.Where(x => x.name == "suggestionActive").FirstOrDefault();
            img_box   = skin.customStyles.Where(x => x.name == "img_box").FirstOrDefault().normal.background;
            m_backend = backend;
            m_options = options;

            m_backend.OnWriteLine += OnWriteLine;
            SetSize(PlayerPrefs.GetInt("beastconsole.size"));
            console_currentPosition = ClosedPosition;
            console_targetPosition  = ClosedPosition;


            m_backend.RegisterVariable <int>(SetSize, this, "console.size", "Set the size of the console, 1/2/3");
            m_backend.RegisterCommand("clr", "clear the console log", this, Clear);
        }
예제 #6
0
        internal void Initialize(ConsoleBackend backend, Options options)
        {
            if (!gameObject.activeSelf)
            {
                return;
            }

            m_eventSystem           = GameObject.FindObjectOfType <EventSystem>();
            this.m_backend          = backend;
            this.m_options          = options;
            m_consoleRoot.anchorMin = new Vector2(0f, 0.65f);
            m_consoleRoot.anchorMax = new Vector2(1f, 1f);
            m_posTarget             = new Vector2(0, 10000);
            m_inputField.onValueChanged.AddListener(DrawAutoCompleteSuggestions);
            m_inputField.onEndEdit.AddListener(HandleInput);
            m_backend.OnWriteLine       += OnWriteLine;
            m_backend.OnExecutedCommand += OnExecutedLine;
            m_backend.RegisterCommand("clear", "clear the console log", this, Clear);
            Console.DestroyChildren(m_consoleContent.transform);
            m_historyRoot.gameObject.SetActive(false);
            m_beastConsoleHelp = m_beastConsoleHelp;

            Console.AddVariable <bool>("console.showHelp", "Shows the info box in the console", x => m_beastConsoleHelp = x, this);
        }
예제 #7
0
 internal Command(string name, string description, ConsoleBackend backend)
 {
     m_name        = name;
     m_description = description;
     m_backend     = backend;
 }
 public AttributeCommand(string name, string description, ConsoleBackend backend) : base(name, description, backend)
 {
 }
예제 #9
0
 internal Variable(string name, string desc, Action <T> setter, object owner, ConsoleBackend backend) : base(name, desc, backend)
 {
     Add(owner, setter);
 }
예제 #10
0
 public PropertyCommand(string name, string description, ConsoleBackend backend) : base(name, description, backend)
 {
 }
예제 #11
0
 public FieldCommand(string name, string description, ConsoleBackend backend) : base(name, description, backend)
 {
 }
예제 #12
0
        /// <summary>
        ///     Call this when the server is started
        /// </summary>
        internal static void OnStartServer(TCNetworkManager workingNetManager)
        {
            serverOnlineFilePath = $"{Game.GetGameExecutePath()}/{ServerOnlineFile}";

            if (File.Exists(serverOnlineFilePath))
            {
                throw new Exception("Server is already online!");
            }

            netManager = workingNetManager;

            Logger.Info("Starting server...");

            //Get the online scene
            TCScene onlineScene = TCScenesManager.FindSceneInfo(Scene);

            if (onlineScene == null)
            {
                Logger.Error($"Failed to find scene {Scene}!");
                throw new FileNotFoundException($"Scene {Scene} not found!");
            }

            //Setup the server's config
            SetupServerConfig();
            Application.targetFrameRate = netManager.serverTickRate;

            //Make some adjustments to scenes config if we are running headless
            if (Game.IsHeadless)
            {
                netManager.offlineScene = null;
                netManager.onlineScene  = onlineScene.scene;
                TCScenesManager.LoadScene(onlineScene);
            }

            //Set what network address to use and start to advertise the server on lan
            netManager.networkAddress = NetHelper.LocalIpAddress();
            netManager.gameDiscovery.AdvertiseServer();

            //Setup ping related stuff
            PingManager.ServerSetup();
            LagCompensationManager.ServerSetup();

            //Run the server autoexec config
            ConsoleBackend.ExecuteFile("server-autoexec");

            //Server chat
            NetworkServer.RegisterHandler <ChatMessage>(ServerChat.ReceivedChatMessage);

            //Create server online file
            try
            {
                serverOnlineFileStream = File.Create(serverOnlineFilePath, 128, FileOptions.DeleteOnClose);
                serverOnlineFileStream.Write(ServerOnlineFileMessage, 0, ServerOnlineFileMessage.Length);
                serverOnlineFileStream.Flush();
                File.SetAttributes(serverOnlineFilePath, FileAttributes.Hidden);
            }
            catch (IOException ex)
            {
                Logger.Error(ex, "An error occurred while setting up the server!");
                netManager.StopHost();

                return;
            }

            Logger.Info("Server has started and is running on '{Address}' with max connections of {MaxPlayers}!",
                        netManager.networkAddress, netManager.maxConnections);
        }