private void listCharacters(L2PcInstance activeChar, int page) {
    Collection<L2PcInstance> allPlayers = L2World.getInstance().getAllPlayers().values();
    L2PcInstance[] players;
    // synchronized (L2World.getInstance().getAllPlayers())
    {
      players = allPlayers.toArray(new L2PcInstance[allPlayers.size()]);
    }

    int maxCharactersPerPage = 20;
    int maxPages = players.length / maxCharactersPerPage;

    if (players.length > maxCharactersPerPage * maxPages) maxPages++;

    // Check if number of users changed
    if (page > maxPages) page = maxPages;

    int charactersStart = maxCharactersPerPage * page;
    int charactersEnd = players.length;
    if (charactersEnd - charactersStart > maxCharactersPerPage)
      charactersEnd = charactersStart + maxCharactersPerPage;

    NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
    adminReply.setFile("data/html/admin/charlist.htm");

    final StringBuilder replyMSG = new StringBuilder(1000);

    for (int x = 0; x < maxPages; x++) {
      int pagenr = x + 1;
      StringUtil.append(
          replyMSG,
          "<center><a action=\"bypass -h admin_show_characters "
              + x
              + "\">"
              + MessageTable.Messages[677].getMessage()
              + pagenr
              + MessageTable.Messages[215].getMessage()
              + "</a></center>");
    }

    adminReply.replace("%pages%", replyMSG.toString());
    replyMSG.setLength(0);

    for (int i = charactersStart; i < charactersEnd; i++) {
      // Add player info into new Table row
      StringUtil.append(
          replyMSG,
          "<tr><td width=80><a action=\"bypass -h admin_character_info ",
          players[i].getName(),
          "\">",
          players[i].getName(),
          "</a></td><td width=110>",
          players[i].getTemplate().className,
          "</td><td width=40>",
          String.valueOf(players[i].getLevel()),
          "</td></tr>");
    }

    adminReply.replace("%players%", replyMSG.toString());
    activeChar.sendPacket(adminReply);
  }
Esempio n. 2
0
  /**
   * Adda mercenary ticket.
   *
   * <ul>
   *   <li>find the npc that needs to be saved in the mercenary spawns, given this item
   *   <li>Use the passed character's location info to add the spawn
   *   <li>create a copy of the item to drop in the world returns the id of the mercenary npc that
   *       was added to the spawn returns -1 if this fails.
   * </ul>
   *
   * @param itemId
   * @param activeChar
   * @return
   */
  public int addTicket(int itemId, L2PcInstance activeChar) {
    int x = activeChar.getX();
    int y = activeChar.getY();
    int z = activeChar.getZ();
    int heading = activeChar.getHeading();

    Castle castle = CastleManager.getInstance().getCastle(activeChar);
    if (castle == null) // this should never happen at this point
    return -1;

    for (int i = 0; i < ITEM_IDS.length; i++) {
      if (ITEM_IDS[i] == itemId) // Find the index of the item used
      {
        spawnMercenary(NPC_IDS[i], x, y, z, 3000);

        // Hire merc for this castle. NpcId is at the same index as the item used.
        castle.getSiege().getSiegeGuardManager().hireMerc(x, y, z, heading, NPC_IDS[i]);

        // create the ticket in the gameworld
        ItemInstance dropticket = new ItemInstance(IdFactory.getInstance().getNextId(), itemId);
        dropticket.setLocation(ItemInstance.ItemLocation.INVENTORY);
        dropticket.setDestroyProtected(true);
        dropticket.dropMe(activeChar, x, y, z);
        L2World.getInstance().storeObject(dropticket); // add to the world
        // and keep track of this ticket in the list
        _droppedTickets.add(dropticket);

        return NPC_IDS[i];
      }
    }
    return -1;
  }
  /**
   * @param activeChar
   * @throws IllegalArgumentException
   */
  private void findDualbox(L2PcInstance activeChar, int multibox) throws IllegalArgumentException {
    Collection<L2PcInstance> allPlayers = L2World.getInstance().getAllPlayers().values();
    L2PcInstance[] players = allPlayers.toArray(new L2PcInstance[allPlayers.size()]);

    Map<String, List<L2PcInstance>> ipMap = new HashMap<String, List<L2PcInstance>>();

    String ip = "0.0.0.0";
    L2GameClient client;

    final Map<String, Integer> dualboxIPs = new HashMap<String, Integer>();

    for (L2PcInstance player : players) {
      client = player.getClient();
      if (client.isDetached()) continue;
      else {
        ip = client.getConnection().getInetAddress().getHostAddress();
        if (ipMap.get(ip) == null) ipMap.put(ip, new ArrayList<L2PcInstance>());
        ipMap.get(ip).add(player);

        if (ipMap.get(ip).size() >= multibox) {
          Integer count = dualboxIPs.get(ip);
          if (count == null) dualboxIPs.put(ip, multibox);
          else dualboxIPs.put(ip, count + 1);
        }
      }
    }

    List<String> keys = new ArrayList<String>(dualboxIPs.keySet());
    Collections.sort(
        keys,
        new Comparator<String>() {
          public int compare(String left, String right) {
            return dualboxIPs.get(left).compareTo(dualboxIPs.get(right));
          }
        });
    Collections.reverse(keys);

    final StringBuilder results = new StringBuilder();
    for (String dualboxIP : keys) {
      StringUtil.append(
          results,
          "<a action=\"bypass -h admin_find_ip "
              + dualboxIP
              + "\">"
              + dualboxIP
              + " ("
              + dualboxIPs.get(dualboxIP)
              + ")</a><br1>");
    }

    NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
    adminReply.setFile("data/html/admin/dualbox.htm");
    adminReply.replace("%multibox%", String.valueOf(multibox));
    adminReply.replace("%results%", results.toString());
    activeChar.sendPacket(adminReply);
  }
Esempio n. 4
0
 /**
  * Delete all tickets from a castle; remove the items from the world and remove references to them
  * from this class
  *
  * @param castleId
  */
 public void deleteTickets(int castleId) {
   Iterator<ItemInstance> it = _droppedTickets.iterator();
   while (it.hasNext()) {
     ItemInstance item = it.next();
     if (item != null && getTicketCastleId(item.getItemId()) == castleId) {
       item.decayMe();
       L2World.getInstance().removeObject(item);
       it.remove();
     }
   }
 }
  /**
   * @param activeChar
   * @param CharacterToFind
   */
  private void findCharacter(L2PcInstance activeChar, String CharacterToFind) {
    int CharactersFound = 0;
    String name;
    Collection<L2PcInstance> allPlayers = L2World.getInstance().getAllPlayers().values();
    L2PcInstance[] players;
    // synchronized (L2World.getInstance().getAllPlayers())
    {
      players = allPlayers.toArray(new L2PcInstance[allPlayers.size()]);
    }
    NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
    adminReply.setFile("data/html/admin/charfind.htm");

    final StringBuilder replyMSG = new StringBuilder(1000);

    for (L2PcInstance player : players) { // Add player info into new Table row
      name = player.getName();
      if (name.toLowerCase().contains(CharacterToFind.toLowerCase())) {
        CharactersFound = CharactersFound + 1;
        StringUtil.append(
            replyMSG,
            "<tr><td width=80><a action=\"bypass -h admin_character_list ",
            name,
            "\">",
            name,
            "</a></td><td width=110>",
            player.getTemplate().className,
            "</td><td width=40>",
            String.valueOf(player.getLevel()),
            "</td></tr>");
      }
      if (CharactersFound > 20) break;
    }
    adminReply.replace("%results%", replyMSG.toString());

    final String replyMSG2;

    if (CharactersFound == 0) {
      replyMSG2 = MessageTable.Messages[678].getMessage();
    } else if (CharactersFound > 20) {
      adminReply.replace("%number%", MessageTable.Messages[679].getMessage());
      replyMSG2 = MessageTable.Messages[680].getMessage();
    } else if (CharactersFound == 1) {
      replyMSG2 = MessageTable.Messages[1196].getMessage();
    } else {
      replyMSG2 = MessageTable.Messages[1197].getMessage();
    }

    adminReply.replace("%number%", String.valueOf(CharactersFound));
    adminReply.replace("%end%", replyMSG2);
    activeChar.sendPacket(adminReply);
  }
Esempio n. 6
0
  private static final void load() {
    try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
      PreparedStatement statement =
          con.prepareStatement("SELECT * FROM castle_siege_guards WHERE isHired=1");
      ResultSet rs = statement.executeQuery();

      int npcId;
      int itemId;
      int x, y, z;

      // start index to begin the search for the itemId corresponding to this NPC :
      // a) skip unnecessary iterations in the search loop
      // b) avoid finding the wrong itemId whenever tickets of different spawn the same npc!
      int startindex = 0;

      while (rs.next()) {
        npcId = rs.getInt("npcId");
        x = rs.getInt("x");
        y = rs.getInt("y");
        z = rs.getInt("z");

        Castle castle = CastleManager.getInstance().getCastle(x, y, z);
        if (castle != null) startindex = 10 * (castle.getCastleId() - 1);

        // find the FIRST ticket itemId with spawns the saved NPC in the saved location
        for (int i = startindex; i < NPC_IDS.length; i++) {
          if (NPC_IDS[i] == npcId) // Find the index of the item used
          {
            // only handle tickets if a siege is not ongoing in this npc's castle
            if (castle != null && !(castle.getSiege().isInProgress())) {
              itemId = ITEM_IDS[i];
              // create the ticket in the gameworld
              ItemInstance dropticket =
                  new ItemInstance(IdFactory.getInstance().getNextId(), itemId);
              dropticket.setLocation(ItemInstance.ItemLocation.INVENTORY);
              dropticket.setDestroyProtected(true);
              dropticket.dropMe(null, x, y, z);
              L2World.getInstance().storeObject(dropticket);
              _droppedTickets.add(dropticket);
            }
            break;
          }
        }
      }
      rs.close();
      statement.close();
    } catch (Exception e) {
      _log.log(Level.WARNING, "Exception: loadMercenaryData(): " + e.getMessage(), e);
    }
    _log.info("MercTicketManager: Loaded " + _droppedTickets.size() + " tickets.");
  }
Esempio n. 7
0
  @Override
  public void handleChat(int type, L2PcInstance activeChar, String target, String text) {
    if (!FloodProtectors.performAction(activeChar.getClient(), Action.TRADE_CHAT)) return;

    final CreatureSay cs =
        new CreatureSay(activeChar.getObjectId(), type, activeChar.getName(), text);
    final int region = MapRegionTable.getMapRegion(activeChar.getX(), activeChar.getY());

    for (L2PcInstance player : L2World.getInstance().getPlayers()) {
      if (!BlockList.isBlocked(player, activeChar)
          && region == MapRegionTable.getMapRegion(player.getX(), player.getY()))
        player.sendPacket(cs);
    }
  }
Esempio n. 8
0
  @Override
  protected void runImpl() {
    final L2PcInstance player = getClient().getActiveChar();
    if (player == null) return;

    final L2PcInstance partner = player.getActiveRequester();
    if (partner == null || L2World.getInstance().getPlayer(partner.getObjectId()) == null) {
      // Partner hasn't be found, cancel the invitation
      player.sendPacket(SystemMessageId.TARGET_IS_NOT_FOUND_IN_THE_GAME);
      player.setActiveRequester(null);
      return;
    }

    // If answer is positive, join the requester's PartyRoom.
    if (_answer == 1 && !partner.isRequestExpired()) {
      PartyMatchRoom _room = PartyMatchRoomList.getInstance().getRoom(partner.getPartyRoom());
      if (_room == null) return;

      if ((player.getLevel() >= _room.getMinLvl()) && (player.getLevel() <= _room.getMaxLvl())) {
        // Remove from waiting list
        PartyMatchWaitingList.getInstance().removePlayer(player);

        player.setPartyRoom(partner.getPartyRoom());

        player.sendPacket(new PartyMatchDetail(player, _room));
        player.sendPacket(new ExPartyRoomMember(player, _room, 0));

        for (L2PcInstance _member : _room.getPartyMembers()) {
          if (_member == null) continue;

          _member.sendPacket(new ExManagePartyRoomMember(player, _room, 0));
          _member.sendPacket(
              SystemMessage.getSystemMessage(SystemMessageId.S1_ENTERED_PARTY_ROOM)
                  .addPcName(player));
        }
        _room.addMember(player);

        // Info Broadcast
        player.broadcastUserInfo();
      } else player.sendPacket(SystemMessageId.CANT_ENTER_PARTY_ROOM);
    }
    // Else, send a message to requester.
    else partner.sendPacket(SystemMessageId.PARTY_MATCHING_REQUEST_NO_RESPONSE);

    // reset transaction timers
    player.setActiveRequester(null);
    partner.onTransactionResponse();
  }
  /**
   * @param activeChar
   * @param characterName
   * @throws IllegalArgumentException
   */
  private void findCharactersPerAccount(L2PcInstance activeChar, String characterName)
      throws IllegalArgumentException {
    if (characterName.matches(Config.CNAME_TEMPLATE)) {
      String account = null;
      Map<Integer, String> chars;
      L2PcInstance player = L2World.getInstance().getPlayer(characterName);
      if (player == null) throw new IllegalArgumentException("Player doesn't exist");
      chars = player.getAccountChars();
      account = player.getAccountName();
      final StringBuilder replyMSG = new StringBuilder(chars.size() * 20);
      NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
      adminReply.setFile("data/html/admin/accountinfo.htm");
      for (String charname : chars.values()) {
        StringUtil.append(replyMSG, charname, "<br1>");
      }

      adminReply.replace("%characters%", replyMSG.toString());
      adminReply.replace("%account%", account);
      adminReply.replace("%player%", characterName);
      activeChar.sendPacket(adminReply);
    } else throw new IllegalArgumentException("Malformed character name");
  }
Esempio n. 10
0
  private static void showHtml(L2PcInstance activeChar) {
    int worldX = activeChar.getX();
    int worldY = activeChar.getY();
    int geoX = ((((worldX - (-327680)) >> 4) >> 11) + 10);
    int geoY = ((((worldY - (-262144)) >> 4) >> 11) + 10);

    NpcHtmlMessage adminReply = new NpcHtmlMessage(0);
    adminReply.setFile("data/html/admin/zone.htm");

    adminReply.replace(
        "%MAPREGION%",
        "[x:"
            + MapRegionTable.getMapRegionX(activeChar.getX())
            + " y:"
            + MapRegionTable.getMapRegionX(activeChar.getY())
            + "]");
    adminReply.replace("%GEOREGION%", "" + geoX + "_" + geoY);
    adminReply.replace(
        "%CLOSESTTOWN%", MapRegionTable.getInstance().getClosestTownName(activeChar));
    adminReply.replace(
        "%CURRENTLOC%",
        "" + activeChar.getX() + ", " + activeChar.getY() + ", " + activeChar.getZ());

    adminReply.replace(
        "%PVP%", (activeChar.isInsideZone(ZoneId.PVP) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%PEACE%",
        (activeChar.isInsideZone(ZoneId.PEACE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%SIEGE%",
        (activeChar.isInsideZone(ZoneId.SIEGE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%MOTHERTREE%",
        (activeChar.isInsideZone(ZoneId.MOTHER_TREE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%CLANHALL%",
        (activeChar.isInsideZone(ZoneId.CLAN_HALL) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%NOLANDING%",
        (activeChar.isInsideZone(ZoneId.NO_LANDING) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%WATER%",
        (activeChar.isInsideZone(ZoneId.WATER) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%JAIL%",
        (activeChar.isInsideZone(ZoneId.JAIL) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%MONSTERTRACK%",
        (activeChar.isInsideZone(ZoneId.MONSTER_TRACK)
            ? "<font color=\"LEVEL\">YES</font>"
            : "NO"));
    adminReply.replace(
        "%CASTLE%",
        (activeChar.isInsideZone(ZoneId.CASTLE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%SWAMP%",
        (activeChar.isInsideZone(ZoneId.SWAMP) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%NOSUMMONFRIEND%",
        (activeChar.isInsideZone(ZoneId.NO_SUMMON_FRIEND)
            ? "<font color=\"LEVEL\">YES</font>"
            : "NO"));
    adminReply.replace(
        "%NOSTORE%",
        (activeChar.isInsideZone(ZoneId.NO_STORE) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%TOWN%",
        (activeChar.isInsideZone(ZoneId.TOWN) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%HQ%", (activeChar.isInsideZone(ZoneId.HQ) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%DANGERAREA%",
        (activeChar.isInsideZone(ZoneId.DANGER_AREA) ? "<font color=\"LEVEL\">YES</font>" : "NO"));
    adminReply.replace(
        "%CASTONARTIFACT%",
        (activeChar.isInsideZone(ZoneId.CAST_ON_ARTIFACT)
            ? "<font color=\"LEVEL\">YES</font>"
            : "NO"));
    adminReply.replace(
        "%NORESTART%",
        (activeChar.isInsideZone(ZoneId.NO_RESTART) ? "<font color=\"LEVEL\">YES</font>" : "NO"));

    StringBuilder zones = new StringBuilder(100);
    L2WorldRegion region = L2World.getInstance().getRegion(activeChar.getX(), activeChar.getY());
    for (L2ZoneType zone : region.getZones()) {
      if (zone.isCharacterInZone(activeChar)) {
        StringUtil.append(zones, String.valueOf(zone.getId()));
        StringUtil.append(zones, " ");
      }
    }
    adminReply.replace("%ZLIST%", zones.toString());
    activeChar.sendPacket(adminReply);
  }
Esempio n. 11
0
  @Override
  public boolean useAdminCommand(String command, L2PcInstance activeChar) {
    // runmod
    if (command.equals("admin_runmod") || command.equals("admin_instant_move"))
      activeChar.setTeleMode(1);
    if (command.equals("admin_runmod tele")) activeChar.setTeleMode(2);
    if (command.equals("admin_runmod norm")) activeChar.setTeleMode(0);

    // teleport via panels
    if (command.equals("admin_tele")) AdminHelpPage.showHelpPage(activeChar, "teleports.htm");
    if (command.equals("admin_tele_areas"))
      AdminHelpPage.showHelpPage(activeChar, "tele/other.htm");

    // recalls / goto types
    if (command.startsWith("admin_goto") || command.startsWith("admin_teleportto")) {
      StringTokenizer st = new StringTokenizer(command);
      if (st.countTokens() > 1) {
        st.nextToken();
        String plyr = st.nextToken();
        L2PcInstance player = L2World.getInstance().getPlayer(plyr);
        if (player == null) {
          activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
          return false;
        }

        teleportToCharacter(activeChar, player);
      }
    } else if (command.startsWith("admin_recall ")) {
      try {
        String targetName = command.substring(13);
        L2PcInstance player = L2World.getInstance().getPlayer(targetName);
        if (player == null) {
          activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
          return false;
        }

        teleportCharacter(player, activeChar.getX(), activeChar.getY(), activeChar.getZ());
      } catch (StringIndexOutOfBoundsException e) {
      }
    } else if (command.startsWith("admin_recall_party")) {
      try {
        String targetName = command.substring(19);
        L2PcInstance player = L2World.getInstance().getPlayer(targetName);
        if (player == null) {
          activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
          return false;
        }

        if (player.isInParty()) {
          for (L2PcInstance pm : player.getParty().getPartyMembers())
            teleportCharacter(pm, activeChar.getX(), activeChar.getY(), activeChar.getZ());

          activeChar.sendMessage("You recall " + player.getName() + "'s party.");
        } else {
          activeChar.sendMessage("You recall " + player.getName() + ", but he isn't in a party.");
          teleportCharacter(player, activeChar.getX(), activeChar.getY(), activeChar.getZ());
        }
      } catch (StringIndexOutOfBoundsException e) {
      }
    } else if (command.startsWith("admin_recall_clan")) {
      try {
        String targetName = command.substring(18);
        L2PcInstance player = L2World.getInstance().getPlayer(targetName);
        if (player == null) {
          activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
          return false;
        }

        L2Clan clan = player.getClan();
        if (clan != null) {
          for (L2PcInstance member : clan.getOnlineMembers())
            teleportCharacter(member, activeChar.getX(), activeChar.getY(), activeChar.getZ());

          activeChar.sendMessage("You recall " + player.getName() + "'s clan.");
        } else {
          activeChar.sendMessage(
              "You recall " + player.getName() + ", but he isn't a clan member.");
          teleportCharacter(player, activeChar.getX(), activeChar.getY(), activeChar.getZ());
        }
      } catch (StringIndexOutOfBoundsException e) {
      }
    } else if (command.startsWith("admin_move_to")) {
      try {
        String val = command.substring(14);
        teleportTo(activeChar, val);
      } catch (Exception e) {
        // Case of empty or missing coordinates
        AdminHelpPage.showHelpPage(activeChar, "teleports.htm");
      }
    } else if (command.startsWith("admin_sendhome")) {
      StringTokenizer st = new StringTokenizer(command);
      if (st.countTokens() > 1) {
        st.nextToken();
        String plyr = st.nextToken();
        L2PcInstance player = L2World.getInstance().getPlayer(plyr);
        if (player == null) {
          activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
          return false;
        }

        sendHome(player);
      } else {
        L2Object target = activeChar.getTarget();
        L2PcInstance player = null;

        // if target isn't a player, select yourself as target
        if (target instanceof L2PcInstance) player = (L2PcInstance) target;
        else player = activeChar;

        sendHome(player);
      }
    }
    return true;
  }
Esempio n. 12
0
  public boolean useAdminCommand(String command, L2PcInstance activeChar) {
    if (command.equals("admin_current_player")) {
      showCharacterInfo(activeChar, null);
    } else if ((command.startsWith("admin_character_list"))
        || (command.startsWith("admin_character_info"))) {
      try {
        String val = command.substring(21);
        L2PcInstance target = L2World.getInstance().getPlayer(val);
        if (target != null) showCharacterInfo(activeChar, target);
        else activeChar.sendPacket(new SystemMessage(SystemMessageId.CHARACTER_DOES_NOT_EXIST));
      } catch (StringIndexOutOfBoundsException e) {
        activeChar.sendMessage(385);
      }
    } else if (command.startsWith("admin_show_characters")) {
      try {
        String val = command.substring(22);
        int page = Integer.parseInt(val);
        listCharacters(activeChar, page);
      } catch (StringIndexOutOfBoundsException e) {
        // Case of empty page number
        activeChar.sendMessage(421);
      }
    } else if (command.startsWith("admin_find_character")) {
      try {
        String val = command.substring(21);
        findCharacter(activeChar, val);
      } catch (StringIndexOutOfBoundsException e) { // Case of empty character name
        activeChar.sendMessage(392);
        listCharacters(activeChar, 0);
      }
    } else if (command.startsWith("admin_find_ip")) {
      try {
        String val = command.substring(14);
        findCharactersPerIp(activeChar, val);
      } catch (Exception e) { // Case of empty or malformed IP number
        activeChar.sendMessage(393);
        listCharacters(activeChar, 0);
      }
    } else if (command.startsWith("admin_find_account")) {
      try {
        String val = command.substring(19);
        findCharactersPerAccount(activeChar, val);
      } catch (Exception e) { // Case of empty or malformed player name
        activeChar.sendMessage(391);
        listCharacters(activeChar, 0);
      }
    } else if (command.equals("admin_edit_character")) editCharacter(activeChar);
    // Karma control commands
    else if (command.equals("admin_nokarma")) setTargetKarma(activeChar, 0);
    else if (command.startsWith("admin_setkarma")) {
      try {
        String val = command.substring(15);
        int karma = Integer.parseInt(val);
        setTargetKarma(activeChar, karma);
      } catch (Exception e) {
        if (Config.DEVELOPER) _log.warning("Set karma error: " + e);
        activeChar.sendMessage(419);
      }
    } else if (command.startsWith("admin_setfame")) {
      try {
        String val = command.substring(14);
        int fame = Integer.parseInt(val);
        L2Object target = activeChar.getTarget();
        if (target instanceof L2PcInstance) {
          L2PcInstance player = (L2PcInstance) target;
          player.setFame(fame);
          player.sendPacket(new UserInfo(player));
          player.sendPacket(new ExBrExtraUserInfo(player));
          L2CoreMessage cm = new L2CoreMessage(MessageTable.Messages[261]);
          cm.addNumber(fame);
          cm.sendMessage(player);
        } else {
          activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
        }
      } catch (Exception e) {
        if (Config.DEVELOPER) _log.warning("Set Fame error: " + e);
        activeChar.sendMessage(316);
      }
    } else if (command.startsWith("admin_save_modifications")) {
      try {
        String val = command.substring(24);
        adminModifyCharacter(activeChar, val);
      } catch (StringIndexOutOfBoundsException e) { // Case of empty character name
        activeChar.sendMessage(113);
        listCharacters(activeChar, 0);
      }
    } else if (command.startsWith("admin_rec")) {
      try {
        String val = command.substring(10);
        int recVal = Integer.parseInt(val);
        L2Object target = activeChar.getTarget();
        L2PcInstance player = null;
        if (target instanceof L2PcInstance) {
          player = (L2PcInstance) target;
        } else {
          return false;
        }
        player.setRecomHave(recVal);
        player.sendMessage(528);
        player.broadcastUserInfo();
      } catch (Exception e) {
        activeChar.sendMessage(414);
      }
    } else if (command.startsWith("admin_setclass")) {
      try {
        String val = command.substring(15);
        int classidval = Integer.parseInt(val);
        L2Object target = activeChar.getTarget();
        L2PcInstance player = null;
        if (target instanceof L2PcInstance) player = (L2PcInstance) target;
        else return false;
        boolean valid = false;
        for (ClassId classid : ClassId.values()) if (classidval == classid.getId()) valid = true;
        if (valid && (player.getClassId().getId() != classidval)) {
          player.setClassId(classidval);
          if (!player.isSubClassActive()) player.setBaseClass(classidval);
          String newclass = player.getTemplate().className;
          player.store();
          L2CoreMessage cm = new L2CoreMessage(MessageTable.Messages[14]);
          cm.addString(newclass);
          cm.sendMessage(player);
          player.broadcastUserInfo();
          cm = new L2CoreMessage(MessageTable.Messages[670]);
          cm.addString(player.getName());
          cm.addString(newclass);
          cm.sendMessage(activeChar);
        }
        activeChar.sendMessage(418);
      } catch (StringIndexOutOfBoundsException e) {
        AdminHelpPage.showHelpPage(activeChar, "charclasses.htm");
      }
    } else if (command.startsWith("admin_settitle")) {
      try {
        String val = command.substring(15);
        L2Object target = activeChar.getTarget();
        L2PcInstance player = null;
        if (target instanceof L2PcInstance) {
          player = (L2PcInstance) target;
        } else {
          return false;
        }
        player.setTitle(val);
        player.sendMessage(644);
        player.broadcastTitleInfo();
      } catch (StringIndexOutOfBoundsException e) { // Case of empty character title
        activeChar.sendMessage(584);
      }
    } else if (command.startsWith("admin_changename")) {
      try {
        String val = command.substring(17);
        L2Object target = activeChar.getTarget();
        L2PcInstance player = null;
        if (target instanceof L2PcInstance) {
          player = (L2PcInstance) target;
        } else {
          return false;
        }
        L2World.getInstance().removeFromAllPlayers(player);
        player.setName(val);
        player.store();
        L2World.getInstance().addToAllPlayers(player);

        player.sendMessage(623);
        player.broadcastUserInfo();

        if (player.isInParty()) {
          // Delete party window for other party members
          player.getParty().broadcastToPartyMembers(player, new PartySmallWindowDeleteAll());
          for (L2PcInstance member : player.getParty().getPartyMembers()) {
            // And re-add
            if (member != player)
              member.sendPacket(new PartySmallWindowAll(member, player.getParty()));
          }
        }
        if (player.getClan() != null) {
          player.getClan().broadcastClanStatus();
        }

        RegionBBSManager.getInstance().changeCommunityBoard();
      } catch (StringIndexOutOfBoundsException e) { // Case of empty character name
        activeChar.sendMessage(420);
      }
    } else if (command.startsWith("admin_setsex")) {
      L2Object target = activeChar.getTarget();
      L2PcInstance player = null;
      if (target instanceof L2PcInstance) {
        player = (L2PcInstance) target;
      } else {
        return false;
      }
      player.getAppearance().setSex(player.getAppearance().getSex() ? false : true);
      player.sendMessage(621);
      player.broadcastUserInfo();
      player.decayMe();
      player.spawnMe(player.getX(), player.getY(), player.getZ());
    } else if (command.startsWith("admin_setcolor")) {
      try {
        String val = command.substring(15);
        L2Object target = activeChar.getTarget();
        L2PcInstance player = null;
        if (target instanceof L2PcInstance) {
          player = (L2PcInstance) target;
        } else {
          return false;
        }
        player.getAppearance().setNameColor(Integer.decode("0x" + val));
        player.sendMessage(622);
        player.broadcastUserInfo();
      } catch (Exception e) { // Case of empty color or invalid hex string
        activeChar.sendMessage(583);
      }
    } else if (command.startsWith("admin_fullfood")) {
      L2Object target = activeChar.getTarget();
      if (target instanceof L2PetInstance) {
        L2PetInstance targetPet = (L2PetInstance) target;
        targetPet.setCurrentFed(targetPet.getMaxFed());
        targetPet
            .getOwner()
            .sendPacket(new SetSummonRemainTime(targetPet.getMaxFed(), targetPet.getCurrentFed()));
      } else activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
    } else if (command.startsWith("admin_unpenalty")) {
      try {
        StringTokenizer st = new StringTokenizer(command, " ");
        if (st.countTokens() != 3) {
          activeChar.sendMessage(364);
          return false;
        }

        st.nextToken();

        boolean changeCreateExpiryTime = st.nextToken().equalsIgnoreCase("create");

        String playerName = st.nextToken();
        L2PcInstance player = null;
        player = L2World.getInstance().getPlayer(playerName);

        if (player == null) {
          Connection con = L2DatabaseFactory.getInstance().getConnection();
          PreparedStatement ps =
              con.prepareStatement(
                  "UPDATE characters SET "
                      + (changeCreateExpiryTime
                          ? "clan_create_expiry_time"
                          : "clan_join_expiry_time")
                      + " WHERE char_name=? LIMIT 1");

          ps.setString(1, playerName);
          ps.execute();
        } else {
          // removing penalty
          if (changeCreateExpiryTime) player.setClanCreateExpiryTime(0);
          else player.setClanJoinExpiryTime(0);
        }

        L2CoreMessage cm = new L2CoreMessage(MessageTable.Messages[470]);
        cm.addString(playerName);
        cm.sendMessage(activeChar);
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else if (command.startsWith("admin_find_dualbox")) {
      int multibox = 2;
      try {
        String val = command.substring(19);
        multibox = Integer.parseInt(val);
        if (multibox < 1) {
          activeChar.sendMessage(97);
          return false;
        }
      } catch (Exception e) {
      }
      findDualbox(activeChar, multibox);
    }

    return true;
  }
Esempio n. 13
0
  /**
   * @param activeChar
   * @param IpAdress
   * @throws IllegalArgumentException
   */
  private void findCharactersPerIp(L2PcInstance activeChar, String IpAdress)
      throws IllegalArgumentException {
    boolean findDisconnected = false;

    if (IpAdress.equals("disconnected")) {
      findDisconnected = true;
    } else {
      if (!IpAdress.matches(
          "^(?:(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2(?:[0-4][0-9]|5[0-5]))\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2(?:[0-4][0-9]|5[0-5]))$"))
        throw new IllegalArgumentException("Malformed IPv4 number");
    }
    Collection<L2PcInstance> allPlayers = L2World.getInstance().getAllPlayers().values();
    L2PcInstance[] players;
    // synchronized (L2World.getInstance().getAllPlayers())
    {
      players = allPlayers.toArray(new L2PcInstance[allPlayers.size()]);
    }
    int CharactersFound = 0;
    L2GameClient client;
    String name, ip = "0.0.0.0";
    final StringBuilder replyMSG = new StringBuilder(1000);
    NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
    adminReply.setFile("data/html/admin/ipfind.htm");
    for (L2PcInstance player : players) {
      client = player.getClient();
      if (client.isDetached()) {
        if (!findDisconnected) {
          continue;
        }
      } else {
        if (findDisconnected) {
          continue;
        } else {
          ip = client.getConnection().getInetAddress().getHostAddress();
          if (!ip.equals(IpAdress)) continue;
        }
      }

      name = player.getName();
      CharactersFound = CharactersFound + 1;
      StringUtil.append(
          replyMSG,
          "<tr><td width=80><a action=\"bypass -h admin_character_list ",
          name,
          "\">",
          name,
          "</a></td><td width=110>",
          player.getTemplate().className,
          "</td><td width=40>",
          String.valueOf(player.getLevel()),
          "</td></tr>");

      if (CharactersFound > 20) break;
    }
    adminReply.replace("%results%", replyMSG.toString());

    final String replyMSG2;

    if (CharactersFound == 0) {
      replyMSG2 = MessageTable.Messages[681].getMessage();
    } else if (CharactersFound > 20) {
      adminReply.replace(
          "%number%", MessageTable.Messages[1213].getMessage() + String.valueOf(CharactersFound));
      replyMSG2 = MessageTable.Messages[682].getMessage();
    } else if (CharactersFound == 1) {
      replyMSG2 = MessageTable.Messages[1196].getMessage();
    } else {
      replyMSG2 = MessageTable.Messages[1197].getMessage();
    }
    adminReply.replace("%ip%", ip);
    adminReply.replace("%number%", String.valueOf(CharactersFound));
    adminReply.replace("%end%", replyMSG2);
    activeChar.sendPacket(adminReply);
  }
Esempio n. 14
0
  @Override
  protected void runImpl() {
    if (!FloodProtectors.performAction(getClient(), Action.SERVER_BYPASS)) return;

    final L2PcInstance activeChar = getClient().getActiveChar();
    if (activeChar == null) return;

    if (_command.isEmpty()) {
      _log.info(activeChar.getName() + " sent an empty requestBypass packet.");
      activeChar.logout();
      return;
    }

    try {
      if (_command.startsWith("admin_")) {
        String command = _command.split(" ")[0];

        IAdminCommandHandler ach =
            AdminCommandHandler.getInstance().getAdminCommandHandler(command);
        if (ach == null) {
          if (activeChar.isGM())
            activeChar.sendMessage("The command " + command.substring(6) + " doesn't exist.");

          _log.warning("No handler registered for admin command '" + command + "'");
          return;
        }

        if (!AdminCommandAccessRights.getInstance()
            .hasAccess(command, activeChar.getAccessLevel())) {
          activeChar.sendMessage("You don't have the access rights to use this command.");
          _log.warning(
              activeChar.getName()
                  + " tried to use admin command "
                  + command
                  + " without proper Access Level.");
          return;
        }

        if (Config.GMAUDIT)
          GMAudit.auditGMAction(
              activeChar.getName() + " [" + activeChar.getObjectId() + "]",
              _command,
              (activeChar.getTarget() != null ? activeChar.getTarget().getName() : "no-target"));

        ach.useAdminCommand(_command, activeChar);
      } else if (_command.startsWith("player_help ")) {
        playerHelp(activeChar, _command.substring(12));
      } else if (_command.startsWith("npc_")) {
        if (!activeChar.validateBypass(_command)) return;

        int endOfId = _command.indexOf('_', 5);
        String id;
        if (endOfId > 0) id = _command.substring(4, endOfId);
        else id = _command.substring(4);

        try {
          final L2Object object = L2World.getInstance().getObject(Integer.parseInt(id));

          if (object != null
              && object instanceof L2Npc
              && endOfId > 0
              && ((L2Npc) object).canInteract(activeChar))
            ((L2Npc) object).onBypassFeedback(activeChar, _command.substring(endOfId + 1));

          activeChar.sendPacket(ActionFailed.STATIC_PACKET);
        } catch (NumberFormatException nfe) {
        }
      }
      // Navigate throught Manor windows
      else if (_command.startsWith("manor_menu_select?")) {
        L2Object object = activeChar.getTarget();
        if (object instanceof L2Npc) ((L2Npc) object).onBypassFeedback(activeChar, _command);
      } else if (_command.startsWith("bbs_")
          || _command.startsWith("_bbs")
          || _command.startsWith("_friend")
          || _command.startsWith("_mail")
          || _command.startsWith("_block")) {
        CommunityBoard.getInstance().handleCommands(getClient(), _command);
      } else if (_command.startsWith("Quest ")) {
        if (!activeChar.validateBypass(_command)) return;

        String[] str = _command.substring(6).trim().split(" ", 2);
        if (str.length == 1) activeChar.processQuestEvent(str[0], "");
        else activeChar.processQuestEvent(str[0], str[1]);
      } else if (_command.startsWith("_match")) {
        String params = _command.substring(_command.indexOf("?") + 1);
        StringTokenizer st = new StringTokenizer(params, "&");
        int heroclass = Integer.parseInt(st.nextToken().split("=")[1]);
        int heropage = Integer.parseInt(st.nextToken().split("=")[1]);
        int heroid = Hero.getInstance().getHeroByClass(heroclass);
        if (heroid > 0) Hero.getInstance().showHeroFights(activeChar, heroclass, heroid, heropage);
      } else if (_command.startsWith("_diary")) {
        String params = _command.substring(_command.indexOf("?") + 1);
        StringTokenizer st = new StringTokenizer(params, "&");
        int heroclass = Integer.parseInt(st.nextToken().split("=")[1]);
        int heropage = Integer.parseInt(st.nextToken().split("=")[1]);
        int heroid = Hero.getInstance().getHeroByClass(heroclass);
        if (heroid > 0) Hero.getInstance().showHeroDiary(activeChar, heroclass, heroid, heropage);
      } else if (_command.startsWith("arenachange")) // change
      {
        final boolean isManager =
            activeChar.getCurrentFolkNPC() instanceof L2OlympiadManagerInstance;
        if (!isManager) {
          // Without npc, command can be used only in observer mode on arena
          if (!activeChar.inObserverMode()
              || activeChar.isInOlympiadMode()
              || activeChar.getOlympiadGameId() < 0) return;
        }

        if (OlympiadManager.getInstance().isRegisteredInComp(activeChar)) {
          activeChar.sendPacket(
              SystemMessageId
                  .WHILE_YOU_ARE_ON_THE_WAITING_LIST_YOU_ARE_NOT_ALLOWED_TO_WATCH_THE_GAME);
          return;
        }

        final int arenaId = Integer.parseInt(_command.substring(12).trim());
        activeChar.enterOlympiadObserverMode(arenaId);
      }
    } catch (Exception e) {
      _log.log(Level.WARNING, "Bad RequestBypassToServer: ", e);
    }
  }
Esempio n. 15
0
  @Override
  public boolean useAdminCommand(String command, L2PcInstance activeChar) {
    StringTokenizer st = new StringTokenizer(command);
    st.nextToken();
    String player = "";
    int duration = -1;
    L2PcInstance targetPlayer = null;

    // One parameter, player name
    if (st.hasMoreTokens()) {
      player = st.nextToken();
      targetPlayer = L2World.getInstance().getPlayer(player);

      // Second parameter, duration
      if (st.hasMoreTokens()) {
        try {
          duration = Integer.parseInt(st.nextToken());
        } catch (NumberFormatException nfe) {
          activeChar.sendMessage("Invalid number format used: " + nfe);
          return false;
        }
      }
    } else {
      // If there is no name, select target
      if (activeChar.getTarget() != null && activeChar.getTarget() instanceof L2PcInstance)
        targetPlayer = (L2PcInstance) activeChar.getTarget();
    }

    // Can't ban yourself
    if (targetPlayer != null && targetPlayer.equals(activeChar)) {
      activeChar.sendPacket(SystemMessageId.CANNOT_USE_ON_YOURSELF);
      return false;
    }

    if (command.startsWith("admin_ban ") || command.equalsIgnoreCase("admin_ban")) {
      activeChar.sendMessage("Available ban commands: //ban_acc, //ban_char, //ban_chat");
      return false;
    } else if (command.startsWith("admin_ban_acc")) {
      if (targetPlayer == null && player.equals("")) {
        activeChar.sendMessage(
            "Usage: //ban_acc <account_name> (if none, target char's account gets banned).");
        return false;
      } else if (targetPlayer == null) {
        LoginServerThread.getInstance().sendAccessLevel(player, -100);
        activeChar.sendMessage("Ban request sent for account " + player + ".");
        auditAction(command, activeChar, player);
      } else {
        targetPlayer.setPunishLevel(L2PcInstance.PunishLevel.ACC, 0);
        activeChar.sendMessage(targetPlayer.getAccountName() + " account is now banned.");
        auditAction(command, activeChar, targetPlayer.getAccountName());
      }
    } else if (command.startsWith("admin_ban_char")) {
      if (targetPlayer == null && player.equals("")) {
        activeChar.sendMessage("Usage: //ban_char <char_name> (if none, target char is banned)");
        return false;
      }

      auditAction(command, activeChar, (targetPlayer == null ? player : targetPlayer.getName()));
      return changeCharAccessLevel(targetPlayer, player, activeChar, -100);
    } else if (command.startsWith("admin_ban_chat")) {
      if (targetPlayer == null && player.equals("")) {
        activeChar.sendMessage("Usage: //ban_chat <char_name> [penalty_minutes]");
        return false;
      }

      if (targetPlayer != null) {
        if (targetPlayer.getPunishLevel().value() > 0) {
          activeChar.sendMessage(targetPlayer.getName() + " is already jailed or banned.");
          return false;
        }

        String banLengthStr = "";
        targetPlayer.setPunishLevel(L2PcInstance.PunishLevel.CHAT, duration);

        if (duration > 0) banLengthStr = " for " + duration + " minutes";

        activeChar.sendMessage(targetPlayer.getName() + " is now chat banned" + banLengthStr + ".");
        auditAction(command, activeChar, targetPlayer.getName());
      } else {
        banChatOfflinePlayer(activeChar, player, duration, true);
        auditAction(command, activeChar, player);
      }
    } else if (command.startsWith("admin_unban ") || command.equalsIgnoreCase("admin_unban")) {
      activeChar.sendMessage("Available unban commands: //unban_acc, //unban_char, //unban_chat");
      return false;
    } else if (command.startsWith("admin_unban_acc")) {
      if (targetPlayer != null) {
        activeChar.sendMessage(
            targetPlayer.getName() + " is currently online so mustn't be banned.");
        return false;
      } else if (!player.equals("")) {
        LoginServerThread.getInstance().sendAccessLevel(player, 0);
        activeChar.sendMessage("Unban request sent for account " + player + ".");
        auditAction(command, activeChar, player);
      } else {
        activeChar.sendMessage("Usage: //unban_acc <account_name>");
        return false;
      }
    } else if (command.startsWith("admin_unban_char")) {
      if (targetPlayer == null && player.equals("")) {
        activeChar.sendMessage("Usage: //unban_char <char_name>");
        return false;
      } else if (targetPlayer != null) {
        activeChar.sendMessage(
            targetPlayer.getName() + " is currently online so mustn't be banned.");
        return false;
      } else {
        auditAction(command, activeChar, player);
        return changeCharAccessLevel(null, player, activeChar, 0);
      }
    } else if (command.startsWith("admin_unban_chat")) {
      if (targetPlayer == null && player.equals("")) {
        activeChar.sendMessage("Usage: //unban_chat <char_name>");
        return false;
      }

      if (targetPlayer != null) {
        if (targetPlayer.isChatBanned()) {
          targetPlayer.setPunishLevel(L2PcInstance.PunishLevel.NONE, 0);
          activeChar.sendMessage(targetPlayer.getName() + "'s chat ban has been lifted.");
          auditAction(command, activeChar, targetPlayer.getName());
        } else activeChar.sendMessage(targetPlayer.getName() + " isn't currently chat banned.");
      } else {
        banChatOfflinePlayer(activeChar, player, 0, false);
        auditAction(command, activeChar, player);
      }
    } else if (command.startsWith("admin_jail")) {
      if (targetPlayer == null && player.equals("")) {
        activeChar.sendMessage(
            "Usage: //jail <charname> [penalty_minutes] (if no name is given, selected target is jailed forever).");
        return false;
      }

      if (targetPlayer != null) {
        targetPlayer.setPunishLevel(L2PcInstance.PunishLevel.JAIL, duration);
        activeChar.sendMessage(
            targetPlayer.getName()
                + " have been jailed for "
                + (duration > 0 ? duration + " minutes." : "ever !"));
        auditAction(command, activeChar, targetPlayer.getName());
      } else {
        jailOfflinePlayer(activeChar, player, duration);
        auditAction(command, activeChar, player);
      }
    } else if (command.startsWith("admin_unjail")) {
      if (targetPlayer == null && player.equals("")) {
        activeChar.sendMessage("Usage: //unjail <charname> (If no name is given target is used).");
        return false;
      } else if (targetPlayer != null) {
        targetPlayer.setPunishLevel(L2PcInstance.PunishLevel.NONE, 0);
        activeChar.sendMessage(targetPlayer.getName() + " have been unjailed.");
        auditAction(command, activeChar, targetPlayer.getName());
      } else {
        unjailOfflinePlayer(activeChar, player);
        auditAction(command, activeChar, player);
      }
    }
    return true;
  }