Ejemplo n.º 1
0
        private void HandleJoin(string[] arguments, IrcClient client)
        {
            Console.WriteLine("Received JOIN request from {0}", client.IsRegistered() ? client.GetNickname() : client.ToString());

            if (!client.IsRegistered())
            {
                string msg = String.Format("411 JOIN CR LF"); //ERR_NOTREGISTERED
                client.SendMessage(msg);
                Console.WriteLine("  Returned 411 (ERR_NOTREGISTERED)");
                return;
            }

            if (arguments.Count() < 1)
            {
                string msg = "412 JOIN CR LF"; //ERR_NEEDMOREPARAMS
                client.SendMessage(msg);
                Console.WriteLine("  Returned 412 (ERR_NEEDMOREPARAMS)");
                return;
            }

            var roomname = arguments[0];

            Room room = m_ircServer.GetRoom(roomname);

            if (room == null)
            {
                string msg = String.Format("402 JOIN {0} CR LF", roomname); //ERR_NOSUCHROOM
                client.SendMessage(msg);
                Console.WriteLine("  Returned 402 (ERR_NOSUCHROOM): {0}", roomname);
                return;
            }

            if (room.Members.Contains(client))
            {
                string msg = String.Format("404 {0} CR LF", roomname); //ERR_ALREADYJOINED
                client.SendMessage(msg);
                Console.WriteLine("  Returned 404 (ERR_ALREADYJOINED): {0}", roomname);
                return;
            }

            if (room.Members.Count >= MAX_NUM_ROOM_MEMBERS)
            {
                string msg = String.Format("414 {0} CR LF", roomname); //ERR_ROOMISFULL
                client.SendMessage(msg);
                Console.WriteLine("  Returned 414 (ERR_ROOMISFULL): {0}", roomname);
                return;
            }

            string notification = String.Format("308 {0} {1} CR LF", roomname, client.GetNickname()); //RPL_JOINSUCCEEDED

            room.SendMessage(notification);
            Console.WriteLine("  Returned 308 (RPL_JOINSUCCEEDED): {0}", roomname);

            room.Members.Add(client);

            string response = String.Format("308 {0} CR LF", roomname); //RPL_JOINSUCCEEDED

            client.SendMessage(response);
            Console.WriteLine("  Notified room {0} of join", roomname);
        }
Ejemplo n.º 2
0
        private void HandleCreate(string[] arguments, IrcClient client)
        {
            Console.WriteLine("Received CREATE request from {0}", client.IsRegistered() ? client.GetNickname() : client.ToString());

            if (!client.IsRegistered())
            {
                string msg = String.Format("411 CREATE CR LF"); //ERR_NOTREGISTERED
                client.SendMessage(msg);
                Console.WriteLine("  Returned 411 (ERR_NOTREGISTERED)");
                return;
            }

            if (arguments.Count() < 1)
            {
                string msg = "412 CREATE CR LF"; //ERR_NEEDMOREPARAMS
                client.SendMessage(msg);
                Console.WriteLine("  Returned 412 (ERR_NEEDMOREPARAMS)");
                return;
            }

            var roomname = arguments[0];

            if (roomname.Length > MAX_ROOM_LENGTH || roomname.Contains(" "))
            {
                string msg = String.Format("407 {0} CR LF", roomname); //ERR_ERRONEOUSROOMNAME
                client.SendMessage(msg);
                Console.WriteLine("  Returned 407 (ERR_ERRONEOUSROOMNAME): {0}", roomname);
                return;
            }

            if (m_ircServer.IsRoomNameInUse(roomname))
            {
                string msg = String.Format("406 {0} CR LF", roomname); //ERR_ROOMNAMEINUSE
                client.SendMessage(msg);
                Console.WriteLine("  Returned 406 (ERR_ROOMNAMEINUSE): {0}", roomname);
                return;
            }

            if (m_ircServer.GetNumRooms() >= MAX_ROOM_NUM)
            {
                string msg = String.Format("405 {0} CR LF", roomname); //ERR_TOOMANYROOMS
                client.SendMessage(msg);
                Console.WriteLine("  Returned 405 (ERR_TOOMANYROOMS): {0}", roomname);
                return;
            }

            m_ircServer.AddRoom(roomname);

            string response = String.Format("307 {0} CR LF", roomname); //RPL_CREATESUCCEEDED

            client.SendMessage(response);
            Console.WriteLine("  Returned 307 (RPL_CREATESUCCEEDED): {0}", roomname);

            Room room = m_ircServer.GetRoom(roomname);

            room.Members.Add(client);
            Console.WriteLine("{0} joined room {1}", client.GetNickname(), room.GetName());

            response = String.Format("308 {0} CR LF", roomname); //RPL_JOINSUCCEEDED
            client.SendMessage(response);
            Console.WriteLine("  Returned 307 (RPL_JOINSUCCEEDED): {0}", roomname);
        }