diff --git a/src/irc.c b/src/irc.c index b72b496..18789cd 100644 --- a/src/irc.c +++ b/src/irc.c @@ -53,6 +53,7 @@ void write_user_list(connection_t *c, char *dest); static void irc_copy_cli(struct link_client *src, struct link_client *dest, struct line *line); +static void irc_cli_make_join(struct link_client *ic); #define LAGOUT_TIME (360) #define LAGCHECK_TIME (90) @@ -297,6 +298,7 @@ static void irc_server_join(struct link_server *s) static void irc_server_connected(struct link_server *server) { + int i; LINK(server)->s_state = IRCS_CONNECTED; irc_server_join(server); log_connected(LINK(server)->log); @@ -308,6 +310,9 @@ static void irc_server_connected(struct link_server *server) write_line(CONN(server), str); free(str); } + + for (i = 0; i < LINK(server)->l_clientc; i++) + irc_cli_make_join(LINK(server)->l_clientv[i]); } /* @@ -584,6 +589,40 @@ static char *get_str_elem(char *str, int num) return NULL; } +static void irc_cli_make_join(struct link_client *ic) +{ + if (LINK(ic)->l_server) { + /* join channels, step one, those in conf, in order */ + list_iterator_t li; + for (list_it_init(&LINK(ic)->chan_infos_order, &li); + list_it_item(&li); list_it_next(&li)) { + struct chan_info *ci = (struct chan_info *) + list_it_item(&li); + struct channel *chan; + if ((chan = hash_get(&LINK(ic)->l_server->channels, + ci->name))) + irc_send_join(ic, chan); + } + + /* step two, those not in conf */ + hash_iterator_t hi; + for (hash_it_init(&LINK(ic)->l_server->channels, &hi); + hash_it_item(&hi); hash_it_next(&hi)) { + struct channel *chan = (struct channel *) + hash_it_item(&hi); + if (!hash_get(&LINK(ic)->chan_infos, chan->name)) + irc_send_join(ic, chan); + } + + /* backlog privates */ + char *str; + while ((str = log_backread(LINK(ic)->log, S_PRIVATES))) { + write_line(CONN(ic), str); + free(str); + } + } +} + static int irc_cli_startup(struct link_client *ic, struct line *line, list_t *linkl) { @@ -688,36 +727,7 @@ static int irc_cli_startup(struct link_client *ic, struct line *line, return OK_FORGET; } - if (LINK(ic)->l_server) { - /* join channels, step one, those in conf, in order */ - list_iterator_t li; - for (list_it_init(&LINK(ic)->chan_infos_order, &li); - list_it_item(&li); list_it_next(&li)) { - struct chan_info *ci = (struct chan_info *) - list_it_item(&li); - struct channel *chan; - if ((chan = hash_get(&LINK(ic)->l_server->channels, - ci->name))) - irc_send_join(ic, chan); - } - - /* step two, those not in conf */ - hash_iterator_t hi; - for (hash_it_init(&LINK(ic)->l_server->channels, &hi); - hash_it_item(&hi); hash_it_next(&hi)) { - struct channel *chan = (struct channel *) - hash_it_item(&hi); - if (!hash_get(&LINK(ic)->chan_infos, chan->name)) - irc_send_join(ic, chan); - } - - /* backlog privates */ - char *str; - while ((str = log_backread(LINK(ic)->log, S_PRIVATES))) { - write_line(CONN(ic), str); - free(str); - } - } + irc_cli_make_join(ic); log_client_connected(LINK(ic)->log); free(init_nick);