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

@@ -484,7 +484,6 @@ BUILT_IN_COMMAND(channel_stats)
{
ChannelList *new = NULL;
char *channel = NULL;
WhowasChanList *new1 = NULL;
int numircops = 0;
int usershere = 0;
int usersaway = 0;
@@ -493,37 +492,23 @@ int chanunop = 0;
char *ircops = NULL;
int server = -1;
int max_hops = 0;
NickList *l;
unsigned long nick_mem = 0,
ban_mem = 0;
unsigned long nick_mem = 0;
unsigned long ban_mem = 0;
BanList *b;
if (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_topics = 0, stats_kicks = 0, stats_pubs = 0, stats_parts = 0;
int stats_signoffs = 0, stats_joins = 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;
NickList *l;
BanList *b;
unsigned long chan_mem = 0;
channel = NULL;
@@ -531,13 +516,8 @@ BanList *b;
{
for (new = get_server_channels(from_server); new; new = new->next)
{
if (!channel)
malloc_strcpy(&channel, new->channel);
else
{
malloc_strcat(&channel, ",");
malloc_strcat(&channel, new->channel);
}
m_s3cat(&channel, ",", new->channel);
for (l = next_nicklist(new, NULL); l; l = next_nicklist(new, l))
{
if (nick_isaway(l))
@@ -583,9 +563,9 @@ BanList *b;
stats_sunbans += new->stats_sunbans;
}
}
if (!ircops)
malloc_strcat(&ircops, empty_string);
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",
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",
channel, empty_string, empty_string,
nick_mem + chan_mem + ban_mem, nick_mem,
(unsigned long)sizeof(ChannelList), ban_mem,
@@ -594,7 +574,7 @@ if (do_hook(CHANNEL_STATS_LIST, "%s %s %s %lu %lu %lu %lu %u %u %u %u %u %u %u %
stats_signoffs, stats_joins, total_bans, max_bans,
stats_sops, stats_sdops, stats_sbans, stats_sunbans,
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(" 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));
@@ -604,29 +584,38 @@ put_it("%s", convert_output_format("Signoffs %C[%W$[-5]0%K]%w Joins %K[%
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("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(&channel);
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 && !(new1 = check_whowas_chan_buffer(channel, -1, 0))))
if (channel)
{
WhowasChanList *whowas_chan = check_whowas_chan_buffer(channel, -1, 0);
if (!whowas_chan)
{
bitchsay("No stats available for %s", channel);
return;
}
if (!new && new1)
new = new1->channellist;
if (!new)
new = whowas_chan->channellist;
}
else
{
bitchsay("Try joining a channel first");
return;
}
if (new)
{
}
for (l = next_nicklist(new, NULL); l; l = next_nicklist(new, l))
{
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)
ban_mem += sizeof(BanList);
}
if (!ircops)
malloc_strcat(&ircops, empty_string);
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",
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),
nick_mem+sizeof(ChannelList)+ban_mem, nick_mem,
(unsigned long)sizeof(ChannelList),ban_mem,
@@ -662,11 +650,10 @@ 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_sops, new->stats_sdops,new->stats_sbans, new->stats_sunbans,
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 %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));
@@ -674,7 +661,7 @@ put_it("%s", convert_output_format("Signoffs %K[%W$[-5]0%K]%w Joins %K[%
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("IRCops %K[%W$[3]0%K]%w$1-", "%d %s", numircops, ircops ? 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"));
@@ -682,7 +669,6 @@ put_it("%s", convert_output_format(" %CIdle user check is %K[%R$0-%K]", "%s", n
/* wtf is do_scan in the channel struct */
}
new_free(&ircops);
}
void update_stats(int what, NickList *nick, ChannelList *chan, int splitter)
@@ -4677,13 +4663,14 @@ ChannelList *chan = NULL;
char *BX_make_channel (char *chan)
{
static char buffer[IRCD_BUFFER_SIZE+1];
*buffer = 0;
if (!chan)
return NULL;
if (*chan != '#' && *chan != '&' && *chan != '+' && *chan != '!')
snprintf(buffer, IRCD_BUFFER_SIZE-2, "#%s", chan);
snprintf(buffer, sizeof buffer, "#%s", chan);
else
strlcpy(buffer, chan, sizeof buffer);
return buffer;
}