cmd_trim added, fixed some bugs and added DATABASE modifications
authorpk910 <philipp@zoelle1.de>
Wed, 24 Aug 2011 07:57:25 +0000 (09:57 +0200)
committerpk910 <philipp@zoelle1.de>
Wed, 24 Aug 2011 07:57:25 +0000 (09:57 +0200)
DATABASE.txt [new file with mode: 0644]
bot_NeonServ.c
cmd_neonserv_mdeluser.c
cmd_neonserv_trim.c
lang.c

diff --git a/DATABASE.txt b/DATABASE.txt
new file mode 100644 (file)
index 0000000..e6d81b4
--- /dev/null
@@ -0,0 +1,15 @@
+//Database of NeonServ V4 modifications for NeonServ V5
+
+ALTER TABLE `bots` CHANGE `botclass` `botclass` INT( 10 ) NOT NULL;
+
+ALTER TABLE `users` CHANGE `user_lang` `user_lang` VARCHAR( 6 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL;
+
+CREATE TABLE IF NOT EXISTS `godlog` (
+  `godlog_id` int(11) NOT NULL AUTO_INCREMENT,
+  `godlog_uid` int(11) NOT NULL,
+  `godlog_cid` int(15) NOT NULL,
+  `godlog_time` int(15) NOT NULL,
+  `godlog_cmd` varchar(512) NOT NULL,
+  PRIMARY KEY (`godlog_id`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
+
index 1dda375415f9993a45e93cf1aeb5a37320ca5cc2..e95c4a04fc9033b35681ed90005106ae89a5d7db 100644 (file)
@@ -76,6 +76,8 @@ static const struct default_language_entry msgtab[] = {
     {"NS_UP_ALREADY_VOICE", "You are already voiced in \002%s\002."},
     {"NS_DOWN_ALREADY", "You are not opped or voiced in \002%s\002."},
     {"NS_MDELUSER_DONE", "Deleted \002%d\002 account(s) matching \002%s\002 with access from \002%d\002 to \002%d\002 from the %s user list."},
+    {"NS_TRIM_DURATION_TOO_SHORT", "You must include a minimum inactivity duration of at least %d seconds to trim."},
+    {"NS_TRIM_DONE", "Trimmed \002%d users\002 with access from %d to %d from the %s user list who were inactive for at least %s."},
     {NULL, NULL}
 };
 
index ed830798e3255edf3473335584d78147cba8a8c7..7dceafb5bbaba77d835e56694026c9a1a1203e0a 100644 (file)
@@ -13,7 +13,7 @@ static CMD_BIND(neonserv_cmd_mdeluser) {
     int min_access, max_access;
     char *seperator = strstr(argv[0], "-");
     if(seperator) {
-        seperator = '\0';
+        *seperator = '\0';
         seperator++;
         min_access = atoi(argv[0]);
         max_access = atoi(seperator);
index e938ed5f57d371bf515e05c4001b2c42c68ae42a..99b8c16d13100c99dee7530a4d1abef04879fa0d 100644 (file)
@@ -2,26 +2,39 @@
 /*
 * argv[0]  target (format: minaccess-maxaccess/users/bans)
 * argv[1]  duration
-* argv[2]  (optional) "vacation"
 */
+static USERLIST_CALLBACK(neonserv_cmd_trim_userlist_lookup);
+static void neonserv_cmd_trim_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, int min_access, int max_access, int duration);
+
+struct neonserv_cmd_trim_cache {
+    struct ClientSocket *client, *textclient;
+    struct UserNode *user;
+    int min_access;
+    int max_access;
+    int duration;
+};
 
 static CMD_BIND(neonserv_cmd_trim) {
     check_mysql();
-    if(!checkChannelAccess(user, chan, "channel_candel", 1, 0)) {
+    if(stricmp(argv[0], "bans") && !checkChannelAccess(user, chan, "channel_candel", 1, 0)) {
         reply(getTextBot(), user, "NS_ACCESS_DENIED");
         return;
     }
     int min_access, max_access;
-    if(!strcmp(argv[0], "users")) {
+    if(!stricmp(argv[0], "users")) {
         min_access = 1;
         max_access = getChannelAccess(user, chan, 0) - 1;
-    } else if(!strcmp(argv[0], "bans")) {
+    } else if(!stricmp(argv[0], "bans")) {
+        if(!checkChannelAccess(user, chan, "channel_staticban", 1, 0)) {
+            reply(getTextBot(), user, "NS_ACCESS_DENIED");
+            return;
+        }
         //TODO: TRIM BANS
         return;
     } else {
         char *seperator = strstr(argv[0], "-");
         if(seperator) {
-            seperator = '\0';
+            *seperator = '\0';
             seperator++;
             min_access = atoi(argv[0]);
             max_access = atoi(seperator);
@@ -40,7 +53,55 @@ static CMD_BIND(neonserv_cmd_trim) {
     }
     //parse duration...
     int duration = strToTime(user, argv[1]);
-    char timeBuf[MAXLEN];
-    reply(getTextBot(), user, "yea; time: %d  (%s)", duration, timeToStr(user, duration, 3, timeBuf));
+    if(duration < 30) {
+        reply(getTextBot(), user, "NS_TRIM_DURATION_TOO_SHORT", 30);
+        return;
+    }
+    struct neonserv_cmd_trim_cache *cache = malloc(sizeof(*cache));
+    if (!cache) {
+        perror("malloc() failed");
+        return;
+    }
+    cache->client = client;
+    cache->textclient = getTextBot();
+    cache->user = user;
+    cache->min_access = min_access;
+    cache->max_access = max_access;
+    cache->duration = duration;
+    get_userlist(chan, neonserv_cmd_trim_userlist_lookup, cache);
 }
 
+static USERLIST_CALLBACK(neonserv_cmd_users_userlist_lookup) {
+    struct neonserv_cmd_users_cache *cache = data;
+    //got userlist
+    neonserv_cmd_trim_async1(cache->client, cache->textclient, cache->user, chan, cache->min_access, cache->max_access, cache->duration);
+    free(cache);
+}
+
+static void neonserv_cmd_trim_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, int min_access, int max_access, int duration) {
+    YSQL_RES *res;
+    MYSQL_ROW row;
+    int trim_count = 0, is_here;
+    struct ChanUser *chanuser;
+    printf_mysql_query("SELECT `chanuser_seen`, `user_user`, `chanuser_id` FROM `chanusers` LEFT JOIN `users` ON `chanuser_uid` = `user_id` WHERE `chanuser_cid` = '%d' AND `chanuser_access` >= '%d' AND `chanuser_access` <= '%d'", chan->channel_id, min_access, max_access);
+    res = mysql_use();
+    while ((row = mysql_fetch_row(res)) != NULL) {
+        if(!strcmp(row[0], "0") || time(0) - atoi(row[0]) >= duration) {
+            //check if the user is currently in the channel
+            is_here = 0;
+            for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) {
+                if((chanuser->user->flags & USERFLAG_ISAUTHED) && !strcmp(chanuser->user->auth, row[1])) {
+                    is_here = 1;
+                    break;
+                }
+            }
+            if(!is_here) {
+                //delete the user
+                trim_count++;
+                printf_mysql_query("DELETE FROM `chanusers` WHERE `chanuser_id` = '%s'", row[2]);
+            }
+        }
+    }
+    char timeBuf[MAXLEN];
+    reply(getTextBot(), user, "NS_TRIM_DONE", trim_count, min_access, max_access, chan->name, timeToStr(user, duration, 3, timeBuf));
+}
diff --git a/lang.c b/lang.c
index 2c186485f7bbada8ef37ac6a082d62897f99acdf..3acd0662548564129a5e381fccbe6a7686a35eef 100644 (file)
--- a/lang.c
+++ b/lang.c
@@ -121,7 +121,6 @@ char *build_language_string(struct UserNode *user, char *buffer, const char *msg
     pos = vsnprintf(buffer, MAXLEN - 2, formatStr, arg_list);
     va_end(arg_list);
     if (pos < 0 || pos > (MAXLEN - 2)) pos = MAXLEN - 2;
-    buffer[pos] = '\n';
-    buffer[pos+1] = '\0';
+    buffer[pos] = '\0';
     return buffer;
 }