{"NS_USER_PROTECTED", "Sorry, \002%s\002 is protected."},
{"NS_SERVICE_IMMUNE", "\002%s\002 may not be kicked, killed, banned, or deopped."},
{"NS_TABLE_NONE", " None"},
+ {"NS_TABLE_COUNT", "Found \002%d\002 matches."},
{"NS_BAN_ALREADY_ADDED", "\002%s\002 is already banned in %s."},
{"NS_INVALID_ACCESS_RANGE", "Invalid access range; minimum (%d) must be lower than maximum (%d)."},
{"NS_CLVL_DONE", "%s now has access \002%d\002 in %s."},
{"NS_SET_TRIGGER_OWNER", "You must have access 500 in %s to change the channel trigger."},
{"NS_WIPEINFO_DONE", "Removed \002%s\002's infoline in \002%s\002."},
{"NS_TRACE_HEADER", "The following users were found:"},
- {"NS_TRACE_FOUND", "Found \002%d\002 matches."},
{"NS_ADDBAN_DONE", "\002%s\002 permantly added to the %s ban list. (matching %d users)"},
+ {"NS_BANS_HEADER_MASK", "Mask"},
+ {"NS_BANS_HEADER_SETBY", "Set By"},
+ {"NS_BANS_HEADER_TRIGGERED", "Triggered"},
+ {"NS_BANS_HEADER_EXPIRES", "Expires"},
+ {"NS_BANS_HEADER_REASON", "Reason"},
{NULL, NULL}
};
#include "cmd_neonserv_addban.c"
//#include "cmd_neonserv_addtimeban.c"
//#include "cmd_neonserv_delban.c"
-//#include "cmd_neonserv_banlist.c"
+#include "cmd_neonserv_bans.c"
//#include "cmd_neonserv_open.c"
//#include "cmd_neonserv_topic.c"
//#include "cmd_neonserv_mode.c"
register_command(BOTID, "ban", neonserv_cmd_ban, 1, CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH, "#channel_canban", 0);
register_command(BOTID, "wipeinfo", neonserv_cmd_wipeinfo, 1, CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH, "#channel_wipeinfo", 0);
register_command(BOTID, "addban", neonserv_cmd_addban, 1, CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH, "#channel_staticban", 0);
+ register_command(BOTID, "bans", neonserv_cmd_bans, 0, CMDFLAG_REQUIRE_CHAN | CMDFLAG_REGISTERED_CHAN | CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH, "1", 0);
register_command(BOTID, "trace", neonserv_cmd_trace, 1, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH, NULL, 400);
--- /dev/null
+
+/*
+* argv[0] (optional) mask
+*/
+static 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, (time(0) - atoi(row[3])), 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);
+}
reply(getTextBot(), user, "%s!%s@%s %s", cuser->nick, cuser->ident, cuser->host, ((cuser->flags & USERFLAG_ISAUTHED) ? cuser->auth : "*"));
}
}
- reply(getTextBot(), user, "NS_TRACE_FOUND", matches);
+ reply(getTextBot(), user, "NS_TABLE_COUNT", matches);
}
int col;
if(table->entrys == table->length) return 0;
for(col = 0; col < table->width; col++) {
- table->contents[table->entrys][col] = ((table->flags & TABLE_FLAG_USE_POINTER) ? entry[col] : strdup(entry[col]));
- if(strlen(entry[col]) > table->maxwidth[col])
+ table->contents[table->entrys][col] = ((table->flags & TABLE_FLAG_USE_POINTER) || !entry[col] ? entry[col] : strdup(entry[col]));
+ if(table->contents[table->entrys][col])
+ table->col_flags[col] |= TABLE_FLAG_COL_CONTENTS;
+ if(entry[col] && strlen(entry[col]) > table->maxwidth[col])
table->maxwidth[col] = strlen(entry[col]);
}
table->entrys++;
return 1;
}
+int table_change(struct Table *table, int row, char **entry) {
+ int col;
+ if(row >= table->length) return 0;
+ for(col = 0; col < table->width; col++) {
+ if(table->contents[row][col] && !(table->flags & TABLE_FLAG_USE_POINTER))
+ free(table->contents[row][col]);
+ table->contents[row][col] = ((table->flags & TABLE_FLAG_USE_POINTER) || !entry[col] ? entry[col] : strdup(entry[col]));
+ if(table->contents[row][col])
+ table->col_flags[col] |= TABLE_FLAG_COL_CONTENTS;
+ if(entry[col] && strlen(entry[col]) > table->maxwidth[col])
+ table->maxwidth[col] = strlen(entry[col]);
+ }
+ return 1;
+}
+
+int table_change_field(struct Table *table, int row, int col, char *entry) {
+ if(row >= table->length) return 0;
+ if(col >= table->width) return 0;
+ if(table->contents[row][col] && !(table->flags & TABLE_FLAG_USE_POINTER))
+ free(table->contents[row][col]);
+ table->contents[row][col] = (((table->flags & TABLE_FLAG_USE_POINTER) || !entry) ? entry : strdup(entry));
+ if(table->contents[row][col])
+ table->col_flags[col] |= TABLE_FLAG_COL_CONTENTS;
+ if(entry && strlen(entry) > table->maxwidth[col])
+ table->maxwidth[col] = strlen(entry);
+ return 1;
+}
+
int table_set_bold(struct Table *table, int collum, int bold) {
if(bold)
table->col_flags[collum] |= TABLE_FLAG_COL_BOLD;
table->table_lines[row] = malloc(tablewidth * sizeof(*table->table_lines[row]));
pos = 0;
for(col = 0; col < table->width; col++) {
+ if(!(table->col_flags[col] & TABLE_FLAG_COL_CONTENTS)) continue;
if(table->col_flags[col] & TABLE_FLAG_COL_BOLD)
table->table_lines[row][pos++] = '\002';
for(i = 0; i < strlen(table->contents[row][col]); i++) {
for(row = 0; row < table->length; row++) {
if(!(table->flags & TABLE_FLAG_USE_POINTER) && table->entrys > row) {
for(col = 0; col < table->width; col++) {
- free(table->contents[row][col]);
+ if(table->contents[row][col])
+ free(table->contents[row][col]);
}
}
free(table->contents[row]);
#include "main.h"
-#define TABLE_FLAG_USE_POINTER 0x01
-#define TABLE_FLAG_COL_BOLD 0x02
+#define TABLE_FLAG_USE_POINTER 0x01
+#define TABLE_FLAG_COL_BOLD 0x02
+#define TABLE_FLAG_COL_CONTENTS 0x04
struct ClientSocket;
struct UserNode;
struct Table *table_init(int width, int length, int flags);
int table_add(struct Table *table, char **entry);
+int table_change(struct Table *table, int row, char **entry);
+int table_change_field(struct Table *table, int row, int col, char *entry);
int table_set_bold(struct Table *table, int collum, int bold);
char **table_end(struct Table *table);
void table_free(struct Table *table);