public void run() { long nextStart = System.currentTimeMillis(); try { while (!dead) { long timeToSleep = nextStart - System.currentTimeMillis(); if (timeToSleep > 10) Thread.sleep(timeToSleep); nextStart += Tickable.TIME_TICK; if ((CMProps.Bools.MUDSTARTED.property()) && (!CMLib.threads().isAllSuspended())) { globalTickCount++; for (Iterator<Exit> iter = exits.iterator(); iter.hasNext(); ) { Exit exit = iter.next(); try { if (!exit.tick(globalTickCount)) exits.remove(exit); } catch (Exception e) { Log.errOut("ServiceEngine", e.toString()); } } for (Iterator<TimeClock> iter = clocks.iterator(); iter.hasNext(); ) { TimeClock clock = iter.next(); try { if (!clock.tick(globalTickCount)) clocks.remove(clock); } catch (Exception e) { Log.errOut("ServiceEngine", e.toString()); } } } } } catch (InterruptedException e) { } }
/* public String tickInfo(String which) { int grpstart=-1; for(int i=0;i<which.length();i++) if(Character.isDigit(which.charAt(i))) { grpstart=i; break; } if(which.equalsIgnoreCase("tickGroupSize")) return ""+ticks.size(); else if(which.toLowerCase().startsWith("tickerssize")) { if(grpstart<0) return""; int group=CMath.s_int(which.substring(grpstart)); if((group>=0)&&(group<ticks.size())) return ""+((Tick)ticks.get(group)).numTickers(); return ""; } int group=-1; int client=-1; int clistart=which.indexOf("-"); if((grpstart>=0)&&(clistart>grpstart)) { group=CMath.s_int(which.substring(grpstart,clistart)); client=CMath.s_int(which.substring(clistart+1)); } if((group<0)||(client<0)||(group>=ticks.size())) return ""; Tick almostTock=(Tick)ticks.get(group); if(client>=almostTock.numTickers()) return ""; TockClient C=null; almostTock.fetchTickerByIndex(client); if(C==null) return ""; if(which.toLowerCase().startsWith("tickername")) { Tickable E=C.clientObject; if(E instanceof Room) return E.ID()+((Room)E).saveNum(); if(E!=null) return E.ID(); return "!NULL!"; } else if(which.toLowerCase().startsWith("tickerstatus")) return ((C.clientObject==null)?"":(""+C.clientObject.getTickStatus())); return ""; } */ public boolean shutdown() { // int numTicks=tickGroup.size(); /*while(ticks.size()>0) { //Log.sysOut("ServiceEngine","Shutting down all tick "+which+"/"+numTicks+"..."); Tick tock=ticks.first(); if(tock!=null) { CMProps.Strings.MUDSTATUS.setProperty("Shutting down...shutting down Service Engine: killing Tick#" + tock.tickObjectCounter+": "+tock.getStatus()); tock.shutdown(); } try{Thread.sleep(100);}catch(Exception e){} }*/ while (areas.size() > 0) { TickArea tock = areas.first(); if (tock != null) { CMProps.Strings.MUDSTATUS.setProperty( "Shutting down...shutting down Service Engine: killing Area#" + tock.tickObjectCounter + ": " + tock.clientObject.getTickStatus()); tock.shutdown(); } try { Thread.sleep(100); } catch (Exception e) { } } CMProps.Strings.MUDSTATUS.setProperty( "Shutting down...shutting down Service Engine: " + ID() + ": thread shutdown"); thread.shutdown(); Log.sysOut("ServiceEngine", "Shutdown complete."); 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 void run() { while (isSuspended) try { Thread.sleep(2000); } catch (Exception e) { } if ((!CMSecurity.isDisabled("UTILITHREAD")) && (!CMSecurity.isDisabled("THREADTHREAD"))) { checkHealth(); // Resources.removeResource("SYSTEM_HASHED_MASKS"); // NOTE: Could use a ReferenceQueue to clean up gced references in the SYSTEM_HASHED_MASKS // hashtable still. } }
public void run() { while (true) { try { while (!tickActQueue.isEmpty()) { awake = false; TickActer next = tickActQueue.first(); long timeToSleep = next.nextAct() - System.currentTimeMillis(); if (timeToSleep > 0) Thread.sleep(timeToSleep); awake = true; nextTicker: if ((CMProps.Bools.MUDSTARTED.property()) && (!isSuspended)) { if (!tickActQueue.remove(next)) break nextTicker; CMClass.threadPool.execute(next); } } } /*try { next.tickAct(); } catch(Exception t) { Log.errOut("ServiceEngine",t); }*/ catch (InterruptedException ioe) { } // If it was interrupted, it is most likely because we need to wake up for a new early // ticker, or the previous new ticker got baleeted. // Interruptions will only come if the thread is sleeping though. // NOTE: tickAct() should NEVER call a sleep (nor take any significant amount of time // anyways)! if (dead) { awake = false; break; } synchronized (tickActQueue) { while (tickActQueue.isEmpty()) try { tickActQueue.wait(); } catch (InterruptedException ioe) { } } } }
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; }