Ejemplo n.º 1
0
        /// <summary>
        /// Handles one IRC command from a TCP connection (already established).
        /// </summary>
        private static void HandleClient(Socket client)
        {
            byte[]     buf         = new byte[Config.ReceiveBufferSize];
            bool       shouldClose = false;
            IrcSession session     = new IrcSession();

            while (!shouldClose)
            {
                if (!client.Connected)
                {
                    return;
                }

                buf.Initialize();

                try
                {
                    client.Receive(buf);
                }
                catch (SocketException)
                {
                    return;
                }

                string   request = Encoding.UTF8.GetString(buf).Replace("\0", "");
                string[] lines   = request.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (string line in lines)
                {
                    IrcResponse[] responses = Router.HandleCommand(line, session);

                    if (!session.Open)
                    {
                        shouldClose = true;
                    }

                    foreach (IrcResponse response in responses)
                    {
                        client.Send(Encoding.UTF8.GetBytes(response.ToString()));
                    }
                }
            }
            client.Close();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles one IRC command from a TCP connection (already established).
        /// </summary>
        private static void HandleClient(Socket client)
        {
            byte[] buf = new byte[Config.ReceiveBufferSize];
            bool shouldClose = false;
            IrcSession session = new IrcSession();

            while (!shouldClose)
            {
                if (!client.Connected)
                    return;

                buf.Initialize();

                try
                {
                    client.Receive(buf);
                }
                catch (SocketException)
                {
                    return;
                }

                string request = Encoding.UTF8.GetString(buf).Replace("\0", "");
                string[] lines = request.Split(new[] {'\r', '\n'}, StringSplitOptions.RemoveEmptyEntries);

                foreach (string line in lines)
                {
                    IrcResponse[] responses = Router.HandleCommand(line, session);

                    if (!session.Open)
                        shouldClose = true;

                    foreach (IrcResponse response in responses)
                    {
                        client.Send(Encoding.UTF8.GetBytes(response.ToString()));
                    }
                }
            }
            client.Close();
        }
Ejemplo n.º 3
0
		public IrcResponse(IrcResponseCode code, IrcSession user, string message)
		{
			User = user;
			Code = code;
			Message = message;
		}
Ejemplo n.º 4
0
 public IrcResponse(IrcResponseCode code, IrcSession user, string message)
 {
     User    = user;
     Code    = code;
     Message = message;
 }