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