Move MapleWorldMapChecker to main module
This commit is contained in:
@@ -1,56 +1,31 @@
|
|||||||
/*
|
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
|
import tools.Pair;
|
||||||
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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package mapleworldmapchecker;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author RonanLana
|
* @author RonanLana
|
||||||
|
* <p>
|
||||||
This application parses the Map.wz file inputted and reports areas (mapids) that are supposed to be referenced
|
* This application parses the Map.wz file inputted and reports areas (mapids) that are supposed to be referenced
|
||||||
throughout the map tree (area map -> continent map -> world map) but are currently missing.
|
* throughout the map tree (area map -> continent map -> world map) but are currently missing.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public class MapleWorldmapChecker {
|
public class WorldmapChecker {
|
||||||
|
private static final File OUTPUT_FILE = ToolConstants.getOutputFile("worldmap_report.txt");
|
||||||
|
private static final int INITIAL_STRING_LENGTH = 50;
|
||||||
|
private static final Map<String, Set<Integer>> worldMapids = new HashMap<>();
|
||||||
|
private static final Map<String, String> parentWorldmaps = new HashMap<>();
|
||||||
|
private static final Set<String> rootWorldmaps = new HashSet<>();
|
||||||
|
|
||||||
static String newFile = "lib/Report.txt";
|
private static PrintWriter printWriter = null;
|
||||||
static PrintWriter printWriter = null;
|
private static BufferedReader bufferedReader = null;
|
||||||
static InputStreamReader fileReader = null;
|
private static Set<Integer> currentWorldMapids;
|
||||||
static BufferedReader bufferedReader = null;
|
private static String currentParent;
|
||||||
|
private static byte status = 0;
|
||||||
static String worldmapPath = "../../wz/Map.wz/WorldMap";
|
private static boolean isInfo;
|
||||||
static int initialStringLength = 50;
|
|
||||||
|
|
||||||
static Map<String, Set<Integer>> worldMapids = new HashMap<>();
|
|
||||||
static Map<String, String> parentWorldmaps = new HashMap<>();
|
|
||||||
static Set<String> rootWorldmaps = new HashSet<>();
|
|
||||||
//static String rootWorldmap = "";
|
|
||||||
|
|
||||||
static Set<Integer> currentWorldMapids;
|
|
||||||
static String currentParent;
|
|
||||||
|
|
||||||
static byte status = 0;
|
|
||||||
static boolean isInfo;
|
|
||||||
|
|
||||||
private static String getName(String token) {
|
private static String getName(String token) {
|
||||||
int i, j;
|
int i, j;
|
||||||
@@ -61,11 +36,11 @@ public class MapleWorldmapChecker {
|
|||||||
i = token.indexOf("\"", i) + 1; //lower bound of the string
|
i = token.indexOf("\"", i) + 1; //lower bound of the string
|
||||||
j = token.indexOf("\"", i); //upper bound
|
j = token.indexOf("\"", i); //upper bound
|
||||||
|
|
||||||
dest = new char[initialStringLength];
|
dest = new char[INITIAL_STRING_LENGTH];
|
||||||
token.getChars(i, j, dest, 0);
|
token.getChars(i, j, dest, 0);
|
||||||
|
|
||||||
d = new String(dest);
|
d = new String(dest);
|
||||||
return(d.trim());
|
return (d.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getValue(String token) {
|
private static String getValue(String token) {
|
||||||
@@ -77,31 +52,29 @@ public class MapleWorldmapChecker {
|
|||||||
i = token.indexOf("\"", i) + 1; //lower bound of the string
|
i = token.indexOf("\"", i) + 1; //lower bound of the string
|
||||||
j = token.indexOf("\"", i); //upper bound
|
j = token.indexOf("\"", i); //upper bound
|
||||||
|
|
||||||
dest = new char[initialStringLength];
|
dest = new char[INITIAL_STRING_LENGTH];
|
||||||
token.getChars(i, j, dest, 0);
|
token.getChars(i, j, dest, 0);
|
||||||
|
|
||||||
d = new String(dest);
|
d = new String(dest);
|
||||||
return(d.trim());
|
return (d.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -109,26 +82,18 @@ public class MapleWorldmapChecker {
|
|||||||
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")) {
|
|
||||||
status += 1;
|
status += 1;
|
||||||
|
|
||||||
if (status == 2) {
|
if (status == 2) {
|
||||||
d = getName(token);
|
d = getName(token);
|
||||||
|
|
||||||
switch (d) {
|
switch (d) {
|
||||||
case "MapList":
|
case "MapList" -> isInfo = false;
|
||||||
isInfo = false;
|
case "info" -> isInfo = true;
|
||||||
break;
|
default -> forwardCursor(status);
|
||||||
|
|
||||||
case "info":
|
|
||||||
isInfo = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
forwardCursor(status);
|
|
||||||
}
|
}
|
||||||
} else if (status == 4) {
|
} else if (status == 4) {
|
||||||
d = getName(token);
|
d = getName(token);
|
||||||
@@ -137,8 +102,7 @@ public class MapleWorldmapChecker {
|
|||||||
forwardCursor(status);
|
forwardCursor(status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (status == 4) {
|
if (status == 4) {
|
||||||
currentWorldMapids.add(Integer.valueOf(getValue(token)));
|
currentWorldMapids.add(Integer.valueOf(getValue(token)));
|
||||||
} else if (status == 2 && isInfo) {
|
} else if (status == 2 && isInfo) {
|
||||||
@@ -160,43 +124,42 @@ public class MapleWorldmapChecker {
|
|||||||
private static void parseWorldmapFile(File worldmapFile) throws IOException {
|
private static void parseWorldmapFile(File worldmapFile) throws IOException {
|
||||||
String line;
|
String line;
|
||||||
|
|
||||||
fileReader = new InputStreamReader(new FileInputStream(worldmapFile), "UTF-8");
|
InputStreamReader fileReader = new InputStreamReader(new FileInputStream(worldmapFile), StandardCharsets.UTF_8);
|
||||||
bufferedReader = new BufferedReader(fileReader);
|
bufferedReader = new BufferedReader(fileReader);
|
||||||
|
|
||||||
currentParent = "";
|
currentParent = "";
|
||||||
status = 0;
|
status = 0;
|
||||||
|
|
||||||
currentWorldMapids = new HashSet<>();
|
currentWorldMapids = new HashSet<>();
|
||||||
while((line = bufferedReader.readLine()) != null) {
|
while ((line = bufferedReader.readLine()) != null) {
|
||||||
translateToken(line);
|
translateToken(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
String worldmapName = worldmapFile.getName();
|
String worldmapName = worldmapFile.getName();
|
||||||
worldMapids.put(worldmapName, currentWorldMapids);
|
worldMapids.put(worldmapName, currentWorldMapids);
|
||||||
|
|
||||||
if (!currentParent.isEmpty()) parentWorldmaps.put(worldmapName, currentParent);
|
if (!currentParent.isEmpty()) {
|
||||||
else rootWorldmaps.add(worldmapName);
|
parentWorldmaps.put(worldmapName, currentParent);
|
||||||
|
} else {
|
||||||
|
rootWorldmaps.add(worldmapName);
|
||||||
|
}
|
||||||
|
|
||||||
bufferedReader.close();
|
bufferedReader.close();
|
||||||
fileReader.close();
|
fileReader.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void parseWorldmapDirectory() {
|
private static void parseWorldmapDirectory() {
|
||||||
System.out.println("Parsing directory '" + worldmapPath + "'");
|
File folder = new File(WZFiles.MAP.getFilePath(), "WorldMap");
|
||||||
File folder = new File(worldmapPath);
|
System.out.println("Parsing directory '" + folder.getPath() + "'");
|
||||||
for (File file : folder.listFiles()) {
|
for (File file : folder.listFiles()) {
|
||||||
if (file.isFile()) {
|
if (file.isFile()) {
|
||||||
try {
|
try {
|
||||||
parseWorldmapFile(file);
|
parseWorldmapFile(file);
|
||||||
}
|
} catch (FileNotFoundException ex) {
|
||||||
catch(FileNotFoundException ex) {
|
|
||||||
System.out.println("Unable to open worldmap file " + file.getAbsolutePath() + ".");
|
System.out.println("Unable to open worldmap file " + file.getAbsolutePath() + ".");
|
||||||
}
|
} catch (IOException ex) {
|
||||||
catch(IOException ex) {
|
|
||||||
System.out.println("Error reading worldmap file " + file.getAbsolutePath() + ".");
|
System.out.println("Error reading worldmap file " + file.getAbsolutePath() + ".");
|
||||||
}
|
} catch (Exception e) {
|
||||||
|
|
||||||
catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -224,7 +187,7 @@ public class MapleWorldmapChecker {
|
|||||||
|
|
||||||
private static void verifyWorldmapTreeMapids() {
|
private static void verifyWorldmapTreeMapids() {
|
||||||
try {
|
try {
|
||||||
printWriter = new PrintWriter(newFile, "UTF-8");
|
printWriter = new PrintWriter(OUTPUT_FILE, StandardCharsets.UTF_8);
|
||||||
printReportFileHeader();
|
printReportFileHeader();
|
||||||
|
|
||||||
if (rootWorldmaps.size() > 1) {
|
if (rootWorldmaps.size() > 1) {
|
||||||
@@ -235,7 +198,7 @@ public class MapleWorldmapChecker {
|
|||||||
worldmaps.addAll(rootWorldmaps);
|
worldmaps.addAll(rootWorldmaps);
|
||||||
|
|
||||||
Map<String, Set<Integer>> tempMapids = new HashMap<>(worldMapids.size());
|
Map<String, Set<Integer>> tempMapids = new HashMap<>(worldMapids.size());
|
||||||
for (Entry<String, Set<Integer>> e : worldMapids.entrySet()) {
|
for (Map.Entry<String, Set<Integer>> e : worldMapids.entrySet()) {
|
||||||
tempMapids.put(e.getKey(), new HashSet<>(e.getValue()));
|
tempMapids.put(e.getKey(), new HashSet<>(e.getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,14 +230,14 @@ public class MapleWorldmapChecker {
|
|||||||
|
|
||||||
if (!unreferencedMapids.isEmpty()) {
|
if (!unreferencedMapids.isEmpty()) {
|
||||||
List<Pair<String, List<Pair<Integer, String>>>> unreferencedEntries = new ArrayList<>(20);
|
List<Pair<String, List<Pair<Integer, String>>>> unreferencedEntries = new ArrayList<>(20);
|
||||||
for (Entry<String, List<Pair<Integer, String>>> e : unreferencedMapids.entrySet()) {
|
for (Map.Entry<String, List<Pair<Integer, String>>> e : unreferencedMapids.entrySet()) {
|
||||||
List<Pair<Integer, String>> list = new ArrayList<>(e.getValue());
|
List<Pair<Integer, String>> list = new ArrayList<>(e.getValue());
|
||||||
Collections.sort(list, (o1, o2) -> o1.getLeft().compareTo(o2.getLeft()));
|
list.sort((o1, o2) -> o1.getLeft().compareTo(o2.getLeft()));
|
||||||
|
|
||||||
unreferencedEntries.add(new Pair<>(e.getKey(), list));
|
unreferencedEntries.add(new Pair<>(e.getKey(), list));
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(unreferencedEntries, (o1, o2) -> o1.getLeft().compareTo(o2.getLeft()));
|
unreferencedEntries.sort((o1, o2) -> o1.getLeft().compareTo(o2.getLeft()));
|
||||||
|
|
||||||
printReportFileResults(unreferencedEntries);
|
printReportFileResults(unreferencedEntries);
|
||||||
}
|
}
|
||||||
@@ -289,5 +252,5 @@ public class MapleWorldmapChecker {
|
|||||||
parseWorldmapDirectory();
|
parseWorldmapDirectory();
|
||||||
verifyWorldmapTreeMapids();
|
verifyWorldmapTreeMapids();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
# Report File autogenerated from the MapleWorldmapChecker feature by Ronan Lana.
|
|
||||||
# Generated data takes into account several data info from the server-side WZ.xmls.
|
|
||||||
|
|
||||||
Missing mapid references in top hierarchy:
|
|
||||||
|
|
||||||
'WorldMap000.img.xml':
|
|
||||||
1020000:WorldMap.img.xml
|
|
||||||
|
|
||||||
|
|
||||||
'WorldMap010.img.xml':
|
|
||||||
101000400:WorldMap.img.xml
|
|
||||||
105040306:WorldMap.img.xml
|
|
||||||
105050500:WorldMap.img.xml
|
|
||||||
193000000:WorldMap.img.xml
|
|
||||||
680000100:WorldMap.img.xml
|
|
||||||
680000110:WorldMap.img.xml
|
|
||||||
680000200:WorldMap.img.xml
|
|
||||||
680000210:WorldMap.img.xml
|
|
||||||
680000300:WorldMap.img.xml
|
|
||||||
680000400:WorldMap.img.xml
|
|
||||||
680000401:WorldMap.img.xml
|
|
||||||
680010000:WorldMap.img.xml
|
|
||||||
680010100:WorldMap.img.xml
|
|
||||||
|
|
||||||
|
|
||||||
'WorldMap012.img.xml':
|
|
||||||
107000500:WorldMap010.img.xml
|
|
||||||
|
|
||||||
|
|
||||||
'WorldMap014.img.xml':
|
|
||||||
106021401:WorldMap010.img.xml
|
|
||||||
106021402:WorldMap010.img.xml
|
|
||||||
106021800:WorldMap010.img.xml
|
|
||||||
|
|
||||||
|
|
||||||
'WorldMap020.img.xml':
|
|
||||||
200080101:WorldMap.img.xml
|
|
||||||
200082301:WorldMap.img.xml
|
|
||||||
211040401:WorldMap.img.xml
|
|
||||||
|
|
||||||
|
|
||||||
'WorldMap021.img.xml':
|
|
||||||
280030000:WorldMap020.img.xml
|
|
||||||
|
|
||||||
|
|
||||||
'WorldMap030.img.xml':
|
|
||||||
220010001:WorldMap.img.xml
|
|
||||||
220011001:WorldMap.img.xml
|
|
||||||
221022100:WorldMap.img.xml
|
|
||||||
221022200:WorldMap.img.xml
|
|
||||||
222010310:WorldMap.img.xml
|
|
||||||
|
|
||||||
|
|
||||||
'WorldMap050.img.xml':
|
|
||||||
240040201:WorldMap.img.xml
|
|
||||||
240040301:WorldMap.img.xml
|
|
||||||
|
|
||||||
|
|
||||||
'WorldMap060.img.xml':
|
|
||||||
251000100:WorldMap.img.xml
|
|
||||||
251010404:WorldMap.img.xml
|
|
||||||
|
|
||||||
|
|
||||||
'WorldMap100.img.xml':
|
|
||||||
140020110:WorldMap.img.xml
|
|
||||||
|
|
||||||
|
|
||||||
'WorldMap142.img.xml':
|
|
||||||
600010002:WorldMap.img.xml
|
|
||||||
|
|
||||||
|
|
||||||
'WorldMap211.img.xml':
|
|
||||||
801040100:WorldMap210.img.xml
|
|
||||||
801040101:WorldMap210.img.xml
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is part of the OdinMS Maple Story Server
|
|
||||||
Copyright (C) 2008 ~ 2010 Patrick Huy <patrick.huy@frz.cc>
|
|
||||||
Matthias Butz <matze@odinms.de>
|
|
||||||
Jan Christian Meyer <vimes@odinms.de>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Affero General Public License 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package mapleworldmapchecker;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a pair of values.
|
|
||||||
*
|
|
||||||
* @author Frz
|
|
||||||
* @since Revision 333
|
|
||||||
* @version 1.0
|
|
||||||
*
|
|
||||||
* @param <E> The type of the left value.
|
|
||||||
* @param <F> The type of the right value.
|
|
||||||
*/
|
|
||||||
public class Pair<E, F> {
|
|
||||||
|
|
||||||
public E left;
|
|
||||||
public F right;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class constructor - pairs two objects together.
|
|
||||||
*
|
|
||||||
* @param left The left object.
|
|
||||||
* @param right The right object.
|
|
||||||
*/
|
|
||||||
public Pair(E left, F right) {
|
|
||||||
this.left = left;
|
|
||||||
this.right = right;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the left value.
|
|
||||||
*
|
|
||||||
* @return The left value.
|
|
||||||
*/
|
|
||||||
public E getLeft() {
|
|
||||||
return left;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the right value.
|
|
||||||
*
|
|
||||||
* @return The right value.
|
|
||||||
*/
|
|
||||||
public F getRight() {
|
|
||||||
return right;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Turns the pair into a string.
|
|
||||||
*
|
|
||||||
* @return Each value of the pair as a string joined with a colon.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return left.toString() + ":" + right.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the hash code of this pair.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
final int prime = 31;
|
|
||||||
int result = 1;
|
|
||||||
result = prime * result + ((left == null) ? 0 : left.hashCode());
|
|
||||||
result = prime * result + ((right == null) ? 0 : right.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks to see if two pairs are equal.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (obj == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (getClass() != obj.getClass()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final Pair other = (Pair) obj;
|
|
||||||
if (left == null) {
|
|
||||||
if (other.left != null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else if (!left.equals(other.left)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (right == null) {
|
|
||||||
if (other.right != null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else if (!right.equals(other.right)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user