Exemple #1
0
 protected void LoadControls()
 {
     #region Main menu
     MnuMain   = new Menu();
     BtnCreate = new Button(Programs[ProgramID.Button],
                            new Vector3(Width / 2 - 64, Height - 128, 0.0f), Vector3.Zero, Vector3.One,
                            Controls, Models, MnuMain,
                            128, 32, 2, Width, Height, Matrix4.Identity,
                            new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                            new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                            () =>
     {
         MnuMain.HideAll();
         MnuNetwork.ShowAll();
         LblNetAddress.HideAll();
         TxtNetAddress.HideAll();
         BtnNetJoin.HideAll();
         return(Task.Delay(0));
     }, "Create game");
     BtnJoin = new Button(Programs[ProgramID.Button],
                          new Vector3(Width / 2 - 64, Height - 192, 0.0f), Vector3.Zero, Vector3.One,
                          Controls, Models, MnuMain,
                          128, 32, 2, Width, Height, Matrix4.Identity,
                          new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                          new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                          () =>
     {
         MnuMain.HideAll();
         MnuNetwork.ShowAll();
         BtnNetCreate.HideAll();
         return(Task.Delay(0));
     }, "Join game");
     BtnExit = new Button(Programs[ProgramID.Button],
                          new Vector3(Width / 2 - 64, Height - 256, 0.0f), Vector3.Zero, Vector3.One,
                          Controls, Models, MnuMain,
                          128, 32, 2, Width, Height, Matrix4.Identity,
                          new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                          new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                          () =>
     {
         Exit();
         return(Task.Delay(0));
     }, "Exit");
     MnuMain.CreateBuffers();
     #endregion
     #region Test menu
     MnuTest = new Menu();
     LblTest = new Label(Programs[ProgramID.Label],
                         Vector3.Zero, Vector3.Zero, Vector3.One,
                         Controls, Models, MnuTest,
                         92, 18, 2, Width, Height, Matrix4.Identity, new Color4(0.1f, 0.1f, 0.1f, 0.6f), "X:0 Y:0");
     BtnTest = new Button(Programs[ProgramID.Button],
                          new Vector3(8.0f, 40.0f, 0.0f), Vector3.Zero, Vector3.One,
                          Controls, Models, MnuTest,
                          128, 32, 2, Width, Height, Matrix4.Identity,
                          new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                          new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                          () =>
     {
         Polymono.Print("Hello");
         return(Task.Delay(0));
     }, "Test button");
     TxtTest = new Textbox(Programs[ProgramID.Label],
                           new Vector3(8.0f, 80.0f, 0.0f), Vector3.Zero, Vector3.One,
                           Controls, Models, MnuTest,
                           128, 32, 2, Width, Height, Matrix4.Identity,
                           new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                           new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                           "Test Textbox");
     MnuTest.CreateBuffers();
     #endregion
     #region Server creation menu
     MnuNetwork = new Menu();
     LblNetName = new Label(Programs[ProgramID.Label],
                            new Vector3((Width / 2) - 64, Height - (64 * 2) + 24, 0.0f), Vector3.Zero, Vector3.One,
                            Controls, Models, MnuNetwork,
                            92, 18, 2, Width, Height, Matrix4.Identity, new Color4(0.1f, 0.1f, 0.1f, 0.6f),
                            "Enter name:");
     TxtNetName = new Textbox(Programs[ProgramID.Label],
                              new Vector3((Width / 2) - 64, Height - (64 * 2), 0.0f), Vector3.Zero, Vector3.One,
                              Controls, Models, MnuNetwork,
                              128, 32, 2, Width, Height, Matrix4.Identity,
                              new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                              new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                              "");
     LblNetAddress = new Label(Programs[ProgramID.Label],
                               new Vector3((Width / 2) - 160, Height - (64 * 3) + 24, 0.0f), Vector3.Zero, Vector3.One,
                               Controls, Models, MnuNetwork,
                               108, 18, 2, Width, Height, Matrix4.Identity, new Color4(0.1f, 0.1f, 0.1f, 0.6f),
                               "Network address:");
     TxtNetAddress = new Textbox(Programs[ProgramID.Label],
                                 new Vector3((Width / 2) - 160, Height - (64 * 3), 0.0f), Vector3.Zero, Vector3.One,
                                 Controls, Models, MnuNetwork,
                                 128, 32, 2, Width, Height, Matrix4.Identity,
                                 new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                                 new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                                 "");
     ChkNetType = new Checkbox(Programs[ProgramID.Button],
                               new Vector3((Width / 2) - 160 + 128 + 8, Height - (64 * 3), 0.0f), Vector3.Zero, Vector3.One,
                               Controls, Models, MnuNetwork,
                               32, 32, 2, Width, Height, Matrix4.Identity,
                               new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                               new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f));
     LblNetPort = new Label(Programs[ProgramID.Label],
                            new Vector3((Width / 2) + 32, Height - (64 * 3) + 24, 0.0f), Vector3.Zero, Vector3.One,
                            Controls, Models, MnuNetwork,
                            92, 18, 2, Width, Height, Matrix4.Identity, new Color4(0.1f, 0.1f, 0.1f, 0.6f),
                            "Network port:");
     TxtNetPort = new Textbox(Programs[ProgramID.Label],
                              new Vector3((Width / 2) + 32, Height - (64 * 3), 0.0f), Vector3.Zero, Vector3.One,
                              Controls, Models, MnuNetwork,
                              128, 32, 2, Width, Height, Matrix4.Identity,
                              new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                              new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                              "");
     BtnNetCreate = new Button(Programs[ProgramID.Button],
                               new Vector3((Width / 2) - 64, Height - (64 * 4), 0.0f), Vector3.Zero, Vector3.One,
                               Controls, Models, MnuNetwork,
                               128, 32, 2, Width, Height, Matrix4.Identity,
                               new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f), // Default model
                               new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f), // Clicked model
                               () =>
     {
         try
         {
             bool v6;
             if (ChkNetType.State == ControlState.Clicked)
             {
                 v6 = true;
             }
             else
             {
                 v6 = false;
             }
             Server server = new Server(this, TxtNetName.Text, v6);
             int port      = Convert.ToInt32(TxtNetPort.Text);
             server.LocalHandler().Bind(port);
             server.LocalHandler().Listen(10);
             server.Start();
             Network = server;
             State   = GameState.Lobby;
             MnuNetwork.HideAll();
             MnuMessage.ShowAll();
             MnuGame.ShowAll();
         }
         catch (SocketException se)
         {
             Polymono.Error(se.Message);
             Polymono.ErrorF(se.StackTrace);
         }
         catch (FormatException fe)
         {
             Polymono.Error("Port is not a readable number.");
             Polymono.Error(fe.Message);
             Polymono.ErrorF(fe.StackTrace);
         }
         return(Task.Delay(0));
     }, "Create Server");
     BtnNetJoin = new Button(Programs[ProgramID.Button],
                             new Vector3((Width / 2) - 64, Height - (64 * 4), 0.0f), Vector3.Zero, Vector3.One,
                             Controls, Models, MnuNetwork,
                             128, 32, 2, Width, Height, Matrix4.Identity,
                             new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f), // Default model
                             new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f), // Clicked model
                             () =>
     {
         try
         {
             bool v6;
             if (ChkNetType.State == ControlState.Clicked)
             {
                 v6 = true;
             }
             else
             {
                 v6 = false;
             }
             Client client  = new Client(this, v6);
             string address = TxtNetAddress.Text;
             int port       = Convert.ToInt32(TxtNetPort.Text);
             string name    = TxtNetName.Text;
             client.ConnectAsync(address, port, name);
             Network = client;
             State   = GameState.Lobby;
             MnuNetwork.HideAll();
             MnuMessage.ShowAll();
         }
         catch (SocketException se)
         {
             Polymono.Error(se.Message);
             Polymono.ErrorF(se.StackTrace);
         }
         catch (FormatException fe)
         {
             Polymono.Error("Port is not a readable number.");
             Polymono.Error(fe.Message);
             Polymono.ErrorF(fe.StackTrace);
         }
         return(Task.Delay(0));
     }, "Join server");
     BtnNetBack = new Button(Programs[ProgramID.Button],
                             new Vector3((Width / 2) - 64, Height - (64 * 6), 0.0f), Vector3.Zero, Vector3.One,
                             Controls, Models, MnuNetwork,
                             128, 32, 2, Width, Height, Matrix4.Identity,
                             new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                             new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                             () =>
     {
         MnuNetwork.HideAll();
         MnuMain.ShowAll();
         return(Task.Delay(0));
     }, "Back");
     MnuNetwork.CreateBuffers();
     #endregion
     #region Message menu
     MnuMessage = new Menu();
     LblMsgBox  = new Label(Programs[ProgramID.Label],
                            new Vector3(32, Height / 2, 0.0f), Vector3.Zero, Vector3.One,
                            Controls, Models, MnuMessage,
                            256, 256, 2, Width, Height, Matrix4.Identity, new Color4(0.1f, 0.1f, 0.1f, 0.6f), "Chat room text" + Environment.NewLine + "Chat room text2");
     TxtMsgInput = new Textbox(Programs[ProgramID.Label],
                               new Vector3(32, Height / 2 - 256, 0.0f), Vector3.Zero, Vector3.One,
                               Controls, Models, MnuMessage,
                               192, 32, 2, Width, Height, Matrix4.Identity,
                               new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                               new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                               "");
     BtnMsgSend = new Button(Programs[ProgramID.Button],
                             new Vector3(32 + 192, Height / 2 - 256, 0.0f), Vector3.Zero, Vector3.One,
                             Controls, Models, MnuMessage,
                             64, 32, 2, Width, Height, Matrix4.Identity,
                             new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                             new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                             () =>
     {
         string text      = TxtMsgInput.Text.Trim();
         TxtMsgInput.Text = "";
         LblMsgBox.Text  += Environment.NewLine + text;
         Network.SendAsync(PacketHandler.Create(PacketType.Message,
                                                Protocol.Chat.EncodeMessage(text)));
         return(Task.Delay(0));
     }, "Send");
     MnuMessage.CreateBuffers();
     #endregion
     #region Game menu
     MnuGame      = new Menu();
     BtnGameStart = new Button(Programs[ProgramID.Button],
                               new Vector3((Width / 2) - 64, Height - (64 * 4), 0.0f), Vector3.Zero, Vector3.One,
                               Controls, Models, MnuGame,
                               128, 32, 2, Width, Height, Matrix4.Identity,
                               new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                               new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                               () =>
     {
         if (IsServer && Board.GetPlayers().Count > 1)
         {
             // Start game.
             ((Server)Network).AcceptClients = false;
             Network.SendAsync(PacketHandler.Create(PacketType.StartGame,
                                                    Protocol.Game.EncodeStartGame(Board.CurrentPlayerID)));
             State = GameState.LobbyRoll;
             MnuGame.HideAll();
             BtnRollDice.ShowAll();
             Polymono.Debug("Starting game.");
         }
         else
         {
             // Not enough players, not server.
             Polymono.Debug($"Cannot start game: [Is server:{IsServer}] [Players: {Board.GetPlayers().Count}]");
             Polymono.Debug("Needs to be server and have more than 1 player in lobby.");
         }
         // Starts game
         return(Task.Delay(0));
     }, "Start Game");
     BtnGameExit = new Button(Programs[ProgramID.Button],
                              new Vector3((Width / 2) - 64, Height - (64 * 6), 0.0f), Vector3.Zero, Vector3.One,
                              Controls, Models, MnuGame,
                              128, 32, 2, Width, Height, Matrix4.Identity,
                              new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                              new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                              async() =>
     {
         await Network.SendAsync(PacketHandler.Create(PacketType.Disconnect,
                                                      Protocol.Connection.EncodeDisconnect(Board.CurrentPlayerID, "Exit lobby")));
         Network = null;
         Polymono.Debug("Exiting game.");
         // Exits game
     }, "Exit Game");
     MnuPlayerOptions = new Menu();
     BtnRollDice      = new Button(Programs[ProgramID.Button],
                                   new Vector3((Width / 2) - 64, (64 * 2), 0.0f), Vector3.Zero, Vector3.One,
                                   Controls, Models, MnuPlayerOptions,
                                   128, 32, 2, Width, Height, Matrix4.Identity,
                                   new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                                   new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                                   () =>
     {
         int rollOne = DiceOne.GetNumber();
         int rollTwo = DiceTwo.GetNumber();
         Network.SendAsync(PacketHandler.Create(PacketType.DiceRoll,
                                                Protocol.Game.EncodeDiceRoll(rollOne, rollTwo,
                                                                             Board.CurrentPlayerID)));
         if (State == GameState.LobbyRoll)
         {
             BtnRollDice.HideAll();
             Board.EndCurrentTurn(Board.CurrentPlayerID);
             Network.SendAsync(PacketHandler.Create(PacketType.EndTurn,
                                                    Protocol.Game.EncodeEndTurn(Board.CurrentPlayerID)));
         }
         else if (State == GameState.PlayerOptions)
         {
             MnuPlayerOptions.HideAll();
             Board.MoveSpaces(rollOne + rollTwo, Board.CurrentPlayerID);
             State = GameState.Moving;
         }
         return(Task.Delay(0));
     }, "Roll Dice");
     BtnPurchaseProperty = new Button(Programs[ProgramID.Button],
                                      new Vector3((Width / 2) - 256, (64 * 2), 0.0f), Vector3.Zero, Vector3.One,
                                      Controls, Models, MnuPlayerOptions,
                                      128, 32, 2, Width, Height, Matrix4.Identity,
                                      new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                                      new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                                      () =>
     {
         // Purchase current property.
         return(Task.Delay(0));
     }, "Purchase");
     BtnTrade = new Button(Programs[ProgramID.Button],
                           new Vector3((Width / 2) + 192, (64 * 2), 0.0f), Vector3.Zero, Vector3.One,
                           Controls, Models, MnuPlayerOptions,
                           128, 32, 2, Width, Height, Matrix4.Identity,
                           new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                           new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                           () =>
     {
         // Trade screen.
         return(Task.Delay(0));
     }, "Trade");
     BtnEndTurn = new Button(Programs[ProgramID.Button],
                             new Vector3((Width / 2) - 64, (64 * 2), 0.0f), Vector3.Zero, Vector3.One,
                             Controls, Models, MnuPlayerOptions,
                             128, 32, 2, Width, Height, Matrix4.Identity,
                             new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                             new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                             () =>
     {
         MnuPlayerOptions.HideAll();
         // Trade screen.
         Board.EndCurrentTurn(Board.CurrentPlayerID);
         Network.SendAsync(PacketHandler.Create(PacketType.EndTurn,
                                                Protocol.Game.EncodeEndTurn(Board.CurrentPlayerID)));
         return(Task.Delay(0));
     }, "End Turn");
     MnuGame.CreateBuffers();
     MnuPlayerOptions.CreateBuffers();
     #endregion
     #region Game menu
     MnuPlayerJailOptions = new Menu();
     BtnPayJail           = new Button(Programs[ProgramID.Button],
                                       new Vector3(), Vector3.Zero, Vector3.One,
                                       Controls, Models, MnuPlayerJailOptions,
                                       128, 32, 2, Width, Height, Matrix4.Identity,
                                       new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                                       new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                                       () =>
     {
         // Pay Jail
         return(Task.Delay(0));
     }, "Roll Dice");
     BtnUseCard = new Button(Programs[ProgramID.Button],
                             new Vector3(), Vector3.Zero, Vector3.One,
                             Controls, Models, MnuPlayerJailOptions,
                             128, 32, 2, Width, Height, Matrix4.Identity,
                             new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.7f, 0.7f, 0.0f, 0.8f),
                             new Color4(0.1f, 0.1f, 0.1f, 0.6f), new Color4(0.0f, 0.6f, 0.7f, 0.8f),
                             () =>
     {
         // Use card
         return(Task.Delay(0));
     }, "Purchase");
     MnuPlayerJailOptions.CreateBuffers();
     #endregion
 }
Exemple #2
0
        protected override void UpdateObjects()
        {
            // Update inputs and camera.
            UpdateInput(UTimeDelta);
            UpdateCamera();
            // Manage game state.
            LblTest.Text = $"X:{Mouse.X} Y:{Mouse.Y}";
            LblTest.SetTranslate(new Vector3(Mouse.X + 16, Height - Mouse.Y, 0.0f));
            LblTest.Update();
            #region Network updating
            UpdateGameFromNetwork();
            #endregion
            #region Update game states
            // If a player should move
            // Move until
            SetWindowTitle(IsServer ? "Server" : "Client", TxtNetName?.Text ?? "N/A", State.ToString(), Board.CurrentPlayerTurn.ToString());
            switch (State)
            {
            case GameState.Menu:
                break;

            case GameState.Lobby:
                break;

            case GameState.LobbyRoll:
                break;

            case GameState.PlayerOptions:
                break;

            case GameState.Moving:
                bool isDone = Board.UpdatePositions(Board.CurrentPlayerTurn, (float)(1d / UpdatePeriod));
                if (isDone && Board.CurrentPlayerTurn == Board.CurrentPlayerID)
                {
                    MnuPlayerOptions.ShowAll();
                    BtnRollDice.HideAll();
                    Network.SendAsync(PacketHandler.Create(PacketType.MoveState,
                                                           Protocol.Game.EncodeMoveDone(Board.CurrentPlayerTurn)));
                    State = GameState.PlayerOptions;
                }
                break;

            default:
                break;
            }
            #endregion
            #region Update Matrices.
            // Update view matrices.
            ViewMatrix       = Camera.GetViewMatrix();
            StaticViewMatrix = Camera.GetStaticViewMatrix();
            ProjectionMatrix = Matrix4.CreatePerspectiveFieldOfView(ToRadians(Camera.Zoom),
                                                                    (float)Width / Height,
                                                                    0.1f, 1000f);
            UIProjectionMatrix = Matrix4.CreateOrthographicOffCenter(
                ClientRectangle.X, ClientRectangle.Width,
                ClientRectangle.Y, ClientRectangle.Height,
                -1.0f, 1.0f);
            // Update projection matrices.
            foreach (var control in Controls.Values)
            {
                control.ProjectionMatrix = UIProjectionMatrix;
                control.Update();
            }
            // Update matrices.
            Skybox.UpdateModelMatrix();
            foreach (var model in Models.Values)
            {
                model.UpdateModelMatrix();
            }
            DiceTwo.UpdateModelMatrix();
            foreach (var player in Board.GetPlayers())
            {
                player.UpdateModelMatrix();
            }
            #endregion
        }
Exemple #3
0
        void AcceptNewConnection(IAsyncResult result)
        {
            if (listener.IsListening)
            {
                listener.BeginGetContext(AcceptNewConnection, null); //Сразу продолжаем прием новых запросов
            }
            else
            {
                return;
            }

            HttpListenerContext  context  = listener.EndGetContext(result);
            HttpListenerRequest  request  = context.Request;
            HttpListenerResponse response = context.Response;

            Out.WriteLine("{0} {1} {2}", DateTime.Now.ToString(), request.RemoteEndPoint, request.HttpMethod);

            try
            {
                PacketSerializer serializer = PacketSerializer.Create(request.ContentType);

                if (serializer == null)
                {
                    throw new NotSupportedException(); //вместо исключения должен быть корректный ответ об ошибке
                }
                //Читаем что нам прислали
                Packet <IPacketContent> packet = serializer.Deserialize <IPacketContent>(request.InputStream);

                if (packet == null)
                {
                    throw new ArgumentException();
                }

                //Подберем обработчик
                PacketHandler handler = PacketHandler.Create(packet.Version);
                handler.Out = Out;

                //Получаем результат
                Packet <IPacketContent> responsePacket = handler.Handle(packet);

                //И отправляем обратно
                using (MemoryStream mstream = new MemoryStream())
                {
                    serializer.Serialize(responsePacket, mstream);

                    response.ContentLength64 = mstream.Length;
                    response.StatusCode      = 200;

                    mstream.Position = 0;
                    mstream.CopyTo(response.OutputStream);
                }
            }
            catch (Exception ex)
            {
                Out.Write("General Exception");
                Out.Write(ex.Message);
                Out.Write(ex.StackTrace);
                response.StatusCode = 500;
            }
            finally
            {
                response.OutputStream.Close();
            }
        }