]>
jfr.im git - irc/quakenet/newserv.git/blob - nterface/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"
11 #include "nterfacer_control.h"
13 int country_nickext
= -1;
15 struct handler
*hl
= NULL
, *hl2
= NULL
;
17 int handle_countrytotals(struct rline
*li
, int argc
, char **argv
);
18 int handle_countrywhois(struct rline
*li
, int argc
, char **argv
);
22 Error("nterfacer_country", ERR_ERROR
, "Unable to register country as nterfacer_control isn't loaded!");
26 country_nickext
= findnickext("geoip");
27 if(country_nickext
== -1)
28 return; /* PPA: registerchanext produces an error, however the module should stop loading */
30 hl
= register_handler(n_node
, "countrytotals", 0, handle_countrytotals
);
31 hl2
= register_handler(n_node
, "countrywhois", 1, handle_countrywhois
);
35 if(country_nickext
== -1)
39 deregister_handler(hl2
);
41 deregister_handler(hl
);
44 int handle_countrytotals(struct rline
*li
, int argc
, char **argv
) {
46 for(i
=COUNTRY_MIN
;i
<=COUNTRY_MAX
;i
++)
47 if(ri_append(li
, "%d", geoip_totals
[i
]) == BF_OVER
)
48 return ri_error(li
, BF_OVER
, "Buffer overflow.");
53 int handle_countrywhois(struct rline
*li
, int argc
, char **argv
) {
55 char *longcountry
, *shortcountry
, *shortcountry3
;
56 nick
*np
= getnickbynick(argv
[0]);
59 return ri_error(li
, ERR_TARGET_NOT_FOUND
, "User not online");
61 result
= (int)((long)np
->exts
[country_nickext
]);
62 if((result
< COUNTRY_MIN
) || (result
> COUNTRY_MAX
))
65 if(!GeoIP_country_info_by_id(result
, &shortcountry
, &shortcountry3
, &longcountry
))
68 ri_append(li
, "%d", result
);
71 ri_append(li
, "%s", "!!");
72 ri_append(li
, "%s", "!!");
73 ri_append(li
, "%s", "Error");
75 ri_append(li
, "%s", shortcountry
);
76 ri_append(li
, "%s", shortcountry3
);
77 ri_append(li
, "%s", longcountry
);