Made sysop/user chat working

This commit is contained in:
Michiel Broek
2003-04-02 21:36:47 +00:00
parent 126b07cf84
commit de14e49f5c
12 changed files with 329 additions and 139 deletions

View File

@@ -90,6 +90,7 @@ void fill_portlist(pp_list **fdp, pp_list *new)
strncpy(tmp->tty, new->tty, 6);
tmp->mflags = new->mflags;
tmp->dflags = new->dflags;
tmp->locktime = 0;
if (*fdp == NULL) {
*fdp = tmp;

View File

@@ -53,6 +53,7 @@ typedef struct _ch_user_rec {
int pointer; /* Message pointer */
unsigned chatting : 1; /* Is chatting in a channel */
unsigned chanop : 1; /* Is a chanop */
unsigned sysop : 1; /* User is sysop in channel #sysop */
} _chat_users;
@@ -118,16 +119,30 @@ void chat_msg(int, char *, char *);
void chat_dump(void)
{
int i;
int i, first;
first = TRUE;
for (i = 0; i < MAXCLIENT; i++)
if (chat_users[i].pid)
Syslog('u', "%5d %-36s %2d %s", chat_users[i].pid, chat_users[i].name, chat_users[i].channel,
chat_users[i].chatting?"True":"False");
if (chat_users[i].pid) {
if (first) {
Syslog('u', " pid username ch chats sysop");
Syslog('u', "----- ------------------------------------ -- ----- -----");
first = FALSE;
}
Syslog('u', "%5d %-36s %2d %s %s", chat_users[i].pid, chat_users[i].name, chat_users[i].channel,
chat_users[i].chatting?"True ":"False", chat_users[i].sysop?"True ":"False");
}
first = TRUE;
for (i = 0; i < MAXCHANNELS; i++)
if (chat_channels[i].owner)
if (chat_channels[i].owner) {
if (first) {
Syslog('c', "channel name owner cnt activ");
Syslog('c', "-------------------- ----- --- -----");
first = FALSE;
}
Syslog('c', "%-20s %5d %3d %s", chat_channels[i].name, chat_channels[i].owner, chat_channels[i].users,
chat_channels[i].active?"True":"False");
}
}
@@ -329,11 +344,16 @@ char *chat_connect(char *data)
{
char *pid, *usr;
static char buf[200];
int i, j, count = 0;
int i, j, count = 0, sys = FALSE;
Syslog('-', "CCON:%s", data);
memset(&buf, 0, sizeof(buf));
if (IsSema((char *)"upsalarm")) {
sprintf(buf, "100:1,Power failure, running on UPS;");
return buf;
}
/*
* Search free userslot
*/
@@ -342,16 +362,18 @@ char *chat_connect(char *data)
/*
* Oke, found
*/
pid = strtok(data, ","); /* Should be 2 */
pid = strtok(NULL, ","); /* The pid */
usr = strtok(NULL, ";"); /* Username */
pid = strtok(data, ","); /* Should be 3 */
pid = strtok(NULL, ","); /* The pid */
usr = strtok(NULL, ","); /* Username */
sys = atoi(strtok(NULL, ";")); /* Sysop flag */
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;
chat_users[i].sysop = sys;
Syslog('-', "Connected user %s (%s) with chatserver, slot %d", usr, pid, i);
Syslog('-', "Connected user %s (%s) with chatserver, slot %d, sysop %s", usr, pid, i, sys ? "True":"False");
/*
* Now put welcome message into the ringbuffer and report success.
@@ -411,6 +433,11 @@ char *chat_put(char *data)
Syslog('-', "CPUT:%s", data);
memset(&buf, 0, sizeof(buf));
if (IsSema((char *)"upsalarm")) {
sprintf(buf, "100:2,1,Power alarm, running on UPS;");
return buf;
}
pid = strtok(data, ",");
pid = strtok(NULL, ",");
msg = strtok(NULL, "\0");
@@ -421,7 +448,7 @@ char *chat_put(char *data)
/*
* We are connected and known, first send the input back to ourself.
*/
system_msg(chat_users[i].pid, msg);
// system_msg(chat_users[i].pid, msg);
if (msg[0] == '/') {
/*
@@ -435,13 +462,9 @@ char *chat_put(char *data)
(strncasecmp(msg, "/quit", 5) == 0) ||
(strncasecmp(msg, "/bye", 4) == 0)) {
part(chat_users[i].pid, (char *)"Quitting");
/*
* Just send messages, the client should later do a
* real disconnect.
*/
sprintf(buf, "Goodbye");
system_msg(chat_users[i].pid, buf);
goto ack;
goto hangup;
}
if (strncasecmp(msg, "/join", 5) == 0) {
cmd = strtok(msg, " \0");
@@ -492,12 +515,16 @@ char *chat_put(char *data)
}
}
Syslog('-', "Pid %s was not connected to chatserver");
sprintf(buf, "100:1,ERROR - Not connected to server;");
sprintf(buf, "100:2,1,ERROR - Not connected to server;");
return buf;
ack:
sprintf(buf, "100:0;");
return buf;
hangup:
sprintf(buf, "100:2,1,Disconnecting;");
return buf;
}
@@ -509,6 +536,12 @@ char *chat_get(char *data)
int i;
// Syslog('-', "CGET:%s", data);
if (IsSema((char *)"upsalarm")) {
sprintf(buf, "100:2,1,Power failure, running on UPS;");
return buf;
}
memset(&buf, 0, sizeof(buf));
pid = strtok(data, ",");
pid = strtok(NULL, ";");
@@ -524,7 +557,7 @@ char *chat_get(char *data)
/*
* Message is for us.
*/
sprintf(buf, "100:1,%s;", chat_messages[chat_users[i].pointer].message);
sprintf(buf, "100:2,0,%s;", chat_messages[chat_users[i].pointer].message);
Syslog('-', "%s", buf);
return buf;
}
@@ -533,7 +566,44 @@ char *chat_get(char *data)
return buf;
}
}
sprintf(buf, "100:1,ERROR - Not connected to server;");
sprintf(buf, "100:2,1,ERROR - Not connected to server;");
return buf;
}
/*
* Check for sysop present for forced chat
*/
char *chat_checksysop(char *data)
{
static char buf[20];
char *pid;
int i;
memset(&buf, 0, sizeof(buf));
pid = strtok(data, ",");
pid = strtok(NULL, ";");
if (reg_ispaging(pid)) {
Syslog('-', "Check sysopchat for pid %s, user has paged", pid);
/*
* Now check if sysop is present in the sysop channel
*/
for (i = 0; i < MAXCLIENT; i++) {
if (atoi(pid) != chat_users[i].pid) {
if (chat_users[i].chatting && chat_users[i].sysop) {
Syslog('-', "Sending ACK on check");
sprintf(buf, "100:1,1;");
reg_sysoptalk(pid);
return buf;
}
}
}
}
sprintf(buf, "100:1,0;");
return buf;
}

View File

@@ -9,5 +9,6 @@ char *chat_connect(char *);
char *chat_close(char *);
char *chat_put(char *);
char *chat_get(char *);
char *chat_checksysop(char *);
#endif

View File

@@ -262,9 +262,9 @@ char *exe_cmd(char *in)
}
/*
* CSYS:1,1; Sysop available for chat (from mbmon)
* CSYS:1,0; Sysop goes away (from mbmon)
* 100:0; Allways Ok.
* CSYS:2,pid,1; Sysop available for chat (from mbmon)
* CSYS:2,pid,0; Sysop goes away (from mbmon)
* 100:0; Allways Ok.
*/
if (strncmp(cmd, "CSYS", 4) == 0) {
reg_sysop(token);
@@ -305,12 +305,23 @@ char *exe_cmd(char *in)
return reg_checkpage(token);
}
/*
* Check for sysop in chatmode for forced sysop chat
*
* CISC:1,pid;
* 100:1,1; Yes (and drop into chatmode)
* 100:1,0; No
*/
if (strncmp(cmd, "CISC", 4) == 0) {
return chat_checksysop(token);
}
/*
* Connect to chatserver
*
* CCON:2,pid,username; Connect to chatserver with username
* 100:1,error; If error
* 100:0; Ok
* CCON:3,pid,username,n; Connect to chatserver with username, n=1 user is the sysop
* 100:1,error; If error
* 100:0; Ok
*/
if (strncmp(cmd, "CCON", 4) == 0) {
return chat_connect(token);
@@ -331,7 +342,8 @@ char *exe_cmd(char *in)
* Put message on server
*
* CPUT:2,pid,message; Put message on server
* 100:1,error; Error
* 100:2,0,error; Error, not fatal and continue chat
* 100:2,1,error; Error, fatal and disconnect
* 100:0; Ok
*/
if (strncmp(cmd, "CPUT", 4) == 0) {
@@ -342,7 +354,8 @@ char *exe_cmd(char *in)
* Get message from server
*
* CGET:1,pid; Get message from server
* 100:1,message; If message present
* 100:2,0,message; If message present
* 100:2,1,error; Error and disconnect
* 100:0; No message
*/
if (strncmp(cmd, "CGET", 4) == 0) {
@@ -524,6 +537,7 @@ char *exe_cmd(char *in)
* If we got this far, there must be an error.
*/
stat_inc_serr();
Syslog('!', "Comm systax error: \"%s:%s\"", cmd, printable(token, 0));
return ebuf;
}

View File

@@ -99,7 +99,6 @@ int reg_newcon(char *data)
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
@@ -372,17 +371,6 @@ int reg_sysop(char *data)
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);
}
@@ -587,13 +575,11 @@ int reg_page(char *data)
return 2;
/*
* Check if another user is pagin the sysop or is already
* chatting with the sysop, if so, mark sysop busy.
* Check if another user is paging the sysop or has paged the sysop.
* If so, mark sysop busy.
*/
for (i = 1; i < MAXCLIENT; i++) {
if (reginfo[i].pid && (reginfo[i].pid != atoi(pid)) && (reginfo[i].channel == 0) && (reginfo[i].chatting))
return 1;
if (reginfo[i].pid && (reginfo[i].pid != atoi(pid)) && (reginfo[i].paging))
if (reginfo[i].pid && (reginfo[i].pid != atoi(pid)) && (reginfo[i].paging || reginfo[i].haspaged))
return 1;
}
@@ -604,7 +590,6 @@ int reg_page(char *data)
* All seems well, accept the page
*/
reginfo[rec].paging = TRUE;
reginfo[rec].channel = 0;
strncpy(reginfo[rec].reason, reason, 80);
reginfo[rec].lastcon = time(NULL);
return 0;
@@ -623,7 +608,7 @@ int reg_cancel(char *data)
cnt = strtok(data, ",");
pid = strtok(NULL, ";");
Syslog('+', "reg_cancel: pid=%d", pid);
Syslog('+', "reg_cancel: pid=%s", pid);
if ((rec = reg_find(pid)) == -1)
return -1;
@@ -631,7 +616,6 @@ int reg_cancel(char *data)
if (reginfo[rec].paging) {
reginfo[rec].paging = FALSE;
reginfo[rec].haspaged = TRUE;
reginfo[rec].channel = -1;
}
reginfo[rec].lastcon = time(NULL);
return 0;
@@ -663,3 +647,34 @@ char *reg_checkpage(char *data)
}
/*
* Check if this user has paged or is paging
*/
int reg_ispaging(char *pid)
{
int rec;
if ((rec = reg_find(pid)) == -1)
return FALSE;
return (reginfo[rec].paging || reginfo[rec].haspaged);
}
/*
* Mark that this user is now talking to the sysop
*/
void reg_sysoptalk(char *pid)
{
int rec;
if ((rec = reg_find(pid)) == -1)
return;
reginfo[rec].paging = FALSE;
reginfo[rec].haspaged = FALSE;
}

View File

@@ -23,20 +23,15 @@ typedef struct _reg_info {
time_t lastcon; /* Last connection */
int altime; /* Alarm time */
unsigned silent : 1; /* Do not disturb */
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;
@@ -59,6 +54,8 @@ int reg_sysop(char *); /* Registrate sysop presence */
int reg_page(char *); /* Page sysop for chat */
int reg_cancel(char *); /* Cancel sysop page */
char *reg_checkpage(char *); /* Check paging status */
int reg_ispaging(char *); /* Check if user with pid paged */
void reg_sysoptalk(char *); /* Is now talking to the sysop */
#endif