/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is PlayerLoginPacket playerLoginPacket)) { this.Logger.LogWarning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(playerLoginPacket.PacketType.ToByte()); message.AddUInt32(playerLoginPacket.CreatureId); message.AddByte(playerLoginPacket.GraphicsSpeed); message.AddByte(playerLoginPacket.CanReportBugs); message.AddByte(Math.Min((byte)0x01, playerLoginPacket.Player.PermissionsLevel)); if (playerLoginPacket.Player.PermissionsLevel > 0) { message.AddByte(OutgoingPacketType.GamemasterFlags.ToByte()); for (var i = 0; i < 32; i++) { // TODO: Actually send individual permissions flags message.AddByte(byte.MaxValue); } } }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is CreatureSpeechPacket creatureSpeechPacket)) { this.Logger.LogWarning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(creatureSpeechPacket.PacketType.ToByte()); message.AddUInt32(0); message.AddString(creatureSpeechPacket.SenderName); message.AddByte(creatureSpeechPacket.SpeechType switch { // ChannelRed = 0x05, //Talk red on chat - #c // PrivateRed = 0x04, //Red private - @name@ text // ChannelOrange = 0x05, //Talk orange on text // ChannelRedAnonymous = 0x05, //Talk red anonymously on chat - #d // MonsterYell = 0x0E, //Yell orange SpeechType.Normal => 0x01, SpeechType.Whisper => 0x02, SpeechType.Yell => 0x03, SpeechType.Private => 0x04, SpeechType.ChannelYellow => 0x05, SpeechType.RuleViolationReport => 0x06, SpeechType.RuleViolationAnswer => 0x07, SpeechType.RuleViolationContinue => 0x08, SpeechType.Broadcast => 0x09, SpeechType.MonsterNormal => 0x0E, _ => 0x01, });
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is TileUpdatePacket tileUpdatePacket)) { this.Logger.LogWarning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(tileUpdatePacket.PacketType.ToByte()); message.AddLocation(tileUpdatePacket.UpdatedTile.Location); if (tileUpdatePacket.UpdatedTile != null) { message.AddBytes(this.BuildDescription(tileUpdatePacket.Player, tileUpdatePacket.UpdatedTile)); message.AddByte(0x00); // skip count } else { message.AddByte(0x01); // skip count } // marks the end. message.AddByte(byte.MaxValue); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is TileUpdatePacket tileUpdatePacket)) { this.Logger.Warning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(tileUpdatePacket.PacketType.ToByte()); message.AddLocation(tileUpdatePacket.Location); if (tileUpdatePacket.DescriptionBytes.Length > 0) { message.AddBytes(tileUpdatePacket.DescriptionBytes); message.AddByte(0x00); // skip count } else { message.AddByte(0x01); // skip count } message.AddByte(byte.MaxValue); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is TextMessagePacket textMessagePacket)) { this.Logger.LogWarning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(textMessagePacket.PacketType.ToByte()); byte valueToSend = textMessagePacket.Type switch { MessageType.CenterWhite => 0x13, MessageType.CenterGreen => 0x16, MessageType.CenterRed => 0x12, MessageType.Status => 0x15, MessageType.StatusNoConsole => 0x17, MessageType.ConsoleOnlyBlue => 0x18, MessageType.ConsoleOnlyRed => 0x19, MessageType.ConsoleOnlyYellow => 0x01, MessageType.ConsoleOnlyLightBlue => 0x04, MessageType.ConsoleOnlyOrange => 0x11, _ => 0x14, }; message.AddByte(valueToSend); message.AddString(textMessagePacket.Message); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is PlayerConditionsPacket playerConditionsPacket)) { this.Logger.LogWarning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(playerConditionsPacket.PacketType.ToByte()); byte conditionFlags = 0; // Add condition icons supported by this version. if (playerConditionsPacket.Player.HasCondition(ConditionType.Posioned)) { conditionFlags |= 1 << 0; } if (playerConditionsPacket.Player.HasCondition(ConditionType.Burning)) { conditionFlags |= 1 << 1; } if (playerConditionsPacket.Player.HasCondition(ConditionType.Electrified)) { conditionFlags |= 1 << 2; } if (playerConditionsPacket.Player.HasCondition(ConditionType.Drunk)) { conditionFlags |= 1 << 3; } if (playerConditionsPacket.Player.HasCondition(ConditionType.ManaShield)) { conditionFlags |= 1 << 4; } if (playerConditionsPacket.Player.HasCondition(ConditionType.Paralyzed)) { conditionFlags |= 1 << 5; } if (playerConditionsPacket.Player.HasCondition(ConditionType.ChangedSpeed)) { conditionFlags |= 1 << 6; } if (playerConditionsPacket.Player.HasCondition(ConditionType.InFight)) { conditionFlags |= 1 << 7; } message.AddByte(conditionFlags); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is PlayerDeathPacket playerDeathPacket)) { this.Logger.Warning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(playerDeathPacket.PacketType.ToByte()); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is HeartbeatResponsePacket heartbeatResponsePacket)) { this.Logger.LogWarning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(heartbeatResponsePacket.PacketType.ToByte()); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is GameServerDisconnectPacket gameServerDisconnectPacket)) { this.Logger.Warning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(gameServerDisconnectPacket.PacketType.ToByte()); message.AddString(gameServerDisconnectPacket.Reason); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is PlayerCancelWalkPacket playerCancelWalkPacket)) { this.Logger.LogWarning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(playerCancelWalkPacket.PacketType.ToByte()); message.AddByte((byte)playerCancelWalkPacket.ResultingDirection.GetClientSafeDirection()); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is ContainerClosePacket containerClosePacket)) { this.Logger.LogWarning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(containerClosePacket.PacketType.ToByte()); message.AddByte(containerClosePacket.ContainerId); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is PlayerInventoryClearSlotPacket clearSlotPacket)) { this.Logger.LogWarning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(clearSlotPacket.PacketType.ToByte()); message.AddByte((byte)clearSlotPacket.Slot); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is MessageOfTheDayPacket messageOfTheDayPacket)) { this.Logger.Warning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(messageOfTheDayPacket.PacketType); message.AddString("1\n" + messageOfTheDayPacket.MessageOfTheDay); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is MapPartialDescriptionPacket mapPartialDescriptionPacket)) { this.Logger.Warning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(mapPartialDescriptionPacket.PacketType.ToByte()); message.AddBytes(mapPartialDescriptionPacket.DescriptionBytes); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is WorldLightPacket worldLightPacket)) { this.Logger.LogWarning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(worldLightPacket.PacketType.ToByte()); message.AddByte(worldLightPacket.Level); message.AddByte(worldLightPacket.Color); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is MagicEffectPacket magicEffectPacket)) { this.Logger.Warning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(magicEffectPacket.PacketType.ToByte()); message.AddLocation(magicEffectPacket.Location); message.AddByte((byte)magicEffectPacket.Effect); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is SquarePacket squarePacket)) { this.Logger.Warning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(squarePacket.PacketType.ToByte()); message.AddUInt32(squarePacket.OnCreatureId); message.AddByte((byte)squarePacket.Color); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is RemoveAtLocationPacket removeAtPositionPacket)) { this.Logger.LogWarning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(removeAtPositionPacket.PacketType.ToByte()); message.AddLocation(removeAtPositionPacket.Location); message.AddByte(removeAtPositionPacket.Stackpos); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is CreatureHealthPacket creatureHealthPacket)) { this.Logger.LogWarning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(creatureHealthPacket.PacketType.ToByte()); message.AddUInt32(creatureHealthPacket.Creature.Id); message.AddByte(creatureHealthPacket.Creature.Stats[CreatureStat.HitPoints].Percent); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is AddCreaturePacket addCreaturePacket)) { this.Logger.LogWarning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(addCreaturePacket.PacketType.ToByte()); message.AddLocation(addCreaturePacket.Creature.Location); message.AddCreature(addCreaturePacket.Creature, addCreaturePacket.AsKnown, addCreaturePacket.RemoveThisCreatureId); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is CreatureSkullPacket creatureSkullPacket)) { this.Logger.LogWarning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(creatureSkullPacket.PacketType.ToByte()); message.AddUInt32(creatureSkullPacket.Creature.Id); message.AddByte(0x00); // creatureSkullPacket.Creature.Skull }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is TextMessagePacket textMessagePacket)) { this.Logger.LogWarning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(textMessagePacket.PacketType.ToByte()); message.AddByte((byte)textMessagePacket.Type); message.AddString(textMessagePacket.Message); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is PlayerInventorySetSlotPacket setSlotPacket)) { this.Logger.Warning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(setSlotPacket.PacketType); message.AddByte((byte)setSlotPacket.Slot); message.AddItem(setSlotPacket.Item); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is MagicEffectPacket magicEffectPacket)) { this.Logger.LogWarning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } if (magicEffectPacket.Effect == AnimatedEffect.None) { return; } message.AddByte(magicEffectPacket.PacketType.ToByte()); message.AddLocation(magicEffectPacket.Location); byte valueToSend = magicEffectPacket.Effect switch { AnimatedEffect.XBlood => 0x01, AnimatedEffect.RingsBlue => 0x02, AnimatedEffect.Puff => 0x03, AnimatedEffect.SparkYellow => 0x04, AnimatedEffect.DamageExplosion => 0x05, AnimatedEffect.DamageMagicMissile => 0x06, AnimatedEffect.AreaFlame => 0x07, AnimatedEffect.RingsYellow => 0x08, AnimatedEffect.RingsGreen => 0x09, AnimatedEffect.XGray => 0x0A, AnimatedEffect.BubbleBlue => 0x0B, AnimatedEffect.DamageEnergy => 0x0C, AnimatedEffect.GlitterBlue => 0x0D, AnimatedEffect.GlitterRed => 0x0E, AnimatedEffect.GlitterGreen => 0x0F, AnimatedEffect.Flame => 0x10, AnimatedEffect.Poison => 0x11, AnimatedEffect.BubbleBlack => 0x12, AnimatedEffect.SoundGreen => 0x13, AnimatedEffect.SoundRed => 0x14, AnimatedEffect.DamageVenomMissile => 0x15, AnimatedEffect.SoundYellow => 0x16, AnimatedEffect.SoundPurple => 0x17, AnimatedEffect.SoundBlue => 0x18, AnimatedEffect.SoundWhite => 0x19, _ => 0x03, }; message.AddByte(valueToSend); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is CreatureSpeedChangePacket creatureSpeedChangePacket)) { this.Logger.Warning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(creatureSpeedChangePacket.PacketType); message.AddUInt32(creatureSpeedChangePacket.Creature.Id); message.AddUInt16(creatureSpeedChangePacket.Creature.Speed); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is PlayerConditionsPacket playerConditionsPacket)) { this.Logger.Warning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(playerConditionsPacket.PacketType); // TODO: implement contidions. message.AddByte(0x00); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is CreatureMovedPacket creatureMovedPacket)) { this.Logger.LogWarning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(creatureMovedPacket.PacketType.ToByte()); message.AddLocation(creatureMovedPacket.FromLocation); message.AddByte(creatureMovedPacket.FromStackpos); message.AddLocation(creatureMovedPacket.ToLocation); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is CreatureLightPacket creatureLightPacket)) { this.Logger.Warning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(creatureLightPacket.PacketType.ToByte()); message.AddUInt32(creatureLightPacket.Creature.Id); message.AddByte(creatureLightPacket.Creature.EmittedLightLevel); message.AddByte(creatureLightPacket.Creature.EmittedLightColor); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is MapDescriptionPacket mapDescriptionPacket)) { this.Logger.LogWarning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(mapDescriptionPacket.PacketType.ToByte()); message.AddLocation(mapDescriptionPacket.Origin); message.AddBytes(this.BuildDescription(mapDescriptionPacket.Player, mapDescriptionPacket.DescriptionTiles)); }
/// <summary> /// Writes a packet to the given <see cref="INetworkMessage"/>. /// </summary> /// <param name="packet">The packet to write.</param> /// <param name="message">The message to write into.</param> public override void WriteToMessage(IOutboundPacket packet, ref INetworkMessage message) { if (!(packet is ContainerUpdateItemPacket containerUpdateItemPacket)) { this.Logger.Warning($"Invalid packet {packet.GetType().Name} routed to {this.GetType().Name}"); return; } message.AddByte(containerUpdateItemPacket.PacketType); message.AddByte(containerUpdateItemPacket.ContainerId); message.AddByte(containerUpdateItemPacket.Index); message.AddItem(containerUpdateItemPacket.Item); }