Esempio n. 1
0
        private void action_private_message()
        {
            var s    = _readdata.Split(':');
            var name = "null_name";
            var temp = "";

            if (s.Length >= 3)
            {
                name = s[2].Trim();
            }
            if (s.Length >= 4)
            {
                temp = s[3].Trim();
            }
            TcpClient t = null;

            if (_chatserver.FindUserRoom(name) != 0)
            {
                t = (TcpClient)_chatserver.ClientConnections[name.ToUpper()];
            }
            if (t != null)
            {
                _chatserver.Write(t.GetStream(),
                                  ChatProtocolValues.NORMAL_MSG(Nickname, temp));
                _chatserver.Write(_client.GetStream(),
                                  ChatProtocolValues.NORMAL_MSG(Nickname, temp));
            }
            else
            {
                _chatserver.Write(_client.GetStream(),
                                  ChatProtocolValues.USER_NOT_FOUND_MSG(name));
            }
        }
Esempio n. 2
0
        //PRIVATE MESSAGE
        private void action_private_message()
        {
            string[] s    = readdata.Split(':');
            string   name = "null_name"; //give a default dummy name

            string temp = "";            //hold the message

            //format is
            //:private:<target>:<message>
            if (s.Length >= 3)
            {
                name = s[2].Trim();
            }
            if (s.Length >= 4)
            {
                temp = s[3].Trim();
            }

            TcpClient t = null;

            if (chatserver.FindUserRoom(name) != 0)
            {
                t = (TcpClient)chatserver.ClientConnections[name.ToUpper()];
            }

            if (t != null)
            {
                //to target
                chatserver.Write(t.GetStream(),
                                 ChatProtocolValues.NORMAL_MSG(nickname, temp));
                //to inform sender
                chatserver.Write(client.GetStream(),
                                 ChatProtocolValues.NORMAL_MSG(nickname, temp));
            }
            else
            {
                chatserver.Write(client.GetStream(),
                                 ChatProtocolValues.USER_NOT_FOUND_MSG(name));
            }
        }
Esempio n. 3
0
        private void action_list()
        {
            var s  = _readdata.Split(' ');
            var p1 = 0;

            if (s.Length == 1)
            {
                p1 = Room;
            }
            if (s.Length >= 2)
            {
                if (s[1].ToUpper() == "ALL")
                {
                    p1 = -1;
                }
                else
                {
                    try
                    {
                        p1 = int.Parse(s[1]);
                    }
                    catch
                    {
                        // ignored
                    }
                }
            }

            if (p1 > _chatserver.NumRoom || p1 == 0)
            {
                _chatserver.Write(_client.GetStream(),
                                  ChatProtocolValues.NoSuchRoomMsg);
            }
            else
            {
                var temp = "";
                if (p1 == -1)
                {
                    for (var i = 0; i < _chatserver.NumRoom; i++)
                    {
                        foreach (string s1 in _chatserver.RoomUsers[i].Values)
                        {
                            temp = temp + "\n   " + s1 + " : room " + (i + 1);
                        }
                    }
                }
                else
                {
                    foreach (string s1 in _chatserver.RoomUsers[p1 - 1].Values)
                    {
                        temp = temp + "\n   " + s1 + " : room " + p1;
                    }
                }

                if (temp == "")
                {
                    temp = "Empty";
                }
                _chatserver.Write(_client.GetStream(),
                                  ChatProtocolValues.NORMAL_MSG("server", temp));
            }
        }
Esempio n. 4
0
        //LIST
        private void action_list()
        {
            string[] s  = readdata.Split(' ');
            int      p1 = 0;      //default to unknown room

            if ((s.Length) == 1)
            {
                p1 = room;                        //set to current room
            }
            //Get the specified room
            if (s.Length >= 2)
            {
                if (s[1].ToUpper() == "ALL")
                {
                    p1 = -1;                   //LIST ALL: indicate all rooms
                }
                else
                {
                    try
                    {
                        p1 = int.Parse(s[1]);                       //to get a room number
                    }
                    catch {}
                }
            }
            ;

            if ((p1 > chatserver.NumRoom) || (p1 == 0))
            {
                chatserver.Write(client.GetStream(),
                                 ChatProtocolValues.NO_SUCH_ROOM_MSG);
            }
            else
            {
                string temp = "";


                if (p1 == -1)
                {
                    for (int i = 0; i < chatserver.NumRoom; i++)
                    {
                        foreach (string s1 in chatserver.RoomUsers[i].Values)
                        {
                            temp = temp + "\n   " + s1 + " : room " + (i + 1);
                        }
                    }
                }
                else
                {
                    foreach (string s1 in chatserver.RoomUsers[p1 - 1].Values)
                    {
                        temp = temp + "\n   " + s1 + " : room " + (p1);
                    }
                }

                if (temp == "")
                {
                    temp = "Empty";
                }
                chatserver.Write(client.GetStream(),
                                 ChatProtocolValues.NORMAL_MSG("server", temp));
            }
        }