diff --git a/ChangeLog b/ChangeLog index 065444d..b899014 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-03-08 Arnaud Cornet + + * samples/bip.conf: change default nick in sample file + * src/irc.c: fix nick desync between client and server + 2006-03-08 Arnaud Cornet * bip: release 0.5.2 diff --git a/TODO b/TODO index 522b35c..7ab843e 100644 --- a/TODO +++ b/TODO @@ -8,3 +8,6 @@ - use gnutls - MODE #channel and WHO #channel on join +11:23 < KiBi> Un /away truc chose automatique quand plus aucun client n'est + attaché. +- in english: automatic command when no more client is connected diff --git a/samples/bip.conf b/samples/bip.conf index e14b4c5..d8ba9db 100644 --- a/samples/bip.conf +++ b/samples/bip.conf @@ -72,7 +72,7 @@ network { user { # The name in bip of the user # This is used by bip only - name = "nohar"; + name = "bip4ever"; # this user's password (md5(md5("tata"))) with seed - generated by bipmkpw password = "3880f2b39b3b9cb507b052b695d2680859bfc327"; @@ -94,12 +94,12 @@ user { # In "ca" mode, it's a directory of a standard openssl store; you must # put PEM objects (certificates, CRLs...) with .pem extension and run # `c_rehash .' in it - ssl_check_store = "/home/nohar/.bip/trustedcerts.txt"; + ssl_check_store = "/home/bip4ever/.bip/trustedcerts.txt"; # These will be the default for each connections - default_nick = "nohar"; - default_user = "nohar"; - default_realname = "nohar"; + default_nick = "bip4ever"; + default_user = "bip4ever"; + default_realname = "bip4ever"; # A user can have mutiple connections to irc networks. # define a connection: diff --git a/src/connection.c b/src/connection.c index 4e2c777..eadee8b 100644 --- a/src/connection.c +++ b/src/connection.c @@ -568,7 +568,7 @@ static int check_event_read(fd_set *fds, connection_t *cn) if (!FD_ISSET(cn->handle, fds)) return 0; - mylog(LOG_DEBUGVERB, "Read positif sur fd %d (state %d)", cn->handle, + mylog(LOG_DEBUGVERB, "Read positif on fd %d (state %d)", cn->handle, cn->connected); /* notify caller to make it check for a new client */ @@ -587,14 +587,14 @@ static int check_event_read(fd_set *fds, connection_t *cn) cn->handle); return 1; } - + if (!cn->incoming_lines) cn->incoming_lines = list_new(NULL); data_find_lines(cn); if (list_is_empty(cn->incoming_lines)) return 0; - - mylog(LOG_DEBUGVERB, "newlines sur fd %d (state %d)", cn->handle, + + mylog(LOG_DEBUGVERB, "newlines on fd %d (state %d)", cn->handle, cn->connected); return 1; } @@ -617,7 +617,7 @@ static int check_event_write(fd_set *fds, connection_t *cn, int *nc) return connection_timedout(cn); } - mylog(LOG_DEBUGVERB, "Write positif sur fd %d (state %d)", + mylog(LOG_DEBUGVERB, "Write positif on fd %d (state %d)", cn->handle, cn->connected); if (cn_is_new(cn)) { @@ -771,7 +771,7 @@ list_t *wait_event(list_t *cn_list, int *msec, int *nc) */ if (cn_is_connected(cn)) { FD_SET(cn->handle, &fds_read); - mylog(LOG_DEBUGVERB, "Test read sur fd %d %d:%d", + mylog(LOG_DEBUGVERB, "Test read on fd %d %d:%d", cn->handle, cn->connected, cn_is_connected(cn)); } @@ -782,7 +782,7 @@ list_t *wait_event(list_t *cn_list, int *msec, int *nc) if (!cn_is_connected(cn) || cn_want_write(cn)) { FD_SET(cn->handle, &fds_write); - mylog(LOG_DEBUGVERB, "Test write sur fd %d %d:%d", + mylog(LOG_DEBUGVERB, "Test write on fd %d %d:%d", cn->handle, cn->connected, cn_is_connected(cn)); } diff --git a/src/irc.c b/src/irc.c index eb42600..57bdf87 100644 --- a/src/irc.c +++ b/src/irc.c @@ -100,6 +100,7 @@ char *nick_from_ircmask(char *mask) char *nick = mask; char *ret; size_t len; + while (*nick && *nick != '!') nick++; if (!*nick) @@ -190,7 +191,7 @@ static int irc_001(struct link_server *server, struct line *line) if (LINK(server)->s_state == IRCS_WAS_CONNECTED) LINK(server)->s_state = IRCS_RECONNECTING; - else + else LINK(server)->s_state = IRCS_CONNECTING; if (line->elemc != 3) @@ -296,10 +297,23 @@ static void irc_server_join(struct link_server *s) static void irc_server_connected(struct link_server *server) { + int i; + char *initmask; LINK(server)->s_state = IRCS_CONNECTED; irc_server_join(server); log_connected(LINK(server)->log); + /* Tell already connected clients what the nick is */ + initmask = make_irc_mask(server->nick, server->irc_mask); + + /* we change nick on client */ + for (i = 0; i < LINK(server)->l_clientc; i++) { + struct link_client *ic = LINK(server)->l_clientv[i]; + WRITE_LINE1(CONN(ic), initmask, "NICK", server->nick); + } + free(initmask); + + /* basic helper for nickserv and co */ if (LINK(server)->on_connect_send) { ssize_t len = strlen(LINK(server)->on_connect_send) + 2; char *str = malloc(len + 1); @@ -744,12 +758,10 @@ static int irc_cli_startup(struct link_client *ic, struct line *line, if (!LINK(ic)) mylog(LOG_ERROR, "Invalid credentials (user:%s connection:%s)", user, connname); - free(user); free(connname); free(pass); - free(ic->init_pass); ic->init_pass = NULL; init_nick = ic->init_nick; @@ -1075,7 +1087,7 @@ static int irc_dispatch_trust_client(struct link_client *ic, struct line *line) if (strcmp(line->elemv[0], "BIP") == 0 && strcmp(line->elemv[1], "TRUST") == 0) r = adm_trust(ic, line); - + return r; } #endif @@ -1230,9 +1242,11 @@ int irc_dispatch(struct link_any *l, struct line *line, list_t *linkl) static int origin_is_me(struct line *l, struct link_server *server) { + char *nick; + if (!l->origin) return 0; - char *nick = nick_from_ircmask(l->origin); + nick = nick_from_ircmask(l->origin); if (strcmp(nick, server->nick) == 0) { free(nick); return 1; @@ -1266,7 +1280,8 @@ static int irc_join(struct link_server *server, struct line *line) * JOIN */ if (!channel) return ERR_PROTOCOL; - + if (!line->origin) + return ERR_PROTOCOL; s_nick = nick_from_ircmask(line->origin); nick = calloc(sizeof(struct nick), 1); @@ -1301,7 +1316,7 @@ static int irc_333(struct link_server *server, struct line *line) struct channel *channel; if (line->elemc != 5) return ERR_PROTOCOL; - + channel = hash_get(&server->channels, line->elemv[2]); /* we can get topic info reply for chans we're not on */ if (!channel) @@ -1457,6 +1472,8 @@ static int irc_part(struct link_server *server, struct line *line) return OK_COPY; } + if (!line->origin) + return ERR_PROTOCOL; s_nick = nick_from_ircmask(line->origin); nick = hash_get(&channel->nicks, s_nick); if (!nick) { @@ -1641,7 +1658,7 @@ static int irc_topic(struct link_server *server, struct line *line) if (line->elemc != 3) return ERR_PROTOCOL; - + channel = hash_get(&server->channels, line->elemv[1]); /* we can't get topic message for chans we're not on */ if (!channel) @@ -1696,7 +1713,7 @@ static int irc_kick(struct link_server *server, struct line *line) channel_free(channel); return OK_COPY; } - + hash_remove(&channel->nicks, nick->name); nick_free(nick); log_kick(LINK(server)->log, line->origin, line->elemv[1], @@ -1736,6 +1753,9 @@ static int irc_nick(struct link_server *server, struct line *line) if (line->elemc != 2) return ERR_PROTOCOL; + if (!line->origin) + return ERR_PROTOCOL; + s_nick = nick_from_ircmask(line->origin); if (strcmp(s_nick, server->nick) == 0) { @@ -1786,7 +1806,10 @@ static int irc_generic_quit(struct link_server *server, struct line *line) if (line->elemc != 2 && line->elemc != 1) return ERR_PROTOCOL; + if (!line->origin) + return ERR_PROTOCOL; s_nick = nick_from_ircmask(line->origin); + for (hash_it_init(&server->channels, &hi); hash_it_item(&hi); hash_it_next(&hi)) { channel = hash_it_item(&hi); @@ -1795,7 +1818,7 @@ static int irc_generic_quit(struct link_server *server, struct line *line) continue; hash_remove(&channel->nicks, s_nick); nick_free(nick); - + log_quit(LINK(server)->log, line->origin, channel->name, line->elemc == 2 ? line->elemv[1] : NULL); }