tried to reorder the program structure and build process
[NeonServV5.git] / src / cmd_neonserv_bans.c
diff --git a/src/cmd_neonserv_bans.c b/src/cmd_neonserv_bans.c
new file mode 100644 (file)
index 0000000..31231d4
--- /dev/null
@@ -0,0 +1,59 @@
+
+#include "cmd_neonserv.h"
+
+/*
+* argv[0]    (optional) mask
+*/
+CMD_BIND(neonserv_cmd_bans) {
+    MYSQL_RES *res;
+    MYSQL_ROW row;
+    //ban list
+    int i, with_expire = 0, cindex = 0;
+    char triggered_str[MAXLEN], expires_str[MAXLEN];
+    struct Table *table;
+    printf_mysql_query("SELECT `ban_mask`, `user_user`, `ban_triggered`, `ban_timeout`, `ban_reason` FROM `bans` LEFT JOIN `users` ON `ban_owner` = `user_id` WHERE `ban_channel` = '%d'", chan->channel_id);
+    res = mysql_use();
+    table = table_init(5, mysql_num_rows(res) + 1, 0);
+    char *content[5];
+    //add a NULL row (we add values later)
+    content[0] = NULL;
+    content[1] = NULL;
+    content[2] = NULL;
+    content[3] = NULL;
+    content[4] = NULL;
+    table_add(table, content);
+    while ((row = mysql_fetch_row(res)) != NULL) {
+        if(argc > 0 && match(argv[0], row[0])) continue;
+        content[0] = row[0];
+        content[1] = row[1];
+        content[2] = (strcmp(row[2], "0") ? timeToStr(user, (time(0) - atoi(row[2])), 2, triggered_str) : get_language_string(user, "NS_USERS_SEEN_NEVER"));
+        if(strcmp(row[3], "0")) {
+            if(!with_expire) {
+                //we're using expire times now...
+                for(i = 0; i < cindex; i++)
+                    table_change_field(table, i+1, 3, get_language_string(user, "NS_USERS_SEEN_NEVER"));
+                with_expire = 1;
+            }
+            content[3] = timeToStr(user, (atoi(row[3]) - time(0)), 2, expires_str);
+        } else
+            content[3] = (with_expire ? get_language_string(user, "NS_USERS_SEEN_NEVER") : NULL);
+        content[4] = row[4];
+        cindex++;
+        table_add(table, content);
+    }
+    //now we add the table header
+    content[0] = get_language_string(user, "NS_BANS_HEADER_MASK");
+    content[1] = get_language_string(user, "NS_BANS_HEADER_SETBY");
+    content[2] = get_language_string(user, "NS_BANS_HEADER_TRIGGERED");
+    content[3] = (with_expire ? get_language_string(user, "NS_BANS_HEADER_EXPIRES") : NULL);
+    content[4] = get_language_string(user, "NS_BANS_HEADER_REASON");
+    table_change(table, 0, content);
+    char **table_lines = table_end(table);
+    for(i = 0; i < table->entrys; i++) {
+        reply(getTextBot(), user, table_lines[i]);
+    }
+    if(!cindex)
+        reply(getTextBot(), user, "NS_TABLE_NONE");
+    reply(getTextBot(), user, "NS_TABLE_COUNT", cindex);
+    table_free(table);
+}