X-Git-Url: https://jfr.im/git/solanum.git/blobdiff_plain/cbeab4bc340b7b3f4fbf424ff327758defb9598a..b5bf3505123e6667643af92563f2d14d6ab3b7c1:/modules/m_names.c diff --git a/modules/m_names.c b/modules/m_names.c index 1b31d9b8..a5e1e920 100644 --- a/modules/m_names.c +++ b/modules/m_names.c @@ -25,7 +25,6 @@ #include "stdinc.h" #include "channel.h" #include "client.h" -#include "common.h" #include "hash.h" #include "match.h" #include "ircd.h" @@ -36,8 +35,11 @@ #include "msg.h" #include "parse.h" #include "modules.h" +#include "s_newconf.h" -static int m_names(struct MsgBuf *, struct Client *, struct Client *, int, const char **); +static const char names_desc[] = "Provides the NAMES command to view users on a channel"; + +static void m_names(struct MsgBuf *, struct Client *, struct Client *, int, const char **); struct Message names_msgtab = { "NAMES", 0, 0, 0, 0, @@ -45,7 +47,8 @@ struct Message names_msgtab = { }; mapi_clist_av1 names_clist[] = { &names_msgtab, NULL }; -DECLARE_MODULE_AV1(names, NULL, NULL, names_clist, NULL, NULL, "$Revision: 254 $"); + +DECLARE_MODULE_AV2(names, NULL, NULL, names_clist, NULL, NULL, NULL, NULL, names_desc); static void names_global(struct Client *source_p); @@ -57,7 +60,7 @@ static void names_global(struct Client *source_p); * m_names * parv[1] = channel */ -static int +static void m_names(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { static time_t last_used = 0; @@ -75,7 +78,7 @@ m_names(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_ sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), (unsigned char *) p); - return 0; + return; } if((chptr = find_channel(p)) != NULL) @@ -86,7 +89,7 @@ m_names(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_ } else { - if(!IsOper(source_p)) + if(!IsOperGeneral(source_p)) { if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) { @@ -94,7 +97,7 @@ m_names(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_ me.name, source_p->name, "NAMES"); sendto_one(source_p, form_str(RPL_ENDOFNAMES), me.name, source_p->name, "*"); - return 0; + return; } else last_used = rb_current_time(); @@ -104,8 +107,6 @@ m_names(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_ sendto_one(source_p, form_str(RPL_ENDOFNAMES), me.name, source_p->name, "*"); } - - return 0; } /* @@ -118,16 +119,10 @@ m_names(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_ static void names_global(struct Client *source_p) { - int mlen; - int tlen; - int cur_len; - int dont_show = NO; - rb_dlink_node *lp, *ptr; + bool dont_show = false; + rb_dlink_node *ptr; struct Client *target_p; struct Channel *chptr = NULL; - struct membership *msptr; - char buf[BUFSIZE]; - char *t; /* first do all visible channels */ RB_DLINK_FOREACH(ptr, global_channel_list.head) @@ -135,15 +130,21 @@ names_global(struct Client *source_p) chptr = ptr->data; channel_member_names(chptr, source_p, 0); } - cur_len = mlen = sprintf(buf, form_str(RPL_NAMREPLY), - me.name, source_p->name, "*", "*"); - t = buf + mlen; + + send_multiline_init(source_p, " ", form_str(RPL_NAMREPLY), + me.name, + source_p->name, + "*", + "*"); /* Second, do all clients in one big sweep */ RB_DLINK_FOREACH(ptr, global_client_list.head) { + rb_dlink_node *ps, *pt; + struct membership *ms, *mt; + target_p = ptr->data; - dont_show = NO; + dont_show = false; if(!IsPerson(target_p) || IsInvisible(target_p)) continue; @@ -155,15 +156,13 @@ names_global(struct Client *source_p) * both were missed out above. if the target is on a * common channel with source, its already been shown. */ - RB_DLINK_FOREACH(lp, target_p->user->channel.head) + ITER_COMM_CHANNELS(ps, pt, source_p->user->channel.head, target_p->user->channel.head, ms, mt, chptr) { - msptr = lp->data; - chptr = msptr->chptr; + if (!mt) continue; - if(PubChannel(chptr) || IsMember(source_p, chptr) || - SecretChannel(chptr)) + if (PubChannel(chptr) || SecretChannel(chptr) || ms) { - dont_show = YES; + dont_show = true; break; } } @@ -171,18 +170,18 @@ names_global(struct Client *source_p) if(dont_show) continue; - if((cur_len + NICKLEN + 2) > (BUFSIZE - 3)) + if (IsCapable(source_p, CLICAP_USERHOST_IN_NAMES)) { - sendto_one(source_p, "%s", buf); - cur_len = mlen; - t = buf + mlen; + send_multiline_item(source_p, "%s!%s@%s", + target_p->name, + target_p->username, + target_p->host); + } + else + { + send_multiline_item(source_p, "%s", target_p->name); } - - tlen = sprintf(t, "%s ", target_p->name); - cur_len += tlen; - t += tlen; } - if(cur_len > mlen) - sendto_one(source_p, "%s", buf); + send_multiline_fini(source_p, NULL); }