Skip to content

Commit

Permalink
Merge pull request #77 from Deewarz/gamemode-layer
Browse files Browse the repository at this point in the history
Addition to gamemode layer implementation
  • Loading branch information
Segfaultd authored Nov 20, 2023
2 parents a1a8c29 + c30d8e5 commit 69e3b5c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
This codebase provides a suite of tools and libraries to simplify the development of multi-player modifications and ensure consistency across all of them. The primary goal is to provide a common foundation and interface, in regards to shared functionality and data. It covers many fields we found important during the development of multi-player mods, such as:
* **Networking**: The core of the framework, it provides all the necessary tools to synchronize data between players.
* **ECS**: Backed by a strong ECS framework that simplifies entity management and world streaming, it is also easily extensible.
* **Scripting**: The **Node.js** scripting layer provides an easy way to create and manage resources used on game servers. It also provides a common interface across all multi-player mods, making it easy to create and manage shared resources between games.
* **Scripting**: The **Node.js** scripting layer provides an easy way to create and manage gamemode used on game servers.
* **Logging**: It is always important to log actions and errors, so the framework provides a simple way to do so.
* **GUI**: It also provides a simple way to create and manage GUI elements using the **Chromium Embedded Framework** library.
* **Sentry**: The framework provides a simple way to report errors and exceptions to the **Sentry** service.
Expand Down
8 changes: 4 additions & 4 deletions code/framework/src/integrations/server/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ namespace Framework::Integrations::Server {
cxxopts::Options options(_opts.modSlug, _opts.modHelpText);
options.allow_unrecognised_options();
options.add_options("MafiaHub Integrations server", {
{"p,port", "Networking port to bind", cxxopts::value<int32_t>()->default_value(std::to_string(_opts.bindPort))},
{"p,port", "Networking port to bind", cxxopts::value<int32_t>()->default_value(std::to_string(_opts.bindPort))},
{"h,host", "Networking host to bind", cxxopts::value<std::string>()->default_value(_opts.bindHost)},
{"c,config", "JSON config file to read", cxxopts::value<std::string>()->default_value(_opts.modConfigFile)},
{"c,config", "JSON config file to read", cxxopts::value<std::string>()->default_value(_opts.modConfigFile)},
{"P,apiport", "HTTP API port to bind", cxxopts::value<int32_t>()->default_value(std::to_string(_opts.webBindPort))},
{"H,apihost", "HTTP API host to bind", cxxopts::value<std::string>()->default_value(_opts.webBindHost)},
{"help", "Prints this help message", cxxopts::value<bool>()->default_value("false")}
Expand Down Expand Up @@ -157,12 +157,12 @@ namespace Framework::Integrations::Server {
Logging::GetLogger(FRAMEWORK_INNER_SERVER)->info("Max Players:\t{}", _opts.maxPlayers);
Logging::GetLogger(FRAMEWORK_INNER_SERVER)->flush();

// Load the scripting resources when everything is ready
// Load the scripting gamemode when everything is ready
Logging::GetLogger(FRAMEWORK_INNER_SERVER)->info("Loading scripting gamemode...");
if(!_scriptingEngine->LoadGamemode()){
return ServerError::SERVER_SCRIPTING_INIT_FAILED;
}

return ServerError::SERVER_NONE;
}

Expand Down
12 changes: 6 additions & 6 deletions code/framework/src/scripting/engines/node/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ namespace Framework::Scripting::Engines::Node {

// Notify the gamemode, if loaded
if(_gamemodeLoaded){
InvokeEvent(Events[EventIDs::RESOURCE_UPDATED]);
InvokeEvent(Events[EventIDs::GAMEMODE_UPDATED]);
}
}

Expand Down Expand Up @@ -217,7 +217,7 @@ namespace Framework::Scripting::Engines::Node {
// Create the execution environment
node::EnvironmentFlags::Flags flags = (node::EnvironmentFlags::Flags)(node::EnvironmentFlags::kOwnsProcessState);
_gamemodeData = node::CreateIsolateData(_isolate, uv_default_loop(), GetPlatform());
std::vector<std::string> argv = {"mafiahub-resource"};
std::vector<std::string> argv = {"mafiahub-gamemode"};
_gamemodeEnvironment = node::CreateEnvironment(_gamemodeData, context, argv, argv, flags);

// Make sure isolate is linked to our node environment
Expand All @@ -232,8 +232,8 @@ namespace Framework::Scripting::Engines::Node {
RunGamemodeScript();

// Invoke the gamemode loaded event
InvokeEvent(Events[EventIDs::RESOURCE_LOADED]);
InvokeEvent(Events[EventIDs::GAMEMODE_LOADED]);

_gamemodeLoaded = true;
return true;
}
Expand All @@ -244,7 +244,7 @@ namespace Framework::Scripting::Engines::Node {
return false;
}

// Scope the resources
// Scope the gamemode
v8::Locker locker(_isolate);
v8::Isolate::Scope isolateScope(_isolate);
v8::HandleScope handleScope(_isolate);
Expand Down Expand Up @@ -324,7 +324,7 @@ namespace Framework::Scripting::Engines::Node {
_watcher.add(dir, cppfs::FileCreated | cppfs::FileRemoved | cppfs::FileModified | cppfs::FileAttrChanged, cppfs::Recursive);
_watcher.addHandler([this, path](cppfs::FileHandle &fh, cppfs::FileEvent ev) {
Logging::GetLogger(FRAMEWORK_INNER_SCRIPTING)->debug("Gamemode is reloaded due to the file changes");
// Close the resource first, we'll start with a clean slate
// Close the gamemode first, we'll start with a clean slate
if(this->IsGamemodeLoaded() && UnloadGamemode(path)){
LoadGamemode(path);
}
Expand Down
2 changes: 1 addition & 1 deletion code/framework/src/scripting/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
#include <string>

namespace Framework::Scripting {
std::map<EventIDs, std::string> Events = {{EventIDs::RESOURCE_LOADED, "resourceLoaded"}, {EventIDs::RESOURCE_UNLOADING, "resourceUnloading"}, {EventIDs::RESOURCE_UPDATED, "resourceUpdated"}};
std::map<EventIDs, std::string> Events = {{EventIDs::GAMEMODE_LOADED, "gamemodeLoaded"}, {EventIDs::GAMEMODE_UNLOADING, "gamemodeUnloading"}, {EventIDs::GAMEMODE_UPDATED, "gamemodeUpdated"}};
} // namespace Framework::Scripting
2 changes: 1 addition & 1 deletion code/framework/src/scripting/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <string>

namespace Framework::Scripting {
enum class EventIDs { RESOURCE_LOADED, RESOURCE_UNLOADING, RESOURCE_UPDATED };
enum class EventIDs { GAMEMODE_LOADED, GAMEMODE_UNLOADING, GAMEMODE_UPDATED };

extern std::map<EventIDs, std::string> Events;
} // namespace Framework::Scripting

0 comments on commit 69e3b5c

Please sign in to comment.