summaryrefslogtreecommitdiff
path: root/logging.c
diff options
context:
space:
mode:
Diffstat (limited to 'logging.c')
-rw-r--r--logging.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/logging.c b/logging.c
index d0ad1a5..7673fc2 100644
--- a/logging.c
+++ b/logging.c
@@ -55,6 +55,9 @@
// If LOG_MODE then it expects a string in the format:
// :nick!bar@baz MODE #channel foo bar [foo bar...]
//
+// If LOG_KICK then it expects a string in the format:
+// :kicker!bar@baz KICK #channel kickee :bla bla bla
+//
// With the ":foo!bar@baz "prefix being important for all
// types.
//
@@ -76,7 +79,8 @@ int logline(char *str, struct ircdstate *ircdstate, char *basedir, int type) {
// Whether or not this is a "/me" PRIVMSG so we can log it slightly differently later
int meprivmsg = 0;
- // Split out the first three space-separated parts of the string, leaving the rest.
+ // Split out the first three (except for LOG_KICK, see below) space-separated parts of the string,
+ // leaving the rest.
// If LOG_PRIVMSG:
// This gets us the prefix (containing the "from" nick), the PRIVMSG command (not needed),
// and the "to" nick or channel. Plus the rest of the string intact (which is the actual
@@ -89,8 +93,16 @@ int logline(char *str, struct ircdstate *ircdstate, char *basedir, int type) {
// the channel whose topic was set, and the rest of the string intact (which is the new topic).
// If LOG_NETWORK:
// Don't do this at all since we want to log the whole string.
+ // If LOG_KICK:
+ // Split out the first four space-separated parts of the string, leaving the rest.
+ // This gets us the prefix (containing the kicker nick), the KICK command (not needed),
+ // the channel name, the kickee, and the rest of the string intact (which is the kick message).
+ int splitnum = 3;
+ if (type == LOG_KICK) {
+ splitnum = 4;
+ }
if (type != LOG_NETWORK) {
- for (int i = 0; i < 3; i++) {
+ for (int i = 0; i < splitnum; i++) {
// Try to split
if ((token = strsep(&str, " ")) == NULL) {
debugprint(DEBUG_CRIT, "Error splitting string for logging, returning!\n");
@@ -313,6 +325,27 @@ int logline(char *str, struct ircdstate *ircdstate, char *basedir, int type) {
break;
+ case LOG_KICK:
+ // Extract the nick from the prefix
+ extractnickfromprefix(tokens[0], 1);
+
+ // Strip the prefix from the kick message
+ stripprefix(str, 1);
+
+ // Build a friendly message (e.g. "kicker has kicked kickee from #channel (kick message)")
+ if (!snprintf(line, MAXCHAR, "%s has kicked %s from %s (%s)", tokens[0], tokens[3], tokens[2], str)) {
+ debugprint(DEBUG_CRIT, "logline(): Error while preparing friendly message for kick log message, returning!\n");
+ return 0;
+ }
+
+ // Build the log filename
+ if (!snprintf(filename, MAXCHAR, "%s/logs/%s.log", basedir, to)) {
+ debugprint(DEBUG_CRIT, "logline(): Error while preparing log filename for kick, returning!\n");
+ return 0;
+ }
+
+ break;
+
default :
debugprint(DEBUG_CRIT, "logline(): Unknown log type '%d', returning 0.\n", type);
return 0;
@@ -373,7 +406,7 @@ int logline(char *str, struct ircdstate *ircdstate, char *basedir, int type) {
}
}
} else if (type == LOG_JOINPART || type == LOG_TOPIC || type == LOG_NETWORK ||
- type == LOG_QUIT || type == LOG_NICK || type == LOG_MODE) {
+ type == LOG_QUIT || type == LOG_NICK || type == LOG_MODE || type == LOG_KICK) {
// Prepend the time string
char line2[MAXCHAR];
if (!snprintf(line2, MAXCHAR, "%s %s", timestr, line)) {