]>
jfr.im git - irc/quakenet/newserv.git/blob - nterfacer/nterfacer_country.c
2 nterfacer newserv geoip country module
3 Copyright (C) 2004 Chris Porter.
6 #include "../nick/nick.h"
7 #include "../core/error.h"
8 #include "../geoip/geoip.h"
9 #include "../lib/version.h"
12 #include "nterfacer_control.h"
16 int country_nickext
= -1;
18 static struct handler
*hl
= NULL
, *hl2
= NULL
;
20 int handle_countrytotals(struct rline
*li
, int argc
, char **argv
);
21 int handle_countrywhois(struct rline
*li
, int argc
, char **argv
);
22 int GeoIP_country_info_by_id(int id
, char **two
, char **three
, char **full
);
26 Error("nterfacer_country", ERR_ERROR
, "Unable to register country as nterfacer_control isn't loaded!");
30 country_nickext
= findnickext("geoip");
31 if(country_nickext
== -1)
32 return; /* PPA: registerchanext produces an error, however the module should stop loading */
34 hl
= register_handler(n_node
, "countrytotals", 0, handle_countrytotals
);
35 hl2
= register_handler(n_node
, "countrywhois", 1, handle_countrywhois
);
39 if(country_nickext
== -1)
43 deregister_handler(hl2
);
45 deregister_handler(hl
);
48 int handle_countrytotals(struct rline
*li
, int argc
, char **argv
) {
50 for(i
=COUNTRY_MIN
;i
<=COUNTRY_MAX
;i
++)
51 if(ri_append(li
, "%d", geoip_totals
[i
]) == BF_OVER
)
52 return ri_error(li
, BF_OVER
, "Buffer overflow.");
57 int handle_countrywhois(struct rline
*li
, int argc
, char **argv
) {
59 char *longcountry
, *shortcountry
, *shortcountry3
;
60 nick
*np
= getnickbynick(argv
[0]);
63 return ri_error(li
, ERR_TARGET_NOT_FOUND
, "User not online");
65 result
= (int)((long)np
->exts
[country_nickext
]);
66 if((result
< COUNTRY_MIN
) || (result
> COUNTRY_MAX
))
69 if(!GeoIP_country_info_by_id(result
, &shortcountry
, &shortcountry3
, &longcountry
))
72 ri_append(li
, "%d", result
);
75 ri_append(li
, "%s", "!!");
76 ri_append(li
, "%s", "!!");
77 ri_append(li
, "%s", "Error");
79 ri_append(li
, "%s", shortcountry
);
80 ri_append(li
, "%s", shortcountry3
);
81 ri_append(li
, "%s", longcountry
);