Skip to content

feat: selective packet disabling#3804

Open
Zbizu wants to merge 16 commits into
opentibiabr:mainfrom
Zbizu:packets1500
Open

feat: selective packet disabling#3804
Zbizu wants to merge 16 commits into
opentibiabr:mainfrom
Zbizu:packets1500

Conversation

@Zbizu

@Zbizu Zbizu commented Jan 14, 2026

Copy link
Copy Markdown
Contributor

Description

Adds definitions to selectively disable packets.
This is very useful for when you have problems with the game client crashing on login to identify the cause.

IMPORTANT: This PR tagets the branch dudantas/feat-monk and will merge to it when accepted
I used that branch as a base for this pr because #3794 involves big protocolgame changes. If I used main branch, either this pr or 3794 would have to remade to fix merge conflicts.
Before merging, ensure that you have everything pushed to 3794.
After merging do a pull on your local repository in order to work on updated version of this branch.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested

  • I compiled it with all options disabled, and later with all options enabled

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I checked the PR checks reports
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works

Summary by CodeRabbit

  • New Features

    • Added passive cooldown reporting for abilities.
    • Introduced compile-time protocol feature flags to optionally disable protocol/UI packet groups.
  • Improvements

    • Refined monk state messaging and condition notifications.
    • Improved cooldown emission logic and pause handling.
    • Enhanced imbuement window behavior and bestiary/creature data sending.

dudantas and others added 8 commits January 10, 2026 16:14
There are some monk behaviors that are not reflecting reality.

I also took the opportunity to align the wording with tibia official
terms for monk harmony manipulation: spend and build.

- The whole party is being healed
- Spender spells are not healing
- Spenders are not building, when using harmony virtue
- Harmony healing is constant, regardless of how many charges are being
built

- Spenders also heals
- Spenders should also build, when using harmony virtue
- Party healing impacts only the lower-health player, not the whole
party
- Harmony passive healing is proportional to the amount of harmony
built/spent

Co-Authored-By: murilo09 <78226931+murilo09@users.noreply.github.com>
Co-Authored-By: Pedro Cruz <phac@cin.ufpe.br>
Co-Authored-By: Felipe <87909998+FelipePaluco@users.noreply.github.com>
Co-Authored-By: Vava <110659678+vavasz@users.noreply.github.com>
Replaced static Spectators::find call with instance method and updated callback execution to remove redundant argument. This improves code clarity and aligns with updated Spectators and callback APIs.
@coderabbitai

coderabbitai Bot commented Jan 14, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Protocol messaging was reorganized: several send helpers were renamed (e.g., sendMonkDatasendMonkState), a new sendPassiveCooldown path was added and used by Gift of Life, and many packet emissions were wrapped with optional PROTOCOL_DISABLE_* compile-time guards (plus a commented feature-flag template).

Changes

Monk State Messaging

Layer / File(s) Summary
Data Shape / API
src/creatures/players/player.hpp, src/server/network/protocol/protocolgame.hpp
Renamed sendMonkData(...)sendMonkState(...) in Player and ProtocolGame declarations.
Callsites / Logic
src/creatures/combat/condition.cpp, src/creatures/players/player.cpp
Replaced calls to sendMonkData(...) with sendMonkState(...) for Serenity, Virtue, Harmony updates and related flows.
Protocol Emission
src/server/network/protocol/protocolgame.cpp
Renamed and updated protocol helper for monk state emission and adjusted login/send paths to call the new symbol; wrapped emission with #ifndef PROTOCOL_DISABLE_MONK_STATES.

Passive Cooldown System

Layer / File(s) Summary
API Addition
src/creatures/players/player.hpp, src/creatures/players/player.cpp, src/server/network/protocol/protocolgame.hpp
Added sendPassiveCooldown(uint8_t passiveId, uint32_t currentCooldown, uint32_t maxCooldown, bool paused) to Player and ProtocolGame and implemented forwarding to client.
Wiring / Caller Update
src/creatures/players/components/wheel/player_wheel.cpp
Replaced manual NetworkMessage construction for Gift of Life cooldown with a call to m_player.sendPassiveCooldown(1, ...); computed paused from zone/infight conditions.

Bestiary & Imbuement APIs

Layer / File(s) Summary
API Renames
src/creatures/players/player.hpp, src/server/network/protocol/protocolgame.hpp
Renamed bestiary/imbuement methods: parseBestiarySendRaces()sendBestiaryRaces(), parseBestiarysendMonsterData()parseSendBestiaryMonsterData(), openImbuementWindow()sendOpenImbuementWindow(), and capitalized several helper names (e.g., AddImbuementInfo, AddPodiumDetails).
Callsites / Protocol
src/creatures/players/player.cpp, src/server/network/protocol/protocolgame.cpp
Updated call sites and dispatchers to new names and adjusted logging strings accordingly; some bestiary/bestiary-monster paths gated by PROTOCOL_DISABLE_BESTIARY.

Protocol Feature Guards & Helper Renames

Layer / File(s) Summary
Feature-flag template
src/utils/definitions.hpp
Added a large commented block of #define PROTOCOL_DISABLE_* feature flags organized by category (commented-out only).
Compilation Guards
src/server/network/protocol/protocolgame.cpp, src/creatures/players/player.cpp
Wrapped many packet emission paths and client writes with #ifndef PROTOCOL_DISABLE_* macros (e.g., Lua messages, hunting tasks, analytics, chat, bosstiary, outfit/OTCR features).
Naming / Helper Normalization
src/server/network/protocol/protocolgame.cpp, src/server/network/protocol/protocolgame.hpp
Renamed many protocol helpers for consistent capitalization and naming (e.g., addBlessAddBlessings, sendForgeSkillStatsAddForgeSkillStats, addCreatureIconAddCreatureIcon, sendOutfitWindowCustomOTCRaddOutfitWindowFeaturesOTCR, sendBosstiarySlotsBytesaddBossSlotInfo).

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested labels

Stale

Suggested reviewers

  • dudantas
  • vllsystems
  • majestyotbr

Poem

🐰 I nibble names and patch the stream,
Monk states now whisper through the dream,
A passive cooldown hums in tune,
Flags commented under the moon,
Hooray — the rabbit hops, code clean! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.46% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat: selective packet disabling' clearly summarizes the main objective: adding feature flags to selectively disable protocol packets to help debug client crashes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dudantas dudantas deleted the branch opentibiabr:main February 13, 2026 02:03
@dudantas dudantas closed this Feb 13, 2026
@dudantas dudantas reopened this Feb 13, 2026
@dudantas dudantas changed the base branch from dudantas/feat-monk to main February 13, 2026 02:13

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/server/network/protocol/protocolgame.cpp (2)

3450-3466: ⚠️ Potential issue | 🟠 Major

Ensure PROTOCOL_DISABLE_UPDATE_ICONS suppresses icon payload in AddCreature

AddCreatureIcon is still invoked during creature add, so icon bytes are still emitted even when PROTOCOL_DISABLE_UPDATE_ICONS is defined. This defeats selective disabling (and could still trigger the crash you’re isolating). Consider sending a zero count when the feature is disabled so the packet layout stays valid.

🧩 Suggested fix (keep field, but zero it when disabled)
 void ProtocolGame::AddCreatureIcon(NetworkMessage &msg, const std::shared_ptr<Creature> &creature) {
-
-	if (!creature || !player || oldProtocol) {
+	if (oldProtocol) {
 		return;
 	}
+#ifdef PROTOCOL_DISABLE_UPDATE_ICONS
+	msg.addByte(0);
+	return;
+#endif
+	if (!creature || !player) {
+		return;
+	}
 
 	const auto icons = creature->getIcons();
 	// client only supports 3 icons, otherwise it will crash
 	const auto count = icons.size() > 3 ? 3 : icons.size();
 	msg.addByte(count);

Also applies to: 8425-8426


8722-8750: ⚠️ Potential issue | 🟠 Major

Guard null imbuement lookups to avoid crashes

getImbuement/getBaseByID/getCategoryByID are dereferenced without null checks. If data is invalid or mismatched (e.g., DB corruption), this becomes a hard crash. Consider early returns with logging.

🛡️ Suggested null-guard
 void ProtocolGame::AddImbuementInfo(NetworkMessage &msg, uint16_t imbuementId) const {
 	Imbuement* imbuement = g_imbuements().getImbuement(imbuementId);
+	if (!imbuement) {
+		g_logger().warn("[ProtocolGame::AddImbuementInfo] Unknown imbuement id {}", imbuementId);
+		return;
+	}
 	const BaseImbuement* baseImbuement = g_imbuements().getBaseByID(imbuement->getBaseID());
 	const CategoryImbuement* categoryImbuement = g_imbuements().getCategoryByID(imbuement->getCategory());
+	if (!baseImbuement || !categoryImbuement) {
+		g_logger().warn("[ProtocolGame::AddImbuementInfo] Missing base/category for imbuement id {}", imbuementId);
+		return;
+	}
🧹 Nitpick comments (5)
src/creatures/players/components/wheel/player_wheel.cpp (1)

1548-1552: Replace magic passive id with a named constant

Keeps the passive-id mapping centralized and avoids accidental drift.

Proposed tweak
 void PlayerWheel::sendGiftOfLifeCooldown() const {
-	// gift of life passive id is 1
-	bool paused = m_player.getZoneType() == ZONE_PROTECTION || !m_player.hasCondition(CONDITION_INFIGHT);
-	m_player.sendPassiveCooldown(1, getGiftOfCooldown(), getGiftOfLifeTotalCooldown(), paused);
+	constexpr uint8_t kGiftOfLifePassiveId = 1;
+	const bool paused = m_player.getZoneType() == ZONE_PROTECTION || !m_player.hasCondition(CONDITION_INFIGHT);
+	m_player.sendPassiveCooldown(kGiftOfLifePassiveId, getGiftOfCooldown(), getGiftOfLifeTotalCooldown(), paused);
 }
src/creatures/players/player.hpp (1)

908-908: Clarify cooldown units in the new API

A short doc comment noting whether values are milliseconds/seconds (and what paused means) would prevent misuse.

src/utils/definitions.hpp (1)

12-142: Consider moving the disable toggles to a dedicated sample header or docs

Keeping a big commented block in a core header can become stale and create merge churn. A separate sample file (included only when needed) or documentation would keep production headers cleaner.

src/server/network/protocol/protocolgame.hpp (1)

422-425: New sendPassiveCooldown declaration fits naturally alongside existing cooldown methods.

The signature and placement next to sendSpellCooldown / sendSpellGroupCooldown / sendUseItemCooldown are consistent. One minor observation: consider whether this method could be const-qualified like AddImbuementInfo and AddForgeSkillStats, since sending a cooldown packet typically shouldn't mutate ProtocolGame state. If the implementation only writes to the output buffer (which takes a non-const ref), this may not be feasible — just worth a quick check.

src/server/network/protocol/protocolgame.cpp (1)

10373-10436: Cap OTCR outfit feature counts to 0xFF

These counts are serialized as uint8_t, but the loop bounds are uint16_t max. If feature lists ever exceed 255, the count will truncate while data keeps growing, desyncing the packet. Consider clamping to uint8_t for wings/auras/effects.

♻️ Example adjustment (apply similarly to auras/effects)
-	uint16_t limitWings = std::numeric_limits<uint16_t>::max();
-	uint16_t wingSize = 0;
+	uint8_t limitWings = std::numeric_limits<uint8_t>::max();
+	uint8_t wingSize = 0;
 	msg.skipBytes(1);
 	const auto &wings = g_game().getAttachedEffects()->getWings();
 	for (const auto &wing : wings) {
 		if (player->attachedEffects().hasWing(wing)) {
 			msg.add<uint16_t>(wing->id);
 			msg.addString(wing->name);
 			++wingSize;
 		}
-		if (wingSize == limitWings) {
+		if (wingSize == limitWings) {
 			break;
 		}
 	}

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 45 days with no activity.

@github-actions github-actions Bot added the Stale No activity label Mar 16, 2026
@dudantas

dudantas commented May 7, 2026

Copy link
Copy Markdown
Member

@copilot resolve the merge conflicts in this pull request

@dudantas dudantas marked this pull request as draft May 7, 2026 18:02
@github-actions github-actions Bot removed the Stale No activity label May 8, 2026
@Zbizu Zbizu marked this pull request as ready for review May 8, 2026 07:38
@sonarqubecloud

sonarqubecloud Bot commented May 8, 2026

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/creatures/players/player.cpp (1)

8096-8100: ⚡ Quick win

Add a focused build check for both packet-disable macro states.

These compile-time branches are easy to regress silently. Add a minimal CI/build step that compiles once with default flags and once with PROTOCOL_DISABLE_LUA_MESSAGES / PROTOCOL_DISABLE_HUNTING_TASKS enabled.

As per coding guidelines, For C++ changes, prefer focused tests or the smallest practical build/check that validates the touched code.

Also applies to: 9780-9785

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/creatures/players/player.cpp` around lines 8096 - 8100, The code path
guarded by PROTOCOL_DISABLE_LUA_MESSAGES (and similarly
PROTOCOL_DISABLE_HUNTING_TASKS around other branches) can regress if not
compiled under both macro states; add a minimal CI/build check that compiles the
project twice (or adds a matrix job) once with default flags and once with
-DPROTOCOL_DISABLE_LUA_MESSAGES and -DPROTOCOL_DISABLE_HUNTING_TASKS set, so the
compilation covers the branch around player.cpp where
client->writeToOutputBuffer(message) is conditionally compiled (also apply the
same check for the other branch at the referenced area around lines ~9780-9785);
ensure the new job only performs a fast compile (no tests) and fails the build
on compilation errors.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/creatures/players/player.cpp`:
- Around line 8096-8100: The code path guarded by PROTOCOL_DISABLE_LUA_MESSAGES
(and similarly PROTOCOL_DISABLE_HUNTING_TASKS around other branches) can regress
if not compiled under both macro states; add a minimal CI/build check that
compiles the project twice (or adds a matrix job) once with default flags and
once with -DPROTOCOL_DISABLE_LUA_MESSAGES and -DPROTOCOL_DISABLE_HUNTING_TASKS
set, so the compilation covers the branch around player.cpp where
client->writeToOutputBuffer(message) is conditionally compiled (also apply the
same check for the other branch at the referenced area around lines ~9780-9785);
ensure the new job only performs a fast compile (no tests) and fails the build
on compilation errors.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 32831779-7b48-494c-8cb2-2be080c2ea20

📥 Commits

Reviewing files that changed from the base of the PR and between 90677ef and 3bed532.

📒 Files selected for processing (6)
  • src/creatures/combat/condition.cpp
  • src/creatures/players/components/wheel/player_wheel.cpp
  • src/creatures/players/player.cpp
  • src/creatures/players/player.hpp
  • src/server/network/protocol/protocolgame.cpp
  • src/server/network/protocol/protocolgame.hpp
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/creatures/combat/condition.cpp
  • src/creatures/players/components/wheel/player_wheel.cpp
  • src/creatures/players/player.hpp
  • src/server/network/protocol/protocolgame.hpp
  • src/server/network/protocol/protocolgame.cpp

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 45 days with no activity.

@github-actions github-actions Bot added the Stale No activity label Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Stale No activity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants