[core] Deprecate PacketGuard, refactor C2S#9796
Conversation
|
✨ Hello and thanks for the PR! ✨ 🤖: This is a friendly automated reminder that the maintainers won't look at your PR until you've properly completed all of the checkboxes in the pre-filled template. |
82bcc7f to
af90c7f
Compare
| -- Packets not listed here have no rate limit. | ||
| -- You should rate limit any packet that a player can send at will that results in | ||
| -- an immediate database hit or generates logs or results in file or network io. | ||
| PACKET_RATE_LIMITS = |
There was a problem hiding this comment.
I would probably push this to it's own settings file, or into network - your choice (or do neither)
| #include "magic_enum/magic_enum_containers.hpp" | ||
|
|
||
| using namespace magic_enum::bitwise_operators; |
There was a problem hiding this comment.
Do these have to live down here? Could/should we have a general enums.h header which self-includes the other actual enum files, and then does this include voodoo at the end?
There was a problem hiding this comment.
I'll leave it like that for the time being but I think enums.h is a good idea for a future refactor.
| // Not implemented. | ||
| return PacketValidator(); | ||
| return PacketValidator(PChar) | ||
| .blockedBy({ BlockedState::InEvent }); |
| return PacketValidator() | ||
| return PacketValidator(PChar) | ||
| .oneOf<GP_CLI_COMMAND_ACTION_ACTIONID>(this->ActionID) | ||
| .custom([&](PacketValidator& pv) |
There was a problem hiding this comment.
If you put the lambda on a new line, you can redule the indentation a bit:
.custom(
[](...
| .isNotFishing(PChar) // Note: It is possible to attack while fishing on retail and is disabled here on purpose. | ||
| .isNotPreventedAction(PChar); | ||
| // Note: It is possible to attack while fishing on retail and is disabled here on purpose. | ||
| pv.blockedBy({ BlockedState::Healing, BlockedState::Sitting, BlockedState::Crafting, BlockedState::Fishing, BlockedState::PreventAction }); |
| SmallPD_Type = (ref<uint16>(SmallPD_ptr, 0) & 0x1FF); | ||
|
|
||
| if (PacketSize[SmallPD_Type] == SmallPD_Size || PacketSize[SmallPD_Type] == 0) // Tests incoming packets for the correct size prior to processing | ||
| if ((ref<uint16>(SmallPD_ptr, 2) <= PSession->client_packet_id) || (ref<uint16>(SmallPD_ptr, 2) > SmallPD_Code)) |
There was a problem hiding this comment.
Loving the reduction in this file 👍
| } | ||
|
|
||
| auto timeNow = timer::now(); | ||
| const auto lastPacketReceived = PChar->m_PacketRecievedTimestamps.emplace(packetId, timeNow); |
There was a problem hiding this comment.
Use structured bindings here
|
|
||
| void PacketParserInitialize() | ||
| // cppcheck-suppress templateRecursion | ||
| consteval auto buildPacketHandlers() -> std::array<PacketHandler, 512> |
- Size checks are enforced for all packets in the handlers and automatically determined from structures - Adds missing padding to a handful of packets - Introduce a flag-driven BlockedState mechanism for packet validation - Rate limit values loaded from settings and handled by PacketSystem - PacketHandlers global array is no longer accessible
af90c7f to
8267b4f
Compare
Should be good to go after another review |

I affirm:
What does this pull request do?
BlockedStatemechanism for packet validationPacketSystemOnIncomingPacketin your modulesPacketValidationnow takes PChar since it's used by several validatorsPacketValidationnow short-circuits on all checksthis->everywhereSteps to test these changes
Need to test size some more and uplift several modules: