Browse Source

Add Command Logging plugin

Add Chat Logging plugin
Added RenX_OnCommandTriggered plugin event

Adjusted CMake files as necessary

Signed-off-by: Sarah <sarahevans045@gmail.com>
pull/17/head
Sarah 4 years ago
parent
commit
36d03df61a
  1. 2
      src/Plugins/RenX/CMakeLists.txt
  2. 3
      src/Plugins/RenX/RenX.ChatLogging/CMakeLists.txt
  3. 105
      src/Plugins/RenX/RenX.ChatLogging/RenX_ChatLogging.cpp
  4. 33
      src/Plugins/RenX/RenX.ChatLogging/RenX_ChatLogging.h
  5. 3
      src/Plugins/RenX/RenX.CommandLogging/CMakeLists.txt
  6. 112
      src/Plugins/RenX/RenX.CommandLogging/RenX_CommandLogging.cpp
  7. 34
      src/Plugins/RenX/RenX.CommandLogging/RenX_CommandLogging.h
  8. 5
      src/Plugins/RenX/RenX.Core/RenX_Plugin.cpp
  9. 1
      src/Plugins/RenX/RenX.Core/RenX_Plugin.h
  10. 4
      src/Plugins/RenX/RenX.Core/RenX_Server.cpp

2
src/Plugins/RenX/CMakeLists.txt

@ -14,6 +14,8 @@ endmacro(add_renx_plugin)
add_subdirectory(RenX.AlwaysRecord) add_subdirectory(RenX.AlwaysRecord)
add_subdirectory(RenX.Announcements) add_subdirectory(RenX.Announcements)
add_subdirectory(RenX.Commands) add_subdirectory(RenX.Commands)
add_subdirectory(RenX.ChatLogging)
add_subdirectory(RenX.CommandLogging)
add_subdirectory(RenX.ExcessiveHeadshots) add_subdirectory(RenX.ExcessiveHeadshots)
add_subdirectory(RenX.ExtraLogging) add_subdirectory(RenX.ExtraLogging)
add_subdirectory(RenX.Greetings) add_subdirectory(RenX.Greetings)

3
src/Plugins/RenX/RenX.ChatLogging/CMakeLists.txt

@ -0,0 +1,3 @@
add_renx_plugin(RenX.ChatLogging
RenX_ChatLogging.cpp
RenX_ChatLogging.h)

105
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
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
src/Plugins/RenX/RenX.CommandLogging/CMakeLists.txt

@ -0,0 +1,3 @@
add_renx_plugin(RenX.CommandLogging
RenX_CommandLogging.cpp
RenX_CommandLogging.h)

112
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
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
src/Plugins/RenX/RenX.Core/RenX_Plugin.cpp

@ -91,6 +91,11 @@ bool RenX::Plugin::RenX_OnBan(Server &, const PlayerInfo &, Jupiter::StringType
return false; 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 &) void RenX::Plugin::RenX_OnJoin(Server &, const PlayerInfo &)
{ {
return; return;

1
src/Plugins/RenX/RenX.Core/RenX_Plugin.h

@ -55,6 +55,7 @@ namespace RenX
virtual void RenX_OnServerFullyConnected(Server &server); virtual void RenX_OnServerFullyConnected(Server &server);
virtual void RenX_OnServerDisconnect(Server &server, RenX::DisconnectReason reason); virtual void RenX_OnServerDisconnect(Server &server, RenX::DisconnectReason reason);
virtual bool RenX_OnBan(Server &server, const PlayerInfo &player, Jupiter::StringType &data); 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 */ /** Player type logs */
virtual void RenX_OnJoin(Server &server, const PlayerInfo &player); virtual void RenX_OnJoin(Server &server, const PlayerInfo &player);

4
src/Plugins/RenX/RenX.Core/RenX_Server.cpp

@ -1158,6 +1158,10 @@ RenX::GameCommand *RenX::Server::triggerCommand(const Jupiter::ReadableString &t
else else
RenX::Server::sendMessage(player, "Access Denied."_jrs); 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; return cmd;
} }
} }

Loading…
Cancel
Save