Implement a per-connection-class default usermode option.
authorMichael Poole <mdpoole@troilus.org>
Tue, 11 May 2004 02:51:09 +0000 (02:51 +0000)
committerMichael Poole <mdpoole@troilus.org>
Tue, 11 May 2004 02:51:09 +0000 (02:51 +0000)
git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@1042 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

ChangeLog
doc/example.conf
include/class.h
include/client.h
ircd/client.c
ircd/ircd_lexer.l
ircd/ircd_parser.y
ircd/s_user.c

index bf3da83f9b6c6bd0b3881d0e49d41e3c6e41b24e..44c72a6ae6d66053be0f81b433f3ab5193961c1c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2004-05-10  Michael Poole <mdpoole@troilus.org>
+
+       Implement a per-connection-class default usermode option.
+
+       * doc/example.conf: Illustrate how to use the option.
+
+       * include/class.h (struct ConnectionClass): New "default_umode"
+       field.
+       (ConfUmode): New macro.
+
+       * include/client.h (client_get_default_umode): New function.
+
+       * ircd/client.c (client_get_default_umode): Implement it.
+
+       * ircd/ircd_lexer.l (usermode): New token.
+
+       * ircd/ircd_parser.y (classblock, etc): New syntax.
+
+       * ircd/s_user.c (register_user): Set default user modes for user.
+       This sends the new mode to the user, so the explicit send later
+       is no longer necessary.
+
 2004-05-10  Michael Poole <mdpoole@troilus.org>
 
        Forward port of asuka-topicburst.patch from Quakenet's "Asuka"
index 904fd0e23fa9f282bf10dabc93a0b672eaa00bd4..38f9c2cccb2b2ad41f9848c0eb3f861d43977ccb 100644 (file)
@@ -98,6 +98,7 @@ Admin {
 #  connectfreq = time;
 #  maxlinks = number;
 #  sendq = size;
+#  usermode = "+i";
 # };
 #
 # <connect freq> applies only to servers, and specifies the frequency 
@@ -141,6 +142,7 @@ Class {
  pingfreq = 1 minutes 30 seconds;
  sendq = 160000;
  maxlinks = 100;
+ usermode = "+iw";
 };
 Client
 {
index 27211c9e1cf0db7ba70afba5d721e574ccc58c27..374c21b5886431c781320b63c313b7b1af6add95 100644 (file)
@@ -36,6 +36,7 @@ struct StatDesc;
 struct ConnectionClass {
   struct ConnectionClass* next;
   char                    *cc_name;
+  char                    *default_umode;
   unsigned int            max_sendq;
   short                   ping_freq;
   short                   conn_freq;
@@ -61,6 +62,7 @@ struct ConnectionClass {
 #define ConfMaxLinks(x) ((x)->conn_class->max_links)
 #define ConfSendq(x)    ((x)->conn_class->max_sendq)
 #define ConfLinks(x)    ((x)->conn_class->ref_count)
+#define ConfUmode(x)    ((x)->conn_class->default_umode)
 
 /*
  * Proto types
index 18e03a2f8cedf5f6c4b33b1cfbc4c6d3e67a280a..f6500bc481b6f80619bb80fe9691224e23ffeb30 100644 (file)
@@ -532,6 +532,7 @@ typedef enum ShowIPType {
 } ShowIPType;
 
 extern const char* get_client_name(const struct Client* sptr, int showip);
+extern const char* client_get_default_umode(const struct Client* sptr);
 extern int client_get_ping(const struct Client* local_client);
 extern void client_drop_sendq(struct Connection* con);
 extern void client_add_sendq(struct Connection* con,
index e12546651a6caf0b185355bb27729456e9117906..0b4e4f93daed6282a1bc688e7e69a4e9116f728d 100644 (file)
@@ -67,6 +67,25 @@ int client_get_ping(const struct Client* acptr)
   return ping;
 }
 
+/*
+ * client_get_default_umode
+ * returns default usermode in attached client connection class
+ */
+const char* client_get_default_umode(const struct Client* sptr)
+{
+  struct ConfItem* aconf;
+  struct SLink* link;
+
+  assert(cli_verify(sptr));
+
+  for (link = cli_confs(sptr); link; link = link->next) {
+    aconf = link->value.aconf;
+    if ((aconf->status & CONF_CLIENT) && ConfUmode(aconf))
+      return ConfUmode(aconf);
+  }
+  return NULL;
+}
+
 /*
  * client_drop_sendq
  * removes the client's connection from the list of connections with
index 774ed3df3521c4107ba05c42a17d929e81b43bd1..71569a2ae6305f5723ed6b4c4c94250b3e84ba6a 100644 (file)
@@ -151,5 +151,6 @@ see_other_opers return TPRIV_SEE_OPERS;
 wide_glines return TPRIV_WIDE_GLINE;
 pseudo return PSEUDO;
 prepend return PREPEND;
+usermode return USERMODE;
 \n lineno++;
 . return yytext[0];
index c79272ff353605c77befbeb88403186548c24fc3..4aa34881009607999cce85f973ea2663bb0d31b2 100644 (file)
@@ -154,6 +154,7 @@ static void parse_error(char *pattern,...) {
 %token QUARANTINE
 %token PSEUDO
 %token PREPEND
+%token USERMODE
 /* and now a lot of priviledges... */
 %token TPRIV_CHAN_LIMIT TPRIV_MODE_LCHAN TPRIV_DEOP_LCHAN TPRIV_WALK_LCHAN
 %token TPRIV_KILL TPRIV_LOCAL_KILL TPRIV_REHASH TPRIV_RESTART TPRIV_DIE
@@ -328,19 +329,22 @@ classblock: CLASS {
   tconn = 0;
   maxlinks = 0;
   sendq = 0;
+  pass = NULL;
 } '{' classitems '}'
 {
   if (name != NULL)
   {
    add_class(name, tping, tconn, maxlinks, sendq);
+   find_class(name)->default_umode = pass;
   }
   else {
    parse_error("Missing name in class block");
   }
+  pass = NULL;
 } ';';
 classitems: classitem classitems | classitem;
 classitem: classname | classpingfreq | classconnfreq | classmaxlinks |
-           classsendq | error;
+           classsendq | classusermode | error;
 classname: NAME '=' QSTRING ';'
 {
   MyFree(name);
@@ -362,6 +366,12 @@ classsendq: SENDQ '=' sizespec ';'
 {
   sendq = yylval.num;
 };
+classusermode: USERMODE '=' QSTRING ';'
+{
+  if (pass)
+    MyFree(pass);
+  DupString(pass, yylval.text);
+};
 
 connectblock: CONNECT
 {
index 8986e108c640a23ccfd9a56827ee5dbcb22d0f70..7134b256d7155847309fbc098a852300020e62d7 100644 (file)
@@ -348,7 +348,7 @@ int register_user(struct Client *cptr, struct Client *sptr,
                   const char *nick, char *username)
 {
   struct ConfItem* aconf;
-  char*            parv[3];
+  char*            parv[4];
   char*            tmpstr;
   char*            tmpstr2;
   char             c = 0;    /* not alphanum */
@@ -362,7 +362,6 @@ int register_user(struct Client *cptr, struct Client *sptr,
   short            badid = 0;
   short            digitgroups = 0;
   struct User*     user = cli_user(sptr);
-  struct Flags flag;
   char             ip_base64[8];
 
   user->last = CurrentTime;
@@ -567,6 +566,15 @@ int register_user(struct Client *cptr, struct Client *sptr,
                            cli_sock_ip(sptr), get_client_class(sptr));
 
     IPcheck_connect_succeeded(sptr);
+    /*
+     * Set user's initial modes
+     */
+    parv[0] = (char*)nick;
+    parv[1] = (char*)nick;
+    parv[2] = (char*)client_get_default_umode(sptr);
+    parv[3] = NULL; /* needed in case of +s */
+    set_user_mode(sptr, sptr, 3, parv);
+    ClearHiddenHost(sptr); /* just in case somebody stuck +x in there */
   }
   else
     /* if (IsServer(cptr)) */
@@ -615,14 +623,9 @@ int register_user(struct Client *cptr, struct Client *sptr,
                        inttobase64(ip_base64, ntohl(cli_ip(sptr).s_addr), 6),
                        NumNick(sptr), cli_info(sptr));
   
-  /* Send umode to client */
-  if (MyUser(sptr))
-  {
-    memset(&flag, 0, sizeof(flag));
-    send_umode(cptr, sptr, &flag, ALL_UMODES);
-    if (cli_snomask(sptr) != SNO_DEFAULT && HasFlag(sptr, FLAG_SERVNOTICE))
-      send_reply(sptr, RPL_SNOMASK, cli_snomask(sptr), cli_snomask(sptr));
-  }
+  /* Send server notice mask to client */
+  if (MyUser(sptr) && (cli_snomask(sptr) != SNO_DEFAULT) && HasFlag(sptr, FLAG_SERVNOTICE))
+    send_reply(sptr, RPL_SNOMASK, cli_snomask(sptr), cli_snomask(sptr));
 
   return 0;
 }