tried to reorder the program structure and build process
[NeonServV5.git] / src / cmd_neonserv_oplog.c
diff --git a/src/cmd_neonserv_oplog.c b/src/cmd_neonserv_oplog.c
new file mode 100644 (file)
index 0000000..a69c449
--- /dev/null
@@ -0,0 +1,41 @@
+
+#include "cmd_neonserv.h"
+
+/*
+* argv[0]     time
+* argv[1-*]   match
+*/
+
+CMD_BIND(neonserv_cmd_oplog) {
+    char *str_match;
+    int duration = (argc ? strToTime(user, argv[0]) : 0);
+    if(argc > (duration ? 1 : 0))
+        str_match = merge_argv(argv, (duration ? 1 : 0), argc);
+    else
+        str_match = "";
+    if(!duration) duration = (60*60*24);
+    MYSQL_RES *res;
+    MYSQL_ROW row;
+    printf_mysql_query("SELECT `godlog_time`, `user_user`, `channel_name`, `godlog_cmd` FROM `godlog` LEFT JOIN `channels` ON `godlog_cid` = `channel_id` LEFT JOIN `users` ON `godlog_uid` = `user_id` WHERE `godlog_time` > '%lu' ORDER BY `godlog_time` ASC", ((unsigned long) time(0) - duration));
+    res = mysql_use();
+    int skip = mysql_num_rows(res) - 100;
+    int count = 0;
+    char timeBuf[50];
+    struct tm *timeinfo;
+    time_t event_time;
+    if(skip < 0) skip = 0;
+    reply(getTextBot(), user, "NS_EVENTS_HEADER");
+    while ((row = mysql_fetch_row(res)) != NULL) {
+        if(skip) {
+            skip--;
+            continue;
+        }
+        if(*str_match && match(str_match, row[3])) continue;
+        count++;
+        event_time = (time_t) atol(row[0]);
+        timeinfo = localtime(&event_time);
+        strftime(timeBuf, 80, "%X %x", timeinfo);
+        reply(getTextBot(), user, "[%s] [%s%s%s]: %s", timeBuf, row[1], (row[2] ? ":" : ""), (row[2] ? row[2] : ""), row[3]);
+    }
+    reply(getTextBot(), user, "NS_TABLE_COUNT", count);
+}