Added User List, added times on stat

This commit is contained in:
Andrew Pamment 2016-03-23 16:31:00 +10:00
parent e7161ab489
commit 7d1b75c29a
6 changed files with 104 additions and 10 deletions

15
ansis/doors.ans Normal file
View File

@ -0,0 +1,15 @@
[?7h
 ワワワワワワ ワワワワワワワ ワワワワワワワ ワワワワワワ ワワワワワワワ ワワワワワワ ワワワワワワワワワワワ ワワワワワワワ ワワワワワワワ
イ゚ワ イロイ゚ワ ロイイ゚ワ ロイロローワ イロイ゚ワワワワ イ゚ー イロイ゚ーワ イ゚ーワ イロイ゚ワワ ゚゚ イロワワワワワ
アロ ゚ワアロ ーイワ゚ イ ーイワ゚ イ イイ イ ー゚アロワ ア゚ーイ゚゚゚ア゚ーイ イ ーイ イ ア゚アイワー イ゚ワワ イ゚
゚゚゚゚゚゚ー ゚゚゚゚゚゚ ゚゚゚゚゚゚ ゚゚ーー゚゚゚゚゚゚ ゚゚ ゚ ーロ ゚゚ ゚ ゚゚ ゚ ーロ ゚゚゚゚゚゚ ゚゚゚゚゚゚ー
トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト
0. Example Doorウウ
ウウ
ウウ
ウウ
ウウ
ウ Q. Quit to Main Menuウ
ウ G. Goodbye (Log Off)ウ
トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト


View File

@ -4,10 +4,10 @@
ーイ イ ーイ イ ア゚ーイ゚゚゚ア゚イイ ーイ イ ア゚ーイ イ ーイ イ ア゚アイワー イ゚ーイ イ ア゚ーイワ゚ イ 
゚゚ ゚ ゚゚ ゚ ーロ ゚゚ ゚ ーロ ゚゚ ゚゚ ゚ ーロ ゚゚ ゚ ゚゚ ゚ ーロ ゚゚゚゚゚゚ ゚゚ ゚ ーロ ゚゚゚゚゚゚
トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト
³ M. Message Areas³ L. BBS List³
³ T. File Areas³ C. Chat System³
³ M. Message Areas³ L. BBS List³
³ T. File Areas³ C. Chat System³
B. Bulletinsウ U. User Listウ
³ O. Online Games³ 1. Last 10 Callers³
³ D. Online Games³ 1. Last 10 Callers³
ウウ
ウウ
ウ G. Goodbye (Log Off)ウ

2
bbs.c
View File

@ -551,7 +551,7 @@ void runbbs(int socket, char *config_path) {
save_user(user);
}
gUser = user;
user->timeson++;
// bulletins
i = 0;
sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i);

3
bbs.h
View File

@ -73,6 +73,7 @@ struct user_record {
int cur_mail_area;
int cur_file_dir;
int cur_file_sub;
int timeson;
};
@ -92,7 +93,7 @@ extern int save_user(struct user_record *user);
extern int check_user(char *loginname);
extern struct user_record *new_user(int socket);
extern struct user_record *check_user_pass(int socket, char *loginname, char *password);
extern void list_users(int socket, struct user_record *user);
extern void main_menu(int socket, struct user_record *user);

View File

@ -1,6 +1,7 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <sys/stat.h>
#include "bbs.h"
extern struct bbs_config conf;
@ -9,7 +10,9 @@ void main_menu(int socket, struct user_record *user) {
int doquit = 0;
char c;
char prompt[128];
char buffer[256];
int i;
struct stat s;
while (!doquit) {
s_displayansi(socket, "mainmenu");
@ -20,6 +23,27 @@ void main_menu(int socket, struct user_record *user) {
c = s_getc(socket);
switch(tolower(c)) {
case 'u':
{
list_users(socket, user);
}
break;
case 'b':
{
i = 0;
sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i);
while (stat(buffer, &s) == 0) {
sprintf(buffer, "bulletin%d", i);
s_displayansi(socket, buffer);
sprintf(buffer, "Press any key to continue...\r\n");
s_putstring(socket, buffer);
s_getc(socket);
i++;
sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i);
}
}
break;
case '1':
{
display_last10_callers(socket, user, 0);

62
users.c
View File

@ -28,7 +28,7 @@ int save_user(struct user_record *user) {
int rc;
char *update_sql = "UPDATE users SET password=?, firstname=?,"
"lastname=?, email=?, location=?, sec_level=?, last_on=?, time_left=?, cur_mail_conf=?, cur_mail_area=?, cur_file_dir=?, cur_file_sub=? where loginname LIKE ?";
"lastname=?, email=?, location=?, sec_level=?, last_on=?, time_left=?, cur_mail_conf=?, cur_mail_area=?, cur_file_dir=?, cur_file_sub=?, times_on=? where loginname LIKE ?";
char *err_msg = 0;
sprintf(buffer, "%s/users.sq3", conf.bbs_path);
@ -57,7 +57,8 @@ int save_user(struct user_record *user) {
sqlite3_bind_int(res, 10, user->cur_mail_area);
sqlite3_bind_int(res, 11, user->cur_file_dir);
sqlite3_bind_int(res, 12, user->cur_file_sub);
sqlite3_bind_text(res, 13, user->loginname, -1, 0);
sqlite3_bind_int(res, 13, user->timeson);
sqlite3_bind_text(res, 14, user->loginname, -1, 0);
} else {
fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db));
}
@ -95,10 +96,11 @@ int inst_user(struct user_record *user) {
"cur_mail_conf INTEGER,"
"cur_mail_area INTEGER,"
"cur_file_sub INTEGER,"
"cur_file_dir INTEGER);";
"cur_file_dir INTEGER,"
"times_on INTEGER);";
char *insert_sql = "INSERT INTO users (loginname, password, firstname,"
"lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub) VALUES(?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
"lastname, email, location, sec_level, last_on, time_left, cur_mail_conf, cur_mail_area, cur_file_dir, cur_file_sub, times_on) VALUES(?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
char *err_msg = 0;
sprintf(buffer, "%s/users.sq3", conf.bbs_path);
@ -139,6 +141,7 @@ int inst_user(struct user_record *user) {
sqlite3_bind_int(res, 11, user->cur_mail_area);
sqlite3_bind_int(res, 12, user->cur_file_dir);
sqlite3_bind_int(res, 13, user->cur_file_sub);
sqlite3_bind_int(res, 14, user->timeson);
} else {
fprintf(stderr, "Failed to execute statement: %s\n", sqlite3_errmsg(db));
@ -206,6 +209,7 @@ struct user_record *check_user_pass(int socket, char *loginname, char *password)
user->cur_mail_area = sqlite3_column_int(res, 11);
user->cur_file_dir = sqlite3_column_int(res, 12);
user->cur_file_sub = sqlite3_column_int(res, 13);
user->timeson = sqlite3_column_int(res, 14);
if (strcmp(password, user->password) != 0) {
free(user);
@ -233,6 +237,55 @@ struct user_record *check_user_pass(int socket, char *loginname, char *password)
return user;
}
void list_users(int socket, struct user_record *user) {
char buffer[256];
sqlite3 *db;
sqlite3_stmt *res;
int rc;
int i;
char *sql = "SELECT loginname,location,times_on FROM users";
sprintf(buffer, "%s/users.sq3", conf.bbs_path);
rc = sqlite3_open(buffer, &db);
if (rc != SQLITE_OK) {
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
rc = sqlite3_prepare_v2(db, sql, -1, &res, 0);
if (rc != SQLITE_OK) {
fprintf(stderr, "Cannot prepare statement: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
s_putstring(socket, "\r\n\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
s_putstring(socket, "User Name Location Times On\r\n");
s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
i = 0;
while (sqlite3_step(res) == SQLITE_ROW) {
sprintf(buffer, "\e[1;37m%-16s \e[1;36m%-32s \e[1;32m%5d\r\n", sqlite3_column_text(res, 0), sqlite3_column_text(res, 1), sqlite3_column_int(res, 2));
s_putstring(socket, buffer);
i++;
if (i == 20) {
sprintf(buffer, "Press any key to continue...\r\n");
s_putstring(socket, buffer);
s_getc(socket);
i = 0;
}
}
s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n");
sqlite3_finalize(res);
sqlite3_close(db);
sprintf(buffer, "Press any key to continue...\r\n");
s_putstring(socket, buffer);
s_getc(socket);
}
int check_user(char *loginname) {
char buffer[256];
sqlite3 *db;
@ -392,6 +445,7 @@ struct user_record *new_user(int socket) {
user->cur_file_sub = 0;
user->cur_mail_area = 0;
user->cur_mail_conf = 0;
user->timeson = 0;
inst_user(user);
return user;