From 7af3d6924e2fc824d3c3a62cfeb7ff7dc07aee15 Mon Sep 17 00:00:00 2001 From: P0nk Date: Sat, 10 Jul 2021 22:43:05 +0200 Subject: [PATCH] Move MapleReactorDropFetcher to main module --- .../tools/mapletools/ReactorDropFetcher.java | 112 ++++++++++++ .../lib/ReactorDropReport.txt | 20 --- .../MapleReactorDropFetcher.java | 170 ------------------ 3 files changed, 112 insertions(+), 190 deletions(-) create mode 100644 src/main/java/tools/mapletools/ReactorDropFetcher.java delete mode 100644 tools/MapleReactorDropFetcher/lib/ReactorDropReport.txt delete mode 100644 tools/MapleReactorDropFetcher/src/maplereactordropfetcher/MapleReactorDropFetcher.java diff --git a/src/main/java/tools/mapletools/ReactorDropFetcher.java b/src/main/java/tools/mapletools/ReactorDropFetcher.java new file mode 100644 index 0000000000..c8c5497c5f --- /dev/null +++ b/src/main/java/tools/mapletools/ReactorDropFetcher.java @@ -0,0 +1,112 @@ +package tools.mapletools; + +import java.io.File; +import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.*; + +/** + * @author RonanLana + *

+ * This application reports in reactor ids that have drops on the SQL table but are + * not yet coded. + */ +public class ReactorDropFetcher { + private static final File OUTPUT_FILE = ToolConstants.getOutputFile("reactor_drop_report.txt"); + private static final String REACTOR_SCRIPT_PATH = ToolConstants.SCRIPTS_PATH + "/reactor"; + private static final Connection con = SimpleDatabaseConnection.getConnection(); + + private static PrintWriter printWriter = null; + private static final Set reactors = new HashSet<>(); + + private static void printReportFileHeader() { + printWriter.println(" # Report File autogenerated from the MapleReactorDropFetcher feature by Ronan Lana."); + printWriter.println(" # Generated data takes into account several data info from the underlying DB and the server-side files."); + printWriter.println(); + } + + private static int getReactorIdFromFilename(String name) { + try { + return Integer.parseInt(name.substring(0, name.indexOf('.'))); + } catch (Exception e) { + return -1; + } + } + + private static void removeScriptedReactorids(String directoryName) { + File directory = new File(directoryName); + + // get all the files from a directory + File[] fList = directory.listFiles(); + for (File file : fList) { + if (file.isFile()) { + reactors.remove(getReactorIdFromFilename(file.getName())); + } + } + } + + private static void loadReactoridsOnDB() throws SQLException { + PreparedStatement ps = con.prepareStatement("SELECT DISTINCT reactorid FROM reactordrops;"); + ResultSet rs = ps.executeQuery(); + + while (rs.next()) { + reactors.add(rs.getInt("reactorid")); + } + + rs.close(); + ps.close(); + } + + private static List getSortedReactorids() { + List sortedReactors = new ArrayList<>(reactors); + Collections.sort(sortedReactors); + + return sortedReactors; + } + + private static void fetchMissingReactorDrops() throws SQLException { + loadReactoridsOnDB(); + removeScriptedReactorids(REACTOR_SCRIPT_PATH); + } + + private static void reportMissingReactorDrops() throws SQLException { + if (!reactors.isEmpty()) { + printWriter.println("MISSING REACTOR DROP SCRIPTS"); + for (Integer reactorid : getSortedReactorids()) { + printWriter.println(" " + reactorid); + } + printWriter.println("\n"); + } + } + + private static void reportMissingReactors() { + try { + System.out.println("Fetching reactors from DB..."); + fetchMissingReactorDrops(); + + con.close(); + printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8); + + // report suspects of missing quest drop data, as well as those drop data that may have incorrect questids. + System.out.println("Reporting results..."); + printReportFileHeader(); + reportMissingReactorDrops(); + + printWriter.close(); + System.out.println("Done!"); + } catch (SQLException e) { + System.out.println("Warning: Could not establish connection to database to report quest data."); + System.out.println(e.getMessage()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void main(String[] args) { + reportMissingReactors(); + } +} \ No newline at end of file diff --git a/tools/MapleReactorDropFetcher/lib/ReactorDropReport.txt b/tools/MapleReactorDropFetcher/lib/ReactorDropReport.txt deleted file mode 100644 index b011a3466e..0000000000 --- a/tools/MapleReactorDropFetcher/lib/ReactorDropReport.txt +++ /dev/null @@ -1,20 +0,0 @@ - # Report File autogenerated from the MapleReactorDropFetcher feature by Ronan Lana. - # Generated data takes into account several data info from the underlying DB and the server-side files. - -MISSING REACTOR DROP SCRIPTS - 200000 - 200001 - 200002 - 200003 - 200004 - 200005 - 200006 - 200007 - 200008 - 200009 - 1022001 - 1032000 - 2052001 - 2112015 - - diff --git a/tools/MapleReactorDropFetcher/src/maplereactordropfetcher/MapleReactorDropFetcher.java b/tools/MapleReactorDropFetcher/src/maplereactordropfetcher/MapleReactorDropFetcher.java deleted file mode 100644 index c0ab9703f4..0000000000 --- a/tools/MapleReactorDropFetcher/src/maplereactordropfetcher/MapleReactorDropFetcher.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - This file is part of the HeavenMS MapleStory Server - Copyleft (L) 2016 - 2019 RonanLana - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation version 3 as published by - the Free Software Foundation. You may not use, modify or distribute - this program under any other version of the GNU Affero General Public - License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ -package maplereactordropfetcher; - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.io.PrintWriter; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.HashSet; -import java.util.Set; - -import java.io.File; - -/** - * - * @author RonanLana - - This application reports in reactor ids that have drops on the SQL table but are - not yet coded. - - */ -public class MapleReactorDropFetcher { - static String host = "jdbc:mysql://localhost:3306/cosmic"; - static String driver = "com.mysql.jdbc.Driver"; - static String username = "cosmic_server"; - static String password = "snailshell"; - - static String reactorScriptPath = "../../scripts/reactor"; - - static String directoryName = "../.."; - static String newFile = "lib/ReactorDropReport.txt"; - - static Connection con = null; - static PrintWriter printWriter = null; - static InputStreamReader fileReader = null; - static BufferedReader bufferedReader = null; - - static Set reactors = new HashSet<>(); - - private static void printReportFileHeader() { - printWriter.println(" # Report File autogenerated from the MapleReactorDropFetcher feature by Ronan Lana."); - printWriter.println(" # Generated data takes into account several data info from the underlying DB and the server-side files."); - printWriter.println(); - } - - private static int getReactorIdFromFilename(String name) { - try { - return Integer.valueOf(name.substring(0, name.indexOf('.'))); - } catch(Exception e) { - return -1; - } - } - - private static void removeScriptedReactorids(String directoryName) { - File directory = new File(directoryName); - - // get all the files from a directory - File[] fList = directory.listFiles(); - for (File file : fList) { - if (file.isFile()) { - reactors.remove(getReactorIdFromFilename(file.getName())); - } - } - } - - private static void loadReactoridsOnDB() throws SQLException { - PreparedStatement ps = con.prepareStatement("SELECT DISTINCT reactorid FROM reactordrops;"); - ResultSet rs = ps.executeQuery(); - - while(rs.next()) { - reactors.add(rs.getInt("reactorid")); - } - - rs.close(); - ps.close(); - } - - private static List getSortedReactorids() { - List sortedReactors = new ArrayList<>(reactors); - Collections.sort(sortedReactors); - - return sortedReactors; - } - - private static void fetchMissingReactorDrops() throws SQLException { - loadReactoridsOnDB(); - removeScriptedReactorids(reactorScriptPath); - } - - private static void reportMissingReactorDrops() throws SQLException { - if(!reactors.isEmpty()) { - printWriter.println("MISSING REACTOR DROP SCRIPTS"); - for(Integer reactorid : getSortedReactorids()) { - printWriter.println(" " + reactorid); - } - printWriter.println("\n"); - } - } - - private static void ReportMissingReactors() { - try { - Class.forName(driver).newInstance(); - - // filter reactorids on DB - con = DriverManager.getConnection(host, username, password); - - System.out.println("Fetching reactors from DB..."); - fetchMissingReactorDrops(); - - con.close(); - printWriter = new PrintWriter(newFile, "UTF-8"); - - // report suspects of missing quest drop data, as well as those drop data that may have incorrect questids. - System.out.println("Reporting results..."); - printReportFileHeader(); - reportMissingReactorDrops(); - - printWriter.close(); - System.out.println("Done!"); - } - - catch(SQLException e) { - System.out.println("Warning: Could not establish connection to database to report quest data."); - System.out.println(e.getMessage()); - } - - catch(ClassNotFoundException e) { - System.out.println("Error: could not find class"); - System.out.println(e.getMessage()); - } - - catch(InstantiationException e) { - System.out.println("Error: instantiation failure"); - System.out.println(e.getMessage()); - } - - catch(Exception e) { - e.printStackTrace(); - } - } - - public static void main(String[] args) { - ReportMissingReactors(); - } - -}