Пример #1
0
        /// <summary>
        /// Sends commands to Quake Live to verify that a server connection exists.
        /// </summary>
        public async Task CheckQlServerConnectionExists()
        {
            QlCommands.ClearQlWinConsole();
            await QlCommands.CheckMainMenuStatus();

            await QlCommands.CheckCmdStatus();

            QlCommands.QlCmdClear();
        }
Пример #2
0
        /// <summary>
        /// Performs the delayed initialization steps.
        /// </summary>
        /// <param name="secondsToWait">The number of seconds the timer should wait before executing.</param>
        private void PerformDelayedInitTasks(double secondsToWait)
        {
            _delayedInitTaskTimer = new Timer(secondsToWait * 1000)
            {
                AutoReset = false, Enabled = true
            };

            // Finalize the delayed initilization tasks
            _delayedInitTaskTimer.Elapsed += async(sender, args) =>
            {
                Log.Write("Performing delayed initilization tasks.", _logClassType, _logPrefix);

                QlCommands.ClearQlWinConsole();

                // Initiate modules such as MOTD and others that can't be started until after we're live
                Mod.Motd.Init();

                // Get IP
                CheckServerAddress();

                // Send configstrings request in order to get an accurate listing of the teams.
                // Strangely, this appears to not register w/ QL at various times, so send it a few
                // different times.
                for (var i = 1; i < 4; i++)
                {
                    await QlCommands.SendToQlDelayedAsync("configstrings", true, (i * 3));
                }

                // Update UI status bar with IP
                await Task.Delay(2000);

                UserInterface.UpdateMonitoringStatusUi(true, ServerInfo.CurrentServerAddress);
                QlCommands.QlCmdClear();

                // Done
                QlCommands.ClearBothQlConsoles();
                QlCommands.SendToQl("echo ^4***^5SST is now ^2LOADED^4***", false);
                QlCommands.SendToQl("print ^4***^5SST is now ^2LOADED^4***", false);
                Log.Write("SST is now loaded on the server.", _logClassType, _logPrefix);
                IsInitComplete                = true;
                MonitoringStartedTime         = DateTime.Now;
                _delayedInitTaskTimer.Enabled = false;
                _delayedInitTaskTimer         = null;
            };
        }
Пример #3
0
        /// <summary>
        /// Gets the server information.
        /// </summary>
        private void GetServerInformation()
        {
            // First and foremost, clear the console and get the player listing.
            QlCommands.ClearQlWinConsole();
            // Re-focus the window
            Win32Api.SwitchToThisWindow(QlWindowUtils.QlWindowHandle, true);
            // Disable developer mode if it's already set, so we can get accurate player listing.
            QlCommands.DisableDeveloperMode();
            // Initially get the player listing when we start. Synchronous since initilization.
            // ReSharper disable once UnusedVariable
            var q = QlCommands.QlCmdPlayers();

            // Get the server's id
            QlCommands.SendToQl("serverinfo", true);
            // Enable developer mode
            QlCommands.EnableDeveloperMode();
            // Delay some initilization tasks and complete initilization
            PerformDelayedInitTasks(InitDelay);

            Log.Write("Requesting server information.", _logClassType, _logPrefix);
        }
Пример #4
0
        /// <summary>
        /// Reads the QL console window.
        /// </summary>
        private void ReadQlConsole()
        {
            var consoleWindow = QlWindowUtils.GetQuakeLiveConsoleWindow();
            var cText         = QlWindowUtils.GetQuakeLiveConsoleTextArea(consoleWindow,
                                                                          QlWindowUtils.GetQuakeLiveConsoleInputArea(consoleWindow));

            if (cText != IntPtr.Zero)
            {
                while (IsReadingConsole)
                {
                    var textLength = Win32Api.SendMessage(cText, Win32Api.WM_GETTEXTLENGTH, IntPtr.Zero,
                                                          IntPtr.Zero);
                    if ((textLength == 0) || (ConsoleTextProcessor.OldWholeConsoleLineLength == textLength))
                    {
                        continue;
                    }

                    // Entire console window text
                    var entireBuffer = new StringBuilder(textLength + 1);
                    Win32Api.SendMessage(cText, Win32Api.WM_GETTEXT, new IntPtr(textLength + 1), entireBuffer);
                    var received = entireBuffer.ToString();
                    ConsoleTextProcessor.ProcessEntireConsoleText(received, textLength);

                    var lengthDifference = Math.Abs(textLength - _oldLength);

                    if (received.Length > lengthDifference)
                    {
                        // Bounds checking
                        int start;
                        int length;

                        if (_oldLength > received.Length)
                        {
                            start  = 0;
                            length = received.Length;
                        }
                        else
                        {
                            start  = _oldLength;
                            length = lengthDifference;
                        }

                        // Standardize QL's annoying string formatting
                        var diffBuilder = new StringBuilder(received.Substring(start, length));
                        diffBuilder.Replace("\"\r\n\r\n", "\"\r\n");
                        diffBuilder.Replace("\r\n\"\r\n", "\r\n");
                        diffBuilder.Replace("\r\n\r\n", "\r\n");
                        ConsoleTextProcessor.ProcessShortConsoleLines(diffBuilder.ToString());
                    }

                    // Detect when buffer is about to be full, in order to auto-clear. Win Edit
                    // controls can have a max of 30,000 characters, see: "Limits of Edit Controls"
                    // - http://msdn.microsoft.com/en-us/library/ms997530.aspx More info: Q3 source
                    // (win_syscon.c), Conbuf_AppendText
                    int begin, end;
                    Win32Api.SendMessage(cText, Win32Api.EM_GETSEL, out begin, out end);
                    if ((begin >= 29300) && (end >= 29300))
                    {
                        Log.Write("Clearing nearly full conbuf.",
                                  _logClassType, _logPrefix);

                        // Auto-clear
                        QlCommands.ClearQlWinConsole();
                    }
                    _oldLength = textLength;
                }
            }
            else
            {
                Log.WriteCritical("Unable to get necessary console handle.", _logClassType, _logPrefix);
            }
        }