소스 검색

* Add cmd_setkey for setting/clearing FiSH keys

Bryan Drewery 15 년 전
부모
커밋
66bc40241a
2개의 변경된 파일43개의 추가작업 그리고 0개의 파일을 삭제
  1. 9 0
      doc/help.txt
  2. 34 0
      src/mod/server.mod/cmdsserv.c

+ 9 - 0
doc/help.txt

@@ -1194,6 +1194,8 @@ See also: botjump, servers, botserver
 :leaf:keyx
 ### $bkeyx$b <nick>
     Initiaite DH1080 key-exchange with nick for FiSH protocol.
+ 
+%{+m}See also: setkey%{-}
 :leaf:kick
 ###  $bkick$b [channel|*] <nickname> [reason]
    Will kick a user off your current console channel (or specified
@@ -1726,6 +1728,13 @@ See also: reload, backup
     '%dbotset wraith nick -'
  
 See also: botset
+:leaf:setkey
+### $bsetkey$b <nick|channel> [key]
+ 
+    Sets the FiSH key for the given target.
+    Use no key to clear the currently set key.
+ 
+See also: keyx
 ::sha1
 ###  $bsha1$b <string>
    Returns the SHA1 hash of the specified string.

+ 34 - 0
src/mod/server.mod/cmdsserv.c

@@ -138,6 +138,39 @@ static void cmd_keyx(int idx, char *par) {
   return;
 }
 
+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");
+    return;
+  }
+
+  char *target = newsplit(&par);
+  char *key = newsplit(&par);
+  bool have_key = FishKeys.contains(target);
+  fish_data_t* fishData = NULL;
+
+  if (!key[0]) {
+    // Clear the key
+    if (have_key) {
+      fishData = FishKeys[target];
+      FishKeys.remove(target);
+      delete fishData;
+      dprintf(idx, "Key cleared for '%s'\n", target);
+    } else {
+      dprintf(idx, "No key found for '%s'\n", target);
+    }
+  } else {
+    // Set the key
+    fishData = new fish_data_t;
+    fishData->sharedKey = key;
+    fishData->timestamp = now;
+    dprintf(idx, "Set key for '%s' to: %s", target, key);
+  }
+  return;
+}
+
 static void cmd_clearqueue(int idx, char *par)
 {
   int msgs;
@@ -202,6 +235,7 @@ static cmd_t C_dcc_serv[] =
   {"jump",		"m",	(Function) cmd_jump,		NULL, LEAF},
   {"keyx",		"o",	(Function) cmd_keyx,		NULL, LEAF},
   {"servers",		"m",	(Function) cmd_servers,		NULL, LEAF},
+  {"setkey",		"m",	(Function) cmd_setkey,		NULL, LEAF},
   {"umode",		"m",	(Function) cmd_umode,		NULL, LEAF},
   {NULL,		NULL,	NULL,				NULL, 0}
 };