added second part of channel handling
This commit is contained in:
parent
80c6a2a928
commit
5a5bfe018e
@ -155,12 +155,22 @@ void chat_dump(void)
|
|||||||
for (i = 0; i < MAXCLIENT; i++)
|
for (i = 0; i < MAXCLIENT; i++)
|
||||||
if (chat_users[i].pid) {
|
if (chat_users[i].pid) {
|
||||||
if (first) {
|
if (first) {
|
||||||
|
#ifdef USE_EXPERIMENT
|
||||||
|
Syslog('u', " pid username nick channel chats sysop");
|
||||||
|
Syslog('u', "----- ------------------------------------ --------- -------------------- ----- -----");
|
||||||
|
#else
|
||||||
Syslog('u', " pid username nick ch chats sysop");
|
Syslog('u', " pid username nick ch chats sysop");
|
||||||
Syslog('u', "----- ------------------------------------ --------- -- ----- -----");
|
Syslog('u', "----- ------------------------------------ --------- -- ----- -----");
|
||||||
|
#endif
|
||||||
first = FALSE;
|
first = FALSE;
|
||||||
}
|
}
|
||||||
Syslog('u', "%5d %-36s %-9s %2d %s %s", chat_users[i].pid, chat_users[i].realname, chat_users[i].nick, chat_users[i].channel,
|
#ifdef USE_EXPERIMENT
|
||||||
chat_users[i].chatting?"True ":"False", chat_users[i].sysop?"True ":"False");
|
Syslog('u', "%5d %-36s %-9s %-20s %s %s", chat_users[i].pid, chat_users[i].realname, chat_users[i].nick,
|
||||||
|
chat_users[i].channel, chat_users[i].chatting?"True ":"False", chat_users[i].sysop?"True ":"False");
|
||||||
|
#else
|
||||||
|
Syslog('u', "%5d %-36s %-9s %2d %s %s", chat_users[i].pid, chat_users[i].realname, chat_users[i].nick,
|
||||||
|
chat_users[i].channel, chat_users[i].chatting?"True ":"False", chat_users[i].sysop?"True ":"False");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
first = TRUE;
|
first = TRUE;
|
||||||
#ifndef USE_EXPERIMENT
|
#ifndef USE_EXPERIMENT
|
||||||
@ -846,6 +856,7 @@ char *chat_put(char *data)
|
|||||||
} else if (strncasecmp(msg, "/topic", 6) == 0) {
|
} else if (strncasecmp(msg, "/topic", 6) == 0) {
|
||||||
#ifdef USE_EXPERIMENT
|
#ifdef USE_EXPERIMENT
|
||||||
if (strlen(chat_users[i].channel)) {
|
if (strlen(chat_users[i].channel)) {
|
||||||
|
sprintf(buf, "** Internal system error");
|
||||||
for (tmpc = channels; tmpc; tmpc = tmpc->next) {
|
for (tmpc = channels; tmpc; tmpc = tmpc->next) {
|
||||||
if (strcmp(chat_users[i].channel, tmpc->name)) {
|
if (strcmp(chat_users[i].channel, tmpc->name)) {
|
||||||
if ((strcmp(chat_users[i].name, tmpc->owner) == 0) || (strcmp(chat_users[i].nick, tmpc->owner) == 0)) {
|
if ((strcmp(chat_users[i].name, tmpc->owner) == 0) || (strcmp(chat_users[i].nick, tmpc->owner) == 0)) {
|
||||||
@ -862,6 +873,8 @@ char *chat_put(char *data)
|
|||||||
sprintf(buf, "** You are not the channel owner");
|
sprintf(buf, "** You are not the channel owner");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
Syslog('r', "channel %s is not what we want", tmpc->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
156
mbtask/taskibc.c
156
mbtask/taskibc.c
@ -89,6 +89,9 @@ void command_squit(char *, char *);
|
|||||||
void command_user(char *, char *);
|
void command_user(char *, char *);
|
||||||
void command_quit(char *, char *);
|
void command_quit(char *, char *);
|
||||||
int command_nick(char *, char *);
|
int command_nick(char *, char *);
|
||||||
|
void command_join(char *, char *);
|
||||||
|
void command_part(char *, char *);
|
||||||
|
void command_topic(char *, char *);
|
||||||
void receiver(struct servent *);
|
void receiver(struct servent *);
|
||||||
|
|
||||||
|
|
||||||
@ -1121,6 +1124,141 @@ int command_nick(char *hostname, char *parameters)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void command_join(char *hostname, char *parameters)
|
||||||
|
{
|
||||||
|
ncs_list *tnsl;
|
||||||
|
chn_list *tmp;
|
||||||
|
usr_list *tmpu;
|
||||||
|
char *nick, *server, *channel;
|
||||||
|
int found;
|
||||||
|
|
||||||
|
for (tnsl = ncsl; tnsl; tnsl = tnsl->next) {
|
||||||
|
if (strcmp(tnsl->server, hostname) == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nick = strtok(parameters, " \0");
|
||||||
|
server = strtok(NULL, " \0");
|
||||||
|
channel = strtok(NULL, "\0");
|
||||||
|
|
||||||
|
if (channel == NULL) {
|
||||||
|
send_msg(tnsl, "461 JOIN: Not enough parameters\r\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen(channel) > 20) {
|
||||||
|
send_msg(tnsl, "432 %s: Erroneous channelname\r\n", nick);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
found = FALSE;
|
||||||
|
for (tmp = channels; tmp; tmp = tmp->next) {
|
||||||
|
if (strcmp(tmp->name, channel) == 0) {
|
||||||
|
found = TRUE;
|
||||||
|
tmp->users++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
Syslog('+', "IBC: create channel %s owned by %s@%s", channel, nick, server);
|
||||||
|
add_channel(&channels, channel, nick, server);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (tmpu = users; tmpu; tmpu = tmpu->next) {
|
||||||
|
if ((strcmp(tmpu->server, server) == 0) && (strcmp(tmpu->nick, nick) == 0) && (strcmp(tmpu->name, nick) == 0)) {
|
||||||
|
pthread_mutex_lock(&b_mutex);
|
||||||
|
strncpy(tmpu->channel, channel, 20);
|
||||||
|
pthread_mutex_unlock(&b_mutex);
|
||||||
|
Syslog('+', "IBC: user %s joined channel %s", nick, channel);
|
||||||
|
usrchg = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
chnchg = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void command_part(char *hostname, char *parameters)
|
||||||
|
{
|
||||||
|
ncs_list *tnsl;
|
||||||
|
chn_list *tmp;
|
||||||
|
usr_list *tmpu;
|
||||||
|
char *nick, *server, *channel;
|
||||||
|
|
||||||
|
for (tnsl = ncsl; tnsl; tnsl = tnsl->next) {
|
||||||
|
if (strcmp(tnsl->server, hostname) == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nick = strtok(parameters, " \0");
|
||||||
|
server = strtok(NULL, " \0");
|
||||||
|
channel = strtok(NULL, "\0");
|
||||||
|
|
||||||
|
if (channel == NULL) {
|
||||||
|
send_msg(tnsl, "461 PART: Not enough parameters\r\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (tmp = channels; tmp; tmp = tmp->next) {
|
||||||
|
if (strcmp(tmp->name, channel) == 0) {
|
||||||
|
chnchg = TRUE;
|
||||||
|
tmp->users--;
|
||||||
|
if (tmp->users == 0) {
|
||||||
|
Syslog('+', "IBC: deleted empty channel %s", channel);
|
||||||
|
del_channel(&channels, channel);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (tmpu = users; tmpu; tmpu = tmpu->next) {
|
||||||
|
if ((strcmp(tmpu->server, server) == 0) && (strcmp(tmpu->nick, nick) == 0) && (strcmp(tmpu->name, nick) == 0)) {
|
||||||
|
pthread_mutex_lock(&b_mutex);
|
||||||
|
tmpu->channel[0] = '\0';
|
||||||
|
pthread_mutex_unlock(&b_mutex);
|
||||||
|
Syslog('+', "IBC: user %s left channel %s", nick, channel);
|
||||||
|
usrchg = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void command_topic(char *hostname, char *parameters)
|
||||||
|
{
|
||||||
|
ncs_list *tnsl;
|
||||||
|
chn_list *tmp;
|
||||||
|
char *channel, *topic;
|
||||||
|
|
||||||
|
for (tnsl = ncsl; tnsl; tnsl = tnsl->next) {
|
||||||
|
if (strcmp(tnsl->server, hostname) == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
channel = strtok(parameters, " \0");
|
||||||
|
topic = strtok(NULL, "\0");
|
||||||
|
|
||||||
|
if (topic == NULL) {
|
||||||
|
send_msg(tnsl, "461 TOPIC: Not enough parameters\r\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (tmp = channels; tmp; tmp = tmp->next) {
|
||||||
|
if (strcmp(tmp->name, channel) == 0) {
|
||||||
|
chnchg = TRUE;
|
||||||
|
strncpy(tmp->topic, topic, 54);
|
||||||
|
Syslog('+', "IBC: channel %s topic: %s", channel, topic);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void receiver(struct servent *se)
|
void receiver(struct servent *se)
|
||||||
{
|
{
|
||||||
struct pollfd pfd;
|
struct pollfd pfd;
|
||||||
@ -1234,6 +1372,24 @@ void receiver(struct servent *se)
|
|||||||
} else {
|
} else {
|
||||||
command_nick(hostname, parameters);
|
command_nick(hostname, parameters);
|
||||||
}
|
}
|
||||||
|
} else if (! strcmp(command, (char *)"JOIN")) {
|
||||||
|
if (parameters == NULL) {
|
||||||
|
send_msg(tnsl, "461 %s: Not enough parameters\r\n", command);
|
||||||
|
} else {
|
||||||
|
command_join(hostname, parameters);
|
||||||
|
}
|
||||||
|
} else if (! strcmp(command, (char *)"PART")) {
|
||||||
|
if (parameters == NULL) {
|
||||||
|
send_msg(tnsl, "461 %s: Not enough parameters\r\n", command);
|
||||||
|
} else {
|
||||||
|
command_part(hostname, parameters);
|
||||||
|
}
|
||||||
|
} else if (! strcmp(command, (char *)"TOPIC")) {
|
||||||
|
if (parameters == NULL) {
|
||||||
|
send_msg(tnsl, "461 %s: Not enough parameters\r\n", command);
|
||||||
|
} else {
|
||||||
|
command_topic(hostname, parameters);
|
||||||
|
}
|
||||||
} else if (atoi(command)) {
|
} else if (atoi(command)) {
|
||||||
Syslog('r', "IBC: Got error %d", atoi(command));
|
Syslog('r', "IBC: Got error %d", atoi(command));
|
||||||
} else if (tnsl->state == NCS_CONNECT) {
|
} else if (tnsl->state == NCS_CONNECT) {
|
||||||
|
Reference in New Issue
Block a user