Beispiel #1
0
        public bool ProcessCommand(chat.MessageItem item)
        {
            this.item = item;

            if (this.ProcessSingleCharCommand())
                return true;

            if (this.ProcessDoubleCharCommand())
                return true;

            return false;
        }
Beispiel #2
0
        // process every key stroke
        void ProcessChar(char chr)
        {
            if (this.clientState == ClientStates.TEXT && chr == 9 && lineBuffer.Length == 1 && lineBuffer[0] >= '0' && lineBuffer[0] <= '9')
            {
                int number = int.Parse(lineBuffer.ToString());
                if (number != this.slotNumber)
                {
                    TelnetClient telnetClient = Server.GetTelById(number);
                    if (telnetClient != null && telnetClient.clientState == ClientStates.TEXT)
                    {
                        this.BackSpace();
                        lineBuffer.Clear();
                        lineBuffer.Append(telnetClient.username + ": ");
                        this.LineBufferOut();
                    }
                }
            }

            if (chr == 10 || chr == 13) // line feed || carriage return
            {
                if (lineBuffer.Length != 0)
                {
                    if (this.clientState == ClientStates.USERNAME)
                    {
                        SetUserName();
                    }
                    else
                    {
                        BackSpace();
                        chat.MessageItem messageItem = new chat.MessageItem();
                        messageItem.message = lineBuffer.ToString();
                        messageItem.client = this;
                        sv.Add(messageItem);
                    }
                    lineBuffer.Clear();
                }
            }

            if (chr == 8 || chr == 127 ) // backspace || DEL
            {
                if (lineBuffer.Length >0 )
                {
                    lineBuffer.Remove(lineBuffer.Length -1,1);
                    SendToUser("\x08 \x08");
                    return;
                }
            }

            if (chr > 31  && chr < 127) // normal chars (letters, digits etc)
            {
                if (this.clientState == ClientStates.USERNAME) // login
                {
                    // username no spaces + max length 20
                    if (chr == 32 || lineBuffer.Length > 20)
                    {
                        SendToUser('\b');
                        return;
                    }
                    else
                    {
                        lineBuffer.Append(chr);
                        SendToUser(chr);
                        return;
                    }
                }
                else if (lineBuffer.Length < LINEBUFFERLEN)
                {
                    lineBuffer.Append(chr);
                    string tmp = lineBuffer.ToString();
                    if (tmp.Length > 4 && (tmp.Substring(0,3) == ".li" || tmp.Substring(0,3) == ".re"))
                    {
                        SendToUser("*");
                        return;
                    }
                    SendToUser(chr);
                    return;
                }
            }
        }