예제 #1
0
 public MOB getMobPossessingAnother(MOB mob) {
   if (mob == null) return null;
   Session S = null;
   MOB M = null;
   for (int s = 0; s < CMLib.sessions().size(); s++) {
     S = CMLib.sessions().elementAt(s);
     if (S != null) {
       M = S.mob();
       if ((M != null) && (M.soulMate() == mob)) return M;
     }
   }
   return null;
 }
예제 #2
0
  @Override
  public boolean invoke(MOB mob, Vector commands, Physical givenTarget, boolean auto, int asLevel) {
    if (CMParms.combine(commands, 0).equalsIgnoreCase("auto")) {
      DATA.clear();
      IPS.clear();
      final Hashtable<String, List<MOB>> ipes = new Hashtable<String, List<MOB>>();
      for (final Session S : CMLib.sessions().localOnlineIterable()) {
        if ((S.getAddress().length() > 0) && (S.mob() != null)) {
          List V = ipes.get(S.getAddress());
          if (V == null) {
            V = new Vector();
            ipes.put(S.getAddress(), V);
          }
          if (!V.contains(S.mob())) V.add(S.mob());
        }
      }
      final StringBuffer rpt = new StringBuffer("");
      for (final Enumeration e = ipes.keys(); e.hasMoreElements(); ) {
        final String addr = (String) e.nextElement();
        final List<MOB> names = ipes.get(addr);
        if (names.size() > 1) {
          IPS.put(addr, names);
          rpt.append("Watch #" + (IPS.size()) + " added: ");
          for (int n = 0; n < names.size(); n++) {
            final MOB MN = names.get(n);
            if (MN.fetchEffect(ID()) == null) {
              final Ability A = (Ability) copyOf();
              MN.addNonUninvokableEffect(A);
              A.setSavable(false);
            }
            rpt.append(MN.Name() + " ");
          }
          rpt.append("\n\r");
        }
      }
      if (rpt.length() == 0)
        rpt.append("No users with duplicate IDs found.  Try MULTIWATCH ADD name1 name2 ... ");
      mob.tell(rpt.toString());
      return true;
    } else if (CMParms.combine(commands, 0).equalsIgnoreCase("stop")) {
      boolean foundLegacy = false;
      for (final Session S : CMLib.sessions().localOnlineIterable()) {
        if ((S != null) && (S.mob() != null) && (S.mob().fetchEffect(ID()) != null)) {
          foundLegacy = true;
          break;
        }
      }
      if ((DATA.size() == 0) && (IPS.size() == 0) && (!foundLegacy)) {
        mob.tell(L("Multiwatch is already off."));
        return false;
      }
      for (final Enumeration<List<MOB>> e = IPS.elements(); e.hasMoreElements(); ) {
        final List<MOB> V = e.nextElement();
        for (int v = 0; v < V.size(); v++) {
          final MOB M = V.get(v);
          final Ability A = M.fetchEffect(ID());
          if (A != null) M.delEffect(A);
        }
      }
      for (final Session S : CMLib.sessions().localOnlineIterable()) {
        if ((S != null) && (S.mob() != null)) {
          final MOB M = S.mob();
          final Ability A = M.fetchEffect(ID());
          if (A != null) M.delEffect(A);
        }
      }
      mob.tell(L("Multiplay watcher is now turned off."));
      DATA.clear();
      IPS.clear();
      return true;
    } else if ((commands.size() > 1)
        && ((String) commands.firstElement()).equalsIgnoreCase("add")) {
      final Vector V = new Vector();
      for (int i = 1; i < commands.size(); i++) {
        final String name = (String) commands.elementAt(i);
        final MOB M = CMLib.players().getPlayer(name);
        if ((M.session() != null) && (CMLib.flags().isInTheGame(M, true))) V.addElement(M);
        else mob.tell(L("'@x1' is not online.", name));
      }
      if (V.size() > 1) {
        for (int n = 0; n < V.size(); n++) {
          final MOB MN = (MOB) V.elementAt(n);
          if (MN.fetchEffect(ID()) == null) {
            final Ability A = (Ability) copyOf();
            MN.addNonUninvokableEffect(A);
            A.setSavable(false);
          }
        }
        IPS.put("MANUAL" + (IPS.size() + 1), V);
        mob.tell(L("Manual Watch #@x1 added.", "" + IPS.size()));
      }
      return true;
    } else if ((commands.size() == 0) && (DATA.size() > 0) && (IPS.size() > 0)) {
      final StringBuffer report = new StringBuffer("");
      for (final Enumeration<String> e = IPS.keys(); e.hasMoreElements(); ) {
        final String key = e.nextElement();
        int sync = 0;
        final List<MOB> V = IPS.get(key);
        for (int v = 0; v < V.size(); v++) {
          final MOB M = V.get(v);
          final int data[] = DATA.get(M);
          if (data != null) sync += data[DATA_SYNCHROFOUND];
        }
        report.append("^x" + key + "^?^., Syncs: " + sync + "\n\r");
        report.append(
            CMStrings.padRight(L("Name"), 25)
                + CMStrings.padRight(L("Speech"), 15)
                + CMStrings.padRight(L("Socials"), 15)
                + CMStrings.padRight(L("CMD"), 10)
                + CMStrings.padRight(L("ORDERS"), 10)
                + "\n\r");
        for (int v = 0; v < V.size(); v++) {
          final MOB M = V.get(v);
          int data[] = DATA.get(M);
          if (data == null) data = new int[DATA_TOTAL];
          report.append(CMStrings.padRight(M.Name(), 25));
          report.append(
              CMStrings.padRight(
                  data[DATA_GOODSPEECH] + "/" + data[DATA_DIRSPEECH] + "/" + data[DATA_ANYSPEECH],
                  15));
          report.append(
              CMStrings.padRight(
                  data[DATA_GOODSOCIAL] + "/" + data[DATA_DIRSOCIAL] + "/" + data[DATA_ANYSOCIAL],
                  15));
          report.append(CMStrings.padRight(data[DATA_TYPEDCOMMAND] + "", 10));
          report.append(CMStrings.padRight(data[DATA_ORDER] + "", 10));
          report.append("\n\r");
        }
        report.append("\n\r");
      }

      mob.tell(report.toString());
      return true;
    } else {
      mob.tell(L("Try MULTIWATCH AUTO, MULTIWATCH STOP, or MULTIWATCH ADD name1 name2.."));
      return false;
    }
  }
예제 #3
0
  public String systemReport(String itemCode) {
    long totalMOBMillis = 0;
    long totalMOBTicks = 0;
    long topMOBMillis = 0;
    long topMOBTicks = 0;
    MOB topMOBClient = null;
    for (int s = 0; s < CMLib.sessions().size(); s++) {
      Session S = CMLib.sessions().elementAt(s);
      totalMOBMillis += S.getTotalMillis();
      totalMOBTicks += S.getTotalTicks();
      if (S.getTotalMillis() > topMOBMillis) {
        topMOBMillis = S.getTotalMillis();
        topMOBTicks = S.getTotalTicks();
        topMOBClient = S.mob();
      }
    }

    if (itemCode.equalsIgnoreCase("totalMOBMillis")) return "" + totalMOBMillis;
    else if (itemCode.equalsIgnoreCase("totalMOBMillisTime"))
      return CMLib.english().returnTime(totalMOBMillis, 0);
    else if (itemCode.equalsIgnoreCase("totalMOBMillisTimePlusAverage"))
      return CMLib.english().returnTime(totalMOBMillis, totalMOBTicks);
    else if (itemCode.equalsIgnoreCase("totalMOBTicks")) return "" + totalMOBTicks;
    else if (itemCode.equalsIgnoreCase("topMOBMillis")) return "" + topMOBMillis;
    else if (itemCode.equalsIgnoreCase("topMOBMillisTime"))
      return CMLib.english().returnTime(topMOBMillis, 0);
    else if (itemCode.equalsIgnoreCase("topMOBMillisTimePlusAverage"))
      return CMLib.english().returnTime(topMOBMillis, topMOBTicks);
    else if (itemCode.equalsIgnoreCase("topMOBTicks")) return "" + topMOBTicks;
    else if (itemCode.equalsIgnoreCase("topMOBClient")) {
      if (topMOBClient != null) return topMOBClient.Name();
      return "";
    }

    int totalTickers = 0;
    long totalMillis = 0;
    long totalTicks = 0;
    int topGroupNumber = -1;
    long topGroupMillis = -1;
    long topGroupTicks = 0;
    long topObjectMillis = -1;
    long topObjectTicks = 0;
    int topObjectGroup = 0;
    Tickable topObjectClient = null;
    int num = 0;
    Tick almostTock = null;
    for (Iterator<Tick> e = tickGroups(); e.hasNext(); ) {
      almostTock = e.next();
      totalTickers += almostTock.numTickers();
      totalMillis += almostTock.milliTotal;
      totalTicks += almostTock.tickTotal;
      if (almostTock.milliTotal > topGroupMillis) {
        topGroupMillis = almostTock.milliTotal;
        topGroupTicks = almostTock.tickTotal;
        topGroupNumber = num;
      }
      try {
        for (Iterator et = almostTock.tickers(); et.hasNext(); ) {
          TockClient C = (TockClient) et.next();
          if (C.milliTotal > topObjectMillis) {
            topObjectMillis = C.milliTotal;
            topObjectTicks = C.tickTotal;
            topObjectClient = C.clientObject;
            topObjectGroup = num;
          }
        }
      } catch (NoSuchElementException ex) {
      }
      num++;
    }
    if (itemCode.equalsIgnoreCase("freeMemory"))
      return "" + (Runtime.getRuntime().freeMemory() / 1000);
    else if (itemCode.equalsIgnoreCase("totalMemory"))
      return "" + (Runtime.getRuntime().totalMemory() / 1000);
    else if (itemCode.equalsIgnoreCase("totalTime"))
      return ""
          + CMLib.english().returnTime(System.currentTimeMillis() - CMSecurity.getStartTime(), 0);
    else if (itemCode.equalsIgnoreCase("startTime"))
      return CMLib.time().date2String(CMSecurity.getStartTime());
    else if (itemCode.equalsIgnoreCase("currentTime"))
      return CMLib.time().date2String(System.currentTimeMillis());
    else if (itemCode.equalsIgnoreCase("totalTickers")) return "" + totalTickers;
    else if (itemCode.equalsIgnoreCase("totalMillis")) return "" + totalMillis;
    else if (itemCode.equalsIgnoreCase("totalMillisTime"))
      return CMLib.english().returnTime(totalMillis, 0);
    else if (itemCode.equalsIgnoreCase("totalMillisTimePlusAverage"))
      return CMLib.english().returnTime(totalMillis, totalTicks);
    else if (itemCode.equalsIgnoreCase("totalTicks")) return "" + totalTicks;
    else if (itemCode.equalsIgnoreCase("tickgroupsize")) return "" + ticks.size();
    else if (itemCode.equalsIgnoreCase("topGroupNumber")) return "" + topGroupNumber;
    else if (itemCode.equalsIgnoreCase("topGroupMillis")) return "" + topGroupMillis;
    else if (itemCode.equalsIgnoreCase("topGroupMillisTime"))
      return CMLib.english().returnTime(topGroupMillis, 0);
    else if (itemCode.equalsIgnoreCase("topGroupMillisTimePlusAverage"))
      return CMLib.english().returnTime(topGroupMillis, topGroupTicks);
    else if (itemCode.equalsIgnoreCase("topGroupTicks")) return "" + topGroupTicks;
    else if (itemCode.equalsIgnoreCase("topObjectMillis")) return "" + topObjectMillis;
    else if (itemCode.equalsIgnoreCase("topObjectMillisTime"))
      return CMLib.english().returnTime(topObjectMillis, 0);
    else if (itemCode.equalsIgnoreCase("topObjectMillisTimePlusAverage"))
      return CMLib.english().returnTime(topObjectMillis, topObjectTicks);
    else if (itemCode.equalsIgnoreCase("topObjectTicks")) return "" + topObjectTicks;
    else if (itemCode.equalsIgnoreCase("topObjectGroup")) return "" + topObjectGroup;
    else if (itemCode.toLowerCase().startsWith("thread")) {
      int xstart = "thread".length();
      int xend = xstart;
      while ((xend < itemCode.length()) && (Character.isDigit(itemCode.charAt(xend)))) xend++;
      int threadNum = CMath.s_int(itemCode.substring(xstart, xend));
      int curThreadNum = 0;
      for (Enumeration e = CMLib.libraries(); e.hasMoreElements(); ) {
        CMLibrary lib = (CMLibrary) e.nextElement();
        ThreadEngine.SupportThread thread = lib.getSupportThread();
        if (thread != null) {
          if (curThreadNum == threadNum) {
            String instrCode = itemCode.substring(xend);
            if (instrCode.equalsIgnoreCase("miliTotal")) return "" + thread.milliTotal;
            if (instrCode.equalsIgnoreCase("milliTotal")) return "" + thread.milliTotal;
            if (instrCode.equalsIgnoreCase("status")) return "" + thread.status;
            if (instrCode.equalsIgnoreCase("name")) return "" + thread.getName();
            if (instrCode.equalsIgnoreCase("MilliTotalTime"))
              return CMLib.english().returnTime(thread.milliTotal, 0);
            if (instrCode.equalsIgnoreCase("MiliTotalTime"))
              return CMLib.english().returnTime(thread.milliTotal, 0);
            if (instrCode.equalsIgnoreCase("MilliTotalTimePlusAverage"))
              return CMLib.english().returnTime(thread.milliTotal, thread.tickTotal);
            if (instrCode.equalsIgnoreCase("MiliTotalTimePlusAverage"))
              return CMLib.english().returnTime(thread.milliTotal, thread.tickTotal);
            if (instrCode.equalsIgnoreCase("TickTotal")) return "" + thread.tickTotal;
            break;
          }
          curThreadNum++;
        }
      }
    }
    if (itemCode.equalsIgnoreCase("topObjectClient")) {
      if (topObjectClient != null) return topObjectClient.name();
      return "";
    }

    return "";
  }