From b94dbb4fa1ae3ab2cecaf76748f3ced536ee021d Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Sun, 10 Apr 2016 18:45:02 +1000 Subject: [PATCH] Added Settings Menu --- Makefile | 2 +- ansis_default/mainmenu.ans | 2 +- bbs.h | 3 ++ main_menu.c | 5 ++++ settings.c | 60 ++++++++++++++++++++++++++++++++++++++ users.c | 5 ++++ 6 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 settings.c diff --git a/Makefile b/Makefile index db2f0b4..fc82665 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ DEPS = bbs.h JAMLIB = jamlib/jamlib.a ZMODEM = Xmodem/libzmodem.a -OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o +OBJ = inih/ini.o bbs.o main.o users.o main_menu.o mail_menu.o doors.o bbs_list.o chat_system.o email.o files.o settings.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/ansis_default/mainmenu.ans b/ansis_default/mainmenu.ans index 758414e..119b429 100644 --- a/ansis_default/mainmenu.ans +++ b/ansis_default/mainmenu.ans @@ -8,7 +8,7 @@ ³ T. File Transfer Area³ C. Chat System³ ³ B. Bulletins³ U. User List³ ³ D. Door Games & Utilites³ 1. Last 10 Callers³ - ³ A. Text/ANSI File Collection ³³ + ³ A. Text/ANSI File Collection ³ S. Your Settings³ ³³³ ³³ G. Goodbye (Log Off)³ ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ diff --git a/bbs.h b/bbs.h index a6419f9..9a832c4 100644 --- a/bbs.h +++ b/bbs.h @@ -137,6 +137,7 @@ extern void s_putstring(int socket, char *c); extern void s_displayansi_p(int socket, char *file); extern void s_displayansi(int socket, char *file); extern char s_getchar(int socket); +extern void s_readpass(int socket, char *buffer, int max); extern void s_readstring(int socket, char *buffer, int max); extern char s_getc(int socket); extern void disconnect(int socket); @@ -168,4 +169,6 @@ extern void send_email(int socket, struct user_record *user); extern void list_emails(int socket, struct user_record *user); extern int file_menu(int socket, struct user_record *user); + +extern void settings_menu(int sock, struct user_record *user); #endif diff --git a/main_menu.c b/main_menu.c index e612900..e08c6e3 100644 --- a/main_menu.c +++ b/main_menu.c @@ -119,6 +119,11 @@ void main_menu(int socket, struct user_record *user) { doquit = file_menu(socket, user); } break; + case 's': + { + settings_menu(socket, user); + } + break; } } } diff --git a/settings.c b/settings.c new file mode 100644 index 0000000..e569836 --- /dev/null +++ b/settings.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include "bbs.h" + +void settings_menu(int sock, struct user_record *user) { + char buffer[256]; + int dosettings = 0; + char c; + + while (!dosettings) { + s_putstring(sock, "\e[1;32mYour Settings\r\n"); + s_putstring(sock, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); + s_putstring(sock, "\e[0;36mP. \e[1;37mPassword (\e[1;33mNot Shown\e[1;37m)\r\n"); + sprintf(buffer, "\e[0;36mL. \e[1;37mLocation (\e[1;33m%s\e[1;37m)\r\n", user->location); + s_putstring(sock, buffer); + s_putstring(sock, "\e[0;36mQ. \e[1;37mQuit to Main Menu\r\n"); + s_putstring(sock, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); + + c = s_getc(sock); + + switch(tolower(c)) { + case 'p': + { + s_putstring(sock, "\r\nEnter your current password: "); + s_readpass(sock, buffer, 16); + if (strcmp(buffer, user->password) == 0) { + s_putstring(sock, "\r\nEnter your new password (8 chars min): "); + s_readstring(sock, buffer, 16); + if (strlen(buffer) >= 8) { + free(user->password); + user->password = (char *)malloc(strlen(buffer) + 1); + strcpy(user->password, buffer); + save_user(user); + s_putstring(sock, "\r\nPassword Changed!\r\n"); + } else { + s_putstring(sock, "\r\nPassword too short!\r\n"); + } + } else { + s_putstring(sock, "\r\nPassword Incorrect!\r\n"); + } + } + break; + case 'l': + { + s_putstring(sock, "\r\nEnter your new location: "); + s_readstring(sock, buffer, 32); + free(user->location); + user->location = (char *)malloc(strlen(buffer) + 1); + strcpy(user->location, buffer); + save_user(user); + } + break; + case 'q': + dosettings = 1; + break; + } + } +} diff --git a/users.c b/users.c index 6e9d406..045714d 100644 --- a/users.c +++ b/users.c @@ -213,6 +213,11 @@ struct user_record *check_user_pass(int socket, char *loginname, char *password) user->timeson = sqlite3_column_int(res, 14); if (strcmp(password, user->password) != 0) { + free(user->loginname); + free(user->firstname); + free(user->lastname); + free(user->email); + free(user->location); free(user); sqlite3_finalize(res); sqlite3_close(db);