tried to reorder the program structure and build process
[NeonServV5.git] / cmd_neonserv_users.c
diff --git a/cmd_neonserv_users.c b/cmd_neonserv_users.c
deleted file mode 100644 (file)
index 7834575..0000000
+++ /dev/null
@@ -1,116 +0,0 @@
-
-#include "cmd_neonserv.h"
-
-/*
-* argv[0] - usermask
-* argv[1] - min access
-* argv[2] - max access
-*/
-static USERLIST_CALLBACK(neonserv_cmd_users_userlist_lookup);
-static void neonserv_cmd_users_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, char *usermask, int min_access, int max_access);
-
-struct neonserv_cmd_users_cache {
-    struct ClientSocket *client, *textclient;
-    struct UserNode *user;
-    char *usermask;
-    int min_access;
-    int max_access;
-};
-
-CMD_BIND(neonserv_cmd_users) {
-    int min_access = 1, max_access = 500;
-    char *usermask = NULL;
-    if(argc > 0)
-        usermask = argv[0];
-    if(argc > 2) {
-        min_access = atoi(argv[1]);
-        max_access = atoi(argv[2]);
-    }
-    struct neonserv_cmd_users_cache *cache = malloc(sizeof(*cache));
-    if (!cache) {
-        perror("malloc() failed");
-        return;
-    }
-    cache->client = client;
-    cache->textclient = getTextBot();
-    cache->user = user;
-    cache->usermask = (usermask ? strdup(usermask) : NULL);
-    cache->min_access = min_access;
-    cache->max_access = max_access;
-    get_userlist_with_invisible(chan, neonserv_cmd_users_userlist_lookup, cache);
-}
-
-static USERLIST_CALLBACK(neonserv_cmd_users_userlist_lookup) {
-    struct neonserv_cmd_users_cache *cache = data;
-    neonserv_cmd_users_async1(cache->client, cache->textclient, cache->user, chan, cache->usermask, cache->min_access, cache->max_access);
-    if(cache->usermask)
-        free(cache->usermask);
-    free(cache);
-}
-
-static void neonserv_cmd_users_async1(struct ClientSocket *client, struct ClientSocket *textclient, struct UserNode *user, struct ChanNode *chan, char *usermask, int min_access, int max_access) {
-    MYSQL_RES *res;
-    MYSQL_ROW row;
-    int content_count = 0, cflags, is_here, caccess, i;
-    char seenstr[MAXLEN];
-    struct Table *table;
-    struct ChanUser *chanuser;
-    printf_mysql_query("SELECT `chanuser_access`, `user_user`, `chanuser_seen`, `chanuser_flags` FROM `chanusers` LEFT JOIN `users` ON `chanuser_uid` = `user_id` WHERE `chanuser_cid` = '%d' ORDER BY `chanuser_access` DESC, `user_user` ASC", chan->channel_id);
-    res = mysql_use();
-    table = table_init(4, mysql_num_rows(res) + 1, 0);
-    if(usermask)
-        reply(textclient, user, "NS_USERS_HEADER_MATCH", chan->name, min_access, max_access, usermask);
-    else
-        reply(textclient, user, "NS_USERS_HEADER", chan->name, min_access, max_access);
-    char *content[4];
-    content[0] = get_language_string(user, "NS_USERS_HEADER_ACCESS");
-    content[1] = get_language_string(user, "NS_USERS_HEADER_ACCOUNT");
-    content[2] = get_language_string(user, "NS_USERS_HEADER_SEEN");
-    content[3] = get_language_string(user, "NS_USERS_HEADER_STATE");
-    table_add(table, content);
-    while ((row = mysql_fetch_row(res)) != NULL) {
-        caccess = atoi(row[0]);
-        if((!usermask || !match(usermask, row[1])) && caccess >= min_access && caccess <= max_access) {
-            content[0] = row[0];
-            content[1] = row[1];
-            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])) {
-                    if((chanuser->flags & CHANUSERFLAG_INVISIBLE))
-                        is_here = 2;
-                    else {
-                        is_here = 1;
-                        break;
-                    }
-                }
-            }
-            if(is_here) {
-                content[2] = get_language_string(user, (is_here == 2 ? "NS_USERS_SEEN_INVISIBLE" : "NS_USERS_SEEN_HERE"));
-            } else if(!strcmp(row[2], "0")) {
-                content[2] = get_language_string(user, "NS_USERS_SEEN_NEVER");
-            } else {
-                timeToStr(user, (time(0) - atoi(row[2])), 2, seenstr);
-                content[2] = seenstr; //generate time
-            }
-            cflags = atoi(row[3]);
-            if(cflags & DB_CHANUSER_SUSPENDED)
-                content[3] = get_language_string(user, "NS_USERS_STATE_SUSPENDED");
-            else
-                content[3] = get_language_string(user, "NS_USERS_STATE_NORMAL");
-            content_count++;
-            table_add(table, content);
-        }
-    }
-    //send the table
-    char **table_lines = table_end(table);
-    for(i = 0; i < table->entrys; i++) {
-        reply(textclient, user, table_lines[i]);
-    }
-    if(!content_count)
-        reply(textclient, user, "NS_TABLE_NONE");
-    if(usermask || min_access != 1 || max_access != 500)
-        reply(textclient, user, (table->length == 2 ? "NS_USERS_COUNT_MATCH_1" : "NS_USERS_COUNT_MATCH"), table->length - 1, chan->name, content_count);
-    else
-        reply(textclient, user, (table->length == 2 ? "NS_USERS_COUNT_1" : "NS_USERS_COUNT"), table->length - 1, chan->name);
-    table_free(table);
-}