Example #1
0
  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;
  }
Example #2
0
  @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);
    }
  }
Example #3
0
  @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;
  }
Example #4
0
 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;
 }
Example #5
0
  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");
    }
  }
Example #6
0
 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;
 }
Example #7
0
 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;
 }
Example #8
0
  @Override
  public String runMacro(HTTPRequest httpReq, String parm) {
    final java.util.Map<String, String> parms = parseParms(parm);
    final String last = httpReq.getUrlParameter("JOURNAL");
    if (last == null) return " @break@";
    boolean securityOverride = false;
    if ((Thread.currentThread() instanceof CWThread)
        && CMath.s_bool(((CWThread) Thread.currentThread()).getConfig().getMiscProp("ADMIN"))
        && parms.containsKey("ALLFORUMJOURNALS")) securityOverride = true;

    final MOB M = Authenticate.getAuthenticatedMob(httpReq);
    if ((!securityOverride)
        && (CMLib.journals().isArchonJournalName(last))
        && ((M == null) || (!CMSecurity.isASysOp(M)))) return " @break@";

    final Clan setClan = CMLib.clans().getClan(httpReq.getUrlParameter("CLAN"));
    final JournalsLibrary.ForumJournal journal = CMLib.journals().getForumJournal(last, setClan);
    if (journal == null) return " @break@";

    final StringBuffer str = new StringBuffer("");
    if (parms.containsKey("ISSMTPFORWARD")) {
      @SuppressWarnings("unchecked")
      final TreeMap<String, JournalsLibrary.SMTPJournal> set =
          (TreeMap<String, JournalsLibrary.SMTPJournal>)
              Resources.getResource("SYSTEM_SMTP_JOURNALS");
      final JournalsLibrary.SMTPJournal entry =
          (set != null) ? set.get(last.toUpperCase().trim()) : null;
      final String email =
          ((M != null) && (M.playerStats() != null) && (M.playerStats().getEmail() != null))
              ? M.playerStats().getEmail()
              : "";
      str.append(
              ((entry != null) && (email.length() > 0)) ? Boolean.toString(entry.forward) : "false")
          .append(", ");
    }

    if (parms.containsKey("ISSMTPSUBSCRIBER")) {
      final Map<String, List<String>> lists =
          Resources.getCachedMultiLists("mailinglists.txt", true);
      final List<String> mylist = lists.get(last);
      str.append(
              ((mylist != null) && (M != null))
                  ? Boolean.toString(mylist.contains(M.Name()))
                  : "false")
          .append(", ");
    }

    if (parms.containsKey("SMTPADDRESS")) {
      @SuppressWarnings("unchecked")
      final TreeMap<String, JournalsLibrary.SMTPJournal> set =
          (TreeMap<String, JournalsLibrary.SMTPJournal>)
              Resources.getResource("SYSTEM_SMTP_JOURNALS");
      final JournalsLibrary.SMTPJournal entry =
          (set != null) ? set.get(last.toUpperCase().trim()) : null;
      if ((entry != null) && (entry.forward)) {
        str.append(entry.name.replace(' ', '_') + "@" + CMProps.getVar(CMProps.Str.MUDDOMAIN))
            .append(", ");
      }
    }

    if (parms.containsKey("CANADMIN") || parms.containsKey("ISADMIN"))
      str.append("" + journal.authorizationCheck(M, ForumJournalFlags.ADMIN)).append(", ");

    if (parms.containsKey("CANPOST"))
      str.append("" + journal.authorizationCheck(M, ForumJournalFlags.POST)).append(", ");

    if (parms.containsKey("CANREAD"))
      str.append("" + journal.authorizationCheck(M, ForumJournalFlags.READ)).append(", ");

    if (parms.containsKey("CANREPLY"))
      str.append("" + journal.authorizationCheck(M, ForumJournalFlags.REPLY)).append(", ");

    if (parms.containsKey("ADMINMASK")) str.append("" + journal.adminMask()).append(", ");

    if (parms.containsKey("READMASK")) str.append("" + journal.readMask()).append(", ");

    if (parms.containsKey("POSTMASK")) str.append("" + journal.postMask()).append(", ");

    if (parms.containsKey("REPLYMASK")) str.append("" + journal.replyMask()).append(", ");

    if (parms.containsKey("ID")) str.append("" + journal.NAME()).append(", ");

    if (parms.containsKey("NAME")) str.append("" + journal.NAME()).append(", ");

    if (parms.containsKey("EXPIRE")) str.append("").append(", ");

    final JournalsLibrary.JournalSummaryStats stats = CMLib.journals().getJournalStats(journal);
    if (stats == null) return " @break@";

    if (parms.containsKey("POSTS")) str.append("" + stats.posts).append(", ");

    if (parms.containsKey("THREADS")) str.append("" + stats.threads).append(", ");

    if (parms.containsKey("SHORTDESC")) str.append("" + stats.shortIntro).append(", ");

    if (parms.containsKey("LONGDESC")) str.append("" + stats.longIntro).append(", ");

    if (parms.containsKey("IMAGEPATH")) {
      if ((stats.imagePath == null) || (stats.imagePath.trim().length() == 0))
        str.append(L("images/lilcm.jpg")).append(", ");
      else str.append("" + stats.threads).append(", ");
    }

    String strstr = str.toString();
    if (strstr.endsWith(", ")) strstr = strstr.substring(0, strstr.length() - 2);
    return clearWebMacros(strstr);
  }
Example #9
0
  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");
  }