public TileBoxSet(HouseViewerForm house, Int32 x, Int32 y, Int32 size)
 {
     DoubleBuffered = true;
     this.house     = house;
     this.x         = x;
     this.y         = y;
     this.size      = size;
     MouseMove     += MouseMoveHandler;
 }
        static void Main()
        {
            try
            {
                //String gameDirectory = @"C:\Users\Jonathan Marler\Desktop\CastleDoctrine_v31";
                //String gameDirectory = @"D:\Tools\CastleDoctrine_v32";
                String gameDirectory = Environment.CurrentDirectory;

                String cdServerHostname = "thecastledoctrine.net";
                //String cdServerConnectorString = "gateway:proxy.houston.hp.com:8080%thecastledoctrine.net";


                //
                // Initialize Static Variables
                //
                CDLoader.Load(gameDirectory);
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                houseViewerForm = new HouseViewerForm();

                //
                // Setup WebProxy
                //
                ISocketConnector cdConnector = CDProxy.SetupProxyInterceptor(gameDirectory);


                //
                // Start the listen thread
                //
                EndPoint           cdServerEndPoint = EndPoints.EndPointFromIPOrHost(cdServerHostname, 80);
                GameClientAcceptor acceptor         = new GameClientAcceptor(cdServerEndPoint, cdConnector);
                selectServer = new TcpSelectServer2(new Byte[2048], new TcpSelectListener2[] {
                    new TcpSelectListener2(new IPEndPoint(IPAddress.Any, 80), 32, acceptor.Accept),
                });

                acceptor.selectServer = selectServer;

                Thread listenThread = new Thread(selectServer.Run);
                listenThread.Name = "ListenThread";
                listenThread.Start();

                Application.Run(houseViewerForm);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
            finally
            {
                CDProxy.RestoreProxy();
            }
        }
        public SocketDataHandler DataFromServer(Socket socket, Byte[] data, UInt32 length)
        {
            if (length == 0)
            {
                String rest = serverLineParser.Flush();
                if (printTraffic)
                {
                    if (rest != null)
                    {
                        Console.WriteLine("[SERVER {0}] {1}", id, rest);
                    }
                }

                if (printTraffic)
                {
                    Console.WriteLine("[SERVER {0}] [Closed]", id);
                }
                if (clientSocket.Connected)
                {
                    clientSocket.Shutdown(SocketShutdown.Both);
                }
                return(null);
            }

            clientSocket.Send(data, 0, (Int32)length, SocketFlags.None);

            serverLineParser.Add(data, 0, length);
            String line;

            while (true)
            {
                line = serverLineParser.GetLine();
                if (line == null)
                {
                    break;
                }
                if (printTraffic)
                {
                    Console.WriteLine("[SERVER {0}] {1}", id, line);
                }

                //
                // Check for encrypted map
                //
                if (serverParseState > ServerParseState.Idle)
                {
                    if (serverParseState == ServerParseState.BlankLine)
                    {
                        if (line.Length <= 0)
                        {
                            serverParseState++;
                        }
                    }
                    else if (serverParseState == ServerParseState.Owner)
                    {
                        serverParseState++;
                    }
                    else if (serverParseState == ServerParseState.Map)
                    {
                        HouseViewerForm.HandleEncryptedMap(nextMapEncryptionKey, Convert.FromBase64String(line));
                        nextMapEncryptionKey = null;
                        serverParseState     = ServerParseState.Idle;
                    }
                    else
                    {
                        throw new InvalidOperationException(String.Format("Invalid server parse state '{0}'", serverParseState));
                    }
                }
            }

            return(DataFromServer);
        }