public Tick getAvailTickThread(Tickable E, long TICK_TIME, int tickID) { Tick tock = null; Tick almostTock = null; ThreadGroup grp = null; char threadGroupNum = Thread.currentThread().getThreadGroup().getName().charAt(0); for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) { almostTock = e.next(); if (almostTock != null) { if (almostTock.contains(E, tickID)) return null; if ((tock == null) && (almostTock.TICK_TIME == TICK_TIME) && (!almostTock.solitaryTicker) && (almostTock.numTickers() < TickableGroup.MAX_TICK_CLIENTS)) { grp = almostTock.getThreadGroup(); if ((grp != null) && (grp.getName().charAt(0) == threadGroupNum)) { tock = almostTock; } } } } if (tock != null) return tock; tock = new Tick(TICK_TIME); addTickGroup(tock); return tock; }
@Override public void run() { nextTickTime = System.currentTimeMillis() + tickTime; // final String oldThreadName=Thread.currentThread().getName(); try { currentThread = Thread.currentThread(); lastStart = System.currentTimeMillis(); lastClient = null; final boolean allSuspended = CMLib.threads().isAllSuspended(); if ((CMProps.getBoolVar(CMProps.Bool.MUDSTARTED)) && (!allSuspended)) { for (final Iterator<TickClient> i = tickers(); i.hasNext(); ) { final TickClient client = i.next(); lastClient = client; // if(client.getCurrentTickDown()<=1) // currentThread.setName(oldThreadName+":"+getName()+":"+client.getName()); if (client.tickTicker(false)) { delTicker(client); // cant do i.remove, its an streeset } } } } finally { lastStop = System.currentTimeMillis(); milliTotal += (lastStop - lastStart); tickTotal++; currentThread = null; // Thread.currentThread().setName(oldThreadName); } if (tickers.size() == 0) { if (CMLib.threads() instanceof ServiceEngine) ((ServiceEngine) CMLib.threads()).delTickGroup(this); } }
@Override public boolean invoke( MOB mob, List<String> commands, Physical givenTarget, boolean auto, int asLevel) { MOB target = CMLib.players().getLoadPlayer(CMParms.combine(commands, 0)); if (target == null) target = getTargetAnywhere(mob, commands, givenTarget, false, true, false); if (target == null) return false; final Archon_Record A = (Archon_Record) target.fetchEffect(ID()); if (A != null) { target.delEffect(A); if (target.playerStats() != null) target.playerStats().setLastUpdated(0); mob.tell(L("@x1 will no longer be recorded.", target.Name())); return true; } if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false; final boolean success = proficiencyCheck(mob, 0, auto); if (success) { final CMMsg msg = CMClass.getMsg( mob, target, this, CMMsg.MASK_MOVE | CMMsg.TYP_JUSTICE | (auto ? CMMsg.MASK_ALWAYS : 0), L("^F<S-NAME> begin(s) recording <T-NAMESELF>.^?")); CMLib.color().fixSourceFightColor(msg); if (mob.location().okMessage(mob, msg)) { mob.location().send(mob, msg); final String filename = "/" + target.Name() + System.currentTimeMillis() + ".log"; final CMFile file = new CMFile(filename, null, CMFile.FLAG_LOGERRORS); if (!file.canWrite()) { if (!CMSecurity.isASysOp(mob) || (CMSecurity.isASysOp(target))) Log.sysOut("Record", mob.Name() + " failed to start recording " + target.name() + "."); } else { if (!CMSecurity.isASysOp(mob) || (CMSecurity.isASysOp(target))) Log.sysOut( "Record", mob.Name() + " started recording " + target.name() + " to /" + filename + "."); final Archon_Record A2 = (Archon_Record) copyOf(); final Session F = (Session) CMClass.getCommon("FakeSession"); F.initializeSession(null, Thread.currentThread().getThreadGroup().getName(), filename); if (target.session() == null) target.setSession(F); A2.sess = F; target.addNonUninvokableEffect(A2); mob.tell(L("Enter RECORD @x1 again to stop recording.", target.Name())); } } } else return beneficialVisualFizzle( mob, target, L("<S-NAME> attempt(s) to hush <T-NAMESELF>, but fail(s).")); return success; }
public boolean activate() { if (thread == null) thread = new ThreadEngine.SupportThread( "THThreads" + Thread.currentThread().getThreadGroup().getName().charAt(0), MudHost.TIME_UTILTHREAD_SLEEP, this, CMSecurity.isDebugging("UTILITHREAD")); if (!thread.started) thread.start(); return true; }
public void run() { while (isAllSuspended()) try { Thread.sleep(2000); } catch (Exception e) { } if ((!CMSecurity.isDisabled("UTILITHREAD")) && (!CMSecurity.isDisabled("THREADTHREAD"))) { checkHealth(); Resources.removeResource("SYSTEM_HASHED_MASKS"); } }
public double memoryUse(Environmental E, int number) { double s = -1.0; try { int n = number; Object[] objs = new Object[n]; Environmental cl = E; Runtime rt = Runtime.getRuntime(); long m0 = rt.totalMemory() - rt.freeMemory(); System.gc(); Thread.sleep(500); for (int i = 0; i < n; ++i) objs[i] = E = (Environmental) cl.copyOf(); System.gc(); Thread.sleep(1000); long m1 = rt.totalMemory() - rt.freeMemory(); long dm = m1 - m0; s = (double) dm / (double) n; if (s < 0.0) return memoryUse(E, number); } catch (Exception e) { return -1; } return s; }
public boolean shutdown() { // int numTicks=tickGroup.size(); int which = 0; while (ticks.size() > 0) { // Log.sysOut("ServiceEngine","Shutting down all tick "+which+"/"+numTicks+"..."); Tick tock = ticks.getFirst(); if (tock != null) { CMProps.setUpAllLowVar( CMProps.SYSTEM_MUDSTATUS, "Shutting down...shutting down Service Engine: killing Tick#" + tock.getCounter() + ": " + tock.getStatus()); tock.shutdown(); } try { Thread.sleep(100); } catch (Exception e) { } which++; } CMProps.setUpAllLowVar( CMProps.SYSTEM_MUDSTATUS, "Shutting down...shutting down Service Engine: " + ID() + ": thread shutdown"); thread.shutdown(); // force final time tick! Vector timeObjects = new Vector(); for (Enumeration e = CMLib.map().areas(); e.hasMoreElements(); ) { Area A = ((Area) e.nextElement()); if (!timeObjects.contains(A.getTimeObj())) timeObjects.addElement(A.getTimeObj()); } CMProps.setUpAllLowVar( CMProps.SYSTEM_MUDSTATUS, "Shutting down...shutting down Service Engine: " + ID() + ": saving time objects"); for (int t = 0; t < timeObjects.size(); t++) ((TimeClock) timeObjects.elementAt(t)).save(); Log.sysOut("ServiceEngine", "Shutdown complete."); return true; }
public boolean execute(MOB mob, Vector commands, int metaFlags) throws java.io.IOException { if (mob.session() == null) return true; PlayerStats pstats = mob.playerStats(); if (pstats == null) return true; if ((commands != null) && (commands.size() > 1) && (commands.elementAt(1) instanceof String) && (CMProps.getVar(CMProps.SYSTEM_MAILBOX).length() > 0)) { String name = CMParms.combine(commands, 1); if (name.equalsIgnoreCase("BOX")) { String journalName = CMProps.getVar(CMProps.SYSTEM_MAILBOX); Vector<JournalsLibrary.JournalEntry> msgs = CMLib.database().DBReadJournalMsgs(journalName); while ((mob.session() != null) && (!mob.session().killFlag())) { Vector mymsgs = new Vector(); StringBuffer messages = new StringBuffer( "^X" + CMStrings.padCenter(mob.Name() + "'s MailBox", 48) + "^?^.\n\r"); messages.append( "^X### " + CMStrings.padRight("From", 15) + " " + CMStrings.padRight("Date", 20) + " Subject^?^.\n\r"); for (int num = 0; num < msgs.size(); num++) { JournalsLibrary.JournalEntry thismsg = msgs.elementAt(num); String to = (String) thismsg.to; if (to.equalsIgnoreCase("ALL") || to.equalsIgnoreCase(mob.Name()) || (to.toUpperCase().trim().startsWith("MASK=") && CMLib.masking().maskCheck(to.trim().substring(5), mob, true))) { mymsgs.addElement(thismsg); messages.append( CMStrings.padRight("" + mymsgs.size(), 4) + CMStrings.padRight((thismsg.from), 16) + CMStrings.padRight(CMLib.time().date2String(thismsg.date), 21) + (thismsg.subj) + "\n\r"); } } if ((mymsgs.size() == 0) || (CMath.bset(metaFlags, Command.METAFLAG_POSSESSED)) || (CMath.bset(metaFlags, Command.METAFLAG_AS))) { if (CMath.bset(mob.getBitmap(), MOB.ATT_AUTOFORWARD)) mob.tell( "You have no email waiting, but then, it's probably been forwarded to you already."); else mob.tell("You have no email waiting."); return false; } Session S = mob.session(); try { if (S != null) S.snoopSuspension(1); mob.tell(messages.toString()); } finally { if (S != null) S.snoopSuspension(-1); } String s = mob.session().prompt("Enter a message #", ""); if ((!CMath.isInteger(s)) || (mob.session().killFlag())) return false; int num = CMath.s_int(s); if ((num <= 0) || (num > mymsgs.size())) mob.tell("That is not a valid number."); else while ((mob.session() != null) && (!mob.session().killFlag())) { JournalsLibrary.JournalEntry thismsg = (JournalsLibrary.JournalEntry) mymsgs.elementAt(num - 1); String key = thismsg.key; String from = thismsg.from; String date = CMLib.time().date2String(thismsg.date); String subj = thismsg.subj; String message = thismsg.msg; messages = new StringBuffer(""); messages.append("^XMessage :^?^." + num + "\n\r"); messages.append("^XFrom :^?^." + from + "\n\r"); messages.append("^XDate :^?^." + date + "\n\r"); messages.append("^XSubject :^?^." + subj + "\n\r"); messages.append("^X------------------------------------------------^?^.\n\r"); messages.append(message + "\n\r\n\r"); try { if (S != null) S.snoopSuspension(1); mob.tell(messages.toString()); } finally { if (S != null) S.snoopSuspension(-1); } s = mob.session() .choose("Would you like to D)elete, H)old, or R)eply (D/H/R)? ", "DHR", "H"); if (s.equalsIgnoreCase("H")) break; if (s.equalsIgnoreCase("R")) { if ((from.length() > 0) && (!from.equals(mob.Name())) && (!from.equalsIgnoreCase("BOX")) && (CMLib.players().getLoadPlayer(from) != null)) execute(mob, CMParms.makeVector(getAccessWords()[0], from), metaFlags); else mob.tell("You can not reply to this email."); } else if (s.equalsIgnoreCase("D")) { CMLib.database().DBDeleteJournal(journalName, key); msgs.remove(thismsg); mob.tell("Deleted."); break; } } } } else { MOB M = CMLib.players().getLoadPlayer(name); if (M == null) { mob.tell( "There is no player called '" + name + "' to send email to. If you were trying to read your mail, try EMAIL BOX. If you were trying to change your email address, just enter EMAIL without any parameters."); return false; } if (!CMath.bset(M.getBitmap(), MOB.ATT_AUTOFORWARD)) { if (!mob.session().confirm("Send email to '" + M.Name() + "' (Y/n)?", "Y")) return false; } else { if (!mob.session() .confirm( "Send email to '" + M.Name() + "', even though their AUTOFORWARD is turned off (y/N)?", "N")) return false; } if (CMProps.getIntVar(CMProps.SYSTEMI_MAXMAILBOX) > 0) { int count = CMLib.database() .DBCountJournal(CMProps.getVar(CMProps.SYSTEM_MAILBOX), null, M.Name()); if (count >= CMProps.getIntVar(CMProps.SYSTEMI_MAXMAILBOX)) { mob.tell(M.Name() + "'s mailbox is full."); return false; } } String subject = mob.session().prompt("Email Subject: ", "").trim(); if (subject.length() == 0) { mob.tell("Aborted"); return false; } String message = mob.session().prompt("Enter your message\n\r: ", "").trim(); if (message.trim().length() == 0) { mob.tell("Aborted"); return false; } message += "\n\r\n\rThis message was sent through the " + CMProps.getVar(CMProps.SYSTEM_MUDNAME) + " mail server at " + CMProps.getVar(CMProps.SYSTEM_MUDDOMAIN) + ", port" + CMProps.getVar(CMProps.SYSTEM_MUDPORTS) + ". Please contact the administrators regarding any abuse of this system.\n\r"; CMLib.database() .DBWriteJournal( CMProps.getVar(CMProps.SYSTEM_MAILBOX), mob.Name(), M.Name(), subject, message); mob.tell("Your email has been sent."); return true; } } if ((pstats.getEmail() == null) || (pstats.getEmail().length() == 0)) mob.session().println("\n\rYou have no email address on file for this character."); else { if (commands == null) return true; String change = mob.session() .prompt( "You currently have '" + pstats.getEmail() + "' set as the email address for this character.\n\rChange it (y/N)?", "N"); if (change.toUpperCase().startsWith("N")) return false; } if ((CMProps.getVar(CMProps.SYSTEM_EMAILREQ).toUpperCase().startsWith("PASS")) && (commands != null) && (CMProps.getVar(CMProps.SYSTEM_MAILBOX).length() > 0)) mob.session() .println( "\n\r** Changing your email address will cause you to be logged off, and a new password to be generated and emailed to the new address. **\n\r"); String newEmail = mob.session().prompt("New E-mail Address:"); if (newEmail == null) return false; newEmail = newEmail.trim(); if (!CMProps.getVar(CMProps.SYSTEM_EMAILREQ).toUpperCase().startsWith("OPTION")) { if (newEmail.length() < 6) return false; if (newEmail.indexOf("@") < 0) return false; String confirmEmail = mob.session() .prompt("Confirm that '" + newEmail + "' is correct by re-entering.\n\rRe-enter:"); if (confirmEmail == null) return false; confirmEmail = confirmEmail.trim(); if (confirmEmail.length() == 0) return false; if (!(newEmail.equalsIgnoreCase(confirmEmail))) return false; } pstats.setEmail(newEmail); CMLib.database().DBUpdateEmail(mob); if ((commands != null) && (CMProps.getVar(CMProps.SYSTEM_EMAILREQ).toUpperCase().startsWith("PASS")) && (CMProps.getVar(CMProps.SYSTEM_MAILBOX).length() > 0)) { String password = ""; for (int i = 0; i < 6; i++) password += (char) ('a' + CMLib.dice().roll(1, 26, -1)); pstats.setPassword(password); CMLib.database().DBUpdatePassword(mob.Name(), password); CMLib.database() .DBWriteJournal( CMProps.getVar(CMProps.SYSTEM_MAILBOX), mob.Name(), mob.Name(), "Password for " + mob.Name(), "Your new password for " + mob.Name() + " is: " + pstats.password() + "\n\rYou can login by pointing your mud client at " + CMProps.getVar(CMProps.SYSTEM_MUDDOMAIN) + " port(s):" + CMProps.getVar(CMProps.SYSTEM_MUDPORTS) + ".\n\rYou may use the PASSWORD command to change it once you are online."); mob.tell("You will receive an email with your new password shortly. Goodbye."); if (mob.session() != null) { try { Thread.sleep(1000); } catch (Exception e) { } mob.session().kill(false, false, false); } } return true; }
public void checkHealth() { long lastDateTime = System.currentTimeMillis() - (5 * TimeManager.MILI_MINUTE); long longerDateTime = System.currentTimeMillis() - (120 * TimeManager.MILI_MINUTE); thread.status("checking"); thread.status("checking tick groups."); DVector orderedDeaths = new DVector(3); try { Tick almostTock = null; for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) { almostTock = e.next(); if ((almostTock.awake) && (almostTock.lastStop < lastDateTime)) { TockClient client = almostTock.lastClient; if (client == null) insertOrderDeathInOrder( orderedDeaths, 0, "LOCKED GROUP " + almostTock.getCounter() + "! No further information.", almostTock); else if ((!CMath.bset(client.tickID, Tickable.TICKID_LONGERMASK)) || (almostTock.lastStop < longerDateTime)) { if (client.clientObject == null) insertOrderDeathInOrder( orderedDeaths, 0, "LOCKED GROUP " + almostTock.getCounter() + ": NULL @" + CMLib.time().date2String(client.lastStart) + ", tickID " + client.tickID, almostTock); else { StringBuffer str = null; Tickable obj = client.clientObject; long code = client.clientObject.getTickStatus(); String codeWord = CMLib.threads().getTickStatusSummary(client.clientObject); String msg = null; if (obj instanceof Environmental) str = new StringBuffer( "LOCKED GROUP " + almostTock.getCounter() + " : " + obj.name() + " (" + ((Environmental) obj).ID() + ") @" + CMLib.time().date2String(client.lastStart) + ", status(" + code + " (" + codeWord + "), tickID " + client.tickID); else str = new StringBuffer( "LOCKED GROUP " + almostTock.getCounter() + ": " + obj.name() + ", status(" + code + " (" + codeWord + ") @" + CMLib.time().date2String(client.lastStart) + ", tickID " + client.tickID); if ((obj instanceof MOB) && (((MOB) obj).location() != null)) msg = str.toString() + " in " + ((MOB) obj).location().roomID(); else if ((obj instanceof Item) && (((Item) obj).owner() != null) && (((Item) obj).owner() instanceof Room)) msg = str.toString() + " in " + ((Room) ((Item) obj).owner()).roomID(); else if ((obj instanceof Item) && (((Item) obj).owner() != null) && (((Item) obj).owner() instanceof MOB)) msg = str.toString() + " owned by " + ((MOB) ((Item) obj).owner()).name(); else if (obj instanceof Room) msg = str.toString() + " is " + ((Room) obj).roomID(); else msg = str.toString(); insertOrderDeathInOrder(orderedDeaths, client.lastStart, msg, almostTock); } } // no isDEBUGGING check -- just always let her rip. thread.debugDumpStack(almostTock); } } } catch (java.util.NoSuchElementException e) { } for (int i = 0; i < orderedDeaths.size(); i++) Log.errOut(thread.getName(), (String) orderedDeaths.elementAt(i, 2)); thread.status("killing tick groups."); for (int x = 0; x < orderedDeaths.size(); x++) { Tick almostTock = (Tick) orderedDeaths.elementAt(x, 3); Vector objs = new Vector(); try { for (Iterator e = almostTock.tickers(); e.hasNext(); ) objs.addElement(e.next()); } catch (NoSuchElementException e) { } almostTock.shutdown(); if (CMLib.threads() instanceof ServiceEngine) ((ServiceEngine) CMLib.threads()).delTickGroup(almostTock); for (int i = 0; i < objs.size(); i++) { TockClient c = (TockClient) objs.elementAt(i); CMLib.threads().startTickDown(c.clientObject, c.tickID, c.reTickDown); } } thread.status("Checking mud threads"); for (int m = 0; m < CMLib.hosts().size(); m++) { Vector badThreads = ((MudHost) CMLib.hosts().elementAt(m)).getOverdueThreads(); if (badThreads.size() > 0) { for (int b = 0; b < badThreads.size(); b++) { Thread T = (Thread) badThreads.elementAt(b); String threadName = T.getName(); if (T instanceof Tickable) threadName = ((Tickable) T).name() + " (" + ((Tickable) T).ID() + "): " + ((Tickable) T).getTickStatus(); thread.status("Killing " + threadName); Log.errOut("Killing stray thread: " + threadName); CMLib.killThread(T, 100, 1); } } } thread.status("Done checking threads"); }