| 1 |
/* |
| 2 |
* Copyright (c) 2008 William Pitcock <[email protected]> |
| 3 |
* Rights to this code are as documented in doc/LICENSE. |
| 4 |
* |
| 5 |
* Allows extension of expiry times if user will be away from IRC for |
| 6 |
* a month or two. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "atheme.h" |
| 10 |
#include "list_common.h" |
| 11 |
#include "list.h" |
| 12 |
|
| 13 |
DECLARE_MODULE_V1 |
| 14 |
( |
| 15 |
"nickserv/vacation", false, _modinit, _moddeinit, |
| 16 |
PACKAGE_STRING, |
| 17 |
VENDOR_STRING |
| 18 |
); |
| 19 |
|
| 20 |
static void ns_cmd_vacation(sourceinfo_t *si, int parc, char *parv[]) |
| 21 |
{ |
| 22 |
char tsbuf[BUFSIZE]; |
| 23 |
|
| 24 |
if (CURRTIME < (time_t)(si->smu->registered + nicksvs.expiry)) |
| 25 |
{ |
| 26 |
command_fail(si, fault_noprivs, _("You must be registered for at least \2%d\2 days in order to enable VACATION mode."), |
| 27 |
(nicksvs.expiry / 3600 / 24)); |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
snprintf(tsbuf, BUFSIZE, "%lu", (unsigned long)CURRTIME); |
| 32 |
metadata_add(si->smu, "private:vacation", tsbuf); |
| 33 |
|
| 34 |
logcommand(si, CMDLOG_SET, "VACATION"); |
| 35 |
|
| 36 |
command_success_nodata(si, _("Your account is now marked as being on vacation.\n" |
| 37 |
"Please be aware that this will be automatically removed the next time you identify to \2%s\2."), |
| 38 |
nicksvs.nick); |
| 39 |
if (nicksvs.expiry > 0) |
| 40 |
command_success_nodata(si, _("Your account will automatically expire in %d days if you do not return."), |
| 41 |
(nicksvs.expiry / 3600 / 24) * 3); |
| 42 |
} |
| 43 |
|
| 44 |
command_t ns_vacation = { "VACATION", N_("Sets an account as being on vacation."), AC_AUTHENTICATED, 1, ns_cmd_vacation, { .path = "nickserv/vacation" } }; |
| 45 |
|
| 46 |
static void user_identify_hook(user_t *u) |
| 47 |
{ |
| 48 |
if (!metadata_find(u->myuser, "private:vacation")) |
| 49 |
return; |
| 50 |
|
| 51 |
notice(nicksvs.nick, u->nick, _("Your account is no longer marked as being on vacation.")); |
| 52 |
metadata_delete(u->myuser, "private:vacation"); |
| 53 |
} |
| 54 |
|
| 55 |
static void user_expiry_hook(hook_expiry_req_t *req) |
| 56 |
{ |
| 57 |
myuser_t *mu = req->data.mu; |
| 58 |
|
| 59 |
if (!metadata_find(mu, "private:vacation")) |
| 60 |
return; |
| 61 |
|
| 62 |
if (mu->lastlogin >= CURRTIME || (unsigned int)(CURRTIME - mu->lastlogin) < nicksvs.expiry * 3) |
| 63 |
req->do_expire = 0; |
| 64 |
} |
| 65 |
|
| 66 |
static void nick_expiry_hook(hook_expiry_req_t *req) |
| 67 |
{ |
| 68 |
mynick_t *mn = req->data.mn; |
| 69 |
myuser_t *mu = mn->owner; |
| 70 |
|
| 71 |
if (!metadata_find(mu, "private:vacation")) |
| 72 |
return; |
| 73 |
|
| 74 |
if (mu->lastlogin >= CURRTIME || (unsigned int)(CURRTIME - mu->lastlogin) < nicksvs.expiry * 3) |
| 75 |
req->do_expire = 0; |
| 76 |
} |
| 77 |
|
| 78 |
static void info_hook(hook_user_req_t *hdata) |
| 79 |
{ |
| 80 |
if (metadata_find(hdata->mu, "private:vacation")) |
| 81 |
command_success_nodata(hdata->si, "%s is on vacation and has an extended expiry time", entity(hdata->mu)->name); |
| 82 |
} |
| 83 |
|
| 84 |
static bool is_vacation(const mynick_t *mn, const void *arg) { |
| 85 |
myuser_t *mu = mn->owner; |
| 86 |
|
| 87 |
return ( metadata_find(mu, "private:vacation") != NULL ); |
| 88 |
} |
| 89 |
|
| 90 |
void _modinit(module_t *m) |
| 91 |
{ |
| 92 |
service_named_bind_command("nickserv", &ns_vacation); |
| 93 |
|
| 94 |
hook_add_event("user_identify"); |
| 95 |
hook_add_user_identify(user_identify_hook); |
| 96 |
|
| 97 |
hook_add_event("user_check_expire"); |
| 98 |
hook_add_user_check_expire(user_expiry_hook); |
| 99 |
|
| 100 |
hook_add_event("nick_check_expire"); |
| 101 |
hook_add_nick_check_expire(nick_expiry_hook); |
| 102 |
|
| 103 |
hook_add_event("user_info"); |
| 104 |
hook_add_user_info(info_hook); |
| 105 |
|
| 106 |
use_nslist_main_symbols(m); |
| 107 |
|
| 108 |
static list_param_t vacation; |
| 109 |
vacation.opttype = OPT_BOOL; |
| 110 |
vacation.is_match = is_vacation; |
| 111 |
|
| 112 |
list_register("vacation", &vacation); |
| 113 |
} |
| 114 |
|
| 115 |
void _moddeinit(module_unload_intent_t intent) |
| 116 |
{ |
| 117 |
service_named_unbind_command("nickserv", &ns_vacation); |
| 118 |
|
| 119 |
hook_del_user_identify(user_identify_hook); |
| 120 |
hook_del_user_check_expire(user_expiry_hook); |
| 121 |
hook_del_nick_check_expire(nick_expiry_hook); |
| 122 |
hook_del_user_info(info_hook); |
| 123 |
|
| 124 |
list_unregister("vacation"); |
| 125 |
} |
| 126 |
|
| 127 |
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs |
| 128 |
* vim:ts=8 |
| 129 |
* vim:sw=8 |
| 130 |
* vim:noexpandtab |
| 131 |
*/ |