X-Git-Url: https://jfr.im/git/irc/evilnet/x3.git/blobdiff_plain/7a27854095fb80ce76e2ef5a59e87f42fbbe45fe..5a2c7cf6485440d208e5f0ec319e22b6fa317a41:/src/hash.c diff --git a/src/hash.c b/src/hash.c index defbf84..51c355c 100644 --- a/src/hash.c +++ b/src/hash.c @@ -5,7 +5,7 @@ * * x3 is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -50,22 +50,49 @@ void init_structs(void) reg_exit_func(hash_cleanup); } +int userList_contains(struct userList *list, struct userNode *user) +{ + unsigned int ii; + + for (ii = 0; ii < list->used; ++ii) { + if (user == list->list[ii]) { + return 1; + } + } + return 0; +} + server_link_func_t *slf_list; +void **slf_list_extra; unsigned int slf_size = 0, slf_used = 0; void -reg_server_link_func(server_link_func_t handler) +reg_server_link_func(server_link_func_t handler, void *extra) { if (slf_used == slf_size) { - if (slf_size) { - slf_size <<= 1; - slf_list = realloc(slf_list, slf_size*sizeof(server_link_func_t)); - } else { - slf_size = 8; - slf_list = malloc(slf_size*sizeof(server_link_func_t)); - } + if (slf_size) { + slf_size <<= 1; + slf_list = realloc(slf_list, slf_size*sizeof(server_link_func_t)); + slf_list_extra = realloc(slf_list_extra, slf_size*sizeof(void*)); + } else { + slf_size = 8; + slf_list = malloc(slf_size*sizeof(server_link_func_t)); + slf_list_extra = malloc(slf_size*sizeof(void*)); + } + } + slf_list[slf_used] = handler; + slf_list_extra[slf_used++] = extra; +} + +void +call_server_link_funcs(struct server *server) +{ + unsigned int i; + + for (i = 0; i < slf_used; ++i) + { + slf_list[i](server, slf_list_extra[i]); } - slf_list[slf_used++] = handler; } struct server* @@ -75,69 +102,104 @@ GetServerH(const char *name) } new_user_func_t *nuf_list; +void **nuf_list_extra; unsigned int nuf_size = 0, nuf_used = 0; void -reg_new_user_func(new_user_func_t handler) +reg_new_user_func(new_user_func_t handler, void *extra) { if (nuf_used == nuf_size) { - if (nuf_size) { - nuf_size <<= 1; - nuf_list = realloc(nuf_list, nuf_size*sizeof(new_user_func_t)); - } else { - nuf_size = 8; - nuf_list = malloc(nuf_size*sizeof(new_user_func_t)); - } + if (nuf_size) { + nuf_size <<= 1; + nuf_list = realloc(nuf_list, nuf_size*sizeof(new_user_func_t)); + nuf_list_extra = realloc(nuf_list_extra, nuf_size*sizeof(void*)); + } else { + nuf_size = 8; + nuf_list = malloc(nuf_size*sizeof(new_user_func_t)); + nuf_list_extra = malloc(nuf_size*sizeof(void*)); + } + } + nuf_list[nuf_used] = handler; + nuf_list_extra[nuf_used++] = extra; +} + +void +call_new_user_funcs(struct userNode* user) +{ + unsigned int i; + + for (i = 0; i < nuf_used && !(user->dead); ++i) + { + nuf_list[i](user, nuf_list_extra[i]); } - nuf_list[nuf_used++] = handler; } static nick_change_func_t *ncf2_list; +static void **ncf2_list_extra; static unsigned int ncf2_size = 0, ncf2_used = 0; void -reg_nick_change_func(nick_change_func_t handler) +reg_nick_change_func(nick_change_func_t handler, void *extra) { if (ncf2_used == ncf2_size) { if (ncf2_size) { ncf2_size <<= 1; ncf2_list = realloc(ncf2_list, ncf2_size*sizeof(nick_change_func_t)); + ncf2_list_extra = realloc(ncf2_list_extra, ncf2_size*sizeof(void*)); } else { ncf2_size = 8; ncf2_list = malloc(ncf2_size*sizeof(nick_change_func_t)); + ncf2_list_extra = malloc(ncf2_size*sizeof(void*)); } } - ncf2_list[ncf2_used++] = handler; + ncf2_list[ncf2_used] = handler; + ncf2_list[ncf2_used++] = extra; } del_user_func_t *duf_list; +void **duf_list_extra; unsigned int duf_size = 0, duf_used = 0; void -reg_del_user_func(del_user_func_t handler) +reg_del_user_func(del_user_func_t handler, void *extra) { if (duf_used == duf_size) { - if (duf_size) { - duf_size <<= 1; - duf_list = realloc(duf_list, duf_size*sizeof(del_user_func_t)); - } else { - duf_size = 8; - duf_list = malloc(duf_size*sizeof(del_user_func_t)); - } + if (duf_size) { + duf_size <<= 1; + duf_list = realloc(duf_list, duf_size*sizeof(del_user_func_t)); + duf_list_extra = realloc(duf_list_extra, duf_size*sizeof(void*)); + } else { + duf_size = 8; + duf_list = malloc(duf_size*sizeof(del_user_func_t)); + duf_list_extra = malloc(duf_size*sizeof(void*)); + } + } + duf_list[duf_used] = handler; + duf_list_extra[duf_used++] = extra; +} + +void +call_del_user_funcs(struct userNode *user, struct userNode *killer, const char *why) +{ + unsigned int i; + + for (i = 0; i < duf_used; ++i) + { + duf_list[i](user, killer, why, duf_list_extra[i]); } - duf_list[duf_used++] = handler; } void -unreg_del_user_func(del_user_func_t handler) +unreg_del_user_func(del_user_func_t handler, void *extra) { unsigned int i; for (i=0; idead; nn++) + ncf2_list[nn](user, old_nick, ncf2_list_extra[nn]); user->timestamp = now; if (IsLocal(user) && !no_announce) irc_nick(user, old_nick); free(old_nick); } +void +SVSNickChange(struct userNode* user, const char *new_nick) +{ + char *old_nick; + unsigned int nn; + + /* don't do anything if there's no change */ + old_nick = user->nick; + if (!strncmp(new_nick, old_nick, NICKLEN)) + return; + + /* remove old entry from clients dictionary */ + dict_remove(clients, old_nick); +#if !defined(WITH_PROTOCOL_P10) + /* Remove from uplink's clients dict */ + dict_remove(user->uplink->users, old_nick); +#endif + /* and reinsert */ + user->nick = strdup(new_nick); + dict_insert(clients, user->nick, user); +#if !defined(WITH_PROTOCOL_P10) + dict_insert(user->uplink->users, user->nick, user); +#endif + + /* Make callbacks for nick changes. Do this with new nick in + * place because that is slightly more useful. + */ + for (nn=0; (nndead; nn++) + ncf2_list[nn](user, old_nick, ncf2_list_extra[nn]); + user->timestamp = now; + + free(old_nick); +} + struct userNode * GetUserH(const char *nick) { @@ -219,7 +315,8 @@ call_account_func(struct userNode *user, const char *stamp) { /* We've received an account stamp for a user; notify NickServ, which registers the sole account_func - right now. + right now. TODO: This is a bug. This needs to register + a proper list not just kill with each call!! -Rubin P10 Protocol violation if (user->modes & FLAGS_STAMPED) here. */ @@ -324,21 +421,25 @@ reg_new_channel_func(new_channel_func_t handler) } static join_func_t *jf_list; +static void **jf_list_extra; static unsigned int jf_size = 0, jf_used = 0; void -reg_join_func(join_func_t handler) +reg_join_func(join_func_t handler, void *extra) { if (jf_used == jf_size) { if (jf_size) { jf_size <<= 1; jf_list = realloc(jf_list, jf_size*sizeof(join_func_t)); + jf_list_extra = realloc(jf_list_extra, jf_size*sizeof(void*)); } else { jf_size = 8; jf_list = malloc(jf_size*sizeof(join_func_t)); + jf_list_extra = malloc(jf_size*sizeof(void*)); } } - jf_list[jf_used++] = handler; + jf_list[jf_used] = handler; + jf_list_extra[jf_used++] = extra; } int rel_age; @@ -514,6 +615,7 @@ DelChannel(struct chanNode *channel) { unsigned int n; + verify(channel); dict_remove(channels, channel->name); if (channel->members.used || channel->locks) { @@ -522,7 +624,7 @@ DelChannel(struct chanNode *channel) /* go through all channel members and delete them from the channel */ for (n=channel->members.used; n>0; ) - DelChannelUser(channel->members.list[--n]->user, channel, false, 1); + DelChannelUser(channel->members.list[--n]->user, channel, NULL, 1); /* delete all channel bans */ for (n=channel->banlist.used; n>0; ) @@ -571,19 +673,22 @@ AddChannelUser(struct userNode *user, struct chanNode* channel) if (channel->members.used == 1 && !(channel->modes & MODE_REGISTERED) - && !(channel->modes & MODE_APASS)) + && !(channel->modes & MODE_APASS)) { mNode->modes |= MODE_CHANOP; + log_module(MAIN_LOG, LOG_DEBUG, "setting op"); + } - for (n=0; ndead; n++) { /* Callbacks return true if they kick or kill the user, * and we can continue without removing mNode. */ - if (jf_list[n](mNode)) + if (jf_list[n](mNode, jf_list_extra[n])) return NULL; } - if (IsLocal(user)) - irc_join(user, channel); - return mNode; } @@ -638,7 +743,7 @@ DelChannelUser(struct userNode* user, struct chanNode* channel, const char *reas struct modeNode* mNode; unsigned int n; - if (reason) + if (IsLocal(user) && reason) irc_part(user, channel, reason); mNode = GetUserMode(channel, user); @@ -713,7 +818,7 @@ ChannelUserKicked(struct userNode* kicker, struct userNode* victim, struct chanN unsigned int n; struct modeNode *mn; - if (!victim || !channel || IsService(victim) || !GetUserMode(channel, victim)) + if (!victim || !channel || !GetUserMode(channel, victim)) return; /* Update the kicker's idle time (kicker may be null if it was a server) */ @@ -750,21 +855,25 @@ int ChannelExemptExists(struct chanNode *channel, const char *exempt) } static topic_func_t *tf_list; +static void **tf_list_extra; static unsigned int tf_size = 0, tf_used = 0; void -reg_topic_func(topic_func_t handler) +reg_topic_func(topic_func_t handler, void *extra) { if (tf_used == tf_size) { if (tf_size) { tf_size <<= 1; tf_list = realloc(tf_list, tf_size*sizeof(topic_func_t)); + tf_list_extra = realloc(tf_list_extra, tf_size*sizeof(void*)); } else { tf_size = 8; tf_list = malloc(tf_size*sizeof(topic_func_t)); + tf_list_extra = malloc(tf_size*sizeof(void*)); } } - tf_list[tf_used++] = handler; + tf_list[tf_used] = handler; + tf_list_extra[tf_used++] = extra; } void @@ -792,7 +901,11 @@ SetChannelTopic(struct chanNode *channel, struct userNode *service, struct userN irc_topic(service, user, channel, topic); } else { for (n=0; n