Skip to content

fix: handle creature square marks for v1076+#1637

Open
dudantas wants to merge 1 commit intomainfrom
dudantas/fix-parse-creatures-square
Open

fix: handle creature square marks for v1076+#1637
dudantas wants to merge 1 commit intomainfrom
dudantas/fix-parse-creatures-square

Conversation

@dudantas
Copy link
Member

@dudantas dudantas commented Feb 7, 2026

This pull request updates the handling of creature marks (squares) received from the server in the ProtocolGame class. The changes clarify and extend the protocol for marking creatures, introducing support for different mark types (removal, temporary, permanent) and improving code documentation and logging. The logic now uses explicit square types and colors, and is backward compatible with older client versions.

Creature Mark Handling Improvements:

  • Refactored parseCreaturesMark to support three mark types: remove, temporary (timed/flashing), and permanent (static), using two explicit parameters (squareType and squareColor) for client versions 1076 and above.
  • Improved debug logging to specify the correct function name when a creature is not found.
  • Added a detailed Doxygen comment to parseCreaturesMark describing the protocol, parameters, and behavior rules for handling creature marks.

Summary by CodeRabbit

Bug Fixes

  • Fixed error logging reference in creature mark parsing

Refactor

  • Enhanced creature mark and square handling with improved compatibility across different game client versions, including better management of mark colors, visibility states, and display timing options

Update creature mark parsing to support the newer server format introduced in client version 1076+. Added detailed documentation for parseCreaturesMark in the header. parseCreaturesMark now maintains backward compatibility for <1076 by reading the legacy single mark byte, while for >=1076 it reads a squareType and squareColor and applies behavior accordingly: type==0 or color==0 removes static and timed squares, type==2 shows a permanent static square, otherwise a timed square is added. Also improved the debug log message when a creature ID is not found.
Copilot AI review requested due to automatic review settings February 7, 2026 01:07
@coderabbitai
Copy link

coderabbitai bot commented Feb 7, 2026

📝 Walkthrough

Walkthrough

A new parseCreaturesMark() function is introduced in the ProtocolGame class to parse and apply creature marks from the server. The implementation includes version-specific logic: older clients (pre-1076) use markType for timed squares, while newer clients (1076+) use squareType and squareColor values to control mark visibility and behavior.

Changes

Cohort / File(s) Summary
Creature Mark Parsing
src/client/protocolgame.h, src/client/protocolgameparse.cpp
Added parseCreaturesMark() function with Doxygen documentation. Implementation includes version-conditional logic: pre-1076 clients handle markType directly, while 1076+ clients interpret squareType values to show/hide/remove marks with colors. Updated error logging reference from misnamed path to parseCreaturesMark.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A mark upon each creature's square,
With colors bright beyond compare,
Old clients get their markType way,
While newer ones use colors play,
Version-wise, we parse with care!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: updating creature square mark handling for client version 1076 and newer.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dudantas/fix-parse-creatures-square

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.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d9e92f7410

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +3641 to +3643
if (squareType == 0 || squareColor == 0) {
creature->hideStaticSquare();
creature->removeTimedSquare();

Choose a reason for hiding this comment

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

P2 Badge Avoid treating squareColor=0 as removal

If the 1076+ server sends a square color of 0 to mean the default color (the old path normalized 0→1 for both static and timed squares, and Creature::addTimedSquare still maps color != 0 ? color : 1), this new branch removes both static and timed squares instead of rendering them. That’s a behavior change for any square update where squareType is flash/stay but squareColor is 0, and it will cause marks to disappear instead of showing the default color. This only manifests when the server uses 0 as a valid color in the new protocol.

Useful? React with 👍 / 👎.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates client-side parsing of server “creature mark / square” messages in ProtocolGame, expanding support for the v1076+ protocol while keeping legacy behavior for older client versions.

Changes:

  • Refactors ProtocolGame::parseCreaturesMark to parse squareType + squareColor for client versions >= 1076, while retaining the <1076 single-byte timed-square behavior.
  • Fixes the debug trace message to reference the correct function name.
  • Adds a Doxygen comment describing the creature mark protocol and behavior rules.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/client/protocolgameparse.cpp Implements new v1076+ mark parsing logic and updates debug logging.
src/client/protocolgame.h Adds Doxygen documentation for parseCreaturesMark.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 3624 to 3629
const uint32_t creatureId = msg->getU32();
const bool isPermanent = g_game.getClientVersion() >= 1076 ? msg->getU8() == 0 : false;
const uint8_t markType = msg->getU8();

const auto& creature = g_map.getCreatureById(creatureId);
if (!creature) {
g_logger.traceDebug("ProtocolGame::parseTrappers: could not get creature with id {}", creatureId);
g_logger.traceDebug("ProtocolGame::parseCreaturesMark: could not get creature with id {}", creatureId);
return;
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

Returning early when the creature is not found now happens before reading the rest of the mark payload. That leaves unread bytes in the InputMessage (markType for <1076, squareType+squareColor for 1076+), which will desynchronize parsing of subsequent opcodes. Consume/discard the appropriate bytes before returning (or parse the fields first, then apply only if creature exists).

Copilot uses AI. Check for mistakes.
Comment on lines +331 to +348
* @param msg Input message containing:
* - uint32 creatureId: Target creature identifier.
* - uint8 squareType: Square behavior type:
* - 0 = SQUARE_REMOVE: remove any square (static and timed)
* - 1 = SQUARE_FLASH: temporary (timed/flashing)
* - 2 = SQUARE_STAY : permanent (static)
* - uint8 squareColor: 8-bit color used by the square.
*
* @note If the creature cannot be found in the map, the function logs a debug trace
* and returns without doing anything.
*
* Behavior rules:
* - If @c squareType == 0 OR @c squareColor == 0:
* Removes any square (static and timed).
* - If @c squareType == 2:
* Shows a permanent/static square using @c squareColor.
* - Otherwise:
* Adds a timed square using @c squareColor.
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

The Doxygen comment describes only the 1076+ wire format (creatureId + squareType + squareColor), but the implementation also supports <1076 where only a single uint8 markType is read and applied as a timed square. Please document the pre-1076 format/behavior as well (or explicitly scope the comment to clientVersion >= 1076).

Suggested change
* @param msg Input message containing:
* - uint32 creatureId: Target creature identifier.
* - uint8 squareType: Square behavior type:
* - 0 = SQUARE_REMOVE: remove any square (static and timed)
* - 1 = SQUARE_FLASH: temporary (timed/flashing)
* - 2 = SQUARE_STAY : permanent (static)
* - uint8 squareColor: 8-bit color used by the square.
*
* @note If the creature cannot be found in the map, the function logs a debug trace
* and returns without doing anything.
*
* Behavior rules:
* - If @c squareType == 0 OR @c squareColor == 0:
* Removes any square (static and timed).
* - If @c squareType == 2:
* Shows a permanent/static square using @c squareColor.
* - Otherwise:
* Adds a timed square using @c squareColor.
* This function supports different wire formats depending on the client version.
*
* For clientVersion < 1076:
* - The message contains a single field:
* - uint8 markType: Encoded mark behavior. Non-zero values are interpreted as a
* temporary/timed mark (equivalent to a flashing square). A zero value removes
* any existing mark on the creature.
*
* For clientVersion >= 1076:
* - @param msg Input message containing:
* - uint32 creatureId: Target creature identifier.
* - uint8 squareType: Square behavior type:
* - 0 = SQUARE_REMOVE: remove any square (static and timed)
* - 1 = SQUARE_FLASH: temporary (timed/flashing)
* - 2 = SQUARE_STAY : permanent (static)
* - uint8 squareColor: 8-bit color used by the square.
*
* @note If the creature cannot be found in the map, the function logs a debug trace
* and returns without doing anything.
*
* Behavior rules for clientVersion >= 1076:
* - If @c squareType == 0 OR @c squareColor == 0:
* Removes any square (static and timed).
* - If @c squareType == 2:
* Shows a permanent/static square using @c squareColor.
* - Otherwise:
* Adds a timed square using @c squareColor.
*
* For clientVersion < 1076, the single @c markType is mapped internally to the
* corresponding behavior (removal or timed square) to produce the same visual
* effect as newer protocol versions.

Copilot uses AI. Check for mistakes.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/client/protocolgame.h`:
- Around line 331-349: Update the docblock for the message handler that reads
parameter msg to document the legacy (<1076) payload: explicitly state that for
clients with protocol version <1076 the implementation consumes a single uint8
markType byte (named markType) instead of the v1076+ uint8 squareType + uint8
squareColor pair, and describe that markType is interpreted by the same rules
(markType==0 removes squares; other values are handled as legacy marks) so
readers can understand both formats; reference the existing parameter names msg,
squareType, squareColor and the legacy markType and note the protocol version
threshold (<1076).

Comment on lines +331 to +349
* @param msg Input message containing:
* - uint32 creatureId: Target creature identifier.
* - uint8 squareType: Square behavior type:
* - 0 = SQUARE_REMOVE: remove any square (static and timed)
* - 1 = SQUARE_FLASH: temporary (timed/flashing)
* - 2 = SQUARE_STAY : permanent (static)
* - uint8 squareColor: 8-bit color used by the square.
*
* @note If the creature cannot be found in the map, the function logs a debug trace
* and returns without doing anything.
*
* Behavior rules:
* - If @c squareType == 0 OR @c squareColor == 0:
* Removes any square (static and timed).
* - If @c squareType == 2:
* Shows a permanent/static square using @c squareColor.
* - Otherwise:
* Adds a timed square using @c squareColor.
*/
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Document the legacy (<1076) payload to avoid protocol confusion.

The doc block only describes the v1076+ squareType/squareColor format, but the implementation also consumes a legacy single markType byte for older clients. Adding that note keeps the header aligned with behavior.

📝 Suggested doc update
 * `@param` msg Input message containing:
 * - uint32 creatureId: Target creature identifier.
- * - uint8  squareType: Square behavior type:
- *   - 0 = SQUARE_REMOVE: remove any square (static and timed)
- *   - 1 = SQUARE_FLASH: temporary (timed/flashing)
- *   - 2 = SQUARE_STAY : permanent (static)
- * - uint8  squareColor: 8-bit color used by the square.
+ * - For clientVersion < 1076:
+ *   - uint8 markType: legacy timed square color.
+ * - For clientVersion >= 1076:
+ *   - uint8  squareType: Square behavior type:
+ *     - 0 = SQUARE_REMOVE: remove any square (static and timed)
+ *     - 1 = SQUARE_FLASH: temporary (timed/flashing)
+ *     - 2 = SQUARE_STAY : permanent (static)
+ *   - uint8  squareColor: 8-bit color used by the square.
🤖 Prompt for AI Agents
In `@src/client/protocolgame.h` around lines 331 - 349, Update the docblock for
the message handler that reads parameter msg to document the legacy (<1076)
payload: explicitly state that for clients with protocol version <1076 the
implementation consumes a single uint8 markType byte (named markType) instead of
the v1076+ uint8 squareType + uint8 squareColor pair, and describe that markType
is interpreted by the same rules (markType==0 removes squares; other values are
handled as legacy marks) so readers can understand both formats; reference the
existing parameter names msg, squareType, squareColor and the legacy markType
and note the protocol version threshold (<1076).

@github-actions
Copy link

github-actions bot commented Mar 9, 2026

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

@github-actions github-actions bot added the Stale label Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants