diff --git a/.gitignore b/.gitignore index 534d74f..0cb8e07 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ last10.dat ansis/* config/* illusion/* +scripts/* logs/* *.a lua/lua diff --git a/bbs.c b/bbs.c index efc24d5..f826200 100644 --- a/bbs.c +++ b/bbs.c @@ -119,7 +119,7 @@ void timer_handler(int signum) { if (gUser->timeleft <= 0) { s_putstring(gSocket, "\r\n\r\nSorry, you're out of time today..\r\n"); - disconnect(gSocket); + disconnect(gSocket, "Out of Time"); } @@ -129,7 +129,7 @@ void timer_handler(int signum) { } if (usertimeout <= 0) { s_putstring(gSocket, "\r\n\r\nTimeout waiting for input..\r\n"); - disconnect(gSocket); + disconnect(gSocket, "Timeout"); } } } @@ -464,24 +464,24 @@ char s_getchar(int socket) { len = read(socket, &c, 1); if (len == 0) { - disconnect(socket); + disconnect(socket, "Socket Closed"); } while (c == 255) { len = read(socket, &c, 1); if (len == 0) { - disconnect(socket); + disconnect(socket, "Socket Closed"); } else if (c == 255) { usertimeout = 10; return c; } len = read(socket, &c, 1); if (len == 0) { - disconnect(socket); + disconnect(socket, "Socket Closed"); } len = read(socket, &c, 1); if (len == 0) { - disconnect(socket); + disconnect(socket, "Socket Closed"); } } @@ -489,7 +489,7 @@ char s_getchar(int socket) { if (c == '\r') { if (len == 0) { - disconnect(socket); + disconnect(socket, "Socket Closed"); } } } while (c == '\n'); @@ -551,12 +551,12 @@ void s_readpass(int socket, char *buffer, int max) { } } -void disconnect(int socket) { +void disconnect(int socket, char *calledby) { char buffer[256]; if (gUser != NULL) { save_user(gUser); } - dolog("Node %d disconnected", mynode); + dolog("Node %d disconnected (%s)", mynode, calledby); sprintf(buffer, "%s/nodeinuse.%d", conf.bbs_path, mynode); remove(buffer); close(socket); @@ -842,8 +842,6 @@ void runbbs(int socket, char *config_path, char *ip) { s_displayansi(socket, "issue"); - - s_putstring(socket, "\e[0mEnter your Login Name or NEW to create an account\r\n"); s_putstring(socket, "Login:> "); @@ -857,7 +855,7 @@ void runbbs(int socket, char *config_path, char *ip) { user = check_user_pass(socket, buffer, password); if (user == NULL) { s_putstring(socket, "\r\nIncorrect Login.\r\n"); - disconnect(socket); + disconnect(socket, "Incorrect Login"); } for (i=1;i<=conf.nodes;i++) { @@ -866,14 +864,14 @@ void runbbs(int socket, char *config_path, char *ip) { nodefile = fopen(buffer, "r"); if (!nodefile) { printf("Error opening nodefile!\n"); - disconnect(socket); + disconnect(socket, "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); + disconnect(socket, "Already Logged in"); } fclose(nodefile); } @@ -966,5 +964,5 @@ void runbbs(int socket, char *config_path, char *ip) { s_displayansi(socket, "goodbye"); dolog("%s is logging out, on node %d", user->loginname, mynode); - disconnect(socket); + disconnect(socket, "Log out"); } diff --git a/bbs.h b/bbs.h index 5024608..ef95312 100644 --- a/bbs.h +++ b/bbs.h @@ -147,7 +147,7 @@ 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); +extern void disconnect(int socket, char *calledby); extern void display_info(int socket); extern void display_last10_callers(int socket, struct user_record *user); diff --git a/chat_system.c b/chat_system.c index 85f9a95..aefbf9e 100644 --- a/chat_system.c +++ b/chat_system.c @@ -172,7 +172,7 @@ void chat_system(int sock, struct user_record *user) { len = read(sock, &c, 1); if (len == 0) { raw("QUIT\r\n"); - disconnect(sock); + disconnect(sock, "Socket closed"); } if (c == '\r') { diff --git a/doors.c b/doors.c index e9e7438..f7c3d05 100644 --- a/doors.c +++ b/doors.c @@ -204,7 +204,7 @@ void rundoor(int socket, struct user_record *user, char *cmd, int stdio) { len = read(socket, &c, 1); if (len == 0) { close(master); - disconnect(socket); + disconnect(socket, "Socket Closed"); return; } if (c == '\n' || c == '\0') { diff --git a/files.c b/files.c index 6b947f1..e71e16a 100644 --- a/files.c +++ b/files.c @@ -128,7 +128,7 @@ int doIO(ZModem *zm) { } else if (i > 0) { len = read(zm->ifd, buffer, 2048); if (len == 0) { - disconnect(zm->ifd); + disconnect(zm->ifd, "Socket closed"); } pos = 0; diff --git a/main.c b/main.c index 38149ee..b57b306 100644 --- a/main.c +++ b/main.c @@ -64,6 +64,13 @@ int main(int argc, char **argv) { c = sizeof(struct sockaddr_in); while ((client_sock = accept(socket_desc, (struct sockaddr *)&client, (socklen_t *)&c))) { + if (client_sock == -1) { + if (errno == EINTR) { + continue; + } else { + exit(-1); + } + } pid = fork(); if (pid < 0) {