Skip to content

Conversation

@Segfaultd
Copy link
Member

@Segfaultd Segfaultd commented Dec 20, 2025

Summary by CodeRabbit

  • Refactor

    • Internal event dispatching for chat, player, and vehicle moved to resource-managed global events.
    • Entities now follow resource-reload lifecycle behavior.
  • New Features

    • Added a freeroam resource with startup/shutdown lifecycle hooks and manifest.
    • Added a shared-utils resource exposing a public utils export.
  • Chores

    • Removed legacy gamemode scaffolding, workspace/editor configs, and several SDK/type declaration files.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 20, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Replaces direct scripting engine calls with ResourceManager::InvokeGlobalEvent across core builtins; adds RemovedOnResourceReload lifecycle markers for some entities; removes legacy gamemode SDK/config; and introduces new resources freeroam and shared-utils with updated event APIs and exports.

Changes

Cohort / File(s) Summary
Core builtin event dispatch
code/server/src/core/builtins/chat.h, code/server/src/core/builtins/player.cpp, code/server/src/core/builtins/vehicle.cpp
Swap direct scripting engine invocations for ResourceManager::InvokeGlobalEvent, add scripting/resource/resource_manager.h includes and null-checks; behavior preserved but dispatched via ResourceManager.
Core module lifecycle marker
code/server/src/core/modules/vehicle.cpp, code/server/src/core/modules/human.cpp
Replace RemovedOnGameModeReload with RemovedOnResourceReload for entity component registrations to tie removal to resource reloads.
Gamemode removal (docs/config/SDK)
gamemode/...
gamemode/.editorconfig, gamemode/README.md, gamemode/gamemode.code-workspace, gamemode/manifest.json, gamemode/client/.luarc.json, gamemode/client/main.lua, gamemode/client/sdk.client.d.lua, gamemode/server/.luarc.json, gamemode/server/sdk.server.d.lua, gamemode/shared/.luarc.json, gamemode/shared/sdk.shared.d.lua
Delete legacy gamemode documentation, editor/workspace configs, Lua LSP configs, manifest and large SDK declaration files (removes many Lua type/event declarations).
Freeroam resource added / migrated
resources/freeroam/manifest.json, resources/freeroam/client/main.lua, resources/freeroam/server/main.lua, resources/freeroam/server/debug.lua
Add freeroam resource manifest and client/server mains; migrate gamemode logic to resource scope, replace Event.onEvent.onGlobal, Event.emitEvent.broadcast, update import paths and logging prefixes; add resource lifecycle handlers.
Shared-utils resource added
resources/shared-utils/manifest.json, resources/shared-utils/utils.lua
Add shared-utils manifest and register "utils" export via Exports.register("utils", utils).

Sequence Diagram(s)

mermaid
sequenceDiagram
autonumber
participant Core as C++ Core (builtin)
participant RM as ResourceManager
participant Lua as Lua Runtime / Global Event Handlers
participant Resource as Resource (freeroam/shared-utils)

Core->>RM: GetResourceManager()
alt RM exists
    Core->>RM: InvokeGlobalEvent("onPlayerConnected", PlayerProxy)
    RM->>Lua: Dispatch global event to subscribers
    Lua->>Resource: onGlobal callback invoked in resource
    Resource-->>Lua: callback logic (e.g., Console.log, Event.broadcast)
else RM null
    Core-->>Core: early return / skip invocation
end

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

  • Pay attention to C++ event-to-ResourceManager migration in chat.h, player.cpp, vehicle.cpp.
  • Verify lifecycle semantics for RemovedOnResourceReload in modules/vehicle.cpp and modules/human.cpp.
  • Confirm nothing left referencing removed gamemode SDK files and that freeroam/shared-utils event API changes match resource-side expectations.

Possibly related PRs

Suggested reviewers

  • zpl-zak

Poem

🐰 Hopped from engine calls to a manager bright,
Events now travel on a global flight,
Old gamemode leaves, new resources play,
Freeroam and utils hop into the day,
I nibble bugs and wish you smooth deploys!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.88% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ 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 'Resource manager system transition' directly reflects the main objective of the PR, which involves replacing direct scripting engine invocations with ResourceManager-based event dispatch across multiple core modules.

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4ce5911 and 21100df.

📒 Files selected for processing (1)
  • code/server/src/core/modules/human.cpp (1 hunks)

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

@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

🧹 Nitpick comments (5)
code/server/src/core/builtins/vehicle.cpp (2)

14-24: Consider logging when ResourceManager is unavailable.

The null-check provides safety, but silently returning when ResourceManager is unavailable could hide initialization issues. Consider adding a warning log to aid debugging if events fail to dispatch.

🔎 Suggested enhancement with logging
 void Vehicle::EventVehiclePlayerEnter(flecs::entity vehicle, flecs::entity player, int seatIndex) {
     const auto resourceManager = Framework::CoreModules::GetResourceManager();
     if (!resourceManager) {
+        // Log warning that ResourceManager is unavailable
+        FW_LOG_WARNING("ResourceManager unavailable, event onVehiclePlayerEnter not dispatched");
         return;
     }

     auto vehicleObj = Vehicle(vehicle);
     auto playerObj  = Player(player);

     resourceManager->InvokeGlobalEvent("onVehiclePlayerEnter", vehicleObj, playerObj, seatIndex);
 }

26-36: Apply the same logging recommendation here.

Similar to EventVehiclePlayerEnter, consider logging when ResourceManager is unavailable to aid in debugging.

code/server/src/core/builtins/chat.h (1)

16-28: Consider logging when ResourceManager is unavailable.

Similar to the vehicle event handlers, the null-checks provide safety but could hide initialization issues. Consider adding warning logs when ResourceManager is unavailable and events fail to dispatch.

🔎 Suggested enhancement with logging
 static void EventChatMessage(flecs::entity e, std::string message) {
     const auto resourceManager = Framework::CoreModules::GetResourceManager();
-    if (resourceManager) {
-        resourceManager->InvokeGlobalEvent("onChatMessage", Player(e), message);
+    if (!resourceManager) {
+        FW_LOG_WARNING("ResourceManager unavailable, event onChatMessage not dispatched");
+        return;
     }
+    resourceManager->InvokeGlobalEvent("onChatMessage", Player(e), message);
 }

 static void EventChatCommand(flecs::entity e, std::string message, std::string command, std::vector<std::string> args) {
     const auto resourceManager = Framework::CoreModules::GetResourceManager();
-    if (resourceManager) {
-        resourceManager->InvokeGlobalEvent("onChatCommand", Player(e), message, command, args);
+    if (!resourceManager) {
+        FW_LOG_WARNING("ResourceManager unavailable, event onChatCommand not dispatched");
+        return;
     }
+    resourceManager->InvokeGlobalEvent("onChatCommand", Player(e), message, command, args);
 }
code/server/src/core/builtins/player.cpp (1)

11-16: Consider logging when ResourceManager is unavailable.

The null check prevents crashes, but silent failures can complicate debugging in production. Consider adding telemetry or a warning log when resourceManager is null so operators can detect misconfiguration.

🔎 Optional: Add logging for null ResourceManager
 void Player::EventPlayerConnected(flecs::entity e) {
     const auto resourceManager = Framework::CoreModules::GetResourceManager();
     if (resourceManager) {
         resourceManager->InvokeGlobalEvent("onPlayerConnected", Player(e));
+    } else {
+        // Log warning: ResourceManager unavailable, event not dispatched
     }
 }
resources/freeroam/server/main.lua (1)

3-4: Add error handling for the shared-utils import.

If the shared-utils resource fails to load or export the utils module, accessing utils later (e.g., line 19, 296) will cause runtime errors. Consider adding a nil check or pcall wrapper to provide a clearer error message.

🔎 Proposed error handling
 -- Get utils from shared-utils resource export
-local utils = Exports.get("shared-utils", "utils")
+local utils = Exports.get("shared-utils", "utils")
+if not utils then
+  error("[FREEROAM] Failed to load utils from shared-utils resource")
+end
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 522f670 and 4ce5911.

📒 Files selected for processing (21)
  • code/server/src/core/builtins/chat.h (1 hunks)
  • code/server/src/core/builtins/player.cpp (1 hunks)
  • code/server/src/core/builtins/vehicle.cpp (1 hunks)
  • code/server/src/core/modules/vehicle.cpp (1 hunks)
  • gamemode/.editorconfig (0 hunks)
  • gamemode/README.md (0 hunks)
  • gamemode/client/.luarc.json (0 hunks)
  • gamemode/client/main.lua (0 hunks)
  • gamemode/client/sdk.client.d.lua (0 hunks)
  • gamemode/gamemode.code-workspace (0 hunks)
  • gamemode/manifest.json (0 hunks)
  • gamemode/server/.luarc.json (0 hunks)
  • gamemode/server/sdk.server.d.lua (0 hunks)
  • gamemode/shared/.luarc.json (0 hunks)
  • gamemode/shared/sdk.shared.d.lua (0 hunks)
  • resources/freeroam/client/main.lua (1 hunks)
  • resources/freeroam/manifest.json (1 hunks)
  • resources/freeroam/server/debug.lua (3 hunks)
  • resources/freeroam/server/main.lua (7 hunks)
  • resources/shared-utils/manifest.json (1 hunks)
  • resources/shared-utils/utils.lua (1 hunks)
💤 Files with no reviewable changes (11)
  • gamemode/README.md
  • gamemode/shared/.luarc.json
  • gamemode/gamemode.code-workspace
  • gamemode/.editorconfig
  • gamemode/client/main.lua
  • gamemode/manifest.json
  • gamemode/server/.luarc.json
  • gamemode/client/.luarc.json
  • gamemode/server/sdk.server.d.lua
  • gamemode/client/sdk.client.d.lua
  • gamemode/shared/sdk.shared.d.lua
🧰 Additional context used
🧬 Code graph analysis (2)
code/server/src/core/builtins/vehicle.cpp (2)
code/server/src/core/modules/vehicle.cpp (1)
  • Vehicle (27-42)
code/server/src/core/modules/vehicle.h (1)
  • Vehicle (9-22)
code/server/src/core/builtins/chat.h (1)
code/shared/rpc/chat_message.h (1)
  • MafiaMP (17-37)
🔇 Additional comments (13)
resources/shared-utils/utils.lua (1)

23-26: LGTM!

The export registration is implemented correctly and aligns with the manifest declaration. Maintaining the return statement preserves backward compatibility for any code using require().

resources/shared-utils/manifest.json (1)

1-16: LGTM!

The manifest structure is well-formed with appropriate metadata, file declarations, and exports. Priority 0 is suitable for a shared utility resource that other resources depend on.

resources/freeroam/manifest.json (1)

1-22: LGTM!

The manifest is properly structured with appropriate dependency on shared-utils and file declarations. The priority of 10 ensures freeroam loads after its dependencies.

resources/freeroam/client/main.lua (1)

1-7: LGTM!

The resource lifecycle functions are properly implemented with clear logging. The [FREEROAM] prefix maintains consistency with the server-side logging convention.

resources/freeroam/server/debug.lua (2)

4-19: LGTM!

The migration from Event.on to Event.onGlobal correctly aligns with the resource-based global event system. The debug logging functionality remains intact.

Also applies to: 21-43, 45-56


1-1: Import path change verified and correct.

The module exists at resources/freeroam/server/config.lua and is properly loaded by both debug.lua and main.lua using the new path freeroam/server/config. No references to the old gamemode/server/config path remain in the codebase.

code/server/src/core/builtins/player.cpp (3)

8-9: LGTM!

The include is necessary for the ResourceManager-based event dispatch pattern used throughout this file.


18-23: Consistent implementation.

Same ResourceManager-based dispatch pattern as EventPlayerConnected. The same logging consideration applies here.


25-30: Event name consistency verified across C++ and Lua files. All event names dispatched in player.cpp ("onPlayerConnected", "onPlayerDisconnected", "onPlayerDied") exactly match their registrations in resources/freeroam/server/main.lua. No string literal mismatches found.

resources/freeroam/server/main.lua (4)

8-28: LGTM!

The lifecycle hooks are well-structured and follow convention-based patterns. The resource initialization logic is clear, and logging uses the correct [FREEROAM] prefix.


30-105: Event registrations successfully migrated to global scope.

All event handlers correctly use Event.onGlobal instead of Event.on, aligning with the ResourceManager-based dispatch from C++. The event names match the dispatched events, and logging prefixes are consistently updated.


351-351: LGTM!

The change from Event.emit to Event.broadcast is correct for the global event system and aligns with the resource-based architecture.


335-336: LGTM!

The logging prefix is correctly updated to [FREEROAM], maintaining consistency with the rest of the file.

@github-project-automation github-project-automation bot moved this to In Progress in MafiaHub Dashboard Dec 20, 2025
@Segfaultd Segfaultd merged commit 02da51d into master Dec 20, 2025
1 check was pending
@Segfaultd Segfaultd deleted the scripting/resource-manager-system branch December 20, 2025 21:01
@github-project-automation github-project-automation bot moved this from In Progress to Done in MafiaHub Dashboard Dec 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants