Example #1
0
 public DVector parseLootPolicyFor(MOB mob) {
   if (mob == null) return new DVector(3);
   Vector lootPolicy =
       (!mob.isMonster())
           ? new Vector()
           : CMParms.parseCommas(CMProps.getVar(CMProps.SYSTEM_ITEMLOOTPOLICY), true);
   DVector policies = new DVector(3);
   for (int p = 0; p < lootPolicy.size(); p++) {
     String s = ((String) lootPolicy.elementAt(p)).toUpperCase().trim();
     if (s.length() == 0) continue;
     Vector compiledMask = null;
     int maskDex = s.indexOf("MASK=");
     if (maskDex >= 0) {
       s = s.substring(0, maskDex).trim();
       compiledMask =
           CMLib.masking()
               .maskCompile(((String) lootPolicy.elementAt(p)).substring(maskDex + 5).trim());
     } else compiledMask = new Vector();
     Vector parsed = CMParms.parse(s);
     int pct = 100;
     for (int x = 0; x < parsed.size(); x++)
       if (CMath.isInteger((String) parsed.elementAt(x)))
         pct = CMath.s_int((String) parsed.elementAt(x));
       else if (CMath.isPct((String) parsed.elementAt(x)))
         pct = (int) Math.round(CMath.s_pct((String) parsed.elementAt(x)) * 100.0);
     int flags = 0;
     if (parsed.contains("RUIN")) flags |= CMMiscUtils.LOOTFLAG_RUIN;
     else if (parsed.contains("LOSS")) flags |= CMMiscUtils.LOOTFLAG_LOSS;
     if (flags == 0) flags |= CMMiscUtils.LOOTFLAG_LOSS;
     if (parsed.contains("WORN")) flags |= CMMiscUtils.LOOTFLAG_WORN;
     else if (parsed.contains("UNWORN")) flags |= CMMiscUtils.LOOTFLAG_UNWORN;
     policies.addElement(Integer.valueOf(pct), Integer.valueOf(flags), compiledMask);
   }
   return policies;
 }
Example #2
0
 public Set<MOB> getDeadMOBsFrom(Environmental whoE) {
   if (whoE instanceof MOB) {
     final MOB mob = (MOB) whoE;
     final Room room = mob.location();
     if (room != null) return getEveryoneHere(mob, room);
   } else if (whoE instanceof Item) {
     final Item item = (Item) whoE;
     final Environmental E = item.owner();
     if (E != null) {
       final Room room = getTickersRoom(whoE);
       if (room != null) {
         if ((E instanceof MOB) && ((mask == null) || (CMLib.masking().maskCheck(mask, E, false))))
           return new XHashSet<MOB>((MOB) E);
         else if (E instanceof Room) return getEveryoneHere(null, (Room) E);
         room.recoverRoomStats();
       }
     }
   } else if (whoE instanceof Room) return getEveryoneHere(null, (Room) whoE);
   else if (whoE instanceof Area) {
     final Set<MOB> allMobs = new HashSet<MOB>();
     for (final Enumeration r = ((Area) whoE).getMetroMap(); r.hasMoreElements(); ) {
       final Room R = (Room) r.nextElement();
       allMobs.addAll(getEveryoneHere(null, R));
     }
   }
   return new HashSet<MOB>();
 }
Example #3
0
 private boolean amMerging(
     CMClass.CMObjectType doType, MaskingLibrary.CompiledZapperMask mask, Environmental E) {
   if (amMergingType(doType, E)) {
     if (mask == null) return true;
     return CMLib.masking().maskCheck(mask, E, true);
   }
   return false;
 }
Example #4
0
 @Override
 public void setMiscText(String newMiscText) {
   super.setMiscText(newMiscText);
   final String maskStr = CMParms.getParmStr(newMiscText, "mask", "");
   mask = null;
   if ((maskStr != null) && (maskStr.trim().length() > 0))
     mask = CMLib.masking().getPreCompiledMask(maskStr);
 }
Example #5
0
 @Override
 public boolean execute(MOB mob, List<String> commands, int metaFlags) throws java.io.IOException {
   final StringBuffer head = new StringBuffer("");
   final boolean isArchonLooker = CMSecurity.isASysOp(mob);
   head.append("^x[");
   head.append(CMStrings.padRight(L("Class"), 16) + " ");
   head.append(CMStrings.padRight(L("Race"), 8) + " ");
   head.append(CMStrings.padRight(L("Lvl"), 4) + " ");
   if (isArchonLooker) head.append(CMStrings.padRight(L("Last"), 18) + " ");
   head.append("] Character Name^.^?\n\r");
   mob.tell(
       "^x["
           + CMStrings.centerPreserve(
               L("The Administrators of @x1", CMProps.getVar(CMProps.Str.MUDNAME)),
               head.length() - 10)
           + "]^.^?");
   final java.util.List<PlayerLibrary.ThinPlayer> allUsers =
       CMLib.database().getExtendedUserList();
   String mask = CMProps.getVar(CMProps.Str.WIZLISTMASK);
   if (mask.length() == 0) mask = "-ANYCLASS +Archon";
   final MaskingLibrary.CompiledZMask compiledMask = CMLib.masking().maskCompile(mask);
   for (final PlayerLibrary.ThinPlayer U : allUsers) {
     CharClass C;
     final MOB player = CMLib.players().getPlayer(U.name());
     if (player != null) C = player.charStats().getCurrentClass();
     else C = CMClass.getCharClass(U.charClass());
     if (C == null) C = CMClass.findCharClass(U.charClass());
     if (((player != null) && (CMLib.masking().maskCheck(compiledMask, player, true)))
         || (CMLib.masking().maskCheck(compiledMask, U))) {
       head.append("[");
       if (C != null) head.append(CMStrings.padRight(C.name(), 16) + " ");
       else head.append(CMStrings.padRight(L("Unknown"), 16) + " ");
       head.append(CMStrings.padRight(U.race(), 8) + " ");
       if ((C == null) || (!C.leveless()))
         head.append(CMStrings.padRight("" + U.level(), 4) + " ");
       else head.append(CMStrings.padRight("    ", 4) + " ");
       if (isArchonLooker)
         head.append(CMStrings.padRight(CMLib.time().date2String(U.last()), 18) + " ");
       head.append("] " + U.name());
       head.append("\n\r");
     }
   }
   mob.tell(head.toString());
   return false;
 }
 @Override
 public void setMiscText(String newText) {
   super.setMiscText(newText);
   spellV = null;
   compiledMask = null;
   lastMOB = null;
   chanceToHappen = -1;
   maxTicks = -1;
   final String maskString = getMaskString(newText);
   if (maskString.length() > 0) compiledMask = CMLib.masking().getPreCompiledMask(maskString);
 }
Example #7
0
 public Set<MOB> getEveryoneHere(MOB spareMe, Room R) {
   final Set<MOB> V = new HashSet<MOB>();
   if (R == null) return V;
   for (int i = 0; i < R.numInhabitants(); i++) {
     final MOB M = R.fetchInhabitant(i);
     if ((spareMe != null) && (spareMe == M)) continue;
     if ((M != null)
         && (!CMSecurity.isAllowed(M, R, CMSecurity.SecFlag.IMMORT))
         && ((mask == null) || (CMLib.masking().maskCheck(mask, M, false)))) V.add(M);
   }
   return V;
   // CMLib.combat().postDeath(null,M,null);
 }
 public String spellAccountingsWithMask(String pre, String post) {
   final List<Ability> spellList = getMySpellsV();
   String id = "";
   for (int v = 0; v < spellList.size(); v++) {
     final Ability A = spellList.get(v);
     if (spellList.size() == 1) id += A.name();
     else if (v == (spellList.size() - 1)) id += "and " + A.name();
     else id += A.name() + ", ";
   }
   if (spellList.size() > 0) id = pre + id + post;
   final String maskString = getMaskString(text());
   if (maskString.length() > 0) id += "  Restrictions: " + CMLib.masking().maskDesc(maskString);
   return id;
 }
 public boolean addMeIfNeccessary(
     PhysicalAgent source, Physical target, boolean makeLongLasting, int asLevel, short maxTicks) {
   final List<Ability> V = getMySpellsV();
   if ((target == null)
       || (V.size() == 0)
       || ((compiledMask != null) && (!CMLib.masking().maskCheck(compiledMask, target, true))))
     return false;
   final List VTOO = convertToV2(V, target);
   if (VTOO.size() == 0) return false;
   final MOB qualMOB = getInvokerMOB(source, target);
   for (int v = 0; v < VTOO.size(); v += 2) {
     final Ability A = (Ability) VTOO.get(v);
     final Vector V2 = (Vector) VTOO.get(v + 1);
     if (level >= 0) asLevel = level;
     else if (asLevel <= 0) asLevel = (affected != null) ? affected.phyStats().level() : 0;
     A.invoke(qualMOB, V2, target, true, asLevel);
     final Ability EA = target.fetchEffect(A.ID());
     lastMOB = target;
     // this needs to go here because otherwise it makes non-item-invoked spells long lasting,
     // which means they dont go away when item is removed.
     if (EA != null) {
       if ((maxTicks > 0)
           && (maxTicks < Short.MAX_VALUE)
           && (CMath.s_int(EA.getStat("TICKDOWN")) > maxTicks))
         EA.setStat("TICKDOWN", Short.toString(maxTicks));
       else if (makeLongLasting) {
         EA.makeLongLasting();
         if (!uninvocable) {
           EA.makeNonUninvokable();
           if (unrevocableSpells == null) unrevocableSpells = new Vector<Ability>();
           unrevocableSpells.add(EA);
         }
       }
     }
   }
   return true;
 }
Example #10
0
 public Item isRuinedLoot(DVector policies, Item I) {
   if (I == null) return null;
   if ((CMath.bset(I.envStats().disposition(), EnvStats.IS_UNSAVABLE))
       || (CMath.bset(I.envStats().sensesMask(), EnvStats.SENSE_ITEMNORUIN))
       || (I instanceof Coins)) return I;
   if (I.name().toLowerCase().indexOf("ruined ") >= 0) return I;
   for (int d = 0; d < policies.size(); d++) {
     if ((((Vector) policies.elementAt(d, 3)).size() > 0)
         && (!CMLib.masking().maskCheck((Vector) policies.elementAt(d, 3), I, true))) continue;
     if (CMLib.dice().rollPercentage() > ((Integer) policies.elementAt(d, 1)).intValue()) continue;
     int flags = ((Integer) policies.elementAt(d, 2)).intValue();
     if (CMath.bset(flags, CMMiscUtils.LOOTFLAG_WORN) && I.amWearingAt(Wearable.IN_INVENTORY))
       continue;
     else if (CMath.bset(flags, CMMiscUtils.LOOTFLAG_UNWORN)
         && (!I.amWearingAt(Wearable.IN_INVENTORY))) continue;
     if (CMath.bset(flags, CMMiscUtils.LOOTFLAG_LOSS)) return null;
     Item I2 = CMClass.getItem("GenItem");
     I2.baseEnvStats().setWeight(I.baseEnvStats().weight());
     I2.setName(I.Name());
     I2.setDisplayText(I.displayText());
     I2.setDescription(I2.description());
     I2.recoverEnvStats();
     I2.setMaterial(I.material());
     String ruinDescAdder = null;
     switch (I2.material() & RawMaterial.MATERIAL_MASK) {
       case RawMaterial.MATERIAL_LEATHER:
       case RawMaterial.MATERIAL_CLOTH:
       case RawMaterial.MATERIAL_VEGETATION:
       case RawMaterial.MATERIAL_FLESH:
       case RawMaterial.MATERIAL_PAPER:
         ruinDescAdder =
             CMStrings.capitalizeFirstLetter(I2.name()) + " is torn and ruined beyond repair.";
         break;
       case RawMaterial.MATERIAL_METAL:
       case RawMaterial.MATERIAL_MITHRIL:
       case RawMaterial.MATERIAL_WOODEN:
         ruinDescAdder =
             CMStrings.capitalizeFirstLetter(I2.name()) + " is battered and ruined beyond repair.";
         break;
       case RawMaterial.MATERIAL_GLASS:
         ruinDescAdder =
             CMStrings.capitalizeFirstLetter(I2.name())
                 + " is shattered and ruined beyond repair.";
         break;
       case RawMaterial.MATERIAL_ROCK:
       case RawMaterial.MATERIAL_PRECIOUS:
       case RawMaterial.MATERIAL_PLASTIC:
         ruinDescAdder =
             CMStrings.capitalizeFirstLetter(I2.name()) + " is cracked and ruined beyond repair.";
         break;
       case RawMaterial.MATERIAL_UNKNOWN:
       case RawMaterial.MATERIAL_ENERGY:
       case RawMaterial.MATERIAL_LIQUID:
       default:
         ruinDescAdder = CMStrings.capitalizeFirstLetter(I2.name()) + " is ruined beyond repair.";
         break;
     }
     I2.setDescription(CMStrings.endWithAPeriod(I2.description()) + " " + ruinDescAdder);
     String oldName = I2.Name();
     I2.setName(CMLib.english().insertUnColoredAdjective(I2.Name(), "ruined"));
     int x = I2.displayText().toUpperCase().indexOf(oldName.toUpperCase());
     I2.setBaseValue(0);
     if (x >= 0)
       I2.setDisplayText(
           I2.displayText().substring(0, x)
               + I2.Name()
               + I2.displayText().substring(x + oldName.length()));
     return I2;
   }
   return I;
 }
Example #11
0
  public boolean doArchonDBCompare(MOB mob, String scope, String firstWord, Vector commands)
      throws java.io.IOException {
    CMClass.CMObjectType doType = OBJECT_TYPES.get(firstWord.toUpperCase());
    if (doType == null) doType = OBJECT_TYPES.get(firstWord.toUpperCase() + "S");
    if (doType != null) commands.remove(0);
    else doType = CMClass.CMObjectType.LOCALE;

    final String theRest = CMParms.combineQuoted(commands, 0);
    DBConnector dbConnector = null;
    final String dbClass = CMParms.getParmStr(theRest, "DBCLASS", "");
    final String dbService = CMParms.getParmStr(theRest, "DBSERVICE", "");
    final String dbUser = CMParms.getParmStr(theRest, "DBUSER", "");
    final String dbPass = CMParms.getParmStr(theRest, "DBPASS", "");
    final int dbConns = CMParms.getParmInt(theRest, "DBCONNECTIONS", 3);
    final int dbPingIntMins = CMParms.getParmInt(theRest, "DBPINGINTERVALMINS", 30);
    final boolean dbReuse = CMParms.getParmBool(theRest, "DBREUSE", true);
    final String ignore = CMParms.getParmStr(theRest, "IGNORE", "");
    final String maskStr = CMParms.getParmStr(theRest, "MASK", "");
    final Set<String> ignores = new SHashSet(CMParms.parseCommas(ignore.toUpperCase(), true));
    final MaskingLibrary.CompiledZapperMask mask = CMLib.masking().maskCompile(maskStr);
    if (dbClass.length() == 0) {
      mob.tell(L("This command requires DBCLASS= to be set."));
      return false;
    }
    if (dbService.length() == 0) {
      mob.tell(L("This command requires DBSERVICE= to be set."));
      return false;
    }
    if (dbUser.length() == 0) {
      mob.tell(L("This command requires DBUSER= to be set."));
      return false;
    }
    if (dbPass.length() == 0) {
      mob.tell(L("This command requires DBPASS= to be set."));
      return false;
    }

    dbConnector =
        new DBConnector(
            dbClass, dbService, dbUser, dbPass, dbConns, dbPingIntMins, dbReuse, false, false);
    dbConnector.reconnect();
    final DBInterface dbInterface = new DBInterface(dbConnector, null);

    final DBConnection DBTEST = dbConnector.DBFetch();
    if (DBTEST != null) dbConnector.DBDone(DBTEST);
    mob.tell(L("Loading database rooms..."));
    final List<Room> rooms = new LinkedList<Room>();
    if ((!dbConnector.amIOk()) || (!dbInterface.isConnected())) {
      mob.tell(L("Failed to connect to database."));
      return false;
    }
    if (scope.equalsIgnoreCase("AREA"))
      rooms.addAll(
          Arrays.asList(dbInterface.DBReadRoomObjects(mob.location().getArea().Name(), false)));
    else if (scope.equalsIgnoreCase("ROOM")) {
      final Room R = dbInterface.DBReadRoomObject(mob.location().roomID(), false);
      if (R != null) rooms.add(R);
    } else
      for (final Enumeration<Area> e = CMLib.map().areas(); e.hasMoreElements(); )
        rooms.addAll(Arrays.asList(dbInterface.DBReadRoomObjects(e.nextElement().Name(), false)));
    if (rooms.size() == 0) {
      mob.tell(L("No rooms found."));
      return false;
    }
    for (final Room R : rooms) dbInterface.DBReadContent(R.roomID(), R, false);
    mob.tell(L("Data loaded, starting scan."));
    final Comparator<MOB> convM =
        new Comparator<MOB>() {
          @Override
          public int compare(MOB arg0, MOB arg1) {
            final int x = arg0.ID().compareTo(arg1.ID());
            return (x != 0) ? x : arg0.Name().compareTo(arg1.Name());
          }
        };
    final Comparator<Item> convI =
        new Comparator<Item>() {
          @Override
          public int compare(Item arg0, Item arg1) {
            final int x = arg0.ID().compareTo(arg1.ID());
            return (x != 0) ? x : arg0.Name().compareTo(arg1.Name());
          }
        };
    try {
      for (final Room dbR : rooms) {
        Room R = CMLib.map().getRoom(dbR.roomID());
        if (R == null) {
          if (doType == CMClass.CMObjectType.LOCALE)
            Log.sysOut("Merge", dbR.roomID() + " not in database");
          // import, including exits!
          continue;
        }
        synchronized (("SYNC" + dbR.roomID()).intern()) {
          final Area.State oldFlags = R.getArea().getAreaState();
          R.getArea().setAreaState(Area.State.FROZEN);

          boolean updateMobs = false;
          boolean updateItems = false;
          final boolean updateRoom = false;
          R = CMLib.map().getRoom(R);
          CMLib.map().resetRoom(R);
          final List<MOB> mobSetL = new Vector<MOB>();
          for (final Enumeration<MOB> e = dbR.inhabitants(); e.hasMoreElements(); )
            mobSetL.add(e.nextElement());
          final MOB[] mobSet = mobSetL.toArray(new MOB[0]);
          Arrays.sort(mobSet, convM);
          String lastName = "";
          int ct = 1;
          final HashSet<MOB> doneM = new HashSet<MOB>();
          for (final MOB dbM : mobSet) {
            if (!lastName.equals(dbM.Name())) ct = 1;
            else ct++;
            final String rName = dbM.Name() + "." + ct;
            MOB M = null;
            int ctr = ct;
            for (final Enumeration<MOB> m = R.inhabitants(); m.hasMoreElements(); ) {
              final MOB M1 = m.nextElement();
              if (M1.Name().equalsIgnoreCase(dbM.Name()) && ((--ctr) <= 0)) {
                M = M1;
                break;
              }
            }
            if (M == null) {
              if (amMerging(doType, mask, dbM) && (!ignore.contains("MISSING"))) {
                if (mob.session()
                    .confirm(
                        L(
                            "MOB: @x1.@x2 not in local room.\n\rWould you like to add it (y/N)?",
                            dbR.roomID(),
                            rName),
                        L("N"))) {
                  M = (MOB) dbM.copyOf();
                  M.bringToLife(R, true);
                  doneM.add(M);
                  updateMobs = true;
                  Log.sysOut("Merge", mob.Name() + " added mob " + dbR.roomID() + "." + rName);
                }
              }
            } else {
              doneM.add(M);
              if (amMerging(doType, mask, dbM)) {
                if (!dbM.sameAs(M)) {
                  final MOB oldM = (MOB) M.copyOf();
                  if ((dbMerge(mob, "^MMOB " + dbR.roomID() + "." + rName + "^N", dbM, M, ignores))
                      && (!oldM.sameAs(M))) {
                    Log.sysOut("Merge", mob.Name() + " modified mob " + dbR.roomID() + "." + rName);
                    updateMobs = true;
                  }
                }
              }
              final STreeSet<Item> itemSetL = new STreeSet<Item>(convI);
              for (final Enumeration<Item> e = dbM.items(); e.hasMoreElements(); )
                itemSetL.add(e.nextElement());
              final Item[] itemSet = itemSetL.toArray(new Item[0]);
              Arrays.sort(itemSet, convI);
              String lastIName = "";
              int ict = 1;
              final HashSet<Item> doneI = new HashSet<Item>();
              for (final Item dbI : itemSet) {
                if (!lastIName.equals(dbI.Name())) ict = 1;
                else ict++;
                final String rIName = dbI.Name() + "." + ict;
                Item I = null;
                ctr = ict;
                for (final Enumeration<Item> i = M.items(); i.hasMoreElements(); ) {
                  final Item I1 = i.nextElement();
                  if (I1.Name().equalsIgnoreCase(dbI.Name()) && ((--ctr) <= 0)) {
                    I = I1;
                    break;
                  }
                }
                if (I == null) {
                  if (amMerging(doType, mask, dbI) && (!ignore.contains("MISSING"))) {
                    if (mob.session()
                        .confirm(
                            L(
                                "Item: @x1.@x2.@x3 not in local room.\n\rWould you like to add it (y/N)?",
                                dbR.roomID(),
                                dbM.Name(),
                                rIName),
                            L("N"))) {
                      I = (Item) dbI.copyOf();
                      M.addItem(I);
                      doneI.add(I);
                      final Item cI =
                          (dbI.container() == null) ? null : M.findItem(dbI.container().Name());
                      if (cI instanceof Container) I.setContainer((Container) cI);
                      updateMobs = true;
                      Log.sysOut(
                          "Merge",
                          mob.Name()
                              + " added item "
                              + dbR.roomID()
                              + "."
                              + dbM.Name()
                              + "."
                              + rIName);
                    }
                  }
                } else if (amMerging(doType, mask, dbI)) {
                  doneI.add(I);
                  if (!dbI.sameAs(I)) {
                    final Item oldI = (Item) I.copyOf();
                    if ((dbMerge(
                            mob,
                            "^IITEM ^M" + dbR.roomID() + "." + dbM.Name() + "." + rIName + "^N",
                            dbI,
                            I,
                            ignores))
                        && (!oldI.sameAs(I))) {
                      Log.sysOut(
                          "Merge",
                          mob.Name()
                              + " modified item "
                              + dbR.roomID()
                              + "."
                              + dbM.Name()
                              + "."
                              + rIName);
                      updateMobs = true;
                    }
                  }
                }
                lastIName = dbI.Name();
              }
              for (final Enumeration<Item> i = M.items(); i.hasMoreElements(); ) {
                final Item I = i.nextElement();
                if (amMerging(doType, mask, I)
                    && (!doneI.contains(I))
                    && (!ignore.contains("EXTRA"))) {
                  if (mob.session()
                      .confirm(
                          L(
                              "Item: @x1.@x2.@x3 not in database.\n\rWould you like to delete it (y/N)?",
                              R.roomID(),
                              M.Name(),
                              I.Name()),
                          L("N"))) {
                    M.delItem(I);
                    updateMobs = true;
                    Log.sysOut(
                        "Merge",
                        mob.Name()
                            + " deleted item "
                            + R.roomID()
                            + "."
                            + M.Name()
                            + "."
                            + I.Name());
                  }
                }
              }
            }
            lastName = dbM.Name();
          }
          for (final Enumeration<MOB> r = R.inhabitants(); r.hasMoreElements(); ) {
            final MOB M = r.nextElement();
            if (amMerging(doType, mask, M)
                && (!doneM.contains(M))
                && (M.isMonster())
                && (!ignore.contains("EXTRA"))) {
              if (mob.session()
                  .confirm(
                      L(
                          "MOB: @x1.@x2 not in database.\n\rWould you like to delete it (y/N)?",
                          R.roomID(),
                          M.Name()),
                      L("N"))) {
                R.delInhabitant(M);
                updateMobs = true;
                Log.sysOut("Merge", mob.Name() + " deleted mob " + R.roomID() + "." + M.Name());
              }
            }
          }

          final STreeSet<Item> itemSetL = new STreeSet<Item>(convI);
          for (final Enumeration<Item> e = dbR.items(); e.hasMoreElements(); )
            itemSetL.add(e.nextElement());
          final Item[] itemSet = itemSetL.toArray(new Item[0]);
          Arrays.sort(itemSet, convI);
          lastName = "";
          ct = 1;
          final HashSet<Item> doneI = new HashSet<Item>();
          for (final Item dbI : itemSet) {
            if (!lastName.equals(dbI.Name())) ct = 1;
            else ct++;
            final String rName = dbI.Name() + "." + ct;
            Item I = null;
            int ctr = ct;
            for (final Enumeration<Item> i = R.items(); i.hasMoreElements(); ) {
              final Item I1 = i.nextElement();
              if (I1.Name().equalsIgnoreCase(dbI.Name()) && ((--ctr) <= 0)) {
                I = I1;
                break;
              }
            }
            if (I == null) {
              if (amMerging(doType, mask, dbI) && (!ignore.contains("MISSING"))) {
                if (mob.session()
                    .confirm(
                        L(
                            "Item: @x1.@x2 not in local room.\n\rWould you like to add it (y/N)?",
                            dbR.roomID(),
                            rName),
                        L("N"))) {
                  I = (Item) dbI.copyOf();
                  R.addItem(I);
                  doneI.add(I);
                  final Item cI =
                      (dbI.container() == null) ? null : R.findItem(dbI.container().Name());
                  if (cI instanceof Container) I.setContainer((Container) cI);
                  updateItems = true;
                  Log.sysOut("Merge", mob.Name() + " added item " + dbR.roomID() + "." + rName);
                }
              }
            } else if (amMerging(doType, mask, dbI)) {
              doneI.add(I);
              if (!dbI.sameAs(I)) {
                final Item oldI = (Item) I.copyOf();
                if ((dbMerge(mob, "^IITEM " + dbR.roomID() + "." + rName + "^N", dbI, I, ignores))
                    && (!oldI.sameAs(I))) {
                  Log.sysOut("Merge", mob.Name() + " modified item " + dbR.roomID() + "." + rName);
                  updateItems = true;
                }
              }
            }
            lastName = dbI.Name();
          }
          for (final Enumeration<Item> i = R.items(); i.hasMoreElements(); ) {
            final Item I = i.nextElement();
            if (amMerging(doType, mask, I) && (!doneI.contains(I)) && (!ignore.contains("EXTRA"))) {
              if (mob.session()
                  .confirm(
                      L(
                          "Item: @x1.@x2 not in database.\n\rWould you like to delete it (y/N)?",
                          R.roomID(),
                          I.Name()),
                      L("N"))) {
                R.delItem(I);
                updateItems = true;
                Log.sysOut("Merge", mob.Name() + " deleted item " + R.roomID() + "." + I.Name());
              }
            }
          }
          if (updateRoom) CMLib.database().DBUpdateRoom(R);
          if (updateItems) CMLib.database().DBUpdateItems(R);
          if (updateMobs) CMLib.database().DBUpdateMOBs(R);
          CMLib.map().resetRoom(R);
          R.getArea().setAreaState(oldFlags);
        }
        dbR.destroy();
      }
      mob.tell(L("Done"));
    } catch (final CMException cme) {
      mob.tell(L("Cancelled."));
    }
    dbInterface.shutdown();
    return true;
  }
Example #12
0
 public boolean canApply(MOB mob) {
   if ((affected != null) && ((mask.size() == 0) || (CMLib.masking().maskCheck(mask, mob, true))))
     return true;
   return false;
 }
Example #13
0
  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;
  }