summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--art/motd.txt2
-rw-r--r--buildinfo.h2
-rw-r--r--captcha.c25
-rw-r--r--captcha.h5
-rw-r--r--libterm/print_utils.c122
-rw-r--r--libterm/print_utils.h13
-rw-r--r--libterm/screen_modes.c3
-rw-r--r--microbbs.c245
-rw-r--r--motd.c110
-rw-r--r--motd.h3
-rw-r--r--sysinfo.c21
11 files changed, 218 insertions, 333 deletions
diff --git a/art/motd.txt b/art/motd.txt
index 6fb310e..f2cb7b5 100644
--- a/art/motd.txt
+++ b/art/motd.txt
@@ -24,4 +24,4 @@
\__,_|_|_|\___/ \_/\_/ \___|\__,_(_)___/|_| \__, |
__/ |
|___/
-Source: ftp://bbs.hacking.allowed.org/microbbs-0.1.9.tar.gz
+Source: ftp://bbs.hacking.allowed.org/microbbs-0.2.1.tar.gz
diff --git a/buildinfo.h b/buildinfo.h
index 2d91704..ac59237 100644
--- a/buildinfo.h
+++ b/buildinfo.h
@@ -4,7 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
-#define BUILD_VERSION "0.2.0"
+#define BUILD_VERSION "0.2.1"
#define BUILD_DATE (__DATE__)
void print_build_info();
diff --git a/captcha.c b/captcha.c
index ad614be..97fc7d6 100644
--- a/captcha.c
+++ b/captcha.c
@@ -2,14 +2,31 @@
#ifdef CONFIG_CAPTCHA
-int captcha_test1()
+//ask question if you are bot or not will protect from simplest bots
+//or just any other automatic stuff
+//After captcha used amount of logs reduced, becouse 99% logs before where
+//generated by auto-bot-travelers
+int captcha_test1( term_screen *ts)
{
int ret = 0;
- char s[2];
+ const int s_size = 2;
+ char s[s_size];
+ int column, row;
+ int c;
+
+ //setup terminal output position
+ term_clr_scr( ts );
+ column = term_get_maxcol( ts );
+ row = term_get_maxrow( ts );
+ term_cur_set_c( ts, column/2 );
+ term_cur_set_r( ts, row/2 );
+
+ //just ask question
printf("Are you bot?(y/n):\n");
- fgets(s,2,stdin);
- if ( s[0] == 'n' || s[0] == 'N')
+ c = term_getc( ts );
+ if ( (c == 'n') || ( c == 'N') )
ret = 1;
+
return ret;
}
diff --git a/captcha.h b/captcha.h
index e2b71c0..7a2e948 100644
--- a/captcha.h
+++ b/captcha.h
@@ -6,13 +6,16 @@
#include "kconfig.h"
#include "logs.h"
+#include "debug.h"
+
+#include "libterm/term_io.h"
//ask question if you are bot or no. In 99% cases should protect from random
//bots.
// Return:
// 0 - test not passed
// 1 - test passed
-int captcha_test1();
+int captcha_test1( term_screen* );
diff --git a/libterm/print_utils.c b/libterm/print_utils.c
deleted file mode 100644
index 9d4bac0..0000000
--- a/libterm/print_utils.c
+++ /dev/null
@@ -1,122 +0,0 @@
-#include "print_utils.h"
-
-int term_fprint( screen_mode_e mode, FILE *f )
-{
- int ret=-1;
- if (f == NULL)
- return -1;
-
- switch ( mode )
- {
- case SCREEN_MODE_80x24:
- {
- /*
- const int m_x=80,m_y=24;
- int x=0,y=0;
- int fret=1;
- char c;
- while ((fret = fread(&c,1,1,f)) == 1)
- {
- if ( c != '\n' )
- {
- if ( (x < m_x) && (y < m_y) )
- {
- putc( c );
- }
- x+=1;
- } else if ( c == '\n' )
- {
- x = 0;
- y += 1;
- }
- }
- */
- }
- break;
- default:
- printf("Unknown screen mode\n");
- }
-
- return ret;
-}
-
-
-//print data to terminal starting from x,y
-//return 0x0000yyyy0000xxxx, current stopped position
-int term_print( term_screen *ts, const char *buf, size_t size,
- int init_x, int init_y )
-{
- int posx=0, posy=0;
- int ret=-1;
- if ( buf == NULL )
- {
- return -1;
- }
-
- if ( size <= 0 )
- {
- return -1;
- }
-
- //calculate position
- //fix for diff modes also needed
- if ( ts->term_col > 80)
- {
- posx = (ts->term_col-80)/2;
- }
- if (ts->term_row > 24)
- {
- posy = (ts->term_row-24)/2;
- }
-
- switch ( ts->mode )
- {
- case SCREEN_MODE_80x24:
- {
- int m_x=80, m_y=24;
- int x=init_x, y=init_y;
- char c;
- int i,j;
-
-
- if (( init_x == 0 ) && (init_y == 0))
- {
- for (i=0; i<posx;i++)
- printf(" ");
- }
-
- //draw image according to mode
- for (i=0; i<size; i++)
- {
- c = buf[i];
- if ( c == '\n' )
- {
- printf("\n");
- //set
- for (j=0; j<posx; j++)
- printf(" ");
- x = 0;
- y += 1;
- //printf("asdasdsad\n");
- } else if ( c != '\n' )
- {
- if ( (x < m_x ) && (y < m_y) )
- {
- printf("%c",c);
- }
- x += 1;
- }
- }
- ret = x&0x0000ffff | ((y&0x0000ffff)<<16);
- //printf( "%08x\n", ret );
- }
- break;
- default:
- printf("Unknown mode\n");
- }
-
- return ret;
-}
-
-
-
diff --git a/libterm/print_utils.h b/libterm/print_utils.h
deleted file mode 100644
index 6665262..0000000
--- a/libterm/print_utils.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef __LIBTERM_PRINT_UTILS_H
-#define __LIBTERM_PRINT_UTILS_H
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "screen_modes.h"
-#include "term.h"
-
-int term_fprint( screen_mode_e, FILE* );
-int term_print( term_screen*, const char*, size_t, int, int );
-
-#endif
diff --git a/libterm/screen_modes.c b/libterm/screen_modes.c
new file mode 100644
index 0000000..709b332
--- /dev/null
+++ b/libterm/screen_modes.c
@@ -0,0 +1,3 @@
+#include "screen_modes.h"
+
+
diff --git a/microbbs.c b/microbbs.c
index f620502..d0d03ba 100644
--- a/microbbs.c
+++ b/microbbs.c
@@ -5,24 +5,30 @@
#include "logs.h"
#include "motd.h"
#include "libterm/term.h"
+#include "libterm/term_io.h"
#include "ini.h"
int main( int argc, char **argv )
{
int ret_len;
+ int quit_main_menu = 0;
+ int column, row;
- size_t str_size=128;
- char *str=malloc(str_size);
+ int main_menu_input=0;
+ char main_menu_cmd;
term_screen ts;
term_init( &ts );
+ term_set_raw_mode( &ts );
term_clr_scr( &ts );
//lunch captcha and try to detect if its random bot
#ifdef CONFIG_CAPTCHA
- if ( captcha_test1() != 1)
- return 1;
+ if ( captcha_test1( ts ) != 1)
+ {
+ goto exit_restore_terminal;
+ }
bbs_log_captcha( NULL );
#endif
@@ -30,12 +36,20 @@ int main( int argc, char **argv )
//too much fake stuff comes to log
bbs_log_main( NULL ); //write to default place
#ifdef CONFIG_MOTD
- bbs_login_motd( NULL, "art/motd.txt" );
+ bbs_motd_draw( &ts, "art/motd.txt" );
+ sleep( 3 );
print_build_info();
#endif
- while ( strncmp( str, "q", 1 ) && strncmp( str, "Q", 1 ) )
+ 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_MOTD
printf("(M)otd ");
#endif
@@ -68,116 +82,127 @@ int main( int argc, char **argv )
printf("Mesa(G)es ");
#endif
- printf("(Q)uit (S)ysinfo: ");
- ret_len = getline( &str, &str_size, stdin );
- if ( ret_len > 0)
+ 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 )
{
- switch ( str[0] )
- {
- //------------------------------------------------------------------
- #ifdef CONFIG_MOTD
- case 'm':
- case 'M':
- {
- bbs_login_motd( &ts, "art/motd.txt" );
- }
- 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':
- {
- printf("Door games\n");
- }
- 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':
- {
- printf("Login?\n");
- }
- break;
- #endif
-
- //------------------------------------------------------------------
- #ifdef CONFIG_TODO
- case 'o':
- case 'O':
- {
- printf("Todo list\n");
- bbs_todo( &ts, NULL );
- }
- break;
- #endif
-
- //------------------------------------------------------------------
- case 'q':
- case 'Q':
- bbs_log_quit( NULL );
- break;
- default:
- printf("Unknow command\n");
- }
+ //------------------------------------------------------------------
+ #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':
+ {
+ printf("Door games\n");
+ }
+ 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':
+ {
+ printf("Login?\n");
+ }
+ 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_quit_motd( &ts, "art/quit.txt" );
+ bbs_motd_draw( &ts, "art/quit.txt" );
+ sleep( 3 );
#endif
+exit_restore_terminal:
term_clr_scr( &ts );
term_set_orig_mode( &ts );
return 0;
diff --git a/motd.c b/motd.c
index 8d11b3f..359834b 100644
--- a/motd.c
+++ b/motd.c
@@ -4,103 +4,55 @@
//TODO merge 2 functions in one proper
//TODO complcations with libterm
-int bbs_login_motd( term_screen *ts, const char *fname )
+int bbs_motd_draw( term_screen *ts, const char *fname )
{
- int posx=0, posy=0;
- int i;
- FILE *f = fopen( fname, "r" );
- if ( f == NULL )
- {
- printf("Cannot open file %s\n", fname);
- return -1;
- }
-
- int ret;
- const int buf_size=160;
+ int posc=0, posr=0;
+ int ret=0;
+ const int buf_size=80*25+1;
char buf[buf_size];
int x=0,y=0;
+ int row=0,column=0;
- if ( ts->term_row > 24 )
- {
- posy = (ts->term_row-24)/2;
- }
- for (i=0;i<posy;i++)
- printf("\n");
- ret = 1;
- while ( ret > 0 )
- {
- memset( buf, 0, buf_size );
- ret = fread( buf, 1, buf_size, f );
- if (ret > 0)
- {
- //printf("%d %d",x,y);
- x = term_print( ts, buf, ret, x, y );
- y = (x&0xffff0000)>>16;
- x = x&0x0000ffff;
- }
- }
- fclose( f );
-
- //printf("->posy=%d y=%d x=%d\n",posy,y,x);
- //printf("-->%d\n",ts->term_row-posy-(24-y));
- for (i=0;i<(ts->term_row-posy-y);i++)
- printf("\n");
- //for (i=0;i < ts->term_row-(ts->term_row-posy-24+y);i++)
- // printf("\n");
- //printf("%d\n",i);
-
- //printf("%d %d %d\n",y,posy,ts->term_row);
-
- return 0;
-}
-int bbs_quit_motd( term_screen *ts, const char *fname )
-{
- int posx=0, posy=0;
- int i;
FILE *f = fopen( fname, "r" );
if ( f == NULL )
{
printf("Cannot open file %s\n", fname);
return -1;
}
-
- int ret;
- const int buf_size=160;
- char buf[buf_size];
- int x=0,y=0;
- if ( ts->term_row > 24 )
- {
- posy = (ts->term_row-24)/2;
- }
- for (i=0;i<posy;i++)
- printf("\n");
- ret = 1;
- while ( ret > 0 )
+ term_clr_scr( ts );
+ row = term_get_maxrow( ts );
+ column = term_get_maxcol( ts );
+ term_cur_set_r( ts, ++posr );
+ term_cur_set_c( ts, 0 );
+
+ memset( buf, 0, buf_size );
+ ret = fread( buf, 1, buf_size, f );
+ if (ret > 0)
{
- memset( buf, 0, buf_size );
- ret = fread( buf, 1, buf_size, f );
- if (ret > 0)
{
- //printf("%d %d",x,y);
- x = term_print( ts, buf, ret, x, y );
- y = (x&0xffff0000)>>16;
- x = x&0x0000ffff;
+ int i=0;
+ while ( i < ret )
+ {
+ if ( buf[i] != '\n' )
+ {
+ printf("%c",buf[i] );
+ }
+ else if ( buf[i] == '\n')
+ {
+ posr += 1;
+ fflush( stdout );
+ term_cur_set_r( ts, posr );
+ term_cur_set_c( ts, 0 );
+ }
+ i++;
+ }
}
+
}
fclose( f );
- //printf("->posy=%d y=%d x=%d\n",posy,y,x);
- //printf("-->%d\n",ts->term_row-posy-(24-y));
- for (i=0;i<(ts->term_row-posy-y);i++)
- printf("\n");
- //for (i=0;i < ts->term_row-(ts->term_row-posy-24+y);i++)
- // printf("\n");
- //printf("%d\n",i);
-
- //printf("%d %d %d\n",y,posy,ts->term_row);
-
return 0;
}
diff --git a/motd.h b/motd.h
index 638612b..d116c1b 100644
--- a/motd.h
+++ b/motd.h
@@ -14,8 +14,7 @@
//get file name
//calculate current termsize and then print motd in da middle
-int bbs_login_motd( term_screen*, const char* );
-int bbs_quit_motd( term_screen*, const char* );
+int bbs_motd_draw( term_screen*, const char* );
#endif
diff --git a/sysinfo.c b/sysinfo.c
index 5d1eacb..72bd41b 100644
--- a/sysinfo.c
+++ b/sysinfo.c
@@ -4,11 +4,32 @@ int bbs_sysinfo( term_screen *ts )
{
int ret=0;
+ //setup screen to show stuff
+ term_clr_scr( ts );
+
+ printf("Press ANYKEY \n\n\n");
+
+ term_cur_set_c( ts, 0 );
printf("BBS:MicroBBS %s (%s)\n", BUILD_VERSION, BUILD_DATE);
+
+ term_cur_set_c( ts, 0 );
printf("Author: FreeArtMan\n");
+
+ term_cur_set_c( ts, 0 );
printf("Contributor: epoch\n");
+
+ term_cur_set_c( ts, 0 );
+ printf("Main chan: irc://irc.freenode.net#mainlv\n");
+
+ term_cur_set_c( ts, 0 );
printf("Ideological support: irc://hacking.allowed.org#default\n");
+ //main loop wait while press something
+ term_cur_set_r( ts, term_get_maxrow( ts ) );
+ term_cur_set_c( ts, 0 );
+ printf(":"); fflush( stdout );
+ term_getc( ts );
+
return ret;
}