Changed databases

This commit is contained in:
Michiel Broek 2005-05-01 13:12:41 +00:00
parent e3ad201c51
commit c4b5cb546e
3 changed files with 83 additions and 61 deletions

View File

@ -95,16 +95,6 @@ typedef struct _channel_rec {
/*
* 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 * The buffers
*/ */
@ -154,12 +144,12 @@ void chat_dump(void)
for (tmpu = users; tmpu; tmpu = tmpu->next) { for (tmpu = users; tmpu; tmpu = tmpu->next) {
if (tmpu->pid) { if (tmpu->pid) {
if (first) { if (first) {
Syslog('u', " pid username nick channel chats sysop"); Syslog('u', " pid username nick channel sysop");
Syslog('u', "----- ------------------------------------ --------- -------------------- ----- -----"); Syslog('u', "----- ------------------------------------ --------- -------------------- -----");
first = FALSE; first = FALSE;
} }
Syslog('u', "%5d %-36s %-9s %-20s %s %s", tmpu->pid, tmpu->realname, tmpu->nick, Syslog('u', "%5d %-36s %-9s %-20s %s", tmpu->pid, tmpu->realname, tmpu->nick,
tmpu->channel, tmpu->chatting?"True ":"False", tmpu->sysop?"True ":"False"); tmpu->channel, tmpu->sysop?"True ":"False");
} }
} }
#else #else
@ -293,7 +283,6 @@ int join(pid_t pid, char *channel, int sysop)
pthread_mutex_lock(&b_mutex); pthread_mutex_lock(&b_mutex);
strncpy(tmpu->channel, channel, 20); strncpy(tmpu->channel, channel, 20);
tmpu->chatting = TRUE;
pthread_mutex_unlock(&b_mutex); pthread_mutex_unlock(&b_mutex);
Syslog('+', "IBC: user %s has joined channel %s", tmpu->nick, channel); Syslog('+', "IBC: user %s has joined channel %s", tmpu->nick, channel);
usrchg = TRUE; usrchg = TRUE;
@ -358,8 +347,6 @@ int join(pid_t pid, char *channel, int sysop)
pthread_mutex_lock(&b_mutex); pthread_mutex_lock(&b_mutex);
strncpy(tmpu->channel, channel, 20); strncpy(tmpu->channel, channel, 20);
tmpu->chatting = TRUE;
tmpu->chanop = TRUE;
pthread_mutex_unlock(&b_mutex); pthread_mutex_unlock(&b_mutex);
Syslog('+', "IBC: user %s created and joined channel %s", tmpu->nick, channel); Syslog('+', "IBC: user %s created and joined channel %s", tmpu->nick, channel);
usrchg = TRUE; usrchg = TRUE;
@ -435,7 +422,7 @@ int part(pid_t pid, char *reason)
#ifdef USE_EXPERIMENT #ifdef USE_EXPERIMENT
for (tmpu = users; tmpu; tmpu = tmpu->next) { for (tmpu = users; tmpu; tmpu = tmpu->next) {
if ((tmpu->pid == pid) && tmpu->chatting) { if ((tmpu->pid == pid) && strlen(tmpu->channel)) {
for (tmp = channels; tmp; tmp = tmp->next) { for (tmp = channels; tmp; tmp = tmp->next) {
if (strcmp(tmp->name, tmpu->channel) == 0) { if (strcmp(tmp->name, tmpu->channel) == 0) {
tmp->users--; tmp->users--;
@ -466,6 +453,7 @@ int part(pid_t pid, char *reason)
*/ */
Syslog('+', "IBC: removed channel %s, no more users left", tmp->name); Syslog('+', "IBC: removed channel %s, no more users left", tmp->name);
del_channel(&channels, tmp->name); del_channel(&channels, tmp->name);
chnchg = TRUE;
} }
/* /*
@ -473,7 +461,6 @@ int part(pid_t pid, char *reason)
*/ */
pthread_mutex_lock(&b_mutex); pthread_mutex_lock(&b_mutex);
tmpu->channel[0] = '\0'; tmpu->channel[0] = '\0';
tmpu->chatting = FALSE;
pthread_mutex_unlock(&b_mutex); pthread_mutex_unlock(&b_mutex);
usrchg = TRUE; usrchg = TRUE;
@ -516,7 +503,6 @@ int part(pid_t pid, char *reason)
} }
#endif #endif
Syslog('-', "No channel found");
return FALSE; return FALSE;
} }
@ -567,7 +553,7 @@ void chat_msg(char *channel, char *nick, char *msg)
buf[79] = '\0'; buf[79] = '\0';
for (tmpu = users; tmpu; tmpu = tmpu->next) { for (tmpu = users; tmpu; tmpu = tmpu->next) {
if ((strcmp(tmpu->channel, channel) == 0) && tmpu->chatting) { if (strlen(tmpu->channel) && (strcmp(tmpu->channel, channel) == 0)) {
system_msg(tmpu->pid, buf); system_msg(tmpu->pid, buf);
} }
} }
@ -913,14 +899,14 @@ char *chat_put(char *data)
system_msg(tmpu->pid, buf); system_msg(tmpu->pid, buf);
sprintf(buf, "Nick Real name Flags"); sprintf(buf, "Nick Real name Flags");
system_msg(tmpu->pid, buf); system_msg(tmpu->pid, buf);
sprintf(buf, "---------------------------------------- ----------------------------- -------"); sprintf(buf, "---------------------------------------- ------------------------------ -------");
system_msg(tmpu->pid, buf); system_msg(tmpu->pid, buf);
count = 0; count = 0;
for (tmp = users; tmp; tmp = tmp->next) { for (tmp = users; tmp; tmp = tmp->next) {
if (strcmp(tmp->channel, tmpu->channel) == 0) { if (strcmp(tmp->channel, tmpu->channel) == 0) {
sprintf(temp, "%s@%s", tmp->nick, tmp->server); sprintf(temp, "%s@%s", tmp->nick, tmp->server);
sprintf(buf, "%-40s %-30s %s", temp, tmp->realname, sprintf(buf, "%-40s %-30s %s", temp, tmp->realname,
tmp->chanop ? (char *)"chanop" : (char *)""); tmp->sysop ? (char *)"sysop" : (char *)"");
system_msg(tmpu->pid, buf); system_msg(tmpu->pid, buf);
count++; count++;
} }
@ -1211,7 +1197,7 @@ char *chat_checksysop(char *data)
#ifdef USE_EXPERIMENT #ifdef USE_EXPERIMENT
for (tmpu = users; tmpu; tmpu = tmpu->next) { for (tmpu = users; tmpu; tmpu = tmpu->next) {
if (atoi(pid) != tmpu->pid) { if (atoi(pid) != tmpu->pid) {
if (tmpu->chatting && tmpu->sysop) { if (strlen(tmpu->channel) && (strcasecmp(tmpu->channel, "#sysop") == 0) && tmpu->sysop) {
Syslog('-', "Sending ACK on check"); Syslog('-', "Sending ACK on check");
sprintf(buf, "100:1,1;"); sprintf(buf, "100:1,1;");
reg_sysoptalk(pid); reg_sysoptalk(pid);

View File

@ -48,14 +48,18 @@ ncs_list *ncsl = NULL; /* Neighbours list */
srv_list *servers = NULL; /* Active servers */ srv_list *servers = NULL; /* Active servers */
usr_list *users = NULL; /* Active users */ usr_list *users = NULL; /* Active users */
chn_list *channels = NULL; /* Active channels */ chn_list *channels = NULL; /* Active channels */
ban_list *banned = NULL; /* Banned users */
nick_list *nicknames = NULL; /* Known nicknames */
int ls; /* Listen socket */ int ls; /* Listen socket */
struct sockaddr_in myaddr_in; /* Listen socket address */ struct sockaddr_in myaddr_in; /* Listen socket address */
struct sockaddr_in clientaddr_in; /* Remote socket address */ struct sockaddr_in clientaddr_in; /* Remote socket address */
int changed = FALSE; /* Databases changed */
char crbuf[512]; /* Chat receive buffer */ char crbuf[512]; /* Chat receive buffer */
int srvchg = FALSE; /* Is serverlist changed */ int srvchg = FALSE; /* Is serverlist changed */
int usrchg = FALSE; /* Is userlist changed */ int usrchg = FALSE; /* Is userlist changed */
int chnchg = FALSE; /* Is channellist changed */ int chnchg = FALSE; /* Is channellist changed */
int banchg = FALSE; /* Is banned users changed */
int nickchg = FALSE; /* Is nicknames changed */
pthread_mutex_t b_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t b_mutex = PTHREAD_MUTEX_INITIALIZER;
@ -145,33 +149,41 @@ void dump_ncslist(void)
usr_list *usrp; usr_list *usrp;
chn_list *chnp; chn_list *chnp;
if (!changed && !srvchg && !usrchg && !chnchg) if (!srvchg && !usrchg && !chnchg && !banchg && !nickchg)
return; return;
if (srvchg) {
if (ncsl) {
Syslog('r', "Server State Del Pwd Srv Next action"); Syslog('r', "Server State Del Pwd Srv Next action");
Syslog('r', "------------------------------ ------- --- --- --- -----------"); Syslog('r', "------------------------------ ------- --- --- --- -----------");
for (tmp = ncsl; tmp; tmp = tmp->next) { for (tmp = ncsl; tmp; tmp = tmp->next) {
Syslog('r', "%-30s %-7s %s %s %s %d", tmp->server, ncsstate[tmp->state], Syslog('r', "%-30s %-7s %s %s %s %d", tmp->server, ncsstate[tmp->state],
tmp->remove ? "yes":"no ", tmp->gotpass ? "yes":"no ", tmp->remove ? "yes":"no ", tmp->gotpass ? "yes":"no ",
tmp->gotserver ? "yes":"no ", (int)tmp->action - (int)now); tmp->gotserver ? "yes":"no ", (int)tmp->action - (int)now);
} }
} else {
Syslog('r', "No servers configured");
}
if (srvchg) { if (servers) {
Syslog('+', "IBC: Server Router Hops Users Connect time"); Syslog('+', "IBC: Server Router Hops Users Connect time");
Syslog('+', "IBC: ------------------------- ------------------------- ----- ----- --------------------"); Syslog('+', "IBC: ------------------------- ------------------------- ----- ----- --------------------");
for (srv = servers; srv; srv = srv->next) { for (srv = servers; srv; srv = srv->next) {
Syslog('+', "IBC: %-25s %-25s %5d %5d %s", srv->server, srv->router, srv->hops, srv->users, rfcdate(srv->connected)); Syslog('+', "IBC: %-25s %-25s %5d %5d %s", srv->server, srv->router, srv->hops,
srv->users, rfcdate(srv->connected));
}
} else {
Syslog('+', "IBC: Servers list is empty");
} }
} }
if (usrchg) { if (usrchg) {
if (users) { if (users) {
Syslog('+', "IBC: Server User Name/Nick Channel Cop Connect time"); Syslog('+', "IBC: Server User Name/Nick Channel Sys Connect time");
Syslog('+', "IBC: -------------------- -------------------- --------- ------------- --- --------------------"); Syslog('+', "IBC: -------------------- -------------------- --------- ------------- --- --------------------");
for (usrp = users; usrp; usrp = usrp->next) { for (usrp = users; usrp; usrp = usrp->next) {
Syslog('+', "IBC: %-20s %-20s %-9s %-13s %s %s", usrp->server, usrp->realname, usrp->nick, usrp->channel, Syslog('+', "IBC: %-20s %-20s %-9s %-13s %s %s", usrp->server, usrp->realname, usrp->nick, usrp->channel,
usrp->chanop ? "yes":"no ", rfcdate(usrp->connected)); usrp->sysop ? "yes":"no ", rfcdate(usrp->connected));
} }
} else { } else {
Syslog('+', "IBC: Users list is empty"); Syslog('+', "IBC: Users list is empty");
@ -194,7 +206,8 @@ void dump_ncslist(void)
srvchg = FALSE; srvchg = FALSE;
usrchg = FALSE; usrchg = FALSE;
chnchg = FALSE; chnchg = FALSE;
changed = FALSE; banchg = FALSE;
nickchg = FALSE;
} }
@ -595,7 +608,7 @@ void check_servers(void)
} }
if (!inlist ) { if (!inlist ) {
fill_ncslist(&ncsl, ibcsrv.server, ibcsrv.myname, ibcsrv.passwd); fill_ncslist(&ncsl, ibcsrv.server, ibcsrv.myname, ibcsrv.passwd);
changed = TRUE; srvchg = TRUE;
Syslog('+', "IBC: new configured Internet BBS Chatserver: %s", ibcsrv.server); Syslog('+', "IBC: new configured Internet BBS Chatserver: %s", ibcsrv.server);
} }
} }
@ -617,7 +630,7 @@ void check_servers(void)
Syslog('+', "IBC: server %s removed from configuration", tnsl->server); Syslog('+', "IBC: server %s removed from configuration", tnsl->server);
tnsl->remove = TRUE; tnsl->remove = TRUE;
tnsl->action = now; tnsl->action = now;
changed = TRUE; srvchg = TRUE;
} }
} }
fclose(fp); fclose(fp);
@ -635,7 +648,7 @@ void check_servers(void)
if (((int)tnsl->action - (int)now) <= 0) { if (((int)tnsl->action - (int)now) <= 0) {
switch (tnsl->state) { switch (tnsl->state) {
case NCS_INIT: Syslog('r', "%s init", tnsl->server); case NCS_INIT: Syslog('r', "%s init", tnsl->server);
changed = TRUE; srvchg = TRUE;
/* /*
* If Internet is available, setup the connection. * If Internet is available, setup the connection.
@ -665,7 +678,7 @@ void check_servers(void)
Syslog('!', "IBC: no IP address for %s: %s", tnsl->server, errmsg); Syslog('!', "IBC: no IP address for %s: %s", tnsl->server, errmsg);
tnsl->action = now + (time_t)120; tnsl->action = now + (time_t)120;
tnsl->state = NCS_FAIL; tnsl->state = NCS_FAIL;
changed = TRUE; srvchg = TRUE;
break; break;
} }
@ -674,7 +687,7 @@ void check_servers(void)
Syslog('!', "$IBC: can't create socket for %s", tnsl->server); Syslog('!', "$IBC: can't create socket for %s", tnsl->server);
tnsl->state = NCS_FAIL; tnsl->state = NCS_FAIL;
tnsl->action = now + (time_t)120; tnsl->action = now + (time_t)120;
changed = TRUE; srvchg = TRUE;
break; break;
} }
@ -697,7 +710,7 @@ void check_servers(void)
VERSION, CFG.bbs_name); VERSION, CFG.bbs_name);
tnsl->action = now + (time_t)10; tnsl->action = now + (time_t)10;
tnsl->state = NCS_WAITPWD; tnsl->state = NCS_WAITPWD;
changed = TRUE; srvchg = TRUE;
break; break;
case NCS_WAITPWD: /* case NCS_WAITPWD: /*
@ -714,7 +727,7 @@ void check_servers(void)
} }
Syslog('r', "next call in %d %d seconds", CFG.dialdelay, j); Syslog('r', "next call in %d %d seconds", CFG.dialdelay, j);
tnsl->action = now + (time_t)j; tnsl->action = now + (time_t)j;
changed = TRUE; srvchg = TRUE;
break; break;
case NCS_CONNECT: /* case NCS_CONNECT: /*
@ -732,7 +745,7 @@ void check_servers(void)
tnsl->token = 0; tnsl->token = 0;
del_router(&servers, tnsl->server); del_router(&servers, tnsl->server);
broadcast(tnsl->server, "SQUIT %s Connection died\r\n", tnsl->server); broadcast(tnsl->server, "SQUIT %s Connection died\r\n", tnsl->server);
changed = TRUE; srvchg = TRUE;
system_shout("*** NETWORK SPLIT, lost connection with server %s", tnsl->server); system_shout("*** NETWORK SPLIT, lost connection with server %s", tnsl->server);
break; break;
} }
@ -754,19 +767,19 @@ void check_servers(void)
case NCS_HANGUP: Syslog('r', "%s hangup => call", tnsl->server); case NCS_HANGUP: Syslog('r', "%s hangup => call", tnsl->server);
tnsl->action = now + (time_t)1; tnsl->action = now + (time_t)1;
tnsl->state = NCS_CALL; tnsl->state = NCS_CALL;
changed = TRUE; srvchg = TRUE;
break; break;
case NCS_DEAD: Syslog('r', "%s dead -> call", tnsl->server); case NCS_DEAD: Syslog('r', "%s dead -> call", tnsl->server);
tnsl->action = now + (time_t)1; tnsl->action = now + (time_t)1;
tnsl->state = NCS_CALL; tnsl->state = NCS_CALL;
changed = TRUE; srvchg = TRUE;
break; break;
case NCS_FAIL: Syslog('r', "%s fail => init", tnsl->server); case NCS_FAIL: Syslog('r', "%s fail => init", tnsl->server);
tnsl->action = now + (time_t)1; tnsl->action = now + (time_t)1;
tnsl->state = NCS_INIT; tnsl->state = NCS_INIT;
changed = TRUE; srvchg = TRUE;
break; break;
} }
} }
@ -806,7 +819,7 @@ int command_pass(char *hostname, char *parameters)
tnsl->version = atoi(version); tnsl->version = atoi(version);
if (lnk && strchr(lnk, 'Z')) if (lnk && strchr(lnk, 'Z'))
tnsl->compress = TRUE; tnsl->compress = TRUE;
changed = TRUE; srvchg = TRUE;
return 0; return 0;
} }
@ -854,7 +867,7 @@ int command_server(char *hostname, char *parameters)
broadcast(tnsl->server, "SERVER %s %d %s %s %s %s\r\n", name, ihops, id, prod, vers, fullname); broadcast(tnsl->server, "SERVER %s %d %s %s %s %s\r\n", name, ihops, id, prod, vers, fullname);
system_shout("* New server: %s, %s", name, fullname); system_shout("* New server: %s, %s", name, fullname);
tnsl->gotserver = TRUE; tnsl->gotserver = TRUE;
changed = TRUE; srvchg = TRUE;
tnsl->state = NCS_CONNECT; tnsl->state = NCS_CONNECT;
tnsl->action = now + (time_t)10; tnsl->action = now + (time_t)10;
Syslog('+', "IBC: connected with neighbour server: %s", tnsl->server); Syslog('+', "IBC: connected with neighbour server: %s", tnsl->server);
@ -934,7 +947,7 @@ int command_server(char *hostname, char *parameters)
} }
} }
add_server(&servers, tnsl->server, ihops, prod, vers, fullname, hostname); add_server(&servers, tnsl->server, ihops, prod, vers, fullname, hostname);
changed = TRUE; srvchg = TRUE;
return 0; return 0;
} }
@ -944,7 +957,7 @@ int command_server(char *hostname, char *parameters)
*/ */
add_server(&servers, name, ihops, prod, vers, fullname, hostname); add_server(&servers, name, ihops, prod, vers, fullname, hostname);
broadcast(hostname, "SERVER %s %d %s %s %s %s\r\n", name, ihops, id, prod, vers, fullname); broadcast(hostname, "SERVER %s %d %s %s %s %s\r\n", name, ihops, id, prod, vers, fullname);
changed = TRUE; srvchg = TRUE;
Syslog('+', "IBC: new relay server %s: %s", name, fullname); Syslog('+', "IBC: new relay server %s: %s", name, fullname);
system_shout("* New server: %s, %s", name, fullname); system_shout("* New server: %s, %s", name, fullname);
return 0; return 0;
@ -985,7 +998,7 @@ int command_squit(char *hostname, char *parameters)
system_shout("* Server %s disconnected: %s", name, message); system_shout("* Server %s disconnected: %s", name, message);
broadcast(hostname, "SQUIT %s %s\r\n", name, message); broadcast(hostname, "SQUIT %s %s\r\n", name, message);
changed = TRUE; srvchg = TRUE;
return 0; return 0;
} }

View File

@ -57,9 +57,7 @@ typedef struct _usr_list {
char realname[37]; /* Users real name */ char realname[37]; /* Users real name */
char channel[21]; /* Users channel */ char channel[21]; /* Users channel */
time_t connected; /* Users connect time */ time_t connected; /* Users connect time */
unsigned chanop : 1; /* User is a chanop */
unsigned sysop : 1; /* User is a sysop */ unsigned sysop : 1; /* User is a sysop */
unsigned chatting : 1; /* User is chating */
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;
@ -82,6 +80,31 @@ typedef struct _chn_list {
/*
* Database with banned users
*/
typedef struct _ban_list {
struct _ban_list *next;
char name[10]; /* Users name */
char server[64]; /* Users server */
char channel[21]; /* Users banned channel */
time_t kicked; /* Users banned time */
} ban_list;
/*
* Database with nicknames
*/
typedef struct _nick_list {
struct _nick_list *next;
char nick[10]; /* Nickname */
char server[64]; /* Originating server */
time_t lastused; /* Last used time */
} nick_list;
int add_user(usr_list **, char *, char *, char *); int add_user(usr_list **, char *, char *, char *);
void del_user(usr_list **, char *, char *); void del_user(usr_list **, char *, char *);
int add_channel(chn_list **, char *, char *, char *); int add_channel(chn_list **, char *, char *, char *);