Skip to content
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 @@ -75,7 +75,7 @@
- [treq](../src/NosCore.Packets/ClientPackets/Event/TreqPacket.cs) *InGame*

### Exchanges
- [req_exc](../src/NosCore.Packets/ClientPackets/Exchanges/ExchangeRequestPacket.cs) *InGame*
- [req_exc](../src/NosCore.Packets/ClientPackets/Exchanges/ExchangeRequestPacket.cs) *InTrade | InGame*
- [exc_list](../src/NosCore.Packets/ClientPackets/Exchanges/ExcListPacket.cs) *InTrade | InGame*

### Families
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace NosCore.Packets.ClientPackets.Exchanges
{
[PacketHeader("req_exc", Scope.InGame)]
[PacketHeader("req_exc", Scope.InGame | Scope.InTrade)]
public class ExchangeRequestPacket : PacketBase
{
[PacketIndex(0)]
Expand Down
10 changes: 9 additions & 1 deletion src/NosCore.Packets/Deserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,15 @@ public IPacket Deserialize(string packetContent)
}
if (isMaxIndex && string.IsNullOrWhiteSpace(separator))
{
length = (sbyte)(matches.Length - currentIndex);
var remainingTokens = matches.Length - currentIndex;
// Sub-packets whose fields are space-separated span several tokens each
// (exc_list's "type slot amount"), so the item count is tokens / fields.
var subPacketCreator = typeof(IPacket).IsAssignableFrom(subType) && remainingTokens > 0
&& !matches[currentIndex].Contains(packetIndexAttribute.SpecialSeparator ?? ".")
? _packetDeserializerDictionary.Values.FirstOrDefault(s => s.PacketType == subType)
: null;
var tokensPerItem = subPacketCreator == null ? 1 : subPacketCreator.PropertyAmount + 1;
length = (sbyte)((remainingTokens + tokensPerItem - 1) / tokensPerItem);
}

if (!string.IsNullOrWhiteSpace(separator))
Expand Down
2 changes: 1 addition & 1 deletion src/NosCore.Packets/NosCore.Packets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<RepositoryUrl>https://github.com/NosCoreIO/NosCore.Packets.git</RepositoryUrl>
<PackageIconUrl></PackageIconUrl>
<PackageTags>nostale, noscore, chickenapi, nostale private server source, nostale emulator</PackageTags>
<Version>21.1.2</Version>
<Version>21.1.3</Version>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<Description>NosCore's Packets (Nostale packets) defined over classes</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
36 changes: 36 additions & 0 deletions test/NosCore.Packets.Tests/DeserializerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
// -----------------------------------

using NosCore.Packets.ClientPackets.Chat;
using NosCore.Packets.ClientPackets.Exchanges;
using NosCore.Packets.Attributes;
using System.Reflection;
using NosCore.Packets.ClientPackets.Inventory;
using NosCore.Packets.ClientPackets.Login;
using NosCore.Packets.ClientPackets.Movement;
Expand Down Expand Up @@ -63,6 +66,8 @@ public class DeserializerTest
typeof(CBListPacket),
typeof(CScalcPacket),
typeof(CreateFamilyPacket),
typeof(ExcListPacket),
typeof(ExcListSubPacket),
typeof(UnresolvedPacket)
});

Expand Down Expand Up @@ -495,5 +500,36 @@ public void PacketWithEmptySpecialSeparatorSplitsEachCharIntoField()
Assert.AreEqual((byte)3, packet.ArmorUpgradeRareSubPacket!.Upgrade);
Assert.AreEqual((sbyte)5, packet.ArmorUpgradeRareSubPacket.Rare);
}

[TestMethod]
public void DeserializeSpaceSeparatedSubPacketListYieldsOneItemPerSubPacket()
{
var packet = (ExcListPacket)Deserializer.Deserialize("exc_list 21 44 10 53 21 2 87 55");
Assert.AreEqual(21, packet.Gold);
Assert.AreEqual(44, packet.BankGold);
Assert.HasCount(2, packet.SubPackets!);
Assert.AreEqual(PocketType.Raid, packet.SubPackets![0]!.PocketType);
Assert.AreEqual(53, packet.SubPackets[0]!.Slot);
Assert.AreEqual(21, packet.SubPackets[0]!.Amount);
Assert.AreEqual(PocketType.Etc, packet.SubPackets[1]!.PocketType);
Assert.AreEqual(87, packet.SubPackets[1]!.Slot);
Assert.AreEqual(55, packet.SubPackets[1]!.Amount);
}

[TestMethod]
public void DeserializeSpaceSeparatedSubPacketListWithASingleSubPacket()
{
var packet = (ExcListPacket)Deserializer.Deserialize("exc_list 5000 0 0 3 2");
Assert.HasCount(1, packet.SubPackets!);
Assert.AreEqual(3, packet.SubPackets![0]!.Slot);
Assert.AreEqual(2, packet.SubPackets[0]!.Amount);
}

[TestMethod]
public void ExchangeRequestIsAcceptedWhileTrading()
{
var scopes = typeof(ExchangeRequestPacket).GetCustomAttribute<PacketHeaderAttribute>()!.Scopes;
Assert.IsTrue(scopes.HasFlag(Scope.InTrade));
}
}
}
Loading