From 4d6ca4a951af494f04357fec18caaf3eaed0b67a Mon Sep 17 00:00:00 2001 From: Michael Poole Date: Tue, 30 Mar 2004 04:40:38 +0000 Subject: [PATCH] translate interval strings; translate more NickServ messages * Translate interval strings to the user's language. * Translate cookie emails and auth failure messages based on the account's preferred language, rather than the user's preferred language (they will not be authed, so they would get lang_C). git-archimport-id: srvx@srvx.net--2004-srvx/srvx--devo--1.3--patch-39 --- src/chanserv.c | 56 ++++++++++++++++++++++----------------------- src/common.h | 12 ++++++---- src/global.c | 6 +---- src/main.c | 14 ++++++++++++ src/mod-helpserv.c | 24 +++++++++---------- src/mod-memoserv.c | 2 +- src/mod-sockcheck.c | 2 +- src/nickserv.c | 48 ++++++++++++++++++++++---------------- src/opserv.c | 23 +++++++++++-------- src/saxdb.c | 6 ++--- src/tools.c | 41 ++++++++++++++++++--------------- 11 files changed, 131 insertions(+), 103 deletions(-) diff --git a/src/chanserv.c b/src/chanserv.c index ed5a433..9fdec6c 100644 --- a/src/chanserv.c +++ b/src/chanserv.c @@ -1334,7 +1334,7 @@ expire_channels(UNUSED_ARG(void *data)) struct userData *user; char delay[INTERVALLEN], reason[INTERVALLEN + 64]; - intervalString(delay, chanserv_conf.channel_expire_delay); + intervalString(delay, chanserv_conf.channel_expire_delay, NULL); sprintf(reason, "Channel registration automatically expired after %s of disuse.", delay); for(channel = channelList; channel; channel = next) @@ -1539,7 +1539,7 @@ static CHANSERV_FUNC(cmd_noregister) { dnr = iter_data(it); if(dnr->set) - reply("CSMSG_DNR_INFO_SET", dnr->chan_name, intervalString(buf, now - dnr->set), dnr->setter, dnr->reason); + reply("CSMSG_DNR_INFO_SET", dnr->chan_name, intervalString(buf, now - dnr->set, user->handle_info), dnr->setter, dnr->reason); else reply("CSMSG_DNR_INFO", dnr->chan_name, dnr->setter, dnr->reason); matches++; @@ -1548,7 +1548,7 @@ static CHANSERV_FUNC(cmd_noregister) { dnr = iter_data(it); if(dnr->set) - reply("CSMSG_DNR_INFO_SET", dnr->chan_name, intervalString(buf, now - dnr->set), dnr->setter, dnr->reason); + reply("CSMSG_DNR_INFO_SET", dnr->chan_name, intervalString(buf, now - dnr->set, user->handle_info), dnr->setter, dnr->reason); else reply("CSMSG_DNR_INFO", dnr->chan_name, dnr->setter, dnr->reason); matches++; @@ -1557,7 +1557,7 @@ static CHANSERV_FUNC(cmd_noregister) { dnr = iter_data(it); if(dnr->set) - reply("CSMSG_DNR_INFO_SET", dnr->chan_name, intervalString(buf, now - dnr->set), dnr->setter, dnr->reason); + reply("CSMSG_DNR_INFO_SET", dnr->chan_name, intervalString(buf, now - dnr->set, user->handle_info), dnr->setter, dnr->reason); else reply("CSMSG_DNR_INFO", dnr->chan_name, dnr->setter, dnr->reason); matches++; @@ -2381,7 +2381,7 @@ cmd_trim_bans(struct userNode *user, struct chanNode *channel, unsigned long dur count++; } - intervalString(interval, duration); + intervalString(interval, duration, user->handle_info); send_message(user, chanserv, "CSMSG_TRIMMED_BANS", count, channel->name, interval); return 1; } @@ -2429,7 +2429,7 @@ cmd_trim_users(struct userNode *user, struct chanNode *channel, unsigned short m min_access = 1; max_access = UL_OWNER; } - send_message(user, chanserv, "CSMSG_TRIMMED_USERS", count, min_access, max_access, channel->name, intervalString(interval, duration)); + send_message(user, chanserv, "CSMSG_TRIMMED_USERS", count, min_access, max_access, channel->name, intervalString(interval, duration, user->handle_info)); return 1; } @@ -2826,7 +2826,7 @@ eject_user(struct userNode *user, struct chanNode *channel, unsigned int argc, c /* automated kickban */ } else if(duration) - reply("CSMSG_BAN_EXTENDED", ban, intervalString(interval, duration)); + reply("CSMSG_BAN_EXTENDED", ban, intervalString(interval, duration, user->handle_info)); else reply("CSMSG_BAN_ADDED", name, channel->name); @@ -2933,7 +2933,7 @@ eject_user(struct userNode *user, struct chanNode *channel, unsigned int argc, c else if(action & ACTION_ADD_BAN) { if(duration) - reply("CSMSG_TIMED_BAN_ADDED", name, channel->name, intervalString(interval, duration)); + reply("CSMSG_TIMED_BAN_ADDED", name, channel->name, intervalString(interval, duration, user->handle_info)); else reply("CSMSG_BAN_ADDED", name, channel->name); } @@ -3449,7 +3449,7 @@ cmd_list_users(struct userNode *user, struct chanNode *channel, unsigned int arg else if(!uData->seen) ary[2] = "Never"; else - ary[2] = intervalString(seen, now - uData->seen); + ary[2] = intervalString(seen, now - uData->seen, user->handle_info); ary[2] = strdup(ary[2]); if(IsUserSuspended(uData)) ary[3] = "Suspended"; @@ -3556,12 +3556,12 @@ static CHANSERV_FUNC(cmd_bans) if(!timed) expires = ""; else if(ban->expires) - expires = intervalString(e_buffer, ban->expires - now); + expires = intervalString(e_buffer, ban->expires - now, user->handle_info); else expires = msg_never; if(ban->triggered) - triggered = intervalString(t_buffer, now - ban->triggered); + triggered = intervalString(t_buffer, now - ban->triggered, user->handle_info); else triggered = msg_never; @@ -3795,34 +3795,34 @@ show_suspension_info(struct svccmd *cmd, struct userNode *user, struct suspended reply("CSMSG_CHANNEL_SUSPENDED_0", suspended->suspender, suspended->reason); break; case 1: /* no issue time, expires in future */ - intervalString(buf1, suspended->expires-now); + intervalString(buf1, suspended->expires-now, user->handle_info); reply("CSMSG_CHANNEL_SUSPENDED_1", suspended->suspender, buf1, suspended->reason); break; case 2: /* no issue time, expired */ - intervalString(buf1, now-suspended->expires); + intervalString(buf1, now-suspended->expires, user->handle_info); reply("CSMSG_CHANNEL_SUSPENDED_2", suspended->suspender, buf1, suspended->reason); break; case 3: /* no issue time, revoked */ - intervalString(buf1, now-suspended->revoked); + intervalString(buf1, now-suspended->revoked, user->handle_info); reply("CSMSG_CHANNEL_SUSPENDED_3", suspended->suspender, buf1, suspended->reason); break; case 4: /* issue time set, indefinite expiration */ - intervalString(buf1, now-suspended->issued); + intervalString(buf1, now-suspended->issued, user->handle_info); reply("CSMSG_CHANNEL_SUSPENDED_4", buf1, suspended->suspender, suspended->reason); break; case 5: /* issue time set, expires in future */ - intervalString(buf1, now-suspended->issued); - intervalString(buf2, suspended->expires-now); + intervalString(buf1, now-suspended->issued, user->handle_info); + intervalString(buf2, suspended->expires-now, user->handle_info); reply("CSMSG_CHANNEL_SUSPENDED_5", buf1, suspended->suspender, buf2, suspended->reason); break; case 6: /* issue time set, expired */ - intervalString(buf1, now-suspended->issued); - intervalString(buf2, now-suspended->expires); + intervalString(buf1, now-suspended->issued, user->handle_info); + intervalString(buf2, now-suspended->expires, user->handle_info); reply("CSMSG_CHANNEL_SUSPENDED_6", buf1, suspended->suspender, buf2, suspended->reason); break; case 7: /* issue time set, revoked */ - intervalString(buf1, now-suspended->issued); - intervalString(buf2, now-suspended->revoked); + intervalString(buf1, now-suspended->issued, user->handle_info); + intervalString(buf2, now-suspended->revoked, user->handle_info); reply("CSMSG_CHANNEL_SUSPENDED_7", buf1, suspended->suspender, buf2, suspended->reason); break; default: @@ -3870,8 +3870,8 @@ static CHANSERV_FUNC(cmd_info) reply("CSMSG_CHANNEL_OWNER", owner->handle->handle); reply("CSMSG_CHANNEL_USERS", cData->userCount); reply("CSMSG_CHANNEL_BANS", cData->banCount); - reply("CSMSG_CHANNEL_VISITED", intervalString(buffer, now - cData->visited)); - reply("CSMSG_CHANNEL_REGISTERED", intervalString(buffer, now - cData->registered)); + reply("CSMSG_CHANNEL_VISITED", intervalString(buffer, now - cData->visited, user->handle_info)); + reply("CSMSG_CHANNEL_REGISTERED", intervalString(buffer, now - cData->registered, user->handle_info)); privileged = IsStaff(user); if(((uData && uData->access >= UL_COOWNER) || privileged) && cData->registrar) @@ -3908,8 +3908,8 @@ static CHANSERV_FUNC(cmd_netinfo) reply("CSMSG_NETWORK_CHANNELS", registered_channels); reply("CSMSG_NETWORK_BANS", banCount); reply("CSMSG_CHANNEL_USERS", userCount); - reply("CSMSG_SERVICES_UPTIME", intervalString(interval, time(NULL) - boot_time)); - reply("CSMSG_BURST_LENGTH",intervalString(interval, burst_length)); + reply("CSMSG_SERVICES_UPTIME", intervalString(interval, time(NULL) - boot_time, user->handle_info)); + reply("CSMSG_BURST_LENGTH", intervalString(interval, burst_length, user->handle_info)); return 1; } @@ -4115,7 +4115,7 @@ static CHANSERV_FUNC(cmd_seen) if(uData->present) reply("CSMSG_USER_PRESENT", handle->handle); else if(uData->seen) - reply("CSMSG_USER_SEEN", handle->handle, channel->name, intervalString(seen, now - uData->seen)); + reply("CSMSG_USER_SEEN", handle->handle, channel->name, intervalString(seen, now - uData->seen, user->handle_info)); else reply("CSMSG_NEVER_SEEN", handle->handle, channel->name); @@ -4667,7 +4667,7 @@ static CHANSERV_FUNC(cmd_unvisited) limit = atoi(argv[2]); } - intervalString(buffer, interval); + intervalString(buffer, interval, user->handle_info); reply("CSMSG_UNVISITED_HEADER", limit, buffer); for(cData = channelList; cData && matches < limit; cData = cData->next) @@ -4675,7 +4675,7 @@ static CHANSERV_FUNC(cmd_unvisited) if((now - cData->visited) < interval) continue; - intervalString(buffer, now - cData->visited); + intervalString(buffer, now - cData->visited, user->handle_info); reply("CSMSG_UNVISITED_DATA", cData->channel->name, buffer); matches++; } diff --git a/src/common.h b/src/common.h index a16b14b..952b1de 100644 --- a/src/common.h +++ b/src/common.h @@ -162,12 +162,14 @@ void STRUCTNAME##_clean(struct STRUCTNAME *list) {\ free(list->list);\ } -/* The longest string that's likely to be produced is "10 minutes, and 10 - seconds." (27 characters) */ -#define INTERVALLEN 32 +/* The longest string that is likely to be produced in English is "10 + * minutes, and 10 seconds" (27 characters). Other languages will + * vary, so there's plenty of leeway. + */ +#define INTERVALLEN 50 -char *intervalString2(char *output, time_t interval, int brief); -#define intervalString(OUTPUT, INTERVAL) intervalString2((OUTPUT), (INTERVAL), 0) +struct handle_info; +char *intervalString(char *output, time_t interval, struct handle_info *hi); int getipbyname(const char *name, unsigned long *ip); int set_policer_param(const char *param, void *data, void *extra); const char *strtab(unsigned int ii); diff --git a/src/global.c b/src/global.c index c810668..0e9c2b1 100644 --- a/src/global.c +++ b/src/global.c @@ -442,13 +442,9 @@ static GLOBAL_FUNC(cmd_list) table.contents[nn][0] = strdup(buffer); table.contents[nn][1] = messageType(message); if(message->duration) - { - intervalString(buffer, message->posted + message->duration - now); - } + intervalString(buffer, message->posted + message->duration - now, user->handle_info); else - { strcpy(buffer, "Never."); - } table.contents[nn][2] = strdup(buffer); table.contents[nn][3] = message->from; length = strlen(message->message); diff --git a/src/main.c b/src/main.c index 997c478..32ff878 100644 --- a/src/main.c +++ b/src/main.c @@ -117,6 +117,20 @@ static const struct message_entry msgtab[] = { { "MSG_DB_WRITE_ERROR", "Error while writing database %s." }, { "MSG_DB_WROTE_DB", "Wrote database %s (in "FMT_TIME_T".%06lu seconds)." }, { "MSG_DB_WROTE_ALL", "Wrote all databases (in "FMT_TIME_T".%06lu seconds)." }, + { "MSG_AND", "and" }, + { "MSG_0_SECONDS", "0 seconds" }, + { "MSG_YEAR", "year" }, + { "MSG_YEARS", "years" }, + { "MSG_WEEK", "week" }, + { "MSG_WEEKS", "weeks" }, + { "MSG_DAY", "day" }, + { "MSG_DAYS", "days" }, + { "MSG_HOUR", "hour" }, + { "MSG_HOURS", "hours" }, + { "MSG_MINUTE", "minute" }, + { "MSG_MINUTES", "minutes" }, + { "MSG_SECOND", "second" }, + { "MSG_SECONDS", "seconds" }, { NULL, NULL } }; diff --git a/src/mod-helpserv.c b/src/mod-helpserv.c index 177e11e..57a42ca 100644 --- a/src/mod-helpserv.c +++ b/src/mod-helpserv.c @@ -924,7 +924,7 @@ static struct helpserv_request * create_request(struct userNode *user, struct he sprintf(lbuf[0], fmt, req->id); } if (req != hs->unhandled) { - intervalString(unh, now - hs->unhandled->opened); + intervalString(unh, now - hs->unhandled->opened, user->handle_info); fmt = user_find_message(user, "HSMSG_REQ_UNHANDLED_TIME"); sprintf(lbuf[1], fmt, unh); } else { @@ -1067,7 +1067,7 @@ static void helpserv_usermsg(struct userNode *user, struct helpserv_bot *hs, cha char buf[MAX_LINE_SIZE], updatestr[INTERVALLEN], timestr[MAX_LINE_SIZE]; strftime(timestr, MAX_LINE_SIZE, HSFMT_TIME, localtime(&req->opened)); - intervalString(updatestr, now - req->updated); + intervalString(updatestr, now - req->updated, user->handle_info); if (req->helper && (hs->notify >= NOTIFY_USER)) if (user->handle_info) helpserv_notify(req->helper, "HSMSG_PAGE_UPD_REQUEST_AUTHED", req->id, user->nick, user->handle_info->handle, timestr, updatestr); @@ -1241,7 +1241,7 @@ static HELPSERV_USERCMD(usercmd_wait) { pos = count; } assert(pos >= 0); - intervalString(buf, now - req->hs->unhandled->opened); + intervalString(buf, now - req->hs->unhandled->opened, req->user->handle_info); helpserv_user_reply("HSMSG_WAIT_STATUS", pos+1, count, buf); } @@ -1768,7 +1768,7 @@ static HELPSERV_FUNC(cmd_list) { } tbl.contents[line][1] = strdup(username); tbl.contents[line][2] = req->helper ? req->helper->handle->handle : "(Unassigned)"; - intervalString(opentime, now - req->opened); + intervalString(opentime, now - req->opened, user->handle_info); tbl.contents[line][3] = strdup(opentime); tbl.contents[line][4] = ((req->user || req->handle->users) ? "Online" : "Offline"); } @@ -1802,7 +1802,7 @@ static void helpserv_show(int from_opserv, struct helpserv_bot *hs, struct userN else helpserv_notice(user, "HSMSG_REQ_INFO_2e"); strftime(buf, MAX_LINE_SIZE, HSFMT_TIME, localtime(&req->opened)); - intervalString(buf2, now - req->opened); + intervalString(buf2, now - req->opened, user->handle_info); helpserv_notice(user, "HSMSG_REQ_INFO_3", buf, buf2); helpserv_notice(user, "HSMSG_REQ_INFO_4"); for (nn=0; nn < req->text->used; nn++) @@ -2313,7 +2313,7 @@ static HELPSERV_FUNC(cmd_bots) { tbl.contents[i][1] = bot->helpchan->name; tbl.contents[i][2] = owner ? owner->handle->handle : "None"; tbl.contents[i][3] = alloca(INTERVALLEN); - intervalString((char*)tbl.contents[i][3], now - bot->last_active); + intervalString((char*)tbl.contents[i][3], now - bot->last_active, user->handle_info); } table_send((from_opserv ? opserv : hs->helpserv), user->nick, 0, NULL, tbl); @@ -2399,7 +2399,7 @@ static void run_whine_interval(void *data) { if (reqlist.used) { char strwhinedelay[INTERVALLEN]; - intervalString(strwhinedelay, (time_t)hs->intervals[INTERVAL_WHINE_DELAY]); + intervalString(strwhinedelay, (time_t)hs->intervals[INTERVAL_WHINE_DELAY], NULL); #if ANNOYING_ALERT_PAGES tbl.length = reqlist.used + 1; tbl.width = 4; @@ -2420,7 +2420,7 @@ static void run_whine_interval(void *data) { tbl.contents[i][0] = strdup(reqid); tbl.contents[i][1] = unh->user ? unh->user->nick : "Not online"; tbl.contents[i][2] = unh->handle ? unh->handle->handle : "Not authed"; - intervalString(unh_time, now - unh->opened); + intervalString(unh_time, now - unh->opened, NULL); tbl.contents[i][3] = strdup(unh_time); } @@ -2500,11 +2500,11 @@ static void run_whine_interval(void *data) { } tbl.contents[i][2] = strdup(reqid); - intervalString(idle_time, now - mn->idle_since); + intervalString(idle_time, now - mn->idle_since, NULL); tbl.contents[i][3] = strdup(idle_time); } - intervalString(stridledelay, (time_t)hs->intervals[INTERVAL_IDLE_DELAY]); + intervalString(stridledelay, (time_t)hs->intervals[INTERVAL_IDLE_DELAY], NULL); helpserv_page(PGSRC_STATUS, "HSMSG_PAGE_IDLE_HEADER", mode_list.used, hs->helpchan->name, stridledelay); table_send(hs->helpserv, hs->page_targets[PGSRC_STATUS]->name, 0, page_types[hs->page_types[PGSRC_STATUS]].func, tbl); @@ -3000,7 +3000,7 @@ static int opt_interval(struct userNode *user, struct helpserv_bot *hs, int from return 0; } if (new_int && new_int < min) { - intervalString(buf, min); + intervalString(buf, min, user->handle_info); helpserv_notice(user, "HSMSG_INVALID_INTERVAL", user_find_message(user, interval_types[idx].print_name), buf); return 0; } @@ -3008,7 +3008,7 @@ static int opt_interval(struct userNode *user, struct helpserv_bot *hs, int from changed = 1; } if (hs->intervals[idx]) { - intervalString(buf, hs->intervals[idx]); + intervalString(buf, hs->intervals[idx], user->handle_info); helpserv_notice(user, interval_types[idx].print_name, buf); } else helpserv_notice(user, interval_types[idx].print_name, user_find_message(user, "HSMSG_0_DISABLED")); diff --git a/src/mod-memoserv.c b/src/mod-memoserv.c index 729fae1..1fc9b1f 100644 --- a/src/mod-memoserv.c +++ b/src/mod-memoserv.c @@ -357,7 +357,7 @@ static MODCMD_FUNC(cmd_expiry) return 1; } - intervalString(interval, memoserv_conf.message_expiry); + intervalString(interval, memoserv_conf.message_expiry, user->handle_info); reply("MSMSG_EXPIRY", interval, memoserv_conf.message_expiry); return 1; } diff --git a/src/mod-sockcheck.c b/src/mod-sockcheck.c index 0a07eab..0e03822 100644 --- a/src/mod-sockcheck.c +++ b/src/mod-sockcheck.c @@ -1080,7 +1080,7 @@ static MODCMD_FUNC(cmd_stats_proxycheck) reply("PCMSG_NOT_CACHED", hostname); return 0; } - intervalString(elapse_buf, now - sci->last_touched); + intervalString(elapse_buf, now - sci->last_touched, user->handle_info); switch (sci->decision) { case CHECKING: msg = "PCMSG_STATUS_CHECKING"; break; case ACCEPT: msg = "PCMSG_STATUS_ACCEPTED"; break; diff --git a/src/nickserv.c b/src/nickserv.c index 98351a8..3c1fb57 100644 --- a/src/nickserv.c +++ b/src/nickserv.c @@ -161,7 +161,7 @@ static const struct message_entry msgtab[] = { { "NSMSG_NICK_NOT_REGISTERED", "Nick $b%s$b has not been registered to any account." }, { "NSMSG_HANDLE_NOT_FOUND", "Could not find your account -- did you register yet?" }, { "NSMSG_ALREADY_AUTHED", "You are already authed to account $b%s$b; you must reconnect to auth to a different account." }, - { "NSMSG_USE_AUTHCOOKIE", "Your hostmask is not valid for account $b%s$b. Please use the $bauthcookie$b command to grant yourself access. (/msg $S authcookie %s)" }, + { "NSMSG_USE_AUTHCOOKIE", "Your hostmask is not valid for account $b%1$s$b. Please use the $bauthcookie$b command to grant yourself access. (/msg $S authcookie %1$s)" }, { "NSMSG_HOSTMASK_INVALID", "Your hostmask is not valid for account $b%s$b." }, { "NSMSG_USER_IS_SERVICE", "$b%s$b is a network service; you can only use that command on real users." }, { "NSMSG_USER_PREV_AUTH", "$b%s$b is already authenticated." }, @@ -974,17 +974,17 @@ nickserv_make_cookie(struct userNode *user, struct handle_info *hi, enum cookie_ case ACTIVATION: hi->passwd[0] = 0; /* invalidate password */ send_message(user, nickserv, "NSMSG_USE_COOKIE_REGISTER"); - fmt = user_find_message(user, "NSEMAIL_ACTIVATION_SUBJECT"); + fmt = handle_find_message(hi, "NSEMAIL_ACTIVATION_SUBJECT"); snprintf(subject, sizeof(subject), fmt, netname); - fmt = user_find_message(user, "NSEMAIL_ACTIVATION_BODY"); + fmt = handle_find_message(hi, "NSEMAIL_ACTIVATION_BODY"); snprintf(body, sizeof(body), fmt, netname, cookie->cookie, nickserv->nick, self->name, hi->handle); first_time = 1; break; case PASSWORD_CHANGE: send_message(user, nickserv, "NSMSG_USE_COOKIE_RESETPASS"); - fmt = user_find_message(user, "NSEMAIL_PASSWORD_CHANGE_SUBJECT"); + fmt = handle_find_message(hi, "NSEMAIL_PASSWORD_CHANGE_SUBJECT"); snprintf(subject, sizeof(subject), fmt, netname); - fmt = user_find_message(user, "NSEMAIL_PASSWORD_CHANGE_BODY"); + fmt = handle_find_message(hi, "NSEMAIL_PASSWORD_CHANGE_BODY"); snprintf(body, sizeof(body), fmt, netname, cookie->cookie, nickserv->nick, self->name, hi->handle); break; case EMAIL_CHANGE: @@ -992,18 +992,18 @@ nickserv_make_cookie(struct userNode *user, struct handle_info *hi, enum cookie_ hi->email_addr = cookie->data; if (misc) { send_message(user, nickserv, "NSMSG_USE_COOKIE_EMAIL_2"); - fmt = user_find_message(user, "NSEMAIL_EMAIL_CHANGE_SUBJECT"); + fmt = handle_find_message(hi, "NSEMAIL_EMAIL_CHANGE_SUBJECT"); snprintf(subject, sizeof(subject), fmt, netname); - fmt = user_find_message(user, "NSEMAIL_EMAIL_CHANGE_BODY_NEW"); + fmt = handle_find_message(hi, "NSEMAIL_EMAIL_CHANGE_BODY_NEW"); snprintf(body, sizeof(body), fmt, netname, cookie->cookie+COOKIELEN/2, nickserv->nick, self->name, hi->handle, COOKIELEN/2); sendmail(nickserv, hi, subject, body, 1); - fmt = user_find_message(user, "NSEMAIL_EMAIL_CHANGE_BODY_OLD"); + fmt = handle_find_message(hi, "NSEMAIL_EMAIL_CHANGE_BODY_OLD"); snprintf(body, sizeof(body), fmt, netname, cookie->cookie, nickserv->nick, self->name, hi->handle, COOKIELEN/2, hi->email_addr); } else { send_message(user, nickserv, "NSMSG_USE_COOKIE_EMAIL_1"); - fmt = user_find_message(user, "NSEMAIL_EMAIL_VERIFY_SUBJECT"); + fmt = handle_find_message(hi, "NSEMAIL_EMAIL_VERIFY_SUBJECT"); snprintf(subject, sizeof(subject), fmt, netname); - fmt = user_find_message(user, "NSEMAIL_EMAIL_VERIFY_BODY"); + fmt = handle_find_message(hi, "NSEMAIL_EMAIL_VERIFY_BODY"); snprintf(body, sizeof(body), fmt, netname, cookie->cookie, nickserv->nick, self->name, hi->handle); sendmail(nickserv, hi, subject, body, 1); subject[0] = 0; @@ -1011,9 +1011,9 @@ nickserv_make_cookie(struct userNode *user, struct handle_info *hi, enum cookie_ hi->email_addr = misc; break; case ALLOWAUTH: - fmt = user_find_message(user, "NSEMAIL_ALLOWAUTH_SUBJECT"); + fmt = handle_find_message(hi, "NSEMAIL_ALLOWAUTH_SUBJECT"); snprintf(subject, sizeof(subject), fmt, netname); - fmt = user_find_message(user, "NSEMAIL_ALLOWAUTH_BODY"); + fmt = handle_find_message(hi, "NSEMAIL_ALLOWAUTH_BODY"); snprintf(body, sizeof(body), fmt, netname, cookie->cookie, nickserv->nick, self->name, hi->handle); send_message(user, nickserv, "NSMSG_USE_COOKIE_AUTH"); break; @@ -1235,7 +1235,7 @@ static NICKSERV_FUNC(cmd_handleinfo) reply("NSMSG_HANDLEINFO_REGGED", ctime(&hi->registered)); if (!hi->users) { - intervalString(buff, now - hi->lastseen); + intervalString(buff, now - hi->lastseen, user->handle_info); reply("NSMSG_HANDLEINFO_LASTSEEN", buff); } else { reply("NSMSG_HANDLEINFO_LASTSEEN_NOW"); @@ -1509,18 +1509,24 @@ static NICKSERV_FUNC(cmd_auth) reply("NSMSG_HANDLE_NOT_FOUND"); return 0; } + /* Responses from here on look up the language used by the handle they asked about. */ passwd = argv[pw_arg]; if (!valid_user_for(user, hi)) { if (hi->email_addr && nickserv_conf.email_enabled) - reply("NSMSG_USE_AUTHCOOKIE", hi->handle, hi->handle); + send_message_type(4, user, cmd->parent->bot, + handle_find_message(hi, "NSMSG_USE_AUTHCOOKIE"), + hi->handle); else - reply("NSMSG_HOSTMASK_INVALID", hi->handle); + send_message_type(4, user, cmd->parent->bot, + handle_find_message(hi, "NSMSG_HOSTMASK_INVALID"), + hi->handle); argv[pw_arg] = "BADMASK"; return 1; } if (!checkpass(passwd, hi->passwd)) { unsigned int n; - reply("NSMSG_PASSWORD_INVALID"); + send_message_type(4, user, cmd->parent->bot, + handle_find_message(hi, "NSMSG_PASSWORD_INVALID")); argv[pw_arg] = "BADPASS"; for (n=0; nparent->bot, + handle_find_message(hi, "NSMSG_HANDLE_SUSPENDED")); argv[pw_arg] = "SUSPENDED"; return 1; } maxlogins = hi->maxlogins ? hi->maxlogins : nickserv_conf.default_maxlogins; for (used = 0, other = hi->users; other; other = other->next_authed) { if (++used >= maxlogins) { - reply("NSMSG_MAX_LOGINS", maxlogins); + send_message_type(4, user, cmd->parent->bot, + handle_find_message(hi, "NSMSG_MAX_LOGINS"), + maxlogins); argv[pw_arg] = "MAXLOGINS"; return 1; } } + set_user_handle_info(user, hi, 1); if (nickserv_conf.email_required && !hi->email_addr) reply("NSMSG_PLEASE_SET_EMAIL"); if (!is_secure_password(hi->handle, passwd, NULL)) reply("NSMSG_WEAK_PASSWORD"); if (hi->passwd[0] != '$') cryptpass(passwd, hi->passwd); - reply("NSMSG_AUTH_SUCCESS"); argv[pw_arg] = "****"; - set_user_handle_info(user, hi, 1); return 1; } diff --git a/src/opserv.c b/src/opserv.c index 6d31e78..74a4380 100644 --- a/src/opserv.c +++ b/src/opserv.c @@ -1193,7 +1193,7 @@ static MODCMD_FUNC(cmd_whois) #endif reply("OSMSG_WHOIS_SERVER", target->uplink->name); reply("OSMSG_WHOIS_ACCOUNT", (target->handle_info ? target->handle_info->handle : "Not authenticated")); - intervalString(buffer, now - target->timestamp); + intervalString(buffer, now - target->timestamp, user->handle_info); reply("OSMSG_WHOIS_NICK_AGE", buffer); if (target->channels.used <= MAX_CHANNELS_WHOIS) opserv_ison(user, target, "OSMSG_WHOIS_CHANNELS"); @@ -1395,8 +1395,9 @@ static MODCMD_FUNC(cmd_stats_network2) { #endif tbl.contents[nn][1] = buffer; ofs = strlen(buffer) + 1; - intervalString(buffer + ofs, now - server->link); - if (server->self_burst) strcat(buffer + ofs, " Bursting"); + intervalString(buffer + ofs, now - server->link, user->handle_info); + if (server->self_burst) + strcat(buffer + ofs, " Bursting"); tbl.contents[nn][2] = buffer + ofs; nn++; } @@ -1428,9 +1429,9 @@ static MODCMD_FUNC(cmd_stats_trusted) { th = dict_find(opserv_trusted_hosts, argv[1], NULL); if (th) { if (th->issued) - intervalString(issued, now - th->issued); + intervalString(issued, now - th->issued, user->handle_info); if (th->expires) - intervalString(length, th->expires - now); + intervalString(length, th->expires - now, user->handle_info); if (th->limit) sprintf(limit, "limit %lu", th->limit); reply("OSMSG_HOST_IS_TRUSTED", @@ -1448,9 +1449,9 @@ static MODCMD_FUNC(cmd_stats_trusted) { for (it = dict_first(opserv_trusted_hosts); it; it = iter_next(it)) { th = iter_data(it); if (th->issued) - intervalString(issued, now - th->issued); + intervalString(issued, now - th->issued, user->handle_info); if (th->expires) - intervalString(length, th->expires - now); + intervalString(length, th->expires - now, user->handle_info); if (th->limit) sprintf(limit, "limit %lu", th->limit); reply("OSMSG_HOST_IS_TRUSTED", iter_key(it), @@ -1491,7 +1492,7 @@ static MODCMD_FUNC(cmd_stats_uptime) { clocks_per_sec = CLOCKS_PER_SEC; } } - intervalString(uptime, time(NULL)-boot_time); + intervalString(uptime, time(NULL)-boot_time, user->handle_info); times(&buf); reply("OSMSG_UPTIME_STATS", uptime, lines_processed, @@ -1540,8 +1541,10 @@ static MODCMD_FUNC(cmd_stats_gags) { table.contents[0][3] = "Reason"; for (nn=1, gag=gagList; gag; nn++, gag=gag->next) { char expstr[INTERVALLEN]; - if (gag->expires) intervalString(expstr, gag->expires - now); - else strcpy(expstr, "Never"); + if (gag->expires) + intervalString(expstr, gag->expires - now, user->handle_info); + else + strcpy(expstr, "Never"); table.contents[nn] = calloc(table.width, sizeof(char*)); table.contents[nn][0] = gag->mask; table.contents[nn][1] = gag->owner; diff --git a/src/saxdb.c b/src/saxdb.c index 2ddd158..88f8352 100644 --- a/src/saxdb.c +++ b/src/saxdb.c @@ -423,14 +423,14 @@ static MODCMD_FUNC(cmd_stats_databases) { tbl.contents[ii][0] = db->name; tbl.contents[ii][1] = db->mondo_section ? db->mondo_section : db->filename; if (db->write_interval) { - intervalString(buf, db->write_interval); + intervalString(buf, db->write_interval, user->handle_info); } else { strcpy(buf, "Never"); } tbl.contents[ii][2] = buf; if (db->last_write) { - intervalString(buf+INTERVALLEN, now - db->last_write); - intervalString(buf+INTERVALLEN*2, db->last_write_duration); + intervalString(buf+INTERVALLEN, now - db->last_write, user->handle_info); + intervalString(buf+INTERVALLEN*2, db->last_write_duration, user->handle_info); } else { strcpy(buf+INTERVALLEN, "Never"); strcpy(buf+INTERVALLEN*2, "Never"); diff --git a/src/tools.c b/src/tools.c index c2fc94e..219d0af 100644 --- a/src/tools.c +++ b/src/tools.c @@ -18,6 +18,7 @@ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include "helpfile.h" #include "log.h" #include "nickserv.h" #include "recdb.h" @@ -643,25 +644,29 @@ unsplit_string(char *set[], unsigned int max, char *dest) } char * -intervalString2(char *output, time_t interval, int brief) +intervalString(char *output, time_t interval, struct handle_info *hi) { static const struct { - const char *name; + const char *msg_single; + const char *msg_plural; long length; } unit[] = { - { "year", 365 * 24 * 60 * 60 }, - { "week", 7 * 24 * 60 * 60 }, - { "day", 24 * 60 * 60 }, - { "hour", 60 * 60 }, - { "minute", 60 }, - { "second", 1 } + { "MSG_YEAR", "MSG_YEARS", 365 * 24 * 60 * 60 }, + { "MSG_WEEK", "MSG_WEEKS", 7 * 24 * 60 * 60 }, + { "MSG_DAY", "MSG_DAYS", 24 * 60 * 60 }, + { "MSG_HOUR", "MSG_HOURS", 60 * 60 }, + { "MSG_MINUTE", "MSG_MINUTES", 60 }, + { "MSG_SECOND", "MSG_SECONDS", 1 } }; + struct language *lang; + const char *msg; unsigned int type, words, pos, count; + lang = hi ? hi->language : lang_C; if(!interval) { - strcpy(output, brief ? "0s" : "0 seconds"); - return output; + msg = language_find_message(lang, "MSG_0_SECONDS"); + return strcpy(output, msg); } for (type = 0, words = pos = 0; @@ -672,15 +677,15 @@ intervalString2(char *output, time_t interval, int brief) count = interval / unit[type].length; interval = interval % unit[type].length; - if (brief) - pos += sprintf(output + pos, "%d%c", count, unit[type].name[0]); - else if (words == 1) - pos += sprintf(output + pos, " and %d %s", count, unit[type].name); + if (words++ == 1) { + msg = language_find_message(lang, "MSG_AND"); + pos += sprintf(output + pos, " %s ", msg); + } + if (count == 1) + msg = language_find_message(lang, unit[type].msg_single); else - pos += sprintf(output + pos, "%d %s", count, unit[type].name); - if (count != 1) - output[pos++] = 's'; - words++; + msg = language_find_message(lang, unit[type].msg_plural); + pos += sprintf(output + pos, "%d %s", count, msg); } output[pos] = 0; -- 2.20.1