summaryrefslogtreecommitdiff
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
parent40a9f76e2d4ddd972b2e9ea2594c7567718517f4 (diff)
Correctly log and replay "/me" PRIVMSGs.
-rw-r--r--TODO2
-rw-r--r--logging.c37
-rw-r--r--replay.c8
3 files changed, 39 insertions, 8 deletions
diff --git a/TODO b/TODO
index 966ba41..9f95a77 100644
--- a/TODO
+++ b/TODO
@@ -1,7 +1,5 @@
Fuzzing.
-"/me" PRIVMSGs are not logged or replayed correctly.
-
Fix warnings with different compilers (older gcc, clang).
Support multiple connect commands.
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
diff --git a/replay.c b/replay.c
index f4635c1..5e54f28 100644
--- a/replay.c
+++ b/replay.c
@@ -101,6 +101,7 @@ void formattime(char *str) {
int len = strlen(str);
// Find the start of the message if it's a PRIVMSG
+ // TODO - What if this string happens to appear in a non-PRIVMSG?
char *ret;
int pos1;
if ((ret = strstr(str, "PRIVMSG")) != NULL) {
@@ -111,6 +112,13 @@ void formattime(char *str) {
return;
}
+ // Make sure it's not a "/me" line
+ // TODO - What if this string happens to appear in a non-PRIVMSG?
+ if (strstr(str, " :\1ACTION ")) {
+ // If so, stop here
+ return;
+ }
+
char *ret2;
int pos2;
// Find the start of the actual message within the PRIVMSG