#define __MICROBBS_MAIN #include #include #include "kconfig.h" #include "logs.h" #include "motd.h" #include "sysinfo.h" #include "articles.h" #include "user.h" #include "libterm/term.h" #include "libterm/term_io.h" #include "ini.h" int main( int argc, char **argv ) { int quit_main_menu = 0; int main_menu_input=0; char main_menu_cmd; term_screen ts; memset( (void *)&ts, 0, sizeof(ts) ); term_init( &ts ); term_set_raw_mode( &ts ); term_clr_scr( &ts ); //init global variable of bbs user #ifdef CONFIG_LOGIN bbs_user_init( &g_user ); #endif //lunch captcha and try to detect if its random bot #ifdef CONFIG_CAPTCHA if ( captcha_test1( ts ) != 1) { goto exit_restore_terminal; } bbs_log_captcha( NULL ); #endif //write to log that some user have accesed bbs //too much fake stuff comes to log bbs_log_main( NULL ); //write to default place #ifdef CONFIG_MOTD bbs_motd_draw( &ts, "art/motd.txt" ); sleep( 3 ); print_build_info(); #endif while ( quit_main_menu == 0 ) { //prepare screen for main menu output term_clr_scr( &ts ); //column = term_cur_pos_c( &ts ); //row = term_cur_pos_r( &ts ); term_cur_set_r( &ts, 0 ); term_cur_set_c( &ts, 0 ); #ifdef CONFIG_LOGIN if ( bbs_user_get_status( &g_user ) == BBS_USER_LOGEDIN ) printf("[LOGEDIN] "); #endif #ifdef CONFIG_MOTD printf("(M)otd "); #endif #ifdef CONFIG_ARTICLES printf("(A)rticles "); #endif #ifdef CONFIG_DOORGAMES printf("(D)oor games "); #endif #ifdef CONFIG_TWIT printf("(T)wit "); #endif #ifdef CONFIG_BOARD printf("(B)oard "); #endif #ifdef CONFIG_LOGIN if ( bbs_user_get_status( &g_user ) != BBS_USER_LOGEDIN ) printf("(L)ogin "); #endif #ifdef CONFIG_TODO printf("T(o)do "); #endif #ifdef CONFIG_MESSAGING printf("Mesa(G)es "); #endif printf("(Q)uit (S)ysinfo"); fflush( stdout ); term_cur_set_c( &ts, 0 ); term_cur_set_r( &ts, term_get_maxrow( &ts ) ); printf(":"); fflush( stdout ); //ret_len = getline( &str, &str_size, stdin ); main_menu_input = term_getc( &ts ); //if something whent wrong dont know why, need to get some test case if ( main_menu_input == -1 ) continue; main_menu_cmd = (char)main_menu_input; switch ( main_menu_cmd ) { //------------------------------------------------------------------ #ifdef CONFIG_MOTD case 'm': case 'M': { bbs_motd_draw( &ts, "art/motd.txt" ); sleep( 3 ); } break; #endif //------------------------------------------------------------------ case 's': case 'S': { bbs_sysinfo( &ts ); } break; //------------------------------------------------------------------ #ifdef CONFIG_ARTICLES case 'a': case 'A': { bbs_article_list( &ts, "./article/" ); } break; #endif //------------------------------------------------------------------ #ifdef CONFIG_TWIT case 't': case 'T': { printf("Twitter like\n"); } break; #endif //------------------------------------------------------------------ #ifdef CONFIG_DOORGAMES case 'd': case 'D': { bbs_door( &ts, NULL ); } break; #endif //------------------------------------------------------------------ #ifndef CONFIG_MESSAGING case 'g': case 'G': { printf("Messages\n"); } break; #endif //------------------------------------------------------------------ #ifdef CONFIG_BOARD case 'b': case 'B': { printf("Board\n"); } break; #endif //------------------------------------------------------------------ #ifdef CONFIG_LOGIN case 'l': case 'L': { bbs_login( &ts ); } break; #endif //------------------------------------------------------------------ #ifdef CONFIG_TODO case 'o': case 'O': { printf("Todo list\n"); bbs_todo( &ts, NULL ); } break; #endif //------------------------------------------------------------------ case 'q': case 'Q': quit_main_menu = 1; bbs_log_quit( NULL ); break; default: printf("Unknow command\n"); } } #ifdef CONFIG_MOTD bbs_motd_draw( &ts, "art/quit.txt" ); sleep( 3 ); #endif exit_restore_terminal: term_clr_scr( &ts ); term_set_orig_mode( &ts ); return 0; goto exit_restore_terminal; // if some flags used points that label not used }