From 1370a10fed1fa87e5fb234042a42f2b53d83ddd7 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Sat, 6 Aug 2016 14:36:36 +1000 Subject: [PATCH] Major refactoring --- ansis_default/mailmenu.ans | Bin 2022 -> 2157 bytes bbs.c | 234 +++++++++++++------------- bbs.h | 59 +++---- bbs_list.c | 127 +++++++------- chat_system.c | 117 +++++++------ doors.c | 43 +++-- email.c | 125 +++++++------- files.c | 138 ++++++++------- lua_glue.c | 14 +- mail_menu.c | 333 +++++++++++++++++-------------------- main_menu.c | 65 ++++---- settings.c | 35 ++-- users.c | 155 +++++++++-------- 13 files changed, 694 insertions(+), 751 deletions(-) diff --git a/ansis_default/mailmenu.ans b/ansis_default/mailmenu.ans index cd2621c86ec175ec726643bf8a31291025d2ce60..ce962b5870ab35f58eb853ede2b63061d55e1588 100644 GIT binary patch delta 167 zcmaFH|5jkb0#+^qYh$xq7wKq2>&eSll{tW%03auK^LbWrrh2Jh$53Zi0|N!>0V4xL jGXo0)(>Lr442+Bc3_=WGAnfVns}Sby2;o6VCI$uoXoVY| delta 30 kcmaDW@Qi=M0#-I-vs@SH=*g>CmDvofft-NNS6RiG0HTlyfdBvi diff --git a/bbs.c b/bbs.c index 08d89b4..cf07292 100644 --- a/bbs.c +++ b/bbs.c @@ -44,12 +44,12 @@ void dolog(char *fmt, ...) { dolog("Error opening log file!"); return; } - va_list ap; - va_start(ap, fmt); - vsnprintf(buffer, 512, fmt, ap); - va_end(ap); + va_list ap; + va_start(ap, fmt); + vsnprintf(buffer, 512, fmt, ap); + va_end(ap); - fprintf(logfptr, "%02d:%02d:%02d [%s] %s\n", time_now.tm_hour, time_now.tm_min, time_now.tm_sec, ipaddress, buffer); + fprintf(logfptr, "%02d:%02d:%02d [%s] %s\n", time_now.tm_hour, time_now.tm_min, time_now.tm_sec, ipaddress, buffer); fclose(logfptr); } @@ -117,8 +117,8 @@ void timer_handler(int signum) { gUser->timeleft--; if (gUser->timeleft <= 0) { - s_putstring(gSocket, "\r\n\r\nSorry, you're out of time today..\r\n"); - disconnect(gSocket, "Out of Time"); + s_printf("\r\n\r\nSorry, you're out of time today..\r\n"); + disconnect("Out of Time"); } @@ -127,21 +127,32 @@ void timer_handler(int signum) { usertimeout--; } if (usertimeout <= 0) { - s_putstring(gSocket, "\r\n\r\nTimeout waiting for input..\r\n"); - disconnect(gSocket, "Timeout"); + s_printf("\r\n\r\nTimeout waiting for input..\r\n"); + disconnect("Timeout"); } } } -void s_putchar(int socket, char c) { - write(socket, &c, 1); +void s_printf(char *fmt, ...) { + char buffer[512]; + + va_list ap; + va_start(ap, fmt); + vsnprintf(buffer, 512, fmt, ap); + va_end(ap); + + s_putstring(buffer); +} + +void s_putchar(char c) { + write(gSocket, &c, 1); } -void s_putstring(int socket, char *c) { - write(socket, c, strlen(c)); +void s_putstring(char *c) { + write(gSocket, c, strlen(c)); } -void s_displayansi_p(int socket, char *file) { +void s_displayansi_p(char *file) { FILE *fptr; char c; @@ -151,14 +162,14 @@ void s_displayansi_p(int socket, char *file) { } c = fgetc(fptr); while (!feof(fptr) && c != 0x1a) { - s_putchar(socket, c); + s_putchar(c); c = fgetc(fptr); } fclose(fptr); } -void s_displayansi(int socket, char *file) { +void s_displayansi(char *file) { FILE *fptr; char c; @@ -172,39 +183,39 @@ void s_displayansi(int socket, char *file) { } c = fgetc(fptr); while (!feof(fptr) && c != 0x1a) { - s_putchar(socket, c); + s_putchar(c); c = fgetc(fptr); } fclose(fptr); } -char s_getchar(int socket) { +char s_getchar() { unsigned char c; int len; do { - len = read(socket, &c, 1); + len = read(gSocket, &c, 1); if (len == 0) { - disconnect(socket, "Socket Closed"); + disconnect("Socket Closed"); } while (c == 255) { - len = read(socket, &c, 1); + len = read(gSocket, &c, 1); if (len == 0) { - disconnect(socket, "Socket Closed"); + disconnect("Socket Closed"); } else if (c == 255) { usertimeout = 10; return c; } - len = read(socket, &c, 1); + len = read(gSocket, &c, 1); if (len == 0) { - disconnect(socket, "Socket Closed"); + disconnect("Socket Closed"); } - len = read(socket, &c, 1); + len = read(gSocket, &c, 1); if (len == 0) { - disconnect(socket, "Socket Closed"); + disconnect("Socket Closed"); } } @@ -212,7 +223,7 @@ char s_getchar(int socket) { if (c == '\r') { if (len == 0) { - disconnect(socket, "Socket Closed"); + disconnect("Socket Closed"); } } } while (c == '\n'); @@ -220,25 +231,25 @@ char s_getchar(int socket) { return (char)c; } -char s_getc(int socket) { - char c = s_getchar(socket); +char s_getc() { + char c = s_getchar(); - s_putchar(socket, c); + s_putchar(c); return (char)c; } -void s_readstring(int socket, char *buffer, int max) { +void s_readstring(char *buffer, int max) { int i; char c; memset(buffer, 0, max); for (i=0;i 0) { buffer[i-1] = '\0'; i -= 2; - s_putstring(socket, "\e[D \e[D"); + s_printf("\e[D \e[D"); continue; } else if (c == '\b' || c == 127) { i -= 1; @@ -248,23 +259,23 @@ void s_readstring(int socket, char *buffer, int max) { if (c == '\n' || c == '\r') { return; } - s_putchar(socket, c); + s_putchar(c); buffer[i] = c; buffer[i+1] = '\0'; } } -void s_readpass(int socket, char *buffer, int max) { +void s_readpass(char *buffer, int max) { int i; char c; for (i=0;i 0) { buffer[i-1] = '\0'; i-=2; - s_putstring(socket, "\e[D \e[D"); + s_printf("\e[D \e[D"); continue; } else if (c == '\b' || c == 127) { i -= 1; @@ -274,13 +285,13 @@ void s_readpass(int socket, char *buffer, int max) { if (c == '\n' || c == '\r') { return; } - s_putchar(socket, '*'); + s_putchar('*'); buffer[i] = c; buffer[i+1] = '\0'; } } -void disconnect(int socket, char *calledby) { +void disconnect(char *calledby) { char buffer[256]; if (gUser != NULL) { save_user(gUser); @@ -288,7 +299,7 @@ void disconnect(int socket, char *calledby) { dolog("Node %d disconnected (%s)", mynode, calledby); sprintf(buffer, "%s/nodeinuse.%d", conf.bbs_path, mynode); remove(buffer); - close(socket); + close(gSocket); exit(0); } @@ -332,16 +343,15 @@ void record_last10_callers(struct user_record *user) { } } -void display_last10_callers(int socket, struct user_record *user) { +void display_last10_callers(struct user_record *user) { struct last10_callers callers[10]; int i,z,j; - char buffer[256]; - struct tm l10_time; + struct tm l10_time; FILE *fptr = fopen("last10.dat", "rb"); - s_putstring(socket, "\r\n\e[1;37mLast 10 callers:\r\n"); - s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\r\n"); + s_printf("\r\n\e[1;37mLast 10 callers:\r\n"); + s_printf("\e[1;30m-------------------------------------------------------------------------------\r\n"); if (fptr != NULL) { @@ -358,53 +368,41 @@ void display_last10_callers(int socket, struct user_record *user) { for (z=0;zsec_level >= conf.automsgwritelvl) { timen = time(NULL); @@ -414,11 +412,10 @@ void automessage_write(int socket, struct user_record *user) { automsg[strlen(automsg) - 1] = '\r'; automsg[strlen(automsg)] = '\n'; - s_putstring(socket, "\r\nEnter your message (4 lines):\r\n"); + s_printf("\r\nEnter your message (4 lines):\r\n"); for (i=0;i<4;i++) { - sprintf(buffer, "\r\n%d: ", i); - s_putstring(socket, buffer); - s_readstring(socket, buffer, 75); + s_printf("\r\n%d: ", i); + s_readstring(buffer, 75); strcat(automsg, buffer); strcat(automsg, "\r\n"); } @@ -433,12 +430,12 @@ void automessage_write(int socket, struct user_record *user) { } } -void automessage_display(int socket) { +void automessage_display() { struct stat s; FILE *fptr; char buffer[90]; int i; - s_putstring(socket, "\r\n\r\n"); + s_printf("\r\n\r\n"); if (stat("automessage.txt", &s) == 0) { fptr = fopen("automessage.txt", "r"); if (fptr) { @@ -448,17 +445,17 @@ void automessage_display(int socket) { buffer[strlen(buffer) - 1] = '\r'; buffer[strlen(buffer)] = '\n'; - s_putstring(socket, buffer); + s_printf(buffer); } fclose(fptr); } else { dolog("Error opening automessage.txt"); } } else { - s_putstring(socket, "No automessage!\r\n"); + s_printf("No automessage!\r\n"); } - s_putstring(socket, "\e[0mPress any key to continue...\r\n"); - s_getc(socket); + s_printf("\e[0mPress any key to continue...\r\n"); + s_getc(); } void runbbs(int socket, char *ip) { @@ -484,11 +481,11 @@ void runbbs(int socket, char *ip) { write(socket, iac_echo, 3); write(socket, iac_sga, 3); + gUser = NULL; + gSocket = socket; - - sprintf(buffer, "Magicka BBS v%d.%d (%s), Loading...\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_STR); - s_putstring(socket, buffer); - + s_printf("Magicka BBS v%d.%d (%s), Loading...\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_STR); + // find out which node we are mynode = 0; for (i=1;i<=conf.nodes;i++) { @@ -510,12 +507,11 @@ void runbbs(int socket, char *ip) { } if (mynode == 0) { - s_putstring(socket, "Sorry, all nodes are in use. Please try later\r\n"); + s_printf("Sorry, all nodes are in use. Please try later\r\n"); close(socket); exit(1); } - gUser = NULL; - gSocket = socket; + usertimeout = 10; timeoutpaused = 0; @@ -531,22 +527,22 @@ void runbbs(int socket, char *ip) { setitimer (ITIMER_REAL, &itime, 0); - s_displayansi(socket, "issue"); + s_displayansi("issue"); - s_putstring(socket, "\e[0mEnter your Login Name or NEW to create an account\r\n"); - s_putstring(socket, "Login:> "); + s_printf("\e[0mEnter your Login Name or NEW to create an account\r\n"); + s_printf("Login:> "); - s_readstring(socket, buffer, 25); + s_readstring(buffer, 25); if (strcasecmp(buffer, "new") == 0) { - user = new_user(socket); + user = new_user(); } else { - s_putstring(socket, "\r\nPassword:> "); - s_readpass(socket, password, 16); - user = check_user_pass(socket, buffer, password); + s_printf("\r\nPassword:> "); + s_readpass(password, 16); + user = check_user_pass(buffer, password); if (user == NULL) { - s_putstring(socket, "\r\nIncorrect Login.\r\n"); - disconnect(socket, "Incorrect Login"); + s_printf("\r\nIncorrect Login.\r\n"); + disconnect("Incorrect Login"); } for (i=1;i<=conf.nodes;i++) { @@ -555,14 +551,14 @@ void runbbs(int socket, char *ip) { nodefile = fopen(buffer, "r"); if (!nodefile) { dolog("Error opening nodefile!"); - disconnect(socket, "Error opening nodefile!"); + disconnect("Error opening nodefile!"); } fgets(buffer, 256, nodefile); if (strcasecmp(user->loginname, buffer) == 0) { fclose(nodefile); - s_putstring(socket, "\r\nYou are already logged in.\r\n"); - disconnect(socket, "Already Logged in"); + s_printf("\r\nYou are already logged in.\r\n"); + disconnect("Already Logged in"); } fclose(nodefile); } @@ -621,10 +617,9 @@ void runbbs(int socket, char *ip) { while (stat(buffer, &s) == 0) { sprintf(buffer, "bulletin%d", i); - s_displayansi(socket, buffer); - sprintf(buffer, "\e[0mPress any key to continue...\r\n"); - s_putstring(socket, buffer); - s_getc(socket); + s_displayansi(buffer); + s_printf("\e[0mPress any key to continue...\r\n"); + s_getc(); i++; sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i); } @@ -632,28 +627,27 @@ void runbbs(int socket, char *ip) { // external login cmd // display info - display_info(socket); + display_info(); - display_last10_callers(socket, user); + display_last10_callers(user); // check email i = mail_getemailcount(user); if (i > 0) { - sprintf(buffer, "\r\nYou have %d e-mail(s) in your inbox.\r\n", i); - s_putstring(socket, buffer); + s_printf("\r\nYou have %d e-mail(s) in your inbox.\r\n", i); } else { - s_putstring(socket, "\r\nYou have no e-mail.\r\n"); + s_printf("\r\nYou have no e-mail.\r\n"); } - mail_scan(socket, user); + mail_scan(user); - automessage_display(socket); + automessage_display(); } record_last10_callers(user); // main menu - main_menu(socket, user); + main_menu(user); - s_displayansi(socket, "goodbye"); + s_displayansi("goodbye"); dolog("%s is logging out, on node %d", user->loginname, mynode); - disconnect(socket, "Log out"); + disconnect("Log out"); } diff --git a/bbs.h b/bbs.h index 729a363..9a057bc 100644 --- a/bbs.h +++ b/bbs.h @@ -136,52 +136,53 @@ struct user_record { int timeson; }; -extern void automessage_write(int socket, struct user_record *user); -extern void automessage_display(int socket); +extern void automessage_write(struct user_record *user); +extern void automessage_display(); extern void dolog(char *fmt, ...); extern void runbbs(int sock, char *ipaddress); extern struct fido_addr *parse_fido_addr(const char *str); -extern void s_putchar(int socket, char c); -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, char *calledby); -extern void display_info(int socket); -extern void display_last10_callers(int socket, struct user_record *user); +extern void s_putchar(char c); +extern void s_printf(char *fmt, ...); +extern void s_putstring(char *c); +extern void s_displayansi_p(char *file); +extern void s_displayansi(char *file); +extern char s_getchar(); +extern void s_readpass(char *buffer, int max); +extern void s_readstring(char *buffer, int max); +extern char s_getc(); +extern void disconnect(char *calledby); +extern void display_info(); +extern void display_last10_callers(struct user_record *user); extern void gen_salt(char **s); extern char *hash_sha256(char *pass, char *salt); 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 struct user_record *new_user(); +extern struct user_record *check_user_pass(char *loginname, char *password); +extern void list_users(struct user_record *user); -extern void main_menu(int socket, struct user_record *user); +extern void main_menu(struct user_record *user); -extern void mail_scan(int socket, struct user_record *user); -extern int mail_menu(int socket, struct user_record *user); -extern char *editor(int socket, struct user_record *user, char *quote, char *from, int email); -extern char *external_editor(int socket, struct user_record *user, char *to, char *from, char *quote, char *qfrom, char *subject, int email); +extern void mail_scan(struct user_record *user); +extern int mail_menu(struct user_record *user); +extern char *editor(struct user_record *user, char *quote, char *from, int email); +extern char *external_editor(struct user_record *user, char *to, char *from, char *quote, char *qfrom, char *subject, int email); -extern int door_menu(int socket, struct user_record *user); -extern void rundoor(int socket, struct user_record *user, char *cmd, int stdio); +extern int door_menu(struct user_record *user); +extern void rundoor(struct user_record *user, char *cmd, int stdio); -extern void bbs_list(int socket, struct user_record *user); +extern void bbs_list(struct user_record *user); -extern void chat_system(int sock, struct user_record *user); +extern void chat_system(struct user_record *user); extern int mail_getemailcount(struct user_record *user); -extern void send_email(int socket, struct user_record *user); -extern void list_emails(int socket, struct user_record *user); +extern void send_email(struct user_record *user); +extern void list_emails(struct user_record *user); -extern int file_menu(int socket, struct user_record *user); +extern int file_menu(struct user_record *user); -extern void settings_menu(int sock, struct user_record *user); +extern void settings_menu(struct user_record *user); extern void lua_push_cfunctions(lua_State *L); #endif diff --git a/bbs_list.c b/bbs_list.c index 7b7dcb8..5a3a78a 100644 --- a/bbs_list.c +++ b/bbs_list.c @@ -8,7 +8,7 @@ extern struct bbs_config conf; extern int mynode; -void add_bbs(int socket, struct user_record *user) { +void add_bbs(struct user_record *user) { char *create_sql = "CREATE TABLE IF NOT EXISTS bbslist (" "id INTEGER PRIMARY KEY," "bbsname TEXT," @@ -28,27 +28,24 @@ void add_bbs(int socket, struct user_record *user) { sqlite3_stmt *res; int rc; - s_putstring(socket, "\r\n\e[1;37mEnter the BBS Name: \e[0m"); - s_readstring(socket, bbsname, 18); + s_printf("\r\n\e[1;37mEnter the BBS Name: \e[0m"); + s_readstring(bbsname, 18); - s_putstring(socket, "\r\n\e[1;37mEnter the Sysop's Name: \e[0m"); - s_readstring(socket, sysop, 16); + s_printf("\r\n\e[1;37mEnter the Sysop's Name: \e[0m"); + s_readstring(sysop, 16); - s_putstring(socket, "\r\n\e[1;37mEnter the Telnet URL: \e[0m"); - s_readstring(socket, telnet, 38); + s_printf("\r\n\e[1;37mEnter the Telnet URL: \e[0m"); + s_readstring(telnet, 38); - s_putstring(socket, "\r\nYou entered:\r\n"); - s_putstring(socket, "\e[1;30m----------------------------------------------\e[0m\r\n"); - sprintf(buffer, "\e[1;37mBBS Name: \e[1;32m%s\r\n", bbsname); - s_putstring(socket, buffer); - sprintf(buffer, "\e[1;37mSysop: \e[1;32m%s\r\n", sysop); - s_putstring(socket, buffer); - sprintf(buffer, "\e[1;37mTelnet URL: \e[1;32m%s\r\n", telnet); - s_putstring(socket, buffer); - s_putstring(socket, "\e[1;30m----------------------------------------------\e[0m\r\n"); - s_putstring(socket, "Is this correct? (Y/N) :"); + s_printf("\r\nYou entered:\r\n"); + s_printf("\e[1;30m----------------------------------------------\e[0m\r\n"); + s_printf("\e[1;37mBBS Name: \e[1;32m%s\r\n", bbsname); + s_printf("\e[1;37mSysop: \e[1;32m%s\r\n", sysop); + s_printf("\e[1;37mTelnet URL: \e[1;32m%s\r\n", telnet); + s_printf("\e[1;30m----------------------------------------------\e[0m\r\n"); + s_printf("Is this correct? (Y/N) :"); - c = s_getc(socket); + c = s_getc(); if (tolower(c) == 'y') { sprintf(buffer, "%s/bbslist.sq3", conf.bbs_path); @@ -96,79 +93,78 @@ void add_bbs(int socket, struct user_record *user) { } sqlite3_finalize(res); sqlite3_close(db); - s_putstring(socket, "\r\n\e[1;32mAdded!\e[0m\r\n"); + s_printf("\r\n\e[1;32mAdded!\e[0m\r\n"); } else { - s_putstring(socket, "\r\n\e[1;31mAborted!\e[0m\r\n"); + s_printf("\r\n\e[1;31mAborted!\e[0m\r\n"); } } -void delete_bbs(int socket, struct user_record *user) { +void delete_bbs(struct user_record *user) { char buffer[256]; sqlite3 *db; - sqlite3_stmt *res; - int rc; - char *sql = "SELECT bbsname FROM bbslist WHERE id=? and owner=?"; - char *dsql = "DELETE FROM bbslist WHERE id=?"; - int i; - char c; + sqlite3_stmt *res; + int rc; + char *sql = "SELECT bbsname FROM bbslist WHERE id=? and owner=?"; + char *dsql = "DELETE FROM bbslist WHERE id=?"; + int i; + char c; - s_putstring(socket, "\r\nPlease enter the id of the BBS you want to delete: "); - s_readstring(socket, buffer, 5); - i = atoi(buffer); + s_printf("\r\nPlease enter the id of the BBS you want to delete: "); + s_readstring(buffer, 5); + i = atoi(buffer); - sprintf(buffer, "%s/bbslist.sq3", conf.bbs_path); + sprintf(buffer, "%s/bbslist.sq3", conf.bbs_path); - rc = sqlite3_open(buffer, &db); + rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { return; } - rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); + rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); if (rc == SQLITE_OK) { sqlite3_bind_int(res, 1, i); sqlite3_bind_int(res, 2, user->id); } else { sqlite3_close(db); - s_putstring(socket, "\r\nThere are no BBSes in the list yet!\r\n"); + s_printf("\r\nThere are no BBSes in the list yet!\r\n"); return; } if (sqlite3_step(res) == SQLITE_ROW) { - sprintf(buffer, "\r\nAre you sure you want to delete %s?\r\n", sqlite3_column_text(res, 0)); - s_putstring(socket, buffer); + s_printf("\r\nAre you sure you want to delete %s?\r\n", sqlite3_column_text(res, 0)); sqlite3_finalize(res); - c = s_getc(socket); + c = s_getc(); if (tolower(c) == 'y') { rc = sqlite3_prepare_v2(db, dsql, -1, &res, 0); if (rc == SQLITE_OK) { sqlite3_bind_int(res, 1, i); } else { sqlite3_close(db); - s_putstring(socket, "\r\nThere are no BBSes in the list yet!\r\n"); + s_printf("\r\nThere are no BBSes in the list yet!\r\n"); return; } sqlite3_step(res); - s_putstring(socket, "\r\n\e[1;32mDeleted!\e[0m\r\n"); + s_printf("\r\n\e[1;32mDeleted!\e[0m\r\n"); sqlite3_finalize(res); } else { - s_putstring(socket, "\r\n\e[1;32mAborted!\e[0m\r\n"); + s_printf("\r\n\e[1;32mAborted!\e[0m\r\n"); } } else { sqlite3_finalize(res); - s_putstring(socket, "\r\nThat BBS entry either doesn't exist or wasn't created by you.\r\n"); + s_printf("\r\nThat BBS entry either doesn't exist or wasn't created by you.\r\n"); } sqlite3_close(db); } -void list_bbses(int socket) { +void list_bbses() { char buffer[256]; sqlite3 *db; - sqlite3_stmt *res; - int rc; - char *sql = "SELECT id,bbsname,sysop,telnet FROM bbslist"; - int i; + sqlite3_stmt *res; + int rc; + char *sql = "SELECT id,bbsname,sysop,telnet FROM bbslist"; + int i; - sprintf(buffer, "%s/bbslist.sq3", conf.bbs_path); + sprintf(buffer, "%s/bbslist.sq3", conf.bbs_path); - rc = sqlite3_open(buffer, &db); + rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { dolog("Cannot open database: %s", sqlite3_errmsg(db)); sqlite3_close(db); @@ -177,51 +173,48 @@ void list_bbses(int socket) { rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); if (rc != SQLITE_OK) { sqlite3_close(db); - s_putstring(socket, "\r\nThere are no BBSes in the list yet!\r\n"); + s_printf("\r\nThere are no BBSes in the list yet!\r\n"); return; } i = 0; - s_putstring(socket, "\r\n\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); + s_printf("\r\n\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); while (sqlite3_step(res) == SQLITE_ROW) { - sprintf(buffer, "\e[1;30m[\e[1;34m%3d\e[1;30m] \e[1;37m%-18s \e[1;33m%-16s \e[1;32m%-37s\e[0m\r\n", sqlite3_column_int(res, 0), sqlite3_column_text(res, 1), sqlite3_column_text(res, 2), sqlite3_column_text(res, 3)); - s_putstring(socket, buffer); + s_printf("\e[1;30m[\e[1;34m%3d\e[1;30m] \e[1;37m%-18s \e[1;33m%-16s \e[1;32m%-37s\e[0m\r\n", sqlite3_column_int(res, 0), sqlite3_column_text(res, 1), sqlite3_column_text(res, 2), sqlite3_column_text(res, 3)); i++; if (i == 20) { - sprintf(buffer, "Press any key to continue...\r\n"); - s_putstring(socket, buffer); - s_getc(socket); + s_printf("Press any key to continue...\r\n"); + s_getc(); i = 0; } } - s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); - sqlite3_finalize(res); - sqlite3_close(db); + s_printf("\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); + s_printf("Press any key to continue...\r\n"); + s_getc(); } -void bbs_list(int socket, struct user_record *user) { +void bbs_list(struct user_record *user) { int doquit = 0; char c; while(!doquit) { - s_putstring(socket, "\r\n\e[1;32mBBS Listings: \e[1;37m(\e[1;33mL\e[1;37m) \e[1;32mList, \e[1;37m(\e[1;33mA\e[1;37m) \e[1;32mAdd \e[1;37m(\e[1;33mD\e[1;37m) \e[1;32mDelete \e[1;37m(\e[1;33mQ\e[1;37m) \e[1;32mQuit\e[0m\r\n"); + s_printf("\r\n\e[1;32mBBS Listings: \e[1;37m(\e[1;33mL\e[1;37m) \e[1;32mList, \e[1;37m(\e[1;33mA\e[1;37m) \e[1;32mAdd \e[1;37m(\e[1;33mD\e[1;37m) \e[1;32mDelete \e[1;37m(\e[1;33mQ\e[1;37m) \e[1;32mQuit\e[0m\r\n"); - c = s_getc(socket); + c = s_getc(); switch(tolower(c)) { case 'l': - list_bbses(socket); + list_bbses(); break; case 'a': - add_bbs(socket, user); + add_bbs(user); break; case 'd': - delete_bbs(socket, user); + delete_bbs(user); break; case 'q': doquit = 1; diff --git a/chat_system.c b/chat_system.c index aefbf9e..94a9b72 100644 --- a/chat_system.c +++ b/chat_system.c @@ -11,6 +11,7 @@ extern struct bbs_config conf; extern int mynode; +extern int gSocket; static char **screenbuffer; static int chat_socket; @@ -43,25 +44,25 @@ int hostname_to_ip(char * hostname , char* ip) { struct hostent *he; struct in_addr **addr_list; int i; - - if ( (he = gethostbyname( hostname ) ) == NULL) + + if ( (he = gethostbyname( hostname ) ) == NULL) { // get the host info return 1; } - + addr_list = (struct in_addr **) he->h_addr_list; - + for(i = 0; addr_list[i] != NULL; i++) { strcpy(ip , inet_ntoa(*addr_list[i]) ); return 0; } - + return 1; } void append_screenbuffer(char *buffer) { int z; - + for (z=0;zloginname, user->loginname); raw("NICK %s\r\n", user->loginname); raw("JOIN %s\r\n", conf.irc_channel); - + memset(buffer, 0, 513); - - screenbuffer = (char **)malloc(sizeof(char *) * 23); + + screenbuffer = (char **)malloc(sizeof(char *) * 23); for (i=0;i<23;i++) { screenbuffer[i] = (char *)malloc(81); memset(screenbuffer[i], 0, 81); } - + while (1) { FD_ZERO(&fds); - FD_SET(sock, &fds); + FD_SET(gSocket, &fds); FD_SET(chat_socket, &fds); - - if (chat_socket > sock) { + + if (chat_socket > gSocket) { t = chat_socket + 1; } else { - t = sock + 1; + t = gSocket + 1; } - + ret = select(t, &fds, NULL, NULL, NULL); - + if (ret > 0) { - if (FD_ISSET(sock, &fds)) { - len = read(sock, &c, 1); + if (FD_ISSET(gSocket, &fds)) { + len = read(gSocket, &c, 1); if (len == 0) { raw("QUIT\r\n"); - disconnect(sock, "Socket closed"); + disconnect("Socket closed"); } - + if (c == '\r') { if (inputbuffer[0] == '/') { if (strcasecmp(&inputbuffer[1], "quit") == 0) { @@ -205,19 +206,19 @@ void chat_system(int sock, struct user_record *user) { do_update = 2; } } - } + } if (FD_ISSET(chat_socket, &fds)) { len = read(chat_socket, &c, 1); if (len == 0) { - s_putstring(sock, "\r\n\r\n\r\nLost connection to chat server!\r\n"); + s_putstring("\r\n\r\n\r\nLost connection to chat server!\r\n"); for (i=0;i<22;i++) { free(screenbuffer[i]); } - free(screenbuffer); + free(screenbuffer); return; } - - if (c == '\r' || buffer_at == 512) { + + if (c == '\r' || buffer_at == 512) { if (!strncmp(buffer, "PING", 4)) { buffer[1] = 'O'; raw(buffer); @@ -241,7 +242,7 @@ void chat_system(int sock, struct user_record *user) { } - if (!strncmp(cmd, "PRIVMSG", 7) || !strncmp(cmd, "NOTICE", 6)) { + if (!strncmp(cmd, "PRIVMSG", 7) || !strncmp(cmd, "NOTICE", 6)) { for (j=0;j 0) { - s_putstring(sock, inputbuffer); - } + s_putstring(inputbuffer); + } do_update = 0; } else if (do_update == 2) { - sprintf(buffer2, "\e[24;1f%s\e[K", inputbuffer); - s_putstring(sock, buffer2); + s_printf("\e[24;1f%s\e[K", inputbuffer); } } } diff --git a/doors.c b/doors.c index 358c102..d6790f3 100644 --- a/doors.c +++ b/doors.c @@ -22,6 +22,7 @@ extern struct bbs_config conf; extern int mynode; +extern int gSocket; int running_door_pid = 0; int running_door = 0; @@ -36,7 +37,7 @@ void doorchld_handler(int s) running_door = 0; } -int write_door32sys(int socket, struct user_record *user) { +int write_door32sys(struct user_record *user) { struct stat s; char buffer[256]; FILE *fptr; @@ -59,7 +60,7 @@ int write_door32sys(int socket, struct user_record *user) { } fprintf(fptr, "2\n"); // telnet type - fprintf(fptr, "%d\n", socket); // socket + fprintf(fptr, "%d\n", gSocket); // socket fprintf(fptr, "38400\n"); // baudrate fprintf(fptr, "Magicka %d.%d\n", VERSION_MAJOR, VERSION_MINOR); fprintf(fptr, "%d\n", user->id); @@ -126,7 +127,7 @@ int write_door32sys(int socket, struct user_record *user) { return 0; } -void rundoor(int socket, struct user_record *user, char *cmd, int stdio) { +void rundoor(struct user_record *user, char *cmd, int stdio) { char buffer[256]; int pid; char *arguments[4]; @@ -143,7 +144,7 @@ void rundoor(int socket, struct user_record *user, char *cmd, int stdio) { timeoutpaused = 1; - if (write_door32sys(socket, user) != 0) { + if (write_door32sys(user) != 0) { return; } @@ -152,7 +153,7 @@ void rundoor(int socket, struct user_record *user, char *cmd, int stdio) { arguments[0] = strdup(cmd); sprintf(buffer, "%d", mynode); arguments[1] = strdup(buffer); - sprintf(buffer, "%d", socket); + sprintf(buffer, "%d", gSocket); arguments[2] = strdup(buffer); arguments[3] = NULL; @@ -192,19 +193,19 @@ void rundoor(int socket, struct user_record *user, char *cmd, int stdio) { while(running_door != 0) { FD_ZERO(&fdset); FD_SET(master, &fdset); - FD_SET(socket, &fdset); - if (master > socket) { + FD_SET(gSocket, &fdset); + if (master > gSocket) { t = master + 1; } else { - t = socket + 1; + t = gSocket + 1; } ret = select(t, &fdset, NULL, NULL, NULL); if (ret > 0) { - if (FD_ISSET(socket, &fdset)) { - len = read(socket, &c, 1); + if (FD_ISSET(gSocket, &fdset)) { + len = read(gSocket, &c, 1); if (len == 0) { close(master); - disconnect(socket, "Socket Closed"); + disconnect("Socket Closed"); return; } if (c == '\n' || c == '\0') { @@ -217,7 +218,7 @@ void rundoor(int socket, struct user_record *user, char *cmd, int stdio) { close(master); break; } - write(socket, &c, 1); + write(gSocket, &c, 1); } } } @@ -227,16 +228,15 @@ void rundoor(int socket, struct user_record *user, char *cmd, int stdio) { free(arguments[1]); free(arguments[2]); } else { - sprintf(buffer, "%s %d %d", cmd, mynode, socket); + sprintf(buffer, "%s %d %d", cmd, mynode, gSocket); system(buffer); } timeoutpaused = 0; } -int door_menu(int socket, struct user_record *user) { +int door_menu(struct user_record *user) { int doquit = 0; int dodoors = 0; - char prompt[128]; char buffer[256]; int i; char c; @@ -268,12 +268,11 @@ int door_menu(int socket, struct user_record *user) { while (!dodoors) { if (do_internal_menu == 1) { - s_displayansi(socket, "doors"); + s_displayansi("doors"); - sprintf(prompt, "\e[0m\r\nTL: %dm :> ", user->timeleft); - s_putstring(socket, prompt); + s_printf("\e[0m\r\nTL: %dm :> ", user->timeleft); - c = s_getc(socket); + c = s_getc(); } else { lua_getglobal(L, "menu"); result = lua_pcall(L, 0, 1, 0); @@ -293,8 +292,8 @@ int door_menu(int socket, struct user_record *user) { break; case 'g': { - s_putstring(socket, "\r\nAre you sure you want to log off? (Y/N)"); - c = s_getc(socket); + s_printf("\r\nAre you sure you want to log off? (Y/N)"); + c = s_getc(); if (tolower(c) == 'y') { doquit = 1; dodoors = 1; @@ -306,7 +305,7 @@ int door_menu(int socket, struct user_record *user) { for (i=0;ikey)) { dolog("%s is launched door %s, on node %d", user->loginname, conf.doors[i]->name, mynode); - rundoor(socket, user, conf.doors[i]->command, conf.doors[i]->stdio); + rundoor(user, conf.doors[i]->command, conf.doors[i]->stdio); dolog("%s is returned from door %s, on node %d", user->loginname, conf.doors[i]->name, mynode); break; } diff --git a/email.c b/email.c index cb7aa5d..c14c1f9 100644 --- a/email.c +++ b/email.c @@ -8,7 +8,7 @@ extern struct bbs_config conf; -void send_email(int socket, struct user_record *user) { +void send_email(struct user_record *user) { char buffer[256]; sqlite3 *db; sqlite3_stmt *res; @@ -27,30 +27,30 @@ void send_email(int socket, struct user_record *user) { char *isql = "INSERT INTO email (sender, recipient, subject, body, date, seen) VALUES(?, ?, ?, ?, ?, 0)"; char *err_msg = 0; - s_putstring(socket, "\r\nTO: "); - s_readstring(socket, buffer, 16); + s_printf("\r\nTO: "); + s_readstring(buffer, 16); if (strlen(buffer) == 0) { - s_putstring(socket, "\r\nAborted\r\n"); + s_printf("\r\nAborted\r\n"); return; } if (check_user(buffer)) { - s_putstring(socket, "\r\n\r\nInvalid Username\r\n"); + s_printf("\r\n\r\nInvalid Username\r\n"); return; } recipient = strdup(buffer); - s_putstring(socket, "\r\nSUBJECT: "); - s_readstring(socket, buffer, 25); + s_printf("\r\nSUBJECT: "); + s_readstring(buffer, 25); if (strlen(buffer) == 0) { free(recipient); - s_putstring(socket, "\r\nAborted\r\n"); + s_printf("\r\nAborted\r\n"); return; } subject = strdup(buffer); // post a message - msg = external_editor(socket, user, user->loginname, recipient, NULL, NULL, subject, 1); + msg = external_editor(user, user->loginname, recipient, NULL, NULL, subject, 1); if (msg != NULL) { sprintf(buffer, "%s/email.sq3", conf.bbs_path); @@ -87,7 +87,7 @@ void send_email(int socket, struct user_record *user) { dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); sqlite3_finalize(res); sqlite3_close(db); - s_putstring(socket, "\r\nNo such email\r\n"); + s_printf("\r\nNo such email\r\n"); return; } sqlite3_step(res); @@ -125,23 +125,23 @@ void show_email(int socket, struct user_record *user, int msgno) { rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + sqlite3_close(db); - exit(1); - } - rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); + exit(1); + } + rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); - if (rc == SQLITE_OK) { - sqlite3_bind_text(res, 1, user->loginname, -1, 0); - sqlite3_bind_int(res, 2, msgno); - } else { - dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); + if (rc == SQLITE_OK) { + sqlite3_bind_text(res, 1, user->loginname, -1, 0); + sqlite3_bind_int(res, 2, msgno); + } else { + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); sqlite3_finalize(res); sqlite3_close(db); - s_putstring(socket, "\r\nNo such email\r\n"); + s_printf("\r\nNo such email\r\n"); return; - } + } if (sqlite3_step(res) == SQLITE_ROW) { id = sqlite3_column_int(res, 0); sender = strdup((char *)sqlite3_column_text(res, 1)); @@ -150,16 +150,14 @@ void show_email(int socket, struct user_record *user, int msgno) { date = (time_t)sqlite3_column_int(res, 4); - sprintf(buffer, "\e[2J\e[1;32mFrom : \e[1;37m%s\r\n", sender); - s_putstring(socket, buffer); - sprintf(buffer, "\e[1;32mSubject : \e[1;37m%s\r\n", subject); - s_putstring(socket, buffer); + s_printf("\e[2J\e[1;32mFrom : \e[1;37m%s\r\n", sender); + s_printf("\e[1;32mSubject : \e[1;37m%s\r\n", subject); localtime_r(&date, &msg_date); sprintf(buffer, "\e[1;32mDate : \e[1;37m%s", asctime(&msg_date)); buffer[strlen(buffer) - 1] = '\0'; strcat(buffer, "\r\n"); - s_putstring(socket, buffer); - s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); + s_printf(buffer); + s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); lines = 0; chars = 0; @@ -167,16 +165,16 @@ void show_email(int socket, struct user_record *user, int msgno) { for (z=0;zloginname, sender, body, sender, subject, 1); + replybody = external_editor(user, user->loginname, sender, body, sender, subject, 1); if (replybody != NULL) { rc = sqlite3_prepare_v2(db, isql, -1, &res, 0); @@ -224,7 +221,7 @@ void show_email(int socket, struct user_record *user, int msgno) { dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); sqlite3_finalize(res); sqlite3_close(db); - s_putstring(socket, "\r\nNo such email\r\n"); + s_printf("\r\nNo such email\r\n"); return; } sqlite3_step(res); @@ -249,7 +246,7 @@ void show_email(int socket, struct user_record *user, int msgno) { dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); sqlite3_finalize(res); sqlite3_close(db); - s_putstring(socket, "\r\nNo such email\r\n"); + s_printf("\r\nNo such email\r\n"); return; } sqlite3_step(res); @@ -265,7 +262,7 @@ void show_email(int socket, struct user_record *user, int msgno) { } } -void list_emails(int socket, struct user_record *user) { +void list_emails(struct user_record *user) { char buffer[256]; sqlite3 *db; sqlite3_stmt *res; @@ -298,12 +295,12 @@ void list_emails(int socket, struct user_record *user) { dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); sqlite3_finalize(res); sqlite3_close(db); - s_putstring(socket, "\r\nYou have no email\r\n"); + s_printf("\r\nYou have no email\r\n"); return; } msgid = 0; - s_putstring(socket, "\e[2J\e[1;37;44m[MSG#] Subject From Date \r\n\e[0m"); + s_printf("\e[2J\e[1;37;44m[MSG#] Subject From Date \r\n\e[0m"); while (sqlite3_step(res) == SQLITE_ROW) { from = strdup((char *)sqlite3_column_text(res, 0)); subject = strdup((char *)sqlite3_column_text(res, 1)); @@ -311,18 +308,16 @@ void list_emails(int socket, struct user_record *user) { date = (time_t)sqlite3_column_int(res, 3); localtime_r(&date, &msg_date); if (seen == 0) { - sprintf(buffer, "\e[1;30m[\e[1;34m%4d\e[1;30m]\e[1;32m*\e[1;37m%-39.39s \e[1;32m%-16.16s \e[1;35m%02d:%02d %02d-%02d-%02d\e[0m\r\n", msgid + 1, subject, from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + s_printf("\e[1;30m[\e[1;34m%4d\e[1;30m]\e[1;32m*\e[1;37m%-39.39s \e[1;32m%-16.16s \e[1;35m%02d:%02d %02d-%02d-%02d\e[0m\r\n", msgid + 1, subject, from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } else { - sprintf(buffer, "\e[1;30m[\e[1;34m%4d\e[1;30m] \e[1;37m%-39.39s \e[1;32m%-16.16s \e[1;35m%02d:%02d %02d-%02d-%02d\e[0m\r\n", msgid + 1, subject, from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + s_printf("\e[1;30m[\e[1;34m%4d\e[1;30m] \e[1;37m%-39.39s \e[1;32m%-16.16s \e[1;35m%02d:%02d %02d-%02d-%02d\e[0m\r\n", msgid + 1, subject, from, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } - s_putstring(socket, buffer); - free(from); free(subject); if (msgid % 22 == 0 && msgid != 0) { - s_putstring(socket, "\e[1;37mEnter \e[1;36m# \e[1;37mto read, \e[1;36mQ \e[1;37mto quit or \e[1;36mEnter\e[1;37m to continue\e[0m\r\n"); - s_readstring(socket, buffer, 5); + s_printf("\e[1;37mEnter \e[1;36m# \e[1;37mto read, \e[1;36mQ \e[1;37mto quit or \e[1;36mEnter\e[1;37m to continue\e[0m\r\n"); + s_readstring(buffer, 5); if (strlen(buffer) > 0) { if (tolower(buffer[0]) == 'q') { sqlite3_finalize(res); @@ -336,15 +331,15 @@ void list_emails(int socket, struct user_record *user) { return; } } - s_putstring(socket, "\e[2J\e[1;37;44m[MSG#] Subject From Date \r\n\e[0m"); + s_printf("\e[2J\e[1;37;44m[MSG#] Subject From Date \r\n\e[0m"); } msgid++; } if (msgid == 0) { - s_putstring(socket, "\r\nYou have no email\r\n"); + s_printf( "\r\nYou have no email\r\n"); } else { - s_putstring(socket, "\e[1;37mEnter \e[1;36m# \e[1;37mto read, or \e[1;36mEnter\e[1;37m to quit\e[0m\r\n"); - s_readstring(socket, buffer, 5); + s_printf("\e[1;37mEnter \e[1;36m# \e[1;37mto read, or \e[1;36mEnter\e[1;37m to quit\e[0m\r\n"); + s_readstring(buffer, 5); if (strlen(buffer) > 0) { msgtoread = atoi(buffer) - 1; sqlite3_finalize(res); @@ -363,32 +358,32 @@ int mail_getemailcount(struct user_record *user) { int count; char buffer[256]; sqlite3 *db; - sqlite3_stmt *res; - int rc; + sqlite3_stmt *res; + int rc; sprintf(buffer, "%s/email.sq3", conf.bbs_path); rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + sqlite3_close(db); - exit(1); - } - rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); + exit(1); + } + rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); - if (rc == SQLITE_OK) { - sqlite3_bind_text(res, 1, user->loginname, -1, 0); - } else { - dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); + if (rc == SQLITE_OK) { + sqlite3_bind_text(res, 1, user->loginname, -1, 0); + } else { + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); sqlite3_finalize(res); sqlite3_close(db); return 0; - } + } count = 0; - if (sqlite3_step(res) == SQLITE_ROW) { + if (sqlite3_step(res) == SQLITE_ROW) { count = sqlite3_column_int(res, 0); } diff --git a/files.c b/files.c index 54e65fb..7fb558c 100644 --- a/files.c +++ b/files.c @@ -13,6 +13,7 @@ #include "lua/lualib.h" #include "lua/lauxlib.h" extern struct bbs_config conf; +extern int gSocket; static int doCancel = 0; @@ -127,7 +128,7 @@ int doIO(ZModem *zm) { } else if (i > 0) { len = read(zm->ifd, buffer, 2048); if (len == 0) { - disconnect(zm->ifd, "Socket closed"); + disconnect("Socket closed"); } pos = 0; @@ -159,7 +160,7 @@ int doIO(ZModem *zm) { return done; } -void upload_zmodem(int socket, struct user_record *user) { +void upload_zmodem(struct user_record *user) { ZModem zm; int done; @@ -170,8 +171,8 @@ void upload_zmodem(int socket, struct user_record *user) { zm.windowsize = 0; zm.bufsize = 0; - zm.ifd = socket; - zm.ofd = socket; + zm.ifd = gSocket; + zm.ofd = gSocket; zm.zrinitflags = 0; zm.zsinitflags = 0; @@ -183,7 +184,7 @@ void upload_zmodem(int socket, struct user_record *user) { doIO(&zm); } -void upload(int socket, struct user_record *user) { +void upload(struct user_record *user) { char buffer[331]; char buffer2[66]; char buffer3[256]; @@ -197,19 +198,18 @@ void upload(int socket, struct user_record *user) { "approved INTEGER);"; char *sql = "INSERT INTO files (filename, description, size, dlcount, approved) VALUES(?, ?, ?, 0, 0)"; sqlite3 *db; - sqlite3_stmt *res; - int rc; - struct stat s; - char *err_msg = NULL; + sqlite3_stmt *res; + int rc; + struct stat s; + char *err_msg = NULL; - upload_zmodem(socket, user); + upload_zmodem(user); - s_putstring(socket, "\r\nPlease enter a description:\r\n"); + s_printf("\r\nPlease enter a description:\r\n"); buffer[0] = '\0'; for (i=0;i<5;i++) { - sprintf(buffer2, "\r\n%d: ", i); - s_putstring(socket, buffer2); - s_readstring(socket, buffer2, 65); + s_printf("\r\n%d: ", i); + s_readstring(buffer2, 65); if (strlen(buffer2) == 0) { break; } @@ -261,7 +261,7 @@ void upload(int socket, struct user_record *user) { sqlite3_close(db); } -void download_zmodem(int socket, struct user_record *user, char *filename) { +void download_zmodem(struct user_record *user, char *filename) { ZModem zm; int done ; fd_set readfds; @@ -280,8 +280,8 @@ void download_zmodem(int socket, struct user_record *user, char *filename) { zm.windowsize = 0; zm.bufsize = 0; - zm.ifd = socket; - zm.ofd = socket; + zm.ifd = gSocket; + zm.ofd = gSocket; zm.zrinitflags = 0; zm.zsinitflags = 0; @@ -331,7 +331,7 @@ void download_zmodem(int socket, struct user_record *user, char *filename) { } } -void download(int socket, struct user_record *user) { +void download(struct user_record *user) { int i; char *ssql = "select dlcount from files where filename like ?"; char *usql = "update files set dlcount=? where filename like ?"; @@ -343,7 +343,7 @@ void download(int socket, struct user_record *user) { int rc; for (i=0;icur_file_dir]->file_subs[user->cur_file_sub]->database); @@ -397,7 +397,7 @@ void download(int socket, struct user_record *user) { tagged_count = 0; } -void list_files(int socket, struct user_record *user) { +void list_files(struct user_record *user) { char *sql = "select filename, description, size, dlcount from files where approved=1"; char buffer[256]; sqlite3 *db; @@ -430,7 +430,7 @@ void list_files(int socket, struct user_record *user) { if (rc != SQLITE_OK) { sqlite3_finalize(res); sqlite3_close(db); - s_putstring(socket, "\r\nNo files in this area!\r\n"); + s_printf("\r\nNo files in this area!\r\n"); return; } @@ -455,10 +455,10 @@ void list_files(int socket, struct user_record *user) { sqlite3_close(db); if (files_c == 0) { - s_putstring(socket, "\r\nNo files in this area!\r\n"); + s_printf("\r\nNo files in this area!\r\n"); return; } - s_putstring(socket, "\r\n"); + s_printf("\r\n"); for (i=0;isize; if (file_size > 1024 * 1024 * 1024) { @@ -473,20 +473,19 @@ void list_files(int socket, struct user_record *user) { } else { file_unit = 'b'; } - sprintf(buffer, "\r\n\r\n\e[1;30m[\e[1;34m%3d\e[1;30m] \e[1;33m%3ddloads \e[1;36m%4d%c \e[1;37m%-56s\r\n \e[0;32m", i, files_e[i]->dlcount, file_size, file_unit, basename(files_e[i]->filename)); - s_putstring(socket, buffer); + s_printf("\r\n\r\n\e[1;30m[\e[1;34m%3d\e[1;30m] \e[1;33m%3ddloads \e[1;36m%4d%c \e[1;37m%-56s\r\n \e[0;32m", i, files_e[i]->dlcount, file_size, file_unit, basename(files_e[i]->filename)); lines+=3; for (j=0;jdescription);j++) { if (files_e[i]->description[j] == '\n') { - s_putstring(socket, "\r\n"); + s_printf("\r\n"); lines++; if (lines >= 18) { lines = 0; while (1) { - s_putstring(socket, "\r\n\e[0mEnter # to tag, Q to quit, Enter to continue: "); - s_readstring(socket, buffer, 5); + s_printf("\r\n\e[0mEnter # to tag, Q to quit, Enter to continue: "); + s_readstring(buffer, 5); if (strlen(buffer) == 0) { - s_putstring(socket, "\r\n"); + s_printf("\r\n"); break; } else if (tolower(buffer[0]) == 'q') { for (z=0;zfilename); tagged_count++; - sprintf(buffer, "\r\nTagged %s\r\n", basename(files_e[z]->filename)); - s_putstring(socket, buffer); + s_printf("\r\nTagged %s\r\n", basename(files_e[z]->filename)); } else { - s_putstring(socket, "\r\nAlready Tagged\r\n"); + s_printf("\r\nAlready Tagged\r\n"); } } else { - s_putstring(socket, "\r\nSorry, you don't have permission to download from this area\r\n"); + s_printf("\r\nSorry, you don't have permission to download from this area\r\n"); } } } } } else { - s_putstring(socket, " \e[0;32m"); + s_printf(" \e[0;32m"); } } else { - s_putchar(socket, files_e[i]->description[j]); + s_putchar(files_e[i]->description[j]); } } } while (1) { - s_putstring(socket, "\r\n\e[0mEnter # to tag, Enter to quit: "); - s_readstring(socket, buffer, 5); + s_printf("\r\n\e[0mEnter # to tag, Enter to quit: "); + s_readstring(buffer, 5); if (strlen(buffer) == 0) { for (z=0;zfilename); @@ -545,7 +543,7 @@ void list_files(int socket, struct user_record *user) { free(files_e[z]); } free(files_e); - s_putstring(socket, "\r\n"); + s_printf("\r\n"); return; } else { z = atoi(buffer); @@ -566,20 +564,19 @@ void list_files(int socket, struct user_record *user) { } tagged_files[tagged_count] = strdup(files_e[z]->filename); tagged_count++; - sprintf(buffer, "\r\nTagged %s\r\n", basename(files_e[z]->filename)); - s_putstring(socket, buffer); + s_printf("\r\nTagged %s\r\n", basename(files_e[z]->filename)); } else { - s_putstring(socket, "\r\nAlready Tagged\r\n"); + s_printf("\r\nAlready Tagged\r\n"); } } else { - s_putstring(socket, "\r\nSorry, you don't have permission to download from this area\r\n"); + s_printf("\r\nSorry, you don't have permission to download from this area\r\n"); } } } } } -int file_menu(int socket, struct user_record *user) { +int file_menu(struct user_record *user) { int doquit = 0; int dofiles = 0; char c; @@ -614,12 +611,11 @@ int file_menu(int socket, struct user_record *user) { while (!dofiles) { if (do_internal_menu == 1) { - s_displayansi(socket, "filemenu"); + s_displayansi("filemenu"); - sprintf(prompt, "\e[0m\r\nDir: (%d) %s\r\nSub: (%d) %s\r\nTL: %dm :> ", user->cur_file_dir, conf.file_directories[user->cur_file_dir]->name, user->cur_file_sub, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->name, user->timeleft); - s_putstring(socket, prompt); + s_printf("\e[0m\r\nDir: (%d) %s\r\nSub: (%d) %s\r\nTL: %dm :> ", user->cur_file_dir, conf.file_directories[user->cur_file_dir]->name, user->cur_file_sub, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->name, user->timeleft); - c = s_getc(socket); + c = s_getc(); } else { lua_getglobal(L, "menu"); result = lua_pcall(L, 0, 1, 0); @@ -636,25 +632,24 @@ int file_menu(int socket, struct user_record *user) { switch(tolower(c)) { case 'i': { - s_putstring(socket, "\r\n\r\nFile Directories:\r\n\r\n"); + s_printf("\r\n\r\nFile Directories:\r\n\r\n"); for (i=0;isec_level <= user->sec_level) { - sprintf(prompt, " %d. %s\r\n", i, conf.file_directories[i]->name); - s_putstring(socket, prompt); + s_printf(" %d. %s\r\n", i, conf.file_directories[i]->name); } if (i != 0 && i % 20 == 0) { - s_putstring(socket, "Press any key to continue...\r\n"); - c = s_getc(socket); + s_printf("Press any key to continue...\r\n"); + c = s_getc(); } } - s_putstring(socket, "Enter the directory number: "); - s_readstring(socket, prompt, 5); + s_printf("Enter the directory number: "); + s_readstring(prompt, 5); if (tolower(prompt[0]) != 'q') { j = atoi(prompt); if (j < 0 || j >= conf.file_directory_count || conf.file_directories[j]->sec_level > user->sec_level) { - s_putstring(socket, "\r\nInvalid directory number!\r\n"); + s_printf("\r\nInvalid directory number!\r\n"); } else { - s_putstring(socket, "\r\n"); + s_printf("\r\n"); user->cur_file_dir = j; user->cur_file_sub = 0; } @@ -663,43 +658,42 @@ int file_menu(int socket, struct user_record *user) { break; case 's': { - s_putstring(socket, "\r\n\r\nFile Subdirectories:\r\n\r\n"); + s_printf("\r\n\r\nFile Subdirectories:\r\n\r\n"); for (i=0;icur_file_dir]->file_sub_count;i++) { - sprintf(prompt, " %d. %s\r\n", i, conf.file_directories[user->cur_file_dir]->file_subs[i]->name); - s_putstring(socket, prompt); + s_printf(" %d. %s\r\n", i, conf.file_directories[user->cur_file_dir]->file_subs[i]->name); if (i != 0 && i % 20 == 0) { - s_putstring(socket, "Press any key to continue...\r\n"); - c = s_getc(socket); + s_printf("Press any key to continue...\r\n"); + c = s_getc(); } } - s_putstring(socket, "Enter the sub directory number: "); - s_readstring(socket, prompt, 5); + s_printf("Enter the sub directory number: "); + s_readstring(prompt, 5); if (tolower(prompt[0]) != 'q') { j = atoi(prompt); if (j < 0 || j >= conf.file_directories[user->cur_file_dir]->file_sub_count) { - s_putstring(socket, "\r\nInvalid sub directiry number!\r\n"); + s_printf("\r\nInvalid sub directiry number!\r\n"); } else { - s_putstring(socket, "\r\n"); + s_printf("\r\n"); user->cur_file_sub = j; } } } break; case 'l': - list_files(socket, user); + list_files(user); break; case 'u': { if (user->sec_level >= conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->upload_sec_level) { - upload(socket, user); + upload(user); } else { - s_putstring(socket, "Sorry, you don't have permission to upload in this Sub\r\n"); + s_printf("Sorry, you don't have permission to upload in this Sub\r\n"); } } break; case 'd': - download(socket, user); + download(user); break; case 'c': { @@ -764,8 +758,8 @@ int file_menu(int socket, struct user_record *user) { break; case 'g': { - s_putstring(socket, "\r\nAre you sure you want to log off? (Y/N)"); - c = s_getc(socket); + s_printf("\r\nAre you sure you want to log off? (Y/N)"); + c = s_getc(); if (tolower(c) == 'y') { dofiles = 1; doquit = 1; diff --git a/lua_glue.c b/lua_glue.c index 3cd6c18..ea8ec0d 100644 --- a/lua_glue.c +++ b/lua_glue.c @@ -12,7 +12,7 @@ extern int gSocket; int l_bbsWString(lua_State *L) { char *str = (char *)lua_tostring(L, -1); - s_putstring(gSocket, str); + s_printf("%s", str); return 0; } @@ -25,7 +25,7 @@ int l_bbsRString(lua_State *L) { len = 256; } - s_readstring(gSocket, buffer, len); + s_readstring(buffer, len); lua_pushstring(L, buffer); @@ -35,7 +35,7 @@ int l_bbsRString(lua_State *L) { int l_bbsRChar(lua_State *L) { char c; - c = s_getc(gSocket); + c = s_getc(); lua_pushlstring(L, &c, 1); @@ -45,7 +45,7 @@ int l_bbsRChar(lua_State *L) { int l_bbsDisplayAnsi(lua_State *L) { char *str = (char *)lua_tostring(L, -1); - s_displayansi(gSocket, str); + s_displayansi(str); return 0; } @@ -94,7 +94,7 @@ int l_bbsGetEmailCount(lua_State *L) { } int l_bbsMailScan(lua_State *L) { - mail_scan(gSocket, gUser); + mail_scan(gUser); return 0; } @@ -102,7 +102,7 @@ int l_bbsRunDoor(lua_State *L) { char *cmd = (char *)lua_tostring(L, 1); int stdio = lua_toboolean(L, 2); - rundoor(gSocket, gUser, cmd, stdio); + rundoor(gUser, cmd, stdio); return 0; } @@ -114,7 +114,7 @@ int l_bbsTimeLeft(lua_State *L) { } int l_bbsDisplayAutoMsg(lua_State *L) { - automessage_display(gSocket); + automessage_display(); return 0; } diff --git a/mail_menu.c b/mail_menu.c index b6704db..5df479d 100644 --- a/mail_menu.c +++ b/mail_menu.c @@ -261,7 +261,7 @@ struct msg_headers *read_message_headers(int msgconf, int msgarea, struct user_r return msghs; } -char *external_editor(int socket, struct user_record *user, char *to, char *from, char *quote, char *qfrom, char *subject, int email) { +char *external_editor(struct user_record *user, char *to, char *from, char *quote, char *qfrom, char *subject, int email) { char c; FILE *fptr; char *body = NULL; @@ -279,8 +279,8 @@ char *external_editor(int socket, struct user_record *user, char *to, char *from if (conf.external_editor_cmd != NULL) { - s_putstring(socket, "\r\nUse external editor? (Y/N) "); - c = s_getc(socket); + s_printf("\r\nUse external editor? (Y/N) "); + c = s_getc(); if (tolower(c) == 'y') { sprintf(buffer, "%s/node%d", conf.bbs_path, mynode); @@ -335,7 +335,7 @@ char *external_editor(int socket, struct user_record *user, char *to, char *from } fclose(fptr); - rundoor(socket, user, conf.external_editor_cmd, conf.external_editor_stdio); + rundoor(user, conf.external_editor_cmd, conf.external_editor_stdio); // readin msgtmp sprintf(buffer, "%s/node%d/MSGTMP", conf.bbs_path, mynode); @@ -413,10 +413,10 @@ char *external_editor(int socket, struct user_record *user, char *to, char *from return body2; } } - return editor(socket, user, quote, qfrom, email); + return editor(user, quote, qfrom, email); } -char *editor(int socket, struct user_record *user, char *quote, char *from, int email) { +char *editor(struct user_record *user, char *quote, char *from, int email) { int lines = 0; char buffer[256]; char linebuffer[80]; @@ -460,14 +460,13 @@ char *editor(int socket, struct user_record *user, char *quote, char *from, int } } } - s_putstring(socket, "\r\n\e[1;32mMagicka Internal Editor, Type \e[1;37m/S \e[1;32mto save, \e[1;37m/A \e[1;32mto abort and \e[1;37m/? \e[1;32mfor help\r\n"); - s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m"); + s_printf("\r\n\e[1;32mMagicka Internal Editor, Type \e[1;37m/S \e[1;32mto save, \e[1;37m/A \e[1;32mto abort and \e[1;37m/? \e[1;32mfor help\r\n"); + s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m"); while(!doquit) { - sprintf(prompt, "\r\n\e[1;30m[\e[1;34m%3d\e[1;30m]: \e[0m%s", lines, next_line_buffer); - s_putstring(socket, prompt); + s_printf("\r\n\e[1;30m[\e[1;34m%3d\e[1;30m]: \e[0m%s", lines, next_line_buffer); strcpy(linebuffer, next_line_buffer); - s_readstring(socket, &linebuffer[strlen(next_line_buffer)], 70 - strlen(next_line_buffer)); + s_readstring(&linebuffer[strlen(next_line_buffer)], 70 - strlen(next_line_buffer)); memset(next_line_buffer, 0, 70); if (strlen(linebuffer) == 70 && linebuffer[69] != ' ') { @@ -475,8 +474,7 @@ char *editor(int socket, struct user_record *user, char *quote, char *from, int if (linebuffer[i] == ' ') { linebuffer[i] = '\0'; strcpy(next_line_buffer, &linebuffer[i+1]); - sprintf(prompt, "\e[%dD\e[0K", 70 - i); - s_putstring(socket, prompt); + s_printf("\e[%dD\e[0K", 70 - i); break; } } @@ -548,21 +546,20 @@ char *editor(int socket, struct user_record *user, char *quote, char *from, int return NULL; } else if (toupper(linebuffer[1]) == 'Q') { if (quote == NULL) { - s_putstring(socket, "\r\nNo message to quote!\r\n"); + s_printf("\r\nNo message to quote!\r\n"); } else { - s_putstring(socket, "\r\n"); + s_printf("\r\n"); for (i=0;i quotelines) { qto = quotelines; @@ -571,7 +568,7 @@ char *editor(int socket, struct user_record *user, char *quote, char *from, int qfrom = 0; } if (qfrom > qto) { - s_putstring(socket, "Quoting Cancelled\r\n"); + s_printf("Quoting Cancelled\r\n"); } for (i=qfrom;i<=qto;i++) { @@ -585,40 +582,38 @@ char *editor(int socket, struct user_record *user, char *quote, char *from, int lines++; } - s_putstring(socket, "\r\n\e[1;32mMagicka Internal Editor, Type \e[1;37m/S \e[1;32mto save, \e[1;37m/A \e[1;32mto abort and \e[1;37m/? \e[1;32mfor help\r\n"); - s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m"); + s_printf("\r\n\e[1;32mMagicka Internal Editor, Type \e[1;37m/S \e[1;32mto save, \e[1;37m/A \e[1;32mto abort and \e[1;37m/? \e[1;32mfor help\r\n"); + s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m"); for (i=0;i= lines) { - s_putstring(socket, "\r\nAborted...\r\n"); + s_printf("\r\nAborted...\r\n"); } else { for (i=z;i= lines) { - s_putstring(socket, "\r\nAborted...\r\n"); + s_printf("\r\nAborted...\r\n"); } else { - sprintf(buffer, "\r\n\e[1;30m[\e[1;34m%3d\e[1;30m]: \e[0m%s", z, content[z]); - s_putstring(socket, buffer); - sprintf(buffer, "\r\n\e[1;30m[\e[1;34m%3d\e[1;30m]: \e[0m", z); - s_putstring(socket, buffer); - s_readstring(socket, linebuffer, 70); + s_printf("\r\n\e[1;30m[\e[1;34m%3d\e[1;30m]: \e[0m%s", z, content[z]); + s_printf("\r\n\e[1;30m[\e[1;34m%3d\e[1;30m]: \e[0m", z); + s_readstring(linebuffer, 70); free(content[z]); content[z] = strdup(linebuffer); } } } else if (toupper(linebuffer[1]) == 'I') { - s_putstring(socket, "\r\nInsert before which line? "); - s_readstring(socket, buffer, 6); + s_printf("\r\nInsert before which line? "); + s_readstring(buffer, 6); if (strlen(buffer) == 0) { - s_putstring(socket, "\r\nAborted...\r\n"); + s_printf("\r\nAborted...\r\n"); } else { z = atoi(buffer); if (z < 0 || z >= lines) { - s_putstring(socket, "\r\nAborted...\r\n"); + s_printf("\r\nAborted...\r\n"); } else { - sprintf(buffer, "\r\n\e[1;30m[\e[1;34m%3d\e[1;30m]: \e[0m", z); - s_putstring(socket, buffer); - s_readstring(socket, linebuffer, 70); + s_printf("\r\n\e[1;30m[\e[1;34m%3d\e[1;30m]: \e[0m", z); + s_readstring(linebuffer, 70); lines++; content = (char **)realloc(content, sizeof(char *) * lines); @@ -750,24 +742,20 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh if (msghs->msgs[mailno]->oaddress != NULL && conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) { from_addr = parse_fido_addr(msghs->msgs[mailno]->oaddress); - sprintf(buffer, "\e[2J\e[1;32mFrom : \e[1;37m%s (%d:%d/%d.%d)\r\n", msghs->msgs[mailno]->from, from_addr->zone, from_addr->net, from_addr->node, from_addr->point); + s_printf("\e[2J\e[1;32mFrom : \e[1;37m%s (%d:%d/%d.%d)\r\n", msghs->msgs[mailno]->from, from_addr->zone, from_addr->net, from_addr->node, from_addr->point); free(from_addr); } else { - sprintf(buffer, "\e[2J\e[1;32mFrom : \e[1;37m%s\r\n", msghs->msgs[mailno]->from); + s_printf("\e[2J\e[1;32mFrom : \e[1;37m%s\r\n", msghs->msgs[mailno]->from); } - s_putstring(socket, buffer); - sprintf(buffer, "\e[1;32mTo : \e[1;37m%-27.27s \e[1;32mArea : \e[1;37m%-27.27s\r\n", msghs->msgs[mailno]->to, conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->name); - s_putstring(socket, buffer); - sprintf(buffer, "\e[1;32mSubject : \e[1;37m%-27.27s \e[1;32mMsgNo : \e[1;37m%4d of %4d\r\n", msghs->msgs[mailno]->subject, mailno + 1, msghs->msg_count); - s_putstring(socket, buffer); - localtime_r((time_t *)&msghs->msgs[mailno]->msg_h->DateWritten, &msg_date); + s_printf("\e[1;32mTo : \e[1;37m%-27.27s \e[1;32mArea : \e[1;37m%-27.27s\r\n", msghs->msgs[mailno]->to, conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->name); + s_printf("\e[1;32mSubject : \e[1;37m%-27.27s \e[1;32mMsgNo : \e[1;37m%4d of %4d\r\n", msghs->msgs[mailno]->subject, mailno + 1, msghs->msg_count); + localtime_r((time_t *)&msghs->msgs[mailno]->msg_h->DateWritten, &msg_date); sprintf(buffer, "\e[1;32mDate : \e[1;37m%s", asctime(&msg_date)); buffer[strlen(buffer) - 1] = '\0'; strcat(buffer, "\r\n"); - s_putstring(socket, buffer); - sprintf(buffer, "\e[1;32mAttribs : \e[1;37m%s\r\n", (msghs->msgs[mailno]->msg_h->Attribute & MSG_SENT ? "SENT" : "")); - s_putstring(socket, buffer); - s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); + s_printf(buffer); + s_printf("\e[1;32mAttribs : \e[1;37m%s\r\n", (msghs->msgs[mailno]->msg_h->Attribute & MSG_SENT ? "SENT" : "")); + s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); body = (char *)malloc(msghs->msgs[mailno]->msg_h->TxtLen); @@ -817,16 +805,16 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh if (body[z] == '\r' || chars == 79) { chars = 0; if (body[z] == '\r') { - s_putstring(socket, "\r\n"); + s_printf("\r\n"); } else { - s_putchar(socket, body[z]); + s_putchar(body[z]); } lines++; if (lines >= 17) { - s_putstring(socket, "\e[1;37mPress a key to continue...\e[0m"); - s_getc(socket); + s_printf("\e[1;37mPress a key to continue...\e[0m"); + s_getc(); lines = 0; - s_putstring(socket, "\e[7;1H\e[0J"); + s_printf("\e[7;1H\e[0J"); } } else if (body[z] == '\e' && body[z + 1] == '[') { ansi = z; @@ -835,7 +823,7 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh if (body[z] == 'm') { strncpy(buffer, &body[ansi], (z - ansi) + 1); buffer[z - ansi + 1] = '\0'; - s_putstring(socket, buffer); + s_printf("%s", buffer); } else if (body[z] == 'A') { j = atoi(&body[ansi + 2]); if (j == 0 && ansi + 2 == z) { @@ -843,7 +831,7 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh } for (i=0;i= 0) { - s_putstring(socket, "\e[A"); + s_printf("\e[A"); lines--; } else { break; @@ -856,7 +844,7 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh } for (i=0;i= 0) { - s_putstring(socket, "\e[D"); + s_printf("\e[D"); chars--; } else { break; @@ -891,18 +879,18 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh } } else { chars++; - s_putchar(socket, body[z]); + s_putchar(body[z]); } } - s_putstring(socket, "\r\n\e[1;37mPress \e[1;36mR \e[1;37mto reply, \e[1;36mQ \e[1;37mto quit, \e[1;36mB \e[1;37mto go Back, \e[1;36mSPACE \e[1;37mfor Next Mesage..."); + s_printf("\r\n\e[1;37mPress \e[1;36mR \e[1;37mto reply, \e[1;36mQ \e[1;37mto quit, \e[1;36mB \e[1;37mto go Back, \e[1;36mSPACE \e[1;37mfor Next Mesage..."); - c = s_getc(socket); + c = s_getc(); if (tolower(c) == 'r') { JAM_CloseMB(jb); if (user->sec_level < conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->write_sec_level) { - s_putstring(socket, "\r\nSorry, you are not allowed to post in this area\r\n"); + s_printf("\r\nSorry, you are not allowed to post in this area\r\n"); } else { if (msghs->msgs[mailno]->subject != NULL) { if (strncasecmp(msghs->msgs[mailno]->subject, "RE:", 3) != 0) { @@ -914,25 +902,24 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh subject = (char *)malloc(strlen(buffer) + 1); strcpy(subject, buffer); - sprintf(buffer, "\r\n\r\nReplying to: %s\r\n", subject); - s_putstring(socket, buffer); - s_putstring(socket, "Change Subject? (Y/N) "); + s_printf("\r\n\r\nReplying to: %s\r\n", subject); + s_printf("Change Subject? (Y/N) "); - c = s_getc(socket); + c = s_getc(); if (tolower(c) == 'y') { - s_putstring(socket, "\r\nNew subject: "); - s_readstring(socket, buffer, 25); + s_printf("\r\nNew subject: "); + s_readstring(buffer, 25); if (strlen(buffer) == 0) { - s_putstring(socket, "\r\nOk, not changing the subject line..."); + s_printf("\r\nOk, not changing the subject line..."); } else { free(subject); subject = (char *)malloc(strlen(buffer) + 1); strcpy(subject, buffer); } } - s_putstring(socket, "\r\n"); + s_printf("\r\n"); if (msghs->msgs[mailno]->from != NULL) { strcpy(buffer, msghs->msgs[mailno]->from); @@ -961,7 +948,7 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh to = (char *)malloc(strlen(buffer) + 1); strcpy(to, buffer); } - replybody = external_editor(socket, user, to, from, body, msghs->msgs[mailno]->from, subject, 0); + replybody = external_editor(user, to, from, body, msghs->msgs[mailno]->from, subject, 0); if (replybody != NULL) { jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); @@ -1189,7 +1176,7 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh } else if (c == ' ') { mailno++; if (mailno >= msghs->msg_count) { - s_putstring(socket, "\r\n\r\nNo more messages\r\n"); + s_printf("\r\n\r\nNo more messages\r\n"); doquit = 1; } } else if (tolower(c) == 'b') { @@ -1200,7 +1187,7 @@ void read_message(int socket, struct user_record *user, struct msg_headers *msgh } } -int mail_menu(int socket, struct user_record *user) { +int mail_menu(struct user_record *user) { int doquit = 0; int domail = 0; char c; @@ -1269,13 +1256,12 @@ int mail_menu(int socket, struct user_record *user) { while (!domail) { if (do_internal_menu == 1) { - s_displayansi(socket, "mailmenu"); + s_displayansi("mailmenu"); - sprintf(prompt, "\e[0m\r\nConf: (%d) %s\r\nArea: (%d) %s\r\nTL: %dm :> ", user->cur_mail_conf, conf.mail_conferences[user->cur_mail_conf]->name, user->cur_mail_area, conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->name, user->timeleft); - s_putstring(socket, prompt); - - c = s_getc(socket); + s_printf("\e[0m\r\nConf: (%d) %s\r\nArea: (%d) %s\r\nTL: %dm :> ", user->cur_mail_conf, conf.mail_conferences[user->cur_mail_conf]->name, user->cur_mail_area, conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->name, user->timeleft); + + c = s_getc(); } else { lua_getglobal(L, "menu"); result = lua_pcall(L, 0, 1, 0); @@ -1292,7 +1278,7 @@ int mail_menu(int socket, struct user_record *user) { switch(tolower(c)) { case 'd': { - s_putstring(socket, "\r\n"); + s_printf("\r\n"); // list mail in message base msghs = read_message_headers(user->cur_mail_conf, user->cur_mail_area, user); if (msghs != NULL && msghs->msg_count > 0) { @@ -1308,9 +1294,9 @@ int mail_menu(int socket, struct user_record *user) { all_unread = 1; } JAM_CloseMB(jb); - sprintf(buffer, "Read message [1-%d] or N for New: ", msghs->msg_count); - s_putstring(socket, buffer); - s_readstring(socket, buffer, 6); + s_printf("Read message [1-%d] or N for New: ", msghs->msg_count); + + s_readstring(buffer, 6); if (tolower(buffer[0]) == 'n') { if (all_unread == 0) { @@ -1341,14 +1327,14 @@ int mail_menu(int socket, struct user_record *user) { case 'p': { if (user->sec_level < conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->write_sec_level) { - s_putstring(socket, "\r\nSorry, you are not allowed to post in this area\r\n"); + s_printf("\r\nSorry, you are not allowed to post in this area\r\n"); break; } if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_WWIV && conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_ECHOMAIL_AREA) { sprintf(buffer, "ALL"); } else { - s_putstring(socket, "\r\nTO: "); - s_readstring(socket, buffer, 16); + s_printf("\r\nTO: "); + s_readstring(buffer, 16); } if (strlen(buffer) == 0) { strcpy(buffer, "ALL"); @@ -1356,43 +1342,41 @@ int mail_menu(int socket, struct user_record *user) { if (conf.mail_conferences[user->cur_mail_conf]->networked == 0 && strcasecmp(buffer, "ALL") != 0) { if (check_user(buffer)) { - s_putstring(socket, "\r\n\r\nInvalid Username\r\n"); + s_printf("\r\n\r\nInvalid Username\r\n"); break; } } if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->type == TYPE_NETMAIL_AREA) { - s_putstring(socket, "\r\nADDR: "); - s_readstring(socket, buffer2, 32); + s_printf("\r\nADDR: "); + s_readstring(buffer2, 32); if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_FIDO) { from_addr = parse_fido_addr(buffer2); if (!from_addr) { - s_putstring(socket, "\r\n\r\nInvalid Address\r\n"); + s_printf("\r\n\r\nInvalid Address\r\n"); break; } else { if (from_addr->zone == 0 && from_addr->net == 0 && from_addr->node == 0 && from_addr->point == 0) { free(from_addr); - s_putstring(socket, "\r\n\r\nInvalid Address\r\n"); + s_printf("\r\n\r\nInvalid Address\r\n"); break; } - sprintf(buffer2, "\r\nMailing to %d:%d/%d.%d\r\n", from_addr->zone, from_addr->net, from_addr->node, from_addr->point); - s_putstring(socket, buffer2); - } + s_printf(buffer2, "\r\nMailing to %d:%d/%d.%d\r\n", from_addr->zone, from_addr->net, from_addr->node, from_addr->point); + } } else if (conf.mail_conferences[user->cur_mail_conf]->nettype == NETWORK_WWIV) { wwiv_to = atoi(buffer2); if (wwiv_to == 0) { - s_putstring(socket, "\r\n\r\nInvalid Address\r\n"); + s_printf("\r\n\r\nInvalid Address\r\n"); break; } else { - sprintf(buffer2, "\r\nMailing to @%d\r\n", wwiv_to); - s_putstring(socket, buffer2); + s_printf("\r\nMailing to @%d\r\n", wwiv_to); } } } to = strdup(buffer); - s_putstring(socket, "\r\nSUBJECT: "); - s_readstring(socket, buffer, 25); + s_printf("\r\nSUBJECT: "); + s_readstring(buffer, 25); if (strlen(buffer) == 0) { - s_putstring(socket, "\r\nAborted!\r\n"); + s_printf("\r\nAborted!\r\n"); free(to); if (from_addr != NULL) { free(from_addr); @@ -1402,7 +1386,7 @@ int mail_menu(int socket, struct user_record *user) { subject = strdup(buffer); // post a message - msg = external_editor(socket, user, to, from, NULL, NULL, subject, 0); + msg = external_editor(user, to, from, NULL, NULL, subject, 0); if (msg != NULL) { jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path); @@ -1599,7 +1583,7 @@ int mail_menu(int socket, struct user_record *user) { break; case 'l': { - s_putstring(socket, "\r\n"); + s_printf("\r\n"); // list mail in message base msghs = read_message_headers(user->cur_mail_conf, user->cur_mail_area, user); if (msghs != NULL && msghs->msg_count > 0) { @@ -1615,10 +1599,9 @@ int mail_menu(int socket, struct user_record *user) { all_unread = 1; } JAM_CloseMB(jb); - sprintf(buffer, "Start at message [1-%d] or N for New? ", msghs->msg_count); - s_putstring(socket, buffer); - - s_readstring(socket, buffer, 6); + s_printf("Start at message [1-%d] or N for New? ", msghs->msg_count); + + s_readstring(buffer, 6); if (tolower(buffer[0]) == 'n') { if (all_unread == 0) { k = jlr.HighReadMsg; @@ -1638,21 +1621,19 @@ int mail_menu(int socket, struct user_record *user) { } } closed = 0; - s_putstring(socket, "\e[2J\e[1;37;44m[MSG#] Subject From To Date \r\n\e[0m"); + s_printf("\e[2J\e[1;37;44m[MSG#] Subject From To Date \r\n\e[0m"); for (j=i-1;jmsg_count;j++) { localtime_r((time_t *)&msghs->msgs[j]->msg_h->DateWritten, &msg_date); if (msghs->msgs[j]->msg_no > jlr.HighReadMsg || all_unread) { - sprintf(buffer, "\e[1;30m[\e[1;34m%4d\e[1;30m]\e[1;32m*\e[1;37m%-25.25s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[0m\r\n", j + 1, msghs->msgs[j]->subject, msghs->msgs[j]->from, msghs->msgs[j]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + s_printf("\e[1;30m[\e[1;34m%4d\e[1;30m]\e[1;32m*\e[1;37m%-25.25s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[0m\r\n", j + 1, msghs->msgs[j]->subject, msghs->msgs[j]->from, msghs->msgs[j]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } else { - sprintf(buffer, "\e[1;30m[\e[1;34m%4d\e[1;30m] \e[1;37m%-25.25s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[0m\r\n", j + 1, msghs->msgs[j]->subject, msghs->msgs[j]->from, msghs->msgs[j]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); + s_printf("\e[1;30m[\e[1;34m%4d\e[1;30m] \e[1;37m%-25.25s \e[1;32m%-15.15s \e[1;33m%-15.15s \e[1;35m%02d:%02d %02d-%02d-%02d\e[0m\r\n", j + 1, msghs->msgs[j]->subject, msghs->msgs[j]->from, msghs->msgs[j]->to, msg_date.tm_hour, msg_date.tm_min, msg_date.tm_mday, msg_date.tm_mon + 1, msg_date.tm_year - 100); } - s_putstring(socket, buffer); - + if ((j - (i - 1)) != 0 && (j - (i - 1)) % 20 == 0) { - sprintf(buffer, "(#) Read Message # (Q) Quit (ENTER) Continue\r\n"); - s_putstring(socket, buffer); - s_readstring(socket, buffer, 6); + s_printf("(#) Read Message # (Q) Quit (ENTER) Continue\r\n"); + s_readstring(buffer, 6); if (tolower(buffer[0]) == 'q') { closed = 1; @@ -1665,14 +1646,13 @@ int mail_menu(int socket, struct user_record *user) { break; } } - s_putstring(socket, "\e[2J\e[1;37;44m[MSG#] Subject From To Date \r\n\e[0m"); + s_printf("\e[2J\e[1;37;44m[MSG#] Subject From To Date \r\n\e[0m"); } } if (closed == 0) { - sprintf(buffer, "(#) Read Message # (ENTER) Quit\r\n"); - s_putstring(socket, buffer); - s_readstring(socket, buffer, 6); + s_printf("(#) Read Message # (ENTER) Quit\r\n"); + s_readstring(buffer, 6); if (strlen(buffer) > 0) { z = atoi(buffer); if (z > 0 && z <= msghs->msg_count) { @@ -1686,31 +1666,30 @@ int mail_menu(int socket, struct user_record *user) { free_message_headers(msghs); } } else { - s_putstring(socket, "\r\nThere is no mail in this area\r\n"); + s_printf("\r\nThere is no mail in this area\r\n"); } } break; case 'c': { - s_putstring(socket, "\r\n\r\nMail Conferences:\r\n\r\n"); + s_printf("\r\n\r\nMail Conferences:\r\n\r\n"); for (i=0;isec_level <= user->sec_level) { - sprintf(buffer, " %d. %s\r\n", i, conf.mail_conferences[i]->name); - s_putstring(socket, buffer); - } + s_printf(" %d. %s\r\n", i, conf.mail_conferences[i]->name); + } if (i != 0 && i % 20 == 0) { - s_putstring(socket, "Press any key to continue...\r\n"); - c = s_getc(socket); + s_printf("Press any key to continue...\r\n"); + c = s_getc(); } } - s_putstring(socket, "Enter the conference number: "); - s_readstring(socket, buffer, 5); + s_printf("Enter the conference number: "); + s_readstring(buffer, 5); if (tolower(buffer[0]) != 'q') { j = atoi(buffer); if (j < 0 || j >= conf.mail_conference_count || conf.mail_conferences[j]->sec_level > user->sec_level) { - s_putstring(socket, "\r\nInvalid conference number!\r\n"); + s_printf("\r\nInvalid conference number!\r\n"); } else { - s_putstring(socket, "\r\n"); + s_printf("\r\n"); user->cur_mail_conf = j; user->cur_mail_area = 0; } @@ -1719,25 +1698,24 @@ int mail_menu(int socket, struct user_record *user) { break; case 'a': { - s_putstring(socket, "\r\n\r\nMail Areas:\r\n\r\n"); + s_printf("\r\n\r\nMail Areas:\r\n\r\n"); for (i=0;icur_mail_conf]->mail_area_count;i++) { if (conf.mail_conferences[user->cur_mail_conf]->mail_areas[i]->read_sec_level <= user->sec_level) { - sprintf(buffer, " %d. %s\r\n", i, conf.mail_conferences[user->cur_mail_conf]->mail_areas[i]->name); - s_putstring(socket, buffer); - } + s_printf(" %d. %s\r\n", i, conf.mail_conferences[user->cur_mail_conf]->mail_areas[i]->name); + } if (i != 0 && i % 20 == 0) { - s_putstring(socket, "Press any key to continue...\r\n"); - c = s_getc(socket); + s_printf("Press any key to continue...\r\n"); + c = s_getc(); } } - s_putstring(socket, "Enter the area number: "); - s_readstring(socket, buffer, 5); + s_printf("Enter the area number: "); + s_readstring(buffer, 5); if (tolower(buffer[0]) != 'q') { j = atoi(buffer); if (j < 0 || j >= conf.mail_conferences[user->cur_mail_conf]->mail_area_count || conf.mail_conferences[user->cur_mail_conf]->mail_areas[j]->read_sec_level > user->sec_level) { - s_putstring(socket, "\r\nInvalid area number!\r\n"); + s_printf("\r\nInvalid area number!\r\n"); } else { - s_putstring(socket, "\r\n"); + s_printf("\r\n"); user->cur_mail_area = j; } } @@ -1750,8 +1728,8 @@ int mail_menu(int socket, struct user_record *user) { break; case 'g': { - s_putstring(socket, "\r\nAre you sure you want to log off? (Y/N)"); - c = s_getc(socket); + s_printf("\r\nAre you sure you want to log off? (Y/N)"); + c = s_getc(); if (tolower(c) == 'y') { domail = 1; doquit = 1; @@ -1760,14 +1738,14 @@ int mail_menu(int socket, struct user_record *user) { break; case 'e': { - send_email(socket, user); + send_email(user); } break; case 'r': { // Read your email... - s_putstring(socket, "\r\n"); - list_emails(socket, user); + s_printf("\r\n"); + list_emails(user); } break; case '}': @@ -1832,7 +1810,7 @@ int mail_menu(int socket, struct user_record *user) { return doquit; } -void mail_scan(int socket, struct user_record *user) { +void mail_scan(struct user_record *user) { s_JamBase *jb; s_JamBaseHeader jbh; s_JamLastRead jlr; @@ -1843,17 +1821,16 @@ void mail_scan(int socket, struct user_record *user) { char buffer[256]; int count; - s_putstring(socket, "\r\nScan for new mail? (Y/N) : "); - c = s_getc(socket); + s_printf("\r\nScan for new mail? (Y/N) : "); + c = s_getc(); if (tolower(c) == 'y') { for (i=0;isec_level > user->sec_level) { continue; } - sprintf(buffer, "\r\n%d. %s\r\n", i, conf.mail_conferences[i]->name); - s_putstring(socket, buffer); - for (j=0;jmail_area_count;j++) { + s_printf("\r\n%d. %s\r\n", i, conf.mail_conferences[i]->name); + for (j=0;jmail_area_count;j++) { if (conf.mail_conferences[i]->mail_areas[j]->read_sec_level > user->sec_level) { continue; } @@ -1871,21 +1848,19 @@ void mail_scan(int socket, struct user_record *user) { JAM_CloseMB(jb); continue; } - sprintf(buffer, " --> %d. %s (%d new)\r\n", j, conf.mail_conferences[i]->mail_areas[j]->name, jbh.ActiveMsgs); + s_printf(" --> %d. %s (%d new)\r\n", j, conf.mail_conferences[i]->mail_areas[j]->name, jbh.ActiveMsgs); } else { if (jlr.HighReadMsg < (jbh.ActiveMsgs - 1)) { - sprintf(buffer, " --> %d. %s (%d new)\r\n", j, conf.mail_conferences[i]->mail_areas[j]->name, (jbh.ActiveMsgs - 1) - jlr.HighReadMsg); + s_printf(" --> %d. %s (%d new)\r\n", j, conf.mail_conferences[i]->mail_areas[j]->name, (jbh.ActiveMsgs - 1) - jlr.HighReadMsg); } else { JAM_CloseMB(jb); continue; } } - s_putstring(socket, buffer); - JAM_CloseMB(jb); + JAM_CloseMB(jb); } } - sprintf(buffer, "\r\nPress any key to continue...\r\n"); - s_putstring(socket, buffer); - s_getc(socket); + s_printf("\r\nPress any key to continue...\r\n"); + s_getc(); } } diff --git a/main_menu.c b/main_menu.c index a0484ca..1bfbda3 100644 --- a/main_menu.c +++ b/main_menu.c @@ -10,7 +10,7 @@ extern struct bbs_config conf; -void main_menu(int socket, struct user_record *user) { +void main_menu(struct user_record *user) { int doquit = 0; char c; char prompt[128]; @@ -45,13 +45,12 @@ void main_menu(int socket, struct user_record *user) { while (!doquit) { if (do_internal_menu == 1) { - s_displayansi(socket, "mainmenu"); + s_displayansi("mainmenu"); - sprintf(prompt, "\r\n\e[0mTL: %dm :> ", user->timeleft); - s_putstring(socket, prompt); + s_printf("\r\n\e[0mTL: %dm :> ", user->timeleft); - c = s_getc(socket); + c = s_getc(); } else { lua_getglobal(L, "menu"); result = lua_pcall(L, 0, 1, 0); @@ -77,49 +76,48 @@ void main_menu(int socket, struct user_record *user) { if (conf.text_file_count > 0) { while(1) { - s_putstring(socket, "\r\n\e[1;32mText Files Collection\r\n"); - s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); + s_printf("\r\n\e[1;32mText Files Collection\r\n"); + s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); for (i=0;iname); - s_putstring(socket, buffer); + s_printf("\e[1;30m[\e[1;34m%3d\e[1;30m] \e[1;37m%s\r\n", i, conf.text_files[i]->name); } - s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); - s_putstring(socket, "Enter the number of a text file to display or Q to quit: "); - s_readstring(socket, buffer, 4); + s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); + s_printf("Enter the number of a text file to display or Q to quit: "); + s_readstring(buffer, 4); if (tolower(buffer[0]) != 'q') { i = atoi(buffer); if (i >= 0 && i < conf.text_file_count) { - s_putstring(socket, "\r\n"); - s_displayansi_p(socket, conf.text_files[i]->path); - s_putstring(socket, "Press any key to continue..."); - s_getc(socket); - s_putstring(socket, "\r\n"); + s_printf("\r\n"); + s_displayansi_p(conf.text_files[i]->path); + s_printf("Press any key to continue..."); + s_getc(); + s_printf("\r\n"); } } else { break; } } } else { - s_putstring(socket, "\r\nSorry, there are no text files to display\r\n"); - s_putstring(socket, "Press any key to continue...\r\n"); - s_getc(socket); + s_printf("\r\nSorry, there are no text files to display\r\n"); + s_printf("Press any key to continue...\r\n"); + s_getc(); } } break; case 'c': { - chat_system(socket, user); + chat_system(user); } break; case 'l': { - bbs_list(socket, user); + bbs_list(user); } break; case 'u': { - list_users(socket, user); + list_users(user); } break; case 'b': @@ -129,10 +127,9 @@ void main_menu(int socket, struct user_record *user) { while (stat(buffer, &s) == 0) { sprintf(buffer, "bulletin%d", i); - s_displayansi(socket, buffer); - sprintf(buffer, "\e[0mPress any key to continue...\r\n"); - s_putstring(socket, buffer); - s_getc(socket); + s_displayansi(buffer); + s_printf("\e[0mPress any key to continue...\r\n"); + s_getc(); i++; sprintf(buffer, "%s/bulletin%d.ans", conf.ansi_path, i); } @@ -140,23 +137,23 @@ void main_menu(int socket, struct user_record *user) { break; case '1': { - display_last10_callers(socket, user); + display_last10_callers(user); } break; case 'd': { - doquit = door_menu(socket, user); + doquit = door_menu(user); } break; case 'm': { - doquit = mail_menu(socket, user); + doquit = mail_menu(user); } break; case 'g': { - s_putstring(socket, "\r\nAre you sure you want to log off? (Y/N)"); - c = s_getc(socket); + s_printf("\r\nAre you sure you want to log off? (Y/N)"); + c = s_getc(); if (tolower(c) == 'y') { doquit = 1; } @@ -164,12 +161,12 @@ void main_menu(int socket, struct user_record *user) { break; case 't': { - doquit = file_menu(socket, user); + doquit = file_menu(user); } break; case 's': { - settings_menu(socket, user); + settings_menu(user); } break; } diff --git a/settings.c b/settings.c index 1411cea..ca1466d 100644 --- a/settings.c +++ b/settings.c @@ -4,32 +4,31 @@ #include #include "bbs.h" -void settings_menu(int sock, struct user_record *user) { +void settings_menu(struct user_record *user) { char buffer[256]; int dosettings = 0; char c; char *hash; while (!dosettings) { - s_putstring(sock, "\e[2J\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"); + s_printf("\e[2J\e[1;32mYour Settings\r\n"); + s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); + s_printf("\e[0;36mP. \e[1;37mPassword (\e[1;33mNot Shown\e[1;37m)\r\n"); + s_printf("\e[0;36mL. \e[1;37mLocation (\e[1;33m%s\e[1;37m)\r\n", user->location); + s_printf("\e[0;36mQ. \e[1;37mQuit to Main Menu\r\n"); + s_printf("\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); - c = s_getc(sock); + c = s_getc(); switch(tolower(c)) { case 'p': { - s_putstring(sock, "\r\nEnter your current password: "); - s_readpass(sock, buffer, 16); + s_printf("\r\nEnter your current password: "); + s_readpass(buffer, 16); hash = hash_sha256(buffer, user->salt); if (strcmp(hash, user->password) == 0) { - s_putstring(sock, "\r\nEnter your new password (8 chars min): "); - s_readstring(sock, buffer, 16); + s_printf("\r\nEnter your new password (8 chars min): "); + s_readstring(buffer, 16); if (strlen(buffer) >= 8) { free(user->password); free(user->salt); @@ -38,19 +37,19 @@ void settings_menu(int sock, struct user_record *user) { user->password = hash_sha256(buffer, user->salt); save_user(user); - s_putstring(sock, "\r\nPassword Changed!\r\n"); + s_printf("\r\nPassword Changed!\r\n"); } else { - s_putstring(sock, "\r\nPassword too short!\r\n"); + s_printf("\r\nPassword too short!\r\n"); } } else { - s_putstring(sock, "\r\nPassword Incorrect!\r\n"); + s_printf("\r\nPassword Incorrect!\r\n"); } } break; case 'l': { - s_putstring(sock, "\r\nEnter your new location: "); - s_readstring(sock, buffer, 32); + s_printf("\r\nEnter your new location: "); + s_readstring(buffer, 32); free(user->location); user->location = (char *)malloc(strlen(buffer) + 1); strcpy(user->location, buffer); diff --git a/users.c b/users.c index 3d657e8..0d94fc3 100644 --- a/users.c +++ b/users.c @@ -219,7 +219,7 @@ int inst_user(struct user_record *user) { return 1; } -struct user_record *check_user_pass(int socket, char *loginname, char *password) { +struct user_record *check_user_pass(char *loginname, char *password) { struct user_record *user; char buffer[256]; sqlite3 *db; @@ -322,7 +322,7 @@ struct user_record *check_user_pass(int socket, char *loginname, char *password) return user; } -void list_users(int socket, struct user_record *user) { +void list_users(struct user_record *user) { char buffer[256]; sqlite3 *db; sqlite3_stmt *res; @@ -346,70 +346,67 @@ void list_users(int socket, struct user_record *user) { sqlite3_close(db); exit(1); } - s_putstring(socket, "\e[2J\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"); + s_printf("\e[2J\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); + s_printf("User Name Location Times On\r\n"); + s_printf("\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); + s_printf("\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)); i++; if (i == 20) { - sprintf(buffer, "Press any key to continue...\r\n"); - s_putstring(socket, buffer); - s_getc(socket); + s_printf("Press any key to continue...\r\n"); + s_getc(); i = 0; } } - s_putstring(socket, "\e[1;30m-------------------------------------------------------------------------------\e[0m\r\n"); - sqlite3_finalize(res); - sqlite3_close(db); + s_printf("\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); + s_printf("Press any key to continue...\r\n"); + s_getc(); } int check_user(char *loginname) { char buffer[256]; sqlite3 *db; - sqlite3_stmt *res; - int rc; - char *sql = "SELECT * FROM users WHERE loginname = ?"; + sqlite3_stmt *res; + int rc; + char *sql = "SELECT * FROM users WHERE loginname = ?"; sprintf(buffer, "%s/users.sq3", conf.bbs_path); rc = sqlite3_open(buffer, &db); if (rc != SQLITE_OK) { - dolog("Cannot open database: %s", sqlite3_errmsg(db)); - sqlite3_close(db); + dolog("Cannot open database: %s", sqlite3_errmsg(db)); + sqlite3_close(db); - exit(1); - } - rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); + exit(1); + } + rc = sqlite3_prepare_v2(db, sql, -1, &res, 0); - if (rc == SQLITE_OK) { - sqlite3_bind_text(res, 1, loginname, -1, 0); - } else { - dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); - } + if (rc == SQLITE_OK) { + sqlite3_bind_text(res, 1, loginname, -1, 0); + } else { + dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); + } - int step = sqlite3_step(res); + int step = sqlite3_step(res); - if (step == SQLITE_ROW) { + if (step == SQLITE_ROW) { sqlite3_finalize(res); sqlite3_close(db); return 0; - } + } - sqlite3_finalize(res); - sqlite3_close(db); - return 1; + sqlite3_finalize(res); + sqlite3_close(db); + return 1; } -struct user_record *new_user(int socket) { +struct user_record *new_user() { char buffer[256]; struct user_record *user; int done = 0; @@ -419,24 +416,24 @@ struct user_record *new_user(int socket) { int i; user = (struct user_record *)malloc(sizeof(struct user_record)); - s_putstring(socket, "\r\n\r\n"); - s_displayansi(socket, "newuser"); + s_printf("\r\n\r\n"); + s_displayansi("newuser"); do { passok = 0; nameok = 0; do { - s_putstring(socket, "\r\nWhat is your login name: "); - s_readstring(socket, buffer, 16); - s_putstring(socket, "\r\n"); + s_printf("\r\nWhat is your login name: "); + s_readstring(buffer, 16); + s_printf("\r\n"); if (strlen(buffer) < 3) { - s_putstring(socket, "Sorry, that name is too short.\r\n"); + s_printf("Sorry, that name is too short.\r\n"); continue; } for (i=0;i= 97 && tolower(buffer[i]) <= 122)) { - s_putstring(socket, "Sorry, invalid character, can only use alpha characters.\r\n"); + s_printf("Sorry, invalid character, can only use alpha characters.\r\n"); nameok = 1; break; } @@ -446,80 +443,80 @@ struct user_record *new_user(int socket) { continue; } if (strcasecmp(buffer, "unknown") == 0) { - s_putstring(socket, "Sorry, that name is reserved.\r\n"); + s_printf("Sorry, that name is reserved.\r\n"); continue; } if (strcasecmp(buffer, "all") == 0) { - s_putstring(socket, "Sorry, that name is reserved.\r\n"); + s_printf("Sorry, that name is reserved.\r\n"); continue; } if (strcasecmp(buffer, "new") == 0) { - s_putstring(socket, "Sorry, that name is reserved.\r\n"); + s_printf("Sorry, that name is reserved.\r\n"); continue; } user->loginname = strdup(buffer); nameok = check_user(user->loginname); if (!nameok) { - s_putstring(socket, "Sorry, that name is in use.\r\n"); + s_printf("Sorry, that name is in use.\r\n"); free(user->loginname); memset(buffer, 0, 256); } } while (!nameok); - s_putstring(socket, "What is your first name: "); + s_printf("What is your first name: "); memset(buffer, 0, 256); - s_readstring(socket, buffer, 32); - s_putstring(socket, "\r\n"); + s_readstring(buffer, 32); + s_printf("\r\n"); user->firstname = strdup(buffer); - s_putstring(socket, "What is your last name: "); + s_printf("What is your last name: "); memset(buffer, 0, 256); - s_readstring(socket, buffer, 32); - s_putstring(socket, "\r\n"); + s_readstring(buffer, 32); + s_printf("\r\n"); user->lastname = strdup(buffer); - s_putstring(socket, "What is your e-mail address: "); + s_printf("What is your e-mail address: "); memset(buffer, 0, 256); - s_readstring(socket, buffer, 64); - s_putstring(socket, "\r\n"); + s_readstring(buffer, 64); + s_printf("\r\n"); user->email = strdup(buffer); - s_putstring(socket, "Where are you located: "); + s_printf("Where are you located: "); memset(buffer, 0, 256); - s_readstring(socket, buffer, 32); - s_putstring(socket, "\r\n"); + s_readstring(buffer, 32); + s_printf("\r\n"); user->location = strdup(buffer); do { - s_putstring(socket, "What password would you like (at least 8 characters): "); + s_printf("What password would you like (at least 8 characters): "); memset(buffer, 0, 256); - s_readstring(socket, buffer, 16); - s_putstring(socket, "\r\n"); + s_readstring(buffer, 16); + s_printf("\r\n"); if (strlen(buffer) >= 8) { passok = 1; } else { - s_putstring(socket, "Password too short!\r\n"); + s_printf("Password too short!\r\n"); } } while (!passok); gen_salt(&user->salt); user->password = hash_sha256(buffer, user->salt); - s_putstring(socket, "You Entered:\r\n"); - s_putstring(socket, "-------------------------------------\r\n"); - s_putstring(socket, "Login Name: "); - s_putstring(socket, user->loginname); - s_putstring(socket, "\r\nFirst Name: "); - s_putstring(socket, user->firstname); - s_putstring(socket, "\r\nLast Name: "); - s_putstring(socket, user->lastname); - s_putstring(socket, "\r\nE-mail: "); - s_putstring(socket, user->email); - s_putstring(socket, "\r\nLocation: "); - s_putstring(socket, user->location); - s_putstring(socket, "\r\n-------------------------------------\r\n"); - s_putstring(socket, "Is this Correct? (Y/N)"); - c = s_getchar(socket); + s_printf("You Entered:\r\n"); + s_printf("-------------------------------------\r\n"); + s_printf("Login Name: "); + s_printf(user->loginname); + s_printf("\r\nFirst Name: "); + s_printf(user->firstname); + s_printf("\r\nLast Name: "); + s_printf(user->lastname); + s_printf("\r\nE-mail: "); + s_printf(user->email); + s_printf("\r\nLocation: "); + s_printf(user->location); + s_printf("\r\n-------------------------------------\r\n"); + s_printf("Is this Correct? (Y/N)"); + c = s_getchar(); while (tolower(c) != 'y' && tolower(c) != 'n') { - c = s_getchar(socket); + c = s_getchar(); } if (tolower(c) == 'y') {