static void show_quota(dbref player, dbref victim) { dbref aowner; int aflags; UTF8 *buff = alloc_lbuf("show_quota"); atr_get_str(buff, victim, A_QUOTA, &aowner, &aflags); int aq = mux_atol(buff); atr_get_str(buff, victim, A_RQUOTA, &aowner, &aflags); int rq = aq - mux_atol(buff); mux_field fldName = StripTabsAndTruncate(Name(victim), buff, LBUF_SIZE-1, 16); if (!Free_Quota(victim)) { mux_sprintf(buff + fldName.m_byte, LBUF_SIZE - fldName.m_byte, T(" Quota: %9d Used: %9d"), aq, rq); } else { mux_sprintf(buff + fldName.m_byte, LBUF_SIZE - fldName.m_byte, T(" Quota: UNLIMITED Used: %9d"), rq); } notify_quiet(player, buff); free_lbuf(buff); }
// --------------------------------------------------------------------------- // do_queue: Queue management // void do_queue(dbref executor, dbref caller, dbref enactor, int eval, int key, char *arg) { UNUSED_PARAMETER(caller); UNUSED_PARAMETER(enactor); UNUSED_PARAMETER(eval); if (key == QUEUE_KICK) { int i = mux_atol(arg); int save_minPriority = scheduler.GetMinPriority(); if (save_minPriority <= PRIORITY_CF_DEQUEUE_DISABLED) { notify(executor, "Warning: automatic dequeueing is disabled."); scheduler.SetMinPriority(PRIORITY_CF_DEQUEUE_ENABLED); } CLinearTimeAbsolute lsaNow; lsaNow.GetUTC(); scheduler.ReadyTasks(lsaNow); int ncmds = scheduler.RunTasks(i); scheduler.SetMinPriority(save_minPriority); if (!Quiet(executor)) { notify(executor, tprintf("%d commands processed.", ncmds)); } } else if (key == QUEUE_WARP) { int iWarp = mux_atol(arg); ltdWarp.SetSeconds(iWarp); if (scheduler.GetMinPriority() <= PRIORITY_CF_DEQUEUE_DISABLED) { notify(executor, "Warning: automatic dequeueing is disabled."); } scheduler.TraverseUnordered(CallBack_Warp); if (Quiet(executor)) { return; } if (iWarp > 0) { notify(executor, tprintf("WaitQ timer advanced %d seconds.", iWarp)); } else if (iWarp < 0) { notify(executor, tprintf("WaitQ timer set back %d seconds.", iWarp)); } else { notify(executor, "Object queue appended to player queue."); } } }
void ParseDecimalSeconds(size_t n, const UTF8 *p, unsigned short *iMilli, unsigned short *iMicro, unsigned short *iNano) { UTF8 aBuffer[10]; if (n > sizeof(aBuffer) - 1) { n = sizeof(aBuffer) - 1; } memcpy(aBuffer, p, n); memset(aBuffer + n, '0', sizeof(aBuffer) - n - 1); aBuffer[sizeof(aBuffer) - 1] = '\0'; long ns = mux_atol(aBuffer); *iNano = static_cast<unsigned short>(ns % 1000); ns /= 1000; *iMicro = static_cast<unsigned short>(ns % 1000); *iMilli = static_cast<unsigned short>(ns / 1000); }
int nfy_que(dbref sem, int attr, int key, int count) { int cSemaphore = 1; if (attr) { int aflags; dbref aowner; char *str = atr_get(sem, attr, &aowner, &aflags); cSemaphore = mux_atol(str); free_lbuf(str); } Notify_Num_Done = 0; if (cSemaphore > 0) { Notify_Key = key; Notify_Sem = sem; Notify_Attr = attr; Notify_Num_Max = count; if ( key == NFY_NFY || key == NFY_QUIET) { scheduler.TraverseOrdered(CallBack_NotifySemaphoreFirstOrQuiet); } else { scheduler.TraverseUnordered(CallBack_NotifySemaphoreDrainOrAll); } } // Update the sem waiters count. // if ( NFY_NFY == key || NFY_QUIET == key) { add_to(sem, -count, attr); } else { atr_clr(sem, attr); } return Notify_Num_Done; }
void do_timewarp(dbref executor, dbref caller, dbref enactor, int eval, int key, char *arg) { UNUSED_PARAMETER(eval); int secs; secs = mux_atol(arg); // Sem/Wait queues // if ((key == 0) || (key & TWARP_QUEUE)) { do_queue(executor, caller, enactor, 0, QUEUE_WARP, arg); } // Once these are adjusted, we need to Cancel and reschedule the task. // CLinearTimeDelta ltd; ltd.SetSeconds(secs); if (key & TWARP_DUMP) { mudstate.dump_counter -= ltd; scheduler.CancelTask(dispatch_DatabaseDump, 0, 0); scheduler.DeferTask(mudstate.dump_counter, PRIORITY_SYSTEM, dispatch_DatabaseDump, 0, 0); } if (key & TWARP_CLEAN) { mudstate.check_counter -= ltd; scheduler.CancelTask(dispatch_FreeListReconstruction, 0, 0); scheduler.DeferTask(mudstate.check_counter, PRIORITY_SYSTEM, dispatch_FreeListReconstruction, 0, 0); } if (key & TWARP_IDLE) { mudstate.idle_counter -= ltd; scheduler.CancelTask(dispatch_IdleCheck, 0, 0); scheduler.DeferTask(mudstate.idle_counter, PRIORITY_SYSTEM, dispatch_IdleCheck, 0, 0); } if (key & TWARP_EVENTS) { mudstate.events_counter -= ltd; scheduler.CancelTask(dispatch_CheckEvents, 0, 0); scheduler.DeferTask(mudstate.events_counter, PRIORITY_SYSTEM, dispatch_CheckEvents, 0, 0); } }
// --------------------------------------------------------------------------- // add_to: Adjust an object's queue or semaphore count. // static int add_to(dbref executor, int am, int attrnum) { int aflags; dbref aowner; char *atr_gotten = atr_get(executor, attrnum, &aowner, &aflags); int num = mux_atol(atr_gotten); free_lbuf(atr_gotten); num += am; char buff[20]; size_t nlen = 0; *buff = '\0'; if (num) { nlen = mux_ltoa(num, buff); } atr_add_raw_LEN(executor, attrnum, buff, nlen); return num; }
/* --------------------------------------------------------------------------- * did_it_rlevel: Have player do something to/with thing, watching the * attributes. 'what' is actually ignored, the desclist match being used * instead. */ void did_it_rlevel ( dbref player, dbref thing, int what, const UTF8 *def, int owhat, const UTF8 *odef, int awhat, int ctrl_flags, const UTF8 *args[], int nargs ) { if (MuxAlarm.bAlarmed) { return; } UTF8 *d, *buff, *act, *charges, *bp; dbref aowner; int num, aflags; int i; bool found_a_desc; reg_ref **preserve = NULL; bool need_pres = false; // Message to player. // if (0 < what) { // Get description list. // DESC_INFO *desclist = desclist_match(player, thing); found_a_desc = false; for (i = 0; i < desclist->n; i++) { // Ok, if it's A_DESC, we need to check against A_IDESC. // if ( A_IDESC == what && A_DESC == desclist->descs[i]) { d = atr_pget(thing, A_IDESC, &aowner, &aflags); } else { d = atr_pget(thing, desclist->descs[i], &aowner, &aflags); } if ('\0' != d[0]) { // No need for the 'def' message. // found_a_desc = true; if (!need_pres) { need_pres = true; preserve = PushRegisters(MAX_GLOBAL_REGS); save_global_regs(preserve); } buff = bp = alloc_lbuf("did_it.1"); mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player, AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP), args, nargs); *bp = '\0'; if ( A_HTDESC == desclist->descs[i] && Html(player)) { safe_str(T("\r\n"), buff, &bp); *bp = '\0'; notify_html(player, buff); } else { notify(player, buff); } free_lbuf(buff); } free_lbuf(d); } if (!found_a_desc) { // No desc found... try the default desc (again). // A_DESC or A_HTDESC... the worst case we look for it twice. // d = atr_pget(thing, what, &aowner, &aflags); if ('\0' != d[0]) { // No need for the 'def' message // found_a_desc = true; if (!need_pres) { need_pres = true; preserve = PushRegisters(MAX_GLOBAL_REGS); save_global_regs(preserve); } buff = bp = alloc_lbuf("did_it.1"); mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player, AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP), args, nargs); *bp = '\0'; if ( A_HTDESC == what && Html(player)) { safe_str(T("\r\n"), buff, &bp); *bp = '\0'; notify_html(player, buff); } else { notify(player, buff); } free_lbuf(buff); } else if (def) { notify(player, def); } free_lbuf(d); } } else if ( what < 0 && def) { notify(player, def); } if (isPlayer(thing)) { d = atr_pget(mudconf.master_room, get_atr(T("ASSET_DESC")), &aowner, &aflags); if (*d) { if (!need_pres) { need_pres = true; preserve = PushRegisters(MAX_GLOBAL_REGS); save_global_regs(preserve); } buff = bp = alloc_lbuf("did_it.1"); mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player, AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP), args, nargs); *bp = '\0'; notify(player, buff); free_lbuf(buff); } free_lbuf(d); } // Message to neighbors. // dbref loc; if ( 0 < owhat && Has_location(player) && Good_obj(loc = Location(player))) { d = atr_pget(thing, owhat, &aowner, &aflags); if (*d) { if (!need_pres) { need_pres = true; preserve = PushRegisters(MAX_GLOBAL_REGS); save_global_regs(preserve); } buff = bp = alloc_lbuf("did_it.2"); mux_exec(d, LBUF_SIZE-1, buff, &bp, thing, thing, player, AttrTrace(aflags, EV_EVAL|EV_FIGNORE|EV_TOP), args, nargs); *bp = '\0'; if (*buff) { if (aflags & AF_NONAME) { notify_except2_rlevel2(loc, player, player, thing, buff); } else { notify_except2_rlevel2(loc, player, player, thing, tprintf(T("%s %s"), Name(player), buff)); } } free_lbuf(buff); } else if (odef) { if (ctrl_flags & VERB_NONAME) { notify_except2_rlevel2(loc, player, player, thing, odef); } else { notify_except2_rlevel2(loc, player, player, thing, tprintf(T("%s %s"), Name(player), odef)); } } free_lbuf(d); } else if ( owhat < 0 && odef && Has_location(player) && Good_obj(loc = Location(player))) { if (ctrl_flags & VERB_NONAME) { notify_except2_rlevel2(loc, player, player, thing, odef); } else { notify_except2_rlevel2(loc, player, player, thing, tprintf(T("%s %s"), Name(player), odef)); } } // If we preserved the state of the global registers, restore them. // if (need_pres) { restore_global_regs(preserve); PopRegisters(preserve, MAX_GLOBAL_REGS); } // Do the action attribute. // if ( awhat > 0 && IsReal(thing, player)) { act = atr_pget(thing, awhat, &aowner, &aflags); if (*act != '\0') { charges = atr_pget(thing, A_CHARGES, &aowner, &aflags); if (*charges) { num = mux_atol(charges); if (num > 0) { buff = alloc_sbuf("did_it.charges"); mux_ltoa(num-1, buff); atr_add_raw(thing, A_CHARGES, buff); free_sbuf(buff); } else { buff = atr_pget(thing, A_RUNOUT, &aowner, &aflags); if (*buff != '\0') { free_lbuf(act); act = buff; } else { free_lbuf(act); free_lbuf(buff); free_lbuf(charges); return; } } } free_lbuf(charges); CLinearTimeAbsolute lta; wait_que(thing, player, player, AttrTrace(aflags, 0), false, lta, NOTHING, 0, act, nargs, args, mudstate.global_regs); } free_lbuf(act); } }
void do_notify ( dbref executor, dbref caller, dbref enactor, int key, int nargs, char *what, char *count ) { UNUSED_PARAMETER(caller); UNUSED_PARAMETER(enactor); UNUSED_PARAMETER(nargs); char *obj = parse_to(&what, '/', 0); init_match(executor, obj, NOTYPE); match_everything(0); dbref thing = noisy_match_result(); if (!Good_obj(thing)) { return; } if (!Controls(executor, thing) && !Link_ok(thing)) { notify(executor, NOPERM_MESSAGE); } else { int atr = A_SEMAPHORE; if ( what && what[0] != '\0') { int i = mkattr(executor, what); if (0 < i) { atr = i; if (atr != A_SEMAPHORE) { // Do they have permission to set this attribute? // ATTR *ap = (ATTR *)anum_get(atr); if (!bCanSetAttr(executor, thing, ap)) { notify_quiet(executor, NOPERM_MESSAGE); return; } } } } int loccount; if ( count && count[0] != '\0') { loccount = mux_atol(count); } else { loccount = 1; } if (loccount > 0) { nfy_que(thing, atr, key, loccount); if ( (!(Quiet(executor) || Quiet(thing))) && key != NFY_QUIET) { if (key == NFY_DRAIN) { notify_quiet(executor, "Drained."); } else { notify_quiet(executor, "Notified."); } } } } }
bool do_convtime(const UTF8 *str, FIELDEDTIME *ft) { memset(ft, 0, sizeof(FIELDEDTIME)); if (!str || !ft) { return false; } // Day-of-week OR month. // const UTF8 *p = str; int i, iHash; if (!ParseThreeLetters(&p, &iHash)) { return false; } for (i = 0; (i < 12) && iHash != MonthTabHash[i]; i++) { ; // Nothing. } if (i == 12) { // The above three letters were probably the Day-Of-Week, the // next three letters are required to be the month name. // if (!ParseThreeLetters(&p, &iHash)) { return false; } for (i = 0; (i < 12) && iHash != MonthTabHash[i]; i++) { ; // Nothing. } if (i == 12) { return false; } } // January = 1, February = 2, etc. // ft->iMonth = static_cast<unsigned short>(i + 1); // Day of month. // ft->iDayOfMonth = (unsigned short)mux_atol(p); if (ft->iDayOfMonth < 1 || daystab[i] < ft->iDayOfMonth) { return false; } while (*p && *p != ' ') p++; while (*p == ' ') p++; // Hours // ft->iHour = (unsigned short)mux_atol(p); if (ft->iHour > 23 || (ft->iHour == 0 && *p != '0')) { return false; } while (*p && *p != ':') p++; if (*p == ':') p++; while (*p == ' ') p++; // Minutes // ft->iMinute = (unsigned short)mux_atol(p); if (ft->iMinute > 59 || (ft->iMinute == 0 && *p != '0')) { return false; } while (*p && *p != ':') p++; if (*p == ':') p++; while (*p == ' ') p++; // Seconds // ft->iSecond = (unsigned short)mux_atol(p); if (ft->iSecond > 59 || (ft->iSecond == 0 && *p != '0')) { return false; } while (mux_isdigit(*p)) { p++; } // Milliseconds, Microseconds, and Nanoseconds // if (*p == '.') { p++; size_t n; const UTF8 *q = (UTF8 *)strchr((char *)p, ' '); if (q) { n = q - p; } else { n = strlen((char *)p); } ParseDecimalSeconds(n, p, &ft->iMillisecond, &ft->iMicrosecond, &ft->iNanosecond); } while (*p && *p != ' ') p++; while (*p == ' ') p++; // Year // ft->iYear = (short)mux_atol(p); while (mux_isdigit(*p)) { p++; } while (*p == ' ') p++; if (*p != '\0') { return false; } // DayOfYear and DayOfWeek // ft->iDayOfYear = 0; ft->iDayOfWeek = 0; return isValidDate(ft->iYear, ft->iMonth, ft->iDayOfMonth); }
static void mung_quotas(dbref player, int key, int value) { dbref aowner; int aq, rq, xq, aflags; UTF8 *buff; if (key & QUOTA_FIX) { // Get value of stuff owned and good value, set other value from that. // xq = count_quota(player); if (key & QUOTA_TOT) { buff = atr_get("mung_quotas.79", player, A_RQUOTA, &aowner, &aflags); aq = mux_atol(buff) + xq; atr_add_raw(player, A_QUOTA, mux_ltoa_t(aq)); free_lbuf(buff); } else { buff = atr_get("mung_quotas.86", player, A_QUOTA, &aowner, &aflags); rq = mux_atol(buff) - xq; atr_add_raw(player, A_RQUOTA, mux_ltoa_t(rq)); free_lbuf(buff); } } else { // Obtain (or calculate) current relative and absolute quota. // buff = atr_get("mung_quotas.96", player, A_QUOTA, &aowner, &aflags); if (!*buff) { free_lbuf(buff); buff = atr_get("mung_quotas.100", player, A_RQUOTA, &aowner, &aflags); rq = mux_atol(buff); free_lbuf(buff); aq = rq + count_quota(player); } else { aq = mux_atol(buff); free_lbuf(buff); buff = atr_get("mung_quotas.109", player, A_RQUOTA, &aowner, &aflags); rq = mux_atol(buff); free_lbuf(buff); } // Adjust values. // if (key & QUOTA_REM) { aq += (value - rq); rq = value; } else { rq += (value - aq); aq = value; } // Set both abs and relative quota. // atr_add_raw(player, A_QUOTA, mux_ltoa_t(aq)); atr_add_raw(player, A_RQUOTA, mux_ltoa_t(rq)); } }
void do_quota ( dbref executor, dbref caller, dbref enactor, int eval, int key, int nargs, UTF8 *arg1, UTF8 *arg2, const UTF8 *cargs[], int ncargs ) { UNUSED_PARAMETER(caller); UNUSED_PARAMETER(enactor); UNUSED_PARAMETER(eval); UNUSED_PARAMETER(nargs); UNUSED_PARAMETER(cargs); UNUSED_PARAMETER(ncargs); if (!(mudconf.quotas || Quota(executor))) { notify_quiet(executor, T("Quotas are not enabled.")); return; } if ((key & QUOTA_TOT) && (key & QUOTA_REM)) { notify_quiet(executor, T("Illegal combination of switches.")); return; } dbref who; int value = 0, i; bool set = false; // Show or set all quotas if requested. // if (key & QUOTA_ALL) { if (arg1 && *arg1) { value = mux_atol(arg1); set = true; } else if (key & (QUOTA_SET | QUOTA_FIX)) { value = 0; set = true; } if (set) { STARTLOG(LOG_WIZARD, "WIZ", "QUOTA"); log_name(executor); log_text(T(" changed everyone\xE2\x80\x99s quota")); ENDLOG; } DO_WHOLE_DB(i) { if (isPlayer(i)) { if (set) { mung_quotas(i, key, value); } show_quota(executor, i); } } return; } // Find out whose quota to show or set. // if (!arg1 || *arg1 == '\0') { who = Owner(executor); } else { who = lookup_player(executor, arg1, true); if (!Good_obj(who)) { notify_quiet(executor, T("Not found.")); return; } } // Make sure we have permission to do it. // if (!Quota(executor)) { if (arg2 && *arg2) { notify_quiet(executor, NOPERM_MESSAGE); return; } if (Owner(executor) != who) { notify_quiet(executor, NOPERM_MESSAGE); return; } } if (arg2 && *arg2) { set = true; value = mux_atol(arg2); } else if (key & QUOTA_FIX) { set = true; value = 0; } if (set) { STARTLOG(LOG_WIZARD, "WIZ", "QUOTA"); log_name(executor); log_text(T(" changed the quota of ")); log_name(who); ENDLOG; mung_quotas(who, key, value); } show_quota(executor, who); }