Reformat and simplify channel_stats() and make_channel()

This commit is contained in:
Kevin Easton
2019-08-26 00:59:23 +10:00
parent ddfbec0b4b
commit 960e2d8087

View File

@@ -482,48 +482,33 @@ int count = 0;
BUILT_IN_COMMAND(channel_stats) BUILT_IN_COMMAND(channel_stats)
{ {
ChannelList *new = NULL; ChannelList *new = NULL;
char *channel = NULL; char *channel = NULL;
WhowasChanList *new1 = NULL; int numircops = 0;
int numircops = 0; int usershere = 0;
int usershere = 0; int usersaway = 0;
int usersaway = 0; int chanops = 0;
int chanops = 0; int chanunop = 0;
int chanunop = 0; char *ircops = NULL;
char *ircops = NULL; int server = -1;
int server = -1; int max_hops = 0;
int max_hops = 0; NickList *l;
unsigned long nick_mem = 0;
NickList *l; unsigned long ban_mem = 0;
unsigned long nick_mem = 0, BanList *b;
ban_mem = 0;
BanList *b;
if (args && *args) if (args && *args)
{ {
channel = next_arg(args, &args); channel = next_arg(args, &args);
if (my_strnicmp(channel, "-ALL", strlen(channel)))
{
if (!(channel = make_channel(channel)))
return;
if (!(new = prepare_command(&server, channel, PC_SILENT)))
if ((channel && !(new1 = check_whowas_chan_buffer(channel, -1, 0))))
return;
}
else
{
if (!my_strnicmp(channel, "-ALL", strlen(channel)))
{
/* Accumulate stats from all joined channels on server */
int stats_ops= 0, stats_dops = 0, stats_bans = 0, stats_unbans = 0; int stats_ops= 0, stats_dops = 0, stats_bans = 0, stats_unbans = 0;
int stats_topics = 0, stats_kicks = 0, stats_pubs = 0, stats_parts = 0; int stats_topics = 0, stats_kicks = 0, stats_pubs = 0, stats_parts = 0;
int stats_signoffs = 0, stats_joins = 0; int stats_signoffs = 0, stats_joins = 0;
int total_nicks = 0, max_nicks = 0, total_bans = 0, max_bans = 0; int total_nicks = 0, max_nicks = 0, total_bans = 0, max_bans = 0;
int stats_sops = 0, stats_sdops = 0, stats_sbans = 0, stats_sunbans = 0; int stats_sops = 0, stats_sdops = 0, stats_sbans = 0, stats_sunbans = 0;
NickList *l;
BanList *b;
unsigned long chan_mem = 0; unsigned long chan_mem = 0;
channel = NULL; channel = NULL;
@@ -531,13 +516,8 @@ BanList *b;
{ {
for (new = get_server_channels(from_server); new; new = new->next) for (new = get_server_channels(from_server); new; new = new->next)
{ {
if (!channel) m_s3cat(&channel, ",", new->channel);
malloc_strcpy(&channel, new->channel);
else
{
malloc_strcat(&channel, ",");
malloc_strcat(&channel, new->channel);
}
for (l = next_nicklist(new, NULL); l; l = next_nicklist(new, l)) for (l = next_nicklist(new, NULL); l; l = next_nicklist(new, l))
{ {
if (nick_isaway(l)) if (nick_isaway(l))
@@ -583,50 +563,59 @@ BanList *b;
stats_sunbans += new->stats_sunbans; stats_sunbans += new->stats_sunbans;
} }
} }
if (!ircops)
malloc_strcat(&ircops, empty_string); if (do_hook(CHANNEL_STATS_LIST,
if (do_hook(CHANNEL_STATS_LIST, "%s %s %s %lu %lu %lu %lu %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %d %s", "%s %s %s %lu %lu %lu %lu %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %d %s",
channel, empty_string, empty_string, channel, empty_string, empty_string,
nick_mem+chan_mem+ban_mem, nick_mem, nick_mem + chan_mem + ban_mem, nick_mem,
(unsigned long)sizeof(ChannelList),ban_mem, (unsigned long)sizeof(ChannelList), ban_mem,
stats_ops, stats_dops, stats_bans, stats_unbans, stats_ops, stats_dops, stats_bans, stats_unbans,
stats_topics, stats_kicks, stats_pubs, stats_parts, stats_topics, stats_kicks, stats_pubs, stats_parts,
stats_signoffs, stats_joins, total_bans, max_bans, stats_signoffs, stats_joins, total_bans, max_bans,
stats_sops, stats_sdops,stats_sbans, stats_sunbans, stats_sops, stats_sdops, stats_sbans, stats_sunbans,
usershere, usersaway, chanops, chanunop,total_nicks,max_nicks, usershere, usersaway, chanops, chanunop, total_nicks, max_nicks,
numircops, max_hops, ircops)) numircops, max_hops, ircops ? ircops : ""))
{ {
put_it("%s", convert_output_format("$G %CInformation for channels %K: %W$0", "%s", channel)); put_it("%s", convert_output_format("$G %CInformation for channels %K: %W$0", "%s", channel));
put_it("%s", convert_output_format(" MEM usage%K:%w Total%K:%w %c$0 bytes %K[%cNicks $1 b Chan $2 b Bans $3 b%K]", "%d %d %d %d", (int)(nick_mem+chan_mem+ban_mem), (int)nick_mem, (int)sizeof(ChannelList), (int)ban_mem)); put_it("%s", convert_output_format(" MEM usage%K:%w Total%K:%w %c$0 bytes %K[%cNicks $1 b Chan $2 b Bans $3 b%K]", "%d %d %d %d", (int)(nick_mem+chan_mem+ban_mem), (int)nick_mem, (int)sizeof(ChannelList), (int)ban_mem));
put_it("%s", convert_output_format("Ops %K[%W$[-5]0%K]%w De-Ops %K[%W$[-5]1%K]%w Bans %K[%W$[-5]2%K]%w Unbans %K[%W$[-5]3%K]%w", "%u %u %u %u", stats_ops, stats_dops, stats_bans, stats_unbans)); put_it("%s", convert_output_format("Ops %K[%W$[-5]0%K]%w De-Ops %K[%W$[-5]1%K]%w Bans %K[%W$[-5]2%K]%w Unbans %K[%W$[-5]3%K]%w", "%u %u %u %u", stats_ops, stats_dops, stats_bans, stats_unbans));
put_it("%s", convert_output_format("Topics %K[%W$[-5]0%K]%w Kicks %K[%W$[-5]1%K]%w Publics %K[%W$[-5]2%K]%w Parts %K[%W$[-5]3%K]%w", "%u %u %u %u", stats_topics, stats_kicks, stats_pubs, stats_parts)); put_it("%s", convert_output_format("Topics %K[%W$[-5]0%K]%w Kicks %K[%W$[-5]1%K]%w Publics %K[%W$[-5]2%K]%w Parts %K[%W$[-5]3%K]%w", "%u %u %u %u", stats_topics, stats_kicks, stats_pubs, stats_parts));
put_it("%s", convert_output_format("Signoffs %C[%W$[-5]0%K]%w Joins %K[%W$[-5]1%K]%w TotalBans %K[%W$[-5]2%K]%w MaxBans %K[%W$[-5]3%K]%w", "%u %u %u %u", stats_signoffs, stats_joins, total_bans, max_bans)); put_it("%s", convert_output_format("Signoffs %C[%W$[-5]0%K]%w Joins %K[%W$[-5]1%K]%w TotalBans %K[%W$[-5]2%K]%w MaxBans %K[%W$[-5]3%K]%w", "%u %u %u %u", stats_signoffs, stats_joins, total_bans, max_bans));
put_it("%s", convert_output_format("ServOps %K[%W$[-5]0%K]%w ServDeop %K[%W$[-5]1%K]%w ServBans %K[%W$[-5]2%K]%w ServUB %K[%W$[-5]3%K]%w", "%u %u %u %u", stats_sops, stats_sdops,stats_sbans, stats_sunbans)); put_it("%s", convert_output_format("ServOps %K[%W$[-5]0%K]%w ServDeop %K[%W$[-5]1%K]%w ServBans %K[%W$[-5]2%K]%w ServUB %K[%W$[-5]3%K]%w", "%u %u %u %u", stats_sops, stats_sdops,stats_sbans, stats_sunbans));
put_it("%s", convert_output_format("Users Here %K[%W$[-5]0%K]%w Users Away %K[%W$[-5]1%K]%w Opped %K[%W$[-5]2%K]%w Unopped %K[%W$[-5]3%K]%w", "%u %u %u %u", usershere, usersaway, chanops, chanunop)); put_it("%s", convert_output_format("Users Here %K[%W$[-5]0%K]%w Users Away %K[%W$[-5]1%K]%w Opped %K[%W$[-5]2%K]%w Unopped %K[%W$[-5]3%K]%w", "%u %u %u %u", usershere, usersaway, chanops, chanunop));
put_it("%s", convert_output_format("TotalNicks %K[%W$[-5]0%K]%w MaxNicks %K[%W$[-5]1%K]%w ServerHops %K[%W$[-5]2%K]%w", "%d %d %d", total_nicks,max_nicks, max_hops)); put_it("%s", convert_output_format("TotalNicks %K[%W$[-5]0%K]%w MaxNicks %K[%W$[-5]1%K]%w ServerHops %K[%W$[-5]2%K]%w", "%d %d %d", total_nicks,max_nicks, max_hops));
put_it("%s", convert_output_format("IRCops %K[%W$[3]0%K]%w$1-", "%d %s", numircops, ircops)); put_it("%s", convert_output_format("IRCops %K[%W$[3]0%K]%w$1-", "%d %s", numircops, ircops ? ircops : ""));
} }
new_free(&ircops); new_free(&ircops);
new_free(&channel); new_free(&channel);
return; return;
} }
} }
else
channel = make_channel(channel);
new = prepare_command(&server, channel, PC_SILENT);
if (!new)
{ {
if (!(new = prepare_command(&server, channel, PC_SILENT))) if (channel)
if ((channel && !(new1 = check_whowas_chan_buffer(channel, -1, 0)))) {
WhowasChanList *whowas_chan = check_whowas_chan_buffer(channel, -1, 0);
if (!whowas_chan)
{
bitchsay("No stats available for %s", channel);
return; return;
} }
if (!new && new1) new = whowas_chan->channellist;
new = new1->channellist; }
if (!new) else
{ {
bitchsay("Try joining a channel first"); bitchsay("Try joining a channel first");
return; return;
} }
if (new) }
{
for (l = next_nicklist(new, NULL); l; l = next_nicklist(new, l)) for (l = next_nicklist(new, NULL); l; l = next_nicklist(new, l))
{ {
nick_mem += sizeof(NickList); nick_mem += sizeof(NickList);
@@ -650,10 +639,9 @@ put_it("%s", convert_output_format("IRCops %K[%W$[3]0%K]%w$1-", "%d %s", num
} }
for (b = new->bans; b; b = b->next) for (b = new->bans; b; b = b->next)
ban_mem += sizeof(BanList); ban_mem += sizeof(BanList);
}
if (!ircops) if (do_hook(CHANNEL_STATS_LIST,
malloc_strcat(&ircops, empty_string); "%s %s %s %ld %ld %ld %ld %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %d %s",
if (do_hook(CHANNEL_STATS_LIST, "%s %s %s %ld %ld %ld %ld %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %u %d %s",
new->channel, my_ctime(new->channel_create.tv_sec), convert_time(now-new->join_time.tv_sec), new->channel, my_ctime(new->channel_create.tv_sec), convert_time(now-new->join_time.tv_sec),
nick_mem+sizeof(ChannelList)+ban_mem, nick_mem, nick_mem+sizeof(ChannelList)+ban_mem, nick_mem,
(unsigned long)sizeof(ChannelList),ban_mem, (unsigned long)sizeof(ChannelList),ban_mem,
@@ -662,27 +650,25 @@ put_it("%s", convert_output_format("IRCops %K[%W$[3]0%K]%w$1-", "%d %s", num
new->stats_signoffs, new->stats_joins, new->totalbans, new->maxbans, new->stats_signoffs, new->stats_joins, new->totalbans, new->maxbans,
new->stats_sops, new->stats_sdops,new->stats_sbans, new->stats_sunbans, new->stats_sops, new->stats_sdops,new->stats_sbans, new->stats_sunbans,
usershere, usersaway, chanops, chanunop,new->totalnicks,new->maxnicks, usershere, usersaway, chanops, chanunop,new->totalnicks,new->maxnicks,
numircops, max_hops, ircops)) numircops, max_hops, ircops ? ircops : ""))
{ {
put_it("%s", convert_output_format("$G %CInformation for channel %K: %W$0", "%s", new->channel)); put_it("%s", convert_output_format("$G %CInformation for channel %K: %W$0", "%s", new->channel));
put_it("%s", convert_output_format("$G %CChannel created %K: %W$0 $1 $2 $3%n in memory %W$4-", "%s %s", convert_time(now-new->channel_create.tv_sec), my_ctime(new->join_time.tv_sec))); put_it("%s", convert_output_format("$G %CChannel created %K: %W$0 $1 $2 $3%n in memory %W$4-", "%s %s", convert_time(now-new->channel_create.tv_sec), my_ctime(new->join_time.tv_sec)));
put_it("%s", convert_output_format(" MEM usage%K:%w Total%K:%w %c$0 bytes %K[%cNicks $1 b Chan $2 b Bans $3 b%K]", "%d %d %d %d", (int)(nick_mem+sizeof(ChannelList)+ban_mem), (int)nick_mem, (int)sizeof(ChannelList), (int)ban_mem));
put_it("%s", convert_output_format("Ops %K[%W$[-5]0%K]%w De-Ops %K[%W$[-5]1%K]%w Bans %K[%W$[-5]2%K]%w Unbans %K[%W$[-5]3%K]%w", "%u %u %u %u", new->stats_ops, new->stats_dops, new->stats_bans, new->stats_unbans));
put_it("%s", convert_output_format("Topics %K[%W$[-5]0%K]%w Kicks %K[%W$[-5]1%K]%w Publics %K[%W$[-5]2%K]%w Parts %K[%W$[-5]3%K]%w", "%u %u %u %u", new->stats_topics, new->stats_kicks, new->stats_pubs, new->stats_parts));
put_it("%s", convert_output_format("Signoffs %K[%W$[-5]0%K]%w Joins %K[%W$[-5]1%K]%w TotalBans %K[%W$[-5]2%K]%w MaxBans %K[%W$[-5]3%K]%w", "%u %u %u %u", new->stats_signoffs, new->stats_joins, new->totalbans, new->maxbans));
put_it("%s", convert_output_format("ServOps %K[%W$[-5]0%K]%w ServDeop %K[%W$[-5]1%K]%w ServBans %K[%W$[-5]2%K]%w ServUB %K[%W$[-5]3%K]%w", "%u %u %u %u", new->stats_sops, new->stats_sdops,new->stats_sbans, new->stats_sunbans));
put_it("%s", convert_output_format("Users Here %K[%W$[-5]0%K]%w Users Away %K[%W$[-5]1%K]%w Opped %K[%W$[-5]2%K]%w Unopped %K[%W$[-5]3%K]%w", "%u %u %u %u", usershere, usersaway, chanops, chanunop));
put_it("%s", convert_output_format("TotalNicks %K[%W$[-5]0%K]%w MaxNicks %K[%W$[-5]1%K]%w ServerHops %K[%W$[-5]2%K]%w", "%d %d %d", new->totalnicks,new->maxnicks, max_hops));
put_it("%s", convert_output_format("IRCops %K[%W$[3]0%K]%w$1-", "%d %s", numircops, ircops ? ircops : ""));
put_it("%s", convert_output_format(" MEM usage%K:%w Total%K:%w %c$0 bytes %K[%cNicks $1 b Chan $2 b Bans $3 b%K]", "%d %d %d %d", (int)(nick_mem+sizeof(ChannelList)+ban_mem), (int)nick_mem, (int)sizeof(ChannelList), (int)ban_mem)); put_it("%s", convert_output_format(" %CThere is %R$0%C limit and limit checking is %R$1-", "%s %s", new->limit ? ltoa(new->limit): "no", new->tog_limit?"Enabled":"Disabled"));
put_it("%s", convert_output_format("Ops %K[%W$[-5]0%K]%w De-Ops %K[%W$[-5]1%K]%w Bans %K[%W$[-5]2%K]%w Unbans %K[%W$[-5]3%K]%w", "%u %u %u %u", new->stats_ops, new->stats_dops, new->stats_bans, new->stats_unbans)); put_it("%s", convert_output_format(" %CIdle user check is %K[%R$0-%K]", "%s", new->check_idle?"Enabled":"Disabled"));
put_it("%s", convert_output_format("Topics %K[%W$[-5]0%K]%w Kicks %K[%W$[-5]1%K]%w Publics %K[%W$[-5]2%K]%w Parts %K[%W$[-5]3%K]%w", "%u %u %u %u", new->stats_topics, new->stats_kicks, new->stats_pubs, new->stats_parts)); /*put_it("%s", convert_output_format("$G End of channel stats for $0", "%s", new->channel));*/
put_it("%s", convert_output_format("Signoffs %K[%W$[-5]0%K]%w Joins %K[%W$[-5]1%K]%w TotalBans %K[%W$[-5]2%K]%w MaxBans %K[%W$[-5]3%K]%w", "%u %u %u %u", new->stats_signoffs, new->stats_joins, new->totalbans, new->maxbans));
put_it("%s", convert_output_format("ServOps %K[%W$[-5]0%K]%w ServDeop %K[%W$[-5]1%K]%w ServBans %K[%W$[-5]2%K]%w ServUB %K[%W$[-5]3%K]%w", "%u %u %u %u", new->stats_sops, new->stats_sdops,new->stats_sbans, new->stats_sunbans));
put_it("%s", convert_output_format("Users Here %K[%W$[-5]0%K]%w Users Away %K[%W$[-5]1%K]%w Opped %K[%W$[-5]2%K]%w Unopped %K[%W$[-5]3%K]%w", "%u %u %u %u", usershere, usersaway, chanops, chanunop));
put_it("%s", convert_output_format("TotalNicks %K[%W$[-5]0%K]%w MaxNicks %K[%W$[-5]1%K]%w ServerHops %K[%W$[-5]2%K]%w", "%d %d %d", new->totalnicks,new->maxnicks, max_hops));
put_it("%s", convert_output_format("IRCops %K[%W$[3]0%K]%w$1-", "%d %s", numircops, ircops));
put_it("%s", convert_output_format(" %CThere is %R$0%C limit and limit checking is %R$1-", "%s %s", new->limit ? ltoa(new->limit): "no", new->tog_limit?"Enabled":"Disabled"));
put_it("%s", convert_output_format(" %CIdle user check is %K[%R$0-%K]", "%s", new->check_idle?"Enabled":"Disabled"));
/*put_it("%s", convert_output_format("$G End of channel stats for $0", "%s", new->channel));*/
/* wtf is do_scan in the channel struct */ /* wtf is do_scan in the channel struct */
} }
new_free(&ircops); new_free(&ircops);
} }
void update_stats(int what, NickList *nick, ChannelList *chan, int splitter) void update_stats(int what, NickList *nick, ChannelList *chan, int splitter)
@@ -4676,14 +4662,15 @@ ChannelList *chan = NULL;
char *BX_make_channel (char *chan) char *BX_make_channel (char *chan)
{ {
static char buffer[IRCD_BUFFER_SIZE+1]; static char buffer[IRCD_BUFFER_SIZE+1];
*buffer = 0;
if (!chan) if (!chan)
return NULL; return NULL;
if (*chan != '#' && *chan != '&' && *chan != '+' && *chan != '!') if (*chan != '#' && *chan != '&' && *chan != '+' && *chan != '!')
snprintf(buffer, IRCD_BUFFER_SIZE-2, "#%s", chan); snprintf(buffer, sizeof buffer, "#%s", chan);
else else
strlcpy(buffer, chan, sizeof buffer); strlcpy(buffer, chan, sizeof buffer);
return buffer; return buffer;
} }