Esempio n. 1
0
        public static void Start()
        {
            // Initialize the screen
            Crt.ClrScr();
            StatusText(Helpers.Copyright, false);

            // Check if running as root
            if (Helpers.StartedAsRoot)
            {
                StatusText("", false);
                StatusText("*** WARNING: Running GameSrv as root is NOT recommended ***", false);
                StatusText("", false);
                StatusText("A safer alternative to running GameSrv as root is to run it via 'privbind'", false);
                StatusText("This will ensure GameSrv is able to bind to ports in the < 1024 range, but", false);
                StatusText("it will run as a regular unprivileged program in every other way", false);
                StatusText("", false);
                StatusText("See start.sh for an example of the recommended method to start GameSrv", false);
                StatusText("", false);
            }

            // Setup log handler
            RMLog.Handler += RMLog_Handler;

            // Init GameSrv
            _GameSrv = new GameSrv();
            _GameSrv.Start();

            // Main program loop
            bool Quit = false;

            while (!Quit)
            {
                char Ch = Crt.ReadKey();
                switch (Ch.ToString().ToUpper())
                {
                case "\0":
                    char Ch2 = Crt.ReadKey();
                    if (Ch2 == ';')     // F1
                    {
                        StatusText("", false);
                        StatusText("GameSrv WFC Screen Help", false);
                        StatusText("-=-=-=-=-=-=-=-=-=-=-=-", false);
                        StatusText("F1 = Help  (this screen)", false);
                        StatusText("C  = Clear (clear the status window)", false);
                        StatusText("P  = Pause (reject new connections, leave existing connections alone)", false);
                        StatusText("S  = Setup (launch the config program)", false);
                        StatusText("Q  = Quit  (shut down and terminate existing connections)", false);
                        StatusText("", false);
                    }
                    break;

                case "C":
                    Crt.ClrScr();
                    break;

                case "P":
                    _GameSrv.Pause();
                    break;

                case "S":
                    Process.Start(StringUtils.PathCombine(ProcessUtils.StartupPath, "GameSrvConfig.exe"));
                    break;

                case "Q":
                    // Check if we're already stopped (or are stopping)
                    if ((_GameSrv.Status != GameSrvStatus.Stopped) && (_GameSrv.Status != GameSrvStatus.Stopping))
                    {
                        int ConnectionCount = NodeManager.ConnectionCount;
                        if (ConnectionCount > 0)
                        {
                            StatusText("", false);
                            StatusText("There are " + ConnectionCount.ToString() + " active connections.", false);
                            StatusText("Are you sure you want to quit [y/N]: ", false);
                            Ch = Crt.ReadKey();
                            if (Ch.ToString().ToUpper() != "Y")
                            {
                                StatusText("", false);
                                StatusText("Cancelling quit request.", false);
                                StatusText("", false);
                                continue;
                            }
                        }
                    }

                    _GameSrv.Stop();
                    _GameSrv.Dispose();
                    Quit = true;
                    break;
                }
            }

            Environment.Exit(0);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            // Check command-line parameters
            foreach (string Arg in args)
            {
                switch (Arg.ToLower())
                {
                case "24h":
                    _TimeFormatFooter = "HH:mm";
                    break;

                case "simple":
                    _FancyOutput = false;
                    break;
                }
            }

            // Remove old "stop requested" file
            if (File.Exists(StringUtils.PathCombine(ProcessUtils.StartupPath, "gamesrvconsole.stop")))
            {
                FileUtils.FileDelete(StringUtils.PathCombine(ProcessUtils.StartupPath, "gamesrvconsole.stop"));
            }

            // Add connection types to counter
            _ConnectionCounts[ConnectionType.RLogin]    = 0;
            _ConnectionCounts[ConnectionType.Telnet]    = 0;
            _ConnectionCounts[ConnectionType.WebSocket] = 0;

            // Initialize the screen
            InitConsole();
            Write(Globals.Copyright, false);

            // Check if running as root
            if (Globals.StartedAsRoot)
            {
                WriteLn("", false);
                WriteLn("*** WARNING: Running GameSrv as root is NOT recommended ***", false);
                WriteLn("", false);
                WriteLn("A safer alternative to running GameSrv as root is to run it via 'privbind'", false);
                WriteLn("This will ensure GameSrv is able to bind to ports in the < 1024 range, but", false);
                WriteLn("it will run as a regular unprivileged program in every other way", false);
                WriteLn("", false);
                WriteLn("See start.sh for an example of the recommended method to start GameSrv", false);
                WriteLn("", false);
            }

            // Init GameSrv
            _GameSrv = new GameSrv();
            _GameSrv.AggregatedStatusMessageEvent += new EventHandler <StringEventArgs>(GameSrv_AggregatedStatusMessageEvent);
            _GameSrv.LogOnEvent += new EventHandler <NodeEventArgs>(GameSrv_LogOnEvent);
            _GameSrv.Start();

            // Main program loop
            int  LastMinute = -1;
            int  LastSecond = -1;
            bool Quit       = false;

            while (!Quit)
            {
                while (!Crt.KeyPressed())
                {
                    Crt.Delay(100);
                    if (DateTime.Now.Minute != LastMinute)
                    {
                        UpdateTime();
                        LastMinute = DateTime.Now.Minute;
                    }

                    if ((DateTime.Now.Second % 2 == 0) && (DateTime.Now.Second != LastSecond))
                    {
                        LastSecond = DateTime.Now.Second;
                        if (File.Exists(StringUtils.PathCombine(ProcessUtils.StartupPath, "gamesrvconsole.stop")))
                        {
                            FileUtils.FileDelete(StringUtils.PathCombine(ProcessUtils.StartupPath, "gamesrvconsole.stop"));

                            _GameSrv.Stop();
                            _GameSrv.Dispose();
                            Quit = true;
                            break;
                        }
                    }
                }

                if (Crt.KeyPressed())
                {
                    char Ch = Crt.ReadKey();
                    switch (Ch.ToString().ToUpper())
                    {
                    case "\0":
                        char Ch2 = Crt.ReadKey();
                        if (Ch2 == ';')     // F1
                        {
                            WriteLn("", false);
                            WriteLn("GameSrv WFC Screen Help", false);
                            WriteLn("-=-=-=-=-=-=-=-=-=-=-=-", false);
                            WriteLn("F1 = Help  (this screen)", false);
                            WriteLn("C  = Clear (clear the status window)", false);
                            WriteLn("P  = Pause (reject new connections, leave existing connections alone)", false);
                            WriteLn("S  = Setup (launch the config program)", false);
                            WriteLn("Q  = Quit  (shut down and terminate existing connections)", false);
                            WriteLn("", false);
                        }
                        break;

                    case "C":
                        Crt.ClrScr();
                        if (_FancyOutput)
                        {
                            Crt.GotoXY(1, 32);
                        }
                        break;

                    case "P":
                        _GameSrv.Pause();
                        break;

                    case "S":
                        Process.Start(StringUtils.PathCombine(ProcessUtils.StartupPath, "GameSrvConfig.exe"));
                        break;

                    case "Q":
                        // Check if we're already stopped (or are stopping)
                        if ((_GameSrv.Status != ServerStatus.Stopped) && (_GameSrv.Status != ServerStatus.Stopping))
                        {
                            int ConnectionCount = _GameSrv.ConnectionCount;
                            if (ConnectionCount > 0)
                            {
                                WriteLn("", false);
                                WriteLn("There are " + ConnectionCount.ToString() + " active connections.", false);
                                WriteLn("Are you sure you want to quit [y/N]: ", false);
                                WriteLn("", false);
                                Ch = Crt.ReadKey();
                                if (Ch.ToString().ToUpper() != "Y")
                                {
                                    WriteLn("", false);
                                    WriteLn("Cancelling quit request.", false);
                                    WriteLn("", false);
                                    continue;
                                }
                            }
                        }

                        _GameSrv.Stop();
                        _GameSrv.Dispose();
                        Quit = true;
                        break;
                    }
                }
            }

            Environment.Exit(0);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            // Check command-line parameters
            foreach (string Arg in args)
            {
                switch (Arg.ToLower())
                {
                    case "24h":
                        _TimeFormatFooter = "HH:mm";
                        break;
                    case "simple":
                        _FancyOutput = false;
                        break;
                }
            }

            // Remove old "stop requested" file
            if (File.Exists(StringUtils.PathCombine(ProcessUtils.StartupPath, "gamesrvconsole.stop")))
            {
                FileUtils.FileDelete(StringUtils.PathCombine(ProcessUtils.StartupPath, "gamesrvconsole.stop"));
            }

            // Add connection types to counter
            _ConnectionCounts[ConnectionType.RLogin] = 0;
            _ConnectionCounts[ConnectionType.Telnet] = 0;
            _ConnectionCounts[ConnectionType.WebSocket] = 0;

            // Initialize the screen
            InitConsole();
            Write(Globals.Copyright, false);

            // Check if running as root
            if (Globals.StartedAsRoot)
            {
                WriteLn("", false);
                WriteLn("*** WARNING: Running GameSrv as root is NOT recommended ***", false);
                WriteLn("", false);
                WriteLn("A safer alternative to running GameSrv as root is to run it via 'privbind'", false);
                WriteLn("This will ensure GameSrv is able to bind to ports in the < 1024 range, but", false);
                WriteLn("it will run as a regular unprivileged program in every other way", false);
                WriteLn("", false);
                WriteLn("See start.sh for an example of the recommended method to start GameSrv", false);
                WriteLn("", false);
            }

            // Init GameSrv
            _GameSrv = new GameSrv();
            _GameSrv.AggregatedStatusMessageEvent += new EventHandler<StringEventArgs>(GameSrv_AggregatedStatusMessageEvent);
            _GameSrv.LogOnEvent += new EventHandler<NodeEventArgs>(GameSrv_LogOnEvent);
            _GameSrv.Start();

            // Main program loop
            int LastMinute = -1;
            int LastSecond = -1;
            bool Quit = false;
            while (!Quit)
            {
                while (!Crt.KeyPressed())
                {
                    Crt.Delay(100);
                    if (DateTime.Now.Minute != LastMinute)
                    {
                        UpdateTime();
                        LastMinute = DateTime.Now.Minute;
                    }

                    if ((DateTime.Now.Second % 2 == 0) && (DateTime.Now.Second != LastSecond))
                    {
                        LastSecond = DateTime.Now.Second;
                        if (File.Exists(StringUtils.PathCombine(ProcessUtils.StartupPath, "gamesrvconsole.stop")))
                        {
                            FileUtils.FileDelete(StringUtils.PathCombine(ProcessUtils.StartupPath, "gamesrvconsole.stop"));

                            _GameSrv.Stop();
                            _GameSrv.Dispose();
                            Quit = true;
                            break;
                        }
                    }
                }

                if (Crt.KeyPressed())
                {
                    char Ch = Crt.ReadKey();
                    switch (Ch.ToString().ToUpper())
                    {
                        case "\0":
                            char Ch2 = Crt.ReadKey();
                            if (Ch2 == ';') // F1
                            {
                                WriteLn("", false);
                                WriteLn("GameSrv WFC Screen Help", false);
                                WriteLn("-=-=-=-=-=-=-=-=-=-=-=-", false);
                                WriteLn("F1 = Help  (this screen)", false);
                                WriteLn("C  = Clear (clear the status window)", false);
                                WriteLn("P  = Pause (reject new connections, leave existing connections alone)", false);
                                WriteLn("S  = Setup (launch the config program)", false);
                                WriteLn("Q  = Quit  (shut down and terminate existing connections)", false);
                                WriteLn("", false);
                            }
                            break;
                        case "C":
                            Crt.ClrScr();
                            if (_FancyOutput) Crt.GotoXY(1, 32);
                            break;
                        case "P":
                            _GameSrv.Pause();
                            break;
                        case "S":
                            Process.Start(StringUtils.PathCombine(ProcessUtils.StartupPath, "GameSrvConfig.exe"));
                            break;
                        case "Q":
                            // Check if we're already stopped (or are stopping)
                            if ((_GameSrv.Status != ServerStatus.Stopped) && (_GameSrv.Status != ServerStatus.Stopping))
                            {
                                int ConnectionCount = _GameSrv.ConnectionCount;
                                if (ConnectionCount > 0)
                                {
                                    WriteLn("", false);
                                    WriteLn("There are " + ConnectionCount.ToString() + " active connections.", false);
                                    WriteLn("Are you sure you want to quit [y/N]: ", false);
                                    WriteLn("", false);
                                    Ch = Crt.ReadKey();
                                    if (Ch.ToString().ToUpper() != "Y")
                                    {
                                        WriteLn("", false);
                                        WriteLn("Cancelling quit request.", false);
                                        WriteLn("", false);
                                        continue;
                                    }
                                }
                            }

                            _GameSrv.Stop();
                            _GameSrv.Dispose();
                            Quit = true;
                            break;
                    }
                }
            }

            Environment.Exit(0);
        }