Skip to content

Commit

Permalink
fix stack / fix fmt v10
Browse files Browse the repository at this point in the history
  • Loading branch information
MillhioreBT committed May 28, 2023
1 parent a18e701 commit 3b59b7f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/definitions.h
Expand Up @@ -47,6 +47,7 @@ static constexpr auto AUTHENTICATOR_PERIOD = 30U;
#pragma warning(disable : 4244) // 'argument' : conversion from 'type1' to 'type2', possible loss of data
#pragma warning(disable : 4250) // 'class1' : inherits 'class2::member' via dominance
#pragma warning(disable : 4267) // 'var' : conversion from 'size_t' to 'type', possible loss of data
#pragma warning(disable : 4275) // can be ignored in Visual C++ if you are deriving from a type in the C++ STL
#pragma warning(disable : 4319) // '~': zero extending 'unsigned int' to 'lua_Number' of greater size
#pragma warning(disable : 4351) // new behavior: elements of array will be default initialized
#pragma warning(disable : 4458) // declaration hides class member
Expand Down
8 changes: 4 additions & 4 deletions src/iomapserialize.cpp
Expand Up @@ -8,8 +8,6 @@
#include "bed.h"
#include "game.h"

#include <fmt/format.h>

extern Game g_game;

void IOMapSerialize::loadHouseItems(Map* map)
Expand Down Expand Up @@ -324,15 +322,17 @@ bool IOMapSerialize::saveHouseInfo()

std::string listText;
if (house->getAccessList(GUEST_LIST, listText) && !listText.empty()) {
if (!stmt.addRow(fmt::format("{:d}, {}, {:s}", house->getId(), GUEST_LIST, db.escapeString(listText)))) {
if (!stmt.addRow(fmt::format("{:d}, {}, {:s}", house->getId(), format_as(GUEST_LIST),
db.escapeString(listText)))) {
return false;
}

listText.clear();
}

if (house->getAccessList(SUBOWNER_LIST, listText) && !listText.empty()) {
if (!stmt.addRow(fmt::format("{:d}, {}, {:s}", house->getId(), SUBOWNER_LIST, db.escapeString(listText)))) {
if (!stmt.addRow(fmt::format("{:d}, {}, {:s}", house->getId(), format_as(SUBOWNER_LIST),
db.escapeString(listText)))) {
return false;
}

Expand Down
20 changes: 9 additions & 11 deletions src/protocolgame.cpp
Expand Up @@ -1740,16 +1740,16 @@ void ProtocolGame::sendCloseContainer(uint8_t cid)
writeToOutputBuffer(msg);
}

void ProtocolGame::sendCreatureTurn(const Creature* creature, uint32_t stackPos)
void ProtocolGame::sendCreatureTurn(const Creature* creature, uint32_t stackpos)
{
if (stackPos == -1 || stackPos >= MAX_STACKPOS_THINGS || !canSee(creature)) {
if (stackpos >= MAX_STACKPOS_THINGS || !canSee(creature)) {
return;
}

NetworkMessage msg;
msg.addByte(0x6B);
msg.addPosition(creature->getPosition());
msg.addByte(static_cast<uint8_t>(stackPos));
msg.addByte(static_cast<uint8_t>(stackpos));

msg.add<uint16_t>(0x63);
msg.add<uint32_t>(creature->getID());
Expand Down Expand Up @@ -1944,7 +1944,7 @@ void ProtocolGame::sendMapDescription(const Position& pos)

void ProtocolGame::sendAddTileItem(const Position& pos, uint32_t stackpos, const Item* item)
{
if (!canSee(pos)) {
if (stackpos >= MAX_STACKPOS_THINGS || !canSee(pos)) {
return;
}

Expand All @@ -1958,7 +1958,7 @@ void ProtocolGame::sendAddTileItem(const Position& pos, uint32_t stackpos, const

void ProtocolGame::sendUpdateTileItem(const Position& pos, uint32_t stackpos, const Item* item)
{
if (!canSee(pos)) {
if (stackpos >= MAX_STACKPOS_THINGS || !canSee(pos)) {
return;
}

Expand All @@ -1983,7 +1983,7 @@ void ProtocolGame::sendRemoveTileThing(const Position& pos, uint32_t stackpos)

void ProtocolGame::sendUpdateTileCreature(const Position& pos, uint32_t stackpos, const Creature* creature)
{
if (stackpos == -1 || stackpos >= MAX_STACKPOS_THINGS || !canSee(pos)) {
if (stackpos >= MAX_STACKPOS_THINGS || !canSee(pos)) {
return;
}

Expand Down Expand Up @@ -2037,7 +2037,7 @@ void ProtocolGame::sendAddCreature(const Creature* creature, const Position& pos
}

if (creature != player) {
if (stackpos != -1 && stackpos < MAX_STACKPOS_THINGS) {
if (stackpos < MAX_STACKPOS_THINGS) {
NetworkMessage msg;
msg.addByte(0x6A);
msg.addPosition(pos);
Expand Down Expand Up @@ -2103,9 +2103,7 @@ void ProtocolGame::sendMoveCreature(const Creature* creature, const Position& ne
const Position& oldPos, int32_t oldStackPos, bool teleport)
{
if (creature == player) {
if (oldStackPos >= MAX_STACKPOS_THINGS) {
sendMapDescription(newPos);
} else if (teleport) {
if (teleport || oldStackPos >= MAX_STACKPOS_THINGS) {
sendRemoveTileThing(oldPos, oldStackPos);
sendMapDescription(newPos);
} else {
Expand Down Expand Up @@ -2480,7 +2478,7 @@ void ProtocolGame::AddCreatureLight(NetworkMessage& msg, const Creature* creatur
// tile
void ProtocolGame::RemoveTileThing(NetworkMessage& msg, const Position& pos, uint32_t stackpos)
{
if (stackpos == -1 || stackpos >= MAX_STACKPOS_THINGS) {
if (stackpos >= MAX_STACKPOS_THINGS) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/protocolgame.h
Expand Up @@ -149,7 +149,7 @@ class ProtocolGame final : public Protocol
void sendCreatureHealth(const Creature* creature);
void sendSkills();
void sendPing();
void sendCreatureTurn(const Creature* creature, uint32_t stackPos);
void sendCreatureTurn(const Creature* creature, uint32_t stackpos);
void sendCreatureSay(const Creature* creature, SpeakClasses type, std::string_view text,
const Position* pos = nullptr);

Expand Down
13 changes: 3 additions & 10 deletions src/tile.cpp
Expand Up @@ -1204,24 +1204,18 @@ int32_t Tile::getStackposOfItem(const Player* player, const Item* item) const
for (auto it = items->getBeginTopItem(), end = items->getEndTopItem(); it != end; ++it) {
if (*it == item) {
return n;
} else if (++n == MAX_STACKPOS_THINGS) {
return -1;
}
++n;
}
} else {
n += items->getTopItemCount();
if (n >= MAX_STACKPOS_THINGS) {
return -1;
}
}
}

if (const CreatureVector* creatures = getCreatures()) {
for (const Creature* creature : *creatures) {
if (player->canSeeCreature(creature)) {
if (++n >= MAX_STACKPOS_THINGS) {
return -1;
}
++n;
}
}
}
Expand All @@ -1230,9 +1224,8 @@ int32_t Tile::getStackposOfItem(const Player* player, const Item* item) const
for (auto it = items->getBeginDownItem(), end = items->getEndDownItem(); it != end; ++it) {
if (*it == item) {
return n;
} else if (++n >= MAX_STACKPOS_THINGS) {
return -1;
}
++n;
}
}
return -1;
Expand Down
6 changes: 6 additions & 0 deletions src/tools.h
Expand Up @@ -76,4 +76,10 @@ int64_t OTSYS_TIME();

SpellGroup_t stringToSpellGroup(std::string_view value);

template <typename E>
auto format_as(E e)
{
return fmt::underlying(e);

Check failure on line 82 in src/tools.h

View workflow job for this annotation

GitHub Actions / ubuntu-Debug

‘underlying’ is not a member of ‘fmt’

Check failure on line 82 in src/tools.h

View workflow job for this annotation

GitHub Actions / ubuntu-Release

‘underlying’ is not a member of ‘fmt’
}

#endif

0 comments on commit 3b59b7f

Please sign in to comment.