diff --git a/ChangeLog b/ChangeLog index 3eec9768..53233a8e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -59,6 +59,12 @@ v0.37.2 23-Feb-2003. or stops. Reports a page from a user in row 3 of the screen (but doesn't do chat right now). + Adjusts its screensize if the environment variables LINES and + COLUMNS are set. + (in ~/.profile add the line "export LINES COLUMNS"). + The show lastcallers now adjusts the number of lines available. + The show server clients screen now adjusts to the number of + lines available. mbtask: Safer logging of user log messages. diff --git a/Makefile b/Makefile index ff0f9035..1b811316 100644 --- a/Makefile +++ b/Makefile @@ -182,6 +182,10 @@ install: rm ${BINDIR}/fbutil ; \ echo "removed ${BINDIR}/fbutil "; \ fi + @if [ -x ${BINDIR}/mbchat ]; then \ + rm ${BINDIR}/mbchat ; \ + echo "removed ${BINDIR}/mbchat"; \ + fi for d in ${SUBDIRS}; do (cd $$d && ${MAKE} $@) || exit; done dist tar: ${TARFILE} diff --git a/TODO b/TODO index 90f1bd08..68e64118 100644 --- a/TODO +++ b/TODO @@ -13,6 +13,10 @@ $Id$ N = Normal, second priority. L = Cosmetic or nice to have. +install: + N: On some (unsupported) distro's with xinetd the installation script + also adds entries to inetd.conf. + libdiesel.a: U: Processed stringlines containing unbalanced " characters are not processed, instead the previous macro value will be returned. diff --git a/mbmon/Makefile b/mbmon/Makefile index 3e368304..b75d0a39 100644 --- a/mbmon/Makefile +++ b/mbmon/Makefile @@ -58,6 +58,6 @@ depend: # DO NOT DELETE THIS LINE - MAKE DEPEND RELIES ON IT # Dependencies generated by make depend mutil.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mberrors.h common.h mutil.h -mbmon.o: ../config.h ../lib/libs.h ../lib/memwatch.h common.h mutil.h +mbmon.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mberrors.h common.h mutil.h common.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mberrors.h common.h # End of generated dependencies diff --git a/mbmon/common.c b/mbmon/common.c index 14be8567..579fcd1c 100644 --- a/mbmon/common.c +++ b/mbmon/common.c @@ -51,7 +51,7 @@ int fromlen; static char spath[PATH_MAX]; /* Server socket path */ static char cpath[PATH_MAX]; /* Client socket path */ - +extern int lines, columns; void InitClient(char *user) @@ -837,7 +837,7 @@ void clear() */ void locate(int y, int x) { - if (y > LINES || x > COLS) { + if (y > lines || x > columns) { printf("ANSI: Invalid screen coordinates: %i, %i\n", y, x); return; } diff --git a/mbmon/common.h b/mbmon/common.h index 7e2985b0..0de2e21d 100644 --- a/mbmon/common.h +++ b/mbmon/common.h @@ -1,6 +1,7 @@ #ifndef _COMMON_H #define _COMMON_H +/* $Id$ */ #pragma pack(1) @@ -28,13 +29,6 @@ #define KEY_PGDN 209 -#ifndef LINES -#define LINES 24 -#endif -#ifndef COLS -#define COLS 80 -#endif - /* * ANSI colors diff --git a/mbmon/mbmon.c b/mbmon/mbmon.c index 1467cf4a..4d5b2556 100644 --- a/mbmon/mbmon.c +++ b/mbmon/mbmon.c @@ -32,11 +32,17 @@ #include "../config.h" #include "../lib/libs.h" #include "../lib/memwatch.h" +#include "../lib/mberrors.h" #include "common.h" #include "mutil.h" -extern int bbs_free; +int lines = 24; +int columns = 80; + +extern int bbs_free; +extern int ttyfd; +extern pid_t mypid; static void die(int onsig) @@ -50,7 +56,7 @@ static void die(int onsig) else Syslog(' ', "Normally finished"); - sprintf(buf, "CSYS:1,0;"); + sprintf(buf, "CSYS:2,%d,0;", mypid); if (socket_send(buf) == 0) sprintf(buf, "%s", socket_receive()); ExitClient(0); @@ -60,175 +66,168 @@ static void die(int onsig) void ShowSysinfo(void) { - int ch; - char buf[128], *cnt; + int ch; + char buf[128], *cnt; - clr_index(); - set_color(WHITE, BLACK); - mvprintw( 5, 6, "4. SHOW BBS SYSTEM INFO"); - set_color(CYAN, BLACK); - mvprintw( 7, 6, "1. Total calls"); - mvprintw( 8, 6, "2. Pots calls"); - mvprintw( 9, 6, "3. ISDN calls"); - mvprintw(10, 6, "4. Network calls"); - mvprintw(11, 6, "5. Local calls"); - mvprintw(12, 6, "6. Date started"); - mvprintw(13, 6, "7. Last caller"); - center_addstr(LINES - 4, (char *)"Press any key"); - IsDoing("View System Info"); + clr_index(); + set_color(WHITE, BLACK); + mvprintw( 5, 6, "4. SHOW BBS SYSTEM INFO"); + set_color(CYAN, BLACK); + mvprintw( 7, 6, "1. Total calls"); + mvprintw( 8, 6, "2. Pots calls"); + mvprintw( 9, 6, "3. ISDN calls"); + mvprintw(10, 6, "4. Network calls"); + mvprintw(11, 6, "5. Local calls"); + mvprintw(12, 6, "6. Date started"); + mvprintw(13, 6, "7. Last caller"); + center_addstr(lines - 3, (char *)"Press any key"); + IsDoing("View System Info"); - do { - show_date(LIGHTGRAY, BLACK, 0, 0); - set_color(LIGHTGRAY, BLACK); - sprintf(buf, "GSYS:1,%d;", getpid()); - if (socket_send(buf) == 0) { - sprintf(buf, "%s", socket_receive()); - if (strncmp(buf, "100:7,", 6) == 0) { - cnt = strtok(buf, ","); - mvprintw( 7,26, "%s", strtok(NULL, ",")); - mvprintw( 8,26, "%s", strtok(NULL, ",")); - mvprintw( 9,26, "%s", strtok(NULL, ",")); - mvprintw(10,26, "%s", strtok(NULL, ",")); - mvprintw(11,26, "%s", strtok(NULL, ",")); - mvprintw(12,26, "%s", strtok(NULL, ",")); - mvprintw(13,26, "%s", strtok(NULL, ";")); - fflush(stdout); - } - } - ch = testkey(LINES - 4, COLS / 2 + 8); - } while (ch == '\0'); + do { + show_date(LIGHTGRAY, BLACK, 0, 0); + set_color(LIGHTGRAY, BLACK); + sprintf(buf, "GSYS:1,%d;", getpid()); + if (socket_send(buf) == 0) { + sprintf(buf, "%s", socket_receive()); + if (strncmp(buf, "100:7,", 6) == 0) { + cnt = strtok(buf, ","); + mvprintw( 7,26, "%s", strtok(NULL, ",")); + mvprintw( 8,26, "%s", strtok(NULL, ",")); + mvprintw( 9,26, "%s", strtok(NULL, ",")); + mvprintw(10,26, "%s", strtok(NULL, ",")); + mvprintw(11,26, "%s", strtok(NULL, ",")); + mvprintw(12,26, "%s", strtok(NULL, ",")); + mvprintw(13,26, "%s", strtok(NULL, ";")); + fflush(stdout); + } + } + ch = testkey(lines - 3, columns / 2 + 8); + } while (ch == '\0'); } void ShowLastcaller(void) { - int records, ch, i, y, o; - char buf[128], *cnt; + int records, maxrows, ch, i, y, o; + char buf[128], *cnt; - clr_index(); - set_color(WHITE, BLACK); - mvprintw( 4, 6, "5. SHOW BBS LASTCALLERS"); - set_color(YELLOW, RED); - mvprintw( 6, 1, "Nr Username Location Level Device Time Mins Calls Speed Actions "); - set_color(CYAN, BLACK); - center_addstr(LINES - 4, (char *)"Press any key"); - IsDoing("View Lastcallers"); + clr_index(); + set_color(WHITE, BLACK); + mvprintw( 4, 6, "5. SHOW BBS LASTCALLERS"); + set_color(YELLOW, RED); + mvprintw( 6, 1, "Nr Username Location Level Device Time Mins Calls Speed Actions "); + set_color(CYAN, BLACK); + center_addstr(lines - 1, (char *)"Press any key"); + IsDoing("View Lastcallers"); + maxrows = lines - 10; - do { - show_date(LIGHTGRAY, BLACK, 0, 0); - records = 0; - sprintf(buf, "GLCC:0;"); + do { + show_date(LIGHTGRAY, BLACK, 0, 0); + records = 0; + sprintf(buf, "GLCC:0;"); + if (socket_send(buf) == 0) { + sprintf(buf, "%s", socket_receive()); + if (strncmp(buf, "100:1,", 6) == 0) { + cnt = strtok(buf, ","); + records = atoi(strtok(NULL, ";")); + } + } + + if (records) { + y = 7; + if (records > maxrows) + o = records - maxrows; + else + o = 1; + set_color(CYAN, BLACK); + for (i = o; i <= records; i++) { + sprintf(buf, "GLCR:1,%d;", i); if (socket_send(buf) == 0) { - sprintf(buf, "%s", socket_receive()); - if (strncmp(buf, "100:1,", 6) == 0) { - cnt = strtok(buf, ","); - records = atoi(strtok(NULL, ";")); - } + sprintf(buf, "%s", socket_receive()); + if (strncmp(buf, "100:9,", 6) == 0) { + cnt = strtok(buf, ","); + mvprintw(y, 1, "%2d", i); + mvprintw(y, 4, "%s", strtok(NULL, ",")); + mvprintw(y,19, "%s", strtok(NULL, ",")); + mvprintw(y,32, "%s", strtok(NULL, ",")); + mvprintw(y,38, "%s", strtok(NULL, ",")); + mvprintw(y,45, "%s", strtok(NULL, ",")); + mvprintw(y,51, "%s", strtok(NULL, ",")); + mvprintw(y,56, "%s", strtok(NULL, ",")); + mvprintw(y,62, "%s", strtok(NULL, ",")); + mvprintw(y,72, "%s", strtok(NULL, ";")); + y++; + } } - - if (records) { - y = 7; - if (records > 10) - o = records - 10; - else - o = 1; - set_color(CYAN, BLACK); - for (i = o; i <= records; i++) { - sprintf(buf, "GLCR:1,%d;", i); - if (socket_send(buf) == 0) { - sprintf(buf, "%s", socket_receive()); - if (strncmp(buf, "100:9,", 6) == 0) { - cnt = strtok(buf, ","); - if (records > 10) { - /* - * Only clear line if there's a change to scroll - */ - locate(y, 1); - clrtoeol(); - } - mvprintw(y, 1, "%2d", i); - mvprintw(y, 4, "%s", strtok(NULL, ",")); - mvprintw(y,19, "%s", strtok(NULL, ",")); - mvprintw(y,32, "%s", strtok(NULL, ",")); - mvprintw(y,38, "%s", strtok(NULL, ",")); - mvprintw(y,45, "%s", strtok(NULL, ",")); - mvprintw(y,51, "%s", strtok(NULL, ",")); - mvprintw(y,56, "%s", strtok(NULL, ",")); - mvprintw(y,62, "%s", strtok(NULL, ",")); - mvprintw(y,72, "%s", strtok(NULL, ";")); - y++; - } - } - } - } - ch = testkey(LINES - 4, COLS / 2 + 8); - } while (ch == '\0'); + } + } + ch = testkey(lines - 1, columns / 2 + 8); + } while (ch == '\0'); } void system_moni(void) { - int ch, y, eof; - char *cnt; - char buf[128]; - time_t start, now; + int ch, y, eof; + char *cnt, buf[128]; + time_t start, now; - clr_index(); - set_color(WHITE, BLACK); - mvprintw( 5, 6, "1. SERVER CLIENTS"); - set_color(YELLOW, RED); - mvprintw( 7, 1, "Pid tty user program city doing time "); - set_color(CYAN, BLACK); - center_addstr(LINES - 4, (char *)"Press any key"); - IsDoing("System Monitor"); + clr_index(); + set_color(WHITE, BLACK); + mvprintw( 5, 6, "1. SERVER CLIENTS"); + set_color(YELLOW, RED); + mvprintw( 7, 1, "Pid tty user program city doing time "); + set_color(CYAN, BLACK); + center_addstr(lines - 1, (char *)"Press any key"); + IsDoing("System Monitor"); - do { - show_date(LIGHTGRAY, BLACK, 0, 0); + do { + show_date(LIGHTGRAY, BLACK, 0, 0); - eof = 0; - set_color(LIGHTGRAY, BLACK); + eof = 0; + set_color(LIGHTGRAY, BLACK); - for (y = 8; y <= LINES - 5; y++) { - if (y == 8) - sprintf(buf, "GMON:1,1;"); - else - sprintf(buf, "GMON:1,0;"); - if (eof == 0) { - if (socket_send(buf) == 0) { - strcpy(buf, socket_receive()); - locate(y, 1); - clrtoeol(); - if (strncmp(buf, "100:0;", 6) == 0) { - /* - * There's no more information - */ - eof = 1; - } else { - cnt = strtok(buf, ","); - mvprintw(y, 1, (char *)"%.5s", strtok(NULL, ",")); - mvprintw(y, 7, (char *)"%.6s", strtok(NULL, ",")); - mvprintw(y,14, (char *)"%.8s", strtok(NULL, ",")); - mvprintw(y,23, (char *)"%.8s", strtok(NULL, ",")); - mvprintw(y,32, (char *)"%.15s", strtok(NULL, ",")); - mvprintw(y,48, (char *)"%.26s", strtok(NULL, ",")); - start = atoi(strtok(NULL, ";")); - now = time(NULL); - mvprintw(y,75, (char *)"%s", t_elapsed(start, now)); - } - } - } else { - /* - * If no valid data, clear line - */ - locate(y, 1); - clrtoeol(); - } - } /* for () */ + for (y = 8; y <= lines - 2; y++) { + if (y == 8) + sprintf(buf, "GMON:1,1;"); + else + sprintf(buf, "GMON:1,0;"); + if (eof == 0) { + if (socket_send(buf) == 0) { + strcpy(buf, socket_receive()); + locate(y, 1); + clrtoeol(); + if (strncmp(buf, "100:0;", 6) == 0) { + /* + * There's no more information + */ + eof = 1; + } else { + cnt = strtok(buf, ","); + mvprintw(y, 1, (char *)"%.5s", strtok(NULL, ",")); + mvprintw(y, 7, (char *)"%.6s", strtok(NULL, ",")); + mvprintw(y,14, (char *)"%.8s", strtok(NULL, ",")); + mvprintw(y,23, (char *)"%.8s", strtok(NULL, ",")); + mvprintw(y,32, (char *)"%.15s", strtok(NULL, ",")); + mvprintw(y,48, (char *)"%.26s", strtok(NULL, ",")); + start = atoi(strtok(NULL, ";")); + now = time(NULL); + mvprintw(y,75, (char *)"%s", t_elapsed(start, now)); + } + } + } else { + /* + * If no valid data, clear line + */ + locate(y, 1); + clrtoeol(); + } + } /* for () */ - ch = testkey(LINES - 4, COLS / 2 + 8); - } while (ch == '\0'); + ch = testkey(lines - 1, columns / 2 + 8); + } while (ch == '\0'); } @@ -318,7 +317,7 @@ void disk_stat(void) set_color(YELLOW, RED); mvprintw( 7, 1, " Size MB Used MB Perc. FS-Type Mountpoint "); set_color(CYAN, BLACK); - mvprintw(LINES - 2, 6, "Press any key"); + mvprintw(lines - 2, 6, "Press any key"); IsDoing("Filesystem Usage"); do { @@ -369,7 +368,7 @@ void disk_stat(void) } } - ch = testkey(LINES - 2, 20); + ch = testkey(lines - 2, 20); } while (ch == '\0'); } @@ -408,11 +407,101 @@ void soft_info(void) set_color(LIGHTCYAN, BLACK); center_addstr(14, (char *)"http://mbse.sourceforge.net or 2:280/2802"); set_color(LIGHTGREEN, BLACK); - center_addstr(LINES -7, (char *)"This is free software; released under the terms of the GNU General"); - center_addstr(LINES -6, (char *)"Public License as published by the Free Software Foundation."); + center_addstr(lines -7, (char *)"This is free software; released under the terms of the GNU General"); + center_addstr(lines -6, (char *)"Public License as published by the Free Software Foundation."); set_color(CYAN, BLACK); - center_addstr(LINES -4, (char *)"Press any key"); - readkey(LINES - 4, COLS / 2 + 8, LIGHTGRAY, BLACK); + center_addstr(lines -4, (char *)"Press any key"); + readkey(lines - 4, columns / 2 + 8, LIGHTGRAY, BLACK); +} + + + +/* + * Sysop/user chat + */ +void Chat(int channel) +{ + int curpos = 0, rline = 0; + unsigned char ch = 0; + char sbuf[81], rbuf[17][81], resp[128], from[36]; + static char buf[128]; + + clr_index(); + locate(lines - 2, 1); + set_color(WHITE, BLUE); + clrtoeol(); + mvprintw(lines - 2, 2, "Sysop to user chat, press @ to exit"); + + set_color(LIGHTGRAY, BLACK); + mvprintw(lines - 1, 1, ">"); + memset(&sbuf, 0, sizeof(sbuf)); + memset(&rbuf, 0, sizeof(rbuf)); + + while (TRUE) { + + /* + * Check for new message + */ + sprintf(buf, "CIPM:1,%d;", mypid); + if (socket_send(buf) == 0) { + strcpy(buf, socket_receive()); + if (strncmp(buf, "100:0;", 6)) { + Syslog('-', "%s", buf); + strncpy(resp, strtok(buf, ":"), 10); /* Should be 100 */ + strncpy(resp, strtok(NULL, ","), 5); /* Should be 3 */ + strncpy(resp, strtok(NULL, ","), 5); /* Should be our channel */ + if (atoi(resp) != channel) { + Syslog('+', "Message in channel %s instead of %d", resp, channel); + } else { + strncpy(from, strtok(NULL, ","), 36); /* From name */ + strncpy(resp, strtok(NULL, "\0"), 80); /* The message */ + resp[strlen(resp)-1] = '\0'; + } + } + } + + /* + * Update top bars + */ + show_date(LIGHTGRAY, BLACK, 0, 0); + + /* + * Check for a pressed key, if so then process it + */ + ch = testkey(lines -1, curpos + 2); + if (ch == '@') { + break; + } else if (isprint(ch)) { + if (curpos < 77) { + putchar(ch); + fflush(stdout); + sbuf[curpos] = ch; + curpos++; + } else { + putchar(7); + } + } else if ((ch == KEY_BACKSPACE) || (ch == KEY_RUBOUT) || (ch == KEY_DEL)) { + if (curpos) { + curpos--; + sbuf[curpos] = '\0'; + printf("\b \b"); + } else { + putchar(7); + } + } else if ((ch == '\r') && curpos) { + sprintf(buf, "CSPM:4,%d,Sysop,-,%s;", channel, sbuf); + Syslog('-', "%s", buf); + if (socket_send(buf) == 0) { + strcpy(buf, socket_receive()); + Syslog('-', "%s", buf); + } + curpos = 0; + memset(&sbuf, 0, sizeof(sbuf)); + locate(lines - 1, 2); + clrtoeol(); + mvprintw(lines - 1, 1, ">"); + } + } } @@ -421,7 +510,8 @@ int main(int argc, char *argv[]) { struct passwd *pw; char buf[128]; - + int rc; + #ifdef MEMWATCH mwInit(); #endif @@ -437,7 +527,7 @@ int main(int argc, char *argv[]) /* * Report sysop available for chat */ - sprintf(buf, "CSYS:1,1;"); + sprintf(buf, "CSYS:2,%d,1;", mypid); if (socket_send(buf) == 0) sprintf(buf, "%s", socket_receive()); @@ -452,6 +542,24 @@ int main(int argc, char *argv[]) signal(SIGTERM,(void (*))die); signal(SIGKILL,(void (*))die); + + /* + * Find out if the environment variables LINES and COLUMNS are present, + * if so, then use these for screen dimensions. + */ + if (getenv("LINES")) { + rc = atoi(getenv("LINES")); + if (rc >= 24) + lines = rc; + } + if (getenv("COLUMNS")) { + rc = atoi(getenv("COLUMNS")); + if (rc >= 80) + columns = rc; + } + Syslog('-', "Screen size set to %dx%d", columns, lines); + + screen_start((char *)"MBmon"); for (;;) { @@ -466,9 +574,10 @@ int main(int argc, char *argv[]) mvprintw( 9, 6, "3. View Filesystem Usage"); mvprintw(10, 6, "4. View BBS System Information"); mvprintw(11, 6, "5. View BBS Lastcallers List"); - mvprintw(12, 6, "6. View Software Information"); + mvprintw(12, 6, "6. Chat with user"); + mvprintw(13, 6, "7. View Software Information"); - switch(select_menu(6)) { + switch(select_menu(7)) { case 0: die(0); break; @@ -488,6 +597,9 @@ int main(int argc, char *argv[]) ShowLastcaller(); break; case 6: + Chat(0); + break; + case 7: soft_info(); break; } diff --git a/mbmon/mbmon.h b/mbmon/mbmon.h index 596d9e24..5c718733 100644 --- a/mbmon/mbmon.h +++ b/mbmon/mbmon.h @@ -1,6 +1,8 @@ #ifndef _MBMON_H #define _MBMON_H +/* $Id$ */ + static void die(int); void ShowSysinfo(void); void ShowLastcaller(void); @@ -8,7 +10,6 @@ void system_moni(void); void system_stat(void); void disk_stat(void); void soft_info(void); - +void Chat(int); #endif - diff --git a/mbmon/mutil.c b/mbmon/mutil.c index 3e5f17a1..286b4c19 100644 --- a/mbmon/mutil.c +++ b/mbmon/mutil.c @@ -35,8 +35,10 @@ #include "common.h" #include "mutil.h" -extern int ttyfd; -int bbs_free; + +extern int lines, columns; +extern int ttyfd; +int bbs_free; unsigned char readkey(int y, int x, int fg, int bg) @@ -93,7 +95,7 @@ unsigned char testkey(int y, int x) } Setraw(); - rc = Waitchar(&ch, 100); + rc = Waitchar(&ch, 50); if (rc == 1) { if (ch == KEY_ESCAPE) rc = Escapechar(&ch); @@ -112,7 +114,7 @@ unsigned char testkey(int y, int x) void show_field(int y, int x, char *str, int length, int fill) { - mvprintw(y, x, padleft(str, length, fill)); + mvprintw(y, x, padleft(str, length, fill)); } @@ -120,14 +122,14 @@ int insertflag = 0; void newinsert(int i, int fg, int bg) { - insertflag = i; - set_color(YELLOW, RED); - if (insertflag != 0) { - mvprintw(2,36," INS "); - } else { - mvprintw(2,36," OVR "); - } - set_color(fg, bg); + insertflag = i; + set_color(YELLOW, RED); + if (insertflag != 0) { + mvprintw(2,36," INS "); + } else { + mvprintw(2,36," OVR "); + } + set_color(fg, bg); } @@ -295,58 +297,58 @@ char *edit_field(int y, int x, int w, int p, char *s_) */ int select_menu(int max) { - static char *menu=(char *)"-"; - char help[80]; - int pick; + static char *menu=(char *)"-"; + char help[80]; + int pick; - sprintf(help, "Select menu item (1..%d) or ^\"-\"^ for previous level.", max); - showhelp(help); + sprintf(help, "Select menu item (1..%d) or ^\"-\"^ for previous level.", max); + showhelp(help); - /* - * Loop forever until it's right. - */ - for (;;) { - mvprintw(LINES - 3, 6, "Enter your choice >"); - menu = (char *)"-"; - menu = edit_field(LINES - 3, 26, 3, '9', menu); - locate(LINES -3, 6); - clrtoeol(); + /* + * Loop forever until it's right. + */ + for (;;) { + mvprintw(lines - 2, 6, "Enter your choice >"); + menu = (char *)"-"; + menu = edit_field(lines - 2, 26, 3, '9', menu); + locate(lines -2, 6); + clrtoeol(); - if (strncmp(menu, "-", 1) == 0) - return 0; + if (strncmp(menu, "-", 1) == 0) + return 0; - pick = atoi(menu); - if ((pick >= 1) && (pick <= max)) - return pick; + pick = atoi(menu); + if ((pick >= 1) && (pick <= max)) + return pick; - working(2, 0, 0); - working(0, 0, 0); - } + working(2, 0, 0); + working(0, 0, 0); + } } void clrtoeol() { - int i; + int i; - printf("\r"); - for (i = 0; i < COLS; i++) - putchar(' '); - printf("\r"); - fflush(stdout); + printf("\r"); + for (i = 0; i < columns; i++) + putchar(' '); + printf("\r"); + fflush(stdout); } void hor_lin(int y, int x, int len) { - int i; + int i; - locate(y, x); - for (i = 0; i < len; i++) - putchar('-'); - fflush(stdout); + locate(y, x); + for (i = 0; i < len; i++) + putchar('-'); + fflush(stdout); } @@ -356,12 +358,12 @@ static int old_b = -1; void set_color(int f, int b) { - if ((f != old_f) || (b != old_b)) { - old_f = f; - old_b = b; - colour(f, b); - fflush(stdout); - } + if ((f != old_f) || (b != old_b)) { + old_f = f; + old_b = b; + colour(f, b); + fflush(stdout); + } } @@ -383,10 +385,10 @@ void show_date(int fg, int bg, int y, int x) set_color(LIGHTGREEN, BLUE); p = ctime(&now); Striplf(p); - mvprintw(1, 44, (char *)"%s TZUTC %s", p, gmtoffset(now)); + mvprintw(1, columns - 36, (char *)"%s TZUTC %s", p, gmtoffset(now)); p = asctime(gmtime(&now)); Striplf(p); - mvprintw(2, 44, (char *)"%s UTC", p); + mvprintw(2, columns - 36, (char *)"%s UTC", p); /* * Indicator if bbs is free @@ -396,15 +398,15 @@ void show_date(int fg, int bg, int y, int x) strcpy(buf, SockR("SBBS:0;")); if (strncmp(buf, "100:2,1", 7) == 0) { set_color(WHITE, RED); - mvprintw(2,74, (char *)" Down "); + mvprintw(2,columns - 6, (char *)" Down "); } else { set_color(WHITE, BLUE); - mvprintw(2,74, (char *)" Free "); + mvprintw(2,columns - 6, (char *)" Free "); } bbs_free = TRUE; } else { set_color(WHITE, RED); - mvprintw(2,74, (char *)" Busy "); + mvprintw(2,columns - 6, (char *)" Busy "); bbs_free = FALSE; } @@ -448,7 +450,7 @@ void show_date(int fg, int bg, int y, int x) void center_addstr(int y, char *s) { - mvprintw(y, (COLS / 2) - (strlen(s) / 2), s); + mvprintw(y, (columns / 2) - (strlen(s) / 2), s); } @@ -458,32 +460,32 @@ void center_addstr(int y, char *s) */ void screen_start(char *name) { - int i; + int i; - /* - * Overwrite screen the first time, if user had it black on white - * it will change to white on black. clear() won't do the trick. - */ - set_color(LIGHTGRAY, BLUE); - locate(1, 1); - for (i = 0; i < LINES; i++) { - if (i == 3) - colour(LIGHTGRAY, BLACK); - clrtoeol(); - if (i < LINES) - printf("\n"); - } - fflush(stdout); + /* + * Overwrite screen the first time, if user had it black on white + * it will change to white on black. clear() won't do the trick. + */ + set_color(LIGHTGRAY, BLUE); + locate(1, 1); + for (i = 0; i < lines; i++) { + if (i == 3) + colour(LIGHTGRAY, BLACK); + clrtoeol(); + if (i < lines) + printf("\n"); + } + fflush(stdout); - set_color(WHITE, BLUE); - locate(1, 1); - printf((char *)"%s for MBSE BBS version %s", name, VERSION); - set_color(YELLOW, BLUE); - locate(2, 1); - printf((char *)SHORTRIGHT); - set_color(LIGHTGRAY, BLACK); - show_date(LIGHTGRAY, BLACK, 0, 0); - fflush(stdout); + set_color(WHITE, BLUE); + locate(1, 1); + printf((char *)"%s for MBSE BBS version %s", name, VERSION); + set_color(YELLOW, BLUE); + locate(2, 1); + printf((char *)SHORTRIGHT); + set_color(LIGHTGRAY, BLACK); + show_date(LIGHTGRAY, BLACK, 0, 0); + fflush(stdout); } @@ -493,9 +495,9 @@ void screen_start(char *name) */ void screen_stop() { - set_color(LIGHTGRAY, BLACK); - clear(); - fflush(stdout); + set_color(LIGHTGRAY, BLACK); + clear(); + fflush(stdout); } @@ -505,51 +507,51 @@ void screen_stop() */ void working(int txno, int y, int x) { - int i; + int i; - /* - * If txno not 0 there will be something written. The - * reversed attributes for mono, or white on red for - * color screens is set. The cursor is turned off and - * original cursor position is saved. - */ - show_date(LIGHTGRAY, BLACK, 0, 0); + /* + * If txno not 0 there will be something written. The + * reversed attributes for mono, or white on red for + * color screens is set. The cursor is turned off and + * original cursor position is saved. + */ + show_date(LIGHTGRAY, BLACK, 0, 0); - if (txno != 0) - set_color(YELLOW, RED); - else - set_color(LIGHTGRAY, BLACK); + if (txno != 0) + set_color(YELLOW, RED); + else + set_color(LIGHTGRAY, BLACK); - switch (txno) { - case 0: mvprintw(4, 66, (char *)" "); + switch (txno) { + case 0: mvprintw(4, columns - 14, (char *)" "); break; - case 1: mvprintw(4, 66, (char *)"Working . . ."); + case 1: mvprintw(4, columns - 14, (char *)"Working . . ."); break; - case 2: mvprintw(4, 66, (char *)">>> ERROR <<<"); + case 2: mvprintw(4, columns - 14, (char *)">>> ERROR <<<"); for (i = 1; i <= 5; i++) { - putchar(7); - fflush(stdout); - usleep(150000); + putchar(7); + fflush(stdout); + usleep(150000); } usleep(550000); break; - case 3: mvprintw(4, 66, (char *)"Form inserted"); + case 3: mvprintw(4, columns - 14, (char *)"Form inserted"); putchar(7); fflush(stdout); sleep(1); break; - case 4: mvprintw(4, 66, (char *)"Form deleted "); + case 4: mvprintw(4, columns - 14, (char *)"Form deleted "); putchar(7); fflush(stdout); sleep(1); break; - } + } - show_date(LIGHTGRAY, BLACK, 0, 0); - set_color(LIGHTGRAY, BLACK); - if (y && x) - locate(y, x); - fflush(stdout); + show_date(LIGHTGRAY, BLACK, 0, 0); + set_color(LIGHTGRAY, BLACK); + if (y && x) + locate(y, x); + fflush(stdout); } @@ -562,7 +564,7 @@ void clr_index() int i; set_color(LIGHTGRAY, BLACK); - for (i = 4; i <= (LINES - 1); i++) { + for (i = 4; i <= (lines); i++) { locate(i, 1); clrtoeol(); } @@ -575,31 +577,31 @@ void clr_index() */ void showhelp(char *T) { - int f, i, x, forlim; + int f, i, x, forlim; - f = FALSE; - locate(LINES-1, 1); - set_color(WHITE, RED); - clrtoeol(); - x = 0; - forlim = strlen(T); + f = FALSE; + locate(lines, 1); + set_color(WHITE, RED); + clrtoeol(); + x = 0; + forlim = strlen(T); - for (i = 0; i < forlim; i++) { - if (T[i] == '^') { - if (f == FALSE) { - f = TRUE; - set_color(YELLOW, RED); - } else { - f = FALSE; - set_color(WHITE, RED); - } - } else { - putchar(T[i]); - x++; - } + for (i = 0; i < forlim; i++) { + if (T[i] == '^') { + if (f == FALSE) { + f = TRUE; + set_color(YELLOW, RED); + } else { + f = FALSE; + set_color(WHITE, RED); + } + } else { + putchar(T[i]); + x++; } - set_color(LIGHTGRAY, BLACK); - fflush(stdout); + } + set_color(LIGHTGRAY, BLACK); + fflush(stdout); } diff --git a/mbtask/Makefile b/mbtask/Makefile index 4d4e163e..a28d67b0 100644 --- a/mbtask/Makefile +++ b/mbtask/Makefile @@ -6,13 +6,13 @@ include ../Makefile.global SRCS = callstat.c scanout.c taskcomm.c taskinfo.c taskstat.c \ mbtask.c outstat.c signame.c taskdisk.c taskregs.c taskutil.c \ - ports.c calllist.c ping.c crc.c + ports.c calllist.c ping.c crc.c taskchat.c HDRS = callstat.h mbtask.h outstat.h signame.h taskdisk.h taskregs.h taskutil.h \ libs.h scanout.h taskcomm.h taskinfo.h taskstat.h \ - ports.h calllist.h ping.h crc.h + ports.h calllist.h ping.h crc.h taskchat.h OBJS = callstat.o scanout.o taskcomm.o taskinfo.o taskstat.o \ mbtask.o outstat.o signame.o taskdisk.o taskregs.o taskutil.o \ - ports.o calllist.o ping.o crc.o + ports.o calllist.o ping.o crc.o taskchat.o LIBS += ../lib/libnodelist.a OTHER = Makefile issue issue.netbsd @@ -93,4 +93,5 @@ ports.o: ../config.h libs.h ../lib/structs.h taskutil.h ../lib/nodelist.h ports. calllist.o: ../config.h libs.h ../lib/structs.h taskstat.h taskutil.h callstat.h outstat.h mbtask.h calllist.h ping.o: ../config.h libs.h ../lib/structs.h ../lib/mberrors.h taskstat.h taskutil.h ping.h crc.o: ../config.h libs.h crc.h +taskchat.o: ../config.h libs.h ../lib/structs.h taskchat.h # End of generated dependencies diff --git a/mbtask/taskchat.c b/mbtask/taskchat.c new file mode 100644 index 00000000..c2bd5ef9 --- /dev/null +++ b/mbtask/taskchat.c @@ -0,0 +1,36 @@ +/***************************************************************************** + * + * $Id$ + * Purpose ...............: mbtask - chat server + * + ***************************************************************************** + * Copyright (C) 1997-2003 + * + * Michiel Broek FIDO: 2:280/2802 + * Beekmansbos 10 + * 1971 BV IJmuiden + * the Netherlands + * + * This file is part of MBSE BBS. + * + * This BBS is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * MBSE BBS is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with MBSE BBS; see the file COPYING. If not, write to the Free + * Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + *****************************************************************************/ + +#include "../config.h" +#include "libs.h" +#include "../lib/structs.h" +#include "taskchat.h" + + diff --git a/mbtask/taskchat.h b/mbtask/taskchat.h new file mode 100644 index 00000000..967246a2 --- /dev/null +++ b/mbtask/taskchat.h @@ -0,0 +1,7 @@ +#ifndef _TASKCHAT_H +#define _TASKCHAT_H + +/* $Id$ */ + + +#endif diff --git a/mbtask/taskregs.c b/mbtask/taskregs.c index 8feacf9d..83f6aa5e 100644 --- a/mbtask/taskregs.c +++ b/mbtask/taskregs.c @@ -360,10 +360,28 @@ int reg_user(char *data) */ int reg_sysop(char *data) { - char *cnt; + char *cnt, *pid; + int rec; cnt = strtok(data, ","); + pid = strtok(NULL, ","); sysop_present = atoi(strtok(NULL, ";")); + + if ((rec = reg_find(pid)) != -1) { + if (sysop_present) { + /* + * Allthough the sysop is not really chatting, still put channel 0 + * into chatmode for the sysop's process. + */ + reginfo[rec].channel = 0; + reginfo[rec].chatting = TRUE; + } else { + reginfo[rec].channel = -1; + reginfo[rec].chatting = FALSE; + } + reginfo[rec].lastcon = time(NULL); + } + Syslog('+', "Sysop present for chat: %s", sysop_present ? "True":"False"); return 0; } @@ -415,7 +433,7 @@ char *reg_ipm(char *data) int reg_spm(char *data) { char *cnt, *ch, *from, *too, *txt, *log; - int i; + int i, error = 0; cnt = strtok(data, ","); ch = strtok(NULL, ","); @@ -424,7 +442,7 @@ int reg_spm(char *data) txt = strtok(NULL, "\0"); txt[strlen(txt)-1] = '\0'; - Syslog('-', "SIPM:%s,%d,%s,%s,%s;", cnt, ch, from, too, txt); + Syslog('-', "SIPM:%s,%s,%s,%s,%s;", cnt, ch, from, too, txt); log = calloc(PATH_MAX, sizeof(char)); sprintf(log, "%s/log/%s", getenv("MBSE_ROOT"), CFG.chat_log); @@ -432,24 +450,23 @@ int reg_spm(char *data) /* * Personal messages and sysop/user chat messages. */ - if (reginfo[i].pid && (strcasecmp(reginfo[i].uname, too) == 0) && - ((atoi(ch) == -1) || (atoi(ch) == 0)) && (atoi(ch) == reginfo[i].channel)) { + if (reginfo[i].pid && + (((strcasecmp(reginfo[i].uname, too) == 0) && (atoi(ch) == -1)) || (atoi(ch) == 0)) && + (atoi(ch) == reginfo[i].channel)) { /* * If the in and out pointers are the same and the * message present flag is still set, then this user * can't get anymore new messages. */ if (reginfo[i].ismsg && (reginfo[i].ptr_in == reginfo[i].ptr_out)) { - free(log); - return 2; + error = 2; } /* * If user has the "do not distrurb" flag set, but the sysop ignore's this. */ if (reginfo[i].silent && (atoi(ch) == -1)) { - free(log); - return 1; + error = 1; } /* @@ -467,9 +484,11 @@ int reg_spm(char *data) ulog(log, (char *)"+", from, ch, txt); } - Syslog('+', "reg_spm: in=%d out=%d ismsg=%d", reginfo[i].ptr_in, reginfo[i].ptr_out, reginfo[i].ismsg); + Syslog('+', "reg_spm: rec=%d in=%d out=%d ismsg=%d", i, reginfo[i].ptr_in, reginfo[i].ptr_out, reginfo[i].ismsg); + } + if ((atoi(ch) == -1) || (atoi(ch) == 0)) { free(log); - return 0; + return error; } /*