Static arrays for chat

This commit is contained in:
Michiel Broek 2006-05-25 16:37:52 +00:00
parent df1096d6a4
commit c6b81401db
5 changed files with 809 additions and 902 deletions

View File

@ -1645,6 +1645,7 @@ int main(int argc, char **argv)
load_ports(); load_ports();
check_ports(); check_ports();
chat_init(); chat_init();
ibc_init();
/* /*
* Now that init is complete and this program is locked, it is * Now that init is complete and this program is locked, it is

View File

@ -65,9 +65,6 @@ _chat_messages chat_messages[MAXMESSAGES];
int buffer_head = 0; /* Messages buffer head */ int buffer_head = 0; /* Messages buffer head */
extern struct sysconfig CFG; /* System configuration */ extern struct sysconfig CFG; /* System configuration */
extern int s_bbsopen; /* The BBS open status */ extern int s_bbsopen; /* The BBS open status */
extern srv_list *servers; /* Connected servers */
extern usr_list *users; /* Connected users */
extern chn_list *channels; /* Connected channels */
extern int usrchg; extern int usrchg;
extern int chnchg; extern int chnchg;
extern int srvchg; extern int srvchg;
@ -103,19 +100,18 @@ void Chatlog(char *level, char *channel, char *msg)
void chat_dump(void) void chat_dump(void)
{ {
int first; int i, first;
usr_list *tmpu;
first = TRUE; first = TRUE;
for (tmpu = users; tmpu; tmpu = tmpu->next) { for (i = 0; i < MAXIBC_USR; i++) {
if (tmpu->pid) { if (usr_list[i].pid) {
if (first) { if (first) {
Syslog('c', " pid username nick channel sysop"); Syslog('c', " pid username nick channel sysop");
Syslog('c', "----- ------------------------------------ --------- -------------------- -----"); Syslog('c', "----- ------------------------------------ --------- -------------------- -----");
first = FALSE; first = FALSE;
} }
Syslog('c', "%5d %-36s %-9s %-20s %s", tmpu->pid, tmpu->realname, tmpu->nick, Syslog('c', "%5d %-36s %-9s %-20s %s", usr_list[i].pid, usr_list[i].realname, usr_list[i].nick,
tmpu->channel, tmpu->sysop?"True ":"False"); usr_list[i].channel, usr_list[i].sysop?"True ":"False");
} }
} }
} }
@ -148,17 +144,18 @@ void system_shout(const char *format, ...)
{ {
char *buf; char *buf;
va_list va_ptr; va_list va_ptr;
usr_list *tmpu; int i;
buf = calloc(512, sizeof(char)); buf = calloc(512, sizeof(char));
va_start(va_ptr, format); va_start(va_ptr, format);
vsnprintf(buf, 512, format, va_ptr); vsnprintf(buf, 512, format, va_ptr);
va_end(va_ptr); va_end(va_ptr);
for (tmpu = users; tmpu; tmpu = tmpu->next) for (i = 0; i < MAXIBC_USR; i++) {
if (tmpu->pid) { if (usr_list[i].pid) {
system_msg(tmpu->pid, buf); system_msg(usr_list[i].pid, buf);
} }
}
Chatlog((char *)"-", (char *)" ", buf); Chatlog((char *)"-", (char *)" ", buf);
free(buf); free(buf);
@ -198,35 +195,32 @@ void chat_help(pid_t pid, int owner)
int join(pid_t pid, char *channel, int sysop) int join(pid_t pid, char *channel, int sysop)
{ {
char buf[81]; char buf[81];
chn_list *tmp; int i, j;
usr_list *tmpu;
Syslog('c', "Join pid %d to channel %s", pid, channel); Syslog('c', "Join pid %d to channel %s", pid, channel);
if (channels) { for (i = 0; i < MAXIBC_CHN; i++) {
for (tmp = channels; tmp; tmp = tmp->next) { if (strcmp(chn_list[i].name, channel) == 0) {
if (strcmp(tmp->name, channel) == 0) { for (j = 0; j < MAXIBC_USR; j++) {
for (tmpu = users; tmpu; tmpu = tmpu->next) { if (usr_list[j].pid == pid) {
if (tmpu->pid == pid) {
strncpy(tmpu->channel, channel, 20); strncpy(usr_list[j].channel, channel, 20);
tmp->users++; chn_list[i].users++;
Syslog('+', "IBC: user %s has joined channel %s", tmpu->nick, channel); Syslog('+', "IBC: user %s has joined channel %s", usr_list[j].nick, channel);
usrchg = TRUE; usrchg = TRUE;
srvchg = TRUE; srvchg = TRUE;
chnchg = TRUE; chnchg = TRUE;
chat_dump(); chat_dump();
snprintf(buf, 81, "%s has joined channel %s, now %d users", tmpu->nick, channel, tmp->users); snprintf(buf, 81, "%s has joined channel %s, now %d users", usr_list[j].nick, channel, chn_list[i].users);
chat_msg(channel, NULL, buf); chat_msg(channel, NULL, buf);
/* /*
* The sysop channel is private to the system, no broadcast * The sysop channel is private to the system, no broadcast
*/ */
if (strcasecmp(channel, "#sysop")) if (strcasecmp(channel, "#sysop"))
send_at((char *)"JOIN", tmpu->nick, channel); send_at((char *)"JOIN", usr_list[j].nick, channel);
return TRUE; return TRUE;
}
} }
} }
} }
@ -244,12 +238,12 @@ int join(pid_t pid, char *channel, int sysop)
/* /*
* No matching channel found, add a new channel. * No matching channel found, add a new channel.
*/ */
for (tmpu = users; tmpu; tmpu = tmpu->next) { for (j = 0; j < MAXIBC_USR; j++) {
if (tmpu->pid == pid) { if (usr_list[j].pid == pid) {
if (add_channel(&channels, channel, tmpu->nick, CFG.myfqdn) == 0) { if (add_channel(channel, usr_list[j].nick, CFG.myfqdn) == 0) {
strncpy(tmpu->channel, channel, 20); strncpy(usr_list[j].channel, channel, 20);
Syslog('+', "IBC: user %s created and joined channel %s", tmpu->nick, channel); Syslog('+', "IBC: user %s created and joined channel %s", usr_list[j].nick, channel);
usrchg = TRUE; usrchg = TRUE;
chnchg = TRUE; chnchg = TRUE;
srvchg = TRUE; srvchg = TRUE;
@ -258,7 +252,7 @@ int join(pid_t pid, char *channel, int sysop)
chat_msg(channel, NULL, buf); chat_msg(channel, NULL, buf);
chat_dump(); chat_dump();
if (strcasecmp(channel, "#sysop")) if (strcasecmp(channel, "#sysop"))
send_at((char *)"JOIN", tmpu->nick, channel); send_at((char *)"JOIN", usr_list[j].nick, channel);
return TRUE; return TRUE;
} }
@ -280,57 +274,58 @@ int join(pid_t pid, char *channel, int sysop)
*/ */
int part(pid_t pid, char *reason) int part(pid_t pid, char *reason)
{ {
char buf[81], *p; char buf[81], *p;
chn_list *tmp; int i, j;
usr_list *tmpu;
if (strlen(reason) > 54) if (strlen(reason) > 54)
reason[54] = '\0'; reason[54] = '\0';
Syslog('c', "Part pid %d from channel, reason %s", pid, reason); Syslog('c', "Part pid %d from channel, reason %s", pid, reason);
for (tmpu = users; tmpu; tmpu = tmpu->next) { for (i = 0; i < MAXIBC_USR; i++) {
if ((tmpu->pid == pid) && strlen(tmpu->channel)) { if ((usr_list[i].pid == pid) && strlen(usr_list[i].channel)) {
for (tmp = channels; tmp; tmp = tmp->next) { for (j = 0; j < MAXIBC_CHN; j++) {
if (strcmp(tmp->name, tmpu->channel) == 0) { if (strcmp(chn_list[j].name, usr_list[i].channel) == 0) {
/* /*
* Inform other users * Inform other users
*/ */
if (reason != NULL) { if (reason != NULL) {
chat_msg(tmpu->channel, tmpu->nick, reason); chat_msg(usr_list[i].channel, usr_list[i].nick, reason);
} }
snprintf(buf, 81, "%s has left channel %s, %d users left", tmpu->nick, tmp->name, tmp->users -1); snprintf(buf, 81, "%s has left channel %s, %d users left",
chat_msg(tmpu->channel, NULL, buf); usr_list[i].nick, chn_list[j].name, chn_list[j].users -1);
if (strcasecmp(tmp->name, (char *)"#sysop")) { chat_msg(usr_list[i].channel, NULL, buf);
p = xstrcpy(tmp->name); if (strcasecmp(chn_list[j].name, (char *)"#sysop")) {
p = xstrcpy(chn_list[j].name);
if (reason && strlen(reason)) { if (reason && strlen(reason)) {
p = xstrcat(p, (char *)" "); p = xstrcat(p, (char *)" ");
p = xstrcat(p, reason); p = xstrcat(p, reason);
} }
send_at((char *)"PART", tmpu->nick, p); send_at((char *)"PART", usr_list[i].nick, p);
free(p); free(p);
} }
/* /*
* Clean channel * Clean channel
*/ */
if (tmp->users > 0) if (chn_list[j].users > 0)
tmp->users--; chn_list[j].users--;
Syslog('+', "IBC: nick %s leaves channel %s, %d user left", tmpu->nick, tmp->name, tmp->users); Syslog('+', "IBC: nick %s leaves channel %s, %d user left",
if (tmp->users == 0) { usr_list[i].nick, chn_list[j].name, chn_list[j].users);
if (chn_list[j].users == 0) {
/* /*
* Last user in channel, remove channel * Last user in channel, remove channel
*/ */
snprintf(buf, 81, "* Removed channel %s", tmp->name); snprintf(buf, 81, "* Removed channel %s", chn_list[j].name);
system_msg(pid, buf); system_msg(pid, buf);
Syslog('+', "IBC: removed channel %s, no more users left", tmp->name); Syslog('+', "IBC: removed channel %s, no more users left", chn_list[j].name);
del_channel(&channels, tmp->name); del_channel(chn_list[j].name);
} }
/* /*
* Update user data * Update user data
*/ */
tmpu->channel[0] = '\0'; usr_list[i].channel[0] = '\0';
usrchg = TRUE; usrchg = TRUE;
chnchg = TRUE; chnchg = TRUE;
srvchg = TRUE; srvchg = TRUE;
@ -366,9 +361,9 @@ void chat_cleanuser(pid_t pid)
*/ */
void chat_msg(char *channel, char *nick, char *msg) void chat_msg(char *channel, char *nick, char *msg)
{ {
char *p; char *p;
usr_list *tmpu; int i;
if (nick == NULL) if (nick == NULL)
p = xstrcpy(msg); p = xstrcpy(msg);
else { else {
@ -379,9 +374,9 @@ void chat_msg(char *channel, char *nick, char *msg)
} }
Chatlog((char *)"+", channel, p); Chatlog((char *)"+", channel, p);
for (tmpu = users; tmpu; tmpu = tmpu->next) { for (i = 0; i < MAXIBC_USR; i++) {
if (strlen(tmpu->channel) && (strcmp(tmpu->channel, channel) == 0)) { if (strlen(usr_list[i].channel) && (strcmp(usr_list[i].channel, channel) == 0)) {
system_msg(tmpu->pid, p); system_msg(usr_list[i].pid, p);
} }
} }
@ -396,9 +391,7 @@ void chat_msg(char *channel, char *nick, char *msg)
void chat_connect_r(char *data, char *buf) void chat_connect_r(char *data, char *buf)
{ {
char *realname, *nick, *temp; char *realname, *nick, *temp;
int count = 0, sys = FALSE; int i, j, rc, count = 0, sys = FALSE;
srv_list *sl;
usr_list *tmpu;
pid_t pid; pid_t pid;
Syslog('c', "CCON:%s", data); Syslog('c', "CCON:%s", data);
@ -427,41 +420,57 @@ void chat_connect_r(char *data, char *buf)
nick = xstrcpy(cldecode(strtok(NULL, ","))); /* Nickname */ nick = xstrcpy(cldecode(strtok(NULL, ","))); /* Nickname */
sys = atoi(strtok(NULL, ";")); /* Sysop flag */ sys = atoi(strtok(NULL, ";")); /* Sysop flag */
add_user(&users, CFG.myfqdn, nick, realname); rc = add_user(CFG.myfqdn, nick, realname);
send_at((char *)"USER", nick, realname); if (rc == 1) {
free(realname);
free(nick);
snprintf(buf, 200, "100:1,Already registered;");
return;
} else if (rc == 2) {
free(realname);
free(nick);
snprintf(buf, 200, "100:1,Too many users connected;");
return;
}
send_at((char *)"USER", nick, realname);
/* /*
* Now search the added entry to update the data * Now search the added entry to update the data
*/ */
for (tmpu = users; tmpu; tmpu = tmpu->next) { for (i = 0; i < MAXIBC_USR; i++) {
if ((strcmp(tmpu->server, CFG.myfqdn) == 0) && (strcmp(tmpu->name, nick) == 0) && (strcmp(tmpu->realname, realname) == 0)) { if ((strcmp(usr_list[i].server, CFG.myfqdn) == 0) &&
(strcmp(usr_list[i].name, nick) == 0) && (strcmp(usr_list[i].realname, realname) == 0)) {
/* /*
* Oke, found * Oke, found
*/ */
tmpu->pid = pid; usr_list[i].pid = pid;
tmpu->pointer = buffer_head; usr_list[i].pointer = buffer_head;
tmpu->sysop = sys; usr_list[i].sysop = sys;
usrchg = TRUE; usrchg = TRUE;
srvchg = TRUE; srvchg = TRUE;
Syslog('c', "Connected user %s (%s) with chatserver, sysop %s", realname, pid, sys ? "True":"False"); Syslog('c', "Connected user %s (%d) with chatserver, sysop %s", realname, (int)pid, sys ? "True":"False");
/* /*
* Now put welcome message into the ringbuffer and report success. * Now put welcome message into the ringbuffer and report success.
*/ */
temp = calloc(81, sizeof(char)); temp = calloc(81, sizeof(char));
snprintf(temp, 200, "MBSE BBS v%s chat server; type /help for help", VERSION); snprintf(temp, 200, "MBSE BBS v%s chat server; type /help for help", VERSION);
system_msg(tmpu->pid, temp); system_msg(usr_list[i].pid, temp);
snprintf(temp, 200, "Welcome to the Internet BBS Chat Network"); snprintf(temp, 200, "Welcome to the Internet BBS Chat Network");
system_msg(tmpu->pid, temp); system_msg(usr_list[i].pid, temp);
snprintf(temp, 200, "Current connected servers:"); snprintf(temp, 200, "Current connected servers:");
system_msg(tmpu->pid, temp); system_msg(usr_list[i].pid, temp);
for (sl = servers; sl; sl = sl->next) { for (j = 0; j < MAXIBC_SRV; j++) {
snprintf(temp, 200, " %s (%d user%s)", sl->fullname, sl->users, (sl->users == 1) ? "":"s"); if (strlen(srv_list[j].server)) {
system_msg(tmpu->pid, temp); snprintf(temp, 200, " %s (%d user%s)", srv_list[j].fullname,
count += sl->users; srv_list[j].users, (srv_list[j].users == 1) ? "":"s");
system_msg(usr_list[i].pid, temp);
count += srv_list[j].users;
}
} }
snprintf(temp, 200, "There %s %d user%s connected", (count != 1)?"are":"is", count, (count != 1)?"s":""); snprintf(temp, 200, "There %s %d user%s connected", (count != 1)?"are":"is", count, (count != 1)?"s":"");
system_msg(tmpu->pid, temp); system_msg(usr_list[i].pid, temp);
snprintf(buf, 200, "100:0;"); snprintf(buf, 200, "100:0;");
free(realname); free(realname);
free(nick); free(nick);
@ -470,9 +479,6 @@ void chat_connect_r(char *data, char *buf)
} }
} }
free(realname);
free(nick);
snprintf(buf, 200, "100:1,Too many users connected;");
return; return;
} }
@ -480,20 +486,20 @@ void chat_connect_r(char *data, char *buf)
void chat_close_r(char *data, char *buf) void chat_close_r(char *data, char *buf)
{ {
pid_t pid; pid_t pid;
usr_list *tmpu; int i;
Syslog('c', "CCLO:%s", data); Syslog('c', "CCLO:%s", data);
strtok(data, ","); strtok(data, ",");
pid = (pid_t)atoi(strtok(NULL, ";")); pid = (pid_t)atoi(strtok(NULL, ";"));
for (tmpu = users; tmpu; tmpu = tmpu->next) { for (i = 0; i < MAXIBC_USR; i++) {
if (tmpu->pid == pid) { if (usr_list[i].pid == pid) {
/* /*
* Remove from IBC network * Remove from IBC network
*/ */
send_at((char *)"QUIT", tmpu->name, (char *)"Leaving chat"); send_at((char *)"QUIT", usr_list[i].name, (char *)"Leaving chat");
del_user(&users, CFG.myfqdn, tmpu->name); del_user(CFG.myfqdn, usr_list[i].name);
Syslog('c', "Closing chat for pid %d", (int)pid); Syslog('c', "Closing chat for pid %d", (int)pid);
snprintf(buf, 81, "100:0;"); snprintf(buf, 81, "100:0;");
return; return;
@ -510,9 +516,7 @@ void chat_close_r(char *data, char *buf)
void chat_put_r(char *data, char *buf) void chat_put_r(char *data, char *buf)
{ {
char *p, *q, *msg, *cmd, *mbuf, *flags, temp[81]; char *p, *q, *msg, *cmd, *mbuf, *flags, temp[81];
int first, count, owner = FALSE, found; int i, j, k, first, count, owner = FALSE, found;
usr_list *tmpu, *tmp;
chn_list *tmpc;
pid_t pid; pid_t pid;
if (IsSema((char *)"upsalarm")) { if (IsSema((char *)"upsalarm")) {
@ -530,39 +534,41 @@ void chat_put_r(char *data, char *buf)
msg = xstrcpy(cldecode(strtok(NULL, ";"))); msg = xstrcpy(cldecode(strtok(NULL, ";")));
mbuf = calloc(200, sizeof(char)); mbuf = calloc(200, sizeof(char));
for (tmpu = users; tmpu; tmpu = tmpu->next) { for (i = 0; i < MAXIBC_USR; i++) {
if (tmpu->pid == pid) { if (usr_list[i].pid == pid) {
if (msg[0] == '/') { if (msg[0] == '/') {
/* /*
* A command, process this but first se if we are in a channel * A command, process this but first see if we are in a channel
* and own the channel. This gives us more power. * and own the channel. This gives us more power.
*/ */
if (strlen(tmpu->channel)) { if (strlen(usr_list[i].channel)) {
for (tmpc = channels; tmpc; tmpc = tmpc->next) { for (j = 0; j < MAXIBC_CHN; j++) {
if (((strcmp(tmpu->nick, tmpc->owner) == 0) || (strcmp(tmpu->name, tmpc->owner) == 0)) && if (((strcmp(usr_list[i].nick, chn_list[j].owner) == 0) ||
(strcmp(tmpu->server, tmpc->server) == 0)) { (strcmp(usr_list[i].name, chn_list[j].owner) == 0)) &&
(strcmp(usr_list[i].server, chn_list[j].server) == 0)) {
owner = TRUE; owner = TRUE;
} }
} }
Syslog('c', "IBC: process command, in channel %s and we are %sthe owner", tmpu->channel, owner ? "":"not "); Syslog('c', "IBC: process command, in channel %s and we are %sthe owner",
usr_list[i].channel, owner ? "":"not ");
} }
if (strncasecmp(msg, "/help", 5) == 0) { if (strncasecmp(msg, "/help", 5) == 0) {
chat_help(pid, owner); chat_help(pid, owner);
goto ack; goto ack;
} else if (strncasecmp(msg, "/echo", 5) == 0) { } else if (strncasecmp(msg, "/echo", 5) == 0) {
snprintf(mbuf, 200, "%s", msg); snprintf(mbuf, 200, "%s", msg);
system_msg(tmpu->pid, mbuf); system_msg(usr_list[i].pid, mbuf);
goto ack; goto ack;
} else if ((strncasecmp(msg, "/exit", 5) == 0) || } else if ((strncasecmp(msg, "/exit", 5) == 0) ||
(strncasecmp(msg, "/quit", 5) == 0) || (strncasecmp(msg, "/quit", 5) == 0) ||
(strncasecmp(msg, "/bye", 4) == 0)) { (strncasecmp(msg, "/bye", 4) == 0)) {
if (strlen(tmpu->channel)) { if (strlen(usr_list[i].channel)) {
/* /*
* If in a channel, leave channel first * If in a channel, leave channel first
*/ */
part(tmpu->pid, (char *)"Quitting"); part(usr_list[i].pid, (char *)"Quitting");
snprintf(mbuf, 81, "Goodbye"); snprintf(mbuf, 81, "Goodbye");
system_msg(tmpu->pid, mbuf); system_msg(usr_list[i].pid, mbuf);
} }
goto hangup; goto hangup;
} else if ((strncasecmp(msg, "/join", 5) == 0) || } else if ((strncasecmp(msg, "/join", 5) == 0) ||
@ -571,76 +577,79 @@ void chat_put_r(char *data, char *buf)
cmd = strtok(NULL, "\0"); cmd = strtok(NULL, "\0");
if ((cmd == NULL) || (cmd[0] != '#') || (strcmp(cmd, "#") == 0)) { if ((cmd == NULL) || (cmd[0] != '#') || (strcmp(cmd, "#") == 0)) {
snprintf(mbuf, 200, "** Try /join #channel"); snprintf(mbuf, 200, "** Try /join #channel");
system_msg(tmpu->pid, mbuf); system_msg(usr_list[i].pid, mbuf);
} else if (strlen(tmpu->channel)) { } else if (strlen(usr_list[i].channel)) {
snprintf(mbuf, 200, "** Cannot join while in a channel"); snprintf(mbuf, 200, "** Cannot join while in a channel");
system_msg(tmpu->pid, mbuf); system_msg(usr_list[i].pid, mbuf);
} else { } else {
join(tmpu->pid, cmd, tmpu->sysop); join(usr_list[i].pid, cmd, usr_list[i].sysop);
} }
chat_dump(); chat_dump();
goto ack; goto ack;
} else if (strncasecmp(msg, "/list", 5) == 0) { } else if (strncasecmp(msg, "/list", 5) == 0) {
first = TRUE; first = TRUE;
for (tmpc = channels; tmpc; tmpc = tmpc->next) { for (j = 0; j < MAXIBC_CHN; j++) {
if (first) { if (strlen(chn_list[j].server)) {
snprintf(mbuf, 200, "Cnt Channel name Channel topic"); if (first) {
system_msg(tmpu->pid, mbuf); snprintf(mbuf, 200, "Cnt Channel name Channel topic");
snprintf(mbuf, 200, "--- -------------------- ------------------------------------------------------"); system_msg(usr_list[i].pid, mbuf);
system_msg(tmpu->pid, mbuf); snprintf(mbuf, 200, "--- -------------------- ------------------------------------------------------");
system_msg(usr_list[i].pid, mbuf);
}
first = FALSE;
q = calloc(81, sizeof(char));
snprintf(q, 81, "%3d %-20s ", chn_list[j].users, chn_list[j].name);
p = xstrcpy(q);
p = xstrcat(p, chn_list[j].topic);
system_msg(usr_list[i].pid, p);
free(p);
free(q);
} }
first = FALSE;
q = calloc(81, sizeof(char));
snprintf(q, 81, "%3d %-20s ", tmpc->users, tmpc->name);
p = xstrcpy(q);
p = xstrcat(p, tmpc->topic);
system_msg(tmpu->pid, p);
free(p);
free(q);
} }
if (first) { if (first) {
snprintf(mbuf, 200, "No active channels to list"); snprintf(mbuf, 200, "No active channels to list");
system_msg(tmpu->pid, mbuf); system_msg(usr_list[i].pid, mbuf);
} }
goto ack; goto ack;
} else if (strncasecmp(msg, "/names", 6) == 0) { } else if (strncasecmp(msg, "/names", 6) == 0) {
if (strlen(tmpu->channel)) { if (strlen(usr_list[i].channel)) {
snprintf(mbuf, 200, "Present in channel %s:", tmpu->channel); snprintf(mbuf, 200, "Present in channel %s:", usr_list[i].channel);
system_msg(tmpu->pid, mbuf); system_msg(usr_list[i].pid, mbuf);
snprintf(mbuf, 200, "Nick Real name Flags"); snprintf(mbuf, 200, "Nick Real name Flags");
system_msg(tmpu->pid, mbuf); system_msg(usr_list[i].pid, mbuf);
snprintf(mbuf, 200, "---------------------------------------- ------------------------------ -----"); snprintf(mbuf, 200, "---------------------------------------- ------------------------------ -----");
system_msg(tmpu->pid, mbuf); system_msg(usr_list[i].pid, mbuf);
count = 0; count = 0;
for (tmp = users; tmp; tmp = tmp->next) { for (j = 0; j < MAXIBC_USR; j++) {
if (strcmp(tmp->channel, tmpu->channel) == 0) { if (strcmp(usr_list[j].channel, usr_list[i].channel) == 0) {
/* /*
* Get channel flags * Get channel flags
*/ */
flags = xstrcpy((char *)"--"); flags = xstrcpy((char *)"--");
for (tmpc = channels; tmpc; tmpc = tmpc->next) { for (k = 0; k < MAXIBC_CHN; k++) {
if (strcmp(tmpc->name, tmpu->channel) == 0) { if (strcmp(chn_list[k].name, usr_list[i].channel) == 0) {
if (((strcmp(tmpc->owner, tmp->nick) == 0) || (strcmp(tmpc->owner, tmp->name) == 0)) && if (((strcmp(chn_list[k].owner, usr_list[j].nick) == 0) ||
(strcmp(tmpc->server, tmp->server) == 0)) { (strcmp(chn_list[k].owner, usr_list[j].name) == 0)) &&
(strcmp(chn_list[k].server, usr_list[j].server) == 0)) {
flags[0] = 'O'; flags[0] = 'O';
} }
} }
} }
if (tmp->sysop) if (usr_list[j].sysop)
flags[1] = 'S'; flags[1] = 'S';
snprintf(temp, 81, "%s@%s", tmp->nick, tmp->server); snprintf(temp, 81, "%s@%s", usr_list[j].nick, usr_list[j].server);
snprintf(mbuf, 200, "%-40s %-30s %s", temp, tmp->realname, flags); snprintf(mbuf, 200, "%-40s %-30s %s", temp, usr_list[j].realname, flags);
system_msg(tmpu->pid, mbuf); system_msg(usr_list[i].pid, mbuf);
count++; count++;
free(flags); free(flags);
} }
} }
snprintf(mbuf, 200, "%d user%s in this channel", count, (count == 1) ?"":"s"); snprintf(mbuf, 200, "%d user%s in this channel", count, (count == 1) ?"":"s");
system_msg(tmpu->pid, mbuf); system_msg(usr_list[i].pid, mbuf);
} else { } else {
snprintf(mbuf, 200, "** Not in a channel"); snprintf(mbuf, 200, "** Not in a channel");
system_msg(tmpu->pid, mbuf); system_msg(usr_list[i].pid, mbuf);
} }
goto ack; goto ack;
} else if (strncasecmp(msg, "/nick", 5) == 0) { } else if (strncasecmp(msg, "/nick", 5) == 0) {
@ -650,24 +659,24 @@ void chat_put_r(char *data, char *buf)
snprintf(mbuf, 200, "** Nickname must be between 1 and 9 characters"); snprintf(mbuf, 200, "** Nickname must be between 1 and 9 characters");
} else { } else {
found = FALSE; found = FALSE;
for (tmp = users; tmp; tmp = tmp->next) { for (j = 0; j < MAXIBC_USR; j++) {
if ((strcmp(tmp->name, cmd) == 0) || (strcmp(tmp->nick, cmd) == 0)) { if ((strcmp(usr_list[j].name, cmd) == 0) || (strcmp(usr_list[j].nick, cmd) == 0)) {
found = TRUE; found = TRUE;
} }
} }
if (!found ) { if (!found ) {
strncpy(tmpu->nick, cmd, 9); strncpy(usr_list[i].nick, cmd, 9);
snprintf(mbuf, 200, "Nick set to \"%s\"", cmd); snprintf(mbuf, 200, "Nick set to \"%s\"", cmd);
system_msg(tmpu->pid, mbuf); system_msg(usr_list[i].pid, mbuf);
send_nick(tmpu->nick, tmpu->name, tmpu->realname); send_nick(usr_list[i].nick, usr_list[i].name, usr_list[i].realname);
usrchg = TRUE; usrchg = TRUE;
chat_dump(); chat_dump();
goto ack; goto ack;
} }
snprintf(mbuf, 200, "Can't set nick"); snprintf(mbuf, 200, "Can't set nick");
} }
system_msg(tmpu->pid, mbuf); system_msg(usr_list[i].pid, mbuf);
chat_dump(); chat_dump();
goto ack; goto ack;
} else if (strncasecmp(msg, "/part", 5) == 0) { } else if (strncasecmp(msg, "/part", 5) == 0) {
@ -675,29 +684,29 @@ void chat_put_r(char *data, char *buf)
Syslog('c', "\"%s\"", cmd); Syslog('c', "\"%s\"", cmd);
cmd = strtok(NULL, "\0"); cmd = strtok(NULL, "\0");
Syslog('c', "\"%s\"", printable(cmd, 0)); Syslog('c', "\"%s\"", printable(cmd, 0));
if (part(tmpu->pid, cmd ? cmd : (char *)"Quitting") == FALSE) { if (part(usr_list[i].pid, cmd ? cmd : (char *)"Quitting") == FALSE) {
snprintf(mbuf, 200, "** Not in a channel"); snprintf(mbuf, 200, "** Not in a channel");
system_msg(tmpu->pid, mbuf); system_msg(usr_list[i].pid, mbuf);
} }
chat_dump(); chat_dump();
goto ack; goto ack;
} else if (strncasecmp(msg, "/topic", 6) == 0) { } else if (strncasecmp(msg, "/topic", 6) == 0) {
if (strlen(tmpu->channel)) { if (strlen(usr_list[i].channel)) {
snprintf(mbuf, 200, "** Internal system error"); snprintf(mbuf, 200, "** Internal system error");
for (tmpc = channels; tmpc; tmpc = tmpc->next) { for (j = 0; j < MAXIBC_CHN; j++) {
if (strcmp(tmpu->channel, tmpc->name) == 0) { if (strcmp(usr_list[i].channel, chn_list[j].name) == 0) {
if (owner) { if (owner) {
cmd = strtok(msg, " \0"); cmd = strtok(msg, " \0");
cmd = strtok(NULL, "\0"); cmd = strtok(NULL, "\0");
if ((cmd == NULL) || (strlen(cmd) == 0) || (strlen(cmd) > 54)) { if ((cmd == NULL) || (strlen(cmd) == 0) || (strlen(cmd) > 54)) {
snprintf(mbuf, 200, "** Topic must be between 1 and 54 characters"); snprintf(mbuf, 200, "** Topic must be between 1 and 54 characters");
} else { } else {
strncpy(tmpc->topic, cmd, 54); strncpy(chn_list[j].topic, cmd, 54);
snprintf(mbuf, 200, "Topic set to \"%s\"", cmd); snprintf(mbuf, 200, "Topic set to \"%s\"", cmd);
p = xstrcpy((char *)"TOPIC "); p = xstrcpy((char *)"TOPIC ");
p = xstrcat(p, tmpc->name); p = xstrcat(p, chn_list[j].name);
p = xstrcat(p, (char *)" "); p = xstrcat(p, (char *)" ");
p = xstrcat(p, tmpc->topic); p = xstrcat(p, chn_list[j].topic);
p = xstrcat(p, (char *)"\r\n"); p = xstrcat(p, (char *)"\r\n");
send_all(p); send_all(p);
free(p); free(p);
@ -711,7 +720,7 @@ void chat_put_r(char *data, char *buf)
} else { } else {
snprintf(mbuf, 200, "** Not in a channel"); snprintf(mbuf, 200, "** Not in a channel");
} }
system_msg(tmpu->pid, mbuf); system_msg(usr_list[i].pid, mbuf);
chat_dump(); chat_dump();
goto ack; goto ack;
} else { } else {
@ -720,27 +729,27 @@ void chat_put_r(char *data, char *buf)
*/ */
cmd = strtok(msg, " \t\r\n\0"); cmd = strtok(msg, " \t\r\n\0");
snprintf(mbuf, 200, "*** \"%s\" :Unknown command", cmd+1); snprintf(mbuf, 200, "*** \"%s\" :Unknown command", cmd+1);
system_msg(tmpu->pid, mbuf); system_msg(usr_list[i].pid, mbuf);
goto ack; goto ack;
} }
} }
if (strlen(tmpu->channel) == 0) { if (strlen(usr_list[i].channel) == 0) {
/* /*
* Trying messages while not in a channel * Trying messages while not in a channel
*/ */
snprintf(mbuf, 200, "** No channel joined. Try /join #channel"); snprintf(mbuf, 200, "** No channel joined. Try /join #channel");
system_msg(tmpu->pid, mbuf); system_msg(usr_list[i].pid, mbuf);
goto ack; goto ack;
} else { } else {
chat_msg(tmpu->channel, tmpu->nick, msg); chat_msg(usr_list[i].channel, usr_list[i].nick, msg);
/* /*
* Send message to all links but not the #sysop channel * Send message to all links but not the #sysop channel
*/ */
if (strcmp(tmpu->channel, "#sysop")) { if (strcmp(usr_list[i].channel, "#sysop")) {
p = xstrcpy((char *)"PRIVMSG "); p = xstrcpy((char *)"PRIVMSG ");
p = xstrcat(p, tmpu->channel); p = xstrcat(p, usr_list[i].channel);
p = xstrcat(p, (char *)" <"); p = xstrcat(p, (char *)" <");
p = xstrcat(p, tmpu->nick); p = xstrcat(p, usr_list[i].nick);
p = xstrcat(p, (char *)"> "); p = xstrcat(p, (char *)"> ");
p = xstrcat(p, msg); p = xstrcat(p, msg);
p = xstrcat(p, (char *)"\r\n"); p = xstrcat(p, (char *)"\r\n");
@ -779,10 +788,10 @@ hangup:
*/ */
void chat_get_r(char *data, char *buf) void chat_get_r(char *data, char *buf)
{ {
char *p; char *p;
usr_list *tmpu; pid_t pid;
pid_t pid; int i;
if (IsSema((char *)"upsalarm")) { if (IsSema((char *)"upsalarm")) {
snprintf(buf, 200, "100:2,1,*** Power failure, running on UPS;"); snprintf(buf, 200, "100:2,1,*** Power failure, running on UPS;");
return; return;
@ -796,19 +805,19 @@ void chat_get_r(char *data, char *buf)
strtok(data, ","); strtok(data, ",");
pid = (pid_t)atoi(strtok(NULL, ";")); pid = (pid_t)atoi(strtok(NULL, ";"));
for (tmpu = users; tmpu; tmpu = tmpu->next) { for (i = 0; i < MAXIBC_USR; i++) {
if (pid == tmpu->pid) { if (pid == usr_list[i].pid) {
while (tmpu->pointer != buffer_head) { while (usr_list[i].pointer != buffer_head) {
if (tmpu->pointer < MAXMESSAGES) if (usr_list[i].pointer < MAXMESSAGES)
tmpu->pointer++; usr_list[i].pointer++;
else else
tmpu->pointer = 0; usr_list[i].pointer = 0;
if (tmpu->pid == chat_messages[tmpu->pointer].topid) { if (usr_list[i].pid == chat_messages[usr_list[i].pointer].topid) {
/* /*
* Message is for us * Message is for us
*/ */
p = xstrcpy((char *)"100:2,0,"); p = xstrcpy((char *)"100:2,0,");
p = xstrcat(p, clencode(chat_messages[tmpu->pointer].message)); p = xstrcat(p, clencode(chat_messages[usr_list[i].pointer].message));
p = xstrcat(p, (char *)";"); p = xstrcat(p, (char *)";");
strncpy(buf, p, 200); strncpy(buf, p, 200);
free(p); free(p);
@ -830,8 +839,8 @@ void chat_get_r(char *data, char *buf)
*/ */
void chat_checksysop_r(char *data, char *buf) void chat_checksysop_r(char *data, char *buf)
{ {
pid_t pid; pid_t pid;
usr_list *tmpu; int i;
strtok(data, ","); strtok(data, ",");
pid = (pid_t)atoi(strtok(NULL, ";")); pid = (pid_t)atoi(strtok(NULL, ";"));
@ -842,9 +851,9 @@ void chat_checksysop_r(char *data, char *buf)
/* /*
* Now check if sysop is present in the sysop channel * Now check if sysop is present in the sysop channel
*/ */
for (tmpu = users; tmpu; tmpu = tmpu->next) { for (i = 0; i < MAXIBC_USR; i++) {
if (pid != tmpu->pid) { if (pid != usr_list[i].pid) {
if (strlen(tmpu->channel) && (strcasecmp(tmpu->channel, "#sysop") == 0) && tmpu->sysop) { if (strlen(usr_list[i].channel) && (strcasecmp(usr_list[i].channel, "#sysop") == 0) && usr_list[i].sysop) {
Syslog('c', "Sending ACK on check"); Syslog('c', "Sending ACK on check");
snprintf(buf, 20, "100:1,1;"); snprintf(buf, 20, "100:1,1;");
reg_sysoptalk(pid); reg_sysoptalk(pid);

File diff suppressed because it is too large Load Diff

View File

@ -3,12 +3,16 @@
/* $Id$ */ /* $Id$ */
#define MAXIBC_NCS 20 /* Maximum Neighbour ChatServers */
#define MAXIBC_SRV 100 /* Maximum Servers in chatnetwork */
#define MAXIBC_USR 100 /* Maximum Users in chatnetwork */
#define MAXIBC_CHN 100 /* Maximum Channels in chatnetwork */
/* /*
* Linked list of neighbour chatservers * Linked list of neighbour chatservers
*/ */
typedef struct _ncs_list { typedef struct _ncs_rec {
struct _ncs_list *next;
char server[64]; /* Server address */ char server[64]; /* Server address */
char resolved[64]; /* Resolved server address */ char resolved[64]; /* Resolved server address */
char myname[64]; /* My server address */ char myname[64]; /* My server address */
@ -27,15 +31,16 @@ typedef struct _ncs_list {
unsigned int token; /* Server token */ unsigned int token; /* Server token */
int halfdead; /* Halfdead connect count */ int halfdead; /* Halfdead connect count */
unsigned int crc; /* CRC value of record */ unsigned int crc; /* CRC value of record */
} ncs_list; } _ncs_list;
_ncs_list ncs_list[MAXIBC_NCS];
/* /*
* Database with servers * Database with servers
*/ */
typedef struct _srv_list { typedef struct _srv_rec {
struct _srv_list *next;
char server[64]; /* FQDN of the server */ char server[64]; /* FQDN of the server */
char router[64]; /* Route to this server */ char router[64]; /* Route to this server */
int hops; /* Howmany hops away */ int hops; /* Howmany hops away */
@ -44,15 +49,16 @@ typedef struct _srv_list {
char vers[21]; /* Version string */ char vers[21]; /* Version string */
char fullname[37]; /* Full BBS name */ char fullname[37]; /* Full BBS name */
int users; /* Users in chat */ int users; /* Users in chat */
} srv_list; } _srv_list;
_srv_list srv_list[MAXIBC_SRV];
/* /*
* Database with users * Database with users
*/ */
typedef struct _usr_list { typedef struct _usr_rec {
struct _usr_list *next;
char server[64]; /* FQDN of users server */ char server[64]; /* FQDN of users server */
char name[10]; /* Users unix name */ char name[10]; /* Users unix name */
char nick[10]; /* Users nick name */ char nick[10]; /* Users nick name */
@ -62,15 +68,16 @@ typedef struct _usr_list {
unsigned sysop : 1; /* User is a sysop */ unsigned sysop : 1; /* User is a sysop */
pid_t pid; /* Users pid if local */ pid_t pid; /* Users pid if local */
int pointer; /* Users message pointer */ int pointer; /* Users message pointer */
} usr_list; } _usr_list;
_usr_list usr_list[MAXIBC_USR];
/* /*
* Database with channels * Database with channels
*/ */
typedef struct _chn_list { typedef struct _chn_rec {
struct _chn_list *next;
char server[64]; /* Originating server */ char server[64]; /* Originating server */
char name[21]; /* Channel name */ char name[21]; /* Channel name */
char topic[55]; /* Channel topic */ char topic[55]; /* Channel topic */
@ -78,7 +85,9 @@ typedef struct _chn_list {
time_t created; /* Channel created */ time_t created; /* Channel created */
time_t lastmsg; /* Last message in channel */ time_t lastmsg; /* Last message in channel */
int users; /* Users in channel */ int users; /* Users in channel */
} chn_list; } _chn_list;
_chn_list chn_list[MAXIBC_CHN];
@ -106,10 +115,10 @@ typedef struct _nick_list {
} nick_list; } nick_list;
int add_user(usr_list **, char *, char *, char *); int add_user(char *, char *, char *);
void del_user(usr_list **, char *, char *); void del_user(char *, char *);
int add_channel(chn_list **, char *, char *, char *); int add_channel(char *, char *, char *);
void del_channel(chn_list **, char *); void del_channel(char *);
int do_command(char *, char *, char *); int do_command(char *, char *, char *);
void send_all(char *); void send_all(char *);
@ -117,8 +126,8 @@ void send_at(char *, char *, char *);
void send_nick(char *, char *, char *); void send_nick(char *, char *, char *);
void check_servers(void); void check_servers(void);
void ibc_receiver(char *); void ibc_receiver(char *);
void ibc_init(void);
void ibc_shutdown(void); void ibc_shutdown(void);
#endif #endif

View File

@ -88,9 +88,6 @@ static status_r status; /* Status data */
extern double Load; /* System Load */ extern double Load; /* System Load */
extern int Processing; /* Is system running */ extern int Processing; /* Is system running */
extern srv_list *servers; /* Connected servers */
extern usr_list *users; /* Connected users */
extern chn_list *channels; /* Connected channels */
/************************************************************************ /************************************************************************
@ -293,17 +290,17 @@ void stat_inc_cerr()
void stat_status_r(char *buf) void stat_status_r(char *buf)
{ {
int srvcnt = 0, chncnt = 0, usrcnt = 0; int i, srvcnt = 0, chncnt = 0, usrcnt = 0;
srv_list *tmps;
chn_list *tmpc;
usr_list *tmpu;
for (tmps = servers; tmps; tmps = tmps->next) for (i = 0; i < MAXIBC_SRV; i++)
srvcnt++; if (strlen(srv_list[i].server))
for (tmpc = channels; tmpc; tmpc = tmpc->next) srvcnt++;
chncnt++; for (i = 0; i < MAXIBC_CHN; i++)
for (tmpu = users; tmpu; tmpu = tmpu->next) if (strlen(chn_list[i].server))
usrcnt++; chncnt++;
for (i = 0; i < MAXIBC_USR; i++)
if (strlen(usr_list[i].server))
usrcnt++;
snprintf(buf, SS_BUFSIZE, "100:23,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%2.2f,%u,%d,%d,%d;", snprintf(buf, SS_BUFSIZE, "100:23,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%2.2f,%u,%d,%d,%d;",
status.start, status.laststart, status.daily, status.start, status.laststart, status.daily,
status.startups, status.clients, status.startups, status.clients,