Code cleanup

This commit is contained in:
Michiel Broek 2005-05-01 13:35:43 +00:00
parent c4b5cb546e
commit 85b7d186f8

View File

@ -114,6 +114,7 @@ extern usr_list *users; /* Connected users */
extern chn_list *channels; /* Connected channels */ extern chn_list *channels; /* Connected channels */
extern int usrchg; extern int usrchg;
extern int chnchg; extern int chnchg;
extern int srvchg;
extern pthread_mutex_t b_mutex; extern pthread_mutex_t b_mutex;
#endif #endif
@ -277,15 +278,17 @@ int join(pid_t pid, char *channel, int sysop)
if (channels) { if (channels) {
for (tmp = channels; tmp; tmp = tmp->next) { for (tmp = channels; tmp; tmp = tmp->next) {
if (strcmp(tmp->name, channel) == 0) { if (strcmp(tmp->name, channel) == 0) {
tmp->users++;
for (tmpu = users; tmpu; tmpu = tmpu->next) { for (tmpu = users; tmpu; tmpu = tmpu->next) {
if (tmpu->pid == pid) { if (tmpu->pid == pid) {
pthread_mutex_lock(&b_mutex); pthread_mutex_lock(&b_mutex);
strncpy(tmpu->channel, channel, 20); strncpy(tmpu->channel, channel, 20);
tmp->users++;
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;
srvchg = TRUE;
chnchg = TRUE;
chat_dump(); chat_dump();
sprintf(buf, "%s has joined channel %s, now %d users", tmpu->nick, channel, tmp->users); sprintf(buf, "%s has joined channel %s, now %d users", tmpu->nick, channel, tmp->users);
@ -350,6 +353,8 @@ int join(pid_t pid, char *channel, int sysop)
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;
chnchg = TRUE;
srvchg = TRUE;
sprintf(buf, "* Created channel %s", channel); sprintf(buf, "* Created channel %s", channel);
chat_msg(channel, NULL, buf); chat_msg(channel, NULL, buf);
@ -425,9 +430,6 @@ int part(pid_t pid, char *reason)
if ((tmpu->pid == pid) && strlen(tmpu->channel)) { 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--;
chnchg = TRUE;
/* /*
* Inform other users * Inform other users
*/ */
@ -446,6 +448,9 @@ int part(pid_t pid, char *reason)
/* /*
* Clean channel * Clean channel
*/ */
pthread_mutex_lock(&b_mutex);
tmp->users--;
pthread_mutex_unlock(&b_mutex);
Syslog('+', "IBC: nick %s leaves channel %s", tmpu->nick, tmp->name); Syslog('+', "IBC: nick %s leaves channel %s", tmpu->nick, tmp->name);
if (tmp->users == 0) { if (tmp->users == 0) {
/* /*
@ -463,6 +468,8 @@ int part(pid_t pid, char *reason)
tmpu->channel[0] = '\0'; tmpu->channel[0] = '\0';
pthread_mutex_unlock(&b_mutex); pthread_mutex_unlock(&b_mutex);
usrchg = TRUE; usrchg = TRUE;
chnchg = TRUE;
srvchg = TRUE;
chat_dump(); chat_dump();
return TRUE; return TRUE;
@ -636,9 +643,13 @@ char *chat_connect(char *data)
/* /*
* Oke, found * Oke, found
*/ */
pthread_mutex_lock(&b_mutex);
tmpu->pid = atoi(pid); tmpu->pid = atoi(pid);
tmpu->pointer = buffer_head; tmpu->pointer = buffer_head;
tmpu->sysop = sys; tmpu->sysop = sys;
pthread_mutex_unlock(&b_mutex);
usrchg = TRUE;
srvchg = TRUE;
Syslog('-', "Connected user %s (%s) with chatserver, sysop %s", realname, pid, sys ? "True":"False"); Syslog('-', "Connected user %s (%s) with chatserver, sysop %s", realname, pid, sys ? "True":"False");
/* /*