added possibility to select a bot used for the statistics
[NeonServV5.git] / src / modules / stats.mod / module.c
index c81e3a6b12a14ecbea820690013d8d19e3ade7aa..4780077c49739e35666736f293626eb1573df819 100644 (file)
@@ -94,21 +94,27 @@ static TIMEQ_CALLBACK(stats_timer_callback) {
     if(get_int_field(tmp))
         pkgpos += sprintf(pkgbuf + pkgpos, "*\n");
     else {
-        struct ClientSocket *bot, *bot1 = NULL, *bot2 = NULL, *bot3 = NULL;
+        sprintf(tmp, "modules/%s/use_bot", modname);
+        char *botname = get_string_field(tmp);
+        struct ClientSocket *bot, *bot1 = NULL, *bot2 = NULL, *bot3 = NULL, *bot4 = NULL;
         for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
-            if(bot->botid == 1 && (bot->flags & SOCKET_FLAG_PREFERRED))
+            if(botname && !stricmp(bot->nick, botname))
                 bot1 = bot;
-            else if((bot->flags & SOCKET_FLAG_PREFERRED))
+            else if(bot->botid == 1 && (bot->flags & SOCKET_FLAG_PREFERRED))
                 bot2 = bot;
-            else
+            else if((bot->flags & SOCKET_FLAG_PREFERRED))
                 bot3 = bot;
+            else
+                bot4 = bot;
         }
         if(bot1)
             bot = bot1;
         else if(bot2)
             bot = bot2;
-        else
+        else if(bot3)
             bot = bot3;
+        else
+            bot = bot4;
         if(bot) {
             pkgpos += sprintf(pkgbuf + pkgpos, "%s!%s@%s %d\n", (bot->user ? bot->user->nick : "*"), (bot->user ? bot->user->ident : "*"), (bot->host ? bot->host : "*"), bot->port);
         } else