]> jfr.im git - irc/quakenet/newserv.git/blobdiff - chanserv/chancmds/addchan.c
CHANSERV: alter default modes for relay addchan.
[irc/quakenet/newserv.git] / chanserv / chancmds / addchan.c
index cdd04b7dddd9a114fcbb1e505b714923a5201c20..7c9c1e1fa04d34f0a4ea63604894c03400fd6690 100644 (file)
@@ -3,10 +3,18 @@
  *
  * CMDNAME: addchan
  * CMDLEVEL: QCMD_OPER
- * CMDARGS: 4
+ * CMDARGS: 5
  * CMDDESC: Adds a new channel to the bot.
  * CMDFUNC: csc_doaddchan
  * CMDPROTO: int csc_doaddchan(void *source, int cargc, char **cargv);
+ * CMDHELP: Usage: addchan <channel> [<owner> [<flags> [<type> [<msguser>]]]]
+ * CMDHELP: Adds the given channel to the bot, where:
+ * CMDHELP: owner   - can be either nickname on the network or #authname.  If not supplied,
+ * CMDHELP:           the channel will belong to the user issuing the ADDCHAN command.
+ * CMDHELP: flags   - can be any valid chanflags (see CHANFLAGS).  If not specified this 
+ * CMDHELP:           defaults to +j.
+ * CMDHELP: type    - is a channel type as per old Q and is now obsolete.
+ * CMDHELP: msguser - send a notification to this user (for service use)
  */
 
 #include "../chanserv.h"
@@ -21,7 +29,7 @@
 #include <stdio.h>
 
 int csc_doaddchan(void *source, int cargc, char **cargv) {
-  nick *sender=source;
+  nick *sender=source, *notify=NULL;
   reguser *rup=getreguserfromnick(sender);
   chanindex *cip;
   regchan *rcp;
@@ -29,6 +37,7 @@ int csc_doaddchan(void *source, int cargc, char **cargv) {
   reguser *founder;
   flag_t flags;
   short type=0;
+  unsigned int count;
   
   if (!rup)
     return CMD_ERROR;
@@ -38,11 +47,16 @@ int csc_doaddchan(void *source, int cargc, char **cargv) {
     return CMD_ERROR;
   }
   
-  if (*cargv[0] != '#') {
+  if (*cargv[0] != '#' || strlen(cargv[0]) > CHANNELLEN) {
     chanservstdmessage(sender, QM_INVALIDCHANNAME, cargv[0]);
     return CMD_ERROR;
   } 
   
+  /* If a 5th argument is supplied, it's a nick to send the reply messages to. */
+  if (cargc>4) {
+    notify=getnickbynick(cargv[4]);
+  }
+  
   if (cargc>1) {
     if (!(founder=findreguser(sender, cargv[1])))
       return CMD_ERROR;
@@ -52,9 +66,14 @@ int csc_doaddchan(void *source, int cargc, char **cargv) {
   
   if (cargc>2) {
     flags=0;
-    setflags(&flags, QCFLAG_ALL, cargv[2], rcflags, REJECT_NONE);    
+    setflags(&flags, QCFLAG_ALL, cargv[2], rcflags, REJECT_NONE);
+    /* Apply relevant policy */
+    if (!UIsDev(rup)) {
+      flags &= QCFLAG_USERCONTROL;
+      flags |= QCFLAG_JOINED;
+    }
   } else {
-    flags = (QCFLAG_JOINED | QCFLAG_BITCH | QCFLAG_PROTECT | QCFLAG_ENFORCE);
+    flags = (QCFLAG_JOINED);
   }
   
   /* Pick up the chantype */
@@ -71,86 +90,34 @@ int csc_doaddchan(void *source, int cargc, char **cargv) {
   
   if (!(cip=findorcreatechanindex(cargv[0]))) {
     chanservstdmessage(sender, QM_INVALIDCHANNAME, cargv[0]);
+    if (notify)
+      chanservstdmessage(notify, QM_INVALIDCHANNAME, cargv[0]);
     return CMD_ERROR;
   }
   
-  if (cip->exts[chanservext]) {
-    chanservstdmessage(sender, QM_ALREADYREGISTERED, cip->name->content);
-    return CMD_ERROR;
-  }
-  
-  /* Initialise the channel */ 
-  rcp=getregchan();
-  
-  /* ID, index */
-  rcp->ID=++lastchannelID;
-  rcp->index=cip;
-  cip->exts[chanservext]=rcp;
-  
-  rcp->chantype=type;
-  rcp->flags=flags;
-  rcp->status=0;
-  rcp->bans=NULL;
-  rcp->lastcountersync=0;
-  
-  rcp->limit=0;
-  rcp->forcemodes=CHANMODE_NOEXTMSG | CHANMODE_TOPICLIMIT;
-  rcp->denymodes=0;
+  count = 0;
 
-  if (CIsAutoLimit(rcp)) {
-    rcp->forcemodes |= CHANMODE_LIMIT;
-  }
-  
-  rcp->autolimit=5;
-  rcp->banstyle=0;
-  
-  rcp->created=rcp->lastactive=rcp->statsreset=rcp->ostatsreset=time(NULL);
-  rcp->banduration=1800;
-  rcp->autoupdate=0;
-  rcp->lastbancheck=0;
-  
-  /* Added by */
-  rcp->addedby=rup->ID;
-  
-  /* Founder */
-  rcp->founder=founder->ID;
-  /* Suspend by */
-  rcp->suspendby=0;
-  
-  rcp->totaljoins=rcp->tripjoins=rcp->otripjoins=rcp->maxusers=rcp->tripusers=rcp->otripusers=0;
-  rcp->welcome=rcp->topic=rcp->key=rcp->suspendreason=rcp->comment=NULL;
-  
-  /* Users */
-  memset(rcp->regusers,0,REGCHANUSERHASHSIZE*sizeof(reguser *));   
-  
-  rcp->checksched=NULL;
-  rcp->ltimestamp=0;
+  for (rcup=founder->knownon;rcup;rcup=rcup->nextbyuser)
+    count++; 
 
-  /* Add new channel to db.. */  
-  csdb_createchannel(rcp);
-  
-  /* Add the founder as +ano */
-  rcup=getregchanuser();
-  rcup->chan=rcp;
-  rcup->user=founder;
-  rcup->flags=(QCUFLAG_OWNER | QCUFLAG_OP | QCUFLAG_AUTOOP);
-  rcup->usetime=0;
-  rcup->info=NULL;
-  rcup->changetime=time(NULL);
-  
-  addregusertochannel(rcup);
-  csdb_createchanuser(rcup);
-  csdb_chanlevhistory_insert(rcp, sender, rcup->user, 0, rcup->flags);
+  if (count > MAXCHANNELS) {
+    chanservstdmessage(sender, QM_TOOMANYCHANNELS, cip->name->content);
+    if (notify)
+      chanservstdmessage(sender, QM_TOOMANYCHANNELS, cip->name->content);
+    return CMD_ERROR;
+  }
 
-  /* If the channel exists, get the ball rolling */
-  if (cip->channel) {
-    chanservjoinchan(cip->channel);
-    rcp->status |= QCSTAT_MODECHECK | QCSTAT_OPCHECK | QCSTAT_BANCHECK;
-    cs_timerfunc(cip);
+  rcp=cs_addchan(cip, sender, rup, founder, flags, CHANMODE_DEFAULT, 0, type);
+  if(rcp == NULL) {
+    chanservstdmessage(sender, QM_ALREADYREGISTERED, cip->name->content);
+    if (notify)
+      chanservstdmessage(notify, QM_ALREADYREGISTERED, cip->name->content);
+    return CMD_ERROR;
   }
 
   cs_log(sender, "ADDCHAN %s #%s %s %s",cip->name->content,founder->username,printflags(rcp->flags,rcflags), chantypes[type]->content);
   chanservstdmessage(sender, QM_DONE);
+  if (notify)
+    chanservstdmessage(notify, QM_DONE);
   return CMD_OK;
 }