]>
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 static struct handler
*hl
, *hl2
;
18 static int handle_countrytotals(struct rline
*li
, int argc
, char **argv
) {
19 for(struct country
*c
= geoip_next(NULL
); c
; c
= geoip_next(c
))
20 if(ri_append(li
, "%s:%d", geoip_code(c
), geoip_total(c
)) == BF_OVER
)
21 return ri_error(li
, BF_OVER
, "Buffer overflow.");
26 static int handle_countrywhois(struct rline
*li
, int argc
, char **argv
) {
27 nick
*np
= getnickbynick(argv
[0]);
30 return ri_error(li
, ERR_TARGET_NOT_FOUND
, "User not online");
32 struct country
*c
= geoip_lookup_nick(np
);
34 return ri_error(li
, ERR_UNKNOWN_ERROR
, "Country lookup for user failed");
36 ri_append(li
, "%s", geoip_code(c
));
37 ri_append(li
, "%s", geoip_name(c
));
44 Error("nterfacer_country", ERR_ERROR
, "Unable to register country as nterfacer_control isn't loaded!");
48 hl
= register_handler(n_node
, "countrytotals", 0, handle_countrytotals
);
49 hl2
= register_handler(n_node
, "countrywhois", 1, handle_countrywhois
);
54 deregister_handler(hl2
);
56 deregister_handler(hl
);