From 36d03df61a9d2e525713e9855c1f5cb51e29228d Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 5 Feb 2021 23:50:37 -0600 Subject: [PATCH 1/3] Add Command Logging plugin Add Chat Logging plugin Added RenX_OnCommandTriggered plugin event Adjusted CMake files as necessary Signed-off-by: Sarah --- src/Plugins/RenX/CMakeLists.txt | 2 + .../RenX/RenX.ChatLogging/CMakeLists.txt | 3 + .../RenX.ChatLogging/RenX_ChatLogging.cpp | 105 ++++++++++++++++ .../RenX/RenX.ChatLogging/RenX_ChatLogging.h | 33 ++++++ .../RenX/RenX.CommandLogging/CMakeLists.txt | 3 + .../RenX_CommandLogging.cpp | 112 ++++++++++++++++++ .../RenX.CommandLogging/RenX_CommandLogging.h | 34 ++++++ src/Plugins/RenX/RenX.Core/RenX_Plugin.cpp | 5 + src/Plugins/RenX/RenX.Core/RenX_Plugin.h | 1 + src/Plugins/RenX/RenX.Core/RenX_Server.cpp | 4 + 10 files changed, 302 insertions(+) create mode 100644 src/Plugins/RenX/RenX.ChatLogging/CMakeLists.txt create mode 100644 src/Plugins/RenX/RenX.ChatLogging/RenX_ChatLogging.cpp create mode 100644 src/Plugins/RenX/RenX.ChatLogging/RenX_ChatLogging.h create mode 100644 src/Plugins/RenX/RenX.CommandLogging/CMakeLists.txt create mode 100644 src/Plugins/RenX/RenX.CommandLogging/RenX_CommandLogging.cpp create mode 100644 src/Plugins/RenX/RenX.CommandLogging/RenX_CommandLogging.h diff --git a/src/Plugins/RenX/CMakeLists.txt b/src/Plugins/RenX/CMakeLists.txt index 9a88f0c..97111a8 100644 --- a/src/Plugins/RenX/CMakeLists.txt +++ b/src/Plugins/RenX/CMakeLists.txt @@ -14,6 +14,8 @@ endmacro(add_renx_plugin) add_subdirectory(RenX.AlwaysRecord) add_subdirectory(RenX.Announcements) add_subdirectory(RenX.Commands) +add_subdirectory(RenX.ChatLogging) +add_subdirectory(RenX.CommandLogging) add_subdirectory(RenX.ExcessiveHeadshots) add_subdirectory(RenX.ExtraLogging) add_subdirectory(RenX.Greetings) diff --git a/src/Plugins/RenX/RenX.ChatLogging/CMakeLists.txt b/src/Plugins/RenX/RenX.ChatLogging/CMakeLists.txt new file mode 100644 index 0000000..293f037 --- /dev/null +++ b/src/Plugins/RenX/RenX.ChatLogging/CMakeLists.txt @@ -0,0 +1,3 @@ +add_renx_plugin(RenX.ChatLogging + RenX_ChatLogging.cpp + RenX_ChatLogging.h) \ No newline at end of file diff --git a/src/Plugins/RenX/RenX.ChatLogging/RenX_ChatLogging.cpp b/src/Plugins/RenX/RenX.ChatLogging/RenX_ChatLogging.cpp new file mode 100644 index 0000000..309e21b --- /dev/null +++ b/src/Plugins/RenX/RenX.ChatLogging/RenX_ChatLogging.cpp @@ -0,0 +1,105 @@ +/** + * This file is in the public domain, furnished "as is", without technical + * support, and with no warranty, express or implied, as to its usefulness for + * any purpose. + * + * Written by Sarah E. + */ + +#include +#include +#include +#include "RenX_ChatLogging.h" +#include "RenX_Server.h" +#include "RenX_PlayerInfo.h" + +void RenX_ChatLogPlugin::PrepFile() +{ + // Check if date changed (Format: YYYY-MM-DD) + std::string current_date = getTimeFormat("%F"); + std::string full_date = getTimeFormat("%c"); + + if (current_date == last_date) { + return; + } + + last_date = current_date; + + // Close any currently opened file + + if (fs.is_open()) { + fs.close(); + } + + // Open new file + + std::string file_name = "ChatLog_" + current_date + ".log"; + fs.open(file_name, std::fstream::out | std::fstream::app); + + fs << "Session Start: " + << full_date + << std::endl; +} + +bool RenX_ChatLogPlugin::initialize() +{ + PrepFile(); + + return fs.is_open(); +} + +RenX_ChatLogPlugin::~RenX_ChatLogPlugin() +{ + if (fs.is_open()) { + fs.close(); + } +} + +std::ostream& operator<<(std::ostream& in_stream, const Jupiter::ReadableString& in_string) { + in_stream.write(in_string.ptr(), in_string.size()); + return in_stream; +} + +void RenX_ChatLogPlugin::RenX_OnChat(RenX::Server& server, const RenX::PlayerInfo& player, const Jupiter::ReadableString& message) +{ + WriteToLog(server, player, message, "ALL"); +} + +void RenX_ChatLogPlugin::RenX_OnTeamChat(RenX::Server& server, const RenX::PlayerInfo& player, const Jupiter::ReadableString& message) +{ + WriteToLog(server, player, message, "TEAM"); +} + +void RenX_ChatLogPlugin::WriteToLog(RenX::Server& server, const RenX::PlayerInfo& player, const Jupiter::ReadableString& message, std::string in_prefix) +{ + // Check if new file needs to be opened + PrepFile(); + + if (!fs.is_open()) { + return; + } + + const std::string& serverHostname = server.getSocketHostname(); + unsigned short serverPort = server.getSocketPort(); + + fs << getTimeFormat("%T") + << " " + << serverHostname + << ":" + << serverPort + << " " + << in_prefix + << " " + << player.name + << ": " + << message + << std::endl; +} + +// Plugin instantiation and entry point. +RenX_ChatLogPlugin pluginInstance; + +extern "C" JUPITER_EXPORT Jupiter::Plugin *getPlugin() +{ + return &pluginInstance; +} diff --git a/src/Plugins/RenX/RenX.ChatLogging/RenX_ChatLogging.h b/src/Plugins/RenX/RenX.ChatLogging/RenX_ChatLogging.h new file mode 100644 index 0000000..e30afd3 --- /dev/null +++ b/src/Plugins/RenX/RenX.ChatLogging/RenX_ChatLogging.h @@ -0,0 +1,33 @@ +/** + * This file is in the public domain, furnished "as is", without technical + * support, and with no warranty, express or implied, as to its usefulness for + * any purpose. + * + * Written by Sarah E. + */ + +#if !defined _RENX_CHATLOG_H_HEADER +#define _RENX_CHATLOG_H_HEADER + +#include "Jupiter/Plugin.h" +#include "Jupiter/Reference_String.h" +#include "RenX_Plugin.h" + +class RenX_ChatLogPlugin : public RenX::Plugin +{ +public: // Jupiter::Plugin + bool initialize() override; + ~RenX_ChatLogPlugin(); + +public: // RenX::Plugin + void RenX_OnTeamChat(RenX::Server& server, const RenX::PlayerInfo& player, const Jupiter::ReadableString& message) override; + void RenX_OnChat(RenX::Server& server, const RenX::PlayerInfo& player, const Jupiter::ReadableString& message) override; + +public: + void PrepFile(); + void WriteToLog(RenX::Server& server, const RenX::PlayerInfo& player, const Jupiter::ReadableString& message, std::string in_prefix); + std::string last_date; + std::fstream fs; +}; + +#endif // _RENX_CHATLOG_H_HEADER \ No newline at end of file diff --git a/src/Plugins/RenX/RenX.CommandLogging/CMakeLists.txt b/src/Plugins/RenX/RenX.CommandLogging/CMakeLists.txt new file mode 100644 index 0000000..6240bb0 --- /dev/null +++ b/src/Plugins/RenX/RenX.CommandLogging/CMakeLists.txt @@ -0,0 +1,3 @@ +add_renx_plugin(RenX.CommandLogging + RenX_CommandLogging.cpp + RenX_CommandLogging.h) \ No newline at end of file diff --git a/src/Plugins/RenX/RenX.CommandLogging/RenX_CommandLogging.cpp b/src/Plugins/RenX/RenX.CommandLogging/RenX_CommandLogging.cpp new file mode 100644 index 0000000..6dd4659 --- /dev/null +++ b/src/Plugins/RenX/RenX.CommandLogging/RenX_CommandLogging.cpp @@ -0,0 +1,112 @@ +/** + * This file is in the public domain, furnished "as is", without technical + * support, and with no warranty, express or implied, as to its usefulness for + * any purpose. + * + * Written by Sarah E. + */ + +#include +#include +#include +#include "RenX_CommandLogging.h" +#include "RenX_GameCommand.h" +#include "RenX_PlayerInfo.h" +#include "RenX_Server.h" +#include "RenX_Functions.h" + +using namespace Jupiter::literals; + +void RenX_CommandLoggingPlugin::PrepFile() +{ + // Check if date changed (Format: YYYY-MM-DD) + std::string current_date = getTimeFormat("%F"); + std::string full_date = getTimeFormat("%c"); + if (current_date == last_date) { + return; + } + + last_date = current_date; + + // Close any currently opened file + + if (fs.is_open()) { + fs.close(); + } + + // Open new file + + std::string file_name = "CommandLog_" + current_date + ".log"; + fs.open(file_name, std::fstream::out | std::fstream::app); + + fs << "Session Start: " + << full_date + << std::endl; +} + +bool RenX_CommandLoggingPlugin::initialize() +{ + RenX_CommandLoggingPlugin::min_access = this->config.get("MinPlayerLevelToLog"_jrs, 1); + RenX_CommandLoggingPlugin::min_cmd_access = this->config.get("MinCommandLevelToLog"_jrs, 1); + + PrepFile(); + + return fs.is_open(); +} + +RenX_CommandLoggingPlugin::~RenX_CommandLoggingPlugin() +{ + if (fs.is_open()) { + fs.close(); + } +} + +void RenX_CommandLoggingPlugin::RenX_OnCommandTriggered(RenX::Server& server, const Jupiter::ReadableString& trigger, RenX::PlayerInfo& player, const Jupiter::ReadableString& parameters, RenX::GameCommand& command) +{ + if (player.access < min_access || command.getAccessLevel() < min_cmd_access) { + return; + } + + WriteToLog(server, player, trigger + " " + parameters); +} + +std::ostream& operator<<(std::ostream& in_stream, const Jupiter::ReadableString& in_string) { + in_stream.write(in_string.ptr(), in_string.size()); + return in_stream; +} + +void RenX_CommandLoggingPlugin::WriteToLog(RenX::Server& server, const RenX::PlayerInfo& player, const Jupiter::ReadableString& message) +{ + // Check if new file needs to be opened + PrepFile(); + + if (!fs.is_open()) { + return; + } + + const std::string& serverHostname = server.getSocketHostname(); + unsigned short serverPort = server.getSocketPort(); + + fs << getTimeFormat("%T") + << " " + << serverHostname + << ":" + << serverPort + << " " + << std::to_string(player.access) + << " " + << player.name + << ": " + << message + << std::endl; +} + + // Plugin instantiation and entry point. +RenX_CommandLoggingPlugin pluginInstance; + +extern "C" JUPITER_EXPORT Jupiter::Plugin * getPlugin() +{ + return &pluginInstance; +} + + diff --git a/src/Plugins/RenX/RenX.CommandLogging/RenX_CommandLogging.h b/src/Plugins/RenX/RenX.CommandLogging/RenX_CommandLogging.h new file mode 100644 index 0000000..032bd3e --- /dev/null +++ b/src/Plugins/RenX/RenX.CommandLogging/RenX_CommandLogging.h @@ -0,0 +1,34 @@ +/** + * This file is in the public domain, furnished "as is", without technical + * support, and with no warranty, express or implied, as to its usefulness for + * any purpose. + * + * Written by Sarah E. + */ + +#if !defined _RENX_CMDLOGGING_H_HEADER +#define _RENX_CMDLOGGING_H_HEADER + +#include "Jupiter/Plugin.h" +#include "Jupiter/Reference_String.h" +#include "RenX_Plugin.h" + +class RenX_CommandLoggingPlugin : public RenX::Plugin +{ +public: // Jupiter::Plugin + bool initialize() override; + ~RenX_CommandLoggingPlugin(); + +public: // RenX::Plugin + void RenX_OnCommandTriggered(RenX::Server& server, const Jupiter::ReadableString& trigger, RenX::PlayerInfo& player, const Jupiter::ReadableString& parameters, RenX::GameCommand& command) override; + +public: + void PrepFile(); + void WriteToLog(RenX::Server& server, const RenX::PlayerInfo& player, const Jupiter::ReadableString& message); + std::string last_date; + std::fstream fs; + int min_access; + int min_cmd_access; +}; + +#endif // _RENX_CMDLOGGING_H_HEADER \ No newline at end of file diff --git a/src/Plugins/RenX/RenX.Core/RenX_Plugin.cpp b/src/Plugins/RenX/RenX.Core/RenX_Plugin.cpp index 0c4570d..f18649d 100644 --- a/src/Plugins/RenX/RenX.Core/RenX_Plugin.cpp +++ b/src/Plugins/RenX/RenX.Core/RenX_Plugin.cpp @@ -91,6 +91,11 @@ bool RenX::Plugin::RenX_OnBan(Server &, const PlayerInfo &, Jupiter::StringType return false; } +void RenX::Plugin::RenX_OnCommandTriggered(Server& server, const Jupiter::ReadableString& trigger, RenX::PlayerInfo& player, const Jupiter::ReadableString& parameters, GameCommand& command) +{ + return; +} + void RenX::Plugin::RenX_OnJoin(Server &, const PlayerInfo &) { return; diff --git a/src/Plugins/RenX/RenX.Core/RenX_Plugin.h b/src/Plugins/RenX/RenX.Core/RenX_Plugin.h index 2f41b7b..d9ff8ce 100644 --- a/src/Plugins/RenX/RenX.Core/RenX_Plugin.h +++ b/src/Plugins/RenX/RenX.Core/RenX_Plugin.h @@ -55,6 +55,7 @@ namespace RenX virtual void RenX_OnServerFullyConnected(Server &server); virtual void RenX_OnServerDisconnect(Server &server, RenX::DisconnectReason reason); virtual bool RenX_OnBan(Server &server, const PlayerInfo &player, Jupiter::StringType &data); + virtual void RenX_OnCommandTriggered(Server& server, const Jupiter::ReadableString& trigger, RenX::PlayerInfo& player, const Jupiter::ReadableString& parameters, GameCommand& command); /** Player type logs */ virtual void RenX_OnJoin(Server &server, const PlayerInfo &player); diff --git a/src/Plugins/RenX/RenX.Core/RenX_Server.cpp b/src/Plugins/RenX/RenX.Core/RenX_Server.cpp index 949e2ae..c04d05f 100644 --- a/src/Plugins/RenX/RenX.Core/RenX_Server.cpp +++ b/src/Plugins/RenX/RenX.Core/RenX_Server.cpp @@ -1158,6 +1158,10 @@ RenX::GameCommand *RenX::Server::triggerCommand(const Jupiter::ReadableString &t else RenX::Server::sendMessage(player, "Access Denied."_jrs); + Jupiter::ArrayList& xPlugins = *getCore()->getPlugins(); + for (size_t i = 0; i < xPlugins.size(); i++) + xPlugins.get(i)->RenX_OnCommandTriggered(*this, trigger, player, parameters, *cmd); + return cmd; } } From 581f470e68d097d36da06682eb8173a8cd6ad64e Mon Sep 17 00:00:00 2001 From: Jessica James Date: Fri, 23 Apr 2021 13:06:26 -0500 Subject: [PATCH 2/3] Playing with github actions --- .github/workflows/cmake.yml | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/cmake.yml diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml new file mode 100644 index 0000000..730a9e3 --- /dev/null +++ b/.github/workflows/cmake.yml @@ -0,0 +1,39 @@ +name: CMake + +on: [push] + +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Release + +jobs: + build: + # The CMake configure and build commands are platform agnostic and should work equally + # well on Windows or Mac. You can convert this to a matrix build if you need + # cross-platform coverage. + # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Create Build Environment + # Some projects don't allow in-source building, so create a separate build directory + # We'll use this as our working directory for all subsequent commands + run: cmake -E make_directory ${{github.workspace}}/build + + - name: Configure CMake + # Use a bash shell so we can use the same syntax for environment variable + # access regardless of the host operating system + shell: bash + working-directory: ${{github.workspace}}/build + # Note the current convention is to use the -S and -B options here to specify source + # and build directories, but this is only available with CMake 3.13 and higher. + # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 + run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE + + - name: Build + working-directory: ${{github.workspace}}/build + shell: bash + # Execute the build. You can specify a specific target with "--target " + run: cmake --build . --config $BUILD_TYPE From 4935bc71e0adfeeb2102f2b8934bb53c74cb93ff Mon Sep 17 00:00:00 2001 From: Jessica James Date: Fri, 23 Apr 2021 13:25:07 -0500 Subject: [PATCH 3/3] Add with submodules recursive --- .github/workflows/cmake.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 730a9e3..4633eff 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -16,6 +16,9 @@ jobs: steps: - uses: actions/checkout@v2 + with: + submodules: recursive + - name: Create Build Environment # Some projects don't allow in-source building, so create a separate build directory