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

View File

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

4
TODO
View File

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

View File

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

View File

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

View File

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

View File

@ -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"
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);
@ -74,7 +80,7 @@ void ShowSysinfo(void)
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");
center_addstr(lines - 3, (char *)"Press any key");
IsDoing("View System Info");
do {
@ -95,7 +101,7 @@ void ShowSysinfo(void)
fflush(stdout);
}
}
ch = testkey(LINES - 4, COLS / 2 + 8);
ch = testkey(lines - 3, columns / 2 + 8);
} while (ch == '\0');
}
@ -103,7 +109,7 @@ void ShowSysinfo(void)
void ShowLastcaller(void)
{
int records, ch, i, y, o;
int records, maxrows, ch, i, y, o;
char buf[128], *cnt;
clr_index();
@ -112,8 +118,9 @@ void ShowLastcaller(void)
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");
center_addstr(lines - 1, (char *)"Press any key");
IsDoing("View Lastcallers");
maxrows = lines - 10;
do {
show_date(LIGHTGRAY, BLACK, 0, 0);
@ -129,8 +136,8 @@ void ShowLastcaller(void)
if (records) {
y = 7;
if (records > 10)
o = records - 10;
if (records > maxrows)
o = records - maxrows;
else
o = 1;
set_color(CYAN, BLACK);
@ -140,13 +147,6 @@ void ShowLastcaller(void)
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, ","));
@ -162,7 +162,7 @@ void ShowLastcaller(void)
}
}
}
ch = testkey(LINES - 4, COLS / 2 + 8);
ch = testkey(lines - 1, columns / 2 + 8);
} while (ch == '\0');
}
@ -171,8 +171,7 @@ void ShowLastcaller(void)
void system_moni(void)
{
int ch, y, eof;
char *cnt;
char buf[128];
char *cnt, buf[128];
time_t start, now;
clr_index();
@ -181,7 +180,7 @@ void system_moni(void)
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");
center_addstr(lines - 1, (char *)"Press any key");
IsDoing("System Monitor");
do {
@ -190,7 +189,7 @@ void system_moni(void)
eof = 0;
set_color(LIGHTGRAY, BLACK);
for (y = 8; y <= LINES - 5; y++) {
for (y = 8; y <= lines - 2; y++) {
if (y == 8)
sprintf(buf, "GMON:1,1;");
else
@ -227,7 +226,7 @@ void system_moni(void)
}
} /* for () */
ch = testkey(LINES - 4, COLS / 2 + 8);
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,6 +510,7 @@ int main(int argc, char *argv[])
{
struct passwd *pw;
char buf[128];
int rc;
#ifdef MEMWATCH
mwInit();
@ -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;
}

View File

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

View File

@ -35,6 +35,8 @@
#include "common.h"
#include "mutil.h"
extern int lines, columns;
extern int ttyfd;
int bbs_free;
@ -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);
@ -306,10 +308,10 @@ int select_menu(int max)
* Loop forever until it's right.
*/
for (;;) {
mvprintw(LINES - 3, 6, "Enter your choice >");
mvprintw(lines - 2, 6, "Enter your choice >");
menu = (char *)"-";
menu = edit_field(LINES - 3, 26, 3, '9', menu);
locate(LINES -3, 6);
menu = edit_field(lines - 2, 26, 3, '9', menu);
locate(lines -2, 6);
clrtoeol();
if (strncmp(menu, "-", 1) == 0)
@ -331,7 +333,7 @@ void clrtoeol()
int i;
printf("\r");
for (i = 0; i < COLS; i++)
for (i = 0; i < columns; i++)
putchar(' ');
printf("\r");
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);
}
@ -466,11 +468,11 @@ void screen_start(char *name)
*/
set_color(LIGHTGRAY, BLUE);
locate(1, 1);
for (i = 0; i < LINES; i++) {
for (i = 0; i < lines; i++) {
if (i == 3)
colour(LIGHTGRAY, BLACK);
clrtoeol();
if (i < LINES)
if (i < lines)
printf("\n");
}
fflush(stdout);
@ -521,11 +523,11 @@ void working(int txno, int y, int x)
set_color(LIGHTGRAY, BLACK);
switch (txno) {
case 0: mvprintw(4, 66, (char *)" ");
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);
@ -533,12 +535,12 @@ void working(int txno, int y, int x)
}
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);
@ -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();
}
@ -578,7 +580,7 @@ void showhelp(char *T)
int f, i, x, forlim;
f = FALSE;
locate(LINES-1, 1);
locate(lines, 1);
set_color(WHITE, RED);
clrtoeol();
x = 0;

View File

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

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)
{
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;
}
/*