namespace OubHackMS.Core
{
    using System;
    using System.Net;
    using System.Net.Sockets;
    using System.Threading;

    internal class QueryListener
    {
        private IPAddress addr = IPAddress.Any;
        private int iMaxLines = 30;
        private ManualResetEvent mre = new ManualResetEvent(true);
        private int port = 0x2260;
        private Socket sock;

        public QueryListener()
        {
            this.sock = new Socket(this.addr.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            this.sock.Bind(new IPEndPoint(this.addr, this.port));
            this.sock.Listen(30);
            this.sock.BeginAccept(new AsyncCallback(this.onConnect), this.sock);
            try
            {
                while (true)
                {
                    this.mre.Reset();
                    this.sock.BeginAccept(new AsyncCallback(this.onConnect), this.sock);
                    this.mre.WaitOne();
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("An exception occured in the UpdateListener : " + exception.Message);
            }
        }

        private bool isGoodPacket(char cPacket)
        {
            if (cPacket != 'l')
            {
                return (cPacket == 'c');
            }
            return true;
        }

        private void onConnect(IAsyncResult res)
        {
        }
    }
}

