Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix item packets when otcv8 is active. #629

Merged
merged 3 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public interface IConnection
string Ip { get; }
long TimeStamp { get; }
byte RandomNumber { get; }
ushort OtcV8Version { get; set; }

event EventHandler<IConnectionEventArgs> OnProcessEvent;
event EventHandler<IConnectionEventArgs> OnCloseEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface INetworkMessage : IReadOnlyNetworkMessage
void AddUInt32(uint value);
void WriteUint32(uint value, int position);
byte[] AddHeader(bool addChecksum = true);
void AddItem(IItem item);
void AddItem(IItem item, bool showItemDescription = false);
void AddLocation(Location location);
void AddLength();
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ public void Execute(IPlayer player, ContainerOperation operation, byte container
connection.OutgoingPackets.Enqueue(new RemoveItemContainerPacket(containerId, slotIndex, item));
break;
case ContainerOperation.ItemAdded:
connection.OutgoingPackets.Enqueue(new AddItemContainerPacket(containerId, item));
connection.OutgoingPackets.Enqueue(new AddItemContainerPacket(containerId, item)
{
ShowItemDescription = connection.OtcV8Version > 0
});
break;
case ContainerOperation.ItemUpdated:
connection.OutgoingPackets.Enqueue(new UpdateItemContainerPacket(containerId, slotIndex, item));
connection.OutgoingPackets.Enqueue(new UpdateItemContainerPacket(containerId, slotIndex, item)
{
ShowItemDescription = connection.OtcV8Version > 0
});
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ private void SendContainerPacket(IPlayer player, byte containerId, IContainer co
{
if (!game.CreatureManager.GetPlayerConnection(player.CreatureId, out var connection)) return;

connection.OutgoingPackets.Enqueue(new OpenContainerPacket(container, containerId));
connection.OutgoingPackets.Enqueue(new OpenContainerPacket(container, containerId)
{
WithDescription = connection.OtcV8Version > 0
});
connection.Send();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public void Execute(IInventory inventory, IItem item, Slot slot, byte amount = 1

if (!game.CreatureManager.GetPlayerConnection(player.CreatureId, out var connection)) return;

connection.OutgoingPackets.Enqueue(new PlayerInventoryItemPacket(player.Inventory, slot));
connection.OutgoingPackets.Enqueue(new PlayerInventoryItemPacket(player.Inventory, slot)
{
ShowItemDescription = connection.OtcV8Version > 0
});

if (player.Shopping)
connection.OutgoingPackets.Enqueue(new SaleItemListPacket(player,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ private void SendPacketsToPlayer(IPlayer player, IConnection connection)
connection.OutgoingPackets.Enqueue(new SelfAppearPacket(player));
connection.OutgoingPackets.Enqueue(new MapDescriptionPacket(player, map));
connection.OutgoingPackets.Enqueue(new MagicEffectPacket(player.Location, EffectT.BubbleBlue));
connection.OutgoingPackets.Enqueue(new PlayerInventoryPacket(player.Inventory));
connection.OutgoingPackets.Enqueue(new PlayerInventoryPacket(player.Inventory)
{
ShowItemDescription = connection.OtcV8Version > 0
});
connection.OutgoingPackets.Enqueue(new PlayerStatusPacket(player));
connection.OutgoingPackets.Enqueue(new PlayerSkillsPacket(player));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public void Execute(TradeRequest tradeRequest)
out var playerRequestedConnection);

playerRequestingConnection.OutgoingPackets.Enqueue(new TradeRequestPacket(tradeRequest.PlayerRequesting.Name,
tradeRequest.Items));
tradeRequest.Items)
{
ShowItemDescription = playerRequestingConnection.OtcV8Version > 0
});

SendTradeMessage(tradeRequest, playerRequestedConnection);

Expand Down Expand Up @@ -55,9 +58,15 @@ private static void SendAcknowledgeTradeToBothPlayers(TradeRequest tradeRequest,
var items = SafeTradeSystem.GetTradedItems(tradeRequest.PlayerRequested);

playerRequestingConnection.OutgoingPackets.Enqueue(new TradeRequestPacket(tradeRequest.PlayerRequested.Name,
items, true));
items, true)
{
ShowItemDescription = playerRequestingConnection.OtcV8Version > 0
});

playerRequestedConnection.OutgoingPackets.Enqueue(new TradeRequestPacket(tradeRequest.PlayerRequesting.Name,
tradeRequest.Items, true));
tradeRequest.Items, true)
{
ShowItemDescription = playerRequestedConnection.OtcV8Version > 0
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ private async Task Connect(IConnection connection, PlayerLogInPacket packet)
Disconnect(connection, "Your account is banned.");
return;
}


connection.OtcV8Version = packet.OtcV8Version;

_game.Dispatcher.AddEvent(new Event(() =>
{
var result = _playerLogInCommand.Execute(playerRecord, connection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ private bool Closed
public long LastPingResponse { get; set; }
public long TimeStamp { get; }
public byte RandomNumber { get; }
public ushort OtcV8Version { get; set; }
public event EventHandler<IConnectionEventArgs> OnProcessEvent;
public event EventHandler<IConnectionEventArgs> OnCloseEvent;
public event EventHandler<IConnectionEventArgs> OnPostProcessEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,17 @@ public void AddString(string value)
/// Inserts item object into the buffer.
/// </summary>
/// <param name="item"></param>
public void AddItem(IItem item)
public void AddItem(IItem item, bool showItemDescription = false)
{
if (item == null)
//todo log
return;

AddBytes(item.GetRaw().ToArray());
if (showItemDescription)
{
AddString("");
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ public class AddItemContainerPacket : OutgoingPacket
{
private readonly byte containerId;
private readonly IItem item;
public required bool ShowItemDescription { get; init; }

public AddItemContainerPacket(byte containerId, IItem item)
{
this.containerId = containerId;
this.item = item;
}


public override void WriteToMessage(INetworkMessage message)
{
message.AddByte((byte)GameOutgoingPacketType.ContainerAddItem);

message.AddByte(containerId);
message.AddItem(item);
message.AddItem(item, ShowItemDescription);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ public UpdateItemContainerPacket(byte containerId, byte slot, IItem item)
this.slot = slot;
}

public required bool ShowItemDescription { get; init; }

public override void WriteToMessage(INetworkMessage message)
{
message.AddByte((byte)GameOutgoingPacketType.ContainerUpdateItem);

message.AddByte(containerId);
message.AddByte(slot);
message.AddItem(item);
message.AddItem(item, ShowItemDescription);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class OpenContainerPacket : OutgoingPacket
{
private readonly IContainer container;
private readonly byte containerId;
public required bool WithDescription { get; init; }

public OpenContainerPacket(IContainer container, byte containerId)
{
Expand All @@ -20,14 +21,14 @@ public override void WriteToMessage(INetworkMessage message)
message.AddByte((byte)GameOutgoingPacketType.ContainerOpen);

message.AddByte(containerId);
message.AddItem(container);
message.AddItem(container, WithDescription);
message.AddString(container.Name);
message.AddByte(container.Capacity);

message.AddByte(container.HasParent ? (byte)0x01 : (byte)0x00);

message.AddByte(Math.Min((byte)0xFF, container.SlotsUsed));

for (byte i = 0; i < container.SlotsUsed; i++) message.AddItem(container.Items[i]);
for (byte i = 0; i < container.SlotsUsed; i++) message.AddItem(container.Items[i], WithDescription);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class PlayerInventoryItemPacket : OutgoingPacket
{
private readonly IInventory inventory;
private readonly Slot slot;
public required bool ShowItemDescription { get; init; }

public PlayerInventoryItemPacket(IInventory inventory, Slot slot)
{
Expand All @@ -26,7 +27,7 @@ public override void WriteToMessage(INetworkMessage message)
{
message.AddByte((byte)GameOutgoingPacketType.InventoryItem);
message.AddByte((byte)slot);
message.AddItem(inventory[slot]);
message.AddItem(inventory[slot], ShowItemDescription);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace NeoServer.Networking.Packets.Outgoing.Player;
public class PlayerInventoryPacket : OutgoingPacket
{
private readonly IInventory inventory;
public required bool ShowItemDescription { get; init; }

public PlayerInventoryPacket(IInventory inventory)
{
Expand All @@ -27,7 +28,7 @@ public override void WriteToMessage(INetworkMessage message)
{
message.AddByte((byte)GameOutgoingPacketType.InventoryItem);
message.AddByte((byte)slot);
message.AddItem(inventory[slot]);
message.AddItem(inventory[slot], ShowItemDescription);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public TradeRequestPacket(string playerName, IItem[] items, bool acknowledged =
private string PlayerName { get; }
private IItem[] Items { get; }
private bool Acknowledged { get; }

public required bool ShowItemDescription { get; init; }
public void WriteToMessage(INetworkMessage message)
{
message.AddByte(Acknowledged
Expand All @@ -25,6 +25,6 @@ public void WriteToMessage(INetworkMessage message)
message.AddString(PlayerName);

message.AddByte((byte)Items.Length);
foreach (var item in Items) message.AddItem(item);
foreach (var item in Items) message.AddItem(item, ShowItemDescription);
}
}
Loading