Added Settings Menu

This commit is contained in:
Andrew Pamment 2016-04-10 18:45:02 +10:00
parent fc970f3d25
commit b94dbb4fa1
6 changed files with 75 additions and 2 deletions

View File

@ -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)

View File

@ -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)³
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

3
bbs.h
View File

@ -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

View File

@ -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;
}
}
}

60
settings.c Normal file
View File

@ -0,0 +1,60 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#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;
}
}
}

View File

@ -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);