Added user and quit network commands

This commit is contained in:
Michiel Broek 2005-04-20 21:27:25 +00:00
parent 9576b3233f
commit bd279ee3c2
2 changed files with 90 additions and 9 deletions

View File

@ -487,7 +487,7 @@ char *chat_close(char *data)
* Remove from IBC network * Remove from IBC network
*/ */
#ifdef USE_EXPERIMENT #ifdef USE_EXPERIMENT
del_user(&users, CFG.myfqdn, chat_users[i].realname); del_user(&users, CFG.myfqdn, chat_users[i].nick);
sprintf(buf, "QUIT %s@%s Leaving chat", chat_users[i].nick, CFG.myfqdn); sprintf(buf, "QUIT %s@%s Leaving chat", chat_users[i].nick, CFG.myfqdn);
send_all(buf); send_all(buf);
#endif #endif

View File

@ -86,6 +86,8 @@ void check_servers(void);
void command_pass(char *, char *); void command_pass(char *, char *);
void command_server(char *, char *); void command_server(char *, char *);
void command_squit(char *, char *); void command_squit(char *, char *);
void command_user(char *, char *);
void command_quit(char *, char *);
void receiver(struct servent *); void receiver(struct servent *);
@ -245,13 +247,13 @@ void add_user(usr_list **fap, char *server, char *nick, char *realname)
/* /*
* Delete one user. * Delete one user.
*/ */
void del_user(usr_list **fap, char *server, char *realname) void del_user(usr_list **fap, char *server, char *nick)
{ {
usr_list *ta, *tan; usr_list **tmp, *tmpa;
srv_list *sl; srv_list *sl;
int rc; int rc;
Syslog('r', "deluser %s %s", server, realname); Syslog('r', "deluser %s %s", server, nick);
if (*fap == NULL) if (*fap == NULL)
return; return;
@ -259,15 +261,23 @@ void del_user(usr_list **fap, char *server, char *realname)
if ((rc = pthread_mutex_lock(&b_mutex))) if ((rc = pthread_mutex_lock(&b_mutex)))
Syslog('!', "del_user() mutex_lock failed rc=%d", rc); Syslog('!', "del_user() mutex_lock failed rc=%d", rc);
for (ta = *fap; ta; ta = ta->next) { tmp = fap;
while ((tan = ta->next) && (strcmp(tan->server, server) == 0) && (strcmp(tan->realname, realname) == 0)) { while (*tmp) {
ta->next = tan->next; // Syslog('r', "%s %s", (*tmp)->server, (*tmp)->realname);
free(tan); if ((strcmp((*tmp)->server, server) == 0) && (strcmp((*tmp)->nick, nick) == 0)) {
// Syslog('r', "remove");
tmpa = *tmp;
*tmp=(*tmp)->next;
free(tmpa);
usrchg = TRUE; usrchg = TRUE;
} else {
tmp = &((*tmp)->next);
} }
ta->next = tan;
} }
// if (!usrchg)
// Syslog('r', "Could not delete user");
for (sl = servers; sl; sl = sl->next) { for (sl = servers; sl; sl = sl->next) {
if ((strcmp(sl->server, server) == 0) && sl->users) { if ((strcmp(sl->server, server) == 0) && sl->users) {
sl->users--; sl->users--;
@ -841,6 +851,63 @@ void command_squit(char *hostname, char *parameters)
void command_user(char *hostname, char *parameters)
{
ncs_list *tnsl;
char *nick, *server, *realname;
for (tnsl = ncsl; tnsl; tnsl = tnsl->next) {
if (strcmp(tnsl->server, hostname) == 0) {
break;
}
}
nick = strtok(parameters, "@\0");
server = strtok(NULL, " \0");
realname = strtok(NULL, "\0");
if (realname == NULL) {
sprintf(csbuf, "461 USER: Not enough parameters\r\n");
send_msg(tnsl->socket, tnsl->servaddr_in, tnsl->server, csbuf);
return;
}
add_user(&users, server, nick, realname);
}
void command_quit(char *hostname, char *parameters)
{
ncs_list *tnsl;
char temp[512], *nick, *server, *message;
for (tnsl = ncsl; tnsl; tnsl = tnsl->next) {
if (strcmp(tnsl->server, hostname) == 0) {
break;
}
}
nick = strtok(parameters, "@\0");
server = strtok(NULL, " \0");
message = strtok(NULL, "\0");
if (server == NULL) {
sprintf(csbuf, "461 QUIT: Not enough parameters\r\n");
send_msg(tnsl->socket, tnsl->servaddr_in, tnsl->server, csbuf);
return;
}
if (message)
sprintf(temp, "MSG ** %s is leaving: %s", nick, message);
else
sprintf(temp, "MSG ** %s is leaving: Quit", nick);
send_all(temp);
del_user(&users, server, nick);
}
void receiver(struct servent *se) void receiver(struct servent *se)
{ {
struct pollfd pfd; struct pollfd pfd;
@ -940,6 +1007,20 @@ void receiver(struct servent *se)
} else { } else {
command_squit(hostname, parameters); command_squit(hostname, parameters);
} }
} else if (! strcmp(command, (char *)"USER")) {
if (parameters == NULL) {
sprintf(csbuf, "461 %s: Not enough parameters\r\n", command);
send_msg(tnsl->socket, tnsl->servaddr_in, tnsl->server, csbuf);
} else {
command_user(hostname, parameters);
}
} else if (! strcmp(command, (char *)"QUIT")) {
if (parameters == NULL) {
sprintf(csbuf, "461 %s: Not enough parameters\r\n", command);
send_msg(tnsl->socket, tnsl->servaddr_in, tnsl->server, csbuf);
} else {
command_quit(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) {