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); }
UTF8 *unparse_object_numonly(dbref target) { UTF8 *buf = alloc_lbuf("unparse_object_numonly"); if (target < 0) { mux_strncpy(buf, aszSpecialDBRefNames[-target], LBUF_SIZE-1); } else if (!Good_obj(target)) { mux_sprintf(buf, LBUF_SIZE, T("*ILLEGAL*(#%d)"), target); } else { mux_sprintf(buf, LBUF_SIZE, T("%s(#%d)"), PureName(target), target); } return buf; }
void do_report(dbref executor, dbref caller, dbref enactor, int extra) { UNUSED_PARAMETER(caller); UNUSED_PARAMETER(enactor); UNUSED_PARAMETER(extra); char *buff = alloc_mbuf("do_report"); int nBin[NPERIODS]; int i; for (i = 0; i < NPERIODS; i++) { nBin[i] = 0; } CLinearTimeAbsolute ltaNow, ltaPlayer; ltaNow.GetLocal(); const int PeriodInSeconds = 28800; int iPlayer; DO_WHOLE_DB(iPlayer) { if (isPlayer(iPlayer)) { int aowner, aflags; char *player_last = atr_get(iPlayer, A_LAST, &aowner, &aflags); if (ltaPlayer.SetString(player_last)) { CLinearTimeDelta ltd(ltaPlayer, ltaNow); int ltdSeconds = ltd.ReturnSeconds(); int iBin = ltdSeconds / PeriodInSeconds; if (0 <= iBin && iBin < NPERIODS) { nBin[iBin]++; } } free_lbuf(player_last); } } int iHour, nSum = 0; notify(executor, "Day Hours Players Total"); for (i = 0, iHour = 0; i < NPERIODS; i++, iHour += 8) { nSum += nBin[i]; mux_sprintf(buff, MBUF_SIZE, "%3d %03d - %03d: %6d %6d", iHour/24 + 1, iHour, iHour+8, nBin[i], nSum); notify(executor, buff); } free_mbuf(buff); }
static bool ValidateHelpFileIndex(int iHelpfile) { if ( iHelpfile < 0 || mudstate.mHelpDesc <= iHelpfile) { UTF8 *buf = alloc_mbuf("do_help.LOG"); STARTLOG(LOG_BUGS, "BUG", "HELP"); mux_sprintf(buf, MBUF_SIZE, T("Unknown help file number: %d"), iHelpfile); log_text(buf); ENDLOG; free_mbuf(buf); return false; } return true; }
void do_txlevel ( dbref executor, dbref caller, dbref enactor, int eval, int key, int nargs, UTF8 *object, UTF8 *arg, const UTF8 *cargs[], int ncargs ) { UNUSED_PARAMETER(caller); UNUSED_PARAMETER(enactor); UNUSED_PARAMETER(eval); UNUSED_PARAMETER(cargs); UNUSED_PARAMETER(ncargs); if (!arg || !*arg) { notify_quiet(executor, T("I don\xE2\x80\x99t know what you want to set!")); return; } // Find thing. // dbref thing = match_controlled(executor, object); if (NOTHING == thing) { return; } UTF8 lname[9]; RLEVEL ormask = 0; RLEVEL andmask = ~ormask; while (*arg) { int negate = 0; while ( *arg && mux_isspace(*arg)) { arg++; } if (*arg == '!') { negate = 1; ++arg; } int i; for (i = 0; *arg && !mux_isspace(*arg); arg++) { if (i < 8) { lname[i++] = *arg; } } lname[i] = '\0'; if (!lname[0]) { if (negate) { notify(executor, T("You must specify a reality level to clear.")); } else { notify(executor, T("You must specify a reality level to set.")); } return; } RLEVEL result = find_rlevel(lname); if (!result) { notify(executor, T("No such reality level.")); continue; } if (negate) { andmask &= ~result; notify(executor, T("Cleared.")); } else { ormask |= result; notify(executor, T("Set.")); } } // Set the Tx Level. // UTF8 *buff = alloc_lbuf("do_rxlevel"); mux_sprintf(buff, LBUF_SIZE, T("%08X %08X"), RxLevel(thing), TxLevel(thing) & andmask | ormask); atr_add_raw(thing, A_RLEVEL, buff); free_lbuf(buff); }
// This Task assumes that pEntry is already unlinked from any lists it may // have been related to. // static void Task_RunQueueEntry(void *pEntry, int iUnused) { UNUSED_PARAMETER(iUnused); BQUE *point = (BQUE *)pEntry; dbref executor = point->executor; if ( Good_obj(executor) && !Going(executor)) { giveto(executor, mudconf.waitcost); mudstate.curr_enactor = point->enactor; mudstate.curr_executor = executor; a_Queue(Owner(executor), -1); point->executor = NOTHING; if (!Halted(executor)) { // Load scratch args. // for (int i = 0; i < MAX_GLOBAL_REGS; i++) { if (mudstate.global_regs[i]) { RegRelease(mudstate.global_regs[i]); mudstate.global_regs[i] = NULL; } mudstate.global_regs[i] = point->scr[i]; point->scr[i] = NULL; } char *command = point->comm; mux_assert(!mudstate.inpipe); mux_assert(mudstate.pipe_nest_lev == 0); mux_assert(mudstate.poutobj == NOTHING); mux_assert(!mudstate.pout); break_called = false; while ( command && !break_called) { mux_assert(!mudstate.poutnew); mux_assert(!mudstate.poutbufc); char *cp = parse_to(&command, ';', 0); if ( cp && *cp) { // Will command be piped? // if ( command && *command == '|' && mudstate.pipe_nest_lev < mudconf.ntfy_nest_lim) { command++; mudstate.pipe_nest_lev++; mudstate.inpipe = true; mudstate.poutnew = alloc_lbuf("process_command.pipe"); mudstate.poutbufc = mudstate.poutnew; mudstate.poutobj = executor; } else { mudstate.inpipe = false; mudstate.poutobj = NOTHING; } CLinearTimeAbsolute ltaBegin; ltaBegin.GetUTC(); MuxAlarm.Set(mudconf.max_cmdsecs); CLinearTimeDelta ltdUsageBegin = GetProcessorUsage(); char *log_cmdbuf = process_command(executor, point->caller, point->enactor, point->eval, false, cp, point->env, point->nargs); CLinearTimeAbsolute ltaEnd; ltaEnd.GetUTC(); if (MuxAlarm.bAlarmed) { notify(executor, "GAME: Expensive activity abbreviated."); s_Flags(point->enactor, FLAG_WORD1, Flags(point->enactor) | HALT); s_Flags(point->executor, FLAG_WORD1, Flags(point->executor) | HALT); halt_que(point->enactor, NOTHING); halt_que(executor, NOTHING); } MuxAlarm.Clear(); CLinearTimeDelta ltdUsageEnd = GetProcessorUsage(); CLinearTimeDelta ltd = ltdUsageEnd - ltdUsageBegin; db[executor].cpu_time_used += ltd; ltd = ltaEnd - ltaBegin; if (ltd > mudconf.rpt_cmdsecs) { STARTLOG(LOG_PROBLEMS, "CMD", "CPU"); log_name_and_loc(executor); char *logbuf = alloc_lbuf("do_top.LOG.cpu"); mux_sprintf(logbuf, LBUF_SIZE, " queued command taking %s secs (enactor #%d): ", ltd.ReturnSecondsString(4), point->enactor); log_text(logbuf); free_lbuf(logbuf); log_text(log_cmdbuf); ENDLOG; } } // Transition %| value. // if (mudstate.pout) { free_lbuf(mudstate.pout); mudstate.pout = NULL; } if (mudstate.poutnew) { *mudstate.poutbufc = '\0'; mudstate.pout = mudstate.poutnew; mudstate.poutnew = NULL; mudstate.poutbufc = NULL; } } // Clean up %| value. // if (mudstate.pout) { free_lbuf(mudstate.pout); mudstate.pout = NULL; } mudstate.pipe_nest_lev = 0; mudstate.inpipe = false; mudstate.poutobj = NOTHING; } } for (int i = 0; i < MAX_GLOBAL_REGS; i++) { if (point->scr[i]) { RegRelease(point->scr[i]); point->scr[i] = NULL; } if (mudstate.global_regs[i]) { RegRelease(mudstate.global_regs[i]); mudstate.global_regs[i] = NULL; } } MEMFREE(point->text); point->text = NULL; free_qentry(point); }
// --------------------------------------------------------------------------- // do_ps: tell executor what commands they have pending in the queue // void do_ps(dbref executor, dbref caller, dbref enactor, int eval, int key, char *target) { UNUSED_PARAMETER(caller); UNUSED_PARAMETER(enactor); UNUSED_PARAMETER(eval); char *bufp; dbref executor_targ, obj_targ; // Figure out what to list the queue for. // if ((key & PS_ALL) && !See_Queue(executor)) { notify(executor, NOPERM_MESSAGE); return; } if (!target || !*target) { obj_targ = NOTHING; if (key & PS_ALL) { executor_targ = NOTHING; } else { executor_targ = Owner(executor); if (!isPlayer(executor)) { obj_targ = executor; } } } else { executor_targ = Owner(executor); obj_targ = match_controlled(executor, target); if (obj_targ == NOTHING) { return; } if (key & PS_ALL) { notify(executor, "Can't specify a target and /all"); return; } if (isPlayer(obj_targ)) { executor_targ = obj_targ; obj_targ = NOTHING; } } key = key & ~PS_ALL; switch (key) { case PS_BRIEF: case PS_SUMM: case PS_LONG: break; default: notify(executor, "Illegal combination of switches."); return; } Show_lsaNow.GetUTC(); Total_SystemTasks = 0; Total_RunQueueEntry = 0; Shown_RunQueueEntry = 0; Total_SemaphoreTimeout = 0; Shown_SemaphoreTimeout = 0; Show_Player_Target = executor_targ; Show_Object_Target = obj_targ; Show_Key = key; Show_Player = executor; Show_bFirstLine = true; scheduler.TraverseOrdered(CallBack_ShowWait); Show_bFirstLine = true; scheduler.TraverseOrdered(CallBack_ShowSemaphore); #ifdef QUERY_SLAVE Show_bFirstLine = true; scheduler.TraverseOrdered(CallBack_ShowSQLQueries); #endif // QUERY_SLAVE if (Wizard(executor)) { notify(executor, "----- System Queue -----"); scheduler.TraverseOrdered(CallBack_ShowDispatches); } // Display stats. // bufp = alloc_mbuf("do_ps"); #ifdef QUERY_SLAVE mux_sprintf(bufp, MBUF_SIZE, "Totals: Wait Queue...%d/%d Semaphores...%d/%d SQL %d/%d", Shown_RunQueueEntry, Total_RunQueueEntry, Shown_SemaphoreTimeout, Total_SemaphoreTimeout, Shown_SQLTimeout, Total_SQLTimeout); #else mux_sprintf(bufp, MBUF_SIZE, "Totals: Wait Queue...%d/%d Semaphores...%d/%d", Shown_RunQueueEntry, Total_RunQueueEntry, Shown_SemaphoreTimeout, Total_SemaphoreTimeout); #endif // QUERY_SLAVE notify(executor, bufp); if (Wizard(executor)) { mux_sprintf(bufp, MBUF_SIZE, " System Tasks.....%d", Total_SystemTasks); notify(executor, bufp); } free_mbuf(bufp); }
static bool ReportTopic(dbref executor, struct help_entry *htab_entry, int iHelpfile, UTF8 *result) { UTF8 szTextFilename[SBUF_SIZE+8]; mux_sprintf(szTextFilename, sizeof(szTextFilename), T("%s.txt"), mudstate.aHelpDesc[iHelpfile].pBaseFilename); size_t offset = htab_entry->pos; FILE *fp; if (!mux_fopen(&fp, szTextFilename, T("rb"))) { STARTLOG(LOG_PROBLEMS, "HLP", "OPEN"); UTF8 *line = alloc_lbuf("ReportTopic.open"); mux_sprintf(line, LBUF_SIZE, T("Can\xE2\x80\x99t open %s for reading."), szTextFilename); log_text(line); free_lbuf(line); ENDLOG; return false; } DebugTotalFiles++; if (fseek(fp, static_cast<long>(offset), 0) < 0L) { STARTLOG(LOG_PROBLEMS, "HLP", "SEEK"); UTF8 *line = alloc_lbuf("ReportTopic.seek"); mux_sprintf(line, LBUF_SIZE, T("Seek error in file %s."), szTextFilename); log_text(line); free_lbuf(line); ENDLOG; if (fclose(fp) == 0) { DebugTotalFiles--; } return false; } UTF8 *line = alloc_lbuf("ReportTopic"); UTF8 *bp = result; bool bInTopicAliases = true; for (;;) { if ( fgets((char *)line, LBUF_SIZE - 2, fp) == NULL || '\0' == line[0]) { break; } if ('&' == line[0]) { if (bInTopicAliases) { continue; } else { break; } } bInTopicAliases = false; // Transform LF into CRLF to be telnet-friendly. // size_t len = strlen((char *)line); if ( 0 < len && '\n' == line[len-1] && ( 1 == len || '\r' != line[len-2])) { line[len-1] = '\r'; line[len ] = '\n'; line[++len] = '\0'; } bool bEval = mudstate.aHelpDesc[iHelpfile].bEval; if (bEval) { dbref executor_for_help = executor; if (Good_obj(mudconf.help_executor)) { executor_for_help = mudconf.help_executor; } mux_exec(line, len, result, &bp, executor_for_help, executor, executor, EV_NO_COMPRESS | EV_FIGNORE | EV_EVAL, NULL, 0); } else { safe_str(line, result, &bp); } } // Zap trailing CRLF if present. // if ( result < bp - 1 && '\r' == bp[-2] && '\n' == bp[-1]) { bp -= 2; } *bp = '\0'; if (fclose(fp) == 0) { DebugTotalFiles--; } free_lbuf(line); return true; }
static void helpindex_read(int iHelpfile) { helpindex_clean(iHelpfile); mudstate.aHelpDesc[iHelpfile].ht = new CHashTable; CHashTable *htab = mudstate.aHelpDesc[iHelpfile].ht; UTF8 szTextFilename[SBUF_SIZE+8]; mux_sprintf(szTextFilename, sizeof(szTextFilename), T("%s.txt"), mudstate.aHelpDesc[iHelpfile].pBaseFilename); FILE *fp; if (!mux_fopen(&fp, szTextFilename, T("rb"))) { STARTLOG(LOG_PROBLEMS, "HLP", "RINDX"); UTF8 *p = alloc_lbuf("helpindex_read.LOG"); mux_sprintf(p, LBUF_SIZE, T("Can\xE2\x80\x99t open %s for reading."), szTextFilename); log_text(p); free_lbuf(p); ENDLOG; return; } DebugTotalFiles++; size_t pos = 0; size_t nTopicOriginal = 0; UTF8 topic[TOPIC_NAME_LEN+1]; HelpIndex_Start(fp); while (HelpIndex_Read(&pos, &nTopicOriginal, topic)) { // Convert the entry to all lowercase letters and add all leftmost // substrings. // // Topic names which appear earlier in the help file have priority // over topics names which appear later in the help file. That is, // we do not associate prefixes with this topic if they have already // been used on a previous topic. // size_t nCased; UTF8 *pCased = mux_strlwr(topic, nCased); bool bOriginal = true; // First is the longest. for (size_t nTopic = nCased; 0 < nTopic; nTopic--) { // Avoid adding any entries with a trailing space. // if (mux_isspace(pCased[nTopic-1])) { continue; } struct help_entry *htab_entry = (struct help_entry *)hashfindLEN(pCased, nTopic, htab); if (htab_entry) { if (!bOriginal) { continue; } hashdeleteLEN(pCased, nTopic, htab); if (htab_entry->key) { MEMFREE(htab_entry->key); htab_entry->key = NULL; Log.tinyprintf(T("helpindex_read: duplicate %s entries for %s" ENDLINE), szTextFilename, pCased); } delete htab_entry; htab_entry = NULL; } try { htab_entry = new struct help_entry; } catch (...) { ; // Nothing. } if (htab_entry) { htab_entry->pos = pos; htab_entry->key = bOriginal ? StringCloneLen(pCased, nTopic) : NULL; bOriginal = false; hashaddLEN(pCased, nTopic, htab_entry, htab); } } } HelpIndex_End(); if (fclose(fp) == 0) { DebugTotalFiles--; } hashreset(htab); }
/* * --------------------------------------------------------------------------- * * Return an lbuf pointing to the object name and possibly the db# and flags */ UTF8 *unparse_object(dbref player, dbref target, bool obey_myopic, bool bAddColor) { UTF8 *buf = alloc_lbuf("unparse_object"); if (NOPERM <= target && target < 0) { mux_strncpy(buf, aszSpecialDBRefNames[-target], LBUF_SIZE-1); } else if (!Good_obj(target)) { mux_sprintf(buf, LBUF_SIZE, T("*ILLEGAL*(#%d)"), target); } else { bool exam; if (obey_myopic) { exam = MyopicExam(player, target); } else { exam = Examinable(player, target); } // Leave and extra 100 bytes for the dbref and flags at the end and // color at the beginning if necessary.. // mux_field fldName = StripTabsAndTruncate( Moniker(target), buf, LBUF_SIZE-100, LBUF_SIZE-100); UTF8 *bp = buf + fldName.m_byte; #if defined(FIRANMUX) if ( fldName.m_column == fldName.m_byte && bAddColor) { // There is no color in the name, so look for @color, or highlight. // UTF8 *buf2 = alloc_lbuf("unparse_object.color"); UTF8 *bp2 = buf2; UTF8 *pLetters = AcquireColorLetters(player, target); if (NULL != pLetters) { safe_str(LettersToBinary(pLetters), buf2, &bp2); free_lbuf(pLetters); pLetters = NULL; } else { safe_str((UTF8 *)COLOR_INTENSE, buf2, &bp2); } *bp = '\0'; safe_str(buf, buf2, &bp2); safe_str((UTF8 *)COLOR_RESET, buf2, &bp2); // Swap buffers. // free_lbuf(buf); buf = buf2; bp = bp2; } #else UNUSED_PARAMETER(bAddColor); #endif // FIRANMUX if ( exam || (Flags(target) & (CHOWN_OK | JUMP_OK | LINK_OK | DESTROY_OK)) || (Flags2(target) & ABODE)) { // Show everything. // UTF8 *fp = decode_flags(player, &(db[target].fs)); safe_str(T("(#"), buf, &bp); safe_ltoa(target, buf, &bp); safe_str(fp, buf, &bp); safe_chr(')', buf, &bp); free_sbuf(fp); } *bp = '\0'; } return buf; }