Exemplo n.º 1
0
        public void SpellAnimation(uint id, int animation, int speed, uint fromId, int fromAnimation)
        {
            var p = new ServerPacket(0x29);

            p.WriteByte(0x00); // ??
            p.WriteUInt32((uint)id);
            p.WriteUInt32((uint)fromId);
            p.WriteUInt16((ushort)animation);
            p.WriteUInt16((ushort)fromAnimation);
            p.WriteUInt16((ushort)speed);
            p.WriteByte(0x00);
            Enqueue(p);
        }
Exemplo n.º 2
0
        public override void DisplayTo(VisibleObject obj)
        {
            if (Hidden || Stealth)
            {
                return;
            }

            if (obj is Player)
            {
                var player = (obj as Player);
                var client = player.Client;

                var p = new ServerPacket(0x07);
                p.WriteUInt16(1);
                p.WriteUInt16((ushort)Point.X);
                p.WriteUInt16((ushort)Point.Y);
                p.WriteUInt32((uint)ID);
                p.WriteUInt16((ushort)((Polymorphed ? PolymorphForm : Sprite) + 0x4000));
                p.WriteByte(0); // random 1
                p.WriteByte(0); // random 2
                p.WriteByte(0); // random 3
                p.WriteByte(0); // unknown a
                p.WriteByte((byte)Direction);
                p.WriteByte(0); // unknown b
                p.WriteByte(Cursed);
                p.WriteByte(0); // unknown d
                p.WriteByte((byte)Type);
                p.WriteString8(Name);

                client.Enqueue(p);
            }
        }
Exemplo n.º 3
0
        private void MsgHandler_ClientJoin(Client client, ClientPacket msg)
        {
            byte seed = msg.ReadByte();

            byte[] key  = msg.Read(msg.ReadByte());
            string name = msg.ReadString(msg.ReadByte());
            uint   id   = msg.ReadUInt32();

            Encryption.Parameters encryptionParameters = new Encryption.Parameters(key, seed);

            if (ExpectedRedirects.ContainsKey(id) && (ExpectedRedirects[id] != null))
            {
                Redirection r = ExpectedRedirects[id];
                if ((r.Name == name) && r.EncryptionParameters.Matches(encryptionParameters))
                {
                    if (r.SourceServer == Program.LobbyServer || r.SourceServer is LoginServer)
                    {
                        var p = new ServerPacket(0x60);
                        p.WriteByte(0x00);
                        p.WriteUInt32(Notification.Checksum);
                        client.Enqueue(p);

                        var packet = new ServerPacket(0x6F);
                        packet.WriteByte(1);
                        packet.WriteUInt16((ushort)GameServer.MetafileDatabase.Count);
                        foreach (var kvp in GameServer.MetafileDatabase)
                        {
                            packet.WriteString8(kvp.Value.Name);
                            packet.WriteUInt32(kvp.Value.Checksum);
                        }
                        client.Enqueue(packet);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void RemoveCharacter(uint id)
        {
            var p = new ServerPacket(0x0E);

            p.WriteUInt32(id);
            Enqueue(p);
        }
Exemplo n.º 5
0
        public virtual bool Turn(Direction direction, bool forcefully)
        {
            if (!forcefully && (Sleeping || Frozen || Coma || Dizzy || MindControlled || Polymorphed))
            {
                return(false);
            }

            Direction = direction;

            switch (Direction)
            {
            case Direction.North: XOffset = 0; YOffset = -1; break;

            case Direction.South: XOffset = 0; YOffset = 1; break;

            case Direction.West: XOffset = -1; YOffset = 0; break;

            case Direction.East: XOffset = 1; YOffset = 0; break;
            }

            foreach (var c in Map.Objects)
            {
                if (WithinRange(c, 12) && c is Player)
                {
                    var p = new ServerPacket(0x11);
                    p.WriteUInt32(ID);
                    p.WriteByte((byte)direction);
                    (c as Player).Client.Enqueue(p);
                }
            }

            return(true);
        }
Exemplo n.º 6
0
 private void MsgHandler_RequestMetafile(Client client, ClientPacket msg)
 {
     if (!msg.ReadBoolean())
     {
         string fileName = msg.ReadString(msg.ReadByte());
         if (GameServer.MetafileDatabase.ContainsKey(fileName))
         {
             var p = new ServerPacket(0x6F);
             p.WriteByte(0);
             p.WriteString8(fileName);
             p.WriteUInt32(GameServer.MetafileDatabase[fileName].Checksum);
             p.WriteUInt16((ushort)GameServer.MetafileDatabase[fileName].RawData.Length);
             p.Write(GameServer.MetafileDatabase[fileName].RawData);
             client.Enqueue(p);
         }
     }
     else
     {
         var p = new ServerPacket(0x6F);
         p.WriteByte(1);
         p.WriteUInt16((ushort)GameServer.MetafileDatabase.Count);
         foreach (var kvp in GameServer.MetafileDatabase)
         {
             p.WriteString8(kvp.Value.Name);
             p.WriteUInt32(kvp.Value.Checksum);
         }
         client.Enqueue(p);
     }
 }
Exemplo n.º 7
0
        public void Redirect(Server.Redirection r)
        {
            r.DestinationServer.ExpectedRedirects.Add(r.ID, r);

            var ipEndPoint = r.DestinationServer.EndPoint;

            byte[] addressBytes = ipEndPoint.Address.GetAddressBytes();

            if (IPAddress.IsLoopback(IPAddress) || IPAddress.ToString().StartsWith("192.168"))
            {
                addressBytes = IPAddress.Parse("192.168.0.42").GetAddressBytes();
            }

            Array.Reverse(addressBytes);

            var p = new ServerPacket(0x03);

            p.Write(addressBytes);
            p.WriteUInt16((ushort)ipEndPoint.Port);
            p.WriteByte((byte)(r.EncryptionParameters.PrivateKey.Length + Encoding.GetEncoding(949).GetBytes(r.Name).Length + 7));
            p.WriteByte(r.EncryptionParameters.Seed);
            p.WriteByte((byte)r.EncryptionParameters.PrivateKey.Length);
            p.Write(r.EncryptionParameters.PrivateKey);
            p.WriteString8(r.Name);
            p.WriteUInt32(r.ID);
            Enqueue(p);
        }
Exemplo n.º 8
0
        public void SendCooldown(int slot, long length, int pane)
        {
            var p = new ServerPacket(0x3F);

            p.WriteByte((byte)pane);
            p.WriteByte((byte)slot);
            p.WriteUInt32((uint)length);
            Enqueue(p);
        }
Exemplo n.º 9
0
        public void BodyAnimation(uint id, int animation, int speed)
        {
            var p = new ServerPacket(0x1A);

            p.WriteUInt32((uint)id);
            p.WriteByte((byte)animation);
            p.WriteUInt16((ushort)speed);
            p.WriteUInt16(0x00);
            Enqueue(p);
        }
Exemplo n.º 10
0
        public void SendPlayerID(uint id)
        {
            var p = new ServerPacket(0x05);

            p.WriteUInt32(id);
            p.WriteByte(1);
            p.WriteByte(213);
            p.WriteByte((byte)Player.Class);
            p.WriteUInt16(0);
            Enqueue(p);
        }
Exemplo n.º 11
0
        public void SpellAnimation(int animation, int x, int y, int speed)
        {
            var p = new ServerPacket(0x29);

            p.WriteByte(0x00); // ??
            p.WriteUInt32(uint.MinValue);
            p.WriteUInt16((ushort)animation);
            p.WriteUInt16((ushort)speed);
            p.WriteUInt16((ushort)x);
            p.WriteUInt16((ushort)y);
            Enqueue(p);
        }
Exemplo n.º 12
0
        private void MsgHandler_ClientVersion(Client client, ClientPacket msg)
        {
            var p = new ServerPacket(0x00);

            p.WriteByte(0x00);
            p.WriteUInt32(Program.Checksum);
            p.WriteByte(0x00);
            p.WriteString8("NexonInc.");
            client.Enqueue(p);

            Program.WriteLine("Client connected: {0}", ((IPEndPoint)client.Socket.RemoteEndPoint).Address);
        }
Exemplo n.º 13
0
        public override void DisplayTo(VisibleObject obj)
        {
            if (obj is Player)
            {
                var player = (obj as Player);
                var client = player.Client;

                var p = new ServerPacket(0x07);
                p.WriteUInt16(1);
                p.WriteUInt16((ushort)Point.X);
                p.WriteUInt16((ushort)Point.Y);
                p.WriteUInt32((uint)ID);
                if (Value < 10)
                {
                    p.WriteUInt16((ushort)(139 + 0x8000));
                }
                else if (Value < 100)
                {
                    p.WriteUInt16((ushort)(142 + 0x8000));
                }
                else if (Value < 1000)
                {
                    p.WriteUInt16((ushort)(138 + 0x8000));
                }
                else if (Value < 10000)
                {
                    p.WriteUInt16((ushort)(141 + 0x8000));
                }
                else if (Value < 100000)
                {
                    p.WriteUInt16((ushort)(137 + 0x8000));
                }
                else if (Value < 1000000)
                {
                    p.WriteUInt16((ushort)(140 + 0x8000));
                }
                else
                {
                    p.WriteUInt16((ushort)(136 + 0x8000));
                }
                p.WriteByte(0); // random 1
                p.WriteByte(0); // random 2
                p.WriteByte(0); // random 3

                client.Enqueue(p);
            }
        }
Exemplo n.º 14
0
        public override void DisplayTo(VisibleObject obj)
        {
            if (obj is Player)
            {
                var player = (obj as Player);
                var client = player.Client;

                if (player.Quests.ContainsKey(QuestName))
                {
                    bool returnQuest = true;

                    var quest = player.Quests[QuestName];
                    if (QuestStep == quest.CurrentStep)
                    {
                        var subQuest = quest.QuestStep;
                        if (subQuest.Progress == QuestProgress.InProgress)
                        {
                            returnQuest = false;
                        }
                    }

                    if (returnQuest)
                    {
                        return;
                    }
                }

                var p = new ServerPacket(0x07);
                p.WriteUInt16(1);
                p.WriteUInt16((ushort)Point.X);
                p.WriteUInt16((ushort)Point.Y);
                p.WriteUInt32((uint)ID);
                p.WriteUInt16((ushort)(Sprite + 0x8000));
                p.WriteByte(0); // random 1
                p.WriteByte(0); // random 2
                p.WriteByte(0); // random 3

                client.Enqueue(p);
            }
        }
Exemplo n.º 15
0
        public virtual void Say(string msg, int type)
        {
            foreach (var c in Map.Objects)
            {
                if (c is Player && (WithinRange(c, 12) || type == 1))
                {
                    var player = c as Player;
                    var packet = new ServerPacket(0x0D);
                    packet.WriteByte((byte)type);
                    packet.WriteUInt32(ID);
                    switch (type)
                    {
                    case 0: packet.WriteString8("{0}: {1}", Name, msg); break;

                    case 1: packet.WriteString8("{0}! {1}", Name, msg); break;

                    default: packet.WriteString8(msg); break;
                    }
                    player.Client.Enqueue(packet);
                }
            }
        }
Exemplo n.º 16
0
        public void SendStatistics(StatUpdateFlags flags)
        {
            if (Player.CanWalkThroughWalls || Player.CanWalkThroughUnits)
            {
                flags |= StatUpdateFlags.GameMasterA;
            }
            else
            {
                flags |= StatUpdateFlags.Swimming;
            }

            var p = new ServerPacket(0x08);

            p.WriteByte((byte)flags);
            if ((flags & StatUpdateFlags.Primary) == StatUpdateFlags.Primary)
            {
                p.Write(new byte[] { 1, 0, 0 });
                p.WriteByte((byte)Player.Level);
                p.WriteByte(0x00);
                p.WriteByte((byte)Player.Ability);
                p.WriteUInt32(Player.MaximumHP);
                p.WriteUInt32(Player.MaximumMP);
                p.WriteUInt16(Player.Str);
                p.WriteUInt16(Player.Int);
                p.WriteUInt16(Player.Wis);
                p.WriteUInt16(Player.Con);
                p.WriteUInt16(Player.Dex);
                p.WriteByte(Player.AvailableStatPoints > 0);
                p.WriteByte((byte)Player.AvailableStatPoints);
                p.WriteUInt16((ushort)Player.MaximumWeight);
                p.WriteUInt16((ushort)Player.CurrentWeight);
                p.WriteUInt32(uint.MinValue);
            }
            if ((flags & StatUpdateFlags.Current) == StatUpdateFlags.Current)
            {
                p.WriteUInt32((uint)Player.CurrentHP);
                p.WriteUInt32((uint)Player.CurrentMP);
            }
            if ((flags & StatUpdateFlags.Experience) == StatUpdateFlags.Experience)
            {
                p.WriteUInt32((uint)Player.Experience);
                p.WriteUInt32((uint)(Player.ToNextLevel - Player.Experience));
                p.WriteUInt32((uint)(Player.ToNextLevel - Player.ToThisLevel));
                p.WriteUInt32((uint)Player.AbilityExp);
                p.WriteUInt32((uint)(Player.ToNextAbility - Player.AbilityExp));
                p.WriteUInt32((uint)(Player.ToNextAbility - Player.ToThisAbility));
                p.WriteUInt32((uint)Player.GamePoints);
                p.WriteUInt32((uint)Player.Gold);
            }
            if ((flags & StatUpdateFlags.Secondary) == StatUpdateFlags.Secondary)
            {
                p.WriteUInt32(uint.MinValue);
                p.WriteUInt16(ushort.MinValue);
                p.WriteByte((byte)Player.OffenseElement);
                p.WriteByte((byte)Player.DefenseElement);
                p.WriteByte((byte)(Player.MagicResistance / 10));
                p.WriteByte(byte.MinValue);
                p.WriteSByte(Player.ArmorClass);
                p.WriteSByte(Player.Dmg);
                p.WriteSByte(Player.Hit);
            }
            Enqueue(p);
        }
Exemplo n.º 17
0
        public virtual void Damage(double dmg, Character attacker = null, int sound = 0, DamageType damageType = DamageType.RawDamage, DamageFlags flags = DamageFlags.None)
        {
            if (LifeStatus != LifeStatus.Alive)
            {
                return;
            }

            RemoveStatus("Morph");

            var realDamage = dmg;

            if ((flags & DamageFlags.CanBeAbsorbed) == DamageFlags.CanBeAbsorbed)
            {
                if (AbsorbingAbsoluteDamage)
                {
                    CurrentAbsoluteDamageAbsorbed += dmg;
                    if (MaximumAbsoluteDamageAbsorbed <= CurrentAbsoluteDamageAbsorbed)
                    {
                        RemoveStatus("AbsoluteAbsorb");
                    }
                    realDamage = 0;
                    SpellAnimation(AbsoluteAbsorbAnimation, 100);
                }
                else if (AbsorbingPhysicalDamage && damageType == DamageType.Physical)
                {
                    CurrentPhysicalDamageAbsorbed += dmg;
                    if (MaximumPhysicalDamageAbsorbed <= CurrentPhysicalDamageAbsorbed)
                    {
                        RemoveStatus("PhysicalAbsorb");
                    }
                    realDamage = 0;
                    SpellAnimation(PhysicalAbsorbAnimation, 100);
                }
                else if (AbsorbingMagicalDamage && damageType == DamageType.Magical)
                {
                    CurrentMagicalDamageAbsorbed += dmg;
                    if (MaximumMagicalDamageAbsorbed <= CurrentMagicalDamageAbsorbed)
                    {
                        RemoveStatus("MagicalAbsorb");
                    }
                    realDamage = 0;
                    SpellAnimation(MagicalAbsorbAnimation, 100);
                }
            }

            if (damageType == DamageType.Physical)
            {
                realDamage *= ArmorProtection * (1d - PhysicalProtection);
            }
            else if (damageType == DamageType.Magical)
            {
                realDamage -= (realDamage * (MagicResistance / 100d));
                realDamage *= (1d - MagicalProtection);
            }

            if (Map.Flags.HasFlag(MapFlags.PlayerKill))
            {
                dmg *= 0.75;
            }

            if (attacker != null)
            {
                if (!Enemies.Contains(attacker))
                {
                    Enemies.Add(attacker);
                }
                if (!attacker.Enemies.Contains(this))
                {
                    attacker.Enemies.Add(this);
                }
                LastAttacker = attacker;
            }

            if ((flags & DamageFlags.CanBeRedirected) == DamageFlags.CanBeRedirected)
            {
                if (RedirectingPhysicalDamage && damageType == DamageType.Physical)
                {
                    if (PhysicalRedirectTarget != null && PhysicalRedirectTarget != this && WithinRange(PhysicalRedirectTarget, 12))
                    {
                        var yourDamage = realDamage * PhysicalRedirectPercent;
                        realDamage -= yourDamage;
                        PhysicalRedirectTarget.Damage(yourDamage, null, 0, DamageType.RawDamage, DamageFlags.None);
                    }
                    if (--PhysicalRedirectCount == 0)
                    {
                        RemoveStatus("PhysicalRedirect");
                    }
                }

                if (RedirectingMagicalDamage && damageType == DamageType.Magical)
                {
                    if (MagicalRedirectTarget != null && MagicalRedirectTarget != this && WithinRange(MagicalRedirectTarget, 12))
                    {
                        var yourDamage = realDamage * MagicalRedirectPercent;
                        realDamage -= yourDamage;
                        MagicalRedirectTarget.Damage(yourDamage, null, 0, DamageType.RawDamage, DamageFlags.None);
                    }
                    if (--MagicalRedirectCount == 0)
                    {
                        RemoveStatus("MagicalRedirect");
                    }
                }
            }

            if ((flags & DamageFlags.CanBeConvertedToManaDamage) == DamageFlags.CanBeConvertedToManaDamage)
            {
                if (ConvertingPhysicalDamageToManaDamage && damageType == DamageType.Physical)
                {
                    CurrentMP -= (long)realDamage;
                    if (CurrentMP < 0)
                    {
                        CurrentMP = 0;
                    }
                    CurrentPhysicalDamageConvertedToManaDamage += dmg;
                    if (MaximumPhysicalDamageConvertedToManaDamage <= CurrentPhysicalDamageConvertedToManaDamage)
                    {
                        RemoveStatus("PhysicalConvertToMana");
                    }
                    realDamage = 0;
                    SpellAnimation(PhysicalConvertToManaAnimation, 100);
                }
                if (ConvertingMagicalDamageToManaDamage && damageType == DamageType.Magical)
                {
                    CurrentMP -= (long)realDamage;
                    if (CurrentMP < 0)
                    {
                        CurrentMP = 0;
                    }
                    CurrentMagicalDamageConvertedToManaDamage += dmg;
                    if (MaximumMagicalDamageConvertedToManaDamage <= CurrentPhysicalDamageConvertedToManaDamage)
                    {
                        RemoveStatus("MagicalConvertToMana");
                    }
                    realDamage = 0;
                    SpellAnimation(MagicalConvertToManaAnimation, 100);
                }
            }

            CurrentHP -= (long)realDamage;

            if (CurrentHP < 0)
            {
                CurrentHP = 0;
            }

            if (attacker != null)
            {
                if (Attackers.ContainsKey(attacker))
                {
                    Attackers[attacker] += realDamage;
                }
                else
                {
                    Attackers.Add(attacker, realDamage);
                }
            }

            double percent = Math.Floor((double)CurrentHP / (double)MaximumHP * 100.0);

            if (percent < 0)
            {
                percent = 0;
            }

            if (percent > 100)
            {
                percent = 100;
            }

            var dot = (flags & DamageFlags.DamageOverTime) == DamageFlags.DamageOverTime;
            var id  = (attacker != null) ? attacker.ID : ID;

            foreach (Character c in Map.Objects)
            {
                if (WithinRange(c, 12) && (c is Player))
                {
                    var packet = new ServerPacket(0x13);
                    packet.WriteUInt32(id);
                    packet.WriteUInt32(ID);
                    packet.WriteByte(dot);
                    packet.WriteByte((byte)percent);
                    packet.WriteUInt32((uint)realDamage);
                    packet.WriteByte((byte)sound);
                    (c as Player).Client.Enqueue(packet);
                }
            }
        }
Exemplo n.º 18
0
        public virtual bool Heal(Character healer, double amount, int sound = 255)
        {
            if (LifeStatus != LifeStatus.Alive)
            {
                return(false);
            }

            if (amount > uint.MaxValue)
            {
                amount = uint.MaxValue;
            }

            if (amount < uint.MinValue)
            {
                amount = uint.MinValue;
            }

            if (ConvertHealToDamage)
            {
                amount *= -1;
            }

            CurrentHP += (long)amount;

            if (CurrentHP > MaximumHP)
            {
                CurrentHP = MaximumHP;
            }

            if (CurrentHP < 0)
            {
                CurrentHP = 0;
            }

            var percent = Math.Floor((double)CurrentHP / (double)MaximumHP * 100.0);

            if (percent > 100)
            {
                percent = 100;
            }

            if (percent < 0)
            {
                percent = 0;
            }

            foreach (Character c in Map.Objects)
            {
                if (WithinRange(c, 12) && c is Player)
                {
                    var packet = new ServerPacket(0x13);
                    packet.WriteUInt32((healer == null) ? ID : healer.ID);
                    packet.WriteUInt32(ID);
                    packet.WriteByte(0x00);
                    packet.WriteByte((byte)percent);
                    packet.WriteUInt32((uint)(0 - amount));
                    packet.WriteByte((byte)sound);
                    (c as Player).Client.Enqueue(packet);
                }
            }
            return(true);
        }
Exemplo n.º 19
0
        public void SendProfile()
        {
            var p = new ServerPacket(0x39);

            p.WriteByte(Player.GameServer.NationDatabase[Player.Nation].Flag);
            p.WriteString8((Player.Guild != null) ? Player.GuildRank.ToString() : string.Empty);

            var masks = new List <byte>();

            for (int i = 0; i < Player.GameServer.TitleDatabase.Count; i++)
            {
                var title = Player.GameServer.TitleDatabase[i];

                var value = i % 8;

                if (value == 0)
                {
                    masks.Add(0);
                }

                var index = masks.Count - 1;

                if (title.Available(Player))
                {
                    switch (value)
                    {
                    case 0: masks[index] += 0x80; break;

                    case 1: masks[index] += 0x40; break;

                    case 2: masks[index] += 0x20; break;

                    case 3: masks[index] += 0x10; break;

                    case 4: masks[index] += 0x08; break;

                    case 5: masks[index] += 0x04; break;

                    case 6: masks[index] += 0x02; break;

                    case 7: masks[index] += 0x01; break;
                    }
                }
            }

            p.WriteByte((byte)masks.Count);
            foreach (var mask in masks)
            {
                p.WriteByte(mask);
            }

            p.WriteByte((byte)Player.Title);
            if (!Player.Group.HasMembers)
            {
                p.WriteString8("그룹 없음");
            }
            else
            {
                StringBuilder sb = new StringBuilder("그룹구성원\n");
                foreach (var player in Player.Group.Members)
                {
                    sb.AppendFormat("{0} {1}\n", (player == Player.Group.Leader) ? "*" : " ", player.Name);
                }
                sb.AppendFormat("총 {0}명", Player.Group.Members.Count);
                p.WriteString8(sb.ToString());
            }
            p.WriteByte(Player.GroupToggle);
            p.WriteByte(0x00); // ??
            p.WriteByte((byte)Player.Class);
            p.WriteByte(0x01); // ??
            p.WriteByte(0x00); // ??
            p.WriteString8(string.Format("{0}{1}{2}",
                                         Player.Master ? "Master " : string.Empty,
                                         (Player.Specialization != Specialization.None) ? Player.Specialization + " " : string.Empty,
                                         Player.Class));
            p.WriteString8((Player.Guild != null) ? Player.Guild.Name : string.Empty);
            p.WriteByte((byte)Player.Legend.Count);
            foreach (var kvp in Player.Legend.OrderBy(l => l.Value.DateUpdated))
            {
                p.WriteByte((byte)kvp.Value.Icon);
                p.WriteByte((byte)kvp.Value.Color);
                p.WriteString8(kvp.Value.Key);
                p.WriteString8(kvp.Value.ToString());
            }
            p.WriteByte(0x00);   // ??
            p.WriteUInt16(Player.DisplayBitmask);
            p.WriteByte(0x02);   // ??
            p.WriteUInt32(0x00); // ??
            p.WriteByte(0x00);   // ??
            Enqueue(p);
        }