Quellcode durchsuchen

Support responding to encrypted channel messages

Bryan Drewery vor 14 Jahren
Ursprung
Commit
c95638e005
1 geänderte Dateien mit 16 neuen und 5 gelöschten Zeilen
  1. 16 5
      src/mod/server.mod/servmsg.c

+ 16 - 5
src/mod/server.mod/servmsg.c

@@ -158,16 +158,27 @@ static int check_bind_raw(char *from, char *code, char *msg)
 
   // Decrypt FiSH before processing
   if (!strcmp(code, "PRIVMSG") || !strcmp(code, "NOTICE")) {
-    char* colon = strchr(msg, ':');
+    putlog(LOG_MISC, "*", "code: %s", code);
+    char* colon = strchr(msg, ':'), *first_word = strchr(msg, ' ');
+    bd::String target(msg, first_word - msg);
+
     ++colon;
     if (colon) {
       if (!strncmp(colon, "+OK ", 4)) {
         char *p = strchr(from, '!');
-        bd::String ciphertext(colon), sharedKey, target(from, p - from);
+        bd::String ciphertext(colon), sharedKey, nick(from, p - from), key_target;
+
+        // If this is a channel msg, decrypt with the channel key
+        if (strchr(CHANMETA, target[0])) {
+          key_target = target;
+        } else {
+          // Otherwise decrypt with the nick's key
+          key_target = nick;
+        }
 
-        if (FishKeys.contains(target)) {
-          sharedKey = FishKeys[target]->sharedKey;
-          FishKeys[target]->timestamp = now;
+        if (FishKeys.contains(key_target)) {
+          sharedKey = FishKeys[key_target]->sharedKey;
+          FishKeys[key_target]->timestamp = now;
         } else {
           struct userrec *u = get_user_by_host(from);
           if (u) {