Beispiel #1
0
        static void Main(string[] args)
        {
            try
            {
                Door.Startup();
                Door.StripLF = false;
                Door.TextAttr(7);
                Door.ClrScr();
                Door.GotoXY(1, 1);
                Door.KeyPressed(); // Ensures statusbar gets drawn before connecting (which blocks updates)

                // Default values (could be overridden when handling CLPs)
                _RLoginClientUserName = Door.DropInfo.Alias;
                _RLoginServerUserName = Door.DropInfo.Alias;

                // Parse CLPs
                HandleCLPs(args);

                // Check if we're being told where to connect, or should display a menu
                if (string.IsNullOrEmpty(_HostName))
                {
                    // No hostname, display a menu
                    Menu();
                }
                else
                {
                    // Have a hostname, connect to it
                    Connect();

                    // Pause before quitting
                    Door.ClearBuffers();
                    if (_WaitOnExit > 0)
                    {
                        Door.WriteLn();
                        Door.TextAttr(15);
                        Door.Write(new string(' ', 30) + "Hit any key to quit");
                        for (int i = 0; i < _WaitOnExit * 10; i++)
                        {
                            if (Door.KeyPressed())
                            {
                                break;
                            }
                            Crt.Delay(100);
                        }
                        Door.ReadKey();
                    }
                    Door.TextAttr(7);
                }
            }
            catch (Exception ex)
            {
                FileUtils.FileAppendAllText("ex.log", ex.ToString() + Environment.NewLine);
            }
            finally
            {
                Door.Shutdown();
            }
        }
Beispiel #2
0
        // This part was taken from Rick Parrish TelnetDoor almost direct copy pase, with some stuff removed.
        private static void Connect()
        {
            _Server = new TelnetConnection();

            if (_Server.Connect(hostURL, _Port))
            {
                bool CanContinue = true;

                if (CanContinue)
                {
                    Door.PipeWrite = false;
                    bool UserAborted = false;
                    while (!UserAborted && Door.Carrier && _Server.Connected)
                    {
                        bool Yield = true;

                        // See if the server sent anything to the client
                        if (_Server.CanRead())
                        {
                            Door.Write(_Server.ReadString());
                            Yield = false;
                        }

                        // See if the client sent anything to the server
                        if (Door.KeyPressed())
                        {
                            string ToSend = "";
                            while (Door.KeyPressed())
                            {
                                byte B = (byte)Door.ReadByte();
                                ToSend += (char)B;
                            }
                            _Server.Write(ToSend);

                            Yield = false;
                        }

                        // See if we need to yield
                        if (Yield)
                        {
                            Crt.Delay(1);
                        }
                    }
                    Door.PipeWrite = true;
                }
            }
            else
            {
                Door.WriteLn("Looks like the BBSLink server isn't online, please try back later.");
            }
        }
Beispiel #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);
        }
Beispiel #4
0
        private static void Connect()
        {
            Door.WriteLn();
            Door.Write(" Connecting to remote server...");

            if (_RLogin)
            {
                _Server = new RLoginConnection();
            }
            else
            {
                _Server = new TelnetConnection();
            }

            // Sanity check on the port
            if ((_Port < 1) || (_Port > 65535))
            {
                _Port = (_RLogin) ? 513 : 23;
            }

            if (_Server.Connect(_HostName, _Port))
            {
                bool CanContinue = true;
                if (_RLogin)
                {
                    // Send rlogin header
                    _Server.Write("\0" + _RLoginClientUserName + "\0" + _RLoginServerUserName + "\0" + _RLoginTerminalType + "\0");

                    // Wait up to 5 seconds for a response
                    char?Ch = _Server.ReadChar(5000);
                    if ((Ch == null) || (Ch != '\0'))
                    {
                        CanContinue = false;
                        Door.WriteLn("failed!");
                        Door.WriteLn();
                        Door.WriteLn(" Looks like the remote server doesn't accept RLogin connections.");
                    }
                }

                if (CanContinue)
                {
                    Door.WriteLn("connected!");

                    if (Door.Local)
                    {
                        Ansi.ESC5nEvent   += new EventHandler(Ansi_ESC5nEvent);
                        Ansi.ESC6nEvent   += new EventHandler(Ansi_ESC6nEvent);
                        Ansi.ESC255nEvent += new EventHandler(Ansi_ESC255nEvent);
                    }

                    Door.PipeWrite = false;
                    bool UserAborted = false;
                    while (!UserAborted && Door.Carrier && _Server.Connected)
                    {
                        bool Yield = true;

                        // See if the server sent anything to the client
                        if (_Server.CanRead())
                        {
                            Door.Write(_Server.ReadString());
                            Yield = false;
                        }

                        // See if the client sent anything to the server
                        if (Door.KeyPressed())
                        {
                            string ToSend = "";
                            while (Door.KeyPressed())
                            {
                                byte B = (byte)Door.ReadByte();
                                if (B == 29)
                                {
                                    // Ctrl-]
                                    _Server.Close();
                                    UserAborted = true;
                                    break;
                                }
                                else
                                {
                                    ToSend += (char)B;
                                }
                            }
                            _Server.Write(ToSend);
                            if (Door.LocalEcho)
                            {
                                Door.Write(ToSend);
                            }

                            Yield = false;
                        }

                        // See if we need to yield
                        if (Yield)
                        {
                            Crt.Delay(1);
                        }
                    }
                    Door.PipeWrite = true;

                    if (UserAborted)
                    {
                        Door.WriteLn();
                        Door.WriteLn();
                        Door.WriteLn(" User hit CTRL-] to disconnect from server.");
                    }
                    else if ((Door.Carrier) && (!_Server.Connected))
                    {
                        Door.WriteLn();
                        Door.WriteLn();
                        Door.WriteLn(" Remote server closed the connection.");
                    }
                }
            }
            else
            {
                Door.WriteLn("failed!");
                Door.WriteLn();
                Door.WriteLn(" Looks like the remote server isn't online, please try back later.");
            }
        }