#define __MICROBBS_MAIN #include #include #include "kconfig.h" #include "logs.h" #include "motd.h" #include "sysinfo.h" #include "articles.h" #include "user.h" #include "bbsconfig.h" #include "twit.h" #include "todo.h" #include "door.h" #include "captcha.h" #include "netbytes.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; //set default config values config_default(); //setting up terminal term_screen ts; memset( (void *)&ts, 0, sizeof(ts) ); term_init( &ts ); term_set_raw_mode( &ts ); term_set_speed( &ts, B38400 ); 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 ) term_printf( &ts, "[LOGEDIN] "); #endif #ifdef CONFIG_MOTD term_printf( &ts, "(M)otd "); #endif #ifdef CONFIG_ARTICLES term_printf( &ts, "(A)rticles "); #endif #ifdef CONFIG_DOORGAMES term_printf( &ts, "(D)oor games "); #endif #ifdef CONFIG_TWIT term_printf( &ts, "(T)wit "); #endif #ifdef CONFIG_BOARD term_printf( &ts, "(B)oard "); #endif #ifdef CONFIG_LOGIN if ( bbs_user_get_status( &g_user ) != BBS_USER_LOGEDIN ) term_printf( &ts, "(L)ogin "); #endif #ifdef CONFIG_TODO term_printf( &ts, "T(o)do "); #endif #ifdef CONFIG_MESSAGING term_printf( &ts, "Mesa(G)es "); #endif term_printf( &ts, "(Q)uit (S)ysinfo"); term_cur_set_c( &ts, 0 ); term_cur_set_r( &ts, term_get_maxrow( &ts ) ); term_printf( &ts, ":"); //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, g_config.article_dir ); } break; #endif //------------------------------------------------------------------ #ifdef CONFIG_TWIT case 't': case 'T': { //printf("Twitter like\n"); bbs_twit( &ts, NULL ); } break; #endif //------------------------------------------------------------------ #ifdef CONFIG_DOORGAMES case 'd': case 'D': { bbs_door( &ts, NULL ); } break; #endif //------------------------------------------------------------------ #ifndef CONFIG_MESSAGING case 'g': case 'G': { term_printf( &ts, "Messages\n"); } break; #endif //------------------------------------------------------------------ #ifdef CONFIG_BOARD case 'b': case 'B': { term_printf( &ts, "Board\n"); } break; #endif //------------------------------------------------------------------ #ifdef CONFIG_LOGIN case 'l': case 'L': { bbs_login( &ts ); } break; #endif //------------------------------------------------------------------ #ifdef CONFIG_TODO case 'o': case 'O': { term_printf( &ts, "Todo list\n"); bbs_todo( &ts, NULL ); } break; #endif //------------------------------------------------------------------ case 'q': case 'Q': quit_main_menu = 1; bbs_log_quit( NULL ); break; default: term_printf( &ts, "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 }