Fix rather serious bug from moving the location the GameSession was set.

This commit is contained in:
Major-
2015-02-27 03:00:08 +00:00
parent 0b6b6ccd03
commit b4cc7aa2bd
3 changed files with 66 additions and 65 deletions
@@ -16,7 +16,7 @@ public final class PlayerDesignMessageHandler extends MessageHandler<PlayerDesig
@Override @Override
public void handle(MessageHandlerContext ctx, Player player, PlayerDesignMessage message) { public void handle(MessageHandlerContext ctx, Player player, PlayerDesignMessage message) {
player.setAppearance(message.getAppearance()); player.setAppearance(message.getAppearance());
player.setNew(true); player.setNew(false);
player.send(new CloseInterfaceMessage()); player.send(new CloseInterfaceMessage());
} }
+59 -63
View File
@@ -83,21 +83,6 @@ public final class Player extends Mob {
*/ */
private PlayerCredentials credentials; private PlayerCredentials credentials;
@Override
public int hashCode() {
return credentials.hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Player) {
Player other = (Player) obj;
return credentials.equals(other.credentials);
}
return false;
}
/** /**
* A flag which indicates there are npcs that couldn't be added. * A flag which indicates there are npcs that couldn't be added.
*/ */
@@ -168,11 +153,6 @@ public final class Player extends Mob {
*/ */
private final transient Deque<Message> queuedMessages = new ArrayDeque<>(); private final transient Deque<Message> queuedMessages = new ArrayDeque<>();
/**
* A flag indicating if the sector changed in the last cycle.
*/
private transient boolean sectorChanged = false;
/** /**
* The player's run energy. * The player's run energy.
*/ */
@@ -188,6 +168,11 @@ public final class Player extends Mob {
*/ */
private ScreenBrightness screenBrightness = ScreenBrightness.NORMAL; private ScreenBrightness screenBrightness = ScreenBrightness.NORMAL;
/**
* A flag indicating if the sector changed in the last cycle.
*/
private transient boolean sectorChanged = false;
/** /**
* The {@link GameSession} currently attached to this {@link Player}. * The {@link GameSession} currently attached to this {@link Player}.
*/ */
@@ -263,6 +248,16 @@ public final class Player extends Mob {
} }
} }
@Override
public boolean equals(Object obj) {
if (obj instanceof Player) {
Player other = (Player) obj;
return credentials.equals(other.credentials);
}
return false;
}
/** /**
* Sets the excessive npcs flag. * Sets the excessive npcs flag.
*/ */
@@ -355,11 +350,6 @@ public final class Player extends Mob {
return EntityType.PLAYER; return EntityType.PLAYER;
} }
@Override
public int getInteractionIndex() {
return getIndex() | 0x8000;
}
/** /**
* Gets this player's friend chat {@link PrivacyState}. * Gets this player's friend chat {@link PrivacyState}.
* *
@@ -387,6 +377,11 @@ public final class Player extends Mob {
return ignores; return ignores;
} }
@Override
public int getInteractionIndex() {
return getIndex() | 0x8000;
}
/** /**
* Gets this player's interface set. * Gets this player's interface set.
* *
@@ -495,6 +490,11 @@ public final class Player extends Mob {
return worldId; return worldId;
} }
@Override
public int hashCode() {
return credentials.hashCode();
}
/** /**
* Indicates whether or not the player with the specified username is on this player's ignore list. * Indicates whether or not the player with the specified username is on this player's ignore list.
* *
@@ -680,6 +680,30 @@ public final class Player extends Mob {
} }
} }
/**
* Sends the initial messages.
*/
public void sendInitialMessages() {
blockSet.add(SynchronizationBlock.createAppearanceBlock(this));
send(new IdAssignmentMessage(index, members)); // TODO should this be sent when we reconnect?
sendMessage("Welcome to RuneScape.");
if (newPlayer) {
interfaceSet.openWindow(InterfaceConstants.AVATAR_DESIGN);
}
int[] tabs = InterfaceConstants.DEFAULT_INVENTORY_TABS;
for (int tab = 0; tab < tabs.length; tab++) {
send(new SwitchTabInterfaceMessage(tab, tabs[tab]));
}
inventory.forceRefresh();
equipment.forceRefresh();
bank.forceRefresh();
skillSet.forceRefresh();
World.getWorld().getLoginDispatcher().dispatch(this);
}
/** /**
* Sends a message to the player. * Sends a message to the player.
* *
@@ -833,15 +857,6 @@ public final class Player extends Mob {
this.privilegeLevel = privilegeLevel; this.privilegeLevel = privilegeLevel;
} }
/**
* Sets the sector changed flag.
*
* @param sectorChanged A flag indicating if the sector has changed.
*/
public void setSectorChanged(boolean sectorChanged) {
this.sectorChanged = sectorChanged;
}
/** /**
* Sets the player's run energy. TODO make this an attribute? * Sets the player's run energy. TODO make this an attribute?
* *
@@ -861,18 +876,22 @@ public final class Player extends Mob {
this.screenBrightness = brightness; this.screenBrightness = brightness;
} }
/**
* Sets the sector changed flag.
*
* @param sectorChanged A flag indicating if the sector has changed.
*/
public void setSectorChanged(boolean sectorChanged) {
this.sectorChanged = sectorChanged;
}
/** /**
* Sets the player's {@link GameSession}. * Sets the player's {@link GameSession}.
* *
* @param session The player's {@link GameSession}. * @param session The player's {@link GameSession}.
* @param reconnecting The reconnecting flag.
*/ */
public void setSession(GameSession session, boolean reconnecting) { public void setSession(GameSession session) {
this.session = session; this.session = session;
if (!reconnecting) {
sendInitialMessages();
}
blockSet.add(SynchronizationBlock.createAppearanceBlock(this));
} }
/** /**
@@ -982,27 +1001,4 @@ public final class Player extends Mob {
skillSet.addListener(new LevelUpSkillListener(this)); skillSet.addListener(new LevelUpSkillListener(this));
} }
/**
* Sends the initial messages.
*/
private void sendInitialMessages() {
send(new IdAssignmentMessage(index, members)); // TODO should this be sent when we reconnect?
sendMessage("Welcome to RuneScape.");
if (!newPlayer) {
interfaceSet.openWindow(InterfaceConstants.AVATAR_DESIGN);
}
int[] tabs = InterfaceConstants.DEFAULT_INVENTORY_TABS;
for (int tab = 0; tab < tabs.length; tab++) {
send(new SwitchTabInterfaceMessage(tab, tabs[tab]));
}
inventory.forceRefresh();
equipment.forceRefresh();
bank.forceRefresh();
skillSet.forceRefresh();
World.getWorld().getLoginDispatcher().dispatch(this);
}
} }
+6 -1
View File
@@ -97,7 +97,7 @@ public final class LoginSession extends Session {
rights = player.getPrivilegeLevel().toInteger(); rights = player.getPrivilegeLevel().toInteger();
GameSession session = new GameSession(channel, serverContext, player); GameSession session = new GameSession(channel, serverContext, player);
RegistrationStatus registration = service.registerPlayer(player, session, request.isReconnecting()); RegistrationStatus registration = service.registerPlayer(player, session);
if (registration != RegistrationStatus.OK) { if (registration != RegistrationStatus.OK) {
optional = Optional.empty(); optional = Optional.empty();
@@ -109,6 +109,7 @@ public final class LoginSession extends Session {
} }
ChannelFuture future = channel.writeAndFlush(new LoginResponse(status, rights, flagged)); ChannelFuture future = channel.writeAndFlush(new LoginResponse(status, rights, flagged));
destroy(); destroy();
if (optional.isPresent()) { if (optional.isPresent()) {
@@ -129,6 +130,10 @@ public final class LoginSession extends Session {
} else { } else {
future.addListener(ChannelFutureListener.CLOSE); future.addListener(ChannelFutureListener.CLOSE);
} }
if (optional.isPresent()) {
optional.get().sendInitialMessages();
}
} }
@Override @Override