Turnabout on Character stats concurrency + Null remote IP patch
Cleared the concurrency conflicts that started occuring after the abstract character's listener code was set to run on new thread, potentally leading to several onStatChange mishaps. Added a check for remoteHost being possibly null when opening a new session with the client.
This commit is contained in:
@@ -213,36 +213,15 @@ public abstract class AbstractMapleCharacterObject extends AbstractAnimatedMaple
|
||||
}
|
||||
|
||||
private void dispatchHpChanged(final int oldHp) {
|
||||
Runnable r = new Runnable() { // thanks BHB (BHB88) for detecting a deadlock case within player stats.
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onHpChanged(oldHp);
|
||||
}
|
||||
};
|
||||
|
||||
map.registerCharacterStatUpdate(r);
|
||||
listener.onHpChanged(oldHp);
|
||||
}
|
||||
|
||||
private void dispatchHpmpPoolUpdated() {
|
||||
Runnable r = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onHpmpPoolUpdate();
|
||||
}
|
||||
};
|
||||
|
||||
map.registerCharacterStatUpdate(r);
|
||||
listener.onHpmpPoolUpdate();
|
||||
}
|
||||
|
||||
private void dispatchStatPoolUpdateAnnounced() {
|
||||
Runnable r = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onAnnounceStatPoolUpdate();
|
||||
}
|
||||
};
|
||||
|
||||
map.registerCharacterStatUpdate(r);
|
||||
listener.onAnnounceStatPoolUpdate();
|
||||
}
|
||||
|
||||
protected void setHp(int newHp) {
|
||||
|
||||
@@ -8590,14 +8590,22 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final boolean chrDied = playerDied;
|
||||
Runnable r = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updatePartyMemberHP(); // thanks BHB (BHB88) for detecting a deadlock case within player stats.
|
||||
|
||||
updatePartyMemberHP();
|
||||
|
||||
if (playerDied) {
|
||||
playerDead();
|
||||
} else {
|
||||
checkBerserk(isHidden());
|
||||
}
|
||||
if (chrDied) {
|
||||
playerDead();
|
||||
} else {
|
||||
checkBerserk(isHidden());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
map.registerCharacterStatUpdate(r);
|
||||
}
|
||||
|
||||
private Pair<MapleStat, Integer> calcHpRatioUpdate(int newHp, int oldHp) {
|
||||
|
||||
@@ -106,7 +106,18 @@ public class MapleServerHandler extends IoHandlerAdapter {
|
||||
|
||||
@Override
|
||||
public void sessionOpened(IoSession session) {
|
||||
session.setAttribute(MapleClient.CLIENT_REMOTE_ADDRESS, ((InetSocketAddress) session.getRemoteAddress()).getAddress().getHostAddress());
|
||||
String remoteHost;
|
||||
try {
|
||||
remoteHost = ((InetSocketAddress) session.getRemoteAddress()).getAddress().getHostAddress();
|
||||
|
||||
if (remoteHost == null) {
|
||||
remoteHost = "null";
|
||||
}
|
||||
} catch (NullPointerException npe) { // thanks Agassy, Alchemist for pointing out possibility of remoteHost = null.
|
||||
remoteHost = "null";
|
||||
}
|
||||
|
||||
session.setAttribute(MapleClient.CLIENT_REMOTE_ADDRESS, remoteHost);
|
||||
|
||||
if (!Server.getInstance().isOnline()) {
|
||||
MapleSessionCoordinator.getInstance().closeSession(session, true);
|
||||
|
||||
@@ -63,16 +63,21 @@ public final class LoginPasswordHandler implements MaplePacketHandler {
|
||||
@Override
|
||||
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
|
||||
String remoteHost = getRemoteIp(c.getSession());
|
||||
if (remoteHost.startsWith("127.")) {
|
||||
if (!ServerConstants.LOCALSERVER) { // thanks Mills for noting HOST can also have a field named "localhost"
|
||||
c.announce(MaplePacketCreator.getLoginFailed(13)); // cannot login as localhost if it's not a local server
|
||||
return;
|
||||
if (!remoteHost.contentEquals("null")) {
|
||||
if (remoteHost.startsWith("127.")) {
|
||||
if (!ServerConstants.LOCALSERVER) { // thanks Mills for noting HOST can also have a field named "localhost"
|
||||
c.announce(MaplePacketCreator.getLoginFailed(13)); // cannot login as localhost if it's not a local server
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (ServerConstants.LOCALSERVER) {
|
||||
c.announce(MaplePacketCreator.getLoginFailed(13)); // cannot login as non-localhost if it's a local server
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (ServerConstants.LOCALSERVER) {
|
||||
c.announce(MaplePacketCreator.getLoginFailed(13)); // cannot login as non-localhost if it's a local server
|
||||
return;
|
||||
}
|
||||
c.announce(MaplePacketCreator.getLoginFailed(14)); // thanks Alchemist for noting remoteHost could be null
|
||||
return;
|
||||
}
|
||||
|
||||
String login = slea.readMapleAsciiString();
|
||||
|
||||
Reference in New Issue
Block a user