]> jfr.im git - irc/quakenet/newserv.git/blobdiff - chanserv/chancmds/invite.c
LOCALUSER: Changed "localinvite" to take a chanindex * to identify the
[irc/quakenet/newserv.git] / chanserv / chancmds / invite.c
index 7eba00a379ff7fe33054c18a99cb2c51f0fdb6d5..69ee2eb0221e7066b27a31cf63e124733adf364e 100644 (file)
@@ -4,9 +4,15 @@
  * CMDNAME: invite
  * CMDLEVEL: QCMD_AUTHED
  * CMDARGS: 1
- * CMDDESC: Invites you to a channel.
+ * CMDDESC: Invites you to a channel or channels.
  * CMDFUNC: csc_doinvite
  * CMDPROTO: int csc_doinvite(void *source, int cargc, char **cargv);
+ * CMDHELP: Usage: INVITE [<channel>]
+ * CMDHELP: Invites you to one or more channels, where:
+ * CMDHELP: channel - channel to be invited to.  If no channel is specified,
+ * CMDHELP:           you will be invited to all channels where you have
+ * CMDHELP:           appropriate access and are not already joined.
+ * CMDHELP: INVITE requires you to be known (+k) on the named channel.
  */
 
 #include "../chanserv.h"
@@ -24,9 +30,36 @@ int csc_doinvite(void *source, int cargc, char **cargv) {
   nick *sender=source;
   chanindex *cip;
 
+  /* If no argument supplied, try and invite the user to every channel
+   * we can. */
   if (cargc<1) {
-    chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "invite");
-    return CMD_ERROR;
+    reguser *rup=getreguserfromnick(sender);
+    regchanuser *rcup;
+
+    if (!rup)
+      return CMD_ERROR;
+
+    for (rcup=rup->knownon;rcup;rcup=rcup->nextbyuser) {
+      /* skip empty or suspended channels */
+      if (!rcup->chan->index->channel || CIsSuspended(rcup->chan)) {
+        continue;
+      }
+      
+      /* skip channels the user is already on */
+      if (getnumerichandlefromchanhash(rcup->chan->index->channel->users, sender->numeric)) {
+        continue;
+      }
+
+      /* skip channels where the user can't do INVITE */
+      if (!CUKnown(rcup)) {
+        continue;
+      }
+      
+      localinvite(chanservnick, rcup->chan->index, sender);
+    }
+    
+    chanservstdmessage(sender, QM_DONE);
+    return CMD_OK;
   }
 
   if (!(cip=cs_checkaccess(sender, cargv[0], CA_KNOWN | CA_OFFCHAN, 
@@ -34,7 +67,7 @@ int csc_doinvite(void *source, int cargc, char **cargv) {
     return CMD_ERROR;
 
   if (cip->channel) {
-    localinvite(chanservnick, cip->channel, sender);
+    localinvite(chanservnick, cip, sender);
   }
   chanservstdmessage(sender, QM_DONE);