Minor renaming and refactoring
This commit is contained in:
@@ -38,6 +38,8 @@ import net.server.audit.locks.MonitoredLockType;
|
|||||||
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
|
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
|
||||||
import net.server.channel.Channel;
|
import net.server.channel.Channel;
|
||||||
import net.server.coordinator.login.MapleLoginBypassCoordinator;
|
import net.server.coordinator.login.MapleLoginBypassCoordinator;
|
||||||
|
import net.server.coordinator.session.Hwid;
|
||||||
|
import net.server.coordinator.session.IpAddresses;
|
||||||
import net.server.coordinator.session.MapleSessionCoordinator;
|
import net.server.coordinator.session.MapleSessionCoordinator;
|
||||||
import net.server.coordinator.session.MapleSessionCoordinator.AntiMulticlientResult;
|
import net.server.coordinator.session.MapleSessionCoordinator.AntiMulticlientResult;
|
||||||
import net.server.guild.MapleGuild;
|
import net.server.guild.MapleGuild;
|
||||||
@@ -157,24 +159,32 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelActive(ChannelHandlerContext ctx) {
|
public void channelActive(ChannelHandlerContext ctx) {
|
||||||
|
final io.netty.channel.Channel channel = ctx.channel();
|
||||||
if (!Server.getInstance().isOnline()) {
|
if (!Server.getInstance().isOnline()) {
|
||||||
ctx.channel().close();
|
channel.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String hostAddress = "null";
|
this.remoteAddress = getRemoteAddress(channel);
|
||||||
|
this.ioChannel = channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getRemoteAddress(io.netty.channel.Channel channel) {
|
||||||
|
String remoteAddress = "null";
|
||||||
try {
|
try {
|
||||||
hostAddress = ((InetSocketAddress) ctx.channel().remoteAddress()).getAddress().getHostAddress();
|
String hostAddress = ((InetSocketAddress) channel.remoteAddress()).getAddress().getHostAddress();
|
||||||
|
if (hostAddress != null) {
|
||||||
|
remoteAddress = IpAddresses.evaluateRemoteAddress(hostAddress); // thanks dyz for noticing Local/LAN/WAN connections not interacting properly
|
||||||
|
}
|
||||||
} catch (NullPointerException npe) {
|
} catch (NullPointerException npe) {
|
||||||
log.warn("Unable to get remote address for client", npe);
|
log.warn("Unable to get remote address for client", npe);
|
||||||
}
|
}
|
||||||
this.remoteAddress = hostAddress;
|
|
||||||
this.ioChannel = ctx.channel();
|
return remoteAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||||
// InPacket packet = new ByteBufInPacket((ByteBuf) msg);
|
|
||||||
if (!(msg instanceof InPacket packet)) {
|
if (!(msg instanceof InPacket packet)) {
|
||||||
log.warn("Received invalid message: {}", msg);
|
log.warn("Received invalid message: {}", msg);
|
||||||
return;
|
return;
|
||||||
@@ -799,17 +809,17 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
|||||||
return accId;
|
return accId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateLoginState(int newstate) {
|
public void updateLoginState(int newState) {
|
||||||
// rules out possibility of multiple account entries
|
// rules out possibility of multiple account entries
|
||||||
if (newstate == LOGIN_LOGGEDIN) {
|
if (newState == LOGIN_LOGGEDIN) {
|
||||||
MapleSessionCoordinator.getInstance().updateOnlineSession(this.getSession());
|
MapleSessionCoordinator.getInstance().updateOnlineClient(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
try (Connection con = DatabaseConnection.getConnection();
|
try (Connection con = DatabaseConnection.getConnection();
|
||||||
PreparedStatement ps = con.prepareStatement("UPDATE accounts SET loggedin = ?, lastlogin = ? WHERE id = ?")) {
|
PreparedStatement ps = con.prepareStatement("UPDATE accounts SET loggedin = ?, lastlogin = ? WHERE id = ?")) {
|
||||||
// using sql currenttime here could potentially break the login, thanks Arnah for pointing this out
|
// using sql currenttime here could potentially break the login, thanks Arnah for pointing this out
|
||||||
|
|
||||||
ps.setInt(1, newstate);
|
ps.setInt(1, newState);
|
||||||
ps.setTimestamp(2, new java.sql.Timestamp(Server.getInstance().getCurrentTime()));
|
ps.setTimestamp(2, new java.sql.Timestamp(Server.getInstance().getCurrentTime()));
|
||||||
ps.setInt(3, getAccID());
|
ps.setInt(3, getAccID());
|
||||||
ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
@@ -817,12 +827,12 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newstate == LOGIN_NOTLOGGEDIN) {
|
if (newState == LOGIN_NOTLOGGEDIN) {
|
||||||
loggedIn = false;
|
loggedIn = false;
|
||||||
serverTransition = false;
|
serverTransition = false;
|
||||||
setAccID(0);
|
setAccID(0);
|
||||||
} else {
|
} else {
|
||||||
serverTransition = (newstate == LOGIN_SERVER_TRANSITION);
|
serverTransition = (newState == LOGIN_SERVER_TRANSITION);
|
||||||
loggedIn = !serverTransition;
|
loggedIn = !serverTransition;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1165,7 +1175,7 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
|||||||
try {
|
try {
|
||||||
if (lastPong < pingedAt) {
|
if (lastPong < pingedAt) {
|
||||||
if (ioChannel.isActive()) {
|
if (ioChannel.isActive()) {
|
||||||
log.info("Disconnected {} due to being idle. Cause: {}", remoteAddress, event.state());
|
log.info("Disconnected {} due to idling. Reason: {}", remoteAddress, event.state());
|
||||||
updateLoginState(MapleClient.LOGIN_NOTLOGGEDIN);
|
updateLoginState(MapleClient.LOGIN_NOTLOGGEDIN);
|
||||||
disconnectSession();
|
disconnectSession();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public final class PacketProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static PacketProcessor getLoginServerProcessor() {
|
public static PacketProcessor getLoginServerProcessor() {
|
||||||
return getProcessor(LoginServer.WORLD, LoginServer.CHANNEL);
|
return getProcessor(LoginServer.WORLD_ID, LoginServer.CHANNEL_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PacketProcessor getChannelServerProcessor(int world, int channel) {
|
public static PacketProcessor getChannelServerProcessor(int world, int channel) {
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import io.netty.channel.nio.NioEventLoopGroup;
|
|||||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||||
|
|
||||||
public class LoginServer extends AbstractServer {
|
public class LoginServer extends AbstractServer {
|
||||||
public static final int WORLD = -1;
|
public static final int WORLD_ID = -1;
|
||||||
public static final int CHANNEL = -1;
|
public static final int CHANNEL_ID = -1;
|
||||||
private Channel channel;
|
private Channel channel;
|
||||||
|
|
||||||
public LoginServer(int port) {
|
public LoginServer(int port) {
|
||||||
|
|||||||
@@ -16,7 +16,16 @@ public abstract class ServerChannelInitializer extends ChannelInitializer<Socket
|
|||||||
void initPipeline(SocketChannel socketChannel, MapleClient client) {
|
void initPipeline(SocketChannel socketChannel, MapleClient client) {
|
||||||
final InitializationVector sendIv = InitializationVector.generateSend();
|
final InitializationVector sendIv = InitializationVector.generateSend();
|
||||||
final InitializationVector recvIv = InitializationVector.generateReceive();
|
final InitializationVector recvIv = InitializationVector.generateReceive();
|
||||||
|
writeInitialUnencryptedHelloPacket(socketChannel, sendIv, recvIv);
|
||||||
|
setUpHandlers(socketChannel, sendIv, recvIv, client);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeInitialUnencryptedHelloPacket(SocketChannel socketChannel, InitializationVector sendIv, InitializationVector recvIv) {
|
||||||
socketChannel.writeAndFlush(Unpooled.wrappedBuffer(MaplePacketCreator.getHello(ServerConstants.VERSION, sendIv, recvIv)));
|
socketChannel.writeAndFlush(Unpooled.wrappedBuffer(MaplePacketCreator.getHello(ServerConstants.VERSION, sendIv, recvIv)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setUpHandlers(SocketChannel socketChannel, InitializationVector sendIv, InitializationVector recvIv,
|
||||||
|
MapleClient client) {
|
||||||
socketChannel.pipeline().addFirst("IdleStateHandler", new IdleStateHandler(30, 30, 0));
|
socketChannel.pipeline().addFirst("IdleStateHandler", new IdleStateHandler(30, 30, 0));
|
||||||
socketChannel.pipeline().addLast("PacketCodec", new PacketCodec(ClientCyphers.of(sendIv, recvIv)));
|
socketChannel.pipeline().addLast("PacketCodec", new PacketCodec(ClientCyphers.of(sendIv, recvIv)));
|
||||||
socketChannel.pipeline().addLast("MapleClient", client);
|
socketChannel.pipeline().addLast("MapleClient", client);
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
|
public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
|
||||||
|
|
||||||
private static Set<Integer> attemptingLoginAccounts = new HashSet<>();
|
private static final Set<Integer> attemptingLoginAccounts = new HashSet<>();
|
||||||
|
|
||||||
private boolean tryAcquireAccount(int accId) {
|
private boolean tryAcquireAccount(int accId) {
|
||||||
synchronized (attemptingLoginAccounts) {
|
synchronized (attemptingLoginAccounts) {
|
||||||
@@ -85,70 +85,76 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
|
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
|
||||||
final int cid = slea.readInt();
|
final int cid = slea.readInt(); // TODO: investigate if this is the "client id" supplied in MaplePacketCreator#getServerIP()
|
||||||
final Server server = Server.getInstance();
|
final Server server = Server.getInstance();
|
||||||
|
|
||||||
if (c.tryacquireClient()) { // thanks MedicOP for assisting on concurrency protection here
|
if (!c.tryacquireClient()) {
|
||||||
try {
|
// thanks MedicOP for assisting on concurrency protection here
|
||||||
World wserv = server.getWorld(c.getWorld());
|
c.announce(MaplePacketCreator.getAfterLoginError(10));
|
||||||
if(wserv == null) {
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
World wserv = server.getWorld(c.getWorld());
|
||||||
|
if (wserv == null) {
|
||||||
|
c.disconnect(true, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Channel cserv = wserv.getChannel(c.getChannel());
|
||||||
|
if (cserv == null) {
|
||||||
|
c.setChannel(1);
|
||||||
|
cserv = wserv.getChannel(c.getChannel());
|
||||||
|
|
||||||
|
if (cserv == null) {
|
||||||
c.disconnect(true, false);
|
c.disconnect(true, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Channel cserv = wserv.getChannel(c.getChannel());
|
MapleCharacter player = wserv.getPlayerStorage().getCharacterById(cid);
|
||||||
if(cserv == null) {
|
IoSession session = c.getSession();
|
||||||
c.setChannel(1);
|
|
||||||
cserv = wserv.getChannel(c.getChannel());
|
|
||||||
|
|
||||||
if(cserv == null) {
|
String remoteHwid;
|
||||||
c.disconnect(true, false);
|
if (player == null) {
|
||||||
return;
|
remoteHwid = MapleSessionCoordinator.getInstance().pickLoginSessionHwid(session);
|
||||||
}
|
if (remoteHwid == null) {
|
||||||
}
|
|
||||||
|
|
||||||
MapleCharacter player = wserv.getPlayerStorage().getCharacterById(cid);
|
|
||||||
IoSession session = c.getSession();
|
|
||||||
|
|
||||||
String remoteHwid;
|
|
||||||
if (player == null) {
|
|
||||||
remoteHwid = MapleSessionCoordinator.getInstance().pickLoginSessionHwid(session);
|
|
||||||
if (remoteHwid == null) {
|
|
||||||
c.disconnect(true, false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
remoteHwid = player.getClient().getHWID();
|
|
||||||
}
|
|
||||||
|
|
||||||
int hwidLen = remoteHwid.length();
|
|
||||||
session.setAttribute(MapleClient.CLIENT_HWID, remoteHwid);
|
|
||||||
session.setAttribute(MapleClient.CLIENT_NIBBLEHWID, remoteHwid.substring(hwidLen - 8, hwidLen));
|
|
||||||
c.setHWID(remoteHwid);
|
|
||||||
|
|
||||||
if (!server.validateCharacteridInTransition(c, cid)) {
|
|
||||||
c.disconnect(true, false);
|
c.disconnect(true, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
boolean newcomer = false;
|
Hwid clientHwid = player.getClient().getHwid();
|
||||||
if (player == null) {
|
remoteHwid = clientHwid == null ? null : clientHwid.hwid();
|
||||||
try {
|
}
|
||||||
player = MapleCharacter.loadCharFromDB(cid, c, true);
|
|
||||||
newcomer = true;
|
int hwidLen = remoteHwid.length();
|
||||||
} catch (SQLException e) {
|
session.setAttribute(MapleClient.CLIENT_HWID, remoteHwid);
|
||||||
e.printStackTrace();
|
String nibbleHwid = remoteHwid.substring(hwidLen - 8, hwidLen);
|
||||||
}
|
session.setAttribute(MapleClient.CLIENT_NIBBLEHWID, nibbleHwid);
|
||||||
|
c.setHwid(new Hwid(remoteHwid));
|
||||||
if (player == null) { //If you are still getting null here then please just uninstall the game >.>, we dont need you fucking with the logs
|
|
||||||
c.disconnect(true, false);
|
if (!server.validateCharacteridInTransition(c, cid)) {
|
||||||
return;
|
c.disconnect(true, false);
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean newcomer = false;
|
||||||
|
if (player == null) {
|
||||||
|
try {
|
||||||
|
player = MapleCharacter.loadCharFromDB(cid, c, true);
|
||||||
|
newcomer = true;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
c.setPlayer(player);
|
|
||||||
c.setAccID(player.getAccountID());
|
if (player == null) { //If you are still getting null here then please just uninstall the game >.>, we dont need you fucking with the logs
|
||||||
|
c.disconnect(true, false);
|
||||||
boolean allowLogin = true;
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.setPlayer(player);
|
||||||
|
c.setAccID(player.getAccountID());
|
||||||
|
|
||||||
|
boolean allowLogin = true;
|
||||||
|
|
||||||
/* is this check really necessary?
|
/* is this check really necessary?
|
||||||
if (state == MapleClient.LOGIN_SERVER_TRANSITION || state == MapleClient.LOGIN_NOTLOGGEDIN) {
|
if (state == MapleClient.LOGIN_SERVER_TRANSITION || state == MapleClient.LOGIN_NOTLOGGEDIN) {
|
||||||
@@ -165,276 +171,274 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int accId = c.getAccID();
|
|
||||||
if (tryAcquireAccount(accId)) { // Sync this to prevent wrong login state for double loggedin handling
|
|
||||||
try {
|
|
||||||
int state = c.getLoginState();
|
|
||||||
if (state != MapleClient.LOGIN_SERVER_TRANSITION || !allowLogin) {
|
|
||||||
c.setPlayer(null);
|
|
||||||
c.setAccID(0);
|
|
||||||
|
|
||||||
if (state == MapleClient.LOGIN_LOGGEDIN) {
|
int accId = c.getAccID();
|
||||||
c.disconnect(true, false);
|
if (tryAcquireAccount(accId)) { // Sync this to prevent wrong login state for double loggedin handling
|
||||||
} else {
|
try {
|
||||||
c.announce(MaplePacketCreator.getAfterLoginError(7));
|
int state = c.getLoginState();
|
||||||
}
|
if (state != MapleClient.LOGIN_SERVER_TRANSITION || !allowLogin) {
|
||||||
|
c.setPlayer(null);
|
||||||
|
c.setAccID(0);
|
||||||
|
|
||||||
return;
|
if (state == MapleClient.LOGIN_LOGGEDIN) {
|
||||||
}
|
c.disconnect(true, false);
|
||||||
c.updateLoginState(MapleClient.LOGIN_LOGGEDIN);
|
|
||||||
} finally {
|
|
||||||
releaseAccount(accId);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
c.setPlayer(null);
|
|
||||||
c.setAccID(0);
|
|
||||||
c.announce(MaplePacketCreator.getAfterLoginError(10));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!newcomer) {
|
|
||||||
c.setLanguage(player.getClient().getLanguage());
|
|
||||||
c.setCharacterSlots((byte) player.getClient().getCharacterSlots());
|
|
||||||
player.newClient(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
cserv.addPlayer(player);
|
|
||||||
wserv.addPlayer(player);
|
|
||||||
player.setEnteredChannelWorld();
|
|
||||||
|
|
||||||
List<PlayerBuffValueHolder> buffs = server.getPlayerBuffStorage().getBuffsFromStorage(cid);
|
|
||||||
if (buffs != null) {
|
|
||||||
List<Pair<Long, PlayerBuffValueHolder>> timedBuffs = getLocalStartTimes(buffs);
|
|
||||||
player.silentGiveBuffs(timedBuffs);
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<MapleDisease, Pair<Long, MobSkill>> diseases = server.getPlayerBuffStorage().getDiseasesFromStorage(cid);
|
|
||||||
if (diseases != null) {
|
|
||||||
player.silentApplyDiseases(diseases);
|
|
||||||
}
|
|
||||||
|
|
||||||
c.announce(MaplePacketCreator.getCharInfo(player));
|
|
||||||
if (!player.isHidden()) {
|
|
||||||
if(player.isGM() && YamlConfig.config.server.USE_AUTOHIDE_GM) {
|
|
||||||
player.toggleHide(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
player.sendKeymap();
|
|
||||||
player.sendQuickmap();
|
|
||||||
player.sendMacros();
|
|
||||||
|
|
||||||
// pot bindings being passed through other characters on the account detected thanks to Croosade dev team
|
|
||||||
MapleKeyBinding autohpPot = player.getKeymap().get(91);
|
|
||||||
player.announce(MaplePacketCreator.sendAutoHpPot(autohpPot != null ? autohpPot.getAction() : 0));
|
|
||||||
|
|
||||||
MapleKeyBinding autompPot = player.getKeymap().get(92);
|
|
||||||
player.announce(MaplePacketCreator.sendAutoMpPot(autompPot != null ? autompPot.getAction() : 0));
|
|
||||||
|
|
||||||
player.getMap().addPlayer(player);
|
|
||||||
player.visitMap(player.getMap());
|
|
||||||
|
|
||||||
BuddyList bl = player.getBuddylist();
|
|
||||||
int[] buddyIds = bl.getBuddyIds();
|
|
||||||
wserv.loggedOn(player.getName(), player.getId(), c.getChannel(), buddyIds);
|
|
||||||
for (CharacterIdChannelPair onlineBuddy : wserv.multiBuddyFind(player.getId(), buddyIds)) {
|
|
||||||
BuddylistEntry ble = bl.get(onlineBuddy.getCharacterId());
|
|
||||||
ble.setChannel(onlineBuddy.getChannel());
|
|
||||||
bl.put(ble);
|
|
||||||
}
|
|
||||||
c.announce(MaplePacketCreator.updateBuddylist(bl.getBuddies()));
|
|
||||||
|
|
||||||
c.announce(MaplePacketCreator.loadFamily(player));
|
|
||||||
if (player.getFamilyId() > 0) {
|
|
||||||
MapleFamily f = wserv.getFamily(player.getFamilyId());
|
|
||||||
if(f != null) {
|
|
||||||
MapleFamilyEntry familyEntry = f.getEntryByID(player.getId());
|
|
||||||
if(familyEntry != null) {
|
|
||||||
familyEntry.setCharacter(player);
|
|
||||||
player.setFamilyEntry(familyEntry);
|
|
||||||
|
|
||||||
c.announce(MaplePacketCreator.getFamilyInfo(familyEntry));
|
|
||||||
familyEntry.announceToSenior(MaplePacketCreator.sendFamilyLoginNotice(player.getName(), true), true);
|
|
||||||
} else {
|
} else {
|
||||||
FilePrinter.printError(FilePrinter.FAMILY_ERROR, "Player " + player.getName() + "'s family doesn't have an entry for them. (" + f.getID() + ")");
|
c.announce(MaplePacketCreator.getAfterLoginError(7));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
c.updateLoginState(MapleClient.LOGIN_LOGGEDIN);
|
||||||
|
} finally {
|
||||||
|
releaseAccount(accId);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
c.setPlayer(null);
|
||||||
|
c.setAccID(0);
|
||||||
|
c.announce(MaplePacketCreator.getAfterLoginError(10));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!newcomer) {
|
||||||
|
c.setLanguage(player.getClient().getLanguage());
|
||||||
|
c.setCharacterSlots((byte) player.getClient().getCharacterSlots());
|
||||||
|
player.newClient(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
cserv.addPlayer(player);
|
||||||
|
wserv.addPlayer(player);
|
||||||
|
player.setEnteredChannelWorld();
|
||||||
|
|
||||||
|
List<PlayerBuffValueHolder> buffs = server.getPlayerBuffStorage().getBuffsFromStorage(cid);
|
||||||
|
if (buffs != null) {
|
||||||
|
List<Pair<Long, PlayerBuffValueHolder>> timedBuffs = getLocalStartTimes(buffs);
|
||||||
|
player.silentGiveBuffs(timedBuffs);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<MapleDisease, Pair<Long, MobSkill>> diseases = server.getPlayerBuffStorage().getDiseasesFromStorage(cid);
|
||||||
|
if (diseases != null) {
|
||||||
|
player.silentApplyDiseases(diseases);
|
||||||
|
}
|
||||||
|
|
||||||
|
c.announce(MaplePacketCreator.getCharInfo(player));
|
||||||
|
if (!player.isHidden()) {
|
||||||
|
if (player.isGM() && YamlConfig.config.server.USE_AUTOHIDE_GM) {
|
||||||
|
player.toggleHide(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
player.sendKeymap();
|
||||||
|
player.sendQuickmap();
|
||||||
|
player.sendMacros();
|
||||||
|
|
||||||
|
// pot bindings being passed through other characters on the account detected thanks to Croosade dev team
|
||||||
|
MapleKeyBinding autohpPot = player.getKeymap().get(91);
|
||||||
|
player.announce(MaplePacketCreator.sendAutoHpPot(autohpPot != null ? autohpPot.getAction() : 0));
|
||||||
|
|
||||||
|
MapleKeyBinding autompPot = player.getKeymap().get(92);
|
||||||
|
player.announce(MaplePacketCreator.sendAutoMpPot(autompPot != null ? autompPot.getAction() : 0));
|
||||||
|
|
||||||
|
player.getMap().addPlayer(player);
|
||||||
|
player.visitMap(player.getMap());
|
||||||
|
|
||||||
|
BuddyList bl = player.getBuddylist();
|
||||||
|
int[] buddyIds = bl.getBuddyIds();
|
||||||
|
wserv.loggedOn(player.getName(), player.getId(), c.getChannel(), buddyIds);
|
||||||
|
for (CharacterIdChannelPair onlineBuddy : wserv.multiBuddyFind(player.getId(), buddyIds)) {
|
||||||
|
BuddylistEntry ble = bl.get(onlineBuddy.getCharacterId());
|
||||||
|
ble.setChannel(onlineBuddy.getChannel());
|
||||||
|
bl.put(ble);
|
||||||
|
}
|
||||||
|
c.announce(MaplePacketCreator.updateBuddylist(bl.getBuddies()));
|
||||||
|
|
||||||
|
c.announce(MaplePacketCreator.loadFamily(player));
|
||||||
|
if (player.getFamilyId() > 0) {
|
||||||
|
MapleFamily f = wserv.getFamily(player.getFamilyId());
|
||||||
|
if (f != null) {
|
||||||
|
MapleFamilyEntry familyEntry = f.getEntryByID(player.getId());
|
||||||
|
if (familyEntry != null) {
|
||||||
|
familyEntry.setCharacter(player);
|
||||||
|
player.setFamilyEntry(familyEntry);
|
||||||
|
|
||||||
|
c.announce(MaplePacketCreator.getFamilyInfo(familyEntry));
|
||||||
|
familyEntry.announceToSenior(MaplePacketCreator.sendFamilyLoginNotice(player.getName(), true), true);
|
||||||
} else {
|
} else {
|
||||||
FilePrinter.printError(FilePrinter.FAMILY_ERROR, "Player " + player.getName() + " has an invalid family ID. (" + player.getFamilyId() + ")");
|
FilePrinter.printError(FilePrinter.FAMILY_ERROR, "Player " + player.getName() + "'s family doesn't have an entry for them. (" + f.getID() + ")");
|
||||||
c.announce(MaplePacketCreator.getFamilyInfo(null));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
FilePrinter.printError(FilePrinter.FAMILY_ERROR, "Player " + player.getName() + " has an invalid family ID. (" + player.getFamilyId() + ")");
|
||||||
c.announce(MaplePacketCreator.getFamilyInfo(null));
|
c.announce(MaplePacketCreator.getFamilyInfo(null));
|
||||||
}
|
}
|
||||||
if (player.getGuildId() > 0) {
|
} else {
|
||||||
MapleGuild playerGuild = server.getGuild(player.getGuildId(), player.getWorld(), player);
|
c.announce(MaplePacketCreator.getFamilyInfo(null));
|
||||||
if (playerGuild == null) {
|
}
|
||||||
player.deleteGuild(player.getGuildId());
|
|
||||||
player.getMGC().setGuildId(0);
|
if (player.getGuildId() > 0) {
|
||||||
player.getMGC().setGuildRank(5);
|
MapleGuild playerGuild = server.getGuild(player.getGuildId(), player.getWorld(), player);
|
||||||
} else {
|
if (playerGuild == null) {
|
||||||
playerGuild.getMGC(player.getId()).setCharacter(player);
|
player.deleteGuild(player.getGuildId());
|
||||||
player.setMGC(playerGuild.getMGC(player.getId()));
|
player.getMGC().setGuildId(0);
|
||||||
server.setGuildMemberOnline(player, true, c.getChannel());
|
player.getMGC().setGuildRank(5);
|
||||||
c.announce(MaplePacketCreator.showGuildInfo(player));
|
} else {
|
||||||
int allianceId = player.getGuild().getAllianceId();
|
playerGuild.getMGC(player.getId()).setCharacter(player);
|
||||||
if (allianceId > 0) {
|
player.setMGC(playerGuild.getMGC(player.getId()));
|
||||||
MapleAlliance newAlliance = server.getAlliance(allianceId);
|
server.setGuildMemberOnline(player, true, c.getChannel());
|
||||||
if (newAlliance == null) {
|
c.announce(MaplePacketCreator.showGuildInfo(player));
|
||||||
newAlliance = MapleAlliance.loadAlliance(allianceId);
|
int allianceId = player.getGuild().getAllianceId();
|
||||||
if (newAlliance != null) {
|
if (allianceId > 0) {
|
||||||
server.addAlliance(allianceId, newAlliance);
|
MapleAlliance newAlliance = server.getAlliance(allianceId);
|
||||||
} else {
|
if (newAlliance == null) {
|
||||||
player.getGuild().setAllianceId(0);
|
newAlliance = MapleAlliance.loadAlliance(allianceId);
|
||||||
}
|
|
||||||
}
|
|
||||||
if (newAlliance != null) {
|
if (newAlliance != null) {
|
||||||
c.announce(MaplePacketCreator.updateAllianceInfo(newAlliance, c.getWorld()));
|
server.addAlliance(allianceId, newAlliance);
|
||||||
c.announce(MaplePacketCreator.allianceNotice(newAlliance.getId(), newAlliance.getNotice()));
|
} else {
|
||||||
|
player.getGuild().setAllianceId(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (newAlliance != null) {
|
||||||
|
c.announce(MaplePacketCreator.updateAllianceInfo(newAlliance, c.getWorld()));
|
||||||
|
c.announce(MaplePacketCreator.allianceNotice(newAlliance.getId(), newAlliance.getNotice()));
|
||||||
|
|
||||||
if (newcomer) {
|
if (newcomer) {
|
||||||
server.allianceMessage(allianceId, MaplePacketCreator.allianceMemberOnline(player, true), player.getId(), -1);
|
server.allianceMessage(allianceId, MaplePacketCreator.allianceMemberOnline(player, true), player.getId(), -1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
player.showNote();
|
player.showNote();
|
||||||
if (player.getParty() != null) {
|
if (player.getParty() != null) {
|
||||||
MaplePartyCharacter pchar = player.getMPC();
|
MaplePartyCharacter pchar = player.getMPC();
|
||||||
|
|
||||||
//Use this in case of enabling party HPbar HUD when logging in, however "you created a party" will appear on chat.
|
//Use this in case of enabling party HPbar HUD when logging in, however "you created a party" will appear on chat.
|
||||||
//c.announce(MaplePacketCreator.partyCreated(pchar));
|
//c.announce(MaplePacketCreator.partyCreated(pchar));
|
||||||
|
|
||||||
pchar.setChannel(c.getChannel());
|
pchar.setChannel(c.getChannel());
|
||||||
pchar.setMapId(player.getMapId());
|
pchar.setMapId(player.getMapId());
|
||||||
pchar.setOnline(true);
|
pchar.setOnline(true);
|
||||||
wserv.updateParty(player.getParty().getId(), PartyOperation.LOG_ONOFF, pchar);
|
wserv.updateParty(player.getParty().getId(), PartyOperation.LOG_ONOFF, pchar);
|
||||||
player.updatePartyMemberHP();
|
player.updatePartyMemberHP();
|
||||||
|
}
|
||||||
|
|
||||||
|
MapleInventory eqpInv = player.getInventory(MapleInventoryType.EQUIPPED);
|
||||||
|
eqpInv.lockInventory();
|
||||||
|
try {
|
||||||
|
for (Item it : eqpInv.list()) {
|
||||||
|
player.equippedItem((Equip) it);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
eqpInv.unlockInventory();
|
||||||
|
}
|
||||||
|
|
||||||
|
c.announce(MaplePacketCreator.updateBuddylist(player.getBuddylist().getBuddies()));
|
||||||
|
|
||||||
|
CharacterNameAndId pendingBuddyRequest = c.getPlayer().getBuddylist().pollPendingRequest();
|
||||||
|
if (pendingBuddyRequest != null) {
|
||||||
|
c.announce(MaplePacketCreator.requestBuddylistAdd(pendingBuddyRequest.getId(), c.getPlayer().getId(), pendingBuddyRequest.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
c.announce(MaplePacketCreator.updateGender(player));
|
||||||
|
player.checkMessenger();
|
||||||
|
c.announce(MaplePacketCreator.enableReport());
|
||||||
|
player.changeSkillLevel(SkillFactory.getSkill(10000000 * player.getJobType() + 12), (byte) (player.getLinkedLevel() / 10), 20, -1);
|
||||||
|
player.checkBerserk(player.isHidden());
|
||||||
|
|
||||||
|
if (newcomer) {
|
||||||
|
for (MaplePet pet : player.getPets()) {
|
||||||
|
if (pet != null) {
|
||||||
|
wserv.registerPetHunger(player, player.getPetIndex(pet));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MapleInventory eqpInv = player.getInventory(MapleInventoryType.EQUIPPED);
|
MapleMount mount = player.getMount(); // thanks Ari for noticing a scenario where Silver Mane quest couldn't be started
|
||||||
eqpInv.lockInventory();
|
if (mount.getItemId() != 0) {
|
||||||
try {
|
player.announce(MaplePacketCreator.updateMount(player.getId(), mount, false));
|
||||||
for(Item it : eqpInv.list()) {
|
|
||||||
player.equippedItem((Equip) it);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
eqpInv.unlockInventory();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.announce(MaplePacketCreator.updateBuddylist(player.getBuddylist().getBuddies()));
|
player.reloadQuestExpirations();
|
||||||
|
|
||||||
CharacterNameAndId pendingBuddyRequest = c.getPlayer().getBuddylist().pollPendingRequest();
|
|
||||||
if (pendingBuddyRequest != null) {
|
|
||||||
c.announce(MaplePacketCreator.requestBuddylistAdd(pendingBuddyRequest.getId(), c.getPlayer().getId(), pendingBuddyRequest.getName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
c.announce(MaplePacketCreator.updateGender(player));
|
|
||||||
player.checkMessenger();
|
|
||||||
c.announce(MaplePacketCreator.enableReport());
|
|
||||||
player.changeSkillLevel(SkillFactory.getSkill(10000000 * player.getJobType() + 12), (byte) (player.getLinkedLevel() / 10), 20, -1);
|
|
||||||
player.checkBerserk(player.isHidden());
|
|
||||||
|
|
||||||
if (newcomer) {
|
|
||||||
for(MaplePet pet : player.getPets()) {
|
|
||||||
if(pet != null) {
|
|
||||||
wserv.registerPetHunger(player, player.getPetIndex(pet));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MapleMount mount = player.getMount(); // thanks Ari for noticing a scenario where Silver Mane quest couldn't be started
|
|
||||||
if (mount.getItemId() != 0) {
|
|
||||||
player.announce(MaplePacketCreator.updateMount(player.getId(), mount, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
player.reloadQuestExpirations();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (!c.hasVotedAlready()){
|
if (!c.hasVotedAlready()){
|
||||||
player.announce(MaplePacketCreator.earnTitleMessage("You can vote now! Vote and earn a vote point!"));
|
player.announce(MaplePacketCreator.earnTitleMessage("You can vote now! Vote and earn a vote point!"));
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
if (player.isGM()){
|
if (player.isGM()) {
|
||||||
Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.earnTitleMessage((player.gmLevel() < 6 ? "GM " : "Admin ") + player.getName() + " has logged in"));
|
Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.earnTitleMessage((player.gmLevel() < 6 ? "GM " : "Admin ") + player.getName() + " has logged in"));
|
||||||
}
|
|
||||||
|
|
||||||
if(diseases != null) {
|
|
||||||
for(Entry<MapleDisease, Pair<Long, MobSkill>> e : diseases.entrySet()) {
|
|
||||||
final List<Pair<MapleDisease, Integer>> debuff = Collections.singletonList(new Pair<>(e.getKey(), e.getValue().getRight().getX()));
|
|
||||||
c.announce(MaplePacketCreator.giveDebuff(debuff, e.getValue().getRight()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(player.isRidingBattleship()) {
|
|
||||||
player.announceBattleshipHp();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
player.buffExpireTask();
|
|
||||||
player.diseaseExpireTask();
|
|
||||||
player.skillCooldownTask();
|
|
||||||
player.expirationTask();
|
|
||||||
player.questExpirationTask();
|
|
||||||
if (GameConstants.hasSPTable(player.getJob()) && player.getJob().getId() != 2001) {
|
|
||||||
player.createDragon();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
player.commitExcludedItems();
|
if (diseases != null) {
|
||||||
showDueyNotification(c, player);
|
for (Entry<MapleDisease, Pair<Long, MobSkill>> e : diseases.entrySet()) {
|
||||||
|
final List<Pair<MapleDisease, Integer>> debuff = Collections.singletonList(new Pair<>(e.getKey(), e.getValue().getRight().getX()));
|
||||||
if (player.getMap().getHPDec() > 0) player.resetHpDecreaseTask();
|
c.announce(MaplePacketCreator.giveDebuff(debuff, e.getValue().getRight()));
|
||||||
|
|
||||||
player.resetPlayerRates();
|
|
||||||
if(YamlConfig.config.server.USE_ADD_RATES_BY_LEVEL == true) player.setPlayerRates();
|
|
||||||
player.setWorldRates();
|
|
||||||
player.updateCouponRates();
|
|
||||||
|
|
||||||
player.receivePartyMemberHP();
|
|
||||||
|
|
||||||
if(player.getPartnerId() > 0) {
|
|
||||||
int partnerId = player.getPartnerId();
|
|
||||||
final MapleCharacter partner = wserv.getPlayerStorage().getCharacterById(partnerId);
|
|
||||||
|
|
||||||
if(partner != null && !partner.isAwayFromWorld()) {
|
|
||||||
player.announce(Wedding.OnNotifyWeddingPartnerTransfer(partnerId, partner.getMapId()));
|
|
||||||
partner.announce(Wedding.OnNotifyWeddingPartnerTransfer(player.getId(), player.getMapId()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if (newcomer) {
|
if (player.isRidingBattleship()) {
|
||||||
EventInstanceManager eim = MapleEventRecallCoordinator.getInstance().recallEventInstance(cid);
|
player.announceBattleshipHp();
|
||||||
if (eim != null) {
|
|
||||||
eim.registerPlayer(player);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tell the client to use the custom scripts available for the NPCs provided, instead of the WZ entries.
|
|
||||||
if (YamlConfig.config.server.USE_NPCS_SCRIPTABLE) {
|
|
||||||
|
|
||||||
// Create a copy to prevent always adding entries to the server's list.
|
|
||||||
Map<Integer, String> npcsIds = YamlConfig.config.server.NPCS_SCRIPTABLE
|
|
||||||
.entrySet().stream().collect(Collectors.toMap(
|
|
||||||
entry -> Integer.parseInt(entry.getKey()),
|
|
||||||
Entry::getValue
|
|
||||||
));
|
|
||||||
|
|
||||||
// Any npc be specified as the rebirth npc. Allow the npc to use custom scripts explicitly.
|
|
||||||
if (YamlConfig.config.server.USE_REBIRTH_SYSTEM) {
|
|
||||||
npcsIds.put(YamlConfig.config.server.REBIRTH_NPC_ID, "Rebirth");
|
|
||||||
}
|
|
||||||
|
|
||||||
c.announce(MaplePacketCreator.setNPCScriptable(npcsIds));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(newcomer) player.setLoginTime(System.currentTimeMillis());
|
|
||||||
} catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
c.releaseClient();
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
c.announce(MaplePacketCreator.getAfterLoginError(10));
|
player.buffExpireTask();
|
||||||
|
player.diseaseExpireTask();
|
||||||
|
player.skillCooldownTask();
|
||||||
|
player.expirationTask();
|
||||||
|
player.questExpirationTask();
|
||||||
|
if (GameConstants.hasSPTable(player.getJob()) && player.getJob().getId() != 2001) {
|
||||||
|
player.createDragon();
|
||||||
|
}
|
||||||
|
|
||||||
|
player.commitExcludedItems();
|
||||||
|
showDueyNotification(c, player);
|
||||||
|
|
||||||
|
if (player.getMap().getHPDec() > 0) player.resetHpDecreaseTask();
|
||||||
|
|
||||||
|
player.resetPlayerRates();
|
||||||
|
if (YamlConfig.config.server.USE_ADD_RATES_BY_LEVEL == true) player.setPlayerRates();
|
||||||
|
player.setWorldRates();
|
||||||
|
player.updateCouponRates();
|
||||||
|
|
||||||
|
player.receivePartyMemberHP();
|
||||||
|
|
||||||
|
if (player.getPartnerId() > 0) {
|
||||||
|
int partnerId = player.getPartnerId();
|
||||||
|
final MapleCharacter partner = wserv.getPlayerStorage().getCharacterById(partnerId);
|
||||||
|
|
||||||
|
if (partner != null && !partner.isAwayFromWorld()) {
|
||||||
|
player.announce(Wedding.OnNotifyWeddingPartnerTransfer(partnerId, partner.getMapId()));
|
||||||
|
partner.announce(Wedding.OnNotifyWeddingPartnerTransfer(player.getId(), player.getMapId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newcomer) {
|
||||||
|
EventInstanceManager eim = MapleEventRecallCoordinator.getInstance().recallEventInstance(cid);
|
||||||
|
if (eim != null) {
|
||||||
|
eim.registerPlayer(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tell the client to use the custom scripts available for the NPCs provided, instead of the WZ entries.
|
||||||
|
if (YamlConfig.config.server.USE_NPCS_SCRIPTABLE) {
|
||||||
|
|
||||||
|
// Create a copy to prevent always adding entries to the server's list.
|
||||||
|
Map<Integer, String> npcsIds = YamlConfig.config.server.NPCS_SCRIPTABLE
|
||||||
|
.entrySet().stream().collect(Collectors.toMap(
|
||||||
|
entry -> Integer.parseInt(entry.getKey()),
|
||||||
|
Entry::getValue
|
||||||
|
));
|
||||||
|
|
||||||
|
// Any npc be specified as the rebirth npc. Allow the npc to use custom scripts explicitly.
|
||||||
|
if (YamlConfig.config.server.USE_REBIRTH_SYSTEM) {
|
||||||
|
npcsIds.put(YamlConfig.config.server.REBIRTH_NPC_ID, "Rebirth");
|
||||||
|
}
|
||||||
|
|
||||||
|
c.announce(MaplePacketCreator.setNPCScriptable(npcsIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newcomer) player.setLoginTime(System.currentTimeMillis());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
c.releaseClient();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user