diff --git a/ansis_default/filemenu.ans b/ansis_default/filemenu.ans index 2683292..c02246c 100644 Binary files a/ansis_default/filemenu.ans and b/ansis_default/filemenu.ans differ diff --git a/magicka.strings b/magicka.strings index f3cff48..a68b4be 100644 --- a/magicka.strings +++ b/magicka.strings @@ -229,3 +229,5 @@ File exists!\r\n \e[1;31mUNSUB\e[0m \r\n\e[1;37mAre you sure you want to reset all messages in %s to unread? \e[0m \r\n\e[1;37mAre you sure you want to reset \e[1;31mall messages \e[1;37min all bases to unread? \e[0m +\r\n\r\n\e[1;30m[\e[1;34m%3d\e[1;30m] \e[1;33m%3ddloads \e[1;36m%4d%c \e[1;37m%-56s\r\n \e[1;31mNEW \e[0;32m +\r\nScan for new files? (Y/N) : diff --git a/menus_default/file.mnu b/menus_default/file.mnu index f2c212e..0bb4014 100644 --- a/menus_default/file.mnu +++ b/menus_default/file.mnu @@ -31,6 +31,9 @@ COMMAND NEXTFILESUB HOTKEY [ COMMAND PREVFILESUB +HOTKEY ! +COMMAND FILESCAN + HOTKEY Q COMMAND PREVMENU diff --git a/scripts_examples/login_stanza.lua b/scripts_examples/login_stanza.lua index a16c69a..69a72bc 100644 --- a/scripts_examples/login_stanza.lua +++ b/scripts_examples/login_stanza.lua @@ -82,6 +82,8 @@ end bbs_mail_scan(); +bbs_file_scan(); + -- Display Auto Message bbs_display_automsg(); diff --git a/src/bbs.c b/src/bbs.c index 9b19f03..5def274 100644 --- a/src/bbs.c +++ b/src/bbs.c @@ -30,6 +30,7 @@ int gSocket; int sshBBS; int usertimeout; int timeoutpaused; +time_t userlaston; char *ipaddress = NULL; @@ -856,6 +857,8 @@ tryagain: localtime_r(&now, &thetime); localtime_r(&user->laston, &oldtime); + userlaston = user->laston; + if (thetime.tm_mday != oldtime.tm_mday || thetime.tm_mon != oldtime.tm_mon || thetime.tm_year != oldtime.tm_year) { user->timeleft = user->sec_info->timeperday; user->laston = now; @@ -902,6 +905,8 @@ tryagain: mail_scan(user); + file_scan(); + automessage_display(); } record_last10_callers(user); diff --git a/src/bbs.h b/src/bbs.h index 2092357..10c0ae8 100644 --- a/src/bbs.h +++ b/src/bbs.h @@ -310,6 +310,7 @@ extern void next_file_dir(struct user_record *user); extern void prev_file_dir(struct user_record *user); extern void next_file_sub(struct user_record *user); extern void prev_file_sub(struct user_record *user); +extern void file_scan(); extern void lua_push_cfunctions(lua_State *L); extern void do_lua_script(char *script); diff --git a/src/files.c b/src/files.c index cb7d8de..bac0d6d 100644 --- a/src/files.c +++ b/src/files.c @@ -23,12 +23,15 @@ extern int mynode; extern int bbs_stdin; extern int bbs_stdout; extern int bbs_stderr; +extern time_t userlaston; +extern struct user_record *gUser; struct file_entry { char *filename; char *description; int size; int dlcount; + time_t uploaddate; }; char **tagged_files; @@ -851,8 +854,8 @@ void download(struct user_record *user) { } void list_files(struct user_record *user) { - char *sql = "select filename, description, size, dlcount from files where approved=1"; - char buffer[256]; + char *sql = "select filename, description, size, dlcount, uploaddate from files where approved=1"; + char buffer[PATH_MAX]; sqlite3 *db; sqlite3_stmt *res; int rc; @@ -868,7 +871,7 @@ void list_files(struct user_record *user) { struct file_entry **files_e; - sprintf(buffer, "%s/%s.sq3", conf.bbs_path, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->database); + snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->database); rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { @@ -901,7 +904,7 @@ void list_files(struct user_record *user) { files_e[files_c]->description = strdup((char *)sqlite3_column_text(res, 1)); files_e[files_c]->size = sqlite3_column_int(res, 2); files_e[files_c]->dlcount = sqlite3_column_int(res, 3); - + files_e[files_c]->uploaddate = sqlite3_column_int(res, 4); files_c++; } sqlite3_finalize(res); @@ -926,7 +929,11 @@ void list_files(struct user_record *user) { } else { file_unit = 'b'; } - s_printf(get_string(69), i, files_e[i]->dlcount, file_size, file_unit, basename(files_e[i]->filename)); + if (files_e[i]->uploaddate > userlaston) { + s_printf(get_string(231), i, files_e[i]->dlcount, file_size, file_unit, basename(files_e[i]->filename)); + } else { + s_printf(get_string(69), i, files_e[i]->dlcount, file_size, file_unit, basename(files_e[i]->filename)); + } lines+=3; for (j=0;jdescription);j++) { if (files_e[i]->description[j] == '\n') { @@ -1193,3 +1200,69 @@ void prev_file_sub(struct user_record *user) { user->cur_file_sub = i - 1; } +void file_scan() { + char c; + int i; + int j; + char buffer[PATH_MAX]; + char sql[] = "SELECT COUNT(*) FROM files WHERE uploaddate > ?"; + int rc; + sqlite3 *db; + sqlite3_stmt *res; + int new_files; + int lines = 0; + + s_printf(get_string(232)); + c = s_getc(); + + if (tolower(c) == 'y') { + for (i=0;isec_level > gUser->sec_level) { + continue; + } + s_printf(get_string(140), i, conf.file_directories[i]->name); + lines += 2; + if (lines == 22) { + s_printf(get_string(6)); + s_getc(); + lines = 0; + } + for (j=0;jfile_sub_count;j++) { + if (conf.file_directories[i]->file_subs[j]->download_sec_level > gUser->sec_level) { + continue; + } + snprintf(buffer, PATH_MAX, "%s/%s.sq3", conf.bbs_path, conf.file_directories[i]->file_subs[j]->database); + rc = sqlite3_open(buffer, &db); + if (rc != SQLITE_OK) { + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + sqlite3_close(db); + + exit(1); + } + sqlite3_busy_timeout(db, 5000); + rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); + + if (rc != SQLITE_OK) { + sqlite3_finalize(res); + sqlite3_close(db); + continue; + } + sqlite3_bind_int(res, 1, userlaston); + + if (sqlite3_step(res) != SQLITE_ERROR) { + new_files = sqlite3_column_int(res, 0); + s_printf(get_string(141), j, conf.file_directories[i]->file_subs[j]->name, new_files); + lines++; + } + sqlite3_finalize(res); + sqlite3_close(db); + + if (lines == 22) { + s_printf(get_string(6)); + s_getc(); + lines = 0; + } + } + } + } +} diff --git a/src/lua_glue.c b/src/lua_glue.c index 1b40996..39417b7 100644 --- a/src/lua_glue.c +++ b/src/lua_glue.c @@ -108,6 +108,11 @@ int l_bbsMailScan(lua_State *L) { return 0; } +int l_bbsFileScan(lua_State *L) { + file_scan(); + return 0; +} + int l_bbsRunDoor(lua_State *L) { char *cmd = (char *)lua_tostring(L, 1); int stdio = lua_toboolean(L, 2); @@ -192,6 +197,8 @@ void lua_push_cfunctions(lua_State *L) { lua_setglobal(L, "bbs_display_automsg"); lua_pushcfunction(L, l_getBBSInfo); lua_setglobal(L, "bbs_get_info"); + lua_pushcfunction(L, l_bbsFileScan); + lua_setglobal(L, "bbs_file_scan"); } void do_lua_script(char *script) { diff --git a/src/menus.c b/src/menus.c index 73855b4..9dbdd04 100644 --- a/src/menus.c +++ b/src/menus.c @@ -49,6 +49,7 @@ #define MENU_SUBUNSUBCONF 39 #define MENU_RESETPOINTERS 40 #define MENU_RESETALLPOINTERS 41 +#define MENU_FILESCAN 42 extern struct bbs_config conf; extern struct user_record *gUser; @@ -197,6 +198,8 @@ int menu_system(char *menufile) { menu[menu_items-1]->command = MENU_RESETPOINTERS; } else if (strncasecmp(&buffer[8], "RESETALLMSGPTRS", 15) == 0) { menu[menu_items-1]->command = MENU_RESETALLPOINTERS; + } else if (strncasecmp(&buffer[8], "FILESCAN", 8) == 0) { + menu[menu_items-1]->command = MENU_FILESCAN; } } else if (strncasecmp(buffer, "SECLEVEL", 8) == 0) { menu[menu_items-1]->seclevel = atoi(&buffer[9]); @@ -495,6 +498,9 @@ int menu_system(char *menufile) { msgbase_reset_all_pointers(); } break; + case MENU_FILESCAN: + file_scan(); + break; default: break; }