Skip to content
Open
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
16 changes: 13 additions & 3 deletions Source/msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
#ifdef USE_SDL3
#include <SDL3/SDL_timer.h>
#else
#include <SDL.h>

Check warning on line 17 in Source/msg.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/msg.cpp:17:1 [misc-include-cleaner]

included header SDL.h is not used directly
#endif

#include <ankerl/unordered_dense.h>
#include <fmt/format.h>

Check warning on line 21 in Source/msg.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/msg.cpp:21:1 [misc-include-cleaner]

included header format.h is not used directly

#if !defined(UNPACKED_MPQS) || !defined(UNPACKED_SAVES) || !defined(NONET)
#define USE_PKWARE
Expand All @@ -28,7 +28,7 @@
#include "DiabloUI/diabloui.h"
#include "automap.h"
#include "config.h"
#include "control/control.hpp"

Check warning on line 31 in Source/msg.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/msg.cpp:31:1 [misc-include-cleaner]

included header control.hpp is not used directly
#include "dead.h"
#include "engine/backbuffer_state.hpp"
#include "engine/random.hpp"
Expand All @@ -44,7 +44,7 @@
#include "monsters/validation.hpp"
#include "nthread.h"
#include "objects.h"
#include "options.h"

Check warning on line 47 in Source/msg.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/msg.cpp:47:1 [misc-include-cleaner]

included header options.h is not used directly
#include "pack.h"
#include "pfile.h"
#include "player.h"
Expand All @@ -59,7 +59,7 @@
#include "utils/endian_swap.hpp"
#include "utils/is_of.hpp"
#include "utils/language.h"
#include "utils/str_cat.hpp"

Check warning on line 62 in Source/msg.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/msg.cpp:62:1 [misc-include-cleaner]

included header str_cat.hpp is not used directly
#include "utils/str_split.hpp"
#include "utils/utf8.hpp"

Expand All @@ -83,20 +83,20 @@

namespace devilution {

void EventFailedPacket(const char *playerName)

Check warning on line 86 in Source/msg.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/msg.cpp:86:6 [misc-use-internal-linkage]

function 'EventFailedPacket' can be made static or moved into an anonymous namespace to enforce internal linkage
{
const std::string message = fmt::format("Player '{}' sent an invalid packet.", playerName);

Check warning on line 88 in Source/msg.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/msg.cpp:88:35 [misc-include-cleaner]

no header providing "fmt::format" is directly included

Check warning on line 88 in Source/msg.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/msg.cpp:88:13 [misc-include-cleaner]

no header providing "std::string" is directly included
EventPlrMsg(message);
}

template <typename T>
void LogFailedPacket(const char *condition, const char *name, T value)

Check warning on line 93 in Source/msg.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/msg.cpp:93:6 [misc-use-internal-linkage]

function 'LogFailedPacket' can be made static or moved into an anonymous namespace to enforce internal linkage
{
LogDebug("Remote player packet validation failed: ValidateField({}: {}, {})", name, value, condition);
}

template <typename T1, typename T2>
void LogFailedPacket(const char *condition, const char *name1, T1 value1, const char *name2, T2 value2)

Check warning on line 99 in Source/msg.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/msg.cpp:99:6 [misc-use-internal-linkage]

function 'LogFailedPacket' can be made static or moved into an anonymous namespace to enforce internal linkage
{
LogDebug("Remote player packet validation failed: ValidateFields({}: {}, {}: {}, {})", name1, value1, name2, value2, condition);
}
Expand Down Expand Up @@ -2164,15 +2164,25 @@

size_t OnChangeInventoryItems(const TCmdChItem &message, Player &player)
{
if (message.bLoc >= InventoryGridCells)
const uint8_t topLeft = message.bLoc;
if (topLeft >= InventoryGridCells)
return sizeof(message);

if (gbBufferMsgs == 1) {
BufferMessage(player, &message, sizeof(message));
} else if (&player != MyPlayer && IsItemAvailable(static_cast<_item_indexes>(Swap16LE(message.def.wIndx)))) {
Item item {};
RecreateItem(player, message, item);
CheckInvSwap(player, item, message.bLoc);

const Size itemSize = GetInventorySize(item);
const int invPitch = InventorySizeInSlots.width;
const int verticalShift = itemSize.width - 1;
const int horizontalShift = itemSize.height - 1;
const uint8_t bottomRight = static_cast<uint8_t>(topLeft + invPitch * verticalShift + horizontalShift);
if (bottomRight >= InventoryGridCells)
return sizeof(message);

CheckInvSwap(player, item, topLeft);
}

return sizeof(message);
Expand Down Expand Up @@ -3228,7 +3238,7 @@
return;

for (int j = 0; j < InventoryGridCells; j++) {
if (player.InvGrid[j] == invListIndex + 1) {
if (std::abs(player.InvGrid[j]) == invListIndex + 1) {
NetSendCmdChInvItem(false, j);
break;
}
Expand Down
Loading