Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/JAJames/Jupiter-Bot
- Loading branch information
Showing
11 changed files
with
344 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
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 | ||
with: | ||
submodules: recursive | ||
|
||
|
||
- 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 <NAME>" | ||
run: cmake --build . --config $BUILD_TYPE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
add_renx_plugin(RenX.ChatLogging | ||
RenX_ChatLogging.cpp | ||
RenX_ChatLogging.h) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. <sarah.evans@qq.com> | ||
*/ | ||
|
||
#include <iostream> | ||
#include <fstream> | ||
#include <string> | ||
#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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. <sarah.evans@qq.com> | ||
*/ | ||
|
||
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
add_renx_plugin(RenX.CommandLogging | ||
RenX_CommandLogging.cpp | ||
RenX_CommandLogging.h) |
112 changes: 112 additions & 0 deletions
112
src/Plugins/RenX/RenX.CommandLogging/RenX_CommandLogging.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. <sarah.evans@qq.com> | ||
*/ | ||
|
||
#include <iostream> | ||
#include <fstream> | ||
#include <string> | ||
#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<int>("MinPlayerLevelToLog"_jrs, 1); | ||
RenX_CommandLoggingPlugin::min_cmd_access = this->config.get<int>("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; | ||
} | ||
|
||
|
34 changes: 34 additions & 0 deletions
34
src/Plugins/RenX/RenX.CommandLogging/RenX_CommandLogging.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. <sarah.evans@qq.com> | ||
*/ | ||
|
||
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters