X-Git-Url: https://jfr.im/git/irc/evilnet/x3.git/blobdiff_plain/21f6caee9936b429da5fcd482b4907315fcb109a..3b7fa78b1de8f9ee8718cba3da3b2db522b70620:/src/hash.c diff --git a/src/hash.c b/src/hash.c index c5e99fc..4fa4f51 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, @@ -23,11 +23,12 @@ #include "hash.h" #include "log.h" -#ifdef HAVE_GEOIP_H +#if defined(HAVE_LIBGEOIP)&&defined(HAVE_GEOIP_H)&&defined(HAVE_GEOIPCITY_H) #include -#endif -#ifdef HAVE_GEOIPCITY_H #include + +GeoIP * gi = NULL; +GeoIP * cgi = NULL; #endif struct server *self; @@ -49,6 +50,18 @@ 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; unsigned int slf_size = 0, slf_used = 0; @@ -188,7 +201,7 @@ NickChange(struct userNode* user, const char *new_nick, int no_announce) /* 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); user->timestamp = now; if (IsLocal(user) && !no_announce) @@ -196,6 +209,40 @@ NickChange(struct userNode* user, const char *new_nick, int no_announce) 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); + user->timestamp = now; + + free(old_nick); +} + struct userNode * GetUserH(const char *nick) { @@ -218,7 +265,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. */ @@ -256,10 +304,10 @@ assign_fakehost(struct userNode *user, const char *host, int announce) void set_geoip_info(struct userNode *user) { + if(IsLocal(user)) + return; /* Need the libs and the headers if this is going to compile properly */ #if defined(HAVE_LIBGEOIP)&&defined(HAVE_GEOIP_H)&&defined(HAVE_GEOIPCITY_H) - GeoIP * gi = NULL; - GeoIP * cgi = NULL; GeoIPRecord * gir; const char *geoip_data_file = NULL; const char *geoip_city_file = NULL; @@ -267,14 +315,14 @@ set_geoip_info(struct userNode *user) geoip_data_file = conf_get_data("services/opserv/geoip_data_file", RECDB_QSTRING); geoip_city_file = conf_get_data("services/opserv/geoip_city_data_file", RECDB_QSTRING); - if ((!geoip_data_file && !geoip_city_file) || IsLocal(user)) + if ((!geoip_data_file && !geoip_city_file)) return; /* Admin doesnt want to use geoip functions */ - if (geoip_data_file) - gi = GeoIP_open(geoip_data_file, GEOIP_STANDARD | GEOIP_CHECK_CACHE); + if (geoip_data_file && !gi) + gi = GeoIP_open(geoip_data_file, GEOIP_MEMORY_CACHE | GEOIP_CHECK_CACHE); - if (geoip_city_file) - cgi = GeoIP_open(geoip_city_file, GEOIP_INDEX_CACHE); + if (geoip_city_file && !cgi) + cgi = GeoIP_open(geoip_city_file, GEOIP_MEMORY_CACHE | GEOIP_CHECK_CACHE); if (cgi) { gir = GeoIP_record_by_name(cgi, user->hostname); @@ -293,12 +341,10 @@ set_geoip_info(struct userNode *user) GeoIPRecord_delete(gir); } - GeoIP_delete(cgi); return; } else if (gi) { const char *country = GeoIP_country_name_by_name(gi, user->hostname); user->country_name = strdup(country ? country : ""); - GeoIP_delete(gi); return; } @@ -515,6 +561,7 @@ DelChannel(struct chanNode *channel) { unsigned int n; + verify(channel); dict_remove(channels, channel->name); if (channel->members.used || channel->locks) { @@ -523,7 +570,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; ) @@ -572,19 +619,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"); + } + + if (IsLocal(user)) { + irc_join(user, channel); + } - 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)) return NULL; } - if (IsLocal(user)) - irc_join(user, channel); - return mNode; } @@ -639,7 +689,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); @@ -714,7 +764,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) */ @@ -793,6 +843,10 @@ SetChannelTopic(struct chanNode *channel, struct userNode *service, struct userN irc_topic(service, user, channel, topic); } else { for (n=0; n