Change the handle_server_stats so that the averages (eg. users per
channel) are correctly rounded. Added a divide_rounded() function that rounds to nearest integer. This also gets rid of the messy floating point divisions in that function. git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@73 13b04d17-f746-0410-82c6-800466cd88b0
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
[Changes 1.2c01]
|
[Changes 1.2c01]
|
||||||
|
|
||||||
|
* Change the display of server stats so that the averages (eg. users per
|
||||||
|
channel) are correctly rounded. (caf)
|
||||||
|
|
||||||
* Reinstate RPL_WHOISACTUALLY numeric - things seem to have stabilised in
|
* Reinstate RPL_WHOISACTUALLY numeric - things seem to have stabilised in
|
||||||
the ircd world on this. (caf)
|
the ircd world on this. (caf)
|
||||||
|
|
||||||
|
|||||||
@@ -381,6 +381,21 @@ static void cannot_join_channel(char *from, char **ArgList)
|
|||||||
reset_display_target();
|
reset_display_target();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* divide_rounded()
|
||||||
|
*
|
||||||
|
* Implements an integer division of a / b, where 1.5 rounds up to 2 and
|
||||||
|
* 1.49 rounds down to 1. Returns zero if divisor is zero.
|
||||||
|
*/
|
||||||
|
static int divide_rounded(int a, int b)
|
||||||
|
{
|
||||||
|
if (a < 0)
|
||||||
|
{
|
||||||
|
a = -a;
|
||||||
|
b = -b;
|
||||||
|
}
|
||||||
|
|
||||||
|
return b ? (a + abs(b / 2)) / b : 0;
|
||||||
|
}
|
||||||
|
|
||||||
int handle_server_stats(char *from, char **ArgList, int comm)
|
int handle_server_stats(char *from, char **ArgList, int comm)
|
||||||
{
|
{
|
||||||
@@ -394,7 +409,6 @@ static int norm = 0,
|
|||||||
local_users = 0,
|
local_users = 0,
|
||||||
total_users = 0,
|
total_users = 0,
|
||||||
services_flag = 0;
|
services_flag = 0;
|
||||||
char tmp[80];
|
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
char *line;
|
char *line;
|
||||||
|
|
||||||
@@ -434,26 +448,33 @@ static int norm = 0,
|
|||||||
total_users = norm + invisible;
|
total_users = norm + invisible;
|
||||||
if (total_users)
|
if (total_users)
|
||||||
{
|
{
|
||||||
sprintf(tmp, "%3.0f", (float)(((float)local_users / (float)total_users) * 100));
|
put_it("%s", convert_output_format("$G %K[%nlocal users on irc%K(%n\002$0\002%K)]%n $1%%",
|
||||||
put_it("%s", convert_output_format("$G %K[%nlocal users on irc%K(%n\002$0\002%K)]%n $1%%", "%d %s", local_users, tmp));
|
"%d %d", local_users, divide_rounded(local_users * 100, total_users)));
|
||||||
sprintf(tmp, "%3.0f", (float)(((float)norm / (float)total_users) * 100));
|
put_it("%s", convert_output_format("$G %K[%nglobal users on irc%K(%n\002$0\002%K)]%n $1%%",
|
||||||
put_it("%s", convert_output_format("$G %K[%nglobal users on irc%K(%n\002$0\002%K)]%n $1%%", "%d %s", norm, tmp));
|
"%d %d", norm, divide_rounded(norm * 100, total_users)));
|
||||||
if (services_flag)
|
if (services_flag)
|
||||||
{
|
{
|
||||||
sprintf(tmp, "%3.0f", (float)(((float)invisible / (float)total_users) * 100));
|
put_it("%s", convert_output_format("$G %K[%ninvisible users on irc%K(%n\002$0\002%K)]%n $1%%",
|
||||||
put_it("%s", convert_output_format("$G %K[%ninvisible users on irc%K(%n\002$0\002%K)]%n $1%%", "%d %s", invisible, tmp));
|
"%d %d", invisible, divide_rounded(invisible * 100, total_users)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
put_it("%s", convert_output_format("$G %K[%nservices on irc%K(%n\002$0\002%K)]%n", "%d", services));
|
put_it("%s", convert_output_format("$G %K[%nservices on irc%K(%n\002$0\002%K)]%n",
|
||||||
sprintf(tmp, "%3.0f", (float)(((float)ircops / (float)total_users) * 100));
|
"%d", services));
|
||||||
put_it("%s", convert_output_format("$G %K[%nircops on irc%K(%n\002$0\002%K)]%n $1%%", "%d %s", ircops, tmp));
|
put_it("%s", convert_output_format("$G %K[%nircops on irc%K(%n\002$0\002%K)]%n $1%%",
|
||||||
|
"%d %d", ircops, divide_rounded(ircops * 100, total_users)));
|
||||||
}
|
}
|
||||||
put_it("%s", convert_output_format("$G %K[%ntotal users on irc%K(%n\002$0\002%K)]%n", "%d", total_users));
|
put_it("%s", convert_output_format("$G %K[%ntotal users on irc%K(%n\002$0\002%K)]%n",
|
||||||
put_it("%s", convert_output_format("$G %K[%nunknown connections%K(%n\002$0\002%K)]%n", "%d", unknown));
|
"%d", total_users));
|
||||||
|
put_it("%s", convert_output_format("$G %K[%nunknown connections%K(%n\002$0\002%K)]%n",
|
||||||
|
"%d", unknown));
|
||||||
|
|
||||||
put_it("%s", convert_output_format("$G %K[%ntotal servers on irc%K(%n\002$0\002%K)]%n %K(%navg. $1 users per server%K)", "%d %d", servers, (servers) ? (int)(total_users/servers) : 0));
|
put_it("%s", convert_output_format(
|
||||||
|
"$G %K[%ntotal servers on irc%K(%n\002$0\002%K)]%n %K(%navg. $1 users per server%K)",
|
||||||
|
"%d %d", servers, divide_rounded(total_users, servers)));
|
||||||
|
|
||||||
put_it("%s", convert_output_format("$G %K[%ntotal channels created%K(%n\002$0\002%K)]%n %K(%navg. $1 users per channel%K)", "%d %d", chans, (chans) ? (int)(total_users/chans) : 0));
|
put_it("%s", convert_output_format(
|
||||||
|
"$G %K[%ntotal channels created%K(%n\002$0\002%K)]%n %K(%navg. $1 users per channel%K)",
|
||||||
|
"%d %d", chans, divide_rounded(total_users, chans)));
|
||||||
break;
|
break;
|
||||||
case 250:
|
case 250:
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user