summaryrefslogtreecommitdiff
path: root/microbbs.c
blob: 08f65c865384cd4d1b0416c3d6c97bae0aace287 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#define __MICROBBS_MAIN

#include <stdio.h>
#include <stdlib.h>


#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 "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
}