a69c449651d0271205536ebc2eccf9f28504ee93
[NeonServV5.git] / cmd_neonserv_oplog.c
1
2 #include "cmd_neonserv.h"
3
4 /*
5 * argv[0]     time
6 * argv[1-*]   match
7 */
8
9 CMD_BIND(neonserv_cmd_oplog) {
10     char *str_match;
11     int duration = (argc ? strToTime(user, argv[0]) : 0);
12     if(argc > (duration ? 1 : 0))
13         str_match = merge_argv(argv, (duration ? 1 : 0), argc);
14     else
15         str_match = "";
16     if(!duration) duration = (60*60*24);
17     MYSQL_RES *res;
18     MYSQL_ROW row;
19     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));
20     res = mysql_use();
21     int skip = mysql_num_rows(res) - 100;
22     int count = 0;
23     char timeBuf[50];
24     struct tm *timeinfo;
25     time_t event_time;
26     if(skip < 0) skip = 0;
27     reply(getTextBot(), user, "NS_EVENTS_HEADER");
28     while ((row = mysql_fetch_row(res)) != NULL) {
29         if(skip) {
30             skip--;
31             continue;
32         }
33         if(*str_match && match(str_match, row[3])) continue;
34         count++;
35         event_time = (time_t) atol(row[0]);
36         timeinfo = localtime(&event_time);
37         strftime(timeBuf, 80, "%X %x", timeinfo);
38         reply(getTextBot(), user, "[%s] [%s%s%s]: %s", timeBuf, row[1], (row[2] ? ":" : ""), (row[2] ? row[2] : ""), row[3]);
39     }
40     reply(getTextBot(), user, "NS_TABLE_COUNT", count);
41 }