Skip to content

Commit

Permalink
add logging feature for commands of each user #47
Browse files Browse the repository at this point in the history
  • Loading branch information
HarpyWar committed Aug 9, 2014
1 parent 3613ad9 commit 3f2d207
Show file tree
Hide file tree
Showing 16 changed files with 580 additions and 6 deletions.
18 changes: 18 additions & 0 deletions conf/bnetd.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ filedir = "${LOCALSTATEDIR}/files"
scriptdir = "${LOCALSTATEDIR}/lua"
reportdir = "${LOCALSTATEDIR}/reports"
chanlogdir = "${LOCALSTATEDIR}/chanlogs"
userlogdir = "${LOCALSTATEDIR}/userlogs"
i18ndir = "${SYSCONFDIR}/i18n"
issuefile = "${SYSCONFDIR}/bnissue.txt"
channelfile = "${SYSCONFDIR}/channel.conf"
Expand Down Expand Up @@ -659,3 +660,20 @@ clan_channel_default_private = 0
# without accepted invitations need. This does not affect WAR3/W3XP ingame
# clan management.
clan_min_invites = 2

###############################################################################
# user commands logging #
#-----------------------------------------------------------------------------#

# Should commands from users be logged to files in the userlogdir?
log_commands = true

# Commands will be logged for users with these command groups
# (global operators and admins are included)
log_command_groups = 2345678

# List of commands that will be logged
# can be defined by connecting them with a comma (,)
# set empty to log all commands
log_command_list = ""

18 changes: 18 additions & 0 deletions conf/bnetd.conf.win32
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ filedir = files
scriptdir = lua
reportdir = var\reports
chanlogdir = var\chanlogs
userlogdir = var\userlogs
i18ndir = conf\i18n
issuefile = conf\bnissue.txt
channelfile = conf\channel.conf
Expand Down Expand Up @@ -640,3 +641,20 @@ clan_channel_default_private = 0
# without accepted invitations need. This does not affect WAR3/W3XP ingame
# clan management.
clan_min_invites = 2

###############################################################################
# user commands logging #
#-----------------------------------------------------------------------------#

# Should commands from users be logged to files in the userlogdir?
log_commands = true

# Commands will be logged for users with these command groups
# (global operators and admins are included)
log_command_groups = 2345678

# List of commands that will be logged
# can be defined by connecting them with a comma (,)
# set empty to log all commands
log_command_list = ""

1 change: 1 addition & 0 deletions conf/command_groups.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
# but will allow them to make themselves Server Admin & Server Operator.

6 /operator /admin /flag /tag
6 /log

7 /set
7 /commandgroups /cg
Expand Down
13 changes: 13 additions & 0 deletions conf/i18n/bnhelp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,19 @@ Syntax for operator/admin:
/lang [code]
Set your language to get another translation:

%log
--------------------------------------------------------
/log <command> <username> [args]
Read <username> log with commands (from the end)
--------------------------------------------------------
/log r[ead] <username> [startline]
Show last lines in user log from [startline]
/log f[ind] <username> <substring> [startline]
Find <substring> in user log from [startline]

Example: /log read Joe
Example: /log find Joe shutdown

%quiz
--------------------------------------------------------
/quiz <command> [option]
Expand Down
1 change: 1 addition & 0 deletions files/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/var/clans")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/var/teams")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/var/reports")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/var/chanlogs")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/var/userlogs")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/var/charinfo")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/var/charsave")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/var/bak/charinfo")
Expand Down
3 changes: 3 additions & 0 deletions files/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ reports_DATA =
chanlogsdir = $(localstatedir)/chanlogs
chanlogs_DATA =

userlogsdir = $(localstatedir)/userlogs
chanlogs_DATA =

charinfodir = $(localstatedir)/charinfo
charinfo_DATA =

Expand Down
2 changes: 1 addition & 1 deletion src/bnetd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ set(BNETD_SOURCES
anongame_wol.cpp anongame_wol.h handle_wserv.cpp handle_wserv.h
luafunctions.cpp luafunctions.h luainterface.cpp luainterface.h
luaobjects.cpp luaobjects.h luawrapper.cpp luawrapper.h
i18n.cpp i18n.h
i18n.cpp i18n.h cmdlog.cpp cmdlog.h
../win32/winmain.cpp ../win32/winmain.h
)

Expand Down
4 changes: 2 additions & 2 deletions src/bnetd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bnetd_SOURCES = account.cpp account_wrap.cpp adbanner.cpp alias_command.cpp anon
tournament.cpp tracker.cpp udptest_send.cpp versioncheck.cpp watch.cpp \
storage_sql2.cpp sql_common.cpp handle_wol.cpp handle_irc_common.cpp handle_apireg.cpp \
handle_wserv.cpp luafunctions.cpp luainterface.cpp luaobjects.cpp luawrapper.cpp \
i18n.cpp icons.cpp
i18n.cpp icons.cpp cmdlog.cpp

bnetd_LDADD = $(top_builddir)/src/common/libcommon.a \
$(top_builddir)/src/compat/libcompat.a \
Expand All @@ -37,4 +37,4 @@ noinst_HEADERS = account.h account_wrap.h adbanner.h alias_command.h \
timer.h topic.h tournament.h udptest_send.h versioncheck.h watch.h \
tracker.h storage_sql2.h sql_common.h handle_wol.h handle_irc_common.h handle_apireg.h \
handle_wserv.h luafunctions.h luainterface.h luaobjects.h luawrapper.h \
i18n.h icons.h
i18n.h icons.h cmdlog.h
11 changes: 9 additions & 2 deletions src/bnetd/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
#include "clan.h"
#include "common/flags.h"
#include "icons.h"
#include "userlog.h"
#include "i18n.h"

#include "attrlayer.h"
Expand Down Expand Up @@ -543,6 +544,7 @@ namespace pvpgn
{ "/alert", _handle_alert_command },
{ "/language", handle_language_command },
{ "/lang", handle_language_command },
{ "/log", handle_log_command },

{ NULL, NULL }

Expand Down Expand Up @@ -574,7 +576,9 @@ namespace pvpgn
// -1 = unsuccess, 0 = success, 1 = execute next c++ code
if (result == 0)
{
// TODO: log command
// log command
if (t_account * account = conn_get_account(c))
userlog_append(account, text);
}
if (result == 0 || result == -1)
return result;
Expand All @@ -600,7 +604,10 @@ namespace pvpgn
// -1 = unsuccess, 0 = success
if (result == 0)
{
// TODO: log command
// log command
if (t_account * account = conn_get_account(c))
userlog_append(account, text);

// TODO: modify all commands to return "0" only if success, and "-1" if not
}
return result;
Expand Down
5 changes: 5 additions & 0 deletions src/bnetd/luainterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ namespace pvpgn
config.update("scriptdir", prefs_get_scriptdir());
config.update("reportdir", prefs_get_reportdir());
config.update("chanlogdir", prefs_get_chanlogdir());
config.update("userlogdir", prefs_get_userlogdir());
config.update("localizefile", prefs_get_localizefile());
config.update("motdfile", prefs_get_motdfile());
config.update("motdw3file", prefs_get_motdw3file());
Expand Down Expand Up @@ -298,6 +299,10 @@ namespace pvpgn
config.update("clan_max_members", prefs_get_clan_max_members());
config.update("clan_channel_default_private", prefs_get_clan_channel_default_private());
config.update("clan_min_invites", prefs_get_clan_min_invites());
config.update("log_commands", prefs_get_log_commands());
config.update("log_command_groups", prefs_get_log_command_groups());
config.update("log_command_list", prefs_get_log_command_list());

}

}
Expand Down
2 changes: 2 additions & 0 deletions src/bnetd/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
#include "topic.h"
#include "handle_apireg.h"
#include "i18n.h"
#include "userlog.h"
#include "common/setup_after.h"

#ifdef WITH_LUA
Expand Down Expand Up @@ -384,6 +385,7 @@ int pre_server_startup(void)
if (realmlist_create(prefs_get_realmfile()) < 0)
eventlog(eventlog_level_error, __FUNCTION__, "could not load realm list");
topiclist_load(prefs_get_topicfile());
userlog_init();

#ifdef WITH_LUA
lua_load(prefs_get_scriptdir());
Expand Down
109 changes: 109 additions & 0 deletions src/bnetd/prefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ namespace pvpgn
char const * transfile;
unsigned int chanlog;
char const * chanlogdir;
char const * userlogdir;
unsigned int quota;
unsigned int quota_lines;
unsigned int quota_time;
Expand Down Expand Up @@ -164,6 +165,9 @@ namespace pvpgn
unsigned int sync_on_logoff;
char const * irc_network_name;
unsigned int localize_by_country;
unsigned int log_commands;
char const * log_command_groups;
char const * log_command_list;

char const * apiregaddrs;
char const * wolv1addrs;
Expand Down Expand Up @@ -417,6 +421,10 @@ namespace pvpgn
static const char *conf_get_chanlogdir(void);
static int conf_setdef_chanlogdir(void);

static int conf_set_userlogdir(const char *valstr);
static const char *conf_get_userlogdir(void);
static int conf_setdef_userlogdir(void);

static int conf_set_quota(const char *valstr);
static const char *conf_get_quota(void);
static int conf_setdef_quota(void);
Expand Down Expand Up @@ -669,6 +677,18 @@ namespace pvpgn
static const char *conf_get_localize_by_country(void);
static int conf_setdef_localize_by_country(void);

static int conf_set_log_commands(const char *valstr);
static const char *conf_get_log_commands(void);
static int conf_setdef_log_commands(void);

static int conf_set_log_command_groups(const char *valstr);
static const char *conf_get_log_command_groups(void);
static int conf_setdef_log_command_groups(void);

static int conf_set_log_command_list(const char *valstr);
static const char *conf_get_log_command_list(void);
static int conf_setdef_log_command_list(void);


static int conf_setdef_apireg_addrs(void);
static int conf_set_apireg_addrs(const char *valstr);
Expand Down Expand Up @@ -773,6 +793,7 @@ namespace pvpgn
{ "transfile", conf_set_transfile, conf_get_transfile, conf_setdef_transfile },
{ "chanlog", conf_set_chanlog, conf_get_chanlog, conf_setdef_chanlog },
{ "chanlogdir", conf_set_chanlogdir, conf_get_chanlogdir, conf_setdef_chanlogdir },
{ "userlogdir", conf_set_userlogdir, conf_get_userlogdir, conf_setdef_userlogdir },
{ "quota", conf_set_quota, conf_get_quota, conf_setdef_quota },
{ "quota_lines", conf_set_quota_lines, conf_get_quota_lines, conf_setdef_quota_lines },
{ "quota_time", conf_set_quota_time, conf_get_quota_time, conf_setdef_quota_time },
Expand Down Expand Up @@ -836,6 +857,9 @@ namespace pvpgn
{ "ladder_prefix", conf_set_ladder_prefix, conf_get_ladder_prefix, conf_setdef_ladder_prefix },
{ "irc_network_name", conf_set_irc_network_name, conf_get_irc_network_name, conf_setdef_irc_network_name },
{ "localize_by_country", conf_set_localize_by_country, conf_get_localize_by_country, conf_setdef_localize_by_country },
{ "log_commands", conf_set_log_commands, conf_get_log_commands, conf_setdef_log_commands },
{ "log_command_groups", conf_set_log_command_groups, conf_get_log_command_groups, conf_setdef_log_command_groups },
{ "log_command_list", conf_set_log_command_list, conf_get_log_command_list, conf_setdef_log_command_list },

{ "apiregaddrs", conf_set_apireg_addrs, conf_get_apireg_addrs, conf_setdef_apireg_addrs },
{ "wgameresaddrs", conf_set_wgameres_addrs, conf_get_wgameres_addrs, conf_setdef_wgameres_addrs },
Expand Down Expand Up @@ -2126,6 +2150,27 @@ namespace pvpgn
}


extern char const * prefs_get_userlogdir(void)
{
return prefs_runtime_config.userlogdir;
}

static int conf_set_userlogdir(const char *valstr)
{
return conf_set_str(&prefs_runtime_config.userlogdir, valstr, NULL);
}

static int conf_setdef_userlogdir(void)
{
return conf_set_str(&prefs_runtime_config.userlogdir, NULL, BNETD_USERLOG_DIR);
}

static const char* conf_get_userlogdir(void)
{
return prefs_runtime_config.userlogdir;
}


extern unsigned int prefs_get_quota(void)
{
return prefs_runtime_config.quota;
Expand Down Expand Up @@ -3507,6 +3552,70 @@ namespace pvpgn
}


extern unsigned int prefs_get_log_commands(void)
{
return prefs_runtime_config.log_commands;
}

static int conf_set_log_commands(const char *valstr)
{
return conf_set_bool(&prefs_runtime_config.log_commands, valstr, 0);
}

static int conf_setdef_log_commands(void)
{
return conf_set_bool(&prefs_runtime_config.log_commands, NULL, 1);
}

static const char* conf_get_log_commands(void)
{
return conf_get_bool(prefs_runtime_config.log_commands);
}


extern char const * prefs_get_log_command_groups(void)
{
return prefs_runtime_config.log_command_groups;
}

static int conf_set_log_command_groups(const char *valstr)
{
return conf_set_str(&prefs_runtime_config.log_command_groups, valstr, NULL);
}

static int conf_setdef_log_command_groups(void)
{
return conf_set_str(&prefs_runtime_config.log_command_groups, NULL, BNETD_LOG_COMMAND_GROUPS);
}

static const char* conf_get_log_command_groups(void)
{
return prefs_runtime_config.log_command_groups;
}


extern char const * prefs_get_log_command_list(void)
{
return prefs_runtime_config.log_command_list;
}

static int conf_set_log_command_list(const char *valstr)
{
return conf_set_str(&prefs_runtime_config.log_command_list, valstr, NULL);
}

static int conf_setdef_log_command_list(void)
{
return conf_set_str(&prefs_runtime_config.log_command_list, NULL, BNETD_LOG_COMMAND_LIST);
}

static const char* conf_get_log_command_list(void)
{
return prefs_runtime_config.log_command_list;
}



/**
* Westwood Online Extensions
*/
Expand Down
4 changes: 4 additions & 0 deletions src/bnetd/prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ namespace pvpgn
extern char const * prefs_get_transfile(void);
extern unsigned int prefs_get_chanlog(void);
extern char const * prefs_get_chanlogdir(void);
extern char const * prefs_get_userlogdir(void);
extern unsigned int prefs_get_quota(void);
extern unsigned int prefs_get_quota_lines(void);
extern unsigned int prefs_get_quota_time(void);
Expand Down Expand Up @@ -180,6 +181,9 @@ namespace pvpgn
extern unsigned int prefs_get_sync_on_logoff(void);
extern char const * prefs_get_irc_network_name(void);
extern unsigned int prefs_get_localize_by_country(void);
extern unsigned int prefs_get_log_commands(void);
extern char const * prefs_get_log_command_groups(void);
extern char const * prefs_get_log_command_list(void);

/**
* Westwood Online Extensions
Expand Down
Loading

0 comments on commit 3f2d207

Please sign in to comment.