Browse Source

Fix PlayerNetPack validation and tests

pull/6528/head
staphen 3 years ago committed by Anders Jenbo
parent
commit
4deae11871
  1. 13
      Source/pack.cpp
  2. 1
      test/pack_test.cpp

13
Source/pack.cpp

@ -590,12 +590,17 @@ bool UnPackNetPlayer(const PlayerNetPack &packed, Player &player)
player.InvGrid[i] = packed.InvGrid[i]; player.InvGrid[i] = packed.InvGrid[i];
for (int i = 0; i < MaxBeltItems; i++) { for (int i = 0; i < MaxBeltItems; i++) {
if (!UnPackNetItem(player, packed.SpdList[i], player.SpdList[i])) Item &item = player.SpdList[i];
if (!UnPackNetItem(player, packed.SpdList[i], item))
return false; return false;
if (player.SpdList[i].isEmpty()) if (item.isEmpty())
continue; continue;
auto loc = static_cast<int8_t>(player.GetItemLocation(player.SpdList[i])); Size beltItemSize = GetInventorySize(item);
ValidateField(loc, loc == ILOC_BELT); int8_t beltItemType = static_cast<int8_t>(item._itype);
bool beltItemUsable = item.isUsable();
ValidateFields(beltItemSize.width, beltItemSize.height, (beltItemSize == Size { 1, 1 }));
ValidateField(beltItemType, item._itype != ItemType::Gold);
ValidateField(beltItemUsable, beltItemUsable);
} }
CalcPlrInv(player, false); CalcPlrInv(player, false);

1
test/pack_test.cpp

@ -870,6 +870,7 @@ public:
{ {
Players.resize(2); Players.resize(2);
MyPlayer = &Players[0]; MyPlayer = &Players[0];
gbIsMultiplayer = true;
PlayerPack testPack { PlayerPack testPack {
0, 0, -1, 9, 0, 2, 61, 24, 0, 0, "MP-Warrior", 0, 120, 25, 60, 60, 37, 0, 85670061, 3921, 13568, 13568, 3904, 3904, 0, 0, -1, 9, 0, 2, 61, 24, 0, 0, "MP-Warrior", 0, 120, 25, 60, 60, 37, 0, 85670061, 3921, 13568, 13568, 3904, 3904,

Loading…
Cancel
Save