Fixes to mbmon screen layout, added basic files for chatserver

This commit is contained in:
Michiel Broek 2003-03-23 21:27:14 +00:00
parent 0cf00e1716
commit 3d157ec16a
13 changed files with 504 additions and 318 deletions

View File

@ -59,6 +59,12 @@ v0.37.2 23-Feb-2003.
or stops. or stops.
Reports a page from a user in row 3 of the screen (but doesn't Reports a page from a user in row 3 of the screen (but doesn't
do chat right now). 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: mbtask:
Safer logging of user log messages. Safer logging of user log messages.

View File

@ -182,6 +182,10 @@ install:
rm ${BINDIR}/fbutil ; \ rm ${BINDIR}/fbutil ; \
echo "removed ${BINDIR}/fbutil "; \ echo "removed ${BINDIR}/fbutil "; \
fi fi
@if [ -x ${BINDIR}/mbchat ]; then \
rm ${BINDIR}/mbchat ; \
echo "removed ${BINDIR}/mbchat"; \
fi
for d in ${SUBDIRS}; do (cd $$d && ${MAKE} $@) || exit; done for d in ${SUBDIRS}; do (cd $$d && ${MAKE} $@) || exit; done
dist tar: ${TARFILE} dist tar: ${TARFILE}

4
TODO
View File

@ -13,6 +13,10 @@ $Id$
N = Normal, second priority. N = Normal, second priority.
L = Cosmetic or nice to have. 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: libdiesel.a:
U: Processed stringlines containing unbalanced " characters are not U: Processed stringlines containing unbalanced " characters are not
processed, instead the previous macro value will be returned. processed, instead the previous macro value will be returned.

View File

@ -58,6 +58,6 @@ depend:
# DO NOT DELETE THIS LINE - MAKE DEPEND RELIES ON IT # DO NOT DELETE THIS LINE - MAKE DEPEND RELIES ON IT
# Dependencies generated by make depend # Dependencies generated by make depend
mutil.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mberrors.h common.h mutil.h 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 common.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mberrors.h common.h
# End of generated dependencies # End of generated dependencies

View File

@ -51,7 +51,7 @@ int fromlen;
static char spath[PATH_MAX]; /* Server socket path */ static char spath[PATH_MAX]; /* Server socket path */
static char cpath[PATH_MAX]; /* Client socket path */ static char cpath[PATH_MAX]; /* Client socket path */
extern int lines, columns;
void InitClient(char *user) void InitClient(char *user)
@ -837,7 +837,7 @@ void clear()
*/ */
void locate(int y, int x) 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); printf("ANSI: Invalid screen coordinates: %i, %i\n", y, x);
return; return;
} }

View File

@ -1,6 +1,7 @@
#ifndef _COMMON_H #ifndef _COMMON_H
#define _COMMON_H #define _COMMON_H
/* $Id$ */
#pragma pack(1) #pragma pack(1)
@ -28,13 +29,6 @@
#define KEY_PGDN 209 #define KEY_PGDN 209
#ifndef LINES
#define LINES 24
#endif
#ifndef COLS
#define COLS 80
#endif
/* /*
* ANSI colors * ANSI colors

View File

@ -32,11 +32,17 @@
#include "../config.h" #include "../config.h"
#include "../lib/libs.h" #include "../lib/libs.h"
#include "../lib/memwatch.h" #include "../lib/memwatch.h"
#include "../lib/mberrors.h"
#include "common.h" #include "common.h"
#include "mutil.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) static void die(int onsig)
@ -50,7 +56,7 @@ static void die(int onsig)
else else
Syslog(' ', "Normally finished"); Syslog(' ', "Normally finished");
sprintf(buf, "CSYS:1,0;"); sprintf(buf, "CSYS:2,%d,0;", mypid);
if (socket_send(buf) == 0) if (socket_send(buf) == 0)
sprintf(buf, "%s", socket_receive()); sprintf(buf, "%s", socket_receive());
ExitClient(0); ExitClient(0);
@ -60,175 +66,168 @@ static void die(int onsig)
void ShowSysinfo(void) void ShowSysinfo(void)
{ {
int ch; int ch;
char buf[128], *cnt; char buf[128], *cnt;
clr_index(); clr_index();
set_color(WHITE, BLACK); set_color(WHITE, BLACK);
mvprintw( 5, 6, "4. SHOW BBS SYSTEM INFO"); mvprintw( 5, 6, "4. SHOW BBS SYSTEM INFO");
set_color(CYAN, BLACK); set_color(CYAN, BLACK);
mvprintw( 7, 6, "1. Total calls"); mvprintw( 7, 6, "1. Total calls");
mvprintw( 8, 6, "2. Pots calls"); mvprintw( 8, 6, "2. Pots calls");
mvprintw( 9, 6, "3. ISDN calls"); mvprintw( 9, 6, "3. ISDN calls");
mvprintw(10, 6, "4. Network calls"); mvprintw(10, 6, "4. Network calls");
mvprintw(11, 6, "5. Local calls"); mvprintw(11, 6, "5. Local calls");
mvprintw(12, 6, "6. Date started"); mvprintw(12, 6, "6. Date started");
mvprintw(13, 6, "7. Last caller"); mvprintw(13, 6, "7. Last caller");
center_addstr(LINES - 4, (char *)"Press any key"); center_addstr(lines - 3, (char *)"Press any key");
IsDoing("View System Info"); IsDoing("View System Info");
do { do {
show_date(LIGHTGRAY, BLACK, 0, 0); show_date(LIGHTGRAY, BLACK, 0, 0);
set_color(LIGHTGRAY, BLACK); set_color(LIGHTGRAY, BLACK);
sprintf(buf, "GSYS:1,%d;", getpid()); sprintf(buf, "GSYS:1,%d;", getpid());
if (socket_send(buf) == 0) { if (socket_send(buf) == 0) {
sprintf(buf, "%s", socket_receive()); sprintf(buf, "%s", socket_receive());
if (strncmp(buf, "100:7,", 6) == 0) { if (strncmp(buf, "100:7,", 6) == 0) {
cnt = strtok(buf, ","); cnt = strtok(buf, ",");
mvprintw( 7,26, "%s", strtok(NULL, ",")); mvprintw( 7,26, "%s", strtok(NULL, ","));
mvprintw( 8,26, "%s", strtok(NULL, ",")); mvprintw( 8,26, "%s", strtok(NULL, ","));
mvprintw( 9,26, "%s", strtok(NULL, ",")); mvprintw( 9,26, "%s", strtok(NULL, ","));
mvprintw(10,26, "%s", strtok(NULL, ",")); mvprintw(10,26, "%s", strtok(NULL, ","));
mvprintw(11,26, "%s", strtok(NULL, ",")); mvprintw(11,26, "%s", strtok(NULL, ","));
mvprintw(12,26, "%s", strtok(NULL, ",")); mvprintw(12,26, "%s", strtok(NULL, ","));
mvprintw(13,26, "%s", strtok(NULL, ";")); mvprintw(13,26, "%s", strtok(NULL, ";"));
fflush(stdout); fflush(stdout);
} }
} }
ch = testkey(LINES - 4, COLS / 2 + 8); ch = testkey(lines - 3, columns / 2 + 8);
} while (ch == '\0'); } while (ch == '\0');
} }
void ShowLastcaller(void) void ShowLastcaller(void)
{ {
int records, ch, i, y, o; int records, maxrows, ch, i, y, o;
char buf[128], *cnt; char buf[128], *cnt;
clr_index(); clr_index();
set_color(WHITE, BLACK); set_color(WHITE, BLACK);
mvprintw( 4, 6, "5. SHOW BBS LASTCALLERS"); mvprintw( 4, 6, "5. SHOW BBS LASTCALLERS");
set_color(YELLOW, RED); set_color(YELLOW, RED);
mvprintw( 6, 1, "Nr Username Location Level Device Time Mins Calls Speed Actions "); mvprintw( 6, 1, "Nr Username Location Level Device Time Mins Calls Speed Actions ");
set_color(CYAN, BLACK); set_color(CYAN, BLACK);
center_addstr(LINES - 4, (char *)"Press any key"); center_addstr(lines - 1, (char *)"Press any key");
IsDoing("View Lastcallers"); IsDoing("View Lastcallers");
maxrows = lines - 10;
do { do {
show_date(LIGHTGRAY, BLACK, 0, 0); show_date(LIGHTGRAY, BLACK, 0, 0);
records = 0; records = 0;
sprintf(buf, "GLCC: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) { if (socket_send(buf) == 0) {
sprintf(buf, "%s", socket_receive()); sprintf(buf, "%s", socket_receive());
if (strncmp(buf, "100:1,", 6) == 0) { if (strncmp(buf, "100:9,", 6) == 0) {
cnt = strtok(buf, ","); cnt = strtok(buf, ",");
records = atoi(strtok(NULL, ";")); 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; ch = testkey(lines - 1, columns / 2 + 8);
if (records > 10) } while (ch == '\0');
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');
} }
void system_moni(void) void system_moni(void)
{ {
int ch, y, eof; int ch, y, eof;
char *cnt; char *cnt, buf[128];
char buf[128]; time_t start, now;
time_t start, now;
clr_index(); clr_index();
set_color(WHITE, BLACK); set_color(WHITE, BLACK);
mvprintw( 5, 6, "1. SERVER CLIENTS"); mvprintw( 5, 6, "1. SERVER CLIENTS");
set_color(YELLOW, RED); set_color(YELLOW, RED);
mvprintw( 7, 1, "Pid tty user program city doing time "); mvprintw( 7, 1, "Pid tty user program city doing time ");
set_color(CYAN, BLACK); set_color(CYAN, BLACK);
center_addstr(LINES - 4, (char *)"Press any key"); center_addstr(lines - 1, (char *)"Press any key");
IsDoing("System Monitor"); IsDoing("System Monitor");
do { do {
show_date(LIGHTGRAY, BLACK, 0, 0); show_date(LIGHTGRAY, BLACK, 0, 0);
eof = 0; eof = 0;
set_color(LIGHTGRAY, BLACK); set_color(LIGHTGRAY, BLACK);
for (y = 8; y <= LINES - 5; y++) { for (y = 8; y <= lines - 2; y++) {
if (y == 8) if (y == 8)
sprintf(buf, "GMON:1,1;"); sprintf(buf, "GMON:1,1;");
else else
sprintf(buf, "GMON:1,0;"); sprintf(buf, "GMON:1,0;");
if (eof == 0) { if (eof == 0) {
if (socket_send(buf) == 0) { if (socket_send(buf) == 0) {
strcpy(buf, socket_receive()); strcpy(buf, socket_receive());
locate(y, 1); locate(y, 1);
clrtoeol(); clrtoeol();
if (strncmp(buf, "100:0;", 6) == 0) { if (strncmp(buf, "100:0;", 6) == 0) {
/* /*
* There's no more information * There's no more information
*/ */
eof = 1; eof = 1;
} else { } else {
cnt = strtok(buf, ","); cnt = strtok(buf, ",");
mvprintw(y, 1, (char *)"%.5s", strtok(NULL, ",")); mvprintw(y, 1, (char *)"%.5s", strtok(NULL, ","));
mvprintw(y, 7, (char *)"%.6s", strtok(NULL, ",")); mvprintw(y, 7, (char *)"%.6s", strtok(NULL, ","));
mvprintw(y,14, (char *)"%.8s", strtok(NULL, ",")); mvprintw(y,14, (char *)"%.8s", strtok(NULL, ","));
mvprintw(y,23, (char *)"%.8s", strtok(NULL, ",")); mvprintw(y,23, (char *)"%.8s", strtok(NULL, ","));
mvprintw(y,32, (char *)"%.15s", strtok(NULL, ",")); mvprintw(y,32, (char *)"%.15s", strtok(NULL, ","));
mvprintw(y,48, (char *)"%.26s", strtok(NULL, ",")); mvprintw(y,48, (char *)"%.26s", strtok(NULL, ","));
start = atoi(strtok(NULL, ";")); start = atoi(strtok(NULL, ";"));
now = time(NULL); now = time(NULL);
mvprintw(y,75, (char *)"%s", t_elapsed(start, now)); mvprintw(y,75, (char *)"%s", t_elapsed(start, now));
} }
} }
} else { } else {
/* /*
* If no valid data, clear line * If no valid data, clear line
*/ */
locate(y, 1); locate(y, 1);
clrtoeol(); clrtoeol();
} }
} /* for () */ } /* for () */
ch = testkey(LINES - 4, COLS / 2 + 8); ch = testkey(lines - 1, columns / 2 + 8);
} while (ch == '\0'); } while (ch == '\0');
} }
@ -318,7 +317,7 @@ void disk_stat(void)
set_color(YELLOW, RED); set_color(YELLOW, RED);
mvprintw( 7, 1, " Size MB Used MB Perc. FS-Type Mountpoint "); mvprintw( 7, 1, " Size MB Used MB Perc. FS-Type Mountpoint ");
set_color(CYAN, BLACK); set_color(CYAN, BLACK);
mvprintw(LINES - 2, 6, "Press any key"); mvprintw(lines - 2, 6, "Press any key");
IsDoing("Filesystem Usage"); IsDoing("Filesystem Usage");
do { do {
@ -369,7 +368,7 @@ void disk_stat(void)
} }
} }
ch = testkey(LINES - 2, 20); ch = testkey(lines - 2, 20);
} while (ch == '\0'); } while (ch == '\0');
} }
@ -408,11 +407,101 @@ void soft_info(void)
set_color(LIGHTCYAN, BLACK); set_color(LIGHTCYAN, BLACK);
center_addstr(14, (char *)"http://mbse.sourceforge.net or 2:280/2802"); center_addstr(14, (char *)"http://mbse.sourceforge.net or 2:280/2802");
set_color(LIGHTGREEN, BLACK); set_color(LIGHTGREEN, BLACK);
center_addstr(LINES -7, (char *)"This is free software; released under the terms of the GNU General"); 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 -6, (char *)"Public License as published by the Free Software Foundation.");
set_color(CYAN, BLACK); set_color(CYAN, BLACK);
center_addstr(LINES -4, (char *)"Press any key"); center_addstr(lines -4, (char *)"Press any key");
readkey(LINES - 4, COLS / 2 + 8, LIGHTGRAY, BLACK); 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; struct passwd *pw;
char buf[128]; char buf[128];
int rc;
#ifdef MEMWATCH #ifdef MEMWATCH
mwInit(); mwInit();
#endif #endif
@ -437,7 +527,7 @@ int main(int argc, char *argv[])
/* /*
* Report sysop available for chat * Report sysop available for chat
*/ */
sprintf(buf, "CSYS:1,1;"); sprintf(buf, "CSYS:2,%d,1;", mypid);
if (socket_send(buf) == 0) if (socket_send(buf) == 0)
sprintf(buf, "%s", socket_receive()); sprintf(buf, "%s", socket_receive());
@ -452,6 +542,24 @@ int main(int argc, char *argv[])
signal(SIGTERM,(void (*))die); signal(SIGTERM,(void (*))die);
signal(SIGKILL,(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"); screen_start((char *)"MBmon");
for (;;) { for (;;) {
@ -466,9 +574,10 @@ int main(int argc, char *argv[])
mvprintw( 9, 6, "3. View Filesystem Usage"); mvprintw( 9, 6, "3. View Filesystem Usage");
mvprintw(10, 6, "4. View BBS System Information"); mvprintw(10, 6, "4. View BBS System Information");
mvprintw(11, 6, "5. View BBS Lastcallers List"); 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: case 0:
die(0); die(0);
break; break;
@ -488,6 +597,9 @@ int main(int argc, char *argv[])
ShowLastcaller(); ShowLastcaller();
break; break;
case 6: case 6:
Chat(0);
break;
case 7:
soft_info(); soft_info();
break; break;
} }

View File

@ -1,6 +1,8 @@
#ifndef _MBMON_H #ifndef _MBMON_H
#define _MBMON_H #define _MBMON_H
/* $Id$ */
static void die(int); static void die(int);
void ShowSysinfo(void); void ShowSysinfo(void);
void ShowLastcaller(void); void ShowLastcaller(void);
@ -8,7 +10,6 @@ void system_moni(void);
void system_stat(void); void system_stat(void);
void disk_stat(void); void disk_stat(void);
void soft_info(void); void soft_info(void);
void Chat(int);
#endif #endif

View File

@ -35,8 +35,10 @@
#include "common.h" #include "common.h"
#include "mutil.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) unsigned char readkey(int y, int x, int fg, int bg)
@ -93,7 +95,7 @@ unsigned char testkey(int y, int x)
} }
Setraw(); Setraw();
rc = Waitchar(&ch, 100); rc = Waitchar(&ch, 50);
if (rc == 1) { if (rc == 1) {
if (ch == KEY_ESCAPE) if (ch == KEY_ESCAPE)
rc = Escapechar(&ch); 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) 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) void newinsert(int i, int fg, int bg)
{ {
insertflag = i; insertflag = i;
set_color(YELLOW, RED); set_color(YELLOW, RED);
if (insertflag != 0) { if (insertflag != 0) {
mvprintw(2,36," INS "); mvprintw(2,36," INS ");
} else { } else {
mvprintw(2,36," OVR "); mvprintw(2,36," OVR ");
} }
set_color(fg, bg); 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) int select_menu(int max)
{ {
static char *menu=(char *)"-"; static char *menu=(char *)"-";
char help[80]; char help[80];
int pick; int pick;
sprintf(help, "Select menu item (1..%d) or ^\"-\"^ for previous level.", max); sprintf(help, "Select menu item (1..%d) or ^\"-\"^ for previous level.", max);
showhelp(help); showhelp(help);
/* /*
* Loop forever until it's right. * Loop forever until it's right.
*/ */
for (;;) { for (;;) {
mvprintw(LINES - 3, 6, "Enter your choice >"); mvprintw(lines - 2, 6, "Enter your choice >");
menu = (char *)"-"; menu = (char *)"-";
menu = edit_field(LINES - 3, 26, 3, '9', menu); menu = edit_field(lines - 2, 26, 3, '9', menu);
locate(LINES -3, 6); locate(lines -2, 6);
clrtoeol(); clrtoeol();
if (strncmp(menu, "-", 1) == 0) if (strncmp(menu, "-", 1) == 0)
return 0; return 0;
pick = atoi(menu); pick = atoi(menu);
if ((pick >= 1) && (pick <= max)) if ((pick >= 1) && (pick <= max))
return pick; return pick;
working(2, 0, 0); working(2, 0, 0);
working(0, 0, 0); working(0, 0, 0);
} }
} }
void clrtoeol() void clrtoeol()
{ {
int i; int i;
printf("\r"); printf("\r");
for (i = 0; i < COLS; i++) for (i = 0; i < columns; i++)
putchar(' '); putchar(' ');
printf("\r"); printf("\r");
fflush(stdout); fflush(stdout);
} }
void hor_lin(int y, int x, int len) void hor_lin(int y, int x, int len)
{ {
int i; int i;
locate(y, x); locate(y, x);
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
putchar('-'); putchar('-');
fflush(stdout); fflush(stdout);
} }
@ -356,12 +358,12 @@ static int old_b = -1;
void set_color(int f, int b) void set_color(int f, int b)
{ {
if ((f != old_f) || (b != old_b)) { if ((f != old_f) || (b != old_b)) {
old_f = f; old_f = f;
old_b = b; old_b = b;
colour(f, b); colour(f, b);
fflush(stdout); fflush(stdout);
} }
} }
@ -383,10 +385,10 @@ void show_date(int fg, int bg, int y, int x)
set_color(LIGHTGREEN, BLUE); set_color(LIGHTGREEN, BLUE);
p = ctime(&now); p = ctime(&now);
Striplf(p); 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)); p = asctime(gmtime(&now));
Striplf(p); Striplf(p);
mvprintw(2, 44, (char *)"%s UTC", p); mvprintw(2, columns - 36, (char *)"%s UTC", p);
/* /*
* Indicator if bbs is free * 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;")); strcpy(buf, SockR("SBBS:0;"));
if (strncmp(buf, "100:2,1", 7) == 0) { if (strncmp(buf, "100:2,1", 7) == 0) {
set_color(WHITE, RED); set_color(WHITE, RED);
mvprintw(2,74, (char *)" Down "); mvprintw(2,columns - 6, (char *)" Down ");
} else { } else {
set_color(WHITE, BLUE); set_color(WHITE, BLUE);
mvprintw(2,74, (char *)" Free "); mvprintw(2,columns - 6, (char *)" Free ");
} }
bbs_free = TRUE; bbs_free = TRUE;
} else { } else {
set_color(WHITE, RED); set_color(WHITE, RED);
mvprintw(2,74, (char *)" Busy "); mvprintw(2,columns - 6, (char *)" Busy ");
bbs_free = FALSE; 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) 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) void screen_start(char *name)
{ {
int i; int i;
/* /*
* Overwrite screen the first time, if user had it black on white * 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. * it will change to white on black. clear() won't do the trick.
*/ */
set_color(LIGHTGRAY, BLUE); set_color(LIGHTGRAY, BLUE);
locate(1, 1); locate(1, 1);
for (i = 0; i < LINES; i++) { for (i = 0; i < lines; i++) {
if (i == 3) if (i == 3)
colour(LIGHTGRAY, BLACK); colour(LIGHTGRAY, BLACK);
clrtoeol(); clrtoeol();
if (i < LINES) if (i < lines)
printf("\n"); printf("\n");
} }
fflush(stdout); fflush(stdout);
set_color(WHITE, BLUE); set_color(WHITE, BLUE);
locate(1, 1); locate(1, 1);
printf((char *)"%s for MBSE BBS version %s", name, VERSION); printf((char *)"%s for MBSE BBS version %s", name, VERSION);
set_color(YELLOW, BLUE); set_color(YELLOW, BLUE);
locate(2, 1); locate(2, 1);
printf((char *)SHORTRIGHT); printf((char *)SHORTRIGHT);
set_color(LIGHTGRAY, BLACK); set_color(LIGHTGRAY, BLACK);
show_date(LIGHTGRAY, BLACK, 0, 0); show_date(LIGHTGRAY, BLACK, 0, 0);
fflush(stdout); fflush(stdout);
} }
@ -493,9 +495,9 @@ void screen_start(char *name)
*/ */
void screen_stop() void screen_stop()
{ {
set_color(LIGHTGRAY, BLACK); set_color(LIGHTGRAY, BLACK);
clear(); clear();
fflush(stdout); fflush(stdout);
} }
@ -505,51 +507,51 @@ void screen_stop()
*/ */
void working(int txno, int y, int x) void working(int txno, int y, int x)
{ {
int i; int i;
/* /*
* If txno not 0 there will be something written. The * If txno not 0 there will be something written. The
* reversed attributes for mono, or white on red for * reversed attributes for mono, or white on red for
* color screens is set. The cursor is turned off and * color screens is set. The cursor is turned off and
* original cursor position is saved. * original cursor position is saved.
*/ */
show_date(LIGHTGRAY, BLACK, 0, 0); show_date(LIGHTGRAY, BLACK, 0, 0);
if (txno != 0) if (txno != 0)
set_color(YELLOW, RED); set_color(YELLOW, RED);
else else
set_color(LIGHTGRAY, BLACK); set_color(LIGHTGRAY, BLACK);
switch (txno) { switch (txno) {
case 0: mvprintw(4, 66, (char *)" "); case 0: mvprintw(4, columns - 14, (char *)" ");
break; break;
case 1: mvprintw(4, 66, (char *)"Working . . ."); case 1: mvprintw(4, columns - 14, (char *)"Working . . .");
break; break;
case 2: mvprintw(4, 66, (char *)">>> ERROR <<<"); case 2: mvprintw(4, columns - 14, (char *)">>> ERROR <<<");
for (i = 1; i <= 5; i++) { for (i = 1; i <= 5; i++) {
putchar(7); putchar(7);
fflush(stdout); fflush(stdout);
usleep(150000); usleep(150000);
} }
usleep(550000); usleep(550000);
break; break;
case 3: mvprintw(4, 66, (char *)"Form inserted"); case 3: mvprintw(4, columns - 14, (char *)"Form inserted");
putchar(7); putchar(7);
fflush(stdout); fflush(stdout);
sleep(1); sleep(1);
break; break;
case 4: mvprintw(4, 66, (char *)"Form deleted "); case 4: mvprintw(4, columns - 14, (char *)"Form deleted ");
putchar(7); putchar(7);
fflush(stdout); fflush(stdout);
sleep(1); sleep(1);
break; break;
} }
show_date(LIGHTGRAY, BLACK, 0, 0); show_date(LIGHTGRAY, BLACK, 0, 0);
set_color(LIGHTGRAY, BLACK); set_color(LIGHTGRAY, BLACK);
if (y && x) if (y && x)
locate(y, x); locate(y, x);
fflush(stdout); fflush(stdout);
} }
@ -562,7 +564,7 @@ void clr_index()
int i; int i;
set_color(LIGHTGRAY, BLACK); set_color(LIGHTGRAY, BLACK);
for (i = 4; i <= (LINES - 1); i++) { for (i = 4; i <= (lines); i++) {
locate(i, 1); locate(i, 1);
clrtoeol(); clrtoeol();
} }
@ -575,31 +577,31 @@ void clr_index()
*/ */
void showhelp(char *T) void showhelp(char *T)
{ {
int f, i, x, forlim; int f, i, x, forlim;
f = FALSE; f = FALSE;
locate(LINES-1, 1); locate(lines, 1);
set_color(WHITE, RED); set_color(WHITE, RED);
clrtoeol(); clrtoeol();
x = 0; x = 0;
forlim = strlen(T); forlim = strlen(T);
for (i = 0; i < forlim; i++) { for (i = 0; i < forlim; i++) {
if (T[i] == '^') { if (T[i] == '^') {
if (f == FALSE) { if (f == FALSE) {
f = TRUE; f = TRUE;
set_color(YELLOW, RED); set_color(YELLOW, RED);
} else { } else {
f = FALSE; f = FALSE;
set_color(WHITE, RED); set_color(WHITE, RED);
} }
} else { } else {
putchar(T[i]); putchar(T[i]);
x++; x++;
}
} }
set_color(LIGHTGRAY, BLACK); }
fflush(stdout); set_color(LIGHTGRAY, BLACK);
fflush(stdout);
} }

View File

@ -6,13 +6,13 @@ include ../Makefile.global
SRCS = callstat.c scanout.c taskcomm.c taskinfo.c taskstat.c \ SRCS = callstat.c scanout.c taskcomm.c taskinfo.c taskstat.c \
mbtask.c outstat.c signame.c taskdisk.c taskregs.c taskutil.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 \ 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 \ 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 \ OBJS = callstat.o scanout.o taskcomm.o taskinfo.o taskstat.o \
mbtask.o outstat.o signame.o taskdisk.o taskregs.o taskutil.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 LIBS += ../lib/libnodelist.a
OTHER = Makefile issue issue.netbsd 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 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 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 crc.o: ../config.h libs.h crc.h
taskchat.o: ../config.h libs.h ../lib/structs.h taskchat.h
# End of generated dependencies # End of generated dependencies

36
mbtask/taskchat.c Normal file
View File

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

7
mbtask/taskchat.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef _TASKCHAT_H
#define _TASKCHAT_H
/* $Id$ */
#endif

View File

@ -360,10 +360,28 @@ int reg_user(char *data)
*/ */
int reg_sysop(char *data) int reg_sysop(char *data)
{ {
char *cnt; char *cnt, *pid;
int rec;
cnt = strtok(data, ","); cnt = strtok(data, ",");
pid = strtok(NULL, ",");
sysop_present = atoi(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"); Syslog('+', "Sysop present for chat: %s", sysop_present ? "True":"False");
return 0; return 0;
} }
@ -415,7 +433,7 @@ char *reg_ipm(char *data)
int reg_spm(char *data) int reg_spm(char *data)
{ {
char *cnt, *ch, *from, *too, *txt, *log; char *cnt, *ch, *from, *too, *txt, *log;
int i; int i, error = 0;
cnt = strtok(data, ","); cnt = strtok(data, ",");
ch = strtok(NULL, ","); ch = strtok(NULL, ",");
@ -424,7 +442,7 @@ int reg_spm(char *data)
txt = strtok(NULL, "\0"); txt = strtok(NULL, "\0");
txt[strlen(txt)-1] = '\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)); log = calloc(PATH_MAX, sizeof(char));
sprintf(log, "%s/log/%s", getenv("MBSE_ROOT"), CFG.chat_log); 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. * Personal messages and sysop/user chat messages.
*/ */
if (reginfo[i].pid && (strcasecmp(reginfo[i].uname, too) == 0) && if (reginfo[i].pid &&
((atoi(ch) == -1) || (atoi(ch) == 0)) && (atoi(ch) == reginfo[i].channel)) { (((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 * If the in and out pointers are the same and the
* message present flag is still set, then this user * message present flag is still set, then this user
* can't get anymore new messages. * can't get anymore new messages.
*/ */
if (reginfo[i].ismsg && (reginfo[i].ptr_in == reginfo[i].ptr_out)) { if (reginfo[i].ismsg && (reginfo[i].ptr_in == reginfo[i].ptr_out)) {
free(log); error = 2;
return 2;
} }
/* /*
* If user has the "do not distrurb" flag set, but the sysop ignore's this. * If user has the "do not distrurb" flag set, but the sysop ignore's this.
*/ */
if (reginfo[i].silent && (atoi(ch) == -1)) { if (reginfo[i].silent && (atoi(ch) == -1)) {
free(log); error = 1;
return 1;
} }
/* /*
@ -467,9 +484,11 @@ int reg_spm(char *data)
ulog(log, (char *)"+", from, ch, txt); 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); free(log);
return 0; return error;
} }
/* /*