Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/rb 136 other player distroyed when player die #124

Merged

Conversation

romainpanno
Copy link
Collaborator

@romainpanno romainpanno commented Oct 23, 2023

  • Please check if the PR fulfills these requirements
  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Norm of the code has been respected
  • In what state is your pull request?
  • Ready to merge / Waiting a reviwer to see my work.
  • Work In Progress (WIP) / My work is not finish but i want daily reviews. (Draft)
  • CI Review / I want to see what the CI thinks of my work.
  • Need feedback / Just to have feedback on what i produced. (May not be merged)
  • What kind of change does this PR introduce? (You can choose multiple)
  • Bug fix
  • Feature request
  • New / Updated documentation
  • Testing CI ( Make the pull request in draft mode)
  • What is the current behavior? (link an issue based on the kind of change this pr introduce)

  • What is the new behavior (if this is a feature change)?

  • Other information:

Summary by CodeRabbit

  • New Feature: Enhanced player interaction with the introduction of player death handling and improved player creation process.
  • New Feature: Added more detailed player information, including position and health, to enhance gameplay.
  • Refactor: Streamlined network protocol with the renaming of "NEW_ALLIE" action to "NEW_PLAYER" and the addition of "PLAYER_DEATH" action.
  • Bug Fix: Improved thread safety with the addition of mutex locks in various functions.
  • Performance: Optimized code performance by enabling certain checks to be evaluated at compile-time.
  • Style: Improved code readability and conformance to linting rules.

@romainpanno romainpanno added the enhancement New feature or request label Oct 23, 2023
@romainpanno romainpanno self-assigned this Oct 23, 2023
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 23, 2023

Warning

Rate Limit Exceeded

@romainpanno has exceeded the limit for the number of files or commits that can be reviewed per hour. Please wait 0 minutes and 40 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, convert this PR to a draft and then mark it as ready for review again to re-trigger the review. Alternatively, you can push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per repository.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 1a06f45 and 358f489.

Walkthrough

This pull request introduces significant changes to the game's network protocol, player and enemy death handling, and player creation. It enhances the game's functionality and communication between the client and server by adding new fields to data structures, renaming actions, and adding new actions. It also improves code maintainability and readability.

Changes

File(s) Summary
docs/network/rfc/RFC.md Updated the game's network protocol documentation.
src/Client/Systems/Graphic/DeathSystems.cpp
src/Client/Systems/Network/ClientNetwork.cpp
src/Client/Systems/Network/ClientNetwork.hpp
Enhanced player and enemy death handling and player creation.
src/ECS/Systems/Systems.cpp
src/ECS/Systems/Systems.hpp
Updated the death handling of players and enemies in the game.
src/Nitwork/ANitwork.cpp
src/Nitwork/ANitwork.hpp
src/Nitwork/Nitwork.h
src/Nitwork/NitworkClient.cpp
src/Nitwork/NitworkClient.hpp
src/Nitwork/NitworkServer.cpp
src/Nitwork/NitworkServer.hpp
src/Nitwork/Zstd.hpp
Made significant changes to the game's network protocol, including renaming actions, adding new actions, and introducing new fields to data structures.
src/Server/Systems/Network/ServerNetwork.cpp
src/Server/Systems/Network/ServerNetwork.hpp
Added a new function to handle player death messages.

"With each new pull, the code does grow, 🌱

Enhancing the game, making it glow. 💫

From player creation to their final breath, 💀

We celebrate these changes, a dance of life and death." 💃🎉


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.json

Copy link
Contributor

@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.

Review Status

Actionable comments generated: 1
Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fd58bbf and 671e332.
Files selected for processing (15)
  • docs/network/rfc/RFC.md (9 hunks)
  • src/Client/Systems/Graphic/DeathSystems.cpp (2 hunks)
  • src/Client/Systems/Network/ClientNetwork.cpp (5 hunks)
  • src/Client/Systems/Network/ClientNetwork.hpp (1 hunks)
  • src/ECS/Systems/Systems.cpp (6 hunks)
  • src/ECS/Systems/Systems.hpp (1 hunks)
  • src/Nitwork/ANitwork.cpp (3 hunks)
  • src/Nitwork/ANitwork.hpp (2 hunks)
  • src/Nitwork/Nitwork.h (7 hunks)
  • src/Nitwork/NitworkClient.cpp (2 hunks)
  • src/Nitwork/NitworkClient.hpp (5 hunks)
  • src/Nitwork/NitworkServer.cpp (5 hunks)
  • src/Nitwork/NitworkServer.hpp (7 hunks)
  • src/Server/Systems/Network/ServerNetwork.cpp (1 hunks)
  • src/Server/Systems/Network/ServerNetwork.hpp (1 hunks)
Additional comments (Suppressed): 51
src/Server/Systems/Network/ServerNetwork.hpp (1)
  • 18-18: The new function receivePlayerDeathMsg has been added to handle player death messages. Ensure that this function is implemented correctly and that it is called in the appropriate places in the codebase. Also, verify that the function properly handles the msg and endpoint parameters.
src/Client/Systems/Network/ClientNetwork.hpp (2)
  • 12-12: The function receiveNewPlayer has been added. Ensure that this function is implemented correctly and that it handles the new player data as expected. Also, verify that the function is being called in the appropriate places in the codebase.

  • 17-17: The function receivePlayerDeath has been added. Ensure that this function is implemented correctly and that it handles the player death data as expected. Also, verify that the function is being called in the appropriate places in the codebase.

src/Client/Systems/Graphic/DeathSystems.cpp (2)
  • 16-16: The setPlayerAnimRectDeath function has been changed from a lambda function to a regular function. Ensure that this change does not affect any other parts of the codebase where this function is used.

  • 29-29: The deathFunctions map has been updated to include a death function for the Types::OtherPlayer type. This is a good addition as it extends the death handling functionality to other players in the game.

src/Nitwork/ANitwork.hpp (2)
  • 99-99: The change from sizeof(struct header_s) to HEADER_SIZE seems to be a refactoring change. Ensure that HEADER_SIZE is correctly defined and equivalent to sizeof(struct header_s). If HEADER_SIZE is not equivalent, it could lead to incorrect memory access, causing undefined behavior.

  • 169-174: The _packetId member variable has been removed. Ensure that this does not affect any functionality where _packetId was used. If _packetId was used in any logic, removing it could cause issues.

src/Nitwork/NitworkClient.cpp (2)
  • 52-52: The change from sizeof(struct header_s) to HEADER_SIZE is a good practice as it makes the code more readable and maintainable. However, please ensure that HEADER_SIZE is correctly defined and equals the size of header_s structure to avoid any potential issues.

  • 227-248: The new method addPlayerDeathMsg is introduced to handle the creation and sending of player death messages. It uses a mutex lock to ensure thread safety when accessing _receivedPacketsIdsMutex. This is a good practice for preventing data races in multithreaded environments. However, please ensure that the lock is released in all possible execution paths to avoid potential deadlocks.

src/Nitwork/Nitwork.h (4)
  • 34-35: The magic numbers for MAGICK_NEW_PLAYER and MAGICK_PLAYER_DEATH have been added. Ensure that these magic numbers are unique and not used elsewhere in the codebase. Also, verify that these magic numbers are handled correctly in the network protocol.

  • 52-55: The action types NEW_PLAYER and PLAYER_DEATH have been added to the n_actionType_t enumeration. Ensure that these new action types are handled correctly in the network protocol and that the N_ACTION_TYPE_MAX value is updated accordingly.

  • 181-187: The msgCreatePlayer_s structure has been modified to include new fields pos, life, and isOtherPlayer. Ensure that these fields are initialized correctly when creating a new player and that they are used correctly in the network protocol.

  • 222-225: A new structure msgPlayerDeath_s has been added to handle player death messages. Ensure that this structure is used correctly in the network protocol and that the playerId field is set correctly when a player dies.

src/Nitwork/ANitwork.cpp (3)
  • 13-13: The initialization of _packetId has been removed from the constructor. If _packetId is used elsewhere in the code, ensure that it is properly initialized before use to avoid undefined behavior.
- ANitwork::ANitwork() : _socket(_context), _packetId(0)
+ ANitwork::ANitwork() : _socket(_context)
  • 140-140: The check for packet size has been changed from sizeof(struct header_s) to HEADER_SIZE. Ensure that HEADER_SIZE is correctly defined and is equivalent to sizeof(struct header_s). If not, this could lead to incorrect behavior when receiving packets.
- if (packetSize > MAX_PACKET_SIZE || packetSize < sizeof(struct header_s)) {
+ if (packetSize > MAX_PACKET_SIZE || packetSize < HEADER_SIZE) {
  • 239-239: The error message for an action not found in actionToSendHandlers has been improved to include the action that was not found. This is a good change as it will make debugging easier by providing more context in the error message.
- Logger::error("NITWORK: action not found");
+ Logger::error("NITWORK: action not found: " + std::to_string(data.action));
src/Client/Systems/Network/ClientNetwork.cpp (4)
  • 1-1: The new hunk includes the CustomTypes.hpp header file. Ensure that this file exists and contains the necessary definitions for the custom types used in the code.

  • 37-45: The code now checks if the health component exists for the enemy before setting its health to 0. This is a good practice as it prevents potential runtime errors if the health component does not exist for a particular enemy.

  • 76-97: The createNewPlayer function has been significantly modified. It now checks if a player or other player with the same ID already exists, and if so, removes that entity before initializing a new one. This could potentially prevent duplication of player entities. However, ensure that removing an existing player entity does not have unintended side effects elsewhere in the code.

  • 243-265: The new function receivePlayerDeath handles the death of a player. It sets the health of the player or other player with the matching ID to 0. This is a good way to represent the death of a player in the game. However, ensure that other parts of the code properly handle a player's health being set to 0, such as removing the player from the game or triggering a respawn.

src/Nitwork/NitworkClient.hpp (5)
  • 39-39: The new method addPlayerDeathMsg is introduced to handle player death messages. Ensure that this method is called appropriately in the codebase whenever a player death event occurs.

  • 72-75: The handleBody function now uses msgCreatePlayer_s instead of msgPlayerInit_s and the receiveNewPlayer function is called instead of receivePlayerInit. Verify that these changes are consistent with the new network protocol and that the msgCreatePlayer_s struct and receiveNewPlayer function are implemented correctly.

  • 124-130: The NEW_ALLIE action has been replaced with NEW_PLAYER. The handleBody function now uses msgCreatePlayer_s instead of msgNewAllie_s and the receiveNewPlayer function is called instead of receiveNewAllie. Ensure that these changes are consistent with the new network protocol and that the msgCreatePlayer_s struct and receiveNewPlayer function are implemented correctly.

  • 166-176: A new PLAYER_DEATH action is introduced. The handleBody function uses msgPlayerDeath_s and the receivePlayerDeath function is called. Ensure that these are implemented correctly and that the PLAYER_DEATH action is handled appropriately in the codebase.

  • 224-229: The sendData function now uses packetPlayerDeath_s for the PLAYER_DEATH action. Verify that packetPlayerDeath_s is implemented correctly and that the PLAYER_DEATH action is handled appropriately when sending data.

src/Nitwork/NitworkServer.hpp (5)
  • 40-40: The function signature for addPlayerInitMessage has been changed to accept a msgCreatePlayer_s object instead of a player ID. Ensure that all calls to this function throughout the codebase have been updated to match the new signature. Also, verify that the msgCreatePlayer_s object contains all the necessary information that was previously provided by the player ID.

  • 50-54: New functions addPlayerDeathMsg and addNewPlayerMsg have been added. Ensure that these functions are being called at the appropriate places in the codebase to handle player death and the addition of new players. Also, verify that the necessary data is being passed to these functions.

  • 78-82: The function sendNewAllie has been modified to accept a packetCreatePlayer_s object instead of a packetNewAllie_s object. Ensure that all calls to this function throughout the codebase have been updated to match the new signature. Also, verify that the packetCreatePlayer_s object contains all the necessary information that was previously provided by the packetNewAllie_s object.

  • 150-156: A new action PLAYER_DEATH has been added to the _actionsHandlers map. Ensure that this action is being handled correctly in the Systems::receivePlayerDeathMsg function and that the necessary data is being passed to this function.

  • 196-197: The sendData function is now being called with different packet types (packetCreatePlayer_s and packetPlayerDeath_s) for the INIT, NEW_PLAYER, and PLAYER_DEATH actions. Ensure that the sendData function can handle these new packet types and that all necessary data is being included in these packets.

src/ECS/Systems/Systems.cpp (6)
  • 341-341: The deadList variable is now a reference to the list of dead components. This change is good for performance as it avoids unnecessary copying of the list. However, ensure that the list is not modified elsewhere in a way that could invalidate this reference.

  • 361-373: The code now checks if the dead entity is a player or other player and sends a death message accordingly. This is a new feature introduced in this PR. Ensure that the addPlayerDeathMsg function handles these messages correctly and that the server and client code can process these messages.

  • 386-402: The sendDeathMsg function has been modified to handle death messages for both players and enemies. This is a significant change from the previous version which only handled enemy death messages. Ensure that the server and client code can process these new types of messages.

  • 418-418: The sendDeathMsg function is now called when an entity's health reaches zero. This is a change from the previous version where sendEnemyDeath was called. This change is part of the new feature introduced in this PR where death messages are sent for both players and enemies.

  • 466-474: The initPlayer function now takes additional parameters for position and health. This is a significant change from the previous version which only took a constant ID and a boolean indicating if the player is another player. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 501-501: The position variable is now initialized with the passed in position instead of a default position. This is a significant change from the previous version where the position was initialized with a default value. Ensure that the passed in position is valid and that this change does not affect the gameplay or player spawning mechanics.

docs/network/rfc/RFC.md (8)
  • 43-45: The addition of "Position", "Life", and "Is Other Player" fields to the server action in the network protocol is noted. Ensure that these fields are properly handled in the server-side code and that the client-side code is updated to correctly interpret these new fields.

  • 104-110: The renaming of the "NEW_ALLIE" action to "NEW_PLAYER" and the addition of "Position", "Life", and "Is Other Player" fields are noted. Make sure that all instances of "NEW_ALLIE" in the codebase are updated to "NEW_PLAYER" and that these new fields are correctly handled.

  • 125-131: The addition of the "PLAYER_DEATH" action is noted. Ensure that this action is correctly handled in both the client-side and server-side code, and that the "Player ID" field is correctly interpreted.

  • 260-263: The renaming of the "NEW_ALLIE" action to "NEW_PLAYER" and the addition of the "PLAYER_DEATH" action in the action body are noted. Make sure that all instances of "NEW_ALLIE" in the codebase are updated to "NEW_PLAYER" and that the "PLAYER_DEATH" action is correctly handled.

  • 290-292: The addition of "pos", "life", and "isOtherPlayer" fields to the server action is noted. Ensure that these fields are properly handled in the server-side code and that the client-side code is updated to correctly interpret these new fields.

  • 310-342: The detailed specifications for the new "Position", "Life", and "Is Other Player" fields are noted. Ensure that these specifications are correctly implemented in the server-side code and that the client-side code is updated to correctly interpret these new fields.

  • 720-782: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [714-778]

The renaming of the "NEW_ALLIE" action to "NEW_PLAYER" and the detailed specifications for the new "Position", "Life", and "Is Other Player" fields are noted. Make sure that all instances of "NEW_ALLIE" in the codebase are updated to "NEW_PLAYER" and that these new fields are correctly handled.

  • 868-915: The addition of the "PLAYER_DEATH" action and the detailed specifications for the "Player ID" field are noted. Ensure that this action and field are correctly handled in both the client-side and server-side code.
src/Nitwork/NitworkServer.cpp (7)
  • 70-70: The change from sizeof(struct header_s) to HEADER_SIZE is not inherently problematic, but it's important to ensure that HEADER_SIZE is defined correctly and matches the size of header_s. If HEADER_SIZE is not equal to sizeof(struct header_s), it could lead to incorrect memory access and undefined behavior.
// Verify that HEADER_SIZE is defined correctly
static_assert(HEADER_SIZE == sizeof(struct header_s), "HEADER_SIZE does not match the size of header_s");
  • 113-130: The function sendNewAllie has been modified to take a packetCreatePlayer_s instead of packetNewAllie_s. Ensure that all calls to this function have been updated to match the new signature. Also, the function now sets the playerId field of the packetMsgCreatePlayer argument, which could potentially overwrite existing data. If this is not the intended behavior, consider passing playerId as a separate argument.

  • 133-165: The new function sendAlliesAlreadyPresent sends information about existing players to a newly connected player. This is a good addition for maintaining game state consistency across all players. However, the function uses a lot of nested loops and conditionals, which increases its complexity. Consider refactoring this function to improve readability and maintainability.

  • 181-196: The handleInitMsg function has been significantly modified. It now uses a packetCreatePlayer_s structure instead of packetNewAllie_s, and it initializes the player using the Systems::initPlayer function with additional parameters for position and health. Ensure that these changes are compatible with the rest of the codebase. Also, the function now sends a packetCreatePlayer_s packet to all clients, which could potentially overwrite existing data. If this is not the intended behavior, consider passing playerId as a separate argument.

  • 247-260: The addPlayerInitMessage function has been modified to take a msgCreatePlayer_s instead of a n_id_t. Ensure that all calls to this function have been updated to match the new signature. Also, the function now sets the msg field of the packetCreatePlayer argument, which could potentially overwrite existing data. If this is not the intended behavior, consider passing playerMsg as a separate argument.

  • 361-373: The new function addPlayerDeathMsg sends a packetPlayerDeath_s packet to all clients when a player dies. This is a good addition for maintaining game state consistency across all players. However, the function uses a std::lock_guard to lock _receivedPacketsIdsMutex, which could potentially lead to deadlocks if not handled properly. Ensure that this mutex is always unlocked, even in case of exceptions.

  • 375-390: The new function addNewPlayerMsg sends a packetCreatePlayer_s packet to a specific client. This is a good addition for maintaining game state consistency across all players. However, the function uses a std::lock_guard to lock _receivedPacketsIdsMutex, which could potentially lead to deadlocks if not handled properly. Ensure that this mutex is always unlocked, even in case of exceptions.

src/Server/Systems/Network/ServerNetwork.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@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.

Review Status

Actionable comments generated: 0
Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 671e332 and 8a396bd.
Files selected for processing (9)
  • src/Client/Systems/Graphic/DeathSystems.cpp (2 hunks)
  • src/Client/Systems/Network/ClientNetwork.cpp (5 hunks)
  • src/ECS/Systems/Systems.cpp (6 hunks)
  • src/ECS/Systems/Systems.hpp (1 hunks)
  • src/Nitwork/ANitwork.hpp (2 hunks)
  • src/Nitwork/NitworkClient.cpp (2 hunks)
  • src/Nitwork/NitworkServer.cpp (5 hunks)
  • src/Nitwork/NitworkServer.hpp (7 hunks)
  • src/Server/Systems/Network/ServerNetwork.cpp (1 hunks)
Additional comments (Suppressed): 30
src/ECS/Systems/Systems.hpp (1)
  • 32-36: The function signature of initPlayer has been changed to include two new parameters: const struct position_absolute_s &pos and const struct health_s &life. Ensure that all calls to this function throughout the codebase have been updated to match the new signature. Also, verify that the new parameters are being used correctly within the function.
src/Nitwork/ANitwork.hpp (2)
  • 98-99: The reinterpret cast has been modified to use HEADER_SIZE instead of sizeof(struct header_s). Ensure that HEADER_SIZE is equivalent to sizeof(struct header_s). If not, this could lead to incorrect memory access.

  • 169-174: The member variable _packetId has been removed. Ensure that this does not affect any functionality where _packetId was used.

src/Client/Systems/Graphic/DeathSystems.cpp (2)
  • 16-17: The setPlayerAnimRectDeath function has been changed from a lambda function to a regular function. Ensure that this change does not affect any other parts of the codebase where this function might be used.

  • 29-30: The deathFunctions map has been updated to include a new entity type Types::OtherPlayer. This change seems to be in line with the PR's goal of handling death notifications for other players. However, it's important to ensure that the setPlayerAnimRectDeath function can handle Types::OtherPlayer entities correctly.

src/Server/Systems/Network/ServerNetwork.cpp (1)
  • 116-151: The receivePlayerDeathMsg function is responsible for handling player death messages. It locks the registry mutex to ensure thread safety, retrieves the necessary components from the registry, and then iterates over the entities that have these components. If it finds an entity with the same ID as the player who died, it checks if the player's health is greater than 0. If it is, it sends a new player message to the endpoint. If the player is not found, it logs a debug message.

This function seems to be well-structured and follows good practices for thread safety and error handling. However, there is a potential issue with the logic in lines 133-146. If the player's health is greater than 0, it sends a new player message. This seems counterintuitive as the function is supposed to handle player death messages. Please verify if this is the intended behavior.

Also, the ternary operator in lines 141-144 could be simplified. The comparison itself returns a boolean value, so the ternary operator is unnecessary.

- .isOtherPlayer = (Nitwork::NitworkServer::getInstance().getPlayerId(endpoint)
-                   != otherPlayer.constId)
-                     ? true
-                     : false,
+ .isOtherPlayer = Nitwork::NitworkServer::getInstance().getPlayerId(endpoint) != otherPlayer.constId,
src/Nitwork/NitworkClient.cpp (2)
  • 52-52: The reinterpret cast is now using HEADER_SIZE instead of sizeof(struct header_s). Ensure that HEADER_SIZE is correctly defined and equivalent to sizeof(struct header_s). If not, this could lead to incorrect memory access.

  • 227-244: The new function addPlayerDeathMsg is added to send a player death message to the server. It uses a mutex lock to ensure thread safety when accessing _receivedPacketsIdsMutex. This is a good practice for preventing data races in a multithreaded environment. However, ensure that the lock is released in all possible execution paths to avoid deadlocks.

The function constructs a packetPlayerDeath_s structure and sends it as a packet. Ensure that the header and action fields are correctly initialized. Currently, the header field is initialized with all zeros, which might not be correct depending on the protocol specification. Also, the action field only has the magick field set to PLAYER_DEATH, ensure that this is the intended behavior.

The function uses std::make_any to create a std::any object from packetPlayerDeath. This is a good practice for creating type-safe containers. However, ensure that the receiver of this packet correctly handles std::any and knows how to extract packetPlayerDeath_s from it.

src/Client/Systems/Network/ClientNetwork.cpp (4)
  • 3-3: The inclusion of "CustomTypes.hpp" is new. Ensure that this header file exists and is necessary for the code changes in this PR.

  • 37-45: The logic for handling enemy death has been modified. Previously, the enemy entity was removed from the registry. Now, the enemy's health is set to 0 if it exists. This change could have implications on how the game handles enemy entities after their death. Ensure that this change is intended and that it doesn't introduce bugs or unexpected behavior in the game.

  • 76-101: The createNewPlayer function is a new addition. It creates a new player or other player entity in the game. The function first checks if a player or other player with the same ID already exists. If so, it removes the existing entity before creating a new one. This could potentially cause issues if the existing player is still in use or referenced elsewhere in the code. Ensure that removing existing players is safe and doesn't cause any issues.

  • 247-271: The receivePlayerDeath function is a new addition. It handles the death of a player or other player entity. The function sets the health of the dying player to 0. This is a significant change to the game's death handling logic and could have implications on how the game handles player deaths. Ensure that this change is intended and that it doesn't introduce bugs or unexpected behavior in the game.

src/Nitwork/NitworkServer.hpp (6)
  • 40-42: The function signature for addPlayerInitMessage has been changed. Ensure that all calls to this function throughout the codebase have been updated to match the new signature. The new signature now includes a msgCreatePlayer_s parameter.

  • 52-56: New functions addPlayerDeathMsg and addNewPlayerMsg have been added. These functions seem to handle player death and new player messages respectively. Ensure that these functions are used correctly in the codebase.

  • 80-84: The function signature for sendNewAllie has been changed. Ensure that all calls to this function throughout the codebase have been updated to match the new signature. The new signature now includes a packetCreatePlayer_s parameter instead of packetNewAllie_s.

  • 152-158: A new action PLAYER_DEATH has been added to the _actionsHandlers map. This action seems to handle player death messages. Ensure that this action is used correctly in the codebase.

  • 185-187: The NEW_ALLIE action has been renamed to NEW_PLAYER in the _actionToSendHandlers map. Ensure that this change is reflected throughout the codebase.

  • 197-200: A new action PLAYER_DEATH has been added to the _actionToSendHandlers map. This action seems to handle player death messages. Ensure that this action is used correctly in the codebase.

src/Nitwork/NitworkServer.cpp (6)
  • 70-70: The reinterpret cast is now using HEADER_SIZE instead of sizeof(struct header_s). Ensure that HEADER_SIZE is correctly defined and equivalent to sizeof(struct header_s). If not, this could lead to incorrect memory access.

  • 113-130: The function sendNewAllie now takes a packetCreatePlayer_s instead of packetNewAllie_s. Ensure that all calls to this function have been updated to match the new signature. Also, the packetCreatePlayer_s structure seems to have more fields than packetNewAllie_s. Make sure these additional fields are correctly handled in the function.

  • 179-204: The handleInitMsg function now initializes a player with position and health parameters. Ensure that these parameters are correctly set in the packetMsgCreatePlayer structure. Also, the function now calls sendAlliesAlreadyPresent after sending the new ally. Make sure this does not introduce any race conditions or other issues.

  • 255-270: The addPlayerInitMessage function now takes a msgCreatePlayer_s instead of a player ID. Ensure that all calls to this function have been updated to match the new signature. Also, the msgCreatePlayer_s structure seems to have more fields than just a player ID. Make sure these additional fields are correctly handled in the function.

  • 371-383: The new function addPlayerDeathMsg sends a PLAYER_DEATH message to all clients. Ensure that this message is correctly handled on the client side and that the player death is correctly reflected in the game state.

  • 385-400: The new function addNewPlayerMsg sends a NEW_PLAYER message to a specific client. Ensure that this message is correctly handled on the client side and that the new player is correctly added to the game state.

src/ECS/Systems/Systems.cpp (6)
  • 341-344: The deadList variable is now a reference instead of a copy. This change is good for performance as it avoids unnecessary copying. However, ensure that the original data is not modified unintentionally through this reference.

  • 361-373: The executeDeathFunction now checks if the dead entity is a player or other player and sends a death message accordingly. This is a new feature introduced in this PR. Ensure that the addPlayerDeathMsg function handles these messages correctly.

  • 386-402: The sendEnemyDeath function is renamed to sendDeathMsg and now handles death messages for both enemies and other players. This is a good change for code maintainability as it reduces code duplication. However, ensure that the addPlayerDeathMsg and addEnemyDeathMsg functions handle these messages correctly.

  • 418-420: The deathChecker function now calls sendDeathMsg instead of sendEnemyDeath. This change is consistent with the renaming of the sendEnemyDeath function to sendDeathMsg.

  • 466-478: The initPlayer function now takes additional parameters for position and health. This change provides more flexibility in player initialization. However, ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 505-507: The initPlayer function now directly uses the passed position for player initialization. This change is consistent with the new parameter added to the function. However, ensure that the passed position is valid and within the game window boundaries.

Copy link
Contributor

@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.

Review Status

Actionable comments generated: 1
Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8a396bd and 118f478.
Files selected for processing (2)
  • docs/network/rfc/RFC.md (9 hunks)
  • src/Client/Systems/Network/ClientNetwork.cpp (5 hunks)
Additional comments (Suppressed): 11
src/Client/Systems/Network/ClientNetwork.cpp (3)
  • 3-3: The inclusion of the "CustomTypes.hpp" header file is new. Ensure that this file exists and is in the correct location. Also, verify that the types defined in this file are used in the new code.

  • 37-47: The new code introduces a health component for enemies. This is a significant change from the previous logic where enemies were simply removed upon death. Now, the health of an enemy is set to 0 upon death. If an enemy does not have a health component, a fatal error is logged and the enemy is removed. This change could have implications for game mechanics and should be thoroughly tested.

  • 249-273: The receivePlayerDeath function is a new addition. It handles player death messages by setting the health of the player or other player to 0. This is a significant change from the previous logic where player death was not handled. This change could have implications for game mechanics and should be thoroughly tested.

docs/network/rfc/RFC.md (8)
  • 43-45: The addition of "Position", "Life", and "Is Other Player" fields to the server's data structure is noted. Ensure that these fields are properly initialized and used in the server-side code. Also, verify that the client-side code has been updated to handle these new fields.

  • 104-110: The renaming of the "NEW_ALLIE" action to "NEW_PLAYER" and the addition of "PLAYER_DEATH" action is noted. Make sure that all instances of "NEW_ALLIE" in the codebase have been updated to "NEW_PLAYER". Also, ensure that the "PLAYER_DEATH" action is properly handled in both the client-side and server-side code.

  • 125-131: The addition of the "PLAYER_DEATH" action is noted. Ensure that this action is properly handled in both the client-side and server-side code. Also, verify that the "Player ID" field is correctly used to identify the player who died.

  • 260-263: The addition of "NEW_PLAYER" and "PLAYER_DEATH" actions to the list of actions is noted. Make sure that these actions are properly handled in the codebase.

  • 290-292: The addition of "pos", "life", and "isOtherPlayer" fields to the server action is noted. Ensure that these fields are properly initialized and used in the server-side code. Also, verify that the client-side code has been updated to handle these new fields.

  • 310-344: The addition of "Position", "Life", and "Is Other Player" fields to the server's data structure is noted. Ensure that these fields are properly initialized and used in the server-side code. Also, verify that the client-side code has been updated to handle these new fields.

  • 722-786: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [716-782]

The renaming of the "NEW_ALLIE" action to "NEW_PLAYER" and the addition of "PLAYER_DEATH" action is noted. Make sure that all instances of "NEW_ALLIE" in the codebase have been updated to "NEW_PLAYER". Also, ensure that the "PLAYER_DEATH" action is properly handled in both the client-side and server-side code.

  • 872-919: The addition of the "PLAYER_DEATH" action is noted. Ensure that this action is properly handled in both the client-side and server-side code. Also, verify that the "Player ID" field is correctly used to identify the player who died.

src/Client/Systems/Network/ClientNetwork.cpp Show resolved Hide resolved
Copy link
Contributor

@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.

Review Status

Actionable comments generated: 0
Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 118f478 and e4f8faf.
Files selected for processing (1)
  • src/Nitwork/Zstd.hpp (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/Nitwork/Zstd.hpp

Copy link
Contributor

@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.

Review Status

Actionable comments generated: 0
Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e4f8faf and 1a06f45.
Files selected for processing (1)
  • src/Nitwork/ANitwork.hpp (3 hunks)
Files skipped from review due to trivial changes (1)
  • src/Nitwork/ANitwork.hpp

@guillaumeAbel guillaumeAbel merged commit 4d541c7 into dev Oct 23, 2023
@Saverio976 Saverio976 deleted the feature/RB-136-other-player-distroyed-when-player-die branch March 4, 2024 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants