summaryrefslogtreecommitdiff
path: root/logging.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-07-18 20:04:22 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-07-18 20:04:22 +0100
commit8f9a58e181d16cad2b86b8116bfe9470774bbdee (patch)
treec6defd0c68707ae51ff3d8affa19267ed853c440 /logging.c
parent40a9f76e2d4ddd972b2e9ea2594c7567718517f4 (diff)
Correctly log and replay "/me" PRIVMSGs.
Diffstat (limited to 'logging.c')
-rw-r--r--logging.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/logging.c b/logging.c
index c3271fe..e7a20ea 100644
--- a/logging.c
+++ b/logging.c
@@ -55,6 +55,9 @@ int logline(char *str, char *ournick, char *basedir, int type) {
char tokens[MAXTOKENS][MAXDATASIZE];
char *token;
+ // 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.
// If LOG_PRIVMSG:
// This gets us the prefix (containing the "from" nick), the PRIVMSG command (not needed),
@@ -114,6 +117,18 @@ int logline(char *str, char *ournick, char *basedir, int type) {
}
}
+ // If it was a "/me" line then strip the "\1ACTION " and the trailing "\1", plus set a flag for later
+ if (strstr(str, "\1ACTION ") == str) {
+ debugprint(DEBUG_FULL, "logline(): /me PRIVMSG detected, stripping ACTION things.\n");
+ // Skip over the first 8 characters (\1ACTION )
+ str += 8;
+ // And remove the trailing \1
+ if (str[strlen(str) - 1] == '\1') {
+ str[strlen(str) - 1] = '\0';
+ }
+ meprivmsg = 1;
+ }
+
debugprint(DEBUG_FULL, "logline(): Logging PRIVMSG from '%s' to '%s' message '%s' in filename '%s'.\n", tokens[0], tokens[2], str, filename);
break;
@@ -226,12 +241,22 @@ int logline(char *str, char *ournick, char *basedir, int type) {
timestr[strlen(timestr) - 1] = '\0';
if (type == LOG_PRIVMSG) {
- // Prepend the time string and "from" nick
- if (!snprintf(line, MAXCHAR, "%s <%s> %s", timestr, tokens[0], str)) {
- fprintf(stderr, "Error while preparing log string to write!\n");
- debugprint(DEBUG_CRIT, "Error while preparing log string to write!\n");
- fclose(fp);
- return 0;
+ // Prepend the time string and "from" nick, different formatting depending on
+ // whether or not it was a "/me" message
+ if (meprivmsg) {
+ if (!snprintf(line, MAXCHAR, "%s * %s %s", timestr, tokens[0], str)) {
+ fprintf(stderr, "Error while preparing /me log string to write!\n");
+ debugprint(DEBUG_CRIT, "Error while preparing /me log string to write!\n");
+ fclose(fp);
+ return 0;
+ }
+ } else {
+ if (!snprintf(line, MAXCHAR, "%s <%s> %s", timestr, tokens[0], str)) {
+ fprintf(stderr, "Error while preparing log string to write!\n");
+ debugprint(DEBUG_CRIT, "Error while preparing log string to write!\n");
+ fclose(fp);
+ return 0;
+ }
}
} else if (type == LOG_JOINPART || type == LOG_TOPIC) {
// Prepend the time string