public void SendWorldMap() { Player.WorldMap.IsOpen = true; var packet = new ServerPacket(0x2E); packet.WriteString8(Player.WorldMap.FileName); packet.WriteByte((byte)Player.WorldMap.Nodes.Count); packet.WriteByte(0x09); for (int i = 0; i < Player.WorldMap.Nodes.Count; i++) { var node = Player.WorldMap.Nodes[i]; packet.WriteUInt16((ushort)node.X); packet.WriteUInt16((ushort)node.Y); packet.WriteString8(node.MapName); packet.WriteInt32(i); packet.WriteUInt16((ushort)node.MapX); packet.WriteUInt16((ushort)node.MapY); } Enqueue(packet); }
public void SendMapInfo() { var p = new ServerPacket(0x15); p.WriteUInt16((ushort)Player.Map.Number); p.WriteByte((byte)(Player.Map.Width % 256)); p.WriteByte((byte)(Player.Map.Height % 256)); byte flags = 0; if ((Player.Map.Flags & MapFlags.Snow) == MapFlags.Snow) { flags |= 1; } if ((Player.Map.Flags & MapFlags.Rain) == MapFlags.Rain) { flags |= 2; } if ((Player.Map.Flags & MapFlags.NoMap) == MapFlags.NoMap) { flags |= 64; } if ((Player.Map.Flags & MapFlags.Winter) == MapFlags.Winter) { flags |= 128; } p.WriteByte(flags); p.WriteByte((byte)(Player.Map.Width / 256)); p.WriteByte((byte)(Player.Map.Height / 256)); p.WriteByte((byte)(Player.Map.Checksum % 256)); p.WriteByte((byte)(Player.Map.Checksum / 256)); p.WriteString8(Player.Map.Name); Enqueue(p); if (Player.CurrentMusic != Player.Map.Music) { Player.CurrentMusic = Player.Map.Music; SoundEffect(0x8000 + Player.Map.Music); } Player.WorldMap.IsOpen = false; }
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); } }
public void AcceptConnection() { if (listener.Pending()) { var socket = listener.AcceptSocket(); var greetMsg = new ServerPacket(0x7E); var client = new Client(socket, this); var ip = ((IPEndPoint)socket.RemoteEndPoint).Address.ToString(); if (Program.IPBanList.Contains(ip)) { client.Connected = false; return; } Clients.Add(client); greetMsg.WriteByte(0x1B); greetMsg.WriteString("CONNECTED SERVER\n"); client.Enqueue(greetMsg); } }
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); } } }
private void MsgHandler_ServerTable(Client client, ClientPacket msg) { bool mismatch = msg.ReadBoolean(); int serverId = msg.ReadByte(); if (mismatch) { var p = new ServerPacket(0x56); p.WriteUInt16((ushort)Program.RawData.Length); p.Write(Program.RawData); client.Enqueue(p); } else { Redirection r = new Redirection(); r.DestinationServer = Program.GameServers[serverId].LoginServer; r.EncryptionParameters = client.EncryptionParams; r.Name = String.Format(String.Empty, r.ID); r.SourceServer = this; client.Redirect(r); } }
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); } } }
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); }
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); }
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); }
public void Enqueue(ServerPacket msg) { sendQueue.Enqueue(msg); }
private void MsgHandler_Login(Client client, ClientPacket msg) { var name = msg.ReadString(msg.ReadByte()); var password1 = msg.ReadString(msg.ReadByte()); var accountid = 0; var password2 = String.Empty; var gamemaster = AdminRights.None; var active = false; var exists = false; var com = Program.MySqlConnection.CreateCommand(); com.CommandText = "SELECT characters.acct_id, characters.password, characters.gm, accounts.active " + "FROM characters " + "LEFT JOIN accounts " + "ON characters.acct_id = accounts.acct_id " + "WHERE (characters.name = @name) AND (characters.server = @server)"; com.Parameters.AddWithValue("@name", name); com.Parameters.AddWithValue("@server", GameServer.Name); var reader = com.ExecuteReader(); if (reader.Read()) { accountid = reader.GetInt32(0); password2 = reader.GetString(1); gamemaster = (AdminRights)Enum.Parse(typeof(AdminRights), reader.GetString(2)); active = (!reader.IsDBNull(3) && reader.GetBoolean(3)); exists = true; } reader.Close(); if (!GameServer.AllowLogin) { client.SendLoginMessage(14, "The game server is currently closed."); return; } if (!exists) { client.SendLoginMessage(14, "That character does not exist."); return; } if (password1 != password2) { client.SendLoginMessage(14, "Incorrect password."); return; } if (accountid == 0) { client.SendLoginMessage(14, "Please register your character at game.wewladh.com"); return; } if (!active) { client.SendLoginMessage(14, "Your account has been locked."); return; } foreach (Client c in GameServer.Clients) { if ((c.Player != null) && c.Player.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)) { c.Connected = false; client.SendLoginMessage(14, "Your character is already playing."); return; } if ((c.Player != null) && (accountid != 0) && (c.Player.AccountID == accountid)) { c.Connected = false; client.SendLoginMessage(14, "Your account is already playing."); return; } } if (Program.RunningSlowly) { client.SendLoginMessage(14, "The game server is busy right now. Please try again."); return; } client.SendLoginMessage(0, "\0"); var p = new ServerPacket(0x22); p.WriteByte(0x00); client.Enqueue(p); foreach (var message in File.ReadAllLines(GameServer.DataPath + "\\login.txt")) { client.SendMessage(message); } var r = new Redirection(); r.DestinationServer = GameServer; r.EncryptionParameters = client.EncryptionParams; r.Name = name; r.SourceServer = this; client.Redirect(r); }