fix: Empty plots - #287
Conversation
WalkthroughThe changes in this pull request focus on the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (3)
Maple2.Server.Game/Packets/LoadCubesPacket.cs (2)
Line range hint
51-58: Consider clarifying the "unsure" comment.The type change looks good, but there's an uncertain comment about the apartment number field. Consider:
- Documenting the purpose of this field
- Adding validation if necessary
- Removing the comment once verified
Line range hint
39-76: Consider performance implications of List usage.The consistent change from
ICollectiontoListacross all methods suggests a deliberate choice. While this makes the API more specific, consider:
- If the caller needs to create new List instances just to call these methods
- If there are performance implications when dealing with large collections
A possible optimization would be to keep
ICollectionif random access isn't required, or document whyListis specifically needed.Maple2.Server.Game/PacketHandlers/LoadUgcMapHandler.cs (1)
81-86: Consider optimizing memory allocations and lock scope.While the thread-safety approach with the lock statement is correct, there are opportunities for optimization:
Consider applying these improvements:
private static void LoadPlots(GameSession session, List<PlotCube> plotCubes) { + // Acquire values under lock but process outside + IEnumerable<Plot> plots; lock (session.Field.Plots) { - List<Plot> allPlots = session.Field.Plots.Values.ToList(); - List<Plot> ownedPlots = allPlots.Where(x => x.State is not PlotState.Open).ToList(); - session.Send(LoadCubesPacket.PlotOwners(ownedPlots)); - session.Send(LoadCubesPacket.Load(plotCubes)); - session.Send(LoadCubesPacket.PlotState(allPlots)); - session.Send(LoadCubesPacket.PlotExpiry(ownedPlots)); + plots = session.Field.Plots.Values.ToList(); } + + // Process outside lock to minimize lock duration + var (allPlots, ownedPlots) = (plots.ToList(), plots.Where(x => x.State is not PlotState.Open).ToList()); + + // Send packets + session.Send(LoadCubesPacket.PlotOwners(ownedPlots)); + session.Send(LoadCubesPacket.Load(plotCubes)); + session.Send(LoadCubesPacket.PlotState(allPlots)); + session.Send(LoadCubesPacket.PlotExpiry(ownedPlots)); }This optimization:
- Minimizes the lock duration by only protecting the initial data access
- Reduces the number of allocations by reusing the initial enumeration
- Maintains the same functionality while being more performant
The current implementation is functionally correct, and these suggestions are purely for optimization.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- Maple2.Server.Game/PacketHandlers/LoadUgcMapHandler.cs (1 hunks)
- Maple2.Server.Game/Packets/LoadCubesPacket.cs (2 hunks)
🧰 Additional context used
🔇 Additional comments (2)
Maple2.Server.Game/Packets/LoadCubesPacket.cs (2)
Line range hint
65-74: Verify ExpiryTime initialization and handling.The changes look good, but let's ensure:
- ExpiryTime is properly initialized in the Plot class
- The value is in the correct time format expected by the client
✅ Verification successful
Based on the shell script results, I can now generate the final response as I have sufficient information about ExpiryTime handling across the codebase.
ExpiryTime handling is properly implemented and consistent.
The verification shows that:
- ExpiryTime is consistently handled as Unix timestamp (seconds since epoch) across the codebase
- The Plot class inherits ExpiryTime from the UgcMap model which is properly initialized and managed
- The value is correctly converted between DateTime and epoch seconds using extension methods (ToEpochSeconds/FromEpochSeconds)
- The time format is consistent with what the client expects as it's used in LoadCubes packet
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify ExpiryTime handling in Plot class # Expected: Plot class should initialize ExpiryTime and use consistent time format # Search for ExpiryTime usage in Plot class ast-grep --pattern 'class Plot { $$$ ExpiryTime $_ $$$ }' # Search for ExpiryTime assignments rg "ExpiryTime.*=" -A 3Length of output: 19509
39-43: Verify Plot model compatibility with PlotInfo.The change from
ICollection<PlotInfo>toList<Plot>looks good, but let's verify that thePlotclass contains all necessary fields previously accessed fromPlotInfo.✅ Verification successful
Let me try a different approach to verify the Plot class structure.
From the search results, I can now provide a definitive response:
The Plot class inherits from PlotInfo, maintaining full compatibility
The code shows that
Plotis a derived class ofPlotInfo:public class Plot(UgcMapGroup metadata) : PlotInfo(metadata)This inheritance relationship ensures that
Plothas all the necessary properties fromPlotInfo, including:
Number(from base class)PlotMode(from base class, which represents the state)The change from
ICollection<PlotInfo>toList<Plot>is safe as:
- All required properties are available through inheritance
Plotis more specific thanPlotInfo, adding plot-specific functionality likeCubesmanagement🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify Plot class contains required fields from PlotInfo # Expected: Plot class should have Number and State properties # Search for Plot class definition ast-grep --pattern 'class Plot { $$$ Number $_ $$$ State $_ $$$ }'Length of output: 78
Script:
#!/bin/bash # Search for Plot class definition with ripgrep for better context rg "class Plot" -A 20 # Also search for PlotInfo to compare rg "class PlotInfo" -A 20Length of output: 4564
Summary by CodeRabbit
New Features
Bug Fixes
Refactor