Skip to content

Commit

Permalink
packet send hook can no longer return new packet
Browse files Browse the repository at this point in the history
  • Loading branch information
Rochet2 committed Mar 14, 2016
1 parent 0023631 commit 4cd17fd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 23 deletions.
5 changes: 0 additions & 5 deletions GlobalMethods.h
Expand Up @@ -1880,13 +1880,8 @@ namespace LuaGlobalFunctions
switch (banMode)
{
case BAN_ACCOUNT:
#ifdef CATA
if (!Utf8ToUpperOnlyLatin(nameOrIP))
return 0;
#else
if (!AccountMgr::normalizeString(nameOrIP))
return 0;
#endif
break;
case BAN_CHARACTER:
if (!normalizePlayerName(nameOrIP))
Expand Down
6 changes: 3 additions & 3 deletions LuaEngine.h
Expand Up @@ -402,9 +402,9 @@ class Eluna
void OnSpawn(GameObject* gameobject);

/* Packet */
bool OnPacketSend(WorldSession* session, WorldPacket& packet);
void OnPacketSendAny(Player* player, WorldPacket& packet, bool& result);
void OnPacketSendOne(Player* player, WorldPacket& packet, bool& result);
bool OnPacketSend(WorldSession* session, const WorldPacket& packet);
void OnPacketSendAny(Player* player, const WorldPacket& packet, bool& result);
void OnPacketSendOne(Player* player, const WorldPacket& packet, bool& result);
bool OnPacketReceive(WorldSession* session, WorldPacket& packet);
void OnPacketReceiveAny(Player* player, WorldPacket& packet, bool& result);
void OnPacketReceiveOne(Player* player, WorldPacket& packet, bool& result);
Expand Down
22 changes: 7 additions & 15 deletions PacketHooks.cpp
Expand Up @@ -29,7 +29,7 @@ using namespace Hooks;
return;\
LOCK_ELUNA

bool Eluna::OnPacketSend(WorldSession* session, WorldPacket& packet)
bool Eluna::OnPacketSend(WorldSession* session, const WorldPacket& packet)
{
bool result = true;
Player* player = NULL;
Expand All @@ -39,7 +39,7 @@ bool Eluna::OnPacketSend(WorldSession* session, WorldPacket& packet)
OnPacketSendOne(player, packet, result);
return result;
}
void Eluna::OnPacketSendAny(Player* player, WorldPacket& packet, bool& result)
void Eluna::OnPacketSendAny(Player* player, const WorldPacket& packet, bool& result)
{
START_HOOK_SERVER(SERVER_EVENT_ON_PACKET_SEND);
Push(new WorldPacket(packet));
Expand All @@ -48,22 +48,18 @@ void Eluna::OnPacketSendAny(Player* player, WorldPacket& packet, bool& result)

while (n > 0)
{
int r = CallOneFunction(n--, 2, 2);
int r = CallOneFunction(n--, 2, 1);

if (lua_isboolean(L, r + 0) && !lua_toboolean(L, r + 0))
result = false;

if (lua_isuserdata(L, r + 1))
if (WorldPacket* data = CHECKOBJ<WorldPacket>(L, r + 1, false))
packet = *data;

lua_pop(L, 2);
lua_pop(L, 1);
}

CleanUpStack(2);
}

void Eluna::OnPacketSendOne(Player* player, WorldPacket& packet, bool& result)
void Eluna::OnPacketSendOne(Player* player, const WorldPacket& packet, bool& result)
{
START_HOOK_PACKET(PACKET_EVENT_ON_PACKET_SEND, packet.GetOpcode());
Push(new WorldPacket(packet));
Expand All @@ -72,16 +68,12 @@ void Eluna::OnPacketSendOne(Player* player, WorldPacket& packet, bool& result)

while (n > 0)
{
int r = CallOneFunction(n--, 2, 2);
int r = CallOneFunction(n--, 2, 1);

if (lua_isboolean(L, r + 0) && !lua_toboolean(L, r + 0))
result = false;

if (lua_isuserdata(L, r + 1))
if (WorldPacket* data = CHECKOBJ<WorldPacket>(L, r + 1, false))
packet = *data;

lua_pop(L, 2);
lua_pop(L, 1);
}

CleanUpStack(2);
Expand Down

3 comments on commit 4cd17fd

@anzz1
Copy link
Contributor

@anzz1 anzz1 commented on 4cd17fd Jan 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but why not? i was scratching my head over this for a long time because the docs still say that "can return false, newpacket" dang

@Rochet2
Copy link
Member Author

@Rochet2 Rochet2 commented on 4cd17fd Jan 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a hunch it was related to the WorldPacket in core code being const. https://github.com/ElunaLuaEngine/ElunaTrinityWotlk/blob/25fd1d1991743baaf3be1407b98db2617279361c/src/server/game/Server/WorldSession.cpp#L209
You can try to send a new packet anyways and it would work just fine - I believe,
I guess the documentation should be changed then if it still says it can return new packet. I also see some other things that should be changed with these hooks, need to take a look at them later.

@anzz1
Copy link
Contributor

@anzz1 anzz1 commented on 4cd17fd Jan 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick reply :)
yeah , i did just that and it worked fine at least in TC-3.3.5, just have to add a variable to skip the hook before sending to not make a infinite loop
https://github.com/anzz1/ElunaLuaScripts/blob/main/fix_custom_trainers.lua

Please sign in to comment.