Fixed many non-critical exceptions

Fixed an issue that could result in server hang
Added a new command ::npcsearch for searching for NPC IDs
This commit is contained in:
Ceikry
2023-02-18 01:37:30 +00:00
committed by Ryan
parent d75e40b98c
commit cecd6f1947
11 changed files with 60 additions and 25 deletions
@@ -194,6 +194,8 @@ public abstract class MovementPulse extends Pulse {
Location ml = mover.getLocation();
// Allow being within 1 square of moving entities to interact with them.
int radius = destination instanceof Entity && ((Entity)destination).getWalkingQueue().hasPath() ? 1 : 0;
if (interactLocation == null)
return false;
if (Math.max(Math.abs(ml.getX() - interactLocation.getX()), Math.abs(ml.getY() - interactLocation.getY())) <= radius) {
try {
if (near || pulse()) {
@@ -8,6 +8,7 @@ import core.game.world.map.Direction;
import core.game.world.map.Location;
import core.game.world.map.Point;
import core.game.world.map.RegionManager;
import core.tools.SystemLogger;
import java.util.Deque;
import java.util.LinkedList;
@@ -374,7 +375,7 @@ public final class WalkingQueue {
Location loc = entity.getLocation();
if (loc == null) {
throw new IllegalStateException(
SystemLogger.logErr(this.getClass(),
"The entity location provided was null."
+ "Are you sure anything down the stack trace isn't providing an NPC with a null location?"
);
@@ -1,7 +1,7 @@
package core.game.system.command.sets
import content.global.activity.jobs.JobManager
import core.api.removeAttribute
import content.global.skill.slayer.Master
import core.api.sendMessage
import core.cache.Cache
import core.cache.def.impl.DataMap
@@ -179,5 +179,23 @@ class DevelopmentCommandSet : CommandSet(Privilege.ADMIN) {
define("testpacket") { player, _ ->
PacketWriteQueue.write(ResetInterface(), PlayerContext(player))
}
define("npcsearch", Privilege.STANDARD, "npcsearch name", "Searches for NPCs that match the name either in main or children.") {player, strings ->
val name = strings.slice(1 until strings.size).joinToString(" ").lowercase()
for (id in 0 until 9000) {
val def = NPCDefinition.forId(id)
if (def.name.isNotBlank() && (def.name.lowercase().contains(name) || name.contains(def.name.lowercase()))) {
notify(player, "$id - ${def.name}")
}
else {
for ((childId,index) in def.childNPCIds?.withIndex() ?: continue) {
val childDef = NPCDefinition.forId(childId)
if (childDef.name.lowercase().contains(name) || name.contains(childDef.name.lowercase())) {
notify(player, "$childId child($id) index $index - ${childDef.name}")
}
}
}
}
}
}
}
+1 -1
View File
@@ -68,7 +68,7 @@ public class IoEventHandler {
return;
}
} catch (IOException e) {
if (e.getMessage().contains("reset by peer")) {
if (e.getMessage().contains("reset by peer") && session != null) {
session.disconnect();
if (session.getPlayer() != null)
session.getPlayer().clear(true);
@@ -15,23 +15,28 @@ import java.nio.ByteBuffer
*/
class LoginReadEvent(session: IoSession?, buffer: ByteBuffer?) : IoReadEvent(session, buffer) {
override fun read(session: IoSession, buffer: ByteBuffer) {
val (response, info) = Login.decodeFromBuffer(buffer)
if(response != AuthResponse.Success || info == null) {
session.write(response)
return
}
val (authResponse, accountInfo) = GameWorld.authenticator.checkLogin(info.username, info.password)
try {
val (response, info) = Login.decodeFromBuffer(buffer)
if (response != AuthResponse.Success || info == null) {
session.write(response)
return
}
val (authResponse, accountInfo) = GameWorld.authenticator.checkLogin(info.username, info.password)
if(authResponse != AuthResponse.Success || accountInfo == null) {
session.write(authResponse)
return
if (authResponse != AuthResponse.Success || accountInfo == null) {
session.write(authResponse)
return
}
val details = PlayerDetails(info.username)
details.accountInfo = accountInfo
details.communication.parse(accountInfo)
session.clientInfo = ClientInfo(info.displayMode, info.windowMode, info.screenWidth, info.screenHeight)
session.isaacPair = info.isaacPair
session.associatedUsername = info.username
Login.proceedWith(session, details, info.opcode)
} catch (e: Exception) {
e.printStackTrace()
session.write(AuthResponse.UnexpectedError)
}
val details = PlayerDetails(info.username)
details.accountInfo = accountInfo
details.communication.parse(accountInfo)
session.clientInfo = ClientInfo(info.displayMode, info.windowMode, info.screenWidth, info.screenHeight)
session.isaacPair = info.isaacPair
session.associatedUsername = info.username
Login.proceedWith(session, details, info.opcode)
}
}