Example #1
0
 public static void reloadAll() {
   MapRegionManager.getInstance().reload();
   ZoneManager.getInstance().reload();
   AuctionManager.getInstance().reload();
   CastleManager.getInstance().reload();
   ClanHallManager.getInstance().reload();
 }
  /**
   * Ends the given auction and sends the notifications
   *
   * @param auction
   */
  public synchronized void endAuction(Auction auction) {
    if (null != AuctionManager.getInstance().getAuctionById(auction.getId())) {
      AuctionManager.getInstance().removeAuction(auction);

      try {
        Bid highestBid = auction.getHighestBid();
        if (highestBid != null) {
          try {
            billingServer.billAuction(
                auction.getCreator().getUsername(),
                auction.getId(),
                auction.getHighestBid().getAmount());
          } catch (RemoteException e) {
            log.warn("could not bill auction: " + e.getMessage());
          }
        }

        analyticsServer.processEvent(AuctionEvent.createAuctionEnded(auction.getId()));

        List<StatisticEvent> events;

        if (highestBid != null) {
          analyticsServer.processEvent(
              BidEvent.createBidWonEvent(
                  highestBid.getBidder().getUsername(),
                  highestBid.getAuction().getId(),
                  highestBid.getAmount()));

          // create successful auction_ended events
          events = StatisticEvent.createEventsOnAuctionEnded((long) auction.getDuration(), true);
        } else {
          // unsuccessful auction_ended events, because no bid
          events = StatisticEvent.createEventsOnAuctionEnded((long) auction.getDuration(), false);
        }

        for (StatisticEvent e : events) analyticsServer.processEvent(e);

      } catch (RemoteException e) {
        log.warn("could not process event: " + e.getMessage());
      }

      notifyAuctionEnded(auction);
    }
  }
  public GameServerStartup() throws Exception {
    long serverLoadStart = System.currentTimeMillis();

    gameServer = this;

    printSection("Database Engine");
    L2DatabaseFactory.getInstance();

    printSection("IDFactory Engine");
    IdFactory.getInstance();
    _log.log(Level.INFO, "IdFactory: Free ObjectID's remaining: " + IdFactory.getInstance().size());

    ThreadPoolManager.getInstance();

    printSection("Engines");
    ScriptsManager.getInstance();
    ServerPacketOpCodeManager.getInstance();

    printSection("World Engine");
    Colors.loadColors();
    GameTimeController.init();
    InstanceManager.getInstance();
    WorldManager.getInstance();
    MapRegionManager.getInstance();
    Announcements.getInstance();
    GlobalVariablesManager.getInstance();
    AccountShareDataTable.getInstance();
    DynamicSpawnData.getInstance();
    ResidenceFunctionData.getInstance();

    printSection("Skills Engine");
    BuffStackGroupData.getInstance();
    EnchantSkillGroupsTable.getInstance();
    SkillTable.getInstance().load(false);
    SkillTreesData.getInstance();

    printSection("Items Engine");
    ItemTable.getInstance().loadClient();
    ItemTable.getInstance().load(false);
    SummonItemsData.getInstance();
    EnchantBonusData.getInstance();
    BuyListData.getInstance();
    MultiSellData.getInstance();
    RecipeData.getInstance();
    // PrimeShopTable.getInstance(); TODO
    ArmorSetsTable.getInstance();
    FishData.getInstance();
    FishingRodsData.getInstance();
    EnchantItemData.getInstance();
    EnchantEffectTable.getInstance();
    CrystallizationData.getInstance();
    SoulCrystalData.getInstance();
    ShapeShiftingItemsData.getInstance();
    HennaTable.getInstance();
    HennaTreeTable.getInstance();
    AugmentationData.getInstance();
    ItemPriceData.getInstance();
    AbilityPointsData.getInstance();
    AlchemyDataTable.getInstance();

    printSection("Characters Engine");
    CharTemplateTable.getInstance();
    ClassTemplateTable.getInstance();
    CharNameTable.getInstance();
    ExperienceTable.getInstance();
    AdminTable.getInstance();
    RaidBossPointsManager.getInstance();
    RelationListManager.getInstance();
    PetDataTable.getInstance();
    CharSummonTable.getInstance();
    SummonPointsTable.getInstance();
    HitConditionBonus.getInstance();
    ObsceneFilterTable.getInstance();

    printSection("Clans Engine");
    ClanTable.getInstance();
    ClanTable.getInstance().restoreWars();
    ClanHallSiegeManager.getInstance();
    ClanHallManager.getInstance();
    AuctionManager.getInstance();

    printSection("Geodata Engine");
    GeoEngine.init();
    PathFinding.init();
    DoorGeoEngine.init();

    printSection("NPCs Engine");
    HerbDropTable.getInstance();
    NpcTable.getInstance();
    AutoChatDataTable.getInstance();
    NpcWalkerRoutesData.getInstance();
    WalkingManager.getInstance();
    ZoneManager.getInstance();
    StaticObjectsData.getInstance();
    ItemAuctionManager.getInstance();
    CastleManager.getInstance();
    FortManager.getInstance().init();
    SpawnTable.getInstance();
    AutoSpawnHandler.getInstance();
    HellboundManager.getInstance();
    RaidBossSpawnManager.getInstance();
    DayNightSpawnManager.getInstance().trim().notifyChangeMode();
    GrandBossManager.getInstance().initZones();
    FourSepulchersManager.getInstance().init();
    TeleportListTable.getInstance();
    BeautyShopData.getInstance();
    CustomDropListDataXml.getInstance();

    printSection("Residence Siege Engine");
    CastleSiegeManager.getInstance().getSieges();
    FortSpawnList.getInstance();
    FortSiegeManager.getInstance();
    CastleManorManager.getInstance();
    CastleMercTicketManager.getInstance();
    ManorData.getInstance();
    ResidenceSiegeMusicList.getInstance();

    printSection("Olympiad Engine");
    Olympiad.getInstance();
    HeroManager.getInstance();

    printSection("Cache Engine");
    CrestCache.getInstance();
    HtmCache.getInstance();

    PartyMatchWaitingList.getInstance();
    PartyMatchRoomList.getInstance();
    PetitionManager.getInstance();
    CursedWeaponsManager.getInstance();
    CommunityBuffTable.getInstance();
    CommunityTeleportData.getInstance();

    printSection("Mods Engine");
    PcCafePointsManager.getInstance();

    if (Config.MMO_TOP_MANAGER_ENABLED) {
      MMOTopManager.getInstance();
    }
    if (Config.L2_TOP_MANAGER_ENABLED) {
      L2TopManager.getInstance();
    }

    printSection("Handlers Engine");
    ActionHandler.getInstance();
    ActionShiftHandler.getInstance();
    AdminCommandHandler.getInstance();
    BypassCommandManager.getInstance();
    ChatCommandManager.getInstance();
    EffectHandler.getInstance();
    ItemHandler.getInstance();
    SkillHandler.getInstance();
    TargetHandler.getInstance();
    TransformHandler.getInstance();
    UserCommandManager.getInstance();
    VoicedHandlerManager.getInstance();

    printSection("Transformations Engine");
    TransformationManager.getInstance();
    TransformationManager.getInstance().report();

    printSection("Jump Engine");
    CharJumpRoutesTable.getInstance();

    printSection("Commission Engine");
    CommissionManager.getInstance();

    printSection("ClanSearch Engine");
    ClanSearchManager.getInstance();

    printSection("Awakening Engine");
    AwakeningManager.getInstance();

    printSection("World Statistics Engine");
    if (ConfigWorldStatistic.WORLD_STATISTIC_ENABLED) {
      WorldStatisticsManager.getInstance();
    } else {
      _log.log(Level.INFO, "World Statistic Engine Disabled");
    }

    printSection("Quests Engine");
    QuestManager.getInstance();
    DynamicQuestManager.getInstance();
    BoatManager.getInstance();
    AirShipManager.getInstance();
    ShuttleManager.getInstance();
    GraciaSeedsManager.getInstance();
    if (Config.ALLOW_WEDDING) {
      WeddingManager.getInstance();
    }
    AutoChatDataTable.getInstance().setAutoChatActive(true);

    printSection("Scripts Engine");
    ScriptsManager.getInstance().executeCoreScripts();

    TaskManager.getInstance();

    QuestManager.getInstance().report();

    if (Config.SAVE_DROPPED_ITEM) {
      ItemsOnGroundManager.getInstance();
    }

    if (Config.AUTODESTROY_ITEM_AFTER > 0 || Config.HERB_AUTO_DESTROY_TIME > 0) {
      ItemsOnGroundAutoDestroyManager.getInstance();
    }

    CastleManager.getInstance().spawnDoors();
    FortManager.getInstance().spawnDoors();

    if (Config.ALLOW_MAIL) {
      MailManager.getInstance();
    }

    MentorManager.getInstance();
    DuelManager.getInstance();

    Runtime.getRuntime().addShutdownHook(GameServerShutdown.getInstance());

    _log.log(Level.INFO, "IdFactory: Free ObjectID's remaining: " + IdFactory.getInstance().size());

    EventManager.getEventsInstances();

    KnownListUpdateTaskManager.getInstance();

    if ((Config.OFFLINE_TRADE_ENABLE || Config.OFFLINE_CRAFT_ENABLE) && Config.RESTORE_OFFLINERS) {
      OfflineTradersTable.restoreOfflineTraders();
    }

    if (Config.DEADLOCK_DETECTOR) {
      _deadDetectThread = new DeadLockDetector();
      _deadDetectThread.setDaemon(true);
      _deadDetectThread.start();
    } else {
      _deadDetectThread = null;
    }

    printSection("Finalization");
    System.runFinalization();
    System.gc();
    Util.printMemoryInfo();
    Util.printCpuInfo();
    Util.printOSInfo();
    Toolkit.getDefaultToolkit().beep();

    printSection("Server Thread");
    LoginServerThread.getInstance().start();

    SelectorConfig sc = new SelectorConfig();
    sc.MAX_READ_PER_PASS = Config.MMO_MAX_READ_PER_PASS;
    sc.MAX_SEND_PER_PASS = Config.MMO_MAX_SEND_PER_PASS;
    sc.SLEEP_TIME = Config.MMO_SELECTOR_SLEEP_TIME;
    sc.HELPER_BUFFER_COUNT = Config.MMO_HELPER_BUFFER_COUNT;
    sc.TCP_NODELAY = Config.MMO_TCP_NODELAY;

    _gamePacketHandler = new L2GamePacketHandler();
    _selectorThread =
        new SelectorThread<>(
            sc, _gamePacketHandler, _gamePacketHandler, _gamePacketHandler, new IPv4Filter());

    InetAddress bindAddress = null;
    if (!Config.GAMESERVER_HOSTNAME.equals("*")) {
      try {
        bindAddress = InetAddress.getByName(Config.GAMESERVER_HOSTNAME);
      } catch (UnknownHostException e1) {
        _log.log(
            Level.ERROR,
            "GameServerStartup: The GameServer bind address is invalid, using all avaliable IPs. Reason: "
                + e1.getMessage(),
            e1);
      }
    }

    try {
      _selectorThread.openServerSocket(bindAddress, Config.PORT_GAME);
    } catch (IOException e) {
      _log.log(
          Level.FATAL,
          "GameServerStartup:: Failed to open server socket. Reason: " + e.getMessage(),
          e);
      System.exit(1);
    }
    _selectorThread.start();
    _log.log(Level.INFO, "Maximum Numbers of Connected Players: " + Config.MAXIMUM_ONLINE_USERS);
    long serverLoadEnd = System.currentTimeMillis();
    _log.log(
        Level.INFO, "Server Loaded in " + (serverLoadEnd - serverLoadStart) / 1000L + " seconds");

    AutoAnnounceTaskManager.getInstance();

    XMLRPCServer.getInstance();
  }
  // create events here
  public synchronized void processMessage(TCPServerConnection tcpConnection, String input) {
    if (input.startsWith("!login")) {
      String username;
      int udpPort = 0;
      try {
        String[] parts = input.split(" ");
        username = parts[1].trim();
        udpPort = Integer.parseInt(parts[2]);
        if (getUser(tcpConnection) == null) {
          User user = addUser(username, tcpConnection);
          analyticsServer.processEvent((EventInterface) UserEvent.createUserLogin(username));
          user.setUdpPort(udpPort);
          tcpConnection.sendMessage("Successfully logged in as " + user.getUsername());
        }
      } catch (IndexOutOfBoundsException e) {
        tcpConnection.sendMessage("You must provide a username!");
      } catch (NumberFormatException e) {
        tcpConnection.sendMessage("Login failed.");
      } catch (ConnectException e) {
        log.warn("could not connect to analytics server.");
      } catch (RemoteException e) {
        log.warn("could not process event: " + e.getMessage());
      }
    } else if (input.trim().equals("!logout")) {
      User user = getUser(tcpConnection);
      if (user == null) {
        tcpConnection.sendMessage("You have to login first!");
      } else {
        String username = user.getUsername();
        users.remove(user);
        try {
          analyticsServer.processEvent(UserEvent.createUserLogout(username));
          user.endSession();
          for (StatisticEvent e :
              StatisticEvent.createEventsOnUserLogout(user.getSessionDuration())) {
            analyticsServer.processEvent(e);
          }

        } catch (ConnectException e) {
          log.warn("could not connect to analytics server.");
        } catch (RemoteException e) {
          log.warn("could not process event: " + e.getMessage());
        }
        tcpConnection.sendMessage("You successfully logged out as " + user.getUsername());
      }
    } else if (input.trim().equals("!end")) {
      User user = getUser(tcpConnection);
      if (user != null)
        try {
          analyticsServer.processEvent(UserEvent.createUserDisconnected(user.getUsername()));
          user.endSession();
          for (StatisticEvent e :
              StatisticEvent.createEventsOnUserLogout(user.getSessionDuration())) {
            analyticsServer.processEvent(e);
          }
        } catch (ConnectException e) {
          log.warn("could not connect to analytics server.");
        } catch (RemoteException e) {
          log.warn("could not process event: " + e.getMessage());
        }
    } else if (input.trim().equals("!list")) {
      for (Auction auction : AuctionManager.getInstance().getAuctions()) {
        Bid heighestBid = auction.getHighestBid();

        String msg =
            String.format(
                "%d. '%s' %s %s %s",
                auction.getId(),
                auction.getName(),
                auction.getCreator().getUsername(),
                heighestBid == null ? "0.00" : heighestBid.getAmount(),
                heighestBid == null ? "none" : heighestBid.getBidder().getUsername());

        tcpConnection.sendMessage(msg);
      }
    } else if (input.startsWith("!create")) {
      if (getUser(tcpConnection) == null) {
        tcpConnection.sendMessage("login first!");
        return;
      }
      try {
        String[] parts = input.split(" ");
        StringBuilder sb = new StringBuilder();
        for (int i = 2; i < parts.length; i++) {
          sb.append(parts[i]).append(" ");
        }
        Auction auction =
            AuctionManager.getInstance()
                .createAuction(
                    sb.toString().trim(), Integer.valueOf(parts[1]), getUser(tcpConnection));

        analyticsServer.processEvent(AuctionEvent.createAuctionStarted(auction.getId()));

        tcpConnection.sendMessage(
            "An auction '"
                + auction.getName()
                + "' with id "
                + auction.getId()
                + " has been created and will end on "
                + auction.getEndDateFormatted());

      } catch (IndexOutOfBoundsException e) {
        tcpConnection.sendMessage("You must provide the duration and the name of the auction!");
      } catch (NumberFormatException e) {
        tcpConnection.sendMessage("After !create you must enter the seconds!");
      } catch (ConnectException e) {
        log.warn("could not connect to analytics server.");
      } catch (RemoteException e) {
        log.warn("could not process event: " + e.getMessage());
      }
    } else if (input.startsWith("!bid")) {
      try {
        String[] parts = input.split(" ");
        int auctionId = Integer.parseInt(parts[1]);
        double amount = Double.parseDouble(parts[2]);
        Bid heighestBid = AuctionManager.getInstance().getHeighestBid(auctionId);
        User user = getUser(tcpConnection);
        Auction auction = AuctionManager.getInstance().getAuctionById(auctionId);
        if (user == null) {
          tcpConnection.sendMessage("You have to login first!");
        } else if (auction != null && user.equals(auction.getCreator())) {
          tcpConnection.sendMessage("You may not bid on your own auction!");
        } else {
          Bid bid = AuctionManager.getInstance().newBid(amount, auctionId, user);
          if (bid != null) {

            try {
              analyticsServer.processEvent(
                  BidEvent.createBidPlacedEvent(
                      user.getUsername(), auction.getId(), bid.getAmount()));
              List<StatisticEvent> events = StatisticEvent.createEventsOnBidPlaced(bid.getAmount());
              for (StatisticEvent e : events) {
                analyticsServer.processEvent(e);
              }
            } catch (ConnectException e) {
              log.warn("could not connect to analytics server.");
            } catch (RemoteException e) {
              log.warn("could not process event: " + e.getMessage());
            }
            tcpConnection.sendMessage(
                "You successfully bid with "
                    + bid.getAmount()
                    + " on '"
                    + bid.getAuction().getName()
                    + "'");

            if (heighestBid != null && !user.equals(heighestBid.getBidder())) {
              try {
                analyticsServer.processEvent(
                    BidEvent.createBidOverbidEvent(
                        heighestBid.getBidder().getUsername(),
                        heighestBid.getAuction().getId(),
                        heighestBid.getAmount()));
              } catch (RemoteException e) {
                log.warn("could not process event: " + e.getMessage());
              }
              notifyUser(
                  heighestBid.getBidder(),
                  "You have been overbid on '" + heighestBid.getAuction().getName() + "'");
            }
          } else {
            tcpConnection.sendMessage("invalid bid");
          }
        }
      } catch (IndexOutOfBoundsException e) {
        tcpConnection.sendMessage("!bid usage: !bid auction.id bid.amount");
      } catch (NumberFormatException e) {
        tcpConnection.sendMessage("argument 2: int auction id, argument 3: double amount");
      }
    }
  }