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

            if (client.IsRegistered())
            {
                string msg = String.Format("413 {0} CR LF", client.GetNickname()); //ERR_ALREADYREGISTERED
                client.SendMessage(msg);
                Console.WriteLine("  Returned 413 (ERR_ALREADYREGISTERED)");
                return;
            }

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

            var nickname = arguments[0];

            if (nickname.Length > MAX_NICKNAME_LENGTH || nickname.Contains(" "))
            {
                string msg = String.Format("409 {0} CR LF", nickname); //ERR_ERONEOUSNICKNAME
                client.SendMessage(msg);
                Console.WriteLine("  Returned 409 (ERR_ERONEOUSNICKNAME): {0}", nickname);
                return;
            }

            if (m_ircServer.IsNicknameInUse(nickname))
            {
                string msg = String.Format("410 {0} CR LF", nickname); //ERR_NICKNAMEINUSE
                client.SendMessage(msg);
                Console.WriteLine("  Returned 410 (ERR_NICKNAMEINUSE): {0}", nickname);
                return;
            }

            client.Register(nickname);

            string response = String.Format("306 {0} CR LF", nickname); //RPL_REGISTERSUCCEEDED

            client.SendMessage(response);
            Console.WriteLine("  Returned 306 (RPL_REGISTERSUCCEEDED): {0}", nickname);
        }