Example #1
0
        /// <summary>
        /// Handles the contents of a network message.
        /// </summary>
        /// <param name="message">The message to handle.</param>
        /// <param name="connection">A reference to the connection from where this message is comming from, for context.</param>
        public override void HandleRequest(INetworkMessage message, IConnection connection)
        {
            var characterDeathInfo = message.ReadCharacterDeathInfo();

            using (var otContext = new OpenTibiaDbContext())
            {
                var playerKilledPlayer = characterDeathInfo.KillerId > 0;

                otContext.Deaths.Add(new Death
                {
                    PlayerId       = characterDeathInfo.VictimId,
                    Level          = characterDeathInfo.VictimLevel,
                    ByPeekay       = (byte)(playerKilledPlayer ? 1 : 0),
                    PeekayId       = playerKilledPlayer ? characterDeathInfo.KillerId : 0,
                    CreatureString = characterDeathInfo.KillerName,
                    Unjust         = (byte)(characterDeathInfo.Unjustified ? 0x01 : 0x00),
                    Timestamp      = characterDeathInfo.Timestamp.ToUnixTimeSeconds(),
                });

                otContext.SaveChanges();

                this.ResponsePackets.Add(new DefaultNoErrorPacket());
            }
        }