Another year is about to end... So we have to update these damn copyright information :P
[NeonServV5.git] / src / cmd_neonserv_unvisited.c
index 3cfaed98bfd97ba0d96c6d6c9b6e4070eac37dcc..9d7cda7f2e4f9fd07587007d3edf706560304afc 100644 (file)
@@ -1,5 +1,5 @@
-/* cmd_neonserv_unvisited.c - NeonServ v5.1
- * Copyright (C) 2011  Philipp Kreil (pk910)
+/* cmd_neonserv_unvisited.c - NeonServ v5.3
+ * Copyright (C) 2011-2012  Philipp Kreil (pk910)
  * 
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -43,7 +43,7 @@ CMD_BIND(neonserv_cmd_unvisited) {
     cache->textclient = getTextBot();
     cache->user = user;
     cache->duration = duration;
-    cache->who_count = 0;
+    cache->who_count = 1; /* small fake to prevent the cache to be freed too early */
     cache->matches = 0;
     printf_mysql_query("SELECT `channel_id`, `channel_name`, `channel_nodelete` FROM `bot_channels` LEFT JOIN `channels` ON `chanid` = `channel_id` LEFT JOIN `users` ON `channel_registrator` = `user_id` WHERE `botid` = '%d'", client->botid);
     res = mysql_use();
@@ -51,8 +51,8 @@ CMD_BIND(neonserv_cmd_unvisited) {
         if(!strcmp(row[2], "1")) continue;
         printf_mysql_query("SELECT `chanuser_seen` FROM `chanusers` WHERE `chanuser_cid` = '%s' AND `chanuser_access` >= 300 ORDER BY `chanuser_seen` DESC LIMIT 1", row[0]);
         res2 = mysql_use();
-        row2 = mysql_fetch_row(res);
-        if(row2 && (time(0) - atoi(row2[0])) < duration) continue;
+        row2 = mysql_fetch_row(res2);
+        if(row2 && atol(row2[0]) > (time(0) - duration)) continue;
         channel = getChanByName(row[1]);
         if(channel) {
             cache->who_count++;
@@ -63,6 +63,7 @@ CMD_BIND(neonserv_cmd_unvisited) {
             cache->matches++;
         }   
     }
+    cache->who_count--; //see fix on line 46
     if(cache->who_count == 0) {
         neonserv_cmd_unvisited_async2(cache);
     }