Reformat and clean up "tools" package

This commit is contained in:
P0nk
2021-09-09 23:28:07 +02:00
parent e8ef3a492c
commit 7be1d119de
19 changed files with 793 additions and 800 deletions

View File

@@ -21,12 +21,7 @@
*/ */
package tools; package tools;
import java.util.AbstractMap; import java.util.*;
import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class ArrayMap<K, V> extends AbstractMap<K, V> { public class ArrayMap<K, V> extends AbstractMap<K, V> {
@@ -77,8 +72,9 @@ public class ArrayMap<K, V> extends AbstractMap<K, V> {
return key + "=" + value; return key + "=" + value;
} }
} }
private Set<? extends java.util.Map.Entry<K, V>> entries = null; private Set<? extends java.util.Map.Entry<K, V>> entries = null;
private ArrayList<Entry<K, V>> list; private final ArrayList<Entry<K, V>> list;
public ArrayMap() { public ArrayMap() {
list = new ArrayList<>(); list = new ArrayList<>();
@@ -94,7 +90,7 @@ public class ArrayMap<K, V> extends AbstractMap<K, V> {
} }
@Override @Override
@SuppressWarnings ("unchecked") @SuppressWarnings("unchecked")
public Set<java.util.Map.Entry<K, V>> entrySet() { public Set<java.util.Map.Entry<K, V>> entrySet() {
if (entries == null) { if (entries == null) {
entries = new AbstractSet<Entry<K, V>>() { entries = new AbstractSet<Entry<K, V>>() {

View File

@@ -13,7 +13,7 @@
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package tools; package tools;
import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.Arrays; import java.util.Arrays;
@@ -376,8 +376,8 @@ public class BCrypt {
* *
* @param d the byte array to encode * @param d the byte array to encode
* @param len the number of bytes to encode * @param len the number of bytes to encode
* @throws IllegalArgumentException if the length is invalid
* @return base64-encoded string * @return base64-encoded string
* @exception IllegalArgumentException if the length is invalid
*/ */
private static String encode_base64(byte[] d, int len) private static String encode_base64(byte[] d, int len)
throws IllegalArgumentException { throws IllegalArgumentException {
@@ -416,6 +416,7 @@ public class BCrypt {
/** /**
* Look up the 3 bits base64-encoded with the specified character, * Look up the 3 bits base64-encoded with the specified character,
* range-checking againt conversion table * range-checking againt conversion table
*
* @param x the base64-encoded value * @param x the base64-encoded value
* @return the decoded value of x * @return the decoded value of x
*/ */
@@ -430,10 +431,11 @@ public class BCrypt {
* Decode a string encoded using bcrypt's base64 scheme to a * Decode a string encoded using bcrypt's base64 scheme to a
* byte array. Note that this is *not* compatible with * byte array. Note that this is *not* compatible with
* the standard MIME-base64 encoding. * the standard MIME-base64 encoding.
*
* @param s the string to decode * @param s the string to decode
* @param maxolen the maximum number of bytes to decode * @param maxolen the maximum number of bytes to decode
* @return an array containing the bytes decoded
* @throws IllegalArgumentException if maxolen is invalid * @throws IllegalArgumentException if maxolen is invalid
* @return an array containing the bytes decoded
*/ */
private static byte[] decode_base64(String s, int maxolen) private static byte[] decode_base64(String s, int maxolen)
throws IllegalArgumentException { throws IllegalArgumentException {
@@ -485,6 +487,7 @@ public class BCrypt {
/** /**
* Blowfish encipher a single 64-bit block encoded as * Blowfish encipher a single 64-bit block encoded as
* two 32-bit halves * two 32-bit halves
*
* @param lr an array containing the two 32-bit half blocks * @param lr an array containing the two 32-bit half blocks
* @param off the position in the array of the blocks * @param off the position in the array of the blocks
*/ */
@@ -492,7 +495,7 @@ public class BCrypt {
int i, n, l = lr[off], r = lr[off + 1]; int i, n, l = lr[off], r = lr[off + 1];
l ^= P[0]; l ^= P[0];
for (i = 0; i <= BLOWFISH_NUM_ROUNDS - 2;) { for (i = 0; i <= BLOWFISH_NUM_ROUNDS - 2; ) {
// Feistel substitution on left word // Feistel substitution on left word
n = S[(l >> 24) & 0xff]; n = S[(l >> 24) & 0xff];
n += S[0x100 | ((l >> 16) & 0xff)]; n += S[0x100 | ((l >> 16) & 0xff)];
@@ -513,6 +516,7 @@ public class BCrypt {
/** /**
* Cycically extract a word of key material * Cycically extract a word of key material
*
* @param data the string to extract the data from * @param data the string to extract the data from
* @param offp a "pointer" (as a one-entry array) to the * @param offp a "pointer" (as a one-entry array) to the
* current offset into data * current offset into data
@@ -522,14 +526,16 @@ public class BCrypt {
*/ */
private static int[] streamtowords(byte[] data, int[] offp, int[] signp) { private static int[] streamtowords(byte[] data, int[] offp, int[] signp) {
int i; int i;
int[] words = { 0, 0 }; int[] words = {0, 0};
int off = offp[0]; int off = offp[0];
int sign = signp[0]; int sign = signp[0];
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
words[0] = (words[0] << 8) | (data[off] & 0xff); words[0] = (words[0] << 8) | (data[off] & 0xff);
words[1] = (words[1] << 8) | (int)data[off]; words[1] = (words[1] << 8) | (int) data[off];
if (i > 0) sign |= words[1] & 0x80; if (i > 0) {
sign |= words[1] & 0x80;
}
off = (off + 1) % data.length; off = (off + 1) % data.length;
} }
@@ -540,25 +546,27 @@ public class BCrypt {
/** /**
* Cycically extract a word of key material * Cycically extract a word of key material
*
* @param data the string to extract the data from * @param data the string to extract the data from
* @param offp a "pointer" (as a one-entry array) to the * @param offp a "pointer" (as a one-entry array) to the
* current offset into data * current offset into data
* @return the next word of material from data * @return the next word of material from data
*/ */
private static int streamtoword(byte[] data, int[] offp) { private static int streamtoword(byte[] data, int[] offp) {
int[] signp = { 0 }; int[] signp = {0};
return streamtowords(data, offp, signp)[0]; return streamtowords(data, offp, signp)[0];
} }
/** /**
* Cycically extract a word of key material, with sign-extension bug * Cycically extract a word of key material, with sign-extension bug
*
* @param data the string to extract the data from * @param data the string to extract the data from
* @param offp a "pointer" (as a one-entry array) to the * @param offp a "pointer" (as a one-entry array) to the
* current offset into data * current offset into data
* @return the next word of material from data * @return the next word of material from data
*/ */
private static int streamtoword_bug(byte[] data, int[] offp) { private static int streamtoword_bug(byte[] data, int[] offp) {
int[] signp = { 0 }; int[] signp = {0};
return streamtowords(data, offp, signp)[1]; return streamtowords(data, offp, signp)[1];
} }
@@ -572,6 +580,7 @@ public class BCrypt {
/** /**
* Key the Blowfish cipher * Key the Blowfish cipher
*
* @param key an array containing the key * @param key an array containing the key
* @param sign_ext_bug true to implement the 2x bug * @param sign_ext_bug true to implement the 2x bug
*/ */
@@ -582,11 +591,12 @@ public class BCrypt {
int plen = P.length, slen = S.length; int plen = P.length, slen = S.length;
for (i = 0; i < plen; i++) { for (i = 0; i < plen; i++) {
if (!sign_ext_bug) if (!sign_ext_bug) {
P[i] = P[i] ^ streamtoword(key, koffp); P[i] = P[i] ^ streamtoword(key, koffp);
else } else {
P[i] = P[i] ^ streamtoword_bug(key, koffp); P[i] = P[i] ^ streamtoword_bug(key, koffp);
} }
}
for (i = 0; i < plen; i += 2) { for (i = 0; i < plen; i += 2) {
encipher(lr, 0); encipher(lr, 0);
@@ -605,6 +615,7 @@ public class BCrypt {
* Perform the "enhanced key schedule" step described by * Perform the "enhanced key schedule" step described by
* Provos and Mazieres in "A Future-Adaptable Password Scheme" * Provos and Mazieres in "A Future-Adaptable Password Scheme"
* http://www.openbsd.org/papers/bcrypt-paper.ps * http://www.openbsd.org/papers/bcrypt-paper.ps
*
* @param data salt information * @param data salt information
* @param key password information * @param key password information
* @param sign_ext_bug true to implement the 2x bug * @param sign_ext_bug true to implement the 2x bug
@@ -616,7 +627,7 @@ public class BCrypt {
int[] koffp = {0}, doffp = {0}; int[] koffp = {0}, doffp = {0};
int[] lr = {0, 0}; int[] lr = {0, 0};
int plen = P.length, slen = S.length; int plen = P.length, slen = S.length;
int[] signp = { 0 }; // non-benign sign-extension flag int[] signp = {0}; // non-benign sign-extension flag
int diff = 0; // zero iff correct and buggy are same int diff = 0; // zero iff correct and buggy are same
for (i = 0; i < plen; i++) { for (i = 0; i < plen; i++) {
@@ -675,6 +686,7 @@ public class BCrypt {
/** /**
* Perform the central password hashing step in the * Perform the central password hashing step in the
* bcrypt scheme * bcrypt scheme
*
* @param password the password to hash * @param password the password to hash
* @param salt the binary salt to hash with the password * @param salt the binary salt to hash with the password
* @param log_rounds the binary logarithm of the number * @param log_rounds the binary logarithm of the number
@@ -723,23 +735,21 @@ public class BCrypt {
/** /**
* Converts given plaintext to byte representation. * Converts given plaintext to byte representation.
*
* @param plaintext the plaintext password to convert * @param plaintext the plaintext password to convert
* @return Byte representation of given plaintext. * @return Byte representation of given plaintext.
*/ */
private static byte[] stringToBytes(String plaintext) { private static byte[] stringToBytes(String plaintext) {
byte[] plaintextb; byte[] plaintextb;
try { plaintextb = plaintext.getBytes(StandardCharsets.UTF_8);
plaintextb = plaintext.getBytes("UTF-8");
} catch (UnsupportedEncodingException uee) {
throw new AssertionError("UTF-8 is not supported");
}
return plaintextb; return plaintextb;
} }
/** /**
* Hash a password using the OpenBSD bcrypt scheme * Hash a password using the OpenBSD bcrypt scheme
*
* @param password the password to hash * @param password the password to hash
* @param salt the salt to hash with (perhaps generated * @param salt the salt to hash with (perhaps generated
* using BCrypt.gensalt) * using BCrypt.gensalt)
@@ -753,6 +763,7 @@ public class BCrypt {
/** /**
* Hash a password using the OpenBSD bcrypt scheme * Hash a password using the OpenBSD bcrypt scheme
*
* @param passwordb the password to hash, as a byte array * @param passwordb the password to hash, as a byte array
* @param salt the salt to hash with (perhaps generated * @param salt the salt to hash with (perhaps generated
* using BCrypt.gensalt) * using BCrypt.gensalt)
@@ -791,7 +802,9 @@ public class BCrypt {
saltb = decode_base64(real_salt, BCRYPT_SALT_LEN); saltb = decode_base64(real_salt, BCRYPT_SALT_LEN);
if (minor >= 'a') // add null terminator if (minor >= 'a') // add null terminator
{
passwordb = Arrays.copyOf(passwordb, passwordb.length + 1); passwordb = Arrays.copyOf(passwordb, passwordb.length + 1);
}
B = new BCrypt(); B = new BCrypt();
hashed = B.crypt_raw(passwordb, saltb, rounds, hashed = B.crypt_raw(passwordb, saltb, rounds,
@@ -821,13 +834,14 @@ public class BCrypt {
/** /**
* Generate a salt for use with the BCrypt.hashpw() method * Generate a salt for use with the BCrypt.hashpw() method
*
* @param prefix the prefix value (default $2y) * @param prefix the prefix value (default $2y)
* @param log_rounds the log2 of the number of rounds of * @param log_rounds the log2 of the number of rounds of
* hashing to apply - the work factor therefore increases as * hashing to apply - the work factor therefore increases as
* 2**log_rounds. * 2**log_rounds.
* @param random an instance of SecureRandom to use * @param random an instance of SecureRandom to use
* @throws IllegalArgumentException if prefix or log_rounds is invalid
* @return an encoded salt value * @return an encoded salt value
* @exception IllegalArgumentException if prefix or log_rounds is invalid
*/ */
public static String gensalt(String prefix, int log_rounds, SecureRandom random) public static String gensalt(String prefix, int log_rounds, SecureRandom random)
throws IllegalArgumentException { throws IllegalArgumentException {
@@ -837,10 +851,10 @@ public class BCrypt {
if (!prefix.startsWith("$2") || if (!prefix.startsWith("$2") ||
(prefix.charAt(2) != 'a' && prefix.charAt(2) != 'y') && (prefix.charAt(2) != 'a' && prefix.charAt(2) != 'y') &&
prefix.charAt(2) != 'b') { prefix.charAt(2) != 'b') {
throw new IllegalArgumentException ("Invalid prefix"); throw new IllegalArgumentException("Invalid prefix");
} }
if (log_rounds < 4 || log_rounds > 31) { if (log_rounds < 4 || log_rounds > 31) {
throw new IllegalArgumentException ("Invalid log_rounds"); throw new IllegalArgumentException("Invalid log_rounds");
} }
random.nextBytes(rnd); random.nextBytes(rnd);
@@ -863,12 +877,13 @@ public class BCrypt {
/** /**
* Generate a salt for use with the BCrypt.hashpw() method * Generate a salt for use with the BCrypt.hashpw() method
*
* @param prefix the prefix value (default $2y) * @param prefix the prefix value (default $2y)
* @param log_rounds the log2 of the number of rounds of * @param log_rounds the log2 of the number of rounds of
* hashing to apply - the work factor therefore increases as * hashing to apply - the work factor therefore increases as
* 2**log_rounds. * 2**log_rounds.
* @throws IllegalArgumentException if prefix or log_rounds is invalid
* @return an encoded salt value * @return an encoded salt value
* @exception IllegalArgumentException if prefix or log_rounds is invalid
*/ */
public static String gensalt(String prefix, int log_rounds) public static String gensalt(String prefix, int log_rounds)
throws IllegalArgumentException { throws IllegalArgumentException {
@@ -877,12 +892,13 @@ public class BCrypt {
/** /**
* Generate a salt for use with the BCrypt.hashpw() method * Generate a salt for use with the BCrypt.hashpw() method
*
* @param log_rounds the log2 of the number of rounds of * @param log_rounds the log2 of the number of rounds of
* hashing to apply - the work factor therefore increases as * hashing to apply - the work factor therefore increases as
* 2**log_rounds. * 2**log_rounds.
* @param random an instance of SecureRandom to use * @param random an instance of SecureRandom to use
* @throws IllegalArgumentException if prefix or log_rounds is invalid
* @return an encoded salt value * @return an encoded salt value
* @exception IllegalArgumentException if prefix or log_rounds is invalid
*/ */
public static String gensalt(int log_rounds, SecureRandom random) public static String gensalt(int log_rounds, SecureRandom random)
throws IllegalArgumentException { throws IllegalArgumentException {
@@ -891,11 +907,12 @@ public class BCrypt {
/** /**
* Generate a salt for use with the BCrypt.hashpw() method * Generate a salt for use with the BCrypt.hashpw() method
*
* @param log_rounds the log2 of the number of rounds of * @param log_rounds the log2 of the number of rounds of
* hashing to apply - the work factor therefore increases as * hashing to apply - the work factor therefore increases as
* 2**log_rounds. * 2**log_rounds.
* @throws IllegalArgumentException if prefix or log_rounds is invalid
* @return an encoded salt value * @return an encoded salt value
* @exception IllegalArgumentException if prefix or log_rounds is invalid
*/ */
public static String gensalt(int log_rounds) public static String gensalt(int log_rounds)
throws IllegalArgumentException { throws IllegalArgumentException {
@@ -906,8 +923,9 @@ public class BCrypt {
* Generate a salt for use with the BCrypt.hashpw() method, * Generate a salt for use with the BCrypt.hashpw() method,
* selecting a reasonable default for the number of hashing * selecting a reasonable default for the number of hashing
* rounds to apply * rounds to apply
*
* @throws IllegalArgumentException if prefix or log_rounds is invalid
* @return an encoded salt value * @return an encoded salt value
* @exception IllegalArgumentException if prefix or log_rounds is invalid
*/ */
public static String gensalt() public static String gensalt()
throws IllegalArgumentException { throws IllegalArgumentException {
@@ -917,6 +935,7 @@ public class BCrypt {
/** /**
* Check that a plaintext password matches a previously hashed * Check that a plaintext password matches a previously hashed
* one * one
*
* @param plaintext the plaintext password to verify * @param plaintext the plaintext password to verify
* @param hashed the previously-hashed password * @param hashed the previously-hashed password
* @return true if the passwords match, false otherwise * @return true if the passwords match, false otherwise
@@ -929,6 +948,7 @@ public class BCrypt {
/** /**
* Check that a plaintext byte[] password matches a previously hashed * Check that a plaintext byte[] password matches a previously hashed
* one * one
*
* @param plaintext the plaintext password to verify * @param plaintext the plaintext password to verify
* @param hashed the previously-hashed password * @param hashed the previously-hashed password
* @return true if the passwords match, false otherwise * @return true if the passwords match, false otherwise
@@ -936,18 +956,16 @@ public class BCrypt {
public static boolean checkpw(byte[] plaintext, String hashed) { public static boolean checkpw(byte[] plaintext, String hashed) {
byte[] hashed_bytes; byte[] hashed_bytes;
byte[] try_bytes; byte[] try_bytes;
try {
String try_pw = hashpw(plaintext, hashed); String try_pw = hashpw(plaintext, hashed);
hashed_bytes = hashed.getBytes("UTF-8"); hashed_bytes = hashed.getBytes(StandardCharsets.UTF_8);
try_bytes = try_pw.getBytes("UTF-8"); try_bytes = try_pw.getBytes(StandardCharsets.UTF_8);
} catch (UnsupportedEncodingException uee) { if (hashed_bytes.length != try_bytes.length) {
return false; return false;
} }
if (hashed_bytes.length != try_bytes.length)
return false;
byte ret = 0; byte ret = 0;
for (int i = 0; i < try_bytes.length; i++) for (int i = 0; i < try_bytes.length; i++) {
ret |= hashed_bytes[i] ^ try_bytes[i]; ret |= hashed_bytes[i] ^ try_bytes[i];
}
return ret == 0; return ret == 0;
} }
} }

View File

@@ -1,10 +1,6 @@
package tools; package tools;
import java.io.File; import java.io.*;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;

View File

@@ -58,7 +58,7 @@ public class HexTool {
int nextb = 0; int nextb = 0;
boolean highoc = true; boolean highoc = true;
outer: outer:
for (;;) { for (; ; ) {
int number = -1; int number = -1;
while (number == -1) { while (number == -1) {
if (nexti == hex.length()) { if (nexti == hex.length()) {

View File

@@ -31,12 +31,11 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
*
* @author Ronan * @author Ronan
*/ */
public class IntervalBuilder { public class IntervalBuilder {
private List<Line2D> intervalLimits = new ArrayList<>(); private final List<Line2D> intervalLimits = new ArrayList<>();
protected MonitoredReadLock intervalRlock; protected MonitoredReadLock intervalRlock;
protected MonitoredWriteLock intervalWlock; protected MonitoredWriteLock intervalWlock;
@@ -100,7 +99,9 @@ public class IntervalBuilder {
} }
int en = bsearchInterval(to); int en = bsearchInterval(to);
if (en < st) en = st - 1; if (en < st) {
en = st - 1;
}
refitOverlappedIntervals(st, en + 1, from, to); refitOverlappedIntervals(st, en + 1, from, to);
} finally { } finally {

View File

@@ -20,13 +20,13 @@ public class LogHelper {
String log = "TRADE BETWEEN " + name1 + " AND " + name2 + "\r\n"; String log = "TRADE BETWEEN " + name1 + " AND " + name2 + "\r\n";
//Trade 1 to trade 2 //Trade 1 to trade 2
log += trade1.getExchangeMesos() + " mesos from " + name1 + " to " + name2 + " \r\n"; log += trade1.getExchangeMesos() + " mesos from " + name1 + " to " + name2 + " \r\n";
for (Item item : trade1.getItems()){ for (Item item : trade1.getItems()) {
String itemName = ItemInformationProvider.getInstance().getName(item.getItemId()) + "(" + item.getItemId() + ")"; String itemName = ItemInformationProvider.getInstance().getName(item.getItemId()) + "(" + item.getItemId() + ")";
log += item.getQuantity() + " " + itemName + " from " + name1 + " to " + name2 + " \r\n"; log += item.getQuantity() + " " + itemName + " from " + name1 + " to " + name2 + " \r\n";
} }
//Trade 2 to trade 1 //Trade 2 to trade 1
log += trade2.getExchangeMesos() + " mesos from " + name2 + " to " + name1 + " \r\n"; log += trade2.getExchangeMesos() + " mesos from " + name2 + " to " + name1 + " \r\n";
for (Item item : trade2.getItems()){ for (Item item : trade2.getItems()) {
String itemName = ItemInformationProvider.getInstance().getName(item.getItemId()) + "(" + item.getItemId() + ")"; String itemName = ItemInformationProvider.getInstance().getName(item.getItemId()) + "(" + item.getItemId() + ")";
log += item.getQuantity() + " " + itemName + " from " + name2 + " to " + name1 + " \r\n"; log += item.getQuantity() + " " + itemName + " from " + name2 + " to " + name1 + " \r\n";
} }
@@ -40,21 +40,21 @@ public class LogHelper {
String log = expedition.getType().toString() + " EXPEDITION\r\n"; String log = expedition.getType().toString() + " EXPEDITION\r\n";
log += getTimeString(expedition.getStartTime()) + "\r\n"; log += getTimeString(expedition.getStartTime()) + "\r\n";
for (String memberName : expedition.getMembers().values()){ for (String memberName : expedition.getMembers().values()) {
log += ">>" + memberName + "\r\n"; log += ">>" + memberName + "\r\n";
} }
log += "BOSS KILLS\r\n"; log += "BOSS KILLS\r\n";
for (String message: expedition.getBossLogs()){ for (String message : expedition.getBossLogs()) {
log += message; log += message;
} }
log += "\r\n"; log += "\r\n";
FilePrinter.print(FilePrinter.LOG_EXPEDITION, log); FilePrinter.print(FilePrinter.LOG_EXPEDITION, log);
} }
public static String getTimeString(long then){ public static String getTimeString(long then) {
long duration = System.currentTimeMillis() - then; long duration = System.currentTimeMillis() - then;
int seconds = (int) (duration / 1000) % 60 ; int seconds = (int) (duration / 1000) % 60;
int minutes = (int) ((duration / (1000*60)) % 60); int minutes = (int) ((duration / (1000 * 60)) % 60);
return minutes + " Minutes and " + seconds + " Seconds"; return minutes + " Minutes and " + seconds + " Seconds";
} }
@@ -71,9 +71,9 @@ public class LogHelper {
FilePrinter.print(FilePrinter.LOG_GACHAPON, log); FilePrinter.print(FilePrinter.LOG_GACHAPON, log);
} }
public static void logChat(Client player, String chatType, String text){ public static void logChat(Client player, String chatType, String text) {
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm"); SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm");
FilePrinter.print(FilePrinter.LOG_CHAT, "[" + sdf.format(Calendar.getInstance().getTime()) + "] (" + chatType + ") " +player.getPlayer().getName() + ": " + text); FilePrinter.print(FilePrinter.LOG_CHAT, "[" + sdf.format(Calendar.getInstance().getTime()) + "] (" + chatType + ") " + player.getPlayer().getName() + ": " + text);
} }
} }

View File

@@ -1,23 +1,19 @@
package tools; package tools;
/** /**
*
* @author Shavit * @author Shavit
*/ */
public class LongTool { public class LongTool {
// Converts 8 bytes to a long. // Converts 8 bytes to a long.
public static long BytesToLong(byte[] aToConvert) public static long BytesToLong(byte[] aToConvert) {
{ if (aToConvert.length != Long.BYTES) {
if(aToConvert.length != Long.BYTES)
{
throw new IllegalArgumentException(String.format("Size of input should be %d", (Long.SIZE / 8))); throw new IllegalArgumentException(String.format("Size of input should be %d", (Long.SIZE / 8)));
} }
long nResult = 0; long nResult = 0;
for(int i = 0; i < Long.BYTES; i++) for (int i = 0; i < Long.BYTES; i++) {
{
nResult <<= Byte.SIZE; nResult <<= Byte.SIZE;
nResult |= (aToConvert[i] & 0xFF); nResult |= (aToConvert[i] & 0xFF);
} }
@@ -26,12 +22,10 @@ public class LongTool {
} }
// Converts a long to 8 bytes. // Converts a long to 8 bytes.
public static byte[] LongToBytes(long nToConvert) public static byte[] LongToBytes(long nToConvert) {
{
byte[] aBytes = new byte[Long.BYTES]; byte[] aBytes = new byte[Long.BYTES];
for(int i = aBytes.length - 1; i >= 0; i--) for (int i = aBytes.length - 1; i >= 0; i--) {
{
aBytes[i] = (byte) (nToConvert & 0xFF); aBytes[i] = (byte) (nToConvert & 0xFF);
nToConvert >>= Byte.SIZE; nToConvert >>= Byte.SIZE;
} }

View File

@@ -23,12 +23,11 @@ package tools;
/** /**
* Represents a pair of values. * Represents a pair of values.
* *
* @author Frz
* @since Revision 333
* @version 1.0
*
* @param <E> The type of the left value. * @param <E> The type of the left value.
* @param <F> The type of the right value. * @param <F> The type of the right value.
* @author Frz
* @version 1.0
* @since Revision 333
*/ */
public class Pair<E, F> { public class Pair<E, F> {
@@ -110,12 +109,7 @@ public class Pair<E, F> {
return false; return false;
} }
if (right == null) { if (right == null) {
if (other.right != null) { return other.right == null;
return false; } else return right.equals(other.right);
}
} else if (!right.equals(other.right)) {
return false;
}
return true;
} }
} }

View File

@@ -23,7 +23,6 @@ import net.packet.InPacket;
/** /**
*
* @author Ronan * @author Ronan
*/ */
public class EmptyMovementException extends Exception { public class EmptyMovementException extends Exception {

View File

@@ -21,7 +21,6 @@ package tools.exceptions;
/** /**
*
* @author Ronan * @author Ronan
*/ */
public class EventInstanceInProgressException extends Exception { public class EventInstanceInProgressException extends Exception {

View File

@@ -11,15 +11,13 @@ import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
/** /**
*
* @author RonanLana * @author RonanLana
* <p>
This application gathers info from the WZ.XML files, fetching all cosmetic coupons and tickets from there, and then * This application gathers info from the WZ.XML files, fetching all cosmetic coupons and tickets from there, and then
searches the NPC script files, identifying the stylish NPCs that supposedly uses them. It will reports all NPCs that * searches the NPC script files, identifying the stylish NPCs that supposedly uses them. It will reports all NPCs that
uses up a card, as well as report those currently unused. * uses up a card, as well as report those currently unused.
* <p>
Estimated parse time: 10 seconds * Estimated parse time: 10 seconds
*/ */
public class CashCosmeticsFetcher { public class CashCosmeticsFetcher {
private static final Map<Integer, String> scriptEntries = new HashMap<>(500); private static final Map<Integer, String> scriptEntries = new HashMap<>(500);
@@ -41,7 +39,7 @@ public class CashCosmeticsFetcher {
private static int getNpcIdFromFilename(String name) { private static int getNpcIdFromFilename(String name) {
try { try {
return Integer.parseInt(name.substring(0, name.indexOf('.'))); return Integer.parseInt(name.substring(0, name.indexOf('.')));
} catch(Exception e) { } catch (Exception e) {
return -1; return -1;
} }
} }
@@ -50,7 +48,7 @@ public class CashCosmeticsFetcher {
ArrayList<File> files = new ArrayList<>(); ArrayList<File> files = new ArrayList<>();
listFiles(ToolConstants.SCRIPTS_PATH + "/npc", files); listFiles(ToolConstants.SCRIPTS_PATH + "/npc", files);
for(File f : files) { for (File f : files) {
Integer npcid = getNpcIdFromFilename(f.getName()); Integer npcid = getNpcIdFromFilename(f.getName());
//System.out.println("Parsing " + f.getAbsolutePath()); //System.out.println("Parsing " + f.getAbsolutePath());
@@ -60,7 +58,7 @@ public class CashCosmeticsFetcher {
StringBuilder stringBuffer = new StringBuilder(); StringBuilder stringBuffer = new StringBuilder();
String line; String line;
while((line = bufferedReader.readLine())!=null){ while ((line = bufferedReader.readLine()) != null) {
stringBuffer.append(line).append("\n"); stringBuffer.append(line).append("\n");
} }
@@ -108,7 +106,7 @@ public class CashCosmeticsFetcher {
System.out.println("Loaded scripts"); System.out.println("Loaded scripts");
reportCosmeticCouponResults(); reportCosmeticCouponResults();
} catch(Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }

View File

@@ -8,13 +8,12 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
/** /**
*
* @author RonanLana * @author RonanLana
* * <p>
This application main objective is to read Vega-related information from * This application main objective is to read Vega-related information from
the item's description report back missing nodes for these items. * the item's description report back missing nodes for these items.
* <p>
Estimated parse time: 10 seconds * Estimated parse time: 10 seconds
*/ */
public class CashVegaChecker { public class CashVegaChecker {
private static final File OUTPUT_FILE = ToolConstants.getOutputFile("vega_checker_report.txt"); private static final File OUTPUT_FILE = ToolConstants.getOutputFile("vega_checker_report.txt");
@@ -40,7 +39,7 @@ public class CashVegaChecker {
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) {
@@ -56,36 +55,33 @@ public class CashVegaChecker {
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;
} }
} }
private static void translateItemToken(String token) { private static void translateItemToken(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;
if (status == 2) { if (status == 2) {
@@ -101,10 +97,9 @@ public class CashVegaChecker {
} }
private static void translateVegaToken(String token) { private static void translateVegaToken(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;
} else { } else {
if (status == 2) { if (status == 2) {
@@ -122,7 +117,7 @@ public class CashVegaChecker {
bufferedReader = new BufferedReader(fileReader); bufferedReader = new BufferedReader(fileReader);
String line; String line;
while((line = bufferedReader.readLine())!=null){ while ((line = bufferedReader.readLine()) != null) {
translateItemToken(line); translateItemToken(line);
} }
@@ -141,7 +136,7 @@ public class CashVegaChecker {
bufferedReader = new BufferedReader(fileReader); bufferedReader = new BufferedReader(fileReader);
String line; String line;
while((line = bufferedReader.readLine())!=null){ while ((line = bufferedReader.readLine()) != null) {
translateVegaToken(line); translateVegaToken(line);
} }

View File

@@ -22,7 +22,6 @@ package tools.mapletools;
import java.util.List; import java.util.List;
/** /**
*
* @author RonanLana * @author RonanLana
*/ */
public class MakerItemEntry { public class MakerItemEntry {

View File

@@ -121,7 +121,7 @@ public class MonsterStatFetcher {
} }
monsterStats.put(mid, stats); monsterStats.put(mid, stats);
} catch(NullPointerException npe) { } catch (NullPointerException npe) {
//System.out.println("[SEVERE] " + mFile.getName() + " failed to load. Issue: " + npe.getMessage() + "\n\n"); //System.out.println("[SEVERE] " + mFile.getName() + " failed to load. Issue: " + npe.getMessage() + "\n\n");
} }
} }

View File

@@ -29,7 +29,6 @@ import tools.PacketCreator;
import java.util.Calendar; import java.util.Calendar;
/** /**
*
* @author FateJiki (RaGeZONE) * @author FateJiki (RaGeZONE)
* @author Ronan - timing pattern * @author Ronan - timing pattern
*/ */
@@ -65,7 +64,7 @@ public class Fishing {
return (0.23 * yearLikelihood) + (0.77 * timeLikelihood) + (baitLikelihood) > 57.777; return (0.23 * yearLikelihood) + (0.77 * timeLikelihood) + (baitLikelihood) > 57.777;
} }
public static void doFishing(Character chr, int baitLevel, double yearLikelihood, double timeLikelihood){ public static void doFishing(Character chr, int baitLevel, double yearLikelihood, double timeLikelihood) {
// thanks Fadi, Vcoc for suggesting a custom fishing system // thanks Fadi, Vcoc for suggesting a custom fishing system
if (!chr.isLoggedinWorld() || !chr.isAlive()) { if (!chr.isLoggedinWorld() || !chr.isAlive()) {
@@ -89,16 +88,16 @@ public class Fishing {
String rewardStr = ""; String rewardStr = "";
fishingEffect = "Effect/BasicEff.img/Catch/Success"; fishingEffect = "Effect/BasicEff.img/Catch/Success";
int rand = (int)(3.0 * Math.random()); int rand = (int) (3.0 * Math.random());
switch(rand){ switch (rand) {
case 0: case 0:
int mesoAward = (int)(1400.0 * Math.random() + 1201) * chr.getMesoRate() + (15 * chr.getLevel() / 5); int mesoAward = (int) (1400.0 * Math.random() + 1201) * chr.getMesoRate() + (15 * chr.getLevel() / 5);
chr.gainMeso(mesoAward, true, true, true); chr.gainMeso(mesoAward, true, true, true);
rewardStr = mesoAward + " mesos."; rewardStr = mesoAward + " mesos.";
break; break;
case 1: case 1:
int expAward = (int)(645.0 * Math.random() + 620.0) * chr.getExpRate() + (15 * chr.getLevel() / 4); int expAward = (int) (645.0 * Math.random() + 620.0) * chr.getExpRate() + (15 * chr.getLevel() / 4);
chr.gainExp(expAward, true, true); chr.gainExp(expAward, true, true);
rewardStr = expAward + " EXP."; rewardStr = expAward + " EXP.";
@@ -123,18 +122,18 @@ public class Fishing {
chr.getMap().broadcastMessage(chr, PacketCreator.showForeignInfo(chr.getId(), fishingEffect), false); chr.getMap().broadcastMessage(chr, PacketCreator.showForeignInfo(chr.getId(), fishingEffect), false);
} }
public static int getRandomItem(){ public static int getRandomItem() {
int rand = (int)(100.0 * Math.random()); int rand = (int) (100.0 * Math.random());
int[] commons = {1002851, 2002020, 2002020, 2000006, 2000018, 2002018, 2002024, 2002027, 2002027, 2000018, 2000018, 2000018, 2000018, 2002030, 2002018, 2000016}; // filler' up int[] commons = {1002851, 2002020, 2002020, 2000006, 2000018, 2002018, 2002024, 2002027, 2002027, 2000018, 2000018, 2000018, 2000018, 2002030, 2002018, 2000016}; // filler' up
int[] uncommons = {1000025, 1002662, 1002812, 1002850, 1002881, 1002880, 1012072, 4020009, 2043220, 2043022, 2040543, 2044420, 2040943, 2043713, 2044220, 2044120, 2040429, 2043220, 2040943}; // filler' uptoo int[] uncommons = {1000025, 1002662, 1002812, 1002850, 1002881, 1002880, 1012072, 4020009, 2043220, 2043022, 2040543, 2044420, 2040943, 2043713, 2044220, 2044120, 2040429, 2043220, 2040943}; // filler' uptoo
int[] rares = {1002859, 1002553, 1002762, 1002763, 1002764, 1002765, 1002766, 1002663, 1002788, 1002949, 2049100, 2340000, 2040822, 2040822, 2040822, 2040822}; // filler' uplast int[] rares = {1002859, 1002553, 1002762, 1002763, 1002764, 1002765, 1002766, 1002663, 1002788, 1002949, 2049100, 2340000, 2040822, 2040822, 2040822, 2040822}; // filler' uplast
if(rand >= 25){ if (rand >= 25) {
return commons[(int)(commons.length * Math.random())]; return commons[(int) (commons.length * Math.random())];
} else if(rand <= 7 && rand >= 4){ } else if (rand <= 7 && rand >= 4) {
return uncommons[(int)(uncommons.length * Math.random())]; return uncommons[(int) (uncommons.length * Math.random())];
} else { } else {
return rares[(int)(rares.length * Math.random())]; return rares[(int) (rares.length * Math.random())];
} }
} }

View File

@@ -21,7 +21,7 @@ import java.util.List;
* CField_Wedding, CField_WeddingPhoto, CWeddingMan, OnMarriageResult, and all Wedding/Marriage enum/structs. * CField_Wedding, CField_WeddingPhoto, CWeddingMan, OnMarriageResult, and all Wedding/Marriage enum/structs.
* *
* @author Eric * @author Eric
* * <p>
* Wishlists edited by Drago (Dragohe4rt) * Wishlists edited by Drago (Dragohe4rt)
*/ */
public class WeddingPackets extends PacketCreator { public class WeddingPackets extends PacketCreator {
@@ -89,8 +89,9 @@ public class WeddingPackets extends PacketCreator {
ENGAGED(0x1), ENGAGED(0x1),
RESERVED(0x2), RESERVED(0x2),
MARRIED(0x3); MARRIED(0x3);
private int ms; private final int ms;
private MarriageStatus(int ms) {
MarriageStatus(int ms) {
this.ms = ms; this.ms = ms;
} }
@@ -107,8 +108,9 @@ public class WeddingPackets extends PacketCreator {
AddReservation(0x4), AddReservation(0x4),
DeleteReservation(0x5), DeleteReservation(0x5),
GetReservation(0x6); GetReservation(0x6);
private int req; private final int req;
private MarriageRequest(int req) {
MarriageRequest(int req) {
this.req = req; this.req = req;
} }
@@ -124,8 +126,9 @@ public class WeddingPackets extends PacketCreator {
CATHEDRAL_NORMAL(0xB), CATHEDRAL_NORMAL(0xB),
VEGAS_PREMIUM(0x14), VEGAS_PREMIUM(0x14),
VEGAS_NORMAL(0x15); VEGAS_NORMAL(0x15);
private int wt; private final int wt;
private WeddingType(int wt) {
WeddingType(int wt) {
this.wt = wt; this.wt = wt;
} }
@@ -140,8 +143,9 @@ public class WeddingPackets extends PacketCreator {
CATHEDRAL_STARTMAP(680000210), CATHEDRAL_STARTMAP(680000210),
PHOTOMAP(680000300), PHOTOMAP(680000300),
EXITMAP(680000500); EXITMAP(680000500);
private int wm; private final int wm;
private WeddingMap(int wm) {
WeddingMap(int wm) {
this.wm = wm; this.wm = wm;
} }
@@ -182,8 +186,9 @@ public class WeddingPackets extends PacketCreator {
WT_VEGAS_NORMAL(5251001), WT_VEGAS_NORMAL(5251001),
WT_VEGAS_PREMIUM(5251002), WT_VEGAS_PREMIUM(5251002),
WT_CATHEDRAL_PREMIUM(5251003); WT_CATHEDRAL_PREMIUM(5251003);
private int wi; private final int wi;
private WeddingItem(int wi) {
WeddingItem(int wi) {
this.wi = wi; this.wi = wi;
} }
@@ -217,7 +222,7 @@ public class WeddingPackets extends PacketCreator {
* - Finally, after encoding all of our data, we send this packet out to a MapGen application server * - Finally, after encoding all of our data, we send this packet out to a MapGen application server
* - The MapGen server will then retrieve the packet byte array and convert the bytes into a ImageIO 2D JPG output * - The MapGen server will then retrieve the packet byte array and convert the bytes into a ImageIO 2D JPG output
* - The result after converting into a JPG will then be remotely uploaded to /weddings/ with ReservedGroomName_ReservedBrideName to be displayed on the web server. * - The result after converting into a JPG will then be remotely uploaded to /weddings/ with ReservedGroomName_ReservedBrideName to be displayed on the web server.
* * <p>
* - Will no longer continue Wedding Photos, needs a WvsMapGen :( * - Will no longer continue Wedding Photos, needs a WvsMapGen :(
* *
* @param ReservedGroomName The groom IGN of the wedding * @param ReservedGroomName The groom IGN of the wedding