[srvx-commits] CVS: services/src helpserv.c,1.82,1.83
Brought to you by:
entrope
From: Entrope <en...@us...> - 2003-10-19 04:19:04
|
Update of /cvsroot/srvx/services/src In directory sc8-pr-cvs1:/tmp/cvs-serv5232/src Modified Files: helpserv.c Log Message: allow configuration of when week starts for different helpers Index: helpserv.c =================================================================== RCS file: /cvsroot/srvx/services/src/helpserv.c,v retrieving revision 1.82 retrieving revision 1.83 diff -C2 -r1.82 -r1.83 *** helpserv.c 26 Sep 2003 15:16:58 -0000 1.82 --- helpserv.c 19 Oct 2003 04:16:10 -0000 1.83 *************** *** 73,76 **** --- 73,77 ---- #define KEY_HELPER_LEVEL "level" #define KEY_HELPER_HELPMODE "helpmode" + #define KEY_HELPER_WEEKSTART "weekstart" #define KEY_HELPER_STATS "stats" #define KEY_HELPER_STATS_TIME "time" *************** *** 132,135 **** --- 133,138 ---- #define HSMSG_INVALID_ACCESS "$b%s$b is an invalid access level." #define HSMSG_CHANGED_ACCESS "%s is now %s $b%s$b" + #define HSMSG_BAD_WEEKDAY "I do not know which day of the week $b%s$b is." + #define HSMSG_WEEK_STARTS "$b%s$b's weeks start on $b%s$b." /* Registration */ *************** *** 240,244 **** #define HSMSG_STATS_TIME "$uTime spent helping in %s:$u" #define HSMSG_STATS_REQS "$uRequest activity statistics:$u" - #define HSFMT_STATS_REPORT_WEEK "Stats report for the week of $b%a, %d %b %Y$b" enum helpserv_level { --- 243,246 ---- *************** *** 378,381 **** --- 380,401 ---- }; + static const char *weekday_names[] = { + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + NULL + }; + + static const char *statsreport_week[] = { + "Stats report for current week", + "Stats report for one week ago", + "Stats report for two weeks ago", + "Stats report for three weeks ago" + }; + static struct { const char *description; *************** *** 435,438 **** --- 455,459 ---- struct helpserv_bot *hs; unsigned int help_mode : 1; + unsigned int week_start : 3; enum helpserv_level level; /* statistics */ *************** *** 1271,1275 **** line = 1; tbl.length = dict_size(hs->users)+1; ! tbl.width = 2; tbl.flags = TABLE_NO_FREE; tbl.contents = alloca(tbl.length * sizeof(*tbl.contents)); --- 1292,1296 ---- line = 1; tbl.length = dict_size(hs->users)+1; ! tbl.width = 3; tbl.flags = TABLE_NO_FREE; tbl.contents = alloca(tbl.length * sizeof(*tbl.contents)); *************** *** 1277,1280 **** --- 1298,1302 ---- tbl.contents[0][0] = "Level"; tbl.contents[0][1] = "Handle"; + tbl.contents[0][2] = "WeekStart"; for (lvl = lvl_highest; lvl >= lvl_lowest; lvl--) { *************** *** 1283,1286 **** --- 1305,1309 ---- tbl.contents[line][0] = helpserv_level_names[lvl]; tbl.contents[line][1] = userList[lvl][i]->handle->handle; + tbl.contents[line][2] = weekday_names[userList[lvl][i]->week_start]; } } *************** *** 1954,1966 **** dict_iterator_t it; unsigned int line, i; - char weekstr[MAX_LINE_SIZE]; - struct tm week_tm; struct userNode *srcbot = from_opserv ? opserv : hs->helpserv; ! if (argc > 1) { ! if (!irccasecmp(argv[1], "NOTICE")) { ! use_privmsg = 0; ! } ! } tbl.length = dict_size(hs->users)+1; --- 1977,1984 ---- dict_iterator_t it; unsigned int line, i; struct userNode *srcbot = from_opserv ? opserv : hs->helpserv; ! if ((argc > 1) && !irccasecmp(argv[1], "NOTICE")) ! use_privmsg = 0; tbl.length = dict_size(hs->users)+1; *************** *** 1982,1990 **** } - localtime_r(&last_stats_update, &week_tm); - week_tm.tm_mday -= week_tm.tm_wday; /* Ensure it'll start on Sunday */ - week_tm.tm_mday -= 7 * 3; /* Oldest to newest */ /* 4 to 1 instead of 3 to 0 because it's unsigned */ ! for (i=4; i > 0; i--, week_tm.tm_mday += 7) { for (it=dict_first(hs->users), line=0; it; it=iter_next(it)) { struct helpserv_user *hs_user = iter_data(it); --- 2000,2005 ---- } /* 4 to 1 instead of 3 to 0 because it's unsigned */ ! for (i=4; i > 0; i--) { for (it=dict_first(hs->users), line=0; it; it=iter_next(it)) { struct helpserv_user *hs_user = iter_data(it); *************** *** 1998,2004 **** sprintf((char *)tbl.contents[line][1], "%u", hs_user->picked_up[i-1]+hs_user->reassigned_to[i-1]); } ! mktime(&week_tm); /* To fix up stuff after messing with tm_mday */ ! strftime(weekstr, MAX_LINE_SIZE, HSFMT_STATS_REPORT_WEEK, &week_tm); ! send_target_message(use_privmsg, user->nick, srcbot, "%s", weekstr); table_send(srcbot, user->nick, 0, (use_privmsg ? irc_privmsg : irc_notice), tbl); } --- 2013,2017 ---- sprintf((char *)tbl.contents[line][1], "%u", hs_user->picked_up[i-1]+hs_user->reassigned_to[i-1]); } ! send_target_message(use_privmsg, user->nick, srcbot, statsreport_week[i-1]); table_send(srcbot, user->nick, 0, (use_privmsg ? irc_privmsg : irc_notice), tbl); } *************** *** 2559,2562 **** --- 2572,2622 ---- } + static HELPSERV_FUNC(cmd_weekstart) { + struct handle_info *hi; + struct helpserv_user *actor, *victim; + int changed = 0; + + REQUIRE_PARMS(2); + actor = from_opserv ? NULL : GetHSUser(hs, user->handle_info); + if (!(hi = helpserv_get_handle_info(user, argv[1]))) + return 0; + if (!(victim = GetHSUser(hs, hi))) { + helpserv_notice(user, HSMSG_NOT_IN_USERLIST, hi->handle, hs->helpserv->nick); + return 0; + } + if (actor && (actor->level <= victim->level) && (actor != victim)) { + helpserv_notice(user, MSG_USER_OUTRANKED, victim->handle->handle); + return 0; + } + if (argc > 2 && (!actor || actor->level >= HlManager)) { + int new_day = 7; + switch (argv[2][0]) { + case 's': case 'S': + if ((argv[2][1] == 'u') || (argv[2][1] == 'U')) + new_day = 0; + else if ((argv[2][1] == 'a') || (argv[2][1] == 'A')) + new_day = 6; + break; + case 'm': case 'M': new_day = 1; break; + case 't': case 'T': + if ((argv[2][1] == 'u') || (argv[2][1] == 'U')) + new_day = 2; + else if ((argv[2][1] == 'h') || (argv[2][1] == 'H')) + new_day = 4; + break; + case 'w': case 'W': new_day = 3; break; + case 'f': case 'F': new_day = 5; break; + } + if (new_day == 7) { + helpserv_notice(user, HSMSG_BAD_WEEKDAY, argv[2]); + return 0; + } + victim->week_start = new_day; + changed = 1; + } + helpserv_notice(user, HSMSG_WEEK_STARTS, victim->handle->handle, weekday_names[victim->week_start]); + return changed; + } + static void set_page_target(struct helpserv_bot *hs, enum page_source idx, const char *target) { struct chanNode *new_target, *old_target; *************** *** 2927,2930 **** --- 2987,2991 ---- saxdb_write_string(ctx, KEY_HELPER_LEVEL, helpserv_level2str(hs_user->level)); saxdb_write_string(ctx, KEY_HELPER_HELPMODE, (hs_user->help_mode ? "1" : "0")); + saxdb_write_int(ctx, KEY_HELPER_WEEKSTART, hs_user->week_start); /* Helper stats */ saxdb_start_record(ctx, KEY_HELPER_STATS, 0); *************** *** 2999,3002 **** --- 3060,3065 ---- str = database_get_data(rd->d.object, KEY_HELPER_HELPMODE, RECDB_QSTRING); hs_user->help_mode = (str && strtol(str, NULL, 0)) ? 1 : 0; + str = database_get_data(rd->d.object, KEY_HELPER_WEEKSTART, RECDB_QSTRING); + hs_user->week_start = str ? strtol(str, NULL, 0) : 0; /* Stats */ *************** *** 4085,4096 **** static time_t helpserv_next_stats(time_t after_when) { ! struct tm *timeinfo=localtime(&after_when); /* This works because mktime(3) says it will accept out-of-range values * and fix them for us. tm_wday and tm_yday are ignored. */ ! timeinfo->tm_mday += 7 - timeinfo->tm_wday; ! /* We want to run stats at midnight (local time). Perhaps make this ! * configurable? */ timeinfo->tm_sec = timeinfo->tm_min = timeinfo->tm_hour = 0; --- 4148,4158 ---- static time_t helpserv_next_stats(time_t after_when) { ! struct tm *timeinfo = localtime(&after_when); /* This works because mktime(3) says it will accept out-of-range values * and fix them for us. tm_wday and tm_yday are ignored. */ ! timeinfo->tm_mday++; ! /* We want to run stats at midnight (local time). */ timeinfo->tm_sec = timeinfo->tm_min = timeinfo->tm_hour = 0; *************** *** 4099,4103 **** /* If data != NULL, then don't add to the timeq */ ! static void helpserv_run_stats(UNUSED_ARG(void *data)) { struct helpserv_bot *hs; struct helpserv_user *hs_user; --- 4161,4166 ---- /* If data != NULL, then don't add to the timeq */ ! static void helpserv_run_stats(time_t when) { ! struct tm when_s; struct helpserv_bot *hs; struct helpserv_user *hs_user; *************** *** 4105,4108 **** --- 4168,4173 ---- dict_iterator_t it, it2; + last_stats_update = when; + localtime_r(&when, &when_s); for (it=dict_first(helpserv_bots_dict); it; it=iter_next(it)) { hs = iter_data(it); *************** *** 4111,4118 **** hs_user = iter_data(it2); if (hs_user->join_time) { ! hs_user->time_per_week[0] += now - hs_user->join_time; ! hs_user->time_per_week[4] += now - hs_user->join_time; ! hs_user->join_time = now; } --- 4176,4186 ---- hs_user = iter_data(it2); + if (hs_user->week_start != when_s.tm_wday) + continue; + if (hs_user->join_time) { ! hs_user->time_per_week[0] += when - hs_user->join_time; ! hs_user->time_per_week[4] += when - hs_user->join_time; ! hs_user->join_time = when; } *************** *** 4130,4140 **** } } - - last_stats_update = now; - if (!data) { - timeq_add(helpserv_next_stats(now), helpserv_run_stats, NULL); - } } static void --- 4198,4207 ---- } } } + static void helpserv_timed_run_stats(UNUSED_ARG(void *data)) { + helpserv_run_stats(now); + timeq_add(helpserv_next_stats(now), helpserv_timed_run_stats, data); + } static void *************** *** 4197,4200 **** --- 4264,4268 ---- helpserv_define_func("MOVE", cmd_move, HlOper, CMD_FROM_OPSERV_ONLY|CMD_NEED_BOT); helpserv_define_func("BOTS", cmd_bots, HlOper, CMD_FROM_OPSERV_ONLY|CMD_IGNORE_EVENT); + helpserv_define_func("WEEKSTART", cmd_weekstart, HlTrial, CMD_NEED_BOT); helpserv_option_dict = dict_new(); *************** *** 4245,4255 **** * time_per_week */ if (last_stats_update && (helpserv_next_stats(last_stats_update) < now)) { ! time_t statsrun=last_stats_update; ! ! while ((statsrun = helpserv_next_stats(statsrun)) < now) { ! helpserv_run_stats((void *)1); ! } } ! timeq_add(helpserv_next_stats(now), helpserv_run_stats, NULL); reg_join_func(handle_join); --- 4313,4321 ---- * time_per_week */ if (last_stats_update && (helpserv_next_stats(last_stats_update) < now)) { ! time_t statsrun = last_stats_update; ! while ((statsrun = helpserv_next_stats(statsrun)) < now) ! helpserv_run_stats(statsrun); } ! timeq_add(helpserv_next_stats(now), helpserv_timed_run_stats, NULL); reg_join_func(handle_join); |