Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
maattch committed Jan 24, 2025
1 parent b227678 commit 4ab84f3
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ void onInventoryUpdate(Player* player, Item* item, slots_t slot, bool equip)
scriptInterface.callVoidFunction(4);
}

void onNetworkMessage(Player* player, uint8_t recvByte, NetworkMessage* msg)
void onNetworkMessage(Player* player, uint8_t recvByte, NetworkMessage_ptr msg)
{
// Player:onNetworkMessage(recvByte, msg)
if (playerHandlers.onNetworkMessage == -1) {
Expand All @@ -1403,7 +1403,7 @@ void onNetworkMessage(Player* player, uint8_t recvByte, NetworkMessage* msg)

lua_pushnumber(L, recvByte);

tfs::lua::pushUserdata(L, msg);
tfs::lua::pushUserdata(L, msg.release());
tfs::lua::setMetatable(L, -1, "NetworkMessage");

scriptInterface.callVoidFunction(3);
Expand Down
4 changes: 2 additions & 2 deletions src/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include "const.h"
#include "creature.h"
#include "luascript.h"
#include "networkmessage.h"

class ItemType;
class NetworkMessage;
class Party;
class Spell;
class Tile;
Expand Down Expand Up @@ -83,7 +83,7 @@ void onLoseExperience(Player* player, uint64_t& exp);
void onGainSkillTries(Player* player, skills_t skill, uint64_t& tries);
void onWrapItem(Player* player, Item* item);
void onInventoryUpdate(Player* player, Item* item, slots_t slot, bool equip);
void onNetworkMessage(Player* player, uint8_t recvByte, NetworkMessage* msg);
void onNetworkMessage(Player* player, uint8_t recvByte, NetworkMessage_ptr msg);
bool onSpellCheck(Player* player, const Spell* spell);

} // namespace tfs::events::player
Expand Down
4 changes: 2 additions & 2 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5548,14 +5548,14 @@ void Game::parsePlayerExtendedOpcode(uint32_t playerId, uint8_t opcode, const st
}
}

void Game::parsePlayerNetworkMessage(uint32_t playerId, uint8_t recvByte, NetworkMessage* msg)
void Game::parsePlayerNetworkMessage(uint32_t playerId, uint8_t recvByte, NetworkMessage_ptr msg)
{
Player* player = getPlayerByID(playerId);
if (!player) {
return;
}

tfs::events::player::onNetworkMessage(player, recvByte, msg);
tfs::events::player::onNetworkMessage(player, recvByte, std::move(msg));
}

std::vector<Item*> Game::getMarketItemList(uint16_t wareId, uint16_t sufficientCount, Player& player)
Expand Down
2 changes: 1 addition & 1 deletion src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ class Game
void playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16_t counter, uint16_t amount);

void parsePlayerExtendedOpcode(uint32_t playerId, uint8_t opcode, const std::string& buffer);
void parsePlayerNetworkMessage(uint32_t playerId, uint8_t recvByte, NetworkMessage* msg);
void parsePlayerNetworkMessage(uint32_t playerId, uint8_t recvByte, NetworkMessage_ptr msg);

std::vector<Item*> getMarketItemList(uint16_t wareId, uint16_t sufficientCount, Player& player);

Expand Down
3 changes: 3 additions & 0 deletions src/networkmessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
class Item;
struct Position;

class NetworkMessage;
using NetworkMessage_ptr = std::unique_ptr<NetworkMessage>;

class NetworkMessage
{
public:
Expand Down
4 changes: 3 additions & 1 deletion src/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,10 @@ void ProtocolGame::parsePacket(NetworkMessage& msg)
// case 0xFE: break; // store window history 2

default:
// we cannot pass an unique_ptr as capture here because
// std::function requires the callable object to be *copyable*
g_dispatcher.addTask([=, playerID = player->getID(), msg = new NetworkMessage(msg)]() {
g_game.parsePlayerNetworkMessage(playerID, recvbyte, msg);
g_game.parsePlayerNetworkMessage(playerID, recvbyte, NetworkMessage_ptr(msg));
});
break;
}
Expand Down

0 comments on commit 4ab84f3

Please sign in to comment.