Example #1
0
 public TelnetClient(TcpClient tcpClient, chat.Server sv, int slotNumber)
 {
     this.tcpClient = tcpClient;
     this.sv = sv;
     this.clientState = ClientStates.SENDGREETING;
     this.slotNumber = slotNumber;
     this.chatCommands = new ChatCommands();
     this.userPrefs = new UserPrefs(); // after class creation
 }
Example #2
0
        public bool ProcessCommand(chat.MessageItem item)
        {
            this.item = item;

            if (this.ProcessSingleCharCommand())
                return true;

            if (this.ProcessDoubleCharCommand())
                return true;

            return false;
        }
Example #3
0
        public void SendMessage( chat.Message msg )
        {
            int size = msg.SerializedSize;

            byte[] buf = new byte[size + 4];

            buf[0] = (byte)((size >> 24) & 0x000000ff);
            buf[1] = (byte)((size >> 16) & 0x000000ff);
            buf[2] = (byte)((size >> 8) & 0x000000ff);
            buf[3] = (byte)((size) & 0x000000ff);

            pb.CodedOutputStream cos = pb.CodedOutputStream.CreateInstance(buf, 4, size);
            msg.WriteTo(cos);

            SendMessage(buf);
        }
Example #4
0
 public void SendUserPrefs(chat.MessageItem item)
 {
 }
Example #5
0
        private void ProcessItem(chat.MessageItem item)
        {
            if (item.message.Length > 1 && item.message[0] == '.')
            {
                // see class ChatCommands
                if (! item.client.chatCommands.ProcessCommand(item))
                {
                    item.client.SendToUser("Unknown command - try .h for help.\r\n");
                }
            }
            else if (item.message.Length > 3 && item.message[0] == '!')
            {
                if (item.message[1] >= '0' && item.message[1] <= '9' )
                {
                    int number;
                    int numberLen = 1;
                    while(numberLen<item.message.Length && item.message[numberLen]>='0' && item.message[numberLen] <= '9') numberLen ++;
                    if (int.TryParse(item.message.Substring(1,numberLen - 1), out number))
                    {
                        if ( number == item.client.slotNumber)
                        {
                            item.client.SendToUser("Cannot whisper in your own ear.\r\n");
                            return ;
                        }
                        TelnetClient target = Server.GetTelById(number);
                        if (target != null && target.clientState == chat.TelnetClient.ClientStates.TEXT)
                        {
                            string messageOriginator = string.Format("Whisper to ({0}) {1}: {2}", target.slotNumber, target.username, item.message);
                            string messageTarget = string.Format("({0}) {1} {2}: {3}", item.client.slotNumber, item.client.username, item.client.userPrefs.GetWhisperText(), item.message);

                            // Send message to target
                            target.BackSpace();
                            if (target.userPrefs.IsWhisperHighlighting())
                                target.SendLineToUserHighlight(messageTarget);
                            else
                                target.SendLineToUser(messageTarget);
                            target.LineBufferOut();

                            // send message to originator (myself)
                            if (item.client.userPrefs.IsWhisperHighlighting())
                                item.client.SendLineToUserHighlight(messageOriginator);
                            else
                                item.client.SendLineToUser(messageOriginator);
                        }
                        else
                        {
                            item.client.SendToUser("No such user.\r\n");
                        }
                    }
                }
            }
            else
            {
                sendToChannel(string.Format("({0}) {1} {2}: {3}\r\n", item.client.slotNumber, item.client.username, item.client.userPrefs.GetSayText(), item.message), item.client.userPrefs.GetChannelNumber());
            }
        }
Example #6
0
 public void Add(chat.MessageItem item)
 {
     lock (this)
     {
         messageQue.Enqueue(item);
     }
 }