Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/JAJames/Jupiter-Bot
Browse files Browse the repository at this point in the history
  • Loading branch information
JAJames committed Apr 25, 2021
2 parents fab246d + 4935bc7 commit 969a034
Show file tree
Hide file tree
Showing 11 changed files with 344 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/cmake.yml
@@ -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
2 changes: 2 additions & 0 deletions src/Plugins/RenX/CMakeLists.txt
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/Plugins/RenX/RenX.ChatLogging/CMakeLists.txt
@@ -0,0 +1,3 @@
add_renx_plugin(RenX.ChatLogging
RenX_ChatLogging.cpp
RenX_ChatLogging.h)
105 changes: 105 additions & 0 deletions 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. <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;
}
33 changes: 33 additions & 0 deletions 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. <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
3 changes: 3 additions & 0 deletions src/Plugins/RenX/RenX.CommandLogging/CMakeLists.txt
@@ -0,0 +1,3 @@
add_renx_plugin(RenX.CommandLogging
RenX_CommandLogging.cpp
RenX_CommandLogging.h)
112 changes: 112 additions & 0 deletions 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. <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 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. <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
5 changes: 5 additions & 0 deletions src/Plugins/RenX/RenX.Core/RenX_Plugin.cpp
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/Plugins/RenX/RenX.Core/RenX_Plugin.h
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/Plugins/RenX/RenX.Core/RenX_Server.cpp
Expand Up @@ -1158,6 +1158,10 @@ RenX::GameCommand *RenX::Server::triggerCommand(const Jupiter::ReadableString &t
else
RenX::Server::sendMessage(player, "Access Denied."_jrs);

Jupiter::ArrayList<RenX::Plugin>& xPlugins = *getCore()->getPlugins();
for (size_t i = 0; i < xPlugins.size(); i++)
xPlugins.get(i)->RenX_OnCommandTriggered(*this, trigger, player, parameters, *cmd);

return cmd;
}
}
Expand Down

0 comments on commit 969a034

Please sign in to comment.