Fixed small bbs problem, started chat protocol

This commit is contained in:
Michiel Broek
2003-03-19 22:45:46 +00:00
parent f5a9861ead
commit 0fc8c478f4
12 changed files with 791 additions and 680 deletions

View File

@@ -77,276 +77,291 @@ int userlog(char *param)
char *exe_cmd(char *);
char *exe_cmd(char *in)
{
static char obuf[SS_BUFSIZE];
static char ibuf[SS_BUFSIZE];
static char cmd[4];
static char token[SS_BUFSIZE];
static char ebuf[19];
static char *cnt, var1[16];
int result;
static char obuf[SS_BUFSIZE];
static char ibuf[SS_BUFSIZE];
static char cmd[4];
static char token[SS_BUFSIZE];
static char ebuf[19];
static char *cnt, var1[16];
int result;
strcpy(ibuf, in);
strncpy(cmd, ibuf, 4);
token[0] = '\0';
strcpy(ebuf, "200:1,Syntax error;");
strcpy(ibuf, in);
strncpy(cmd, ibuf, 4);
token[0] = '\0';
strcpy(ebuf, "200:1,Syntax error;");
/*
* Split the commandline after the colon so we can give the
* options directly to the actual functions. Also set a default
* and most used answer.
*/
strcpy(token, &ibuf[5]);
strcpy(obuf, "100:0;");
/*
* Split the commandline after the colon so we can give the
* options directly to the actual functions. Also set a default
* and most used answer.
*/
strcpy(token, &ibuf[5]);
strcpy(obuf, "100:0;");
/*
* The A(counting) commands.
*
* AINI:5,pid,tty,user,program,city;
* 100:0;
* 200:1,Syntax Error;
*/
if (strncmp(cmd, "AINI", 4) == 0) {
if (reg_newcon(token) != -1)
return obuf;
else {
stat_inc_serr();
return ebuf;
}
/*
* The A(counting) commands.
*
* AINI:5,pid,tty,user,program,city;
* 100:0;
* 200:1,Syntax Error;
*/
if (strncmp(cmd, "AINI", 4) == 0) {
if (reg_newcon(token) != -1)
return obuf;
else {
stat_inc_serr();
return ebuf;
}
}
/*
* ACLO:1,pid;
* 107:0;
* 200:1,Syntax Error;
*/
if (strncmp(cmd ,"ACLO", 4) == 0) {
if (reg_closecon(token) == 0) {
strcpy(obuf, "107:0;");
return obuf;
} else {
stat_inc_serr();
return ebuf;
}
/*
* ACLO:1,pid;
* 107:0;
* 200:1,Syntax Error;
*/
if (strncmp(cmd ,"ACLO", 4) == 0) {
if (reg_closecon(token) == 0) {
strcpy(obuf, "107:0;");
return obuf;
} else {
stat_inc_serr();
return ebuf;
}
}
/*
* ADOI:2,pid,doing;
* 100:0;
* 200:1,Syntax Error;
*/
if (strncmp(cmd, "ADOI", 4) == 0) {
if (reg_doing(token) == 0)
return obuf;
else {
stat_inc_serr();
return ebuf;
}
/*
* ADOI:2,pid,doing;
* 100:0;
* 200:1,Syntax Error;
*/
if (strncmp(cmd, "ADOI", 4) == 0) {
if (reg_doing(token) == 0)
return obuf;
else {
stat_inc_serr();
return ebuf;
}
}
/*
* ATCP:1,pid;
* 100:0;
* 200:1,Syntax Error;
*/
if (strncmp(cmd, "ATCP", 4) == 0) {
if (reg_ip(token) == 0)
return obuf;
else {
stat_inc_serr();
return ebuf;
}
/*
* ATCP:1,pid;
* 100:0;
* 200:1,Syntax Error;
*/
if (strncmp(cmd, "ATCP", 4) == 0) {
if (reg_ip(token) == 0)
return obuf;
else {
stat_inc_serr();
return ebuf;
}
}
/*
* ATTY:2,pid,tty;
* 100:0;
* 200:1,Syntax Error;
*/
if (strncmp(cmd, "ATTY", 4) == 0) {
if (reg_tty(token) == 0)
return obuf;
else {
stat_inc_serr();
return ebuf;
}
/*
* ATTY:2,pid,tty;
* 100:0;
* 200:1,Syntax Error;
*/
if (strncmp(cmd, "ATTY", 4) == 0) {
if (reg_tty(token) == 0)
return obuf;
else {
stat_inc_serr();
return ebuf;
}
}
/*
* ALOG:5,file,program,pid,grade,text;
* 100:0;
* 201:1,errno;
*/
if (strncmp(cmd, "ALOG", 4) == 0) {
if (userlog(token) != 0)
sprintf(obuf, "201:1,%d;", oserr);
return obuf;
}
/*
* ALOG:5,file,program,pid,grade,text;
* 100:0;
* 201:1,errno;
*/
if (strncmp(cmd, "ALOG", 4) == 0) {
if (userlog(token) != 0)
sprintf(obuf, "201:1,%d;", oserr);
return obuf;
}
/*
* AUSR:3,pid,user,city;
* 100:0;
* 200:1,Syntax Error;
*/
if (strncmp(cmd, "AUSR", 4) == 0) {
if (reg_user(token) == 0)
return obuf;
else {
stat_inc_serr();
return ebuf;
}
/*
* AUSR:3,pid,user,city;
* 100:0;
* 200:1,Syntax Error;
*/
if (strncmp(cmd, "AUSR", 4) == 0) {
if (reg_user(token) == 0)
return obuf;
else {
stat_inc_serr();
return ebuf;
}
}
/*
* ADIS:2,pid,flag; (set Do Not Disturb).
* 100:0;
* 200:1,Syntax Error;
*/
if (strncmp(cmd, "ADIS", 4) == 0) {
if (reg_silent(token) == 0)
return obuf;
else {
stat_inc_serr();
return ebuf;
}
/*
* ADIS:2,pid,flag; (set Do Not Disturb).
* 100:0;
* 200:1,Syntax Error;
*/
if (strncmp(cmd, "ADIS", 4) == 0) {
if (reg_silent(token) == 0)
return obuf;
else {
stat_inc_serr();
return ebuf;
}
}
/*
* ATIM:2,pid,seconds;
* 100:0;
* 200:1,Syntax Error;
*/
if (strncmp(cmd, "ATIM", 4) == 0) {
if (reg_timer(TRUE, token) == 0)
return obuf;
else {
stat_inc_serr();
return ebuf;
}
/*
* ATIM:2,pid,seconds;
* 100:0;
* 200:1,Syntax Error;
*/
if (strncmp(cmd, "ATIM", 4) == 0) {
if (reg_timer(TRUE, token) == 0)
return obuf;
else {
stat_inc_serr();
return ebuf;
}
}
/*
* ADEF:1,pid;
* 100:0;
*/
if (strncmp(cmd, "ADEF", 4) == 0) {
if (reg_timer(FALSE, token) == 0)
return obuf;
else {
stat_inc_serr();
return ebuf;
}
/*
* ADEF:1,pid;
* 100:0;
*/
if (strncmp(cmd, "ADEF", 4) == 0) {
if (reg_timer(FALSE, token) == 0)
return obuf;
else {
stat_inc_serr();
return ebuf;
}
}
/*
* The chat commands
*
* CIPM:1,pid; (Is personal message present)
* 100:2,fromname,message;
* 100:0;
*/
if (strncmp(cmd, "CIPM", 4) == 0) {
return reg_ipm(token);
}
/*
* The chat commands
*
* 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;
* 100:0;
*/
if (strncmp(cmd, "CIPM", 4) == 0) {
return reg_ipm(token);
}
/*
* CSPM:3,fromuser,touser,text; (Send personal message).
* 100:1,n; n: 0=oke, 1=donotdisturb 2=buffer full 3=error
* 100:0;
*/
if (strncmp(cmd, "CSPM", 4) == 0) {
if ((result = reg_spm(token))) {
sprintf(obuf, "100:1,%d;", result);
return obuf;
} else
return obuf;
}
/*
* CSPM:3,channel,fromuser,touser,text; (Send personal/chat message).
* 100:1,n; n: 1=donotdisturb 2=buffer full 3=error
* 100:0;
*/
if (strncmp(cmd, "CSPM", 4) == 0) {
if ((result = reg_spm(token))) {
sprintf(obuf, "100:1,%d;", result);
return obuf;
} else
return obuf;
}
/*
* The G(lobal) commands.
*
* GNOP:1,pid;
* 100:0;
*/
if (strncmp(cmd ,"GNOP", 4) == 0) {
reg_nop(token);
return obuf;
}
/*
* CSYS:1,1; Sysop available for chat (from mbmon)
* CSYS:1,0; Sysop goes away (from mbmon)
* 100:0; Allways Ok.
*/
if (strncmp(cmd, "CSYS", 4) == 0) {
reg_sysop(token);
return obuf;
}
/*
* GPNG:n,data;
* 100:n,data;
*/
if (strncmp(cmd, "GPNG", 4) == 0) {
sprintf(obuf, "100:%s", token);
return obuf;
}
/*
* GVER:0;
* 100:1,Version ...;
*/
if (strncmp(cmd, "GVER", 4) == 0) {
sprintf(obuf, "100:1,Version %s;", VERSION);
return obuf;
}
/*
* The G(lobal) commands.
*
* GNOP:1,pid;
* 100:0;
*/
if (strncmp(cmd ,"GNOP", 4) == 0) {
reg_nop(token);
return obuf;
}
/*
* GSTA:0;
* 100:19,start,laststart,daily,startups,clients,tot_clients,tot_peak,tot_syntax,tot_comerr,
* today_clients,today_peak,today_syntax,today_comerr,!BBSopen,ZMH,internet,Processing,Load,sequence;
* 201:1,16;
*/
if (strncmp(cmd, "GSTA", 4) == 0) {
return stat_status();
}
/*
* GPNG:n,data;
* 100:n,data;
*/
if (strncmp(cmd, "GPNG", 4) == 0) {
sprintf(obuf, "100:%s", token);
return obuf;
}
/*
* GMON:1,n; n=1 First time
* 100:7,pid,tty,user,program,city,isdoing,starttime;
* 100:0;
*/
if (strncmp(cmd, "GMON", 4) == 0) {
cnt = strtok(token, ",");
strcpy(var1, strtok(NULL, ";"));
return get_reginfo(atoi(var1));
}
/*
* GVER:0;
* 100:1,Version ...;
*/
if (strncmp(cmd, "GVER", 4) == 0) {
sprintf(obuf, "100:1,Version %s;", VERSION);
return obuf;
}
/*
* GDST:0;
* 100:n,data1,..,data10;
*/
if (strncmp(cmd, "GDST", 4) == 0) {
return get_diskstat();
}
/*
* GSTA:0;
* 100:19,start,laststart,daily,startups,clients,tot_clients,tot_peak,tot_syntax,tot_comerr,
* today_clients,today_peak,today_syntax,today_comerr,!BBSopen,ZMH,internet,Processing,Load,sequence;
* 201:1,16;
*/
if (strncmp(cmd, "GSTA", 4) == 0) {
return stat_status();
}
/*
* GSYS:0;
* 100:7,calls,pots_calls,isdn_calls,network_calls,local_calls,startdate,last_caller;
* 201:1,16;
*/
if (strncmp(cmd, "GSYS", 4) == 0) {
return get_sysinfo();
}
/*
* GMON:1,n; n=1 First time
* 100:7,pid,tty,user,program,city,isdoing,starttime;
* 100:0;
*/
if (strncmp(cmd, "GMON", 4) == 0) {
cnt = strtok(token, ",");
strcpy(var1, strtok(NULL, ";"));
return get_reginfo(atoi(var1));
}
/*
* GLCC:0;
* 100:1,n;
*/
if (strncmp(cmd, "GLCC", 4) == 0) {
return get_lastcallercount();
}
/*
* GDST:0;
* 100:n,data1,..,data10;
*/
if (strncmp(cmd, "GDST", 4) == 0) {
return get_diskstat();
}
/*
* GLCR:1,recno;
* 100:9,user,location,level,device,time,mins,calls,speed,actions;
* 201:1,16;
*/
if (strncmp(cmd, "GLCR", 4) == 0) {
cnt = strtok(token, ",");
strcpy(var1, strtok(NULL, ";"));
return get_lastcallerrec(atoi(var1));
}
/*
* GSYS:0;
* 100:7,calls,pots_calls,isdn_calls,network_calls,local_calls,startdate,last_caller;
* 201:1,16;
*/
if (strncmp(cmd, "GSYS", 4) == 0) {
return get_sysinfo();
}
/*
* GLCC:0;
* 100:1,n;
*/
if (strncmp(cmd, "GLCC", 4) == 0) {
return get_lastcallercount();
}
/*
* GLCR:1,recno;
* 100:9,user,location,level,device,time,mins,calls,speed,actions;
* 201:1,16;
*/
if (strncmp(cmd, "GLCR", 4) == 0) {
cnt = strtok(token, ",");
strcpy(var1, strtok(NULL, ";"));
return get_lastcallerrec(atoi(var1));
}
/*

View File

@@ -4,7 +4,7 @@
* Purpose ...............: Buffers for registration information.
*
*****************************************************************************
* Copyright (C) 1997-2001
* Copyright (C) 1997-2003
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
@@ -38,6 +38,7 @@
extern reg_info reginfo[MAXCLIENT]; /* Array with clients */
static int entrypos = 0; /* Status pointer */
static int mailers = 0; /* Registered mailers */
static int sysop_present = 0; /* Sysop present */
int ipmailers = 0; /* TCP/IP mail sessions */
@@ -48,15 +49,15 @@ int ipmailers = 0; /* TCP/IP mail sessions */
int reg_find(char *);
int reg_find(char *pids)
{
int i;
int i;
for (i = 0; i < MAXCLIENT; i++) {
if ((int)reginfo[i].pid == atoi(pids))
return i;
}
for (i = 0; i < MAXCLIENT; i++) {
if ((int)reginfo[i].pid == atoi(pids))
return i;
}
Syslog('?', "Panic, pid %s not found", pids);
return -1;
Syslog('?', "Panic, pid %s not found", pids);
return -1;
}
@@ -68,70 +69,71 @@ int reg_find(char *pids)
int reg_newcon(char *data)
{
char *cnt, *pid, *tty, *uid, *prg, *city;
int retval;
char *cnt, *pid, *tty, *uid, *prg, *city;
int retval;
cnt = strtok(data, ",");
pid = strtok(NULL, ",");
tty = strtok(NULL, ",");
uid = strtok(NULL, ",");
prg = strtok(NULL, ",");
city = strtok(NULL, ";");
cnt = strtok(data, ",");
pid = strtok(NULL, ",");
tty = strtok(NULL, ",");
uid = strtok(NULL, ",");
prg = strtok(NULL, ",");
city = strtok(NULL, ";");
/*
* Abort if no empty record is found
*/
if ((retval = reg_find((char *)"0")) == -1) {
Syslog('?', "Maximum clients (%d) reached", MAXCLIENT);
return -1;
}
/*
* Abort if no empty record is found
*/
if ((retval = reg_find((char *)"0")) == -1) {
Syslog('?', "Maximum clients (%d) reached", MAXCLIENT);
return -1;
}
memset((char *)&reginfo[retval], 0, sizeof(reg_info));
reginfo[retval].pid = atoi(pid);
strncpy((char *)&reginfo[retval].tty, tty, 6);
strncpy((char *)&reginfo[retval].uname, uid, 35);
strncpy((char *)&reginfo[retval].prg, prg, 14);
strncpy((char *)&reginfo[retval].city, city, 35);
strcpy((char *)&reginfo[retval].doing, "-");
reginfo[retval].started = time(NULL);
reginfo[retval].lastcon = time(NULL);
reginfo[retval].altime = 600;
memset((char *)&reginfo[retval], 0, sizeof(reg_info));
reginfo[retval].pid = atoi(pid);
strncpy((char *)&reginfo[retval].tty, tty, 6);
strncpy((char *)&reginfo[retval].uname, uid, 35);
strncpy((char *)&reginfo[retval].prg, prg, 14);
strncpy((char *)&reginfo[retval].city, city, 35);
strcpy((char *)&reginfo[retval].doing, "-");
reginfo[retval].started = time(NULL);
reginfo[retval].lastcon = time(NULL);
reginfo[retval].altime = 600;
reginfo[retval].channel = -1; /* Default chat channel */
/*
* Everyone says do not disturb, unless the flag
* is cleared by the owner of this process.
*/
reginfo[retval].silent = 1;
/*
* Everyone says do not disturb, unless the flag
* is cleared by the owner of this process.
*/
reginfo[retval].silent = 1;
stat_inc_clients();
if (strcmp(prg, (char *)"mbcico") == 0)
mailers++;
Syslog('-', "Registered client pgm \"%s\", pid %s, slot %d, mailers %d, TCP/IP %d",
stat_inc_clients();
if (strcmp(prg, (char *)"mbcico") == 0)
mailers++;
Syslog('-', "Registered client pgm \"%s\", pid %s, slot %d, mailers %d, TCP/IP %d",
prg, pid, retval, mailers, ipmailers);
return retval;
return retval;
}
int reg_closecon(char *data)
{
char *cnt, *pid;
int rec;
char *cnt, *pid;
int rec;
cnt = strtok(data, ",");
pid = strtok(NULL, ";");
if ((rec = reg_find(pid)) == -1)
return -1;
cnt = strtok(data, ",");
pid = strtok(NULL, ";");
if ((rec = reg_find(pid)) == -1)
return -1;
if (strcmp(reginfo[rec].prg, (char *)"mbcico") == 0)
mailers--;
if (reginfo[rec].istcp)
ipmailers--;
Syslog('-', "Unregistered client pgm \"%s\", pid %s, slot %d, mailers %d, TCP/IP %d",
if (strcmp(reginfo[rec].prg, (char *)"mbcico") == 0)
mailers--;
if (reginfo[rec].istcp)
ipmailers--;
Syslog('-', "Unregistered client pgm \"%s\", pid %s, slot %d, mailers %d, TCP/IP %d",
reginfo[rec].prg, pid, rec, mailers, ipmailers);
memset(&reginfo[rec], 0, sizeof(reg_info));
stat_dec_clients();
return 0;
memset(&reginfo[rec], 0, sizeof(reg_info));
stat_dec_clients();
return 0;
}
@@ -141,44 +143,47 @@ int reg_closecon(char *data)
*/
void reg_check(void)
{
int i;
time_t Now;
int i;
time_t Now;
Now = time(NULL);
for (i = 1; i < MAXCLIENT; i++) {
if (reginfo[i].pid) {
if (kill(reginfo[i].pid, 0) == -1) {
if (errno == ESRCH) {
if (strcmp(reginfo[i].prg, (char *)"mbcico") == 0)
mailers--;
if (reginfo[i].istcp)
ipmailers--;
Syslog('?', "Stale registration found for pid %d (%s), mailers now %d, TCP/IP now %d",
Now = time(NULL);
for (i = 1; i < MAXCLIENT; i++) {
if (reginfo[i].pid) {
if (kill(reginfo[i].pid, 0) == -1) {
if (errno == ESRCH) {
if (strcmp(reginfo[i].prg, (char *)"mbcico") == 0)
mailers--;
if (reginfo[i].istcp)
ipmailers--;
Syslog('?', "Stale registration found for pid %d (%s), mailers now %d, TCP/IP now %d",
reginfo[i].pid, reginfo[i].prg, mailers, ipmailers);
memset(&reginfo[i], 0, sizeof(reg_info));
stat_dec_clients();
}
} else {
/*
* Check timeout
*/
if ((Now - reginfo[i].lastcon) >= reginfo[i].altime) {
if (reginfo[i].altime < 600) {
kill(reginfo[i].pid, SIGKILL);
Syslog('+', "Send SIGKILL to pid %d", reginfo[i].pid);
} else {
kill(reginfo[i].pid, SIGTERM);
Syslog('+', "Send SIGTERM to pid %d", reginfo[i].pid);
}
/*
* 10 seconds to the next kill
*/
reginfo[i].altime = 10;
reginfo[i].lastcon = time(NULL);
}
}
// FIXME: If this was a moderators chat channel, kill the whole channel
memset(&reginfo[i], 0, sizeof(reg_info));
stat_dec_clients();
}
} else {
/*
* Check timeout
*/
if ((Now - reginfo[i].lastcon) >= reginfo[i].altime) {
if (reginfo[i].altime < 600) {
kill(reginfo[i].pid, SIGKILL);
Syslog('+', "Send SIGKILL to pid %d", reginfo[i].pid);
} else {
kill(reginfo[i].pid, SIGTERM);
Syslog('+', "Send SIGTERM to pid %d", reginfo[i].pid);
}
/*
* 10 seconds to the next kill
*/
reginfo[i].altime = 10;
reginfo[i].lastcon = time(NULL);
}
}
}
}
}
@@ -349,39 +354,56 @@ int reg_user(char *data)
/*
* Register sysop available for chat
*/
int reg_sysop(char *data)
{
char *cnt;
cnt = strtok(data, ",");
sysop_present = atoi(strtok(NULL, ";"));
Syslog('+', "Sysop present for chat: %s", sysop_present ? "True":"False");
return 0;
}
/*
* Check for personal message
*/
char *reg_ipm(char *data)
{
char *cnt, *pid;
static char buf[128];
int rec;
char *cnt, *pid;
static char buf[128];
int rec;
buf[0] = '\0';
sprintf(buf, "100:0;");
cnt = strtok(data, ",");
pid = strtok(NULL, ";");
if ((rec = reg_find(pid)) == -1)
return buf;
reginfo[rec].lastcon = time(NULL);
if (!reginfo[rec].ismsg)
return buf;
buf[0] = '\0';
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
reginfo[rec].ptr_out = 0;
if (reginfo[rec].ptr_out == reginfo[rec].ptr_in)
reginfo[rec].ismsg = FALSE;
Syslog('+', "reg_ipm: in=%d out=%d ismsg=%d", reginfo[rec].ptr_in, reginfo[rec].ptr_out, reginfo[rec].ismsg);
buf[0] = '\0';
sprintf(buf, "100:0;");
cnt = strtok(data, ",");
pid = strtok(NULL, ";");
if ((rec = reg_find(pid)) == -1)
return buf;
reginfo[rec].lastcon = time(NULL);
if (!reginfo[rec].ismsg || (reginfo[rec].channel != -1))
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]);
if (reginfo[rec].ptr_out < RB)
reginfo[rec].ptr_out++;
else
reginfo[rec].ptr_out = 0;
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);
return buf;
}
@@ -391,51 +413,77 @@ char *reg_ipm(char *data)
*/
int reg_spm(char *data)
{
char *cnt, *from, *too, *txt;
int i;
char *cnt, *from, *too, *txt;
int ch, i;
cnt = strtok(data, ",");
from = strtok(NULL, ",");
too = strtok(NULL, ",");
txt = strtok(NULL, ";");
cnt = strtok(data, ",");
ch = atoi(strtok(NULL, ","));
from = strtok(NULL, ",");
too = strtok(NULL, ",");
txt = strtok(NULL, "\0");
txt[strlen(txt)-1] = '\0';
for (i = 1; i < MAXCLIENT; i++) {
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)) {
return 2;
}
Syslog('-', "SIPM:%s,%d,%s,%s,%s;", cnt, ch, 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) && ((ch == -1) || (ch == 0)) && (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)) {
return 2;
}
/*
* If user has the "do not distrurb" flag set.
*/
if (reginfo[i].silent) {
return 1;
}
/*
* If user has the "do not distrurb" flag set, but the sysop ignore's this.
*/
if (reginfo[i].silent && (ch == -1)) {
return 1;
}
/*
* If all is well, insert the new message.
*/
strncpy((char *)&reginfo[i].fname[reginfo[i].ptr_in], from, 35);
strncpy((char *)&reginfo[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;
Syslog('+', "reg_spm: in=%d out=%d ismsg=%d", reginfo[i].ptr_in, reginfo[i].ptr_out, reginfo[i].ismsg);
return 0;
}
/*
* If all is well, insert the new message.
*/
strncpy((char *)&reginfo[i].fname[reginfo[i].ptr_in], from, 35);
strncpy((char *)&reginfo[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;
Syslog('+', "reg_spm: in=%d out=%d ismsg=%d", reginfo[i].ptr_in, reginfo[i].ptr_out, reginfo[i].ismsg);
return 0;
}
/*
* User not found
* Chat messages, they are send to each user that is chatting in the right channel.
*/
return 3;
if (reginfo[i].pid && reginfo[i].chatting && reginfo[i].channel == 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 *)&reginfo[i].fname[reginfo[i].ptr_in], from, 35);
strncpy((char *)&reginfo[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;
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);
}
}
}
if ((ch == -1) || (ch == 0))
return 3; // Error
return 0; // Ok
}

View File

@@ -26,16 +26,21 @@ typedef struct _reg_info {
unsigned chatting : 1; /* User is chatting */
unsigned ismsg : 1; /* Message waiting */
unsigned istcp : 1; /* Is a TCP/IP session */
unsigned paging : 1; /* Is paging sysop */
unsigned haspaged : 1; /* Has paged sysop */
unsigned moderator : 1; /* Is channel moderator */
int channel; /* Chat channel */
int ptr_in; /* Input buffer pointer */
int ptr_out; /* Output buffer ptr */
char fname[RB][36]; /* Message from user */
char msg[RB][81]; /* The message itself */
char reason[81]; /* Chat reason */
char chname[21]; /* Short channel name */
char chsubj[61]; /* Channel subject */
} reg_info;
void reg_init(void);
int reg_newcon(char *);
int reg_closecon(char *);
void reg_check(void);
@@ -50,6 +55,7 @@ char *reg_ipm(char *);
int reg_spm(char *);
char *reg_fre(void);
char *get_reginfo(int);
int reg_sysop(char *);
#endif

View File

@@ -159,7 +159,7 @@ void Syslog(int grade, const char *format, ...)
*/
int ulog(char *fn, char *grade, char *prname, char *prpid, char *format)
{
int oldmask;
int i, oldmask;
FILE *log;
oldmask = umask(066);
@@ -172,10 +172,17 @@ int ulog(char *fn, char *grade, char *prname, char *prpid, char *format)
}
fprintf(log, "%s %s %s[%s] ", grade, date(), prname, prpid);
fwrite(format, strlen(format), 1, log);
fprintf(log, "\n");
for (i = 0; i < strlen(format); i++) {
if (iscntrl(format[i])) {
fputc('^', log);
fputc(format[i] + 64, log);
} else {
fputc(format[i], log);
}
}
fputc('\n', log);
fflush(log);
if (fclose(log) != 0) {
oserr = errno;
Syslog('!', "$Cannot close user logfile %s", fn);