From: Michael Poole Date: Tue, 11 May 2004 02:51:09 +0000 (+0000) Subject: Implement a per-connection-class default usermode option. X-Git-Url: http://git.pk910.de/?a=commitdiff_plain;h=8487bf2d00ca961236b8c82db68ebea952b40062;hp=f53298a90117f227596a913b4b5a2abf439fc252;p=ircu2.10.12-pk.git Implement a per-connection-class default usermode option. git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@1042 c9e4aea6-c8fd-4c43-8297-357d70d61c8c --- diff --git a/ChangeLog b/ChangeLog index bf3da83..44c72a6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2004-05-10 Michael Poole + + 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 Forward port of asuka-topicburst.patch from Quakenet's "Asuka" diff --git a/doc/example.conf b/doc/example.conf index 904fd0e..38f9c2c 100644 --- a/doc/example.conf +++ b/doc/example.conf @@ -98,6 +98,7 @@ Admin { # connectfreq = time; # maxlinks = number; # sendq = size; +# usermode = "+i"; # }; # # 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 { diff --git a/include/class.h b/include/class.h index 27211c9..374c21b 100644 --- a/include/class.h +++ b/include/class.h @@ -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 diff --git a/include/client.h b/include/client.h index 18e03a2..f6500bc 100644 --- a/include/client.h +++ b/include/client.h @@ -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, diff --git a/ircd/client.c b/ircd/client.c index e125466..0b4e4f9 100644 --- a/ircd/client.c +++ b/ircd/client.c @@ -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 diff --git a/ircd/ircd_lexer.l b/ircd/ircd_lexer.l index 774ed3d..71569a2 100644 --- a/ircd/ircd_lexer.l +++ b/ircd/ircd_lexer.l @@ -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]; diff --git a/ircd/ircd_parser.y b/ircd/ircd_parser.y index c79272f..4aa3488 100644 --- a/ircd/ircd_parser.y +++ b/ircd/ircd_parser.y @@ -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 { diff --git a/ircd/s_user.c b/ircd/s_user.c index 8986e10..7134b25 100644 --- a/ircd/s_user.c +++ b/ircd/s_user.c @@ -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; }