+static HELPSERV_FUNC(cmd_modstats) {
+ struct handle_info *hi;
+ struct helpserv_user *victim;
+ const char *field_name;
+ int week, mod;
+ unsigned int *field = NULL;
+ char *errptr;
+
+ REQUIRE_PARMS(5);
+ if (!oper_has_access(user, (from_opserv ? opserv : hs->helpserv), helpserv_conf.modstats_level, 0))
+ return 0;
+ 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;
+ }
+
+ field_name = argv[2];
+ if (!strcasecmp(argv[3], "total"))
+ week = 4;
+ else if(!strcasecmp(argv[3], "current"))
+ week = 0;
+ else {
+ week = strtoul(argv[3], &errptr, 0);
+ if (*errptr != '\0') {
+ helpserv_notice(user, "HSMSG_MODSTATS_BAD_WEEK");
+ return 0;
+ }
+ }
+ mod = strtol(argv[4], NULL, 0);
+
+ if (week < 0 || week > 4) {
+ helpserv_notice(user, "HSMSG_MODSTATS_BAD_WEEK");
+ return 0;
+ }
+
+ if (!strcasecmp(field_name, "time")) {
+ if (victim->join_time && (week == 0 || week == 4)) {
+ victim->time_per_week[0] += now - victim->join_time;
+ victim->time_per_week[4] += now - victim->join_time;
+ victim->join_time = now;
+ }
+ field = victim->time_per_week;
+ }
+ else if (!strcasecmp(field_name, "picked") || !strcasecmp(field_name, "picked_up") || !strcasecmp(field_name, "reqs"))
+ field = victim->picked_up;
+ else if (!strcasecmp(field_name, "closed"))
+ field = victim->closed;
+ else if (!strcasecmp(field_name, "ra_from") || !strcasecmp(field_name, "reassigned_from"))
+ field = victim->reassigned_from;
+ else if (!strcasecmp(field_name, "ra_to") || !strcasecmp(field_name, "reassigned_to"))
+ field = victim->reassigned_to;
+ else {
+ helpserv_notice(user, "HSMSG_MODSTATS_BAD_FIELD");
+ return 0;
+ }
+
+ if (mod < 0 && abs(mod) > field[week]) {
+ helpserv_notice(user, "HSMSG_MODSTATS_NEGATIVE");
+ return 0;
+ }
+
+ field[week] += mod;
+ helpserv_notice(user, "HSMSG_MODSTATS_SUCCESS", victim->handle->handle);
+
+ return (mod != 0);
+}
+