summaryrefslogtreecommitdiff
path: root/microbbs.c
blob: 3d4d09409265b9d427c3936a99210cdc51c2db74 (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
#include <stdio.h>
#include <stdlib.h>

#include "kconfig.h"
#include "logs.h"
#include "motd.h"
#include "sysinfo.h"
#include "articles.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 );

	//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_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
		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':
				{
					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_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
}