diff options
author | FreeArtMan <dos21h@gmail.com> | 2015-01-10 15:10:43 +0900 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2015-01-10 15:10:43 +0900 |
commit | bd040d066dc5ba642c4fadca26ddd4e1963e5231 (patch) | |
tree | 47ee71980b1e8fdef4f3fad7cb869f1b91e97deb | |
parent | 3e61314544a9151cb5a49db12a58c4fb74d6bee3 (diff) | |
download | microbbs-bd040d066dc5ba642c4fadca26ddd4e1963e5231.tar.gz microbbs-bd040d066dc5ba642c4fadca26ddd4e1963e5231.zip |
Added door game support upto 9 games
-rw-r--r-- | articles.c | 2 | ||||
-rw-r--r-- | buildinfo.h | 2 | ||||
-rw-r--r-- | door.c | 205 | ||||
-rw-r--r-- | door.h | 24 | ||||
-rw-r--r-- | kconfig.h | 2 | ||||
-rw-r--r-- | microbbs.c | 2 | ||||
-rw-r--r-- | todo.c | 10 |
7 files changed, 242 insertions, 5 deletions
@@ -214,7 +214,7 @@ int bbs_article_list( term_screen *ts, const char *dir_name ) //while there is no more 10 articles use only 1 number //TODO fix that term_cur_set_c( ts, 0 ); - printf("Input article number 0-9:"); fflush( stdout ); + printf("Input article number 1-9:"); fflush( stdout ); int article_input = term_getc( ts ); //if something whent wrong dont know why, need to get some test case char article_number = (char)article_input-'0'; diff --git a/buildinfo.h b/buildinfo.h index ac59237..03b99d9 100644 --- a/buildinfo.h +++ b/buildinfo.h @@ -4,7 +4,7 @@ #include <stdio.h> #include <stdlib.h> -#define BUILD_VERSION "0.2.1" +#define BUILD_VERSION "0.2.2" #define BUILD_DATE (__DATE__) void print_build_info(); @@ -0,0 +1,205 @@ +#include "door.h" + +#ifdef CONFIG_DOORGAMES + + + +//just for full fill libc example +static int dir_door_game_selector (const struct dirent *unused) +{ + return 1; +} + +int bbs_door_start( term_screen *ts, const char *cmd ) +{ + int ret=0; + + int restore_mode=1; + + struct termios orig_i; + struct termios orig_o; + + term_clr_scr( ts ); + + //if ( tcgetattr( ts->ifd, &orig_i ) == -1 ) restore_mode = 0; + //if ( tcgetattr( ts->ofd, &orig_o ) == -1 ) restore_mode = 0; + + tcsetattr( ts->ifd, TCSAFLUSH, &ts->orig_i ); + //tcsetattr( ts->ofd, TCSAFLUSH, &ts->orig_o ); + + //term_clr_scr( ts ); + if ( system( cmd ) == -1 ) + { + bbs_log( NULL, "couldnt execute %s", cmd ); + } + + if ( restore_mode ) + { + tcsetattr( ts->ifd, TCSAFLUSH, &ts->raw_i ); + //tcsetattr( ts->ofd, TCSAFLUSH, &orig_o ); + } + + + return ret; +} + +int bbs_door( term_screen *ts, const char *dir_name ) +{ + int ret=0; + + int quit_loop=0; + int menu_input = 0; + char menu_cmd = 0; + int row = 0; + const char *door_game_dir=NULL; + + if ( ts == NULL ) + return ret; + + + if ( dir_name == NULL ) + { + door_game_dir = CONFIG_DOOR_DEFAULT_DIR; + } else + { + door_game_dir = dir_name; + } + + //list dir + struct stat path_node; + struct dirent **eps; + int n; + + //get all articles names in list and use list every time needed + List *dir_list = llist_new(); + + bbs_log_article_list( NULL ); + + if ( door_game_dir != NULL ) + { + //should have some bugs be carefull + n = scandir( door_game_dir, &eps, dir_door_game_selector, alphasort ); + if ( n >= 0) + { + int cnt; + for ( cnt=0; cnt<n; cnt++) + { + sds d_name = sds_new( eps[cnt]->d_name ); + sds pathname = sds_new( door_game_dir ); + sds_cat( pathname, d_name ); + + //check if its file + term_cur_set_c( ts, 0 ); + if ( stat( pathname, &path_node ) == 0 ) + { + if ( (path_node.st_mode & S_IFREG) && (path_node.st_mode & 0111) ) + { + llist_push( dir_list, pathname ); + } else + { + sds_free( pathname ); + sds_free( d_name ); + } + } else + { + sds_free( pathname ); + sds_free( d_name ); + } + free( eps[cnt] ); + } + free( eps ); + } else + { + printf("Err\n"); + ERROR("Cannot open article directory\n"); + } + ret = 0; + } + + while( (quit_loop == 0) ) + { + term_clr_scr( ts ); + term_cur_set_c( ts, 0 ); + printf("(L)ist games, (P)lay game, (Q)uit"); fflush( stdout ); + + + term_cur_set_c( ts, 0 ); + term_cur_set_r( ts, term_get_maxrow( ts ) ); + printf(":"); fflush( stdout ); + + menu_input = term_getc( ts ); + //if something whent wrong dont know why, need to get some test case + if ( menu_input == -1 ) + { + term_cur_set_c( ts, 0 ); + ERROR("Cannot read char"); + sleep(1); + continue; + } + menu_cmd = (char)menu_input; + + switch( menu_cmd ) + { + case 'q': + case 'Q': + quit_loop = 1; + break; + + case 'l': + case 'L': + { + term_cur_set_c( ts, 0 ); + term_cur_set_r( ts, 2 ); + //print list of executables + struct ListNode *iter=dir_list->first; + int cnt = 1; + while (iter != NULL) + { + term_cur_set_c( ts, 0 ); + printf( "[%02d] %s\n", cnt, (char *)iter->val); + cnt += 1; + iter = iter->next; + } + term_cur_set_c( ts, 0 ); + term_print( ts, "Press ANYKEY\n", 13); + term_getc( ts ); + } + break; + case 'p': + case 'P': + { + term_cur_set_c( ts, 0 ); + printf("Input game number 1-9:"); fflush( stdout ); + int game_input = term_getc( ts ); + //if something whent wrong dont know why, need to get some test case + char game_number = (char)game_input-'0'; + + if ( game_number > 0 && game_number < 10) + { + struct ListNode *iter = dir_list->first; + int cnt = 1; + while ( iter != NULL ) + { + if ( cnt == game_number ) + { + bbs_door_start( ts, iter->val ); + break; + } + cnt += 1; + iter = iter->next; + } + } + } + break; + default: + printf("Try more\n"); + } + } + + //needed special care to free sds strings + //llist_free( dir_list ); + + return ret; +} + +#endif
\ No newline at end of file @@ -0,0 +1,24 @@ +#ifndef __MICROBBS_DOOR_H +#define __MICROBBS_DOOR_H + +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <dirent.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <fcntl.h> +#include <termios.h> + + +#include "kconfig.h" +#include "list.h" +#include "sds.h" + +#include "libterm/term.h" +#include "libterm/term_io.h" + +int bbs_door( term_screen *ts, const char *dir_name ); + +#endif
\ No newline at end of file @@ -2,6 +2,8 @@ #define __KCONFIG_H #define CONFIG_TODO #define CONFIG_TODO_DEFAULT_FILE "todo/todo.txt" +#define CONFIG_DOORGAMES +#define CONFIG_DOOR_DEFAULT_DIR "./door/" #define CONFIG_ARTICLES #define CONFIG_MOTD #define CONFIG_CAPTCHA @@ -140,7 +140,7 @@ int main( int argc, char **argv ) case 'd': case 'D': { - printf("Door games\n"); + bbs_door( &ts, NULL ); } break; #endif @@ -13,17 +13,23 @@ int bbs_todo( term_screen *ts, const char *fname) int menu_input = 0; char menu_cmd = 0; int row = 0; + char *todo_fname = NULL; if ( ts == NULL ) return ret; if ( fname == NULL ) - fname = CONFIG_TODO_DEFAULT_FILE; + { + todo_fname = CONFIG_TODO_DEFAULT_FILE; + } else + { + todo_fname = fname; + } //LOAD DATA FROM FILE TO LINKED LIST List *todo_list = llist_new(); - f_file *file = f_file_open( fname, F_FILE_READ ); + f_file *file = f_file_open( todo_fname, F_FILE_READ ); if ( file != NULL ) { const int l_s = 128; |