Updates for the chatserver
This commit is contained in:
parent
3d157ec16a
commit
c09bebade4
11
ChangeLog
11
ChangeLog
@ -49,10 +49,9 @@ v0.37.2 23-Feb-2003.
|
||||
Added support for door32.sys dropfile.
|
||||
Fixed user idle logoff when new mailcheck took too long.
|
||||
Added email reply when reading new (e)mail.
|
||||
With the CIPM and CSPM mbtask commands added the parameter for
|
||||
the chat channel.
|
||||
To page the sysop, the CPAG and CCAN commands to mbtask are now
|
||||
used.
|
||||
used. Until the chatserver is ready, there is no buildin sysop
|
||||
user chat.
|
||||
|
||||
mbmon:
|
||||
Reports sysop available or left the system when mbmon starts
|
||||
@ -65,17 +64,19 @@ v0.37.2 23-Feb-2003.
|
||||
The show lastcallers now adjusts the number of lines available.
|
||||
The show server clients screen now adjusts to the number of
|
||||
lines available.
|
||||
Added chatserver client, this is more or less complete now and
|
||||
does communicate with the development server.
|
||||
|
||||
mbtask:
|
||||
Safer logging of user log messages.
|
||||
The CSPM command has an extra channel parameter.
|
||||
The CIPM reply has an extra channel parameter.
|
||||
In personal message text the text after a ; character is not
|
||||
ignored anymore.
|
||||
Added CSYS command to report if sysop is available.
|
||||
Added CPAG command to page the sysop.
|
||||
Added CCAN command to cancel the sysop page.
|
||||
Added CCKP command to check for a page.
|
||||
Added CCON, CCLO, CPUT and CGET commands for chatserver. The
|
||||
chatserver commands will be added and are in development.
|
||||
|
||||
lang:
|
||||
Changed language prompts 15, 16 and 152.
|
||||
|
@ -57,7 +57,7 @@ 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 ../lib/mberrors.h common.h mutil.h
|
||||
mutil.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mberrors.h ../lib/structs.h common.h mutil.h
|
||||
mbmon.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mberrors.h ../lib/structs.h common.h mutil.h
|
||||
common.o: ../config.h ../lib/libs.h ../lib/memwatch.h ../lib/mberrors.h common.h
|
||||
# End of generated dependencies
|
||||
|
170
mbmon/mbmon.c
170
mbmon/mbmon.c
@ -33,6 +33,7 @@
|
||||
#include "../lib/libs.h"
|
||||
#include "../lib/memwatch.h"
|
||||
#include "../lib/mberrors.h"
|
||||
#include "../lib/structs.h"
|
||||
#include "common.h"
|
||||
#include "mutil.h"
|
||||
|
||||
@ -44,6 +45,13 @@ extern int bbs_free;
|
||||
extern int ttyfd;
|
||||
extern pid_t mypid;
|
||||
|
||||
struct sysconfig CFG;
|
||||
|
||||
|
||||
char rbuf[50][80]; /* Chat receive buffer */ /* FIXME: must be a dynamic buffer */
|
||||
int rpointer = 0; /* Chat receive pointer */
|
||||
int rsize = 5; /* Chat receive size */
|
||||
|
||||
|
||||
static void die(int onsig)
|
||||
{
|
||||
@ -416,46 +424,99 @@ void soft_info(void)
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Display received chat message
|
||||
*/
|
||||
void DispMsg(char *);
|
||||
void DispMsg(char *msg)
|
||||
{
|
||||
int i;
|
||||
|
||||
strncpy(rbuf[rpointer], msg, 80);
|
||||
mvprintw(4+rpointer, 1, rbuf[rpointer]);
|
||||
if (rpointer == rsize) {
|
||||
/*
|
||||
* Scroll buffer
|
||||
*/
|
||||
for (i = 0; i <= rsize; i++) {
|
||||
locate(i+4,1);
|
||||
clrtoeol();
|
||||
sprintf(rbuf[i], "%s", rbuf[i+1]);
|
||||
mvprintw(i+4, 1, rbuf[i]);
|
||||
}
|
||||
} else {
|
||||
rpointer++;
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Sysop/user chat
|
||||
*/
|
||||
void Chat(int channel)
|
||||
void Chat(void)
|
||||
{
|
||||
int curpos = 0, rline = 0;
|
||||
int curpos = 0, stop = FALSE, data;
|
||||
unsigned char ch = 0;
|
||||
char sbuf[81], rbuf[17][81], resp[128], from[36];
|
||||
static char buf[128];
|
||||
char sbuf[81], resp[128], *cnt, *msg;
|
||||
static char buf[200];
|
||||
|
||||
clr_index();
|
||||
rsize = lines - 7;
|
||||
rpointer = 0;
|
||||
|
||||
sprintf(buf, "CCON,2,%d,%s", mypid, CFG.sysop);
|
||||
Syslog('-', "> %s", buf);
|
||||
if (socket_send(buf) == 0) {
|
||||
strcpy(buf, socket_receive());
|
||||
Syslog('-', "< %s", buf);
|
||||
if (strncmp(buf, "100:1,", 6) == 0) {
|
||||
cnt = strtok(buf, ",");
|
||||
msg = strtok(NULL, "\0");
|
||||
msg[strlen(msg)-1] = '\0';
|
||||
set_color(LIGHTRED, BLACK);
|
||||
mvprintw(4, 1, msg);
|
||||
working(2, 0, 0);
|
||||
working(0, 0, 0);
|
||||
center_addstr(lines -4, (char *)"Press any key");
|
||||
readkey(lines - 4, columns / 2 + 8, LIGHTGRAY, BLACK);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
locate(lines - 2, 1);
|
||||
set_color(WHITE, BLUE);
|
||||
clrtoeol();
|
||||
mvprintw(lines - 2, 2, "Sysop to user chat, press @ to exit");
|
||||
mvprintw(lines - 2, 2, "Chat, type \"/EXIT\" to exit");
|
||||
|
||||
set_color(LIGHTGRAY, BLACK);
|
||||
mvprintw(lines - 1, 1, ">");
|
||||
memset(&sbuf, 0, sizeof(sbuf));
|
||||
memset(&rbuf, 0, sizeof(rbuf));
|
||||
|
||||
while (TRUE) {
|
||||
Syslog('-', "Start loop");
|
||||
|
||||
while (stop == FALSE) {
|
||||
|
||||
/*
|
||||
* Check for new message
|
||||
* Check for new message, loop fast until no more data available.
|
||||
*/
|
||||
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 */
|
||||
data = TRUE;
|
||||
while (data) {
|
||||
sprintf(buf, "CGET:1,%d;", mypid);
|
||||
if (socket_send(buf) == 0) {
|
||||
strcpy(buf, socket_receive());
|
||||
if (strncmp(buf, "100:1,", 6) == 0) {
|
||||
Syslog('-', "> CGET:1,%d;", mypid);
|
||||
Syslog('-', "< %s", buf);
|
||||
strncpy(resp, strtok(buf, ":"), 10); /* Should be 100 */
|
||||
strncpy(resp, strtok(NULL, ","), 5); /* Should be 1 */
|
||||
strncpy(resp, strtok(NULL, "\0"), 80); /* The message */
|
||||
resp[strlen(resp)-1] = '\0';
|
||||
DispMsg(resp);
|
||||
} else {
|
||||
data = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -489,11 +550,20 @@ void Chat(int channel)
|
||||
putchar(7);
|
||||
}
|
||||
} else if ((ch == '\r') && curpos) {
|
||||
sprintf(buf, "CSPM:4,%d,Sysop,-,%s;", channel, sbuf);
|
||||
Syslog('-', "%s", buf);
|
||||
if (strncasecmp(sbuf, "/exit", 5) == 0)
|
||||
stop = TRUE;
|
||||
sprintf(buf, "CPUT:2,%d,%s;", mypid, sbuf);
|
||||
Syslog('-', "> %s", buf);
|
||||
if (socket_send(buf) == 0) {
|
||||
strcpy(buf, socket_receive());
|
||||
Syslog('-', "%s", buf);
|
||||
Syslog('-', "< %s", buf);
|
||||
if (strncmp(buf, "100:1,", 6) == 0) {
|
||||
strncpy(resp, strtok(buf, ":"), 10); /* Should be 100 */
|
||||
strncpy(resp, strtok(NULL, ","), 5); /* Should be 1 */
|
||||
strncpy(resp, strtok(NULL, "\0"), 80); /* The message */
|
||||
resp[strlen(resp)-1] = '\0';
|
||||
DispMsg(resp);
|
||||
}
|
||||
}
|
||||
curpos = 0;
|
||||
memset(&sbuf, 0, sizeof(sbuf));
|
||||
@ -502,6 +572,41 @@ void Chat(int channel)
|
||||
mvprintw(lines - 1, 1, ">");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Before sending the close command, purge all outstanding messages.
|
||||
*/
|
||||
data = TRUE;
|
||||
while (data) {
|
||||
sprintf(buf, "CGET:1,%d;", mypid);
|
||||
if (socket_send(buf) == 0) {
|
||||
strcpy(buf, socket_receive());
|
||||
if (strncmp(buf, "100:1,", 6) == 0) {
|
||||
Syslog('-', "> CGET:1,%d;", mypid);
|
||||
Syslog('-', "< %s", buf);
|
||||
strncpy(resp, strtok(buf, ":"), 10); /* Should be 100 */
|
||||
strncpy(resp, strtok(NULL, ","), 5); /* Should be 1 */
|
||||
strncpy(resp, strtok(NULL, "\0"), 80); /* The message */
|
||||
resp[strlen(resp)-1] = '\0';
|
||||
DispMsg(resp);
|
||||
} else {
|
||||
data = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Close server connection
|
||||
*/
|
||||
sprintf(buf, "CCLO,1,%d", mypid);
|
||||
Syslog('-', "> %s", buf);
|
||||
if (socket_send(buf) == 0) {
|
||||
strcpy(buf, socket_receive());
|
||||
Syslog('-', "< %s", buf);
|
||||
if (strncmp(buf, "100:1,", 6)) {
|
||||
}
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
|
||||
@ -509,13 +614,28 @@ void Chat(int channel)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct passwd *pw;
|
||||
char buf[128];
|
||||
char buf[128], *temp;
|
||||
int rc;
|
||||
FILE *fp;
|
||||
|
||||
#ifdef MEMWATCH
|
||||
mwInit();
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Read configuration
|
||||
*/
|
||||
temp = calloc(PATH_MAX, sizeof(char));
|
||||
sprintf(temp, "%s/etc/config.data", getenv("MBSE_ROOT"));
|
||||
if ((fp = fopen(temp, "r")) == NULL) {
|
||||
perror("\n\nFATAL ERROR: ");
|
||||
printf(" Can't open %s", temp);
|
||||
exit(1);
|
||||
}
|
||||
fread(&CFG, sizeof(CFG), 1, fp);
|
||||
fclose(fp);
|
||||
free(temp);
|
||||
|
||||
/*
|
||||
* Find out who is on the keyboard or automated the keyboard.
|
||||
*/
|
||||
@ -597,7 +717,7 @@ int main(int argc, char *argv[])
|
||||
ShowLastcaller();
|
||||
break;
|
||||
case 6:
|
||||
Chat(0);
|
||||
Chat();
|
||||
break;
|
||||
case 7:
|
||||
soft_info();
|
||||
|
@ -10,6 +10,6 @@ void system_moni(void);
|
||||
void system_stat(void);
|
||||
void disk_stat(void);
|
||||
void soft_info(void);
|
||||
void Chat(int);
|
||||
void Chat(void);
|
||||
|
||||
#endif
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "../lib/libs.h"
|
||||
#include "../lib/memwatch.h"
|
||||
#include "../lib/mberrors.h"
|
||||
#include "../lib/structs.h"
|
||||
#include "common.h"
|
||||
#include "mutil.h"
|
||||
|
||||
|
@ -56,7 +56,7 @@ extern pid_t mypid; /* Pid of this program */
|
||||
void Check_PM(void);
|
||||
void Check_PM(void)
|
||||
{
|
||||
static char buf[128];
|
||||
static char buf[200];
|
||||
char resp[128];
|
||||
|
||||
sprintf(buf, "CIPM:1,%d;", mypid);
|
||||
@ -65,9 +65,8 @@ void Check_PM(void)
|
||||
if (strncmp(buf, "100:0;", 6) == 0)
|
||||
return;
|
||||
|
||||
strcpy(resp, strtok(buf, ":")); /* Should be 100 */
|
||||
strcpy(resp, strtok(NULL, ",")); /* Should be 3 */
|
||||
strcpy(resp, strtok(NULL, ",")); /* Should be channel -1 */
|
||||
strncpy(resp, strtok(buf, ":"), 5); /* Should be 100 */
|
||||
strncpy(resp, strtok(NULL, ","), 3); /* Should be 2 */
|
||||
strncpy(resp, strtok(NULL, ","), 36); /* From Name */
|
||||
colour(CYAN, BLACK);
|
||||
/* ** Message ** from */
|
||||
|
@ -315,11 +315,11 @@ void SendOnlineMsg(char *OpData)
|
||||
if ((strcmp(String, "")) != 0) {
|
||||
buf[0] = '\0';
|
||||
if ((strcasecmp(OpData, "/H") == 0) && strlen(exitinfo.sHandle))
|
||||
sprintf(buf, "CSPM:4,-1,%s,%s,%s;", exitinfo.sHandle, User, String);
|
||||
sprintf(buf, "CSPM:3,%s,%s,%s;", exitinfo.sHandle, User, String);
|
||||
else if (strcasecmp(OpData, "/U") == 0)
|
||||
sprintf(buf, "CSPM:4,-1,%s,%s,%s;", exitinfo.Name, User, String);
|
||||
sprintf(buf, "CSPM:3,%s,%s,%s;", exitinfo.Name, User, String);
|
||||
else
|
||||
sprintf(buf, "CSPM:4,-1,%s,%s,%s;", exitinfo.sUserName, User, String);
|
||||
sprintf(buf, "CSPM:3,%s,%s,%s;", exitinfo.sUserName, User, String);
|
||||
|
||||
if (socket_send(buf) == 0) {
|
||||
strcpy(buf, socket_receive());
|
||||
|
@ -80,10 +80,10 @@ depend:
|
||||
# Dependencies generated by make depend
|
||||
callstat.o: ../config.h libs.h ../lib/structs.h taskutil.h callstat.h
|
||||
scanout.o: ../config.h libs.h ../lib/structs.h taskutil.h scanout.h
|
||||
taskcomm.o: ../config.h libs.h ../lib/structs.h taskstat.h taskregs.h taskdisk.h taskinfo.h taskutil.h taskcomm.h
|
||||
taskcomm.o: ../config.h libs.h ../lib/structs.h taskstat.h taskregs.h taskdisk.h taskinfo.h taskutil.h taskchat.h taskcomm.h
|
||||
taskinfo.o: ../config.h libs.h ../lib/structs.h taskinfo.h
|
||||
taskstat.o: ../config.h libs.h ../lib/structs.h ../lib/mberrors.h taskstat.h callstat.h outstat.h taskutil.h
|
||||
mbtask.o: ../config.h libs.h ../lib/structs.h ../paths.h ../lib/mberrors.h signame.h taskstat.h taskutil.h taskregs.h taskcomm.h callstat.h outstat.h ../lib/nodelist.h ports.h calllist.h ping.h mbtask.h
|
||||
mbtask.o: ../config.h libs.h ../lib/structs.h ../paths.h ../lib/mberrors.h signame.h taskstat.h taskutil.h taskregs.h taskcomm.h callstat.h outstat.h ../lib/nodelist.h ports.h calllist.h ping.h taskchat.h mbtask.h
|
||||
outstat.o: ../config.h libs.h ../lib/structs.h ../lib/mberrors.h taskutil.h taskstat.h scanout.h ../lib/nodelist.h callstat.h ports.h outstat.h
|
||||
signame.o: ../config.h signame.h
|
||||
taskdisk.o: ../config.h libs.h ../lib/structs.h taskdisk.h taskutil.h
|
||||
@ -93,5 +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
|
||||
taskchat.o: ../config.h libs.h ../lib/structs.h taskutil.h taskchat.h
|
||||
# End of generated dependencies
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include "ports.h"
|
||||
#include "calllist.h"
|
||||
#include "ping.h"
|
||||
#include "taskchat.h"
|
||||
#include "mbtask.h"
|
||||
|
||||
|
||||
@ -1315,6 +1316,7 @@ int main(int argc, char **argv)
|
||||
initnl();
|
||||
load_ports();
|
||||
check_ports();
|
||||
chat_init();
|
||||
|
||||
/*
|
||||
* Now that init is complete and this program is locked, it is
|
||||
|
@ -31,6 +31,307 @@
|
||||
#include "../config.h"
|
||||
#include "libs.h"
|
||||
#include "../lib/structs.h"
|
||||
#include "taskutil.h"
|
||||
#include "taskregs.h"
|
||||
#include "taskchat.h"
|
||||
|
||||
#define MAXCHANNELS 100 /* Maximum chat channels */
|
||||
#define MAXMESSAGES 100 /* Maximum ringbuffer for messages */
|
||||
|
||||
|
||||
typedef enum {CH_FREE, CH_PRIVATE, CH_PUBLIC} CHANNELTYPE;
|
||||
|
||||
|
||||
/*
|
||||
* Users connected to the chatserver.
|
||||
*/
|
||||
typedef struct _ch_user_rec {
|
||||
pid_t pid; /* User's pid */
|
||||
char name[36]; /* His name used (may become nick) */
|
||||
time_t connected; /* Time connected */
|
||||
int channel; /* Connected channel or -1 */
|
||||
int pointer; /* Message pointer */
|
||||
unsigned chatting : 1; /* Is chatting in a channel */
|
||||
unsigned chanop : 1; /* Is a chanop */
|
||||
} _chat_users;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Buffer for messages, this is the structure of a ringbuffer which will
|
||||
* hold all messages, private public etc. There is one global input pointer
|
||||
* which points to the current head of the ringbuffer. When a user connects
|
||||
* to a channel, he will get the latest messages in the channel if they
|
||||
* are present.
|
||||
*/
|
||||
typedef struct _chatmsg {
|
||||
pid_t topid; /* Destination pid of message */
|
||||
char fromname[36]; /* Message from user */
|
||||
char message[81]; /* The message to display */
|
||||
time_t posted; /* Timestamp for posted message */
|
||||
} _chat_messages;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* List of banned users from a channel. This is a dynamic list.
|
||||
*/
|
||||
typedef struct _banned {
|
||||
int channel; /* Channel the user is banned from */
|
||||
char user[36]; /* The user who is banned */
|
||||
} banned_users;
|
||||
|
||||
|
||||
/*
|
||||
* The buffers
|
||||
*/
|
||||
_chat_messages chat_messages[MAXMESSAGES];
|
||||
_chat_users chat_users[MAXCLIENT];
|
||||
|
||||
|
||||
int buffer_head = 0; /* Messages buffer head */
|
||||
extern struct sysconfig CFG; /* System configuration */
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Put a system message into the chatbuffer
|
||||
*/
|
||||
void system_msg(pid_t, char *);
|
||||
void system_msg(pid_t pid, char *msg)
|
||||
{
|
||||
if (buffer_head < MAXMESSAGES)
|
||||
buffer_head++;
|
||||
else
|
||||
buffer_head = 0;
|
||||
|
||||
Syslog('-', "system_msg(%d, %s) ptr=%d", pid, msg, buffer_head);
|
||||
memset(&chat_messages[buffer_head], 0, sizeof(_chat_messages));
|
||||
chat_messages[buffer_head].topid = pid;
|
||||
sprintf(chat_messages[buffer_head].fromname, "Server");
|
||||
strncpy(chat_messages[buffer_head].message, msg, 80);
|
||||
chat_messages[buffer_head].posted = time(NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Show help
|
||||
*/
|
||||
void chat_help(pid_t);
|
||||
void chat_help(pid_t pid)
|
||||
{
|
||||
system_msg(pid, (char *)"Topics available:");
|
||||
system_msg(pid, (char *)"");
|
||||
system_msg(pid, (char *)" EXIT HELP");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void chat_init(void)
|
||||
{
|
||||
memset(&chat_users, 0, sizeof(chat_users));
|
||||
memset(&chat_messages, 0, sizeof(chat_messages));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Connect a session to the chatserver.
|
||||
*/
|
||||
char *chat_connect(char *data)
|
||||
{
|
||||
char *pid, *usr;
|
||||
static char buf[200];
|
||||
int i, j, count = 0;
|
||||
|
||||
Syslog('-', "CCON:%s", data);
|
||||
memset(&buf, 0, sizeof(buf));
|
||||
|
||||
/*
|
||||
* Search free userslot
|
||||
*/
|
||||
for (i = 0; i < MAXCLIENT; i++) {
|
||||
if (chat_users[i].pid == 0) {
|
||||
/*
|
||||
* Oke, found
|
||||
*/
|
||||
pid = strtok(data, ","); /* Should be 2 */
|
||||
pid = strtok(NULL, ","); /* The pid */
|
||||
usr = strtok(NULL, ";"); /* Username */
|
||||
chat_users[i].pid = atoi(pid);
|
||||
strncpy(chat_users[i].name, usr, 36);
|
||||
chat_users[i].connected = time(NULL);
|
||||
chat_users[i].pointer = buffer_head;
|
||||
chat_users[i].channel = -1;
|
||||
|
||||
Syslog('-', "Connected user %s (%s) with chatserver, slot %d", usr, pid, i);
|
||||
|
||||
/*
|
||||
* Now put welcome message into the ringbuffer and report success.
|
||||
*/
|
||||
sprintf(buf, "MBSE BBS v%s chat server; type /help for help", VERSION);
|
||||
system_msg(chat_users[i].pid, buf);
|
||||
sprintf(buf, "Welcome to the %s chat network", CFG.bbs_name);
|
||||
system_msg(chat_users[i].pid, buf);
|
||||
for (j = 0; j < MAXCLIENT; j++)
|
||||
if (chat_users[j].pid)
|
||||
count++;
|
||||
sprintf(buf, "There %s %d user%s connected", (count != 1)?"are":"is", count, (count != 1)?"s":"");
|
||||
system_msg(chat_users[i].pid, buf);
|
||||
|
||||
sprintf(buf, "100:0;");
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
sprintf(buf, "100:1,Too many users connected;");
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *chat_close(char *data)
|
||||
{
|
||||
static char buf[200];
|
||||
char *pid;
|
||||
int i;
|
||||
|
||||
Syslog('-', "CCLO:%s", data);
|
||||
memset(&buf, 0, sizeof(buf));
|
||||
pid = strtok(data, ",");
|
||||
pid = strtok(NULL, ";");
|
||||
|
||||
for (i = 0; i < MAXCLIENT; i++) {
|
||||
if (chat_users[i].pid == atoi(pid)) {
|
||||
Syslog('-', "Closing chat for pid %s, slot %d", pid, i);
|
||||
memset(&chat_users[i], 0, sizeof(_chat_users));
|
||||
sprintf(buf, "100:0;");
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
Syslog('-', "Pid %s was not connected to chatserver");
|
||||
sprintf(buf, "100:1,ERROR - Not connected to server;");
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *chat_put(char *data)
|
||||
{
|
||||
static char buf[200];
|
||||
char *pid, *msg, *cmd;
|
||||
int i;
|
||||
|
||||
Syslog('-', "CPUT:%s", data);
|
||||
memset(&buf, 0, sizeof(buf));
|
||||
|
||||
pid = strtok(data, ",");
|
||||
pid = strtok(NULL, ",");
|
||||
msg = strtok(NULL, "\0");
|
||||
msg[strlen(msg)-1] = '\0';
|
||||
|
||||
for (i = 0; i < MAXCLIENT; i++) {
|
||||
if (chat_users[i].pid == atoi(pid)) {
|
||||
/*
|
||||
* We are connected and known, first send the input back to ourself.
|
||||
*/
|
||||
system_msg(chat_users[i].pid, msg);
|
||||
|
||||
if (msg[0] == '/') {
|
||||
/*
|
||||
* A command, process this
|
||||
*/
|
||||
if (strncasecmp(msg, "/help", 5) == 0) {
|
||||
chat_help(atoi(pid));
|
||||
sprintf(buf, "100:0;");
|
||||
return buf;
|
||||
}
|
||||
if (strncasecmp(msg, "/exit", 5) == 0) {
|
||||
/*
|
||||
* Just send messages, the client should later do a
|
||||
* real disconnect.
|
||||
*/
|
||||
sprintf(buf, "Goodbye");
|
||||
system_msg(chat_users[i].pid, buf);
|
||||
sprintf(buf, "100:0;");
|
||||
return buf;
|
||||
}
|
||||
if (strncasecmp(msg, "/join", 5) == 0) {
|
||||
cmd = strtok(msg, " \0");
|
||||
Syslog('-', "\"%s\"", cmd);
|
||||
cmd = strtok(NULL, "\0");
|
||||
Syslog('-', "\"%s\"", cmd);
|
||||
if ((cmd == NULL) || (cmd[0] != '#') || (strcmp(cmd, "#") == 0)) {
|
||||
sprintf(buf, "Try /join #channel");
|
||||
system_msg(chat_users[i].pid, buf);
|
||||
} else {
|
||||
Syslog('-', "Trying to join channel %s", cmd);
|
||||
}
|
||||
sprintf(buf, "100:0;");
|
||||
return buf;
|
||||
}
|
||||
/*
|
||||
* If still here, the command was not recognized.
|
||||
*/
|
||||
cmd = strtok(msg, " \t\r\n\0");
|
||||
sprintf(buf, "%s :Unknown command", cmd+1);
|
||||
system_msg(chat_users[i].pid, buf);
|
||||
sprintf(buf, "100:0;");
|
||||
return buf;
|
||||
}
|
||||
if (chat_users[i].channel == -1) {
|
||||
/*
|
||||
* Trying messages while not in a channel
|
||||
*/
|
||||
sprintf(buf, "No channel joined. Try /join #channel");
|
||||
system_msg(chat_users[i].pid, buf);
|
||||
sprintf(buf, "100:0;");
|
||||
return buf;
|
||||
}
|
||||
sprintf(buf, "100:0;");
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
Syslog('-', "Pid %s was not connected to chatserver");
|
||||
sprintf(buf, "100:1,ERROR - Not connected to server;");
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *chat_get(char *data)
|
||||
{
|
||||
static char buf[200];
|
||||
char *pid;
|
||||
int i;
|
||||
|
||||
Syslog('-', "CGET:%s", data);
|
||||
memset(&buf, 0, sizeof(buf));
|
||||
pid = strtok(data, ",");
|
||||
pid = strtok(NULL, ";");
|
||||
|
||||
for (i = 0; i < MAXCLIENT; i++) {
|
||||
if (atoi(pid) == chat_users[i].pid) {
|
||||
while (chat_users[i].pointer != buffer_head) {
|
||||
if (chat_users[i].pointer < MAXMESSAGES)
|
||||
chat_users[i].pointer++;
|
||||
else
|
||||
chat_users[i].pointer = 0;
|
||||
if (chat_users[i].pid == chat_messages[chat_users[i].pointer].topid) {
|
||||
/*
|
||||
* Message is for us.
|
||||
*/
|
||||
sprintf(buf, "100:1,%s;", chat_messages[chat_users[i].pointer].message);
|
||||
Syslog('-', "%s", buf);
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
sprintf(buf, "100:0;");
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
sprintf(buf, "100:1,ERROR - Not connected to server;");
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,5 +3,10 @@
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
void chat_init(void);
|
||||
char *chat_connect(char *);
|
||||
char *chat_close(char *);
|
||||
char *chat_put(char *);
|
||||
char *chat_get(char *);
|
||||
|
||||
#endif
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "taskdisk.h"
|
||||
#include "taskinfo.h"
|
||||
#include "taskutil.h"
|
||||
#include "taskchat.h"
|
||||
#include "taskcomm.h"
|
||||
|
||||
|
||||
@ -239,14 +240,10 @@ char *exe_cmd(char *in)
|
||||
}
|
||||
|
||||
/*
|
||||
* The chat commands
|
||||
* Check for personal message
|
||||
*
|
||||
* Used channels: -1 Personal messages between ordinary users.
|
||||
* 0 Sysop/user chat
|
||||
* 1..99 Chatting channels
|
||||
*
|
||||
* CIPM:1,pid; (Is personal/chat message present)
|
||||
* 100:3,channel,fromname,message;
|
||||
* CIPM:1,pid; (Is personal message present)
|
||||
* 100:2,fromname,message;
|
||||
* 100:0;
|
||||
*/
|
||||
if (strncmp(cmd, "CIPM", 4) == 0) {
|
||||
@ -254,7 +251,7 @@ char *exe_cmd(char *in)
|
||||
}
|
||||
|
||||
/*
|
||||
* CSPM:3,channel,fromuser,touser,text; (Send personal/chat message).
|
||||
* CSPM:3,fromuser,touser,text; (Send personal message).
|
||||
* 100:1,n; n: 1=donotdisturb 2=buffer full 3=error
|
||||
* 100:0;
|
||||
*/
|
||||
@ -296,10 +293,63 @@ char *exe_cmd(char *in)
|
||||
return obuf;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for sysop page (from mbmon)
|
||||
*
|
||||
* CCKP:0;
|
||||
* 100:3,pid,1,reason; Page is active
|
||||
* 100:3,pid,0,reason; Page is canceled, but user still online
|
||||
* 100:0; No page active
|
||||
*/
|
||||
if (strncmp(cmd, "CCKP", 4) == 0) {
|
||||
return reg_checkpage(token);
|
||||
}
|
||||
|
||||
/*
|
||||
* Connect to chatserver
|
||||
*
|
||||
* CCON:2,pid,username; Connect to chatserver with username
|
||||
* 100:1,error; If error
|
||||
* 100:0; Ok
|
||||
*/
|
||||
if (strncmp(cmd, "CCON", 4) == 0) {
|
||||
return chat_connect(token);
|
||||
}
|
||||
|
||||
/*
|
||||
* Close chat session
|
||||
*
|
||||
* CCLO:1,pid; Leave chatserver
|
||||
* 100:1,error; Error
|
||||
* 100:0; Ok
|
||||
*/
|
||||
if (strncmp(cmd, "CCLO", 4) == 0) {
|
||||
return chat_close(token);
|
||||
}
|
||||
|
||||
/*
|
||||
* Put message on server
|
||||
*
|
||||
* CPUT:2,pid,message; Put message on server
|
||||
* 100:1,error; Error
|
||||
* 100:0; Ok
|
||||
*/
|
||||
if (strncmp(cmd, "CPUT", 4) == 0) {
|
||||
return chat_put(token);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get message from server
|
||||
*
|
||||
* CGET:1,pid; Get message from server
|
||||
* 100:1,message; If message present
|
||||
* 100:0; No message
|
||||
*/
|
||||
if (strncmp(cmd, "CGET", 4) == 0) {
|
||||
return chat_get(token);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The G(lobal) commands.
|
||||
*
|
||||
|
@ -406,12 +406,11 @@ char *reg_ipm(char *data)
|
||||
return buf;
|
||||
|
||||
reginfo[rec].lastcon = time(NULL);
|
||||
if (!reginfo[rec].ismsg || (reginfo[rec].channel != -1))
|
||||
if (!reginfo[rec].ismsg)
|
||||
return buf;
|
||||
|
||||
buf[0] = '\0';
|
||||
sprintf(buf, "100:3,%d,%s,%s;", reginfo[rec].channel,
|
||||
reginfo[rec].fname[reginfo[rec].ptr_out], reginfo[rec].msg[reginfo[rec].ptr_out]);
|
||||
sprintf(buf, "100:2,%s,%s;", reginfo[rec].fname[reginfo[rec].ptr_out], reginfo[rec].msg[reginfo[rec].ptr_out]);
|
||||
if (reginfo[rec].ptr_out < RB)
|
||||
reginfo[rec].ptr_out++;
|
||||
else
|
||||
@ -419,8 +418,7 @@ char *reg_ipm(char *data)
|
||||
if (reginfo[rec].ptr_out == reginfo[rec].ptr_in)
|
||||
reginfo[rec].ismsg = FALSE;
|
||||
|
||||
Syslog('+', "reg_ipm: ch=%d in=%d out=%d ismsg=%d", reginfo[rec].channel,
|
||||
reginfo[rec].ptr_in, reginfo[rec].ptr_out, reginfo[rec].ismsg);
|
||||
Syslog('+', "reg_ipm: in=%d out=%d ismsg=%d", reginfo[rec].ptr_in, reginfo[rec].ptr_out, reginfo[rec].ismsg);
|
||||
|
||||
return buf;
|
||||
}
|
||||
@ -432,41 +430,33 @@ char *reg_ipm(char *data)
|
||||
*/
|
||||
int reg_spm(char *data)
|
||||
{
|
||||
char *cnt, *ch, *from, *too, *txt, *log;
|
||||
int i, error = 0;
|
||||
char *cnt, *from, *too, *txt, *log;
|
||||
int i;
|
||||
|
||||
cnt = strtok(data, ",");
|
||||
ch = strtok(NULL, ",");
|
||||
from = strtok(NULL, ",");
|
||||
too = strtok(NULL, ",");
|
||||
txt = strtok(NULL, "\0");
|
||||
txt[strlen(txt)-1] = '\0';
|
||||
|
||||
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);
|
||||
Syslog('-', "SIPM:%s,%s,%s,%s;", cnt, from, too, txt);
|
||||
|
||||
for (i = 0; i < MAXCLIENT; i++) {
|
||||
/*
|
||||
* 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)) {
|
||||
/*
|
||||
* 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)) {
|
||||
error = 2;
|
||||
return 2;
|
||||
}
|
||||
|
||||
/*
|
||||
* If user has the "do not distrurb" flag set, but the sysop ignore's this.
|
||||
*/
|
||||
if (reginfo[i].silent && (atoi(ch) == -1)) {
|
||||
error = 1;
|
||||
if (reginfo[i].silent) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -481,45 +471,18 @@ int reg_spm(char *data)
|
||||
reginfo[i].ismsg = TRUE;
|
||||
|
||||
if (CFG.iAutoLog && strlen(CFG.chat_log)) {
|
||||
ulog(log, (char *)"+", from, ch, txt);
|
||||
log = calloc(PATH_MAX, sizeof(char));
|
||||
sprintf(log, "%s/log/%s", getenv("MBSE_ROOT"), CFG.chat_log);
|
||||
ulog(log, (char *)"+", from, (char *)"-1", txt);
|
||||
free(log);
|
||||
}
|
||||
|
||||
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 error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Chat messages, they are send to each user that is chatting in the right channel.
|
||||
*/
|
||||
if (reginfo[i].pid && reginfo[i].chatting && reginfo[i].channel == atoi(ch)) {
|
||||
if (reginfo[i].ismsg && (reginfo[i].ptr_in == reginfo[i].ptr_out)) {
|
||||
Syslog('!', "reg_spm: buffer full for %s", reginfo[i].uname);
|
||||
} else {
|
||||
strncpy((char *)®info[i].fname[reginfo[i].ptr_in], from, 35);
|
||||
strncpy((char *)®info[i].msg[reginfo[i].ptr_in], txt, 80);
|
||||
if (reginfo[i].ptr_in < RB)
|
||||
reginfo[i].ptr_in++;
|
||||
else
|
||||
reginfo[i].ptr_in = 0;
|
||||
reginfo[i].ismsg = TRUE;
|
||||
|
||||
if (CFG.iAutoLog && strlen(CFG.chat_log)) {
|
||||
ulog(log, (char *)"+", from, ch, txt);
|
||||
}
|
||||
|
||||
Syslog('+', "reg_spm: user=%s in=%d out=%d ismsg=%d", reginfo[i].uname, reginfo[i].ptr_in,
|
||||
reginfo[i].ptr_out, reginfo[i].ismsg);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
free(log);
|
||||
if ((atoi(ch) == -1) || (atoi(ch) == 0))
|
||||
return 3; // Error
|
||||
return 0; // Ok
|
||||
|
||||
return 3; // Error, user not found
|
||||
}
|
||||
|
||||
|
||||
|
@ -51,8 +51,8 @@ int reg_timer(int, char *);
|
||||
int reg_tty(char *);
|
||||
int reg_user(char *);
|
||||
int reg_silent(char *); /* Set/Reset do not disturb */
|
||||
char *reg_ipm(char *); /* Check for personal/chat msg */
|
||||
int reg_spm(char *); /* Send personal/chat message */
|
||||
char *reg_ipm(char *); /* Check for personal message */
|
||||
int reg_spm(char *); /* Send personal message */
|
||||
char *reg_fre(void); /* Check if system is free */
|
||||
char *get_reginfo(int); /* Get registration info */
|
||||
int reg_sysop(char *); /* Registrate sysop presence */
|
||||
|
Reference in New Issue
Block a user