Another batch of preemptive bugfixing

This commit is contained in:
ceikry 2021-07-26 07:33:07 -05:00
parent b151cb852b
commit 1b7c2914cb
19 changed files with 84 additions and 84 deletions

View file

@ -13,8 +13,10 @@ import ms.world.WorldDatabase;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
/**
@ -138,7 +140,7 @@ public final class Management {
Runtime.getRuntime().addShutdownHook(new ShutdownSequence());
System.out.println("Status: ready.");
System.out.println("Use -commands for a list of commands!");
Scanner s = new Scanner(System.in);
Scanner s = new Scanner(new InputStreamReader(System.in, StandardCharsets.UTF_8));
while (s.hasNext()) {
try {
String command = s.nextLine();

View file

@ -30,7 +30,7 @@ public class ClassLoadServer extends Thread {
/**
* Holds classes and resources already added in the server
*/
protected static HashMap<String, byte[]> resourceCache = new HashMap<String, byte[]>();
protected final static HashMap<String, byte[]> resourceCache = new HashMap<String, byte[]>();
/**
* New socket
@ -60,7 +60,9 @@ public class ClassLoadServer extends Thread {
//System.out.println("New Connection from : " + clientSocket.getInetAddress());
WorkerThread wcs = new WorkerThread(clientSocket);
wcs.start();
} catch (Exception e) {}
} catch (Exception e) {
e.printStackTrace();
}
}
}

View file

@ -137,16 +137,16 @@ public class IoSession {
*/
public void queue(ByteBuffer buffer) {
try {
writingLock.tryLock(1000L, TimeUnit.MILLISECONDS);
} catch (Exception e){
e.printStackTrace();
writingLock.unlock();
return;
}
if(writingLock.tryLock(1000L, TimeUnit.MILLISECONDS)){
writingQueue.add(buffer);
writingLock.unlock();
write();
}
} catch (Exception e){
e.printStackTrace();
writingLock.unlock();
}
}
/**
* Handles the writing of all buffers in the queue.
@ -168,11 +168,12 @@ public class IoSession {
}
writingQueue.remove(0);
}
writingLock.unlock();
} catch (IOException e) {
disconnect();
}
writingLock.unlock();
}
}
/**
* Disconnects the session.

View file

@ -1,6 +1,7 @@
package ms.net.packet;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import ms.system.util.ByteBufferUtils;
@ -301,7 +302,7 @@ public class IoBuffer {
* @return
*/
public IoBuffer putString(String val) {
buf.put(val.getBytes());
buf.put(val.getBytes(StandardCharsets.UTF_8));
buf.put((byte) 0);
return this;
}
@ -313,7 +314,7 @@ public class IoBuffer {
*/
public IoBuffer putJagString(String val) {
buf.put((byte) 0);
buf.put(val.getBytes());
buf.put(val.getBytes(StandardCharsets.UTF_8));
buf.put((byte) 0);
return this;
}
@ -557,18 +558,6 @@ public class IoBuffer {
return buf.getLong();
}
/**
*
* @return
*/
public int getSmart() {
int peek = buf.get(buf.position());
if (peek <= Byte.MAX_VALUE) {
return buf.get() & 0xFF;
}
return (buf.getShort() & 0xFFFF) - 32768;
}
/**
*
* @return

View file

@ -42,7 +42,7 @@ object WorldPacketRepository {
* @param message The message to send.
*/
@JvmStatic
fun sendPlayerMessage(player: PlayerSession?, message: String?) {
fun sendPlayerMessage(player: PlayerSession?, message: String) {
if (player == null) {
return
}
@ -52,7 +52,7 @@ object WorldPacketRepository {
player.world.session.write(buffer)
}
fun sendPlayerMessage(player: PlayerSession?, messages: Array<String?>) {
fun sendPlayerMessage(player: PlayerSession?, messages: Array<String>) {
if (player == null) {
return
}
@ -98,7 +98,7 @@ object WorldPacketRepository {
@JvmStatic
fun sendContactUpdate(
player: PlayerSession,
contact: String?,
contact: String,
block: Boolean,
remove: Boolean,
worldId: Int,
@ -127,7 +127,7 @@ object WorldPacketRepository {
* @param type The message type.
*/
@JvmStatic
fun sendMessage(player: PlayerSession, p: PlayerSession, type: Int, message: String?) {
fun sendMessage(player: PlayerSession, p: PlayerSession, type: Int, message: String) {
val buffer = IoBuffer(5, PacketHeader.BYTE)
buffer.putString(player.username)
buffer.putString(p.username)
@ -184,7 +184,7 @@ object WorldPacketRepository {
* @param names The names.
*/
@JvmStatic
fun notifyPlayers(server: GameServer, player: PlayerSession, names: List<String?>) {
fun notifyPlayers(server: GameServer, player: PlayerSession, names: List<String>) {
val buffer = IoBuffer(8, PacketHeader.SHORT)
buffer.putString(player.username)
buffer.put(player.worldId)
@ -227,7 +227,7 @@ object WorldPacketRepository {
* @param duration The duration of the punishment.
*/
@JvmStatic
fun sendPunishUpdate(world: GameServer, key: String?, type: Int, duration: Long) {
fun sendPunishUpdate(world: GameServer, key: String, type: Int, duration: Long) {
val buffer = IoBuffer(11, PacketHeader.BYTE)
buffer.putString(key)
buffer.put(type)

View file

@ -79,8 +79,9 @@ public final class PunishmentStorage {
e.printStackTrace();
SQLManager.close(connection);
return;
}
} finally {
SQLManager.close(connection);
}
return;
case 2:
ban(player.getIpAddress(), type);
@ -152,8 +153,9 @@ public final class PunishmentStorage {
e.printStackTrace();
SQLManager.close(connection);
return false;
}
} finally {
SQLManager.close(connection);
}
return true;
}
@ -175,8 +177,9 @@ public final class PunishmentStorage {
e.printStackTrace();
SQLManager.close(connection);
return false;
}
} finally {
SQLManager.close(connection);
}
return true;
}
@ -239,8 +242,9 @@ public final class PunishmentStorage {
e.printStackTrace();
SQLManager.close(connection);
return false;
}
} finally {
SQLManager.close(connection);
}
return true;
}
@ -252,9 +256,9 @@ public final class PunishmentStorage {
private static String getDuration(long end) {
String time = "indefinite time";
if (end != Long.MAX_VALUE) {
int days = (int) ((end -= System.currentTimeMillis()) / (24 * 60 * 60_000));
int hours = (int) ((end -= (days * 24 * 60 * 60_000)) / (60 * 60_000));
int minutes = (int) ((end -= (hours * (60 * 60_000))) / 60_000);
int days = (int) ((System.currentTimeMillis()) / (24 * 60 * 60_000));
int hours = (int) (((24L * days * 60 * 60_000)) / (60 * 60_000));
int minutes = (int) (((hours * (60 * 60_000))) / 60_000);
time = days + "d, " + hours + "h, " + minutes + "m";
}
return time;

View file

@ -141,14 +141,20 @@ public final class CommunicationInfo {
public void save(PreparedStatement statement) throws SQLException {
String contacts = "";
String blocked = "";
StringBuilder blockedBuilder = new StringBuilder();
for (int i = 0; i < this.blocked.size(); i++) {
blocked += (i == 0 ? "" : ",") + this.blocked.get(i);
String blockline = (i == 0 ? "" : ",") + this.blocked.get(i);
blockedBuilder.append(blockline);
}
blocked = blockedBuilder.toString();
int count = 0;
StringBuilder contactBuilder = new StringBuilder();
for (Entry<String, ClanRank> entry : this.contacts.entrySet()) {
contacts += "{" + entry.getKey() + "," + entry.getValue().ordinal() + "}" + (count == this.contacts.size() - 1 ? "" : "~");
String contactLine = "{" + entry.getKey() + "," + entry.getValue().ordinal() + "}" + (count == this.contacts.size() - 1 ? "" : "~");
contactBuilder.append(contactLine);
count++;
}
contacts = contactBuilder.toString();
statement.setString(3, contacts);
statement.setString(4, blocked);
statement.setString(5, clanName);
@ -211,6 +217,8 @@ public final class CommunicationInfo {
case 3:
lootRequirement = rank;
break;
default:
break;
}
}
}
@ -239,9 +247,9 @@ public final class CommunicationInfo {
*/
public void save(ByteBuffer buffer) {
buffer.put((byte) contacts.size());
for (String name : contacts.keySet()) {
ByteBufferUtils.putString(name, buffer);
buffer.put((byte) contacts.get(name).ordinal());
for(Entry<String,ClanRank> contact : contacts.entrySet()){
ByteBufferUtils.putString(contact.getKey(), buffer);
buffer.put((byte) contact.getValue().ordinal());
}
buffer.put((byte) blocked.size());
for (String name : blocked) {

View file

@ -52,12 +52,4 @@ public final class SQLTable {
return updated;
}
/**
* Gets the columns.
* @return The columns.
*/
public SQLColumn[] getColumns() {
return columns;
}
}

View file

@ -31,12 +31,16 @@ public final class WorldListSQLHandler extends SQLEntryHandler<GameServer> {
* Clears the world list.
*/
public static void clearWorldList() {
try {
Connection connection = SQLManager.getConnection();
if(connection == null) return;
try {
PreparedStatement statement = connection.prepareStatement("DELETE FROM " + TABLE);
statement.executeUpdate();
} catch (SQLException e) {
} catch (Exception e) {
e.printStackTrace();
SQLManager.close(connection);
} finally {
SQLManager.close(connection);
}
}

View file

@ -1,6 +1,7 @@
package ms.system.util;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
/**
@ -30,7 +31,7 @@ public final class ByteBufferUtils {
* @param buffer The byte buffer.
*/
public static void putString(String s, ByteBuffer buffer) {
buffer.put(s.getBytes()).put((byte) 0);
buffer.put(s.getBytes(StandardCharsets.UTF_8)).put((byte) 0);
}
/**

View file

@ -484,7 +484,7 @@ public class EncryptionManager {
* @return the decoded value of x
*/
private static byte char64(char x) {
if ((int)x < 0 || (int)x > index_64.length)
if ((int)x > index_64.length)
return -1;
return index_64[(int)x];
}

View file

@ -14,26 +14,16 @@ public final class StringUtils {
/**
* The valid characters to be used in names/messages/...
*/
public static final char[] VALID_CHARS = {
private static final char[] VALID_CHARS = {
'_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
};
/**
* Character mapping.
*/
public static char[] mapping = {
'\n',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' ' };
/**
* The an int array241.
*/
public static int[] anIntArray241 = { 215, 203, 83, 158, 104, 101, 93, 84,
private final static int[] anIntArray241 = { 215, 203, 83, 158, 104, 101, 93, 84,
107, 103, 109, 95, 94, 98, 89, 86, 70, 41, 32, 27, 24, 23, -1, -2,
26, -3, -4, 31, 30, -5, -6, -7, 37, 38, 36, -8, -9, -10, 40, -11,
-12, 55, 48, 46, 47, -13, -14, -15, 52, 51, -16, -17, 54, -18, -19,
@ -173,7 +163,7 @@ public final class StringUtils {
boolean wasSpace = true;
for (int i = 0; i < name.length(); i++) {
if (wasSpace) {
newName.append((new String() + name.charAt(i)).toUpperCase());
newName.append(("" + name.charAt(i)).toUpperCase());
wasSpace = false;
} else {
newName.append(name.charAt(i));
@ -306,9 +296,8 @@ public final class StringUtils {
* @return The string value.
*/
public static String getString(String s) {
String string = s.replaceAll("\\<.*?>", "").replaceAll("&#160;", "")
return s.replaceAll("\\<.*?>", "").replaceAll("&#160;", "")
.replaceAll("Discontinued Item:", "");
return string;
}
/**
* Characters used to convert a String to a Long.
@ -319,7 +308,7 @@ public final class StringUtils {
't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2',
'3', '4', '5', '6', '7', '8', '9'
};
public static int[] anIntArray233 = {
private final static int[] anIntArray233 = {
0, 1024, 2048, 3072, 4096, 5120,
6144, 8192, 9216, 12288, 10240, 11264, 16384, 18432, 17408, 20480,
21504, 22528, 23552, 24576, 25600, 26624, 27648, 28672, 29696,
@ -362,7 +351,7 @@ public final class StringUtils {
301188096, 301189120, 301190144, 301191168, 301193216, 301195264,
301194240, 301197312, 301198336, 301199360, 301201408, 301202432
};
public static byte[] aByteArray235 = {
private final static byte[] aByteArray235 = {
22, 22, 22, 22, 22, 22, 21, 22, 22,
20, 22, 22, 22, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
22, 22, 22, 22, 22, 22, 3, 8, 22, 16, 22, 16, 17, 7, 13, 13, 13,
@ -387,16 +376,16 @@ public final class StringUtils {
try {
i_27_ += i_25_;
int i_29_ = 0;
int i_30_ = i_26_ << -2116795453;
int i_30_ = i_26_ << 3;
for (; i_27_ > i_25_; i_25_++) {
int i_31_ = 0xff & is_28_[i_25_];
int i_32_ = anIntArray233[i_31_];
int i_33_ = aByteArray235[i_31_];
int i_34_ = i_30_ >> -1445887805;
int i_34_ = i_30_ >> 3;
int i_35_ = i_30_ & 0x7;
i_29_ &= (-i_35_ >> 473515839);
i_29_ &= (-i_35_ >> 31);
i_30_ += i_33_;
int i_36_ = ((-1 + (i_35_ - -i_33_)) >> -1430991229) + i_34_;
int i_36_ = ((-1 + (i_35_ - -i_33_)) >> 3) + i_34_;
i_35_ += 24;
is[i_34_] = (byte) (i_29_ = (i_29_ | (i_32_ >>> i_35_)));
if ((i_36_ ^ 0xffffffff) < (i_34_ ^ 0xffffffff)) {

View file

@ -132,6 +132,8 @@ public final class PlayerSession {
ex.printStackTrace();
SQLManager.close(connection);
return false;
} finally {
SQLManager.close(connection);
}
return true;
}
@ -160,6 +162,8 @@ public final class PlayerSession {
} catch (SQLException e) {
e.printStackTrace();
SQLManager.close(connection);
} finally {
SQLManager.close(connection);
}
communication.clear();
}
@ -201,6 +205,8 @@ public final class PlayerSession {
} catch (SQLException e) {
e.printStackTrace();
SQLManager.close(connection);
} finally {
SQLManager.close(connection);
}
}
@ -459,7 +465,9 @@ public final class PlayerSession {
@Override
public boolean equals(Object o) {
if(o instanceof PlayerSession) {
return username.equals(((PlayerSession) o).username);
} else return false;
}
@Override

View file

@ -19,7 +19,7 @@ public class WorldDatabase {
/**
* The game servers.
*/
public static final GameServer[] DATABASE = new GameServer[ServerConstants.WORLD_LIMIT];
private static final GameServer[] DATABASE = new GameServer[ServerConstants.WORLD_LIMIT];
/**
* The update time stamp.

View file

@ -102,6 +102,8 @@ public class UIDInfo {
case 4:
serial = ByteBufferUtils.getString(buffer);
break;
default:
break;
}
}
}
@ -112,7 +114,7 @@ public class UIDInfo {
* @return the string.
*/
private String parseFormat(String string) {
if (string == null || string == "") {
if (string == null || string.equals("")) {
return null;
}
StringTokenizer token = new StringTokenizer(string, "|");

View file

@ -139,6 +139,7 @@ public class Definition<T extends Node> {
public String getExamine() {
if (examine == null) {
try {
if(handlers.get("examine") != null)
examine = handlers.get("examine").toString();
} catch (Exception e){
e.printStackTrace();

View file

@ -57,10 +57,8 @@ public final class NPCDefinition extends Definition<NPC> {
*/
public boolean isVisibleOnMap;
/* *//**
* The examine option value
*//*
public String examine;*/
public String examine;
/**
* The drop tables.

View file

@ -6,7 +6,6 @@ import core.cache.misc.buffer.ByteBufferUtils;
import core.game.interaction.OptionHandler;
import core.game.node.entity.player.Player;
import core.game.node.object.Scenery;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import rs09.game.system.SystemLogger;
import rs09.game.world.GameWorld;

View file

@ -358,7 +358,7 @@ object RegionManager {
val region = forId(regionId)
Region.load(region)
val `object`: Scenery? = region.planes[z].getChunkObject(x, y, objectId)
return if (`object` != null && !`object`.isRenderable()) {
return if (`object` != null && !`object`.isRenderable) {
null
} else `object`
}