Skip to content

Feature: Admin Permissions#412

Merged
AngeloTadeucci merged 3 commits intomasterfrom
feature/permissions
Apr 10, 2025
Merged

Feature: Admin Permissions#412
AngeloTadeucci merged 3 commits intomasterfrom
feature/permissions

Conversation

@Zintixx
Copy link
Collaborator

@Zintixx Zintixx commented Apr 10, 2025

Summary by CodeRabbit

  • New Features
    • Introduced enhanced management for admin permissions with dedicated commands to set, remove, and view permissions.
    • Added a new "Game Master" role consolidating various admin capabilities for streamlined administration.
    • Introduced a new command for forcing daily resets for players.
    • Added new properties for managing admin permissions in account and player classes.
    • Enhanced command structure by integrating permission handling directly into various commands.
  • Refactor
    • Optimized command registration and error handling to enforce stricter permission checks.
    • Modified access to the daily reset functionality, refining its availability.
  • Chores
    • Performed minor cleanups in session initialization and permission handling to ensure robust multi-role support.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 10, 2025

Walkthrough

This pull request introduces a framework for managing administrative permissions throughout the application. It adds a new Permissions property to the Account class, updates the AdminPermissions enum with new values, and creates command classes for handling admin permissions. The command routing and session management processes are enhanced with permission checks, while unnecessary code elements and using directives are removed to streamline the codebase.

Changes

File(s) Change Summary
Maple2.Database/Model/Account.cs, Maple2.Model/Game/User/Account.cs, Maple2.Server/Game/Model/Field/Actor/FieldPlayer.cs Added new permissions properties and conversion logic in Account and FieldPlayer classes to support admin permissions.
Maple2.Server/Game/Commands/AdminPermissionCommand.cs, Maple2.Server/Game/Commands/CommandRouter.cs, Maple2.Server/Game/Commands/DailyResetCommand.cs, Maple2.Server/Game/Commands/PlayerCommand.cs, Maple2.Server/Game/Session/GameSession.cs Introduced new admin permission commands, integrated permission checks in command routing, registered commands during session entry, and removed the DailyResetCommand from player commands.
Maple2.Model/Enum/Admin.cs Updated the AdminPermissions enum by adding the “None” member and revising flags with the new “GameMaster” composite permission.
Maple2.Server/Game/Commands/AlertCommand.cs, Maple2.Server/Game/Service/ChannelService.Admin.cs Removed obsolete using directives and modified alert handling to bypass disconnect logic for Admin/GameMaster roles.

Sequence Diagram(s)

sequenceDiagram
  participant GS as GameSession
  participant CH as CommandHandler
  participant CR as CommandRouter
  GS->>CH: EnterServer calls RegisterCommands()
  CH->>CR: Registers commands with permission checks
  CR-->>CH: Returns allowed command list
Loading
sequenceDiagram
  participant P as Player
  participant CR as CommandRouter
  participant APC as AdminPermissionCommand
  P->>CR: Invoke command (e.g. set, remove, view permission)
  CR->>P: Verify AdminPermissions
  alt Sufficient Permission
      CR->>APC: Execute subcommand logic
      APC->>CR: Return result
      CR->>P: Deliver confirmation message
  else Insufficient Permission
      CR->>P: Send unknown command notice
  end
Loading

Possibly related PRs

  • Player Reporting, Custom String Boards, and Alerts #401: The changes in the main PR involve adding a Permissions property to the Account class and modifying conversion logic related to user permissions, which are related to the changes in the retrieved PR that introduce an AdminPermissions enum and various administrative command structures, as both involve enhancements to permission management within the application.

Poem

I’m a little rabbit with a happy code hop,
New permissions bloom as I cheer nonstop.
Accounts and commands now work hand in paw,
Admin magic refined without a glitch or flaw.
Byte by byte, the changes sing a joyful tune—
Hopping through the code under a digital moon! 🐰✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

Actionable comments posted: 2

🧹 Nitpick comments (8)
Maple2.Server.Game/Commands/DailyResetCommand.cs (1)

17-19: Consider adding error handling and feedback

The command doesn't provide any feedback to the user when executed successfully, nor does it handle potential exceptions that might occur during the daily reset process.

Consider adding feedback and basic error handling:

private void Handle(InvocationContext ctx) {
-    session.DailyReset();
+    try {
+        session.DailyReset();
+        ctx.Console.WriteLine("Daily reset completed successfully.");
+    } catch (Exception ex) {
+        ctx.Console.WriteLine($"Error during daily reset: {ex.Message}");
+    }
}
Maple2.Database/Model/Account.cs (1)

38-38: Consider adding a default value for Permissions.

The Permissions property doesn't have a default value, which could potentially lead to null reference exceptions when converting to the model account.

-public string Permissions { get; set; }
+public string Permissions { get; set; } = AdminPermissions.None.ToString();
Maple2.Model/Enum/Admin.cs (1)

81-81: Logical grouping of permissions for GameMaster role.

The GameMaster flag combines appropriate permissions for a game master: Warp, Ban, Alert, StringBoard, EventManagement, and PlayerCommands. This logical grouping simplifies permission assignment.

Consider adding a comment explaining why these specific permissions are bundled together for the GameMaster role.

+// GameMaster role combines all permissions needed for in-game moderation and player assistance
 GameMaster = Warp | Ban | Alert | StringBoard | EventManagement | PlayerCommands,
Maple2.Server.Game/Session/GameSession.cs (1)

177-177: Ensure re-registration logic is safe and idempotent.

Re-registering commands after player initialization is a sound practice to synchronize permissions; however, consider verifying that repeated calls to CommandHandler.RegisterCommands() won't cause performance degradation or potential concurrency conflicts if multiple sessions invoke or overlap this method.

Maple2.Server.Game/Commands/CommandRouter.cs (2)

43-76: Streamline permission checks using patterns or attributes.

The switch expression for permission checks here is helpful for readability. A few considerations:

  1. _ => true as a fallback might unintentionally allow new commands with no permissions set. Explicitly denying unknown commands might be safer.
  2. Repeated “HasFlag” calls can be replaced with a dictionary-based or attribute-based approach if the list grows, potentially reducing duplication.

119-121: Optional: Provide feedback for empty command sets.

Returning an empty string when no commands are available might be confusing for users. Consider returning a short “No commands are currently available.” message instead.

Maple2.Server.Game/Commands/AdminPermissionCommand.cs (2)

24-70: Refine permission-setting logic for broader scope.

  1. The SetCommand only searches the local field (session.Field.GetPlayers()), which might omit offline players or those in other fields. Confirm if the intent is to restrict admin changes only to currently active players in the same map.
  2. After setting the flag, re-registering commands is apt, ensuring immediate effect.

173-190: Method for enumerating permission flags is clear.

Skipping composite flags initially and then appending them at the bottom is a practical structure. Just ensure new composite flags remain excluded from the main loop.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f0e3888 and b46c8b2.

⛔ Files ignored due to path filters (3)
  • Maple2.Server.World/Migrations/20250410190731_AdminPermissions.Designer.cs is excluded by !Maple2.Server.World/Migrations/*
  • Maple2.Server.World/Migrations/20250410190731_AdminPermissions.cs is excluded by !Maple2.Server.World/Migrations/*
  • Maple2.Server.World/Migrations/Ms2ContextModelSnapshot.cs is excluded by !Maple2.Server.World/Migrations/*
📒 Files selected for processing (11)
  • Maple2.Database/Model/Account.cs (4 hunks)
  • Maple2.Model/Enum/Admin.cs (2 hunks)
  • Maple2.Model/Game/User/Account.cs (2 hunks)
  • Maple2.Server.Game/Commands/AdminPermissionCommand.cs (1 hunks)
  • Maple2.Server.Game/Commands/AlertCommand.cs (0 hunks)
  • Maple2.Server.Game/Commands/CommandRouter.cs (3 hunks)
  • Maple2.Server.Game/Commands/DailyResetCommand.cs (1 hunks)
  • Maple2.Server.Game/Commands/PlayerCommand.cs (0 hunks)
  • Maple2.Server.Game/Model/Field/Actor/FieldPlayer.cs (1 hunks)
  • Maple2.Server.Game/Service/ChannelService.Admin.cs (1 hunks)
  • Maple2.Server.Game/Session/GameSession.cs (1 hunks)
💤 Files with no reviewable changes (2)
  • Maple2.Server.Game/Commands/AlertCommand.cs
  • Maple2.Server.Game/Commands/PlayerCommand.cs
🧰 Additional context used
🧬 Code Graph Analysis (5)
Maple2.Server.Game/Commands/DailyResetCommand.cs (3)
Maple2.Server.Game/Session/GameSession.cs (4)
  • GameSession (37-805)
  • GameSession (106-116)
  • GameSession (698-698)
  • DailyReset (602-618)
Maple2.Server.Game/Commands/AlertCommand.cs (1)
  • Handle (33-56)
Maple2.Server.Game/Commands/AdminPermissionCommand.cs (3)
  • Handle (39-69)
  • Handle (87-121)
  • Handle (136-170)
Maple2.Server.Game/Session/GameSession.cs (1)
Maple2.Server.Game/Commands/CommandRouter.cs (1)
  • RegisterCommands (39-81)
Maple2.Server.Game/Service/ChannelService.Admin.cs (2)
Maple2.Server.Core/Packets/NoticePacket.cs (1)
  • NoticePacket (9-77)
Maple2.Server.Core/Network/Session.cs (1)
  • Disconnect (102-107)
Maple2.Model/Game/User/Account.cs (1)
Maple2.Database/Model/Account.cs (2)
  • Account (11-135)
  • PrestigeMission (148-152)
Maple2.Server.Game/Commands/AdminPermissionCommand.cs (6)
Maple2.Server.Game/Session/GameSession.cs (3)
  • GameSession (37-805)
  • GameSession (106-116)
  • GameSession (698-698)
Maple2.Server.Game/Model/Field/Actor/FieldPlayer.cs (2)
  • FieldPlayer (15-529)
  • FieldPlayer (94-107)
Maple2.Server.Game/Commands/CommandRouter.cs (1)
  • RegisterCommands (39-81)
Maple2.Server.Core/Packets/NoticePacket.cs (1)
  • NoticePacket (9-77)
Maple2.Database/Storage/Game/GameStorage.User.cs (1)
  • GetCharacterId (94-98)
Maple2.Model/Game/User/Account.cs (2)
  • Account (5-40)
  • Account (34-39)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (16)
Maple2.Server.Game/Service/ChannelService.Admin.cs (1)

32-39: Code block uses cleaner logical flow.

This block correctly removes the Disconnect flag for sessions that meet the condition and sends a modified notice.

Maple2.Server.Game/Model/Field/Actor/FieldPlayer.cs (1)

87-90: Well-implemented permission property.

The new AdminPermissions property provides a clean interface to access and modify admin permissions directly from the FieldPlayer class. This follows good object-oriented design by delegating to the underlying Account object.

Maple2.Database/Model/Account.cs (3)

3-3: Appropriate import for AdminPermissions enum.

The added import is required for the enum type used in the conversion logic.


77-77: Proper string conversion from enum.

This correctly stores the permissions as a string in the database model.


112-112: Robust parsing with fallback to None.

The implementation correctly handles the conversion from string to enum with case-insensitive parsing and a fallback to AdminPermissions.None if parsing fails, which is good defensive programming.

Maple2.Model/Game/User/Account.cs (3)

1-2: Required enum import added correctly.

The import is necessary for the new AdminPermissions property.


32-32: Good addition of AdminPermissions property.

This property extends the Account model with admin permission capabilities, enabling role-based access control in the game.


38-38: Proper initialization to None by default.

Setting the default value to AdminPermissions.None ensures that all accounts start with no special permissions, which is a security best practice.

Maple2.Model/Enum/Admin.cs (1)

68-68: Adding None as the zero value is best practice.

This follows the standard convention for flag enums to represent no flags being set.

Maple2.Server.Game/Commands/CommandRouter.cs (3)

7-9: Namespace imports are acceptable.

These new namespace imports for Maple2.Model.Enum, Maple2.Model.Game, and Maple2.Model.Metadata are logically correct given the permission checks and metadata references in the updated code.


103-107: Confirm restricting unknown commands to non-admin users aligns with intended design.

The check prevents players without permissions from even seeing a “commands” listing. Confirm whether this is desired behavior or if you want to allow partial command disclosures for non-admin users.


108-111: Good approach for listing available commands.

By displaying the command list here, you help admins discover command capabilities quickly. Ensure that unregistered or restricted commands do not appear in the output, which could mitigate confusion.

Maple2.Server.Game/Commands/AdminPermissionCommand.cs (4)

1-13: File-level overview.

This new file introduces the AdminPermissionCommand hierarchy for setting, removing, and viewing permissions. The namespaces and structure are consistent with the rest of the solution.


14-22: Constructor logic correctly aggregates subcommands.

The constructor unifies "set", "remove", and "view" under the “perm” parent command. This is a clean approach to grouping admin-permission-related operations, improving discoverability.


72-122: Prevent partial removal of composite permissions.

  1. The inability to remove AdminPermissions.Admin is enforced, but consider clarifying why “Admin” is treated as fully locked.
  2. Similar to SetCommand, RemoveCommand only locates players in the current field, which might limit the command’s utility if you intend cross-field or offline modifications.

124-172: Database lookups for viewing permissions seem correct, but watch performance.

Using GetCharacterId() and GetOrFetch() from GameStorage is logical; just ensure large-scale usage doesn’t cause performance bottlenecks. If frequent, consider caching or a unified approach for partial or offline lookups.

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.

Actionable comments posted: 3

🧹 Nitpick comments (3)
Maple2.Server.Game/Commands/AdminPermissionCommand.cs (3)

65-69: Persist permission changes for future sessions.
Currently, permissions are updated in-memory only. If the intent is to persist changes, ensure that the modified permissions get saved in the underlying data store so that they remain across player re-logins or server restarts.


127-170: Consider restricting who can view other players’ permissions.
The “view” command exposes any player’s permissions without any guard. Ensure that only authorized users can retrieve this sensitive data if it’s intended to be confidential.


173-188: Improve composite flag handling in GetFlagsString.
Skipping composite flags in the main loop and appending them as an afterthought is workable, but consider a more descriptive approach—such as grouping base flags separately from combos—and clarifying any invariant that composite flags should never appear individually.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b46c8b2 and 2d68205.

⛔ Files ignored due to path filters (3)
  • Maple2.Server.World/Migrations/20250404235104_RemoveSkillCooldown.cs is excluded by !Maple2.Server.World/Migrations/*
  • Maple2.Server.World/Migrations/20250406064924_DeathCount.cs is excluded by !Maple2.Server.World/Migrations/*
  • Maple2.Server.World/Migrations/20250410190731_AdminPermissions.cs is excluded by !Maple2.Server.World/Migrations/*
📒 Files selected for processing (1)
  • Maple2.Server.Game/Commands/AdminPermissionCommand.cs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
Maple2.Server.Game/Commands/AdminPermissionCommand.cs (5)
Maple2.Server.Game/Session/GameSession.cs (3)
  • GameSession (37-805)
  • GameSession (106-116)
  • GameSession (698-698)
Maple2.Server.Game/Model/Field/Actor/FieldPlayer.cs (2)
  • FieldPlayer (15-529)
  • FieldPlayer (94-107)
Maple2.Server.Core/Packets/NoticePacket.cs (1)
  • NoticePacket (9-77)
Maple2.Database/Storage/Game/GameStorage.User.cs (1)
  • GetCharacterId (94-98)
Maple2.Model/Game/User/Account.cs (2)
  • Account (5-40)
  • Account (34-39)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: build

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.

Actionable comments posted: 0

♻️ Duplicate comments (1)
Maple2.Server.Game/Commands/AdminPermissionCommand.cs (1)

73-122: Use bitwise checks for removing “Admin” permission.
You are comparing player.AdminPermissions == AdminPermissions.Admin at [114–117]. This is a known pitfall if the admin permission is combined with other flags.

- if (player.AdminPermissions == AdminPermissions.Admin) {
+ if ((player.AdminPermissions & AdminPermissions.Admin) == AdminPermissions.Admin) {
    ctx.Console.Out.WriteLine($"Cannot remove admin permissions from {playerName}.");
    return;
}
🧹 Nitpick comments (5)
Maple2.Server.Game/Commands/FindCommand.cs (1)

16-16: Consider renaming to avoid overshadowing the base field.
Defining public const AdminPermissions RequiredPermission can cause confusion because the GameCommand base class also has a RequiredPermission field. To reduce ambiguity, consider using a unique constant name or removing the constant in favor of directly passing the enum value to the base constructor.

- public const AdminPermissions RequiredPermission = AdminPermissions.Find;
+ private const AdminPermissions DefaultPermission = AdminPermissions.Find;
Maple2.Server.Game/Commands/NpcCommand.cs (2)

17-17: Potential naming overlap with base.
Like in FindCommand, you might rename the constant to avoid overshadowing the base class’s RequiredPermission field.


61-61: Potential naming overlap.
Same caution regarding overshadowing the base RequiredPermission property.

Maple2.Server.Game/Commands/AdminPermissionCommand.cs (1)

25-71: Setting permissions logic looks functional.
No major issues. However, be mindful that you’re retrieving the player only within the current field. If the target player is elsewhere or offline, this command won’t find them. That might be intended but worth confirming.

Do you need help with handling offline or cross-field players?

Maple2.Server.Game/Commands/CommandRouter.cs (1)

108-113: Abstract GameCommand for permission-based commands is good.
Centralizing permissions in GameCommand is clean. However, be cautious about overshadowing the RequiredPermission field in derived classes with a same-named constant.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2d68205 and e7f6291.

📒 Files selected for processing (22)
  • Maple2.Server.Game/Commands/AdminPermissionCommand.cs (1 hunks)
  • Maple2.Server.Game/Commands/AlertCommand.cs (1 hunks)
  • Maple2.Server.Game/Commands/BuffCommand.cs (1 hunks)
  • Maple2.Server.Game/Commands/CommandRouter.cs (4 hunks)
  • Maple2.Server.Game/Commands/CoordCommand.cs (1 hunks)
  • Maple2.Server.Game/Commands/DailyResetCommand.cs (1 hunks)
  • Maple2.Server.Game/Commands/DebugCommand.cs (1 hunks)
  • Maple2.Server.Game/Commands/FieldCommand.cs (1 hunks)
  • Maple2.Server.Game/Commands/FindCommand.cs (1 hunks)
  • Maple2.Server.Game/Commands/FreeCamCommand.cs (1 hunks)
  • Maple2.Server.Game/Commands/HomeCommand.cs (1 hunks)
  • Maple2.Server.Game/Commands/ItemCommand.cs (1 hunks)
  • Maple2.Server.Game/Commands/KillCommand.cs (1 hunks)
  • Maple2.Server.Game/Commands/NpcCommand.cs (2 hunks)
  • Maple2.Server.Game/Commands/PetCommand.cs (2 hunks)
  • Maple2.Server.Game/Commands/PlayerCommand.cs (1 hunks)
  • Maple2.Server.Game/Commands/QuestCommand.cs (1 hunks)
  • Maple2.Server.Game/Commands/StringBoardCommand.cs (1 hunks)
  • Maple2.Server.Game/Commands/TriggerCommand.cs (1 hunks)
  • Maple2.Server.Game/Commands/TutorialCommand.cs (1 hunks)
  • Maple2.Server.Game/Commands/WarpCommand.cs (2 hunks)
  • Maple2.Server.Game/Program.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Maple2.Server.Game/Commands/DailyResetCommand.cs
🧰 Additional context used
🧬 Code Graph Analysis (14)
Maple2.Server.Game/Program.cs (1)
Maple2.Server.Game/Commands/CommandRouter.cs (2)
  • GameCommand (108-113)
  • GameCommand (110-112)
Maple2.Server.Game/Commands/FieldCommand.cs (4)
Maple2.Server.Game/Commands/CommandRouter.cs (2)
  • GameCommand (108-113)
  • GameCommand (110-112)
Maple2.Server.Game/Session/GameSession.cs (3)
  • GameSession (37-805)
  • GameSession (106-116)
  • GameSession (698-698)
Maple2.Server.Game/Session/GameSession.State.cs (1)
  • GameSession (12-60)
Maple2.Database/Storage/Metadata/MapEntityStorage.cs (1)
  • MapEntityStorage (13-148)
Maple2.Server.Game/Commands/TutorialCommand.cs (3)
Maple2.Server.Game/Commands/CommandRouter.cs (2)
  • GameCommand (108-113)
  • GameCommand (110-112)
Maple2.Server.Game/Util/ItemStatsCalculator.cs (1)
  • ItemStatsCalculator (14-647)
Maple2.Server.Game/Session/GameSession.cs (3)
  • GameSession (37-805)
  • GameSession (106-116)
  • GameSession (698-698)
Maple2.Server.Game/Commands/HomeCommand.cs (3)
Maple2.Server.Game/Commands/CommandRouter.cs (2)
  • GameCommand (108-113)
  • GameCommand (110-112)
Maple2.Server.Game/Session/GameSession.cs (3)
  • GameSession (37-805)
  • GameSession (106-116)
  • GameSession (698-698)
Maple2.Database/Storage/Metadata/TableMetadataStorage.cs (2)
  • TableMetadataStorage (8-215)
  • TableMetadataStorage (135-195)
Maple2.Server.Game/Commands/DebugCommand.cs (2)
Maple2.Server.Game/Commands/CommandRouter.cs (2)
  • GameCommand (108-113)
  • GameCommand (110-112)
Maple2.Server.Game/Session/GameSession.cs (3)
  • GameSession (37-805)
  • GameSession (106-116)
  • GameSession (698-698)
Maple2.Server.Game/Commands/CoordCommand.cs (2)
Maple2.Server.Game/Commands/CommandRouter.cs (2)
  • GameCommand (108-113)
  • GameCommand (110-112)
Maple2.Database/Storage/Metadata/MapMetadataStorage.cs (2)
  • MapMetadataStorage (12-95)
  • MapMetadataStorage (19-26)
Maple2.Server.Game/Commands/AdminPermissionCommand.cs (6)
Maple2.Server.Game/Commands/CommandRouter.cs (2)
  • GameCommand (108-113)
  • GameCommand (110-112)
Maple2.Server.Game/Session/GameSession.cs (3)
  • GameSession (37-805)
  • GameSession (106-116)
  • GameSession (698-698)
Maple2.Server.Game/Model/Field/Actor/FieldPlayer.cs (2)
  • FieldPlayer (15-529)
  • FieldPlayer (94-107)
Maple2.Server.Core/Packets/NoticePacket.cs (1)
  • NoticePacket (9-77)
Maple2.Database/Storage/Game/GameStorage.User.cs (1)
  • GetCharacterId (94-98)
Maple2.Model/Game/User/Account.cs (2)
  • Account (5-40)
  • Account (34-39)
Maple2.Server.Game/Commands/FindCommand.cs (1)
Maple2.Server.Game/Commands/CommandRouter.cs (2)
  • GameCommand (108-113)
  • GameCommand (110-112)
Maple2.Server.Game/Commands/NpcCommand.cs (3)
Maple2.Server.Game/Commands/CommandRouter.cs (2)
  • GameCommand (108-113)
  • GameCommand (110-112)
Maple2.Server.Game/Session/GameSession.cs (3)
  • GameSession (37-805)
  • GameSession (106-116)
  • GameSession (698-698)
Maple2.Database/Storage/Metadata/NpcMetadataStorage.cs (2)
  • NpcMetadataStorage (11-90)
  • NpcMetadataStorage (19-33)
Maple2.Server.Game/Commands/WarpCommand.cs (3)
Maple2.Server.Game/Commands/CommandRouter.cs (2)
  • GameCommand (108-113)
  • GameCommand (110-112)
Maple2.Server.Game/Session/GameSession.cs (3)
  • GameSession (37-805)
  • GameSession (106-116)
  • GameSession (698-698)
Maple2.Database/Storage/Metadata/MapMetadataStorage.cs (2)
  • MapMetadataStorage (12-95)
  • MapMetadataStorage (19-26)
Maple2.Server.Game/Commands/ItemCommand.cs (4)
Maple2.Database/Model/Item/Item.cs (1)
  • Maple2 (99-145)
Maple2.Server.Game/Commands/CommandRouter.cs (2)
  • GameCommand (108-113)
  • GameCommand (110-112)
Maple2.Server.Game/Session/GameSession.cs (3)
  • GameSession (37-805)
  • GameSession (106-116)
  • GameSession (698-698)
Maple2.Database/Storage/Metadata/ItemMetadataStorage.cs (2)
  • ItemMetadataStorage (10-86)
  • ItemMetadataStorage (16-22)
Maple2.Server.Game/Commands/PlayerCommand.cs (2)
Maple2.Server.Game/Commands/CommandRouter.cs (2)
  • GameCommand (108-113)
  • GameCommand (110-112)
Maple2.Server.Game/Session/GameSession.cs (3)
  • GameSession (37-805)
  • GameSession (106-116)
  • GameSession (698-698)
Maple2.Server.Game/Commands/BuffCommand.cs (3)
Maple2.Server.Game/Commands/CommandRouter.cs (2)
  • GameCommand (108-113)
  • GameCommand (110-112)
Maple2.Server.Game/Session/GameSession.cs (3)
  • GameSession (37-805)
  • GameSession (106-116)
  • GameSession (698-698)
Maple2.Database/Storage/Metadata/SkillMetadataStorage.cs (2)
  • SkillMetadataStorage (11-81)
  • SkillMetadataStorage (17-19)
Maple2.Server.Game/Commands/CommandRouter.cs (3)
Maple2.Server.Game/Session/GameSession.cs (3)
  • GameSession (37-805)
  • GameSession (106-116)
  • GameSession (698-698)
Maple2.Server.Core/Packets/NoticePacket.cs (1)
  • NoticePacket (9-77)
Maple2.Server.Game/Commands/GameConsole.cs (2)
  • Write (35-64)
  • Write (68-75)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (68)
Maple2.Server.Game/Program.cs (1)

139-141: Command registration updated to use GameCommand with permission handling.

The modification changes the command registration to use GameCommand instead of Command, which aligns with the new admin permissions framework. The addition of !type.IsAbstract also ensures that only concrete implementations are registered.

This change correctly integrates with the GameCommand abstract class (from CommandRouter.cs) that now includes the RequiredPermission property, enabling permission-based command execution. All commands inheriting from this class will now have proper permission checks.

Maple2.Server.Game/Commands/KillCommand.cs (3)

15-15: Class inheritance updated to support permission system

The class now inherits from GameCommand instead of Command, which enables the new admin permissions framework.


18-18: Clear permission requirement added

The command now explicitly requires AdminPermissions.GameMaster through a public constant. This improves security and establishes clear access control for the command.


20-20: Constructor updated to use permission system

The constructor now passes the required permission to the base class constructor, completing the integration with the admin permissions framework.

Maple2.Server.Game/Commands/HomeCommand.cs (4)

4-4: Added required using directive

Proper import for the AdminPermissions enum now that it's being used explicitly in this class.


11-11: Class inheritance updated to support permission system

The class now inherits from GameCommand instead of Command, incorporating permission-based access control.


14-14: Debug permission requirement defined

The command now explicitly requires AdminPermissions.Debug. This restricts access to users with debugging privileges only.


16-16: Constructor updated to use permission system

The constructor now passes the required permission to the base class constructor, properly integrating with the admin permissions framework.

Maple2.Server.Game/Commands/AlertCommand.cs (3)

8-8: Class inheritance updated to support permission system

The class now inherits from GameCommand instead of Command, enabling permission-based access control.


11-11: Alert permission requirement specified

The command now explicitly requires AdminPermissions.Alert, creating a specific permission level for sending alerts to all users.


15-15: Constructor updated to use permission system

The constructor now passes the required permission to the base class constructor, implementing the permission check.

Maple2.Server.Game/Commands/TutorialCommand.cs (4)

6-6: Added required using directive

Proper import for the AdminPermissions enum that's now being used in this class.


14-14: Class inheritance updated to support permission system

The class now inherits from GameCommand instead of Command, integrating with the permission framework.


17-17: Debug permission requirement specified

The command now requires AdminPermissions.Debug, ensuring only users with debug privileges can access tutorial commands.


25-25: Constructor updated to use permission system

The constructor now passes the required permission to the base class constructor, properly implementing the permission check.

Maple2.Server.Game/Commands/FieldCommand.cs (4)

5-5: Added necessary import for AdminPermissions enum.

The addition of the Maple2.Model.Enum import is necessary to use the AdminPermissions enum, which supports the permission-based command framework.


12-12: Updated class inheritance to use GameCommand.

The FieldCommand class now inherits from GameCommand instead of Command, which integrates it with the new permission management system.


15-15: Added required permission level for this command.

This constant properly defines the permission level needed to execute the FieldCommand, setting it to Debug level which is appropriate for a command that displays field information.


21-21: Updated constructor to use the new permission parameter.

The constructor now passes the required permission level to the GameCommand base class, ensuring proper permission checks during command execution.

Maple2.Server.Game/Commands/TriggerCommand.cs (4)

5-5: Added necessary import for AdminPermissions enum.

The addition of the Maple2.Model.Enum import allows the use of the AdminPermissions enum, consistent with the new permission framework implementation.


13-13: Updated class inheritance to use GameCommand.

TriggerCommand now inherits from GameCommand instead of Command, integrating it with the permission management system being implemented across command classes.


16-16: Added required permission level for this command.

The RequiredPermission constant is set to AdminPermissions.Debug, which is appropriate for a command that manipulates map triggers and requires elevated privileges.


18-18: Updated constructor to use the new permission parameter.

The constructor now properly passes the RequiredPermission constant to the GameCommand base class constructor, ensuring permission checks are applied when the command is executed.

Maple2.Server.Game/Commands/DebugCommand.cs (4)

13-13: Added necessary import for AdminPermissions enum.

Added import for Maple2.Model.Enum namespace to access the AdminPermissions enum, ensuring consistent implementation of the permission system across command classes.


18-18: Updated class inheritance to use GameCommand.

DebugCommand now inherits from GameCommand instead of Command, aligning with the new permission-based command framework being implemented.


21-21: Added required permission level for this command.

The RequiredPermission constant is set to AdminPermissions.Debug, which is appropriate for a command that provides debug functionality and requires administrator privileges.


25-25: Updated constructor to use the new permission parameter.

The constructor now passes the RequiredPermission constant to the GameCommand base class constructor, ensuring proper permission verification when the command is executed.

Maple2.Server.Game/Commands/PetCommand.cs (4)

6-6: Added necessary import for AdminPermissions enum.

Added import for Maple2.Model.Enum namespace to access the AdminPermissions enum, consistent with the permission framework implementation.


15-15: Updated class inheritance to use GameCommand.

PetCommand now inherits from GameCommand instead of Command, integrating it with the permission management system being implemented across the application.


18-18: Added appropriate permission level for this command.

The RequiredPermission constant is set to AdminPermissions.SpawnItem, which is more specific than the Debug permission used in other commands and appropriate for a command that spawns in-game pets.


24-24: Updated constructor to use the new permission parameter.

The constructor now passes the RequiredPermission constant to the GameCommand base class constructor, ensuring proper permission checks before allowing pet spawning.

Maple2.Server.Game/Commands/StringBoardCommand.cs (3)

11-11: Inheritance change looks good.

The change from inheriting Command to GameCommand aligns with the admin permissions framework being implemented.


14-14: Clear permission requirement definition.

Good addition of the RequiredPermission constant that explicitly defines the needed permission level for this command.


18-18: Constructor update properly implements permission checks.

The base constructor call now correctly passes the required permission level as the first parameter.

Maple2.Server.Game/Commands/QuestCommand.cs (3)

12-12: Inheritance change looks good.

Changing from Command to GameCommand follows the same pattern as other command classes in this PR.


15-15: Appropriate permission requirement.

The RequiredPermission constant is set to AdminPermissions.Quest, which makes sense for this command's functionality.


20-20: Constructor properly implements permission checks.

The base constructor is now called with the required permission as the first parameter, consistent with other command changes.

Maple2.Server.Game/Commands/ItemCommand.cs (4)

6-6: Added necessary enum import.

The import for Maple2.Model.Enum is required for the AdminPermissions enum.


14-14: Inheritance change follows permission framework pattern.

The change from Command to GameCommand is consistent with other command classes in this PR.


17-17: Appropriate permission requirement for item spawning.

Setting RequiredPermission to AdminPermissions.SpawnItem properly restricts this powerful command.


25-25: Constructor updated to implement permission checks.

The base constructor now receives the required permission as its first parameter, implementing the permission framework correctly.

Maple2.Server.Game/Commands/FreeCamCommand.cs (3)

10-10: Inheritance change follows permission framework pattern.

The change from Command to GameCommand is consistent with the other command classes in this PR.


13-13: Debug permission is appropriate for this feature.

Setting RequiredPermission to AdminPermissions.Debug is appropriate for a development/debugging tool like free camera.


17-17: Constructor properly implements permission checks.

The base constructor now correctly receives the required permission as its first parameter.

Maple2.Server.Game/Commands/PlayerCommand.cs (1)

14-14: Well implemented permission framework for PlayerCommand

The code has been updated to use the new GameCommand as the base class and correctly sets the required admin permission. This change aligns with the PR objective of introducing an admin permissions framework.

Also applies to: 17-17, 19-19

Maple2.Server.Game/Commands/CoordCommand.cs (1)

7-7: Proper implementation of permission requirements for CoordCommand

The command has been updated to inherit from GameCommand with the appropriate AdminPermissions.Debug permission level. The necessary import for Maple2.Model.Enum has been added to access the AdminPermissions enum.

Also applies to: 14-14, 17-17, 22-22

Maple2.Server.Game/Commands/WarpCommand.cs (2)

21-21: Correctly implemented permissions for WarpCommand

The WarpCommand class now properly inherits from GameCommand and requires the AdminPermissions.Warp permission level to execute, enhancing the security of map warping commands.

Also applies to: 24-24, 29-29


61-61: Consistent permission implementation for GotoCommand

The GotoCommand class has been updated with the same permission level as WarpCommand, which is logical since both commands provide similar functionality. The implementation is consistent with the overall permission framework.

Also applies to: 64-64, 66-66

Maple2.Server.Game/Commands/BuffCommand.cs (1)

5-5: Appropriate permission level for BuffCommand

The BuffCommand class now requires AdminPermissions.GameMaster permissions, which is a sensible choice given that adding buffs can significantly impact gameplay. The implementation follows the same pattern as other command classes in this PR.

Also applies to: 13-13, 16-16, 21-21

Maple2.Server.Game/Commands/FindCommand.cs (3)

6-6: Import is appropriate.
The added import using Maple2.Model.Enum; is necessary for referencing AdminPermissions.


13-13: Switch to GameCommand is consistent.
Inheriting from GameCommand aligns with the new permission-based approach.


24-24: Base constructor usage looks good.
Passing the known permission, name, and description to the GameCommand constructor is correct.

Maple2.Server.Game/Commands/NpcCommand.cs (5)

6-6: Import is appropriate.
This import is required for the AdminPermissions enum usage.


14-14: Transition to GameCommand is correct.
Aligns with the overall permission-based architecture.


22-22: Constructor signature is consistent.
Providing the permission constant first to the GameCommand base constructor matches the project’s new standard.


58-58: Separate command for NPC animation is a good design.
Inheriting from GameCommand ensures this is also subject to permission checks.


66-66: Correct usage of base constructor.
This maintains consistency with the new permission requirements.

Maple2.Server.Game/Commands/AdminPermissionCommand.cs (3)

14-23: Top-level command structure for admin permissions is effective.
The overall design to introduce subcommands for set, remove, and view is clean. However, ensure that separate subcommands don’t need distinct permission levels if narrower scoping is desired.


125-172: Viewing permissions works correctly.
This logic correctly shows the player’s stored permissions from the database. If future designs require checking whether the user is currently active, consider adding a presence check.


174-190: Flag listing is comprehensive.
Skipping composite permissions initially and adding them later is a neat approach.

Maple2.Server.Game/Commands/CommandRouter.cs (8)

6-8: New using statements align with the updated permission model.
These references to Maple2.Model.Enum, Maple2.Model.Game, and Maple2.Server.Core.Packets are essential for the new command structure.


15-16: Switching field types to GameCommand is consistent.
Replacing the old Command references with GameCommand ensures that permission checks are centrally managed.


21-23: Collecting GameCommand instances is correct.
This properly resolves each GameCommand via dependency injection and aggregates them.


38-48: Registering commands based on flags is appropriate.
This filter ensures only commands matching the player’s admin flags are registered. If a user has multiple flags, HasFlag will correctly allow any matching permission.


69-72: Command invocation is updated properly.
Switching to GameCommand and preserving arguments ensures no regression.


74-77: Validate partial or no permissions.
You’re checking for AdminPermissions.None, which suits a no-permission case. Additionally, limiting the “commands” listing to actual admin users (or a special case) prevents surfers from enumerating command usage.


79-81: Displaying command list only when appropriate.
If the user has zero permissions, you provide no command list. This meets the requirement that non-admins shouldn’t see restricted commands.


91-95: Defensive checks for empty command list.
This guard ensures the output remains clear if no commands are available for the user.

@AngeloTadeucci AngeloTadeucci merged commit cdd7e66 into master Apr 10, 2025
4 checks passed
@AngeloTadeucci AngeloTadeucci deleted the feature/permissions branch April 10, 2025 22:48
@coderabbitai coderabbitai bot mentioned this pull request Jun 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments