Ejemplo n.º 1
0
        private bool ProcessMessage(ISessionData session, ISocketClient client, ISocketMessage message)
        {
            var user = _clientStates.Values.Where(c => c.ConnectionId == client.ConnectionId).SingleOrDefault();

            byte[] bytes = message.GetRawBytes();

            string result = (bytes[0]) switch
            {
                (byte)'/' => ProcessSlashCommand(user, session, client, ref bytes),
                (byte)'?' => GetHelpText(),
                _ => "Bad command or file name." // :)
            };

            client.Send(Encoding.ASCII.GetBytes(result + "\n"));

            return(true);
        }
Ejemplo n.º 2
0
        private bool ProcessPendingAuth(ISessionData session, ISocketClient client, ISocketMessage message)
        {
            var user = _clientStates.Values.Where(c => c.ConnectionId == client.ConnectionId).SingleOrDefault();

            //TODO: Error handling in chat server component

            var msg = message.GetRawBytes();

            if (msg.Length == 0 || msg.Length > 16)
            {
                client.Send(_("Invalid alias" + user.LinePrompt));
                return(false);
            }

            user.Alias = Encoding.ASCII.GetString(msg);
            user.Commands.Add(new JoinCommand()); //TODO: Populate commands based on access? Dunno
            user.Commands.Add(new ListRoomsCommand());

            client.Send(_($"Welcome {user.Alias}\n>"));

            user.Flags = ChatStates.Connected | ChatStates.Authenticated;

            return(true);
        }
Ejemplo n.º 3
0
        protected override void WhenReceiving(ISessionData session, ISocketClient client, ISocketMessage message)
        {
            /*  <-- INCOMING -->
             *  255 253 1    IAC DO ECHO
             *  255 253 31   IAC DO NAWS
             *  255 251 1    IAC WILL ECHO
             *  255 251 3    IAC WILL SUPPRESS-GO-AHEAD
             * */

            /*  <-- REPLY WITH -->
             *  255 252 1    IAC WONT ECHO
             *  255 252 31   IAC WONT NAWS
             *  255 254 1    IAC DONT ECHO
             *  255 254 3    IAC DONT SUPPRESS-GO-AHEAD
             * */

            // https://www.iana.org/assignments/telnet-options/telnet-options.xhtml


            var options = new List <TelnetPacketOption>();

            TelnetPacketOption option = null;

            byte b;
            byte lastByte = 0x00;

            var pos   = 0;
            var bytes = message.GetRawBytes(); // so is this bytes 'by ref'?

            if (message.FirstByte != B.Iac)    // wrong B.Iac value, hell... could be wrong acronym even.
            {
                goto DoneWithOptions;          // ignore the packet if it doesn't have any options? whatever
            }
            do
            {
                b = bytes[pos++]; // byte for the current position

                if (b == B.Iac)   // if it's an identifier for IAC then make a new option
                {
                    Debug.Write("IAC ");
                    if (lastByte == b) // if two IAC bytes (255, 0xFF) then the next byte starts content (if I recall, will look it up)
                    {
                        break;
                    }

                    option = new TelnetPacketOption();
                    options.Add(option);
                }

                option.Declaration = (bytes[pos++]) switch
                {
                    B.Will => TelnetDeclarations.Will,
                    B.Wont => TelnetDeclarations.Wont,
                    B.Do => TelnetDeclarations.Do,
                    B.Dont => TelnetDeclarations.Dont,

                    _ => TelnetDeclarations.None,
                };

                Debug.Write(Enum.GetName(typeof(TelnetDeclarations), option.Declaration) + " ");

                option.Value = (bytes[pos++]) switch
                {
                    (byte)TelnetOptions.Echo => TelnetOptions.Echo,
                    (byte)TelnetOptions.SupressGoAhead => TelnetOptions.SupressGoAhead,
                    (byte)TelnetOptions.FlowControl => TelnetOptions.FlowControl,

                    // moar

                    _ => TelnetOptions.Null,
                };

                Debug.WriteLine(Enum.GetName(typeof(TelnetOptions), option.Value));

                lastByte = b;
            }while (true);