X-Git-Url: https://jfr.im/git/irc/evilnet/x3.git/blobdiff_plain/83ff05c356f6497be2475640d1cb2e3eb369831f..4a2a9a4e6a8fccd440da203bdfb8bba3f0b973a9:/src/hash.c diff --git a/src/hash.c b/src/hash.c index f4e0be5..ad63f3c 100644 --- a/src/hash.c +++ b/src/hash.c @@ -3,7 +3,7 @@ * * This file is part of x3. * - * srvx is free software; you can redistribute it and/or modify + * 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 * (at your option) any later version. @@ -23,6 +23,14 @@ #include "hash.h" #include "log.h" +#if defined(HAVE_LIBGEOIP)&&defined(HAVE_GEOIP_H)&&defined(HAVE_GEOIPCITY_H) +#include +#include + +GeoIP * gi = NULL; +GeoIP * cgi = NULL; +#endif + struct server *self; dict_t channels; dict_t clients; @@ -246,6 +254,55 @@ assign_fakehost(struct userNode *user, const char *host, int announce) irc_fakehost(user, host); } +void +set_geoip_info(struct userNode *user) +{ +/* 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) + GeoIPRecord * gir; + const char *geoip_data_file = NULL; + const char *geoip_city_file = NULL; + + 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)) + return; /* Admin doesnt want to use geoip functions */ + + if (geoip_data_file && !gi) + gi = GeoIP_open(geoip_data_file, GEOIP_MEMORY_CACHE | GEOIP_CHECK_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); + if (gir) { + user->country_name = strdup(gir->country_name ? gir->country_name : ""); + user->country_code = strdup(gir->country_code ? gir->country_code : ""); + user->city = strdup(gir->city ? gir->city : ""); + user->region = strdup(gir->region ? gir->region : ""); + user->postal_code = strdup(gir->postal_code ? gir->postal_code : ""); + + user->latitude = gir->latitude ? gir->latitude : 0; + user->longitude = gir->longitude ? gir->longitude : 0; + user->dma_code = gir->dma_code ? gir->dma_code : 0; + user->area_code = gir->area_code ? gir->area_code : 0; + + GeoIPRecord_delete(gir); + } + + return; + } else if (gi) { + const char *country = GeoIP_country_name_by_name(gi, user->hostname); + user->country_name = strdup(country ? country : ""); + return; + } + + return; +#endif +} + static new_channel_func_t *ncf_list; static unsigned int ncf_size = 0, ncf_used = 0; @@ -289,6 +346,8 @@ wipeout_channel(struct chanNode *cNode, time_t new_time, char **modes, unsigned unsigned int orig_limit; chan_mode_t orig_modes; char orig_key[KEYLEN+1]; + char orig_apass[KEYLEN+1]; + char orig_upass[KEYLEN+1]; unsigned int nn, argc; /* nuke old topic */ @@ -300,6 +359,8 @@ wipeout_channel(struct chanNode *cNode, time_t new_time, char **modes, unsigned orig_modes = cNode->modes; orig_limit = cNode->limit; strcpy(orig_key, cNode->key); + strcpy(orig_upass, cNode->upass); + strcpy(orig_apass, cNode->apass); cNode->modes = 0; mod_chanmode(NULL, cNode, modes, modec, 0); cNode->timestamp = new_time; @@ -329,6 +390,8 @@ wipeout_channel(struct chanNode *cNode, time_t new_time, char **modes, unsigned change->modes_set = orig_modes; change->new_limit = orig_limit; strcpy(change->new_key, orig_key); + strcpy(change->new_upass, orig_upass); + strcpy(change->new_apass, orig_apass); for (nn = argc = 0; nn < cNode->members.used; ++nn) { struct modeNode *mn = cNode->members.list[nn]; if ((mn->modes & MODE_CHANOP) && IsService(mn->user) && IsLocal(mn->user)) { @@ -366,7 +429,7 @@ AddChannel(const char *name, time_t time_, const char *modes, char *banlist, cha banList_init(&cNode->banlist); exemptList_init(&cNode->exemptlist); modeList_init(&cNode->members); - mod_chanmode(NULL, cNode, argv, nn, 0); + mod_chanmode(NULL, cNode, argv, nn, MCP_FROM_SERVER); dict_insert(channels, cNode->name, cNode); cNode->timestamp = time_; rel_age = 1; @@ -374,7 +437,7 @@ AddChannel(const char *name, time_t time_, const char *modes, char *banlist, cha wipeout_channel(cNode, time_, argv, nn); rel_age = 1; } else if (cNode->timestamp == time_) { - mod_chanmode(NULL, cNode, argv, nn, 0); + mod_chanmode(NULL, cNode, argv, nn, MCP_FROM_SERVER); rel_age = 0; } else { rel_age = -1; @@ -494,6 +557,7 @@ AddChannelUser(struct userNode *user, struct chanNode* channel) mNode->channel = channel; mNode->user = user; mNode->modes = 0; + mNode->oplevel = -1; mNode->idle_since = now; /* Add modeNode to channel and to user. @@ -504,7 +568,8 @@ AddChannelUser(struct userNode *user, struct chanNode* channel) modeList_append(&user->channels, mNode); if (channel->members.used == 1 - && !(channel->modes & MODE_REGISTERED)) + && !(channel->modes & MODE_REGISTERED) + && !(channel->modes & MODE_APASS)) mNode->modes |= MODE_CHANOP; for (n=0; nmembers.used && !channel->locks && !(channel->modes & MODE_REGISTERED)) + /* A single check for APASS only should be enough here */ + if (!deleting && !channel->members.used && !channel->locks + && !(channel->modes & MODE_REGISTERED) && !(channel->modes & MODE_APASS)) DelChannel(channel); } +static kick_func_t *kf_list; +static unsigned int kf_size = 0, kf_used = 0; + void KickChannelUser(struct userNode* target, struct chanNode* channel, struct userNode *kicker, const char *why) { + unsigned int n; + if (!target || !channel || IsService(target) || !GetUserMode(channel, target)) return; + + /* This may break things, but lets see.. -Rubin */ + for (n=0; nmembers.list); + verify(user); + verify(user->channels.list); + if (channel->members.used < user->channels.used) { + for (n=0; nmembers.used; n++) { + verify(channel->members.list[n]); + if (user == channel->members.list[n]->user) { + return(user); + } + } + } else { + for (n=0; nchannels.used; n++) { + verify(user->channels.list[n]); + if (channel == user->channels.list[n]->channel) { + return(user); + } + } + } + return NULL; +} + DEFINE_LIST(userList, struct userNode*) DEFINE_LIST(modeList, struct modeNode*) DEFINE_LIST(banList, struct banNode*)