]> jfr.im git - irc/evilnet/x3.git/blobdiff - src/hash.c
Added some bits from check_ctcp into the mark version handling
[irc/evilnet/x3.git] / src / hash.c
index ebf2d9a497e924a99d1065dcfe84d0f1f3812a2e..214d6b9c2941ec3f264f8b0160e610bf02fb826f 100644 (file)
@@ -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,
 #include "hash.h"
 #include "log.h"
 
+#if defined(HAVE_LIBGEOIP)&&defined(HAVE_GEOIP_H)&&defined(HAVE_GEOIPCITY_H)
+#include <GeoIP.h>
+#include <GeoIPCity.h>
+
+GeoIP * gi = NULL;
+GeoIP * cgi = NULL;
+#endif
+
 struct server *self;
 dict_t channels;
 dict_t clients;
@@ -246,6 +254,57 @@ assign_fakehost(struct userNode *user, const char *host, int announce)
         irc_fakehost(user, host);
 }
 
+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)
+    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))
+        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;
 
@@ -654,7 +713,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) */