public void select(Castle castle) { Connection con = null; PreparedStatement statement = null; ResultSet rset = null; try { con = DatabaseFactory.getInstance().getConnection(); statement = con.prepareStatement(SELECT_SQL_QUERY); statement.setInt(1, castle.getId()); rset = statement.executeQuery(); if (rset.next()) { castle.setTaxPercent(rset.getInt("tax_percent")); castle.setTreasury(rset.getLong("treasury")); castle.setRewardCount(rset.getInt("reward_count")); castle.getSiegeDate().setTimeInMillis(rset.getLong("siege_date") * 1000L); castle.getLastSiegeDate().setTimeInMillis(rset.getLong("last_siege_date") * 1000L); castle.getOwnDate().setTimeInMillis(rset.getLong("own_date") * 1000L); castle.setResidenceSide(ResidenceSide.VALUES[rset.getInt("side")], true); } } catch (Exception e) { _log.error("CastleDAO.select(Castle):" + e, e); } finally { DbUtils.closeQuietly(con, statement, rset); } }
public void deletePet(ItemInstance item, Creature owner) { int petObjectId = 0; Connection con = null; PreparedStatement statement = null; ResultSet rset = null; try { int itemObjId = item.getObjectId(); con = DatabaseFactory.getInstance().getConnection(); statement = con.prepareStatement(SELECT_SQL_QUERY); statement.setInt(1, itemObjId); rset = statement.executeQuery(); while (rset.next()) petObjectId = rset.getInt("objId"); DbUtils.close(statement, rset); Player player = owner.getPlayer(); PetInstance pet = player.getPet(); if (pet != null && pet.getObjectId() == petObjectId) pet.unSummon(false); if (player != null && player.isMounted() && player.getMountControlItemObjId() == itemObjId) player.getMount().onControlItemDelete(); // if it's a pet control item, delete the pet statement = con.prepareStatement(DELETE_SQL_QUERY); statement.setInt(1, itemObjId); statement.execute(); } catch (Exception e) { _log.error("CharNameTable.deletePet(ItemInstance, Creature): " + e, e); } finally { DbUtils.closeQuietly(con, statement, rset); } }
private static void LoadFromDB() { Connection con = null; PreparedStatement statement = null; ResultSet rs = null; try { con = DatabaseFactory.getInstance().getConnection(); statement = con.prepareStatement("SELECT * FROM server_variables"); rs = statement.executeQuery(); while (rs.next()) server_vars.set(rs.getString("name"), rs.getString("value")); } catch (Exception e) { _log.error("", e); } finally { DbUtils.closeQuietly(con, statement, rs); } }
private void update0(Castle castle) { Connection con = null; PreparedStatement statement = null; try { con = DatabaseFactory.getInstance().getConnection(); statement = con.prepareStatement(UPDATE_SQL_QUERY); statement.setInt(1, castle.getTaxPercent0()); statement.setLong(2, castle.getTreasury()); statement.setInt(3, castle.getRewardCount()); statement.setInt(4, (int) (castle.getSiegeDate().getTimeInMillis() / 1000L)); statement.setInt(5, (int) (castle.getLastSiegeDate().getTimeInMillis() / 1000L)); statement.setInt(6, (int) (castle.getOwnDate().getTimeInMillis() / 1000L)); statement.setInt(7, castle.getResidenceSide().ordinal()); statement.setInt(8, castle.getId()); statement.execute(); } catch (Exception e) { _log.warn("CastleDAO#update0(Castle): " + e, e); } finally { DbUtils.closeQuietly(con, statement); } }
private static void SaveToDB(String name) { Connection con = null; PreparedStatement statement = null; try { con = DatabaseFactory.getInstance().getConnection(); String value = getVars().getString(name, ""); if (value.isEmpty()) { statement = con.prepareStatement("DELETE FROM server_variables WHERE name = ?"); statement.setString(1, name); statement.execute(); } else { statement = con.prepareStatement("REPLACE INTO server_variables (name, value) VALUES (?,?)"); statement.setString(1, name); statement.setString(2, value); statement.execute(); } } catch (Exception e) { _log.error("", e); } finally { DbUtils.closeQuietly(con, statement); } }
@SuppressWarnings("unchecked") public GameServer() throws Exception { _instance = this; _serverStarted = time(); _listeners = new GameServerListenerList(); new File("./log/").mkdir(); version = new Version(GameServer.class); _log.info("================================================="); _log.info("Project Revision: ........ " + PROJECT_REVISION); _log.info("Build Revision: .......... " + version.getRevisionNumber()); _log.info("Update: .................. " + UPDATE_NAME); _log.info("Build date: .............. " + version.getBuildDate()); _log.info("Compiler version: ........ " + version.getBuildJdk()); _log.info("================================================="); Clients.Load(); // Initialize config Config.load(); // Check binding address checkFreePorts(); // Initialize database Class.forName(Config.DATABASE_DRIVER).newInstance(); DatabaseFactory.getInstance().getConnection().close(); IdFactory _idFactory = IdFactory.getInstance(); if (!_idFactory.isInitialized()) { _log.error("Could not read object IDs from DB. Please Check Your Data."); throw new Exception("Could not initialize the ID factory"); } CacheManager.getInstance(); ThreadPoolManager.getInstance(); LfcDAO.LoadArenas(); LfcStatisticDAO.LoadGlobalStatistics(); LfcStatisticDAO.LoadLocalStatistics(); CustomStatsDAO.LoadCustomValues(); PremiumAccountRatesHolder.loadLists(); BotCheckManager.loadBotQuestions(); FreePremiumAccountsDao.LoadTable(); HidenItemsDAO.LoadAllHiddenItems(); CustomHeroDAO.getInstance(); HWIDBan.getInstance().load(); Scripts.getInstance(); GeoEngine.load(); Strings.reload(); GameTimeController.getInstance(); World.init(); Parsers.parseAll(); ItemsDAO.getInstance(); CrestCache.getInstance(); ImagesCache.getInstance(); CharacterDAO.getInstance(); ClanTable.getInstance(); DailyQuestsManager.EngageSystem(); // FakePlayersTable.getInstance(); SkillTreeTable.getInstance(); SubClassTable.getInstance(); EnchantHPBonusTable.getInstance(); PetSkillsTable.getInstance(); ItemAuctionManager.getInstance(); SpawnManager.getInstance().spawnAll(); FakePlayersSpawnManager.getInstance().spawnAll(); StaticObjectHolder.getInstance().spawnAll(); RaidBossSpawnManager.getInstance(); Scripts.getInstance().init(); ItemHolder.getInstance().initItems(); DimensionalRiftManager.getInstance(); Announcements.getInstance(); LotteryManager.getInstance(); PlayerMessageStack.getInstance(); if (Config.AUTODESTROY_ITEM_AFTER > 0) ItemsAutoDestroy.getInstance(); MonsterRace.getInstance(); if (Config.ENABLE_OLYMPIAD) { Olympiad.load(); Hero.getInstance(); } PetitionManager.getInstance(); CursedWeaponsManager.getInstance(); if (Config.ALLOW_WEDDING) { CoupleManager.getInstance(); } ItemHandler.getInstance(); AdminCommandHandler.getInstance().log(); UserCommandHandler.getInstance().log(); VoicedCommandHandler.getInstance().log(); TaskManager.getInstance(); _log.info("=[Events]========================================="); ResidenceHolder.getInstance().callInit(); EventHolder.getInstance().callInit(); _log.info("=================================================="); BoatHolder.getInstance().spawnAll(); CastleManorManager.getInstance(); Runtime.getRuntime().addShutdownHook(Shutdown.getInstance()); _log.info("IdFactory: Free ObjectID's remaining: " + IdFactory.getInstance().size()); if (Config.ALT_FISH_CHAMPIONSHIP_ENABLED) FishingChampionShipManager.getInstance(); HellboundManager.getInstance(); NaiaTowerManager.getInstance(); NaiaCoreManager.getInstance(); SoDManager.getInstance(); SoIManager.getInstance(); SoHManager.getInstance(); MiniGameScoreManager.getInstance(); CommissionManager.getInstance().init(); WorldStatisticsManager.getInstance(); ArcanManager.getInstance(); ToIManager.getInstance(); ParnassusManager.getInstance(); BaltusManager.getInstance(); Shutdown.getInstance().schedule(Config.RESTART_AT_TIME, Shutdown.RESTART); /* CCP Guard START ccpGuard.Protection.Init(); ** CCP Guard END*/ _log.info("GameServer Started"); _log.info("Maximum Numbers of Connected Players: " + Config.MAXIMUM_ONLINE_USERS); GamePacketHandler gph = new GamePacketHandler(); InetAddress serverAddr = Config.GAMESERVER_HOSTNAME.equalsIgnoreCase("*") ? null : InetAddress.getByName(Config.GAMESERVER_HOSTNAME); _selectorThreads = new ArrayList<SelectorThread<GameClient>>(Config.PORTS_GAME.length); for (int i = 0; i < Config.PORTS_GAME.length; i++) { SelectorThread<GameClient> selectorThread = new SelectorThread<GameClient>(Config.SELECTOR_CONFIG, gph, gph, gph, null); selectorThread.openServerSocket(serverAddr, Config.PORTS_GAME[i]); selectorThread.start(); _selectorThreads.add(i, selectorThread); } AuthServerCommunication.getInstance().start(); if (Config.SERVICES_OFFLINE_TRADE_RESTORE_AFTER_RESTART) ThreadPoolManager.getInstance().schedule(new RestoreOfflineTraders(), 30000L); if (Config.ONLINE_GENERATOR_ENABLED) ThreadPoolManager.getInstance() .scheduleAtFixedRate( new OnlineTxtGenerator(), 5000L, Config.ONLINE_GENERATOR_DELAY * 60 * 1000L); getListeners().onStart(); if (Config.IS_TELNET_ENABLED) statusServer = new TelnetServer(); else _log.info("Telnet server is currently disabled."); _log.info("================================================="); String memUsage = new StringBuilder().append(StatsUtils.getMemUsage()).toString(); for (String line : memUsage.split("\n")) _log.info(line); _log.info("================================================="); }