/// <summary>
 /// Initializes a new instance of the PlayerLoggedPacket class.
 /// </summary>
 /// <param name="player">The player who logged on or off.</param>
 /// <param name="onOff">A value indicating whether the player logged on or off.</param>
 public PlayerLoggedPacket(Player player, bool onOff)
     : base()
 {
     this.OnOff = onOff;
     this.Orientation = new OrientationPacket(player);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Processes packets received from the server.
        /// </summary>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="data">The packet that was received.</param>
        private void Network_Received(object sender, PacketEventArgs data)
        {
            ChatPacket chatPacket = data.Packet as ChatPacket;
            if (chatPacket != null)
            {
                this.interfaceManager.AddMessage(MessageType.PlayerChat, string.Format(CultureInfo.CurrentCulture, "{0}: {1}", chatPacket.Sender, chatPacket.Chat));
                return;
            }

            ErrorMessagePacket messagePacket = data.Packet as ErrorMessagePacket;
            if (messagePacket != null)
            {
                this.interfaceManager.AddMessage(MessageType.SystemMessage, messagePacket.ErrorMessage);
                return;
            }

            IntroductionPacket introductionPacket = data.Packet as IntroductionPacket;
            if (introductionPacket != null)
            {
                this.Engine.Players.Clear();

                this.Engine.MainPlayer.UserName = introductionPacket.UserName;
                this.Engine.MainPlayer.SetOrientation(
                    introductionPacket.OrientationPacket.Position,
                    introductionPacket.OrientationPacket.Rotation,
                    introductionPacket.OrientationPacket.Scaling);
                this.interfaceManager.InventoryWindow.Inventory = introductionPacket.InventoryPacket.Inventory;

                for (int i = 0; i < introductionPacket.OtherPlayersOrientation.Count; i++)
                {
                    Player player = new Player(ExtendedModel.Load(this.Engine.Content, "models.mc->Orienter"), introductionPacket.OtherPlayersOrientation[i].UserName);
                    player.SetOrientation(
                        introductionPacket.OtherPlayersOrientation[i].Position,
                        introductionPacket.OtherPlayersOrientation[i].Rotation,
                        introductionPacket.OtherPlayersOrientation[i].Scaling);
                    this.Engine.Players.Add(player);
                }

                return;
            }

            InventoryPacket inventoryPacket = data.Packet as InventoryPacket;
            if (inventoryPacket != null)
            {
                this.interfaceManager.InventoryWindow.Inventory = inventoryPacket.Inventory;
                return;
            }

            OrientationPacket orientationPacket = data.Packet as OrientationPacket;
            if (orientationPacket != null)
            {
                if (orientationPacket.UserName == this.Engine.MainPlayer.UserName)
                {
                    this.Engine.MainPlayer.SetOrientation(
                        orientationPacket.Position,
                        orientationPacket.Rotation,
                        orientationPacket.Scaling);
                }
                else
                {
                    if (this.Engine.Players.Contains(orientationPacket.UserName))
                    {
                        this.Engine.Players[orientationPacket.UserName].SetOrientation(
                            orientationPacket.Position,
                            orientationPacket.Rotation,
                            orientationPacket.Scaling);
                    }
                }

                return;
            }

            PlayerLoggedPacket playerLoggedPacket = data.Packet as PlayerLoggedPacket;
            if (playerLoggedPacket != null)
            {
                this.interfaceManager.AddMessage(MessageType.SystemMessage, string.Format(CultureInfo.CurrentCulture, playerLoggedPacket.OnOff ? Resources.PlayerLoggedOn : Resources.PlayerLoggedOff, playerLoggedPacket.UserName));

                if (playerLoggedPacket.UserName != this.Engine.MainPlayer.UserName)
                {
                    if (playerLoggedPacket.OnOff)
                    {
                        Player player = new Player(ExtendedModel.Load(this.Engine.Content, "models.mc->Orienter"), playerLoggedPacket.UserName);
                        player.SetOrientation(
                            playerLoggedPacket.Orientation.Position,
                            playerLoggedPacket.Orientation.Rotation,
                            playerLoggedPacket.Orientation.Scaling);
                        this.Engine.Players.Add(player);
                    }
                    else
                    {
                        this.Engine.Players.Remove(playerLoggedPacket.UserName);
                    }
                }

                return;
            }
        }
 /// <summary>
 /// Initializes a new instance of the OrientationPacket class.
 /// </summary>
 /// <param name="player">The player object to obtain the username, position and rotation from.</param>
 public OrientationPacket(Player player)
     : this(player.UserName, player.Position, player.RotationDegrees, player.Scaling)
 {
 }