Răsfoiți Sursa

* Random FiSH key support in .setkey

ducch 14 ani în urmă
părinte
comite
d9682e70b4
1 a modificat fișierele cu 17 adăugiri și 6 ștergeri
  1. 17 6
      src/mod/server.mod/cmdsserv.c

+ 17 - 6
src/mod/server.mod/cmdsserv.c

@@ -132,16 +132,16 @@ static void cmd_setkey(int idx, char *par) {
   putlog(LOG_CMDS, "*", "#%s# setkey %s", dcc[idx].nick, par);
 
   if (!par[0]) {
-    dprintf(idx, "Usage: setkey <nick|channel> [key]\n");
+    dprintf(idx, "Usage: setkey <nick|channel> [key|rand]\n");
     return;
   }
 
   char *target = newsplit(&par);
-  char *key = newsplit(&par);
+  char *newkey = newsplit(&par);
   bool have_key = FishKeys.contains(target);
   fish_data_t* fishData = NULL;
 
-  if (!key[0]) {
+  if (!newkey[0]) {
     // Clear the key
     if (have_key) {
       fishData = FishKeys[target];
@@ -152,12 +152,23 @@ static void cmd_setkey(int idx, char *par) {
       dprintf(idx, "No key found for '%s'\n", target);
     }
   } else {
-    // Set the key
+    // Set a new key
     fishData = new fish_data_t;
-    fishData->sharedKey = key;
+
+    if (!strcmp(newkey, "rand")) {
+      // Set a RANDOM key
+      rand_key = (char*)my_calloc(1, 32+1);
+      make_rand_str(rand_key, 32);
+      fishData->sharedKey = rand_key;
+      free(rand_key);
+    } else {
+      fishData->sharedKey = newkey;
+    }
+
+    // Set the key
     fishData->timestamp = now;
     FishKeys[target] = fishData;
-    dprintf(idx, "Set key for '%s' to: %s", target, key);
+    dprintf(idx, "Set key for '%s' to: %s", target, fishData->sharedKey);
   }
   return;
 }