Move MapleNoItemIdFetcher to main module
This commit is contained in:
@@ -1,70 +1,35 @@
|
|||||||
/*
|
package tools.mapletools;
|
||||||
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
|
import provider.wz.WZFiles;
|
||||||
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,
|
import java.io.*;
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
import java.nio.charset.StandardCharsets;
|
||||||
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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package maplenoitemidfetcher;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author RonanLana
|
* @author RonanLana
|
||||||
*
|
* <p>
|
||||||
* This application finds inexistent itemids within the drop data from
|
* This application finds inexistent itemids within the drop data from
|
||||||
* the Maplestory database specified in the URL below. This program
|
* the Maplestory database specified in the URL below. This program
|
||||||
* assumes all itemids uses 7 digits.
|
* assumes all itemids uses 7 digits.
|
||||||
*
|
* <p>
|
||||||
* A file is generated listing all the inexistent ids.
|
* A file is generated listing all the inexistent ids.
|
||||||
*/
|
*/
|
||||||
public class MapleNoItemIdFetcher {
|
public class NoItemIdFetcher {
|
||||||
static String host = "jdbc:mysql://localhost:3306/cosmic";
|
private static final File OUTPUT_FILE = ToolConstants.getOutputFile("no_item_id_report.txt");
|
||||||
static String driver = "com.mysql.jdbc.Driver";
|
private static final Connection con = SimpleDatabaseConnection.getConnection();
|
||||||
static String username = "cosmic_server";
|
|
||||||
static String password = "snailshell";
|
|
||||||
|
|
||||||
static String wzPath = "../../wz";
|
private static final Set<Integer> existingIds = new HashSet<>();
|
||||||
static String newFile = "lib/result.txt";
|
private static final Set<Integer> nonExistingIds = new HashSet<>();
|
||||||
|
|
||||||
static Connection con = null;
|
private static PrintWriter printWriter = null;
|
||||||
static PrintWriter printWriter = null;
|
private static BufferedReader bufferedReader = null;
|
||||||
static InputStreamReader fileReader = null;
|
private static byte status = 0;
|
||||||
static BufferedReader bufferedReader = null;
|
private static int itemId = -1;
|
||||||
static byte status = 0;
|
|
||||||
static int itemId = -1;
|
|
||||||
|
|
||||||
static Set<Integer> existingIds = new HashSet<>();
|
|
||||||
static Set<Integer> nonExistingIds = new HashSet<>();
|
|
||||||
|
|
||||||
private static String getName(String token) {
|
private static String getName(String token) {
|
||||||
int i, j;
|
int i, j;
|
||||||
@@ -79,27 +44,25 @@ public class MapleNoItemIdFetcher {
|
|||||||
token.getChars(i, j, dest, 0);
|
token.getChars(i, j, dest, 0);
|
||||||
|
|
||||||
d = new String(dest);
|
d = new String(dest);
|
||||||
return(d);
|
return (d);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void forwardCursor(int st) {
|
private static void forwardCursor(int st) {
|
||||||
String line = null;
|
String line = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while(status >= st && (line = bufferedReader.readLine()) != null) {
|
while (status >= st && (line = bufferedReader.readLine()) != null) {
|
||||||
simpleToken(line);
|
simpleToken(line);
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void simpleToken(String token) {
|
private static void simpleToken(String token) {
|
||||||
if(token.contains("/imgdir")) {
|
if (token.contains("/imgdir")) {
|
||||||
status -= 1;
|
status -= 1;
|
||||||
}
|
} else if (token.contains("imgdir")) {
|
||||||
else if(token.contains("imgdir")) {
|
|
||||||
status += 1;
|
status += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,11 +70,10 @@ public class MapleNoItemIdFetcher {
|
|||||||
private static void translateToken(String token) {
|
private static void translateToken(String token) {
|
||||||
String d;
|
String d;
|
||||||
|
|
||||||
if(token.contains("/imgdir")) {
|
if (token.contains("/imgdir")) {
|
||||||
status -= 1;
|
status -= 1;
|
||||||
}
|
} else if (token.contains("imgdir")) {
|
||||||
else if(token.contains("imgdir")) {
|
if (status == 1) { //getting ItemId
|
||||||
if(status == 1) { //getting ItemId
|
|
||||||
d = getName(token);
|
d = getName(token);
|
||||||
itemId = Integer.parseInt(d.substring(1, 8));
|
itemId = Integer.parseInt(d.substring(1, 8));
|
||||||
|
|
||||||
@@ -128,31 +90,29 @@ public class MapleNoItemIdFetcher {
|
|||||||
String line = null;
|
String line = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fileReader = new InputStreamReader(new FileInputStream(file), "UTF-8");
|
InputStreamReader fileReader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
|
||||||
bufferedReader = new BufferedReader(fileReader);
|
bufferedReader = new BufferedReader(fileReader);
|
||||||
|
|
||||||
status = 0;
|
status = 0;
|
||||||
try {
|
try {
|
||||||
while((line = bufferedReader.readLine()) != null) {
|
while ((line = bufferedReader.readLine()) != null) {
|
||||||
translateToken(line);
|
translateToken(line);
|
||||||
}
|
}
|
||||||
} catch(NumberFormatException npe) {
|
} catch (NumberFormatException npe) {
|
||||||
// second criteria, itemid is on the name of the file
|
// second criteria, itemid is on the name of the file
|
||||||
|
|
||||||
try {
|
try {
|
||||||
itemId = Integer.parseInt(file.getName().substring(0, 7));
|
itemId = Integer.parseInt(file.getName().substring(0, 7));
|
||||||
existingIds.add(itemId);
|
existingIds.add(itemId);
|
||||||
} catch(NumberFormatException npe2) {}
|
} catch (NumberFormatException npe2) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bufferedReader.close();
|
bufferedReader.close();
|
||||||
fileReader.close();
|
fileReader.close();
|
||||||
}
|
} catch (FileNotFoundException ex) {
|
||||||
|
|
||||||
catch(FileNotFoundException ex) {
|
|
||||||
System.out.println("Unable to open file '" + file.getName() + "'");
|
System.out.println("Unable to open file '" + file.getName() + "'");
|
||||||
}
|
} catch (IOException ex) {
|
||||||
catch(IOException ex) {
|
|
||||||
System.out.println("Error reading file '" + file.getName() + "'");
|
System.out.println("Error reading file '" + file.getName() + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,7 +134,8 @@ public class MapleNoItemIdFetcher {
|
|||||||
existingIds.add(itemId);
|
existingIds.add(itemId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException nfe) {}
|
} catch (NumberFormatException nfe) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -202,8 +163,8 @@ public class MapleNoItemIdFetcher {
|
|||||||
PreparedStatement ps = con.prepareStatement("SELECT DISTINCT itemid FROM " + table + ";");
|
PreparedStatement ps = con.prepareStatement("SELECT DISTINCT itemid FROM " + table + ";");
|
||||||
ResultSet rs = ps.executeQuery();
|
ResultSet rs = ps.executeQuery();
|
||||||
|
|
||||||
while(rs.next()) {
|
while (rs.next()) {
|
||||||
if(!existingIds.contains(rs.getInt(1))) {
|
if (!existingIds.contains(rs.getInt(1))) {
|
||||||
nonExistingIds.add(rs.getInt(1));
|
nonExistingIds.add(rs.getInt(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,17 +177,14 @@ public class MapleNoItemIdFetcher {
|
|||||||
try {
|
try {
|
||||||
System.out.println("Evaluating item data on DB...");
|
System.out.println("Evaluating item data on DB...");
|
||||||
|
|
||||||
Class.forName(driver).newInstance();
|
|
||||||
con = DriverManager.getConnection(host, username, password);
|
|
||||||
|
|
||||||
evaluateDropsFromTable("drop_data");
|
evaluateDropsFromTable("drop_data");
|
||||||
evaluateDropsFromTable("reactordrops");
|
evaluateDropsFromTable("reactordrops");
|
||||||
|
|
||||||
if(!nonExistingIds.isEmpty()) {
|
if (!nonExistingIds.isEmpty()) {
|
||||||
List<Integer> list = new ArrayList<>(nonExistingIds);
|
List<Integer> list = new ArrayList<>(nonExistingIds);
|
||||||
Collections.sort(list);
|
Collections.sort(list);
|
||||||
|
|
||||||
for(Integer i : list) {
|
for (Integer i : list) {
|
||||||
printWriter.println(i);
|
printWriter.println(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -235,39 +193,23 @@ public class MapleNoItemIdFetcher {
|
|||||||
System.out.println("Total itemid count: " + existingIds.size());
|
System.out.println("Total itemid count: " + existingIds.size());
|
||||||
|
|
||||||
con.close();
|
con.close();
|
||||||
}
|
} catch (Exception e) {
|
||||||
|
|
||||||
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(SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
printWriter = new PrintWriter(newFile, "UTF-8");
|
printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8);
|
||||||
|
|
||||||
existingIds.add(0); // meso itemid
|
existingIds.add(0); // meso itemid
|
||||||
readEquipDataDirectory(wzPath + "/Character.wz");
|
readEquipDataDirectory(WZFiles.CHARACTER.getFilePath());
|
||||||
readItemDataDirectory(wzPath + "/Item.wz");
|
readItemDataDirectory(WZFiles.ITEM.getFilePath());
|
||||||
|
|
||||||
evaluateDropsFromDb();
|
evaluateDropsFromDb();
|
||||||
|
|
||||||
printWriter.close();
|
printWriter.close();
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user