Who patch fix
This commit is contained in:
parent
4055764e81
commit
47d82fdd2a
@ -1,3 +1,7 @@
|
|||||||
|
2006-02-21 Arnaud Cornet <arnaud.cornet@gmail.com>
|
||||||
|
|
||||||
|
* who: Re-organized and fixed fatal.
|
||||||
|
|
||||||
2006-02-05 Arnaud Cornet <arnaud.cornet@gmail.com>
|
2006-02-05 Arnaud Cornet <arnaud.cornet@gmail.com>
|
||||||
* who: merged patch from lappz (Peter Zijlstra) to avoid polluting who
|
* who: merged patch from lappz (Peter Zijlstra) to avoid polluting who
|
||||||
replies to all clients when a client does /who.
|
replies to all clients when a client does /who.
|
||||||
|
39
src/irc.c
39
src/irc.c
@ -363,14 +363,16 @@ static int parse_352(struct link_server *server, struct line *line)
|
|||||||
return OK_COPY_WHO;
|
return OK_COPY_WHO;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int irc_315(struct link_server *server, struct line *line)
|
static int irc_315(struct link_server *server, struct line *l)
|
||||||
{
|
{
|
||||||
if (server->who_client) {
|
struct link *link = LINK(server);
|
||||||
--server->who_client->who_count;
|
if (link->who_client) {
|
||||||
|
--link->who_client->who_count;
|
||||||
|
|
||||||
if (server->who_client->who_count < 0)
|
if (link->who_client->who_count < 0)
|
||||||
fatal("negative who count");
|
fatal("negative who count");
|
||||||
}
|
}
|
||||||
|
l = NULL; /* keep gcc happy */
|
||||||
|
|
||||||
return OK_COPY_WHO;
|
return OK_COPY_WHO;
|
||||||
}
|
}
|
||||||
@ -499,21 +501,19 @@ int irc_dispatch_server(struct link_server *server, struct line *line)
|
|||||||
free(s);
|
free(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ret == OK_COPY_WHO) {
|
if (ret == OK_COPY_WHO && LINK(server)->who_client) {
|
||||||
char *s;
|
char *s;
|
||||||
if (!server->who_client)
|
|
||||||
fatal("no who client");
|
|
||||||
|
|
||||||
s = irc_line_to_string(line);
|
s = irc_line_to_string(line);
|
||||||
write_line(CONN(server->who_client), s);
|
write_line(CONN(LINK(server)->who_client), s);
|
||||||
free(s);
|
free(s);
|
||||||
|
|
||||||
if (!server->who_client->who_count) {
|
if (LINK(server)->who_client->who_count == 0) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < LINK(server)->l_clientc; i++) {
|
for (i = 0; i < LINK(server)->l_clientc; i++) {
|
||||||
struct link_client *ic =
|
struct link_client *ic =
|
||||||
LINK(server)->l_clientv[i];
|
LINK(server)->l_clientv[i];
|
||||||
if (ic == server->who_client) {
|
if (ic == LINK(server)->who_client) {
|
||||||
if (!list_is_empty(&ic->who_queue))
|
if (!list_is_empty(&ic->who_queue))
|
||||||
fatal("who active and queued?");
|
fatal("who active and queued?");
|
||||||
continue;
|
continue;
|
||||||
@ -526,12 +526,12 @@ int irc_dispatch_server(struct link_server *server, struct line *line)
|
|||||||
write_line(CONN(server), l);
|
write_line(CONN(server), l);
|
||||||
free(l);
|
free(l);
|
||||||
}
|
}
|
||||||
server->who_client = ic;
|
LINK(server)->who_client = ic;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i == LINK(server)->l_clientc)
|
if (i == LINK(server)->l_clientc)
|
||||||
server->who_client = NULL;
|
LINK(server)->who_client = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@ -606,11 +606,16 @@ void unbind_from_link(struct link_client *ic)
|
|||||||
{
|
{
|
||||||
struct link *l = LINK(ic);
|
struct link *l = LINK(ic);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < l->l_clientc; i++)
|
for (i = 0; i < l->l_clientc; i++)
|
||||||
if (l->l_clientv[i] == ic)
|
if (l->l_clientv[i] == ic)
|
||||||
break;
|
break;
|
||||||
if (i == l->l_clientc)
|
if (i == l->l_clientc)
|
||||||
fatal("unbind_from_link");
|
fatal("unbind_from_link");
|
||||||
|
|
||||||
|
if (l->who_client == ic)
|
||||||
|
l->who_client = NULL;
|
||||||
|
|
||||||
for (i = i + 1; i < l->l_clientc; i++)
|
for (i = i + 1; i < l->l_clientc; i++)
|
||||||
l->l_clientv[i - 1] = l->l_clientv[i];
|
l->l_clientv[i - 1] = l->l_clientv[i];
|
||||||
|
|
||||||
@ -901,15 +906,15 @@ static int irc_cli_notice(struct link_client *ic, struct line *line)
|
|||||||
|
|
||||||
static int irc_cli_who(struct link_client *ic, struct line *line)
|
static int irc_cli_who(struct link_client *ic, struct line *line)
|
||||||
{
|
{
|
||||||
struct link_server *s = LINK(ic)->l_server;
|
struct link *l = LINK(ic);
|
||||||
|
|
||||||
if (s->who_client && s->who_client != ic) {
|
if (l->who_client && l->who_client != ic) {
|
||||||
list_add_first(&ic->who_queue, irc_line_to_string(line));
|
list_add_first(&ic->who_queue, irc_line_to_string(line));
|
||||||
return OK_FORGET;
|
return OK_FORGET;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!s->who_client)
|
if (!l->who_client)
|
||||||
s->who_client = ic;
|
l->who_client = ic;
|
||||||
|
|
||||||
++ic->who_count;
|
++ic->who_count;
|
||||||
|
|
||||||
@ -1958,8 +1963,6 @@ struct link_server *irc_server_new(struct link *link, connection_t *conn)
|
|||||||
CONN(s) = conn;
|
CONN(s) = conn;
|
||||||
|
|
||||||
irc_lag_init(s);
|
irc_lag_init(s);
|
||||||
|
|
||||||
s->who_client = NULL;
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +70,10 @@ struct link {
|
|||||||
int l_clientc;
|
int l_clientc;
|
||||||
struct link_client **l_clientv;
|
struct link_client **l_clientv;
|
||||||
|
|
||||||
|
/* we honnor the /who from clients one client at a time, this is the
|
||||||
|
* client that is /who-ing */
|
||||||
|
struct link_client *who_client;
|
||||||
|
|
||||||
struct log *log;
|
struct log *log;
|
||||||
|
|
||||||
/* server related live stuff */
|
/* server related live stuff */
|
||||||
@ -188,8 +192,6 @@ struct link_server {
|
|||||||
int lag;
|
int lag;
|
||||||
int laginit_ts;
|
int laginit_ts;
|
||||||
int lagtest_timeout;
|
int lagtest_timeout;
|
||||||
|
|
||||||
struct link_client *who_client;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct link_client *irc_client_new(void);
|
struct link_client *irc_client_new(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user