Пример #1
0
 internal void Farewell(string farewell)
 {
     if (gmcpFlags.Contains("gmcpEnabled"))
     {
         Telnet.SendGMCPPacket(this, $"Core.Goodbye \"{farewell}\"");
     }
     WriteLine($"{farewell}");
     Quit();
 }
Пример #2
0
        internal void Begin()
        {
            int i;

            byte[] socketBuffer = new byte[Telnet.MaxBufferSize];
            try
            {
                // Prod them to check if they support GMCP first.
                SendTelnetCommand(new byte[] { Telnet.IAC, Telnet.WILL, Telnet.GMCP });

                // Now start the actual loop.
                while ((i = stream.Read(socketBuffer, 0, socketBuffer.Length)) != 0)
                {
                    for (int j = 0; j < i; j++)
                    {
                        if ((char)socketBuffer[j] == '\n' || socketBuffer[j] == Telnet.SE || inputBufferIndex >= Telnet.MaxBufferSize)
                        {
                            if (inputBufferIndex > 0)
                            {
                                if (inputBuffer[0] == Telnet.IAC)
                                {
                                    Telnet.Parse(this, inputBuffer, inputBufferIndex);
                                }
                                else
                                {
                                    string sendingInput = SanitizeInput(System.Text.Encoding.ASCII.GetString(inputBuffer, 0, inputBufferIndex));
                                    if (sendingInput.Length > 0)
                                    {
                                        ReceiveInput(sendingInput);
                                    }
                                }
                                inputBufferIndex = 0;
                            }
                        }
                        else
                        {
                            inputBuffer[inputBufferIndex] = socketBuffer[j];
                            inputBufferIndex++;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine($"{id}: disconnected ({e.Message}).");
            }
            Disconnect();
            if (client != null)
            {
                client.Close();
            }
        }