Why wouldn't it? If it isn't, it definitely has it's advantages because it reduces stress on the SQL Server.
Printable View
Think about the MASS amount of characters your caching.
I would recommend caching all characters once and put it in a variable (hashmap, arraylist?? not sure which) then go from there. May be wrong, just a thought o.o
The changing channel procces is alot faster with this, confirmed.
Anyways
Should bePHP Code:public static MapleCharacter retrieveCharacter(int cid, MapleClient c) {
Otherwise you'll be getting a error when you compliePHP Code:public static MapleCharacter retrieveCharacter(int cid, MapleClient c) throws SQLException{
Anyways, good job! :thumbup1:Quote:
exception java.sql.SQLException is never thrown in body of corresponding try statement
@Edit 1.
Bugs:
You can't enter CS and when you change channel you always end up in Henesys.
You people will never understand why I did some thing in my source...
Anyways the first thing that came in my mind when I saw this was... Celino
I didn't use Celino for anything. If you want to make some accusations of any kind, go ahead.
Check out my script and compare it to Celino's :
I don't know which one is faster and/or more efficient, but I'm betting my money on mine for simplicity.PHP Code:public class CharacterTransfer implements Externalizable {
public int characterid, accountid, fame, str, dex, int_, luk, maxhp, maxmp, hp, mp, exp, hpApUsed, mpApUsed,
remainingSp, remainingAp, meso, skinColor, job, hair, face, mapid,
initialSpawnPoint, world, rank, rankMove, jobRank, jobRankMove, guildid,
buddysize, partyid, messengerid, messengerposition, mBookCover, dojo, ACash, MaplePoints,
mount_level, mount_itemid, mount_Fatigue, mount_exp;
public byte channel, dojoRecord, gender, gmLevel, guildrank, alliancerank;
public long lastfametime, TranferTime;
public String name, accountname, BlessOfFairy;
public short level;
public Object monsterbook, inventorys, skillmacro, keymap, savedlocation, famedcharacters,
storage, rocks, wishlist, InfoQuest;
public final Map<Integer, Pair<String, Boolean>> buddies = new LinkedHashMap<Integer, Pair<String, Boolean>>();
public final Map<Integer, Object> Quest = new LinkedHashMap<Integer, Object>(); // Questid instead of MapleQuest, as it's huge. Cant be transporting MapleQuest.java
public final Map<Integer, Object> Skills = new LinkedHashMap<Integer, Object>(); // Skillid instead of Skill.java, as it's huge. Cant be transporting Skill.java and MapleStatEffect.java
public CharacterTransfer() {
}
public CharacterTransfer(final MapleCharacter chr) {
this.characterid = chr.getId();
this.accountid = chr.getAccountID();
this.accountname = chr.getClient().getAccountName();
this.channel = (byte) chr.getClient().getChannel();
this.ACash = chr.getCSPoints(1);
this.MaplePoints = chr.getCSPoints(2);
this.name = chr.getName();
this.fame = chr.getFame();
this.gender = (byte) chr.getGender();
this.level = chr.getLevel();
this.str = chr.getStat().getStr();
this.dex = chr.getStat().getDex();
this.int_ = chr.getStat().getInt();
this.luk = chr.getStat().getLuk();
this.hp = chr.getStat().getHp();
this.mp = chr.getStat().getMp();
this.maxhp = chr.getStat().getMaxHp();
this.maxmp = chr.getStat().getMaxMp();
this.exp = chr.getExp();
this.hpApUsed = chr.getHpApUsed();
this.mpApUsed = chr.getMpApUsed();
this.remainingAp = chr.getRemainingAp();
this.remainingSp = chr.getRemainingSp();
this.meso = chr.getMeso();
this.skinColor = chr.getSkinColor();
this.job = chr.getJob();
this.hair = chr.getHair();
this.face = chr.getFace();
this.mapid = chr.getMapId();
this.initialSpawnPoint = chr.getInitialSpawnpoint();
this.world = chr.getWorld();
this.rank = chr.getRank();
this.rankMove = chr.getRankMove();
this.jobRank = (byte) chr.getJobRank();
this.jobRankMove = chr.getJobRankMove();
this.guildid = chr.getGuildId();
this.guildrank = (byte) chr.getGuildRank();
this.alliancerank = (byte) chr.getAllianceRank();
this.gmLevel = (byte) chr.getGMLevel();
for (final BuddylistEntry qs : chr.getBuddylist().getBuddies()) {
this.buddies.put(qs.getCharacterId(), new tools.Pair<String, Boolean>(qs.getName(), qs.isVisible()));
}
this.buddysize = chr.getBuddyCapacity();
this.partyid = chr.getPartyId();
if (chr.getMessenger() != null) {
this.messengerid = chr.getMessenger().getId();
this.messengerposition = chr.getMessengerPosition();
} else {
messengerid = 0;
messengerposition = 4;
}
this.mBookCover = chr.getMonsterBookCover();
this.dojo = chr.getDojo();
this.dojoRecord = (byte) chr.getDojoRecord();
this.InfoQuest = chr.getInfoQuest_Map();
for (final Map.Entry<MapleQuest, MapleQuestStatus> qs : chr.getQuest_Map().entrySet()) {
this.Quest.put(qs.getKey().getId(), qs.getValue());
}
this.monsterbook = chr.getMonsterBook();
this.inventorys = chr.getInventorys();
for (final Map.Entry<ISkill, SkillEntry> qs : chr.getSkills().entrySet()) {
this.Skills.put(qs.getKey().getId(), qs.getValue());
}
this.BlessOfFairy = chr.getBlessOfFairyOrigin();
this.skillmacro = chr.getMacros();
this.keymap = chr.getKeyLayout();
this.savedlocation = chr.getSavedLocations();
this.famedcharacters = chr.getFamedCharacters();
this.lastfametime = chr.getLastFameTime();
this.storage = chr.getStorage();
this.rocks = chr.getRocks();
this.wishlist = chr.getWishlist();
final MapleMount mount = chr.getMount();
this.mount_itemid = mount.getItemId();
this.mount_Fatigue = mount.getFatigue();
this.mount_level = mount.getLevel();
this.mount_exp = mount.getExp();
}
@Override
public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
this.characterid = in.readInt();
this.accountid = in.readInt();
this.accountname = (String) in.readObject();
this.channel = in.readByte();
this.ACash = in.readInt();
this.MaplePoints = in.readInt();
this.name = (String) in.readObject();
this.fame = in.readInt();
this.gender = in.readByte();
this.level = in.readShort();
this.str = in.readInt();
this.dex = in.readInt();
this.int_ = in.readInt();
this.luk = in.readInt();
this.hp = in.readInt();
this.mp = in.readInt();
this.maxhp = in.readInt();
this.maxmp = in.readInt();
this.exp = in.readInt();
this.hpApUsed = in.readInt();
this.mpApUsed = in.readInt();
this.remainingAp = in.readInt();
this.remainingSp = in.readInt();
this.meso = in.readInt();
this.skinColor = in.readInt();
this.job = in.readInt();
this.hair = in.readInt();
this.face = in.readInt();
this.mapid = in.readInt();
this.initialSpawnPoint = in.readByte();
this.world = in.readByte();
this.rank = in.readInt();
this.rankMove = in.readInt();
this.jobRank = in.readInt();
this.jobRankMove = in.readInt();
this.guildid = in.readInt();
this.guildrank = in.readByte();
this.alliancerank = in.readByte();
this.gmLevel = in.readByte();
this.BlessOfFairy = (String) in.readObject();
this.skillmacro = in.readObject();
this.keymap = in.readObject();
this.savedlocation = in.readObject();
this.famedcharacters = in.readObject();
this.lastfametime = in.readLong();
this.storage = in.readObject();
this.rocks = in.readObject();
this.wishlist = in.readObject();
this.mount_itemid = in.readInt();
this.mount_Fatigue = in.readInt();
this.mount_level = in.readInt();
this.mount_exp = in.readInt();
this.partyid = in.readInt();
this.messengerid = in.readInt();
this.messengerposition = in.readInt();
this.mBookCover = in.readInt();
this.dojo = in.readInt();
this.dojoRecord = in.readByte();
this.monsterbook = in.readObject();
this.inventorys = in.readObject();
this.InfoQuest = in.readObject();
final int skillsize = in.readShort();
int skillid;
Object skill; // SkillEntry
for (int i = 0; i < skillsize; i++) {
skillid = in.readInt();
skill = in.readObject();
this.Skills.put(skillid, skill);
}
this.buddysize = in.readShort();
final short addedbuddysize = in.readShort();
int buddyid;
String buddyname;
boolean visible;
for (int i = 0; i < addedbuddysize; i++) {
buddyid = in.readInt();
buddyname = (String) in.readObject();
visible = in.readBoolean();
buddies.put(buddyid, new Pair(buddyname, visible));
}
final int questsize = in.readShort();
int quest;
Object queststatus;
for (int i = 0; i < questsize; i++) {
quest = in.readInt();
queststatus = in.readObject();
this.Quest.put(quest, queststatus);
}
TranferTime = System.currentTimeMillis();
}
@Override
public void writeExternal(final ObjectOutput out) throws IOException {
out.writeInt(this.characterid);
out.writeInt(this.accountid);
out.writeObject(this.accountname);
out.write(this.channel);
out.writeInt(this.ACash);
out.writeInt(this.MaplePoints);
out.writeObject(this.name);
out.writeInt(this.fame);
out.write(this.gender);
out.writeShort(this.level);
out.writeInt(this.str);
out.writeInt(this.dex);
out.writeInt(this.int_);
out.writeInt(this.luk);
out.writeInt(this.hp);
out.writeInt(this.mp);
out.writeInt(this.maxhp);
out.writeInt(this.maxmp);
out.writeInt(this.exp);
out.writeInt(this.hpApUsed);
out.writeInt(this.mpApUsed);
out.writeInt(this.remainingAp);
out.writeInt(this.remainingSp);
out.writeInt(this.meso);
out.writeInt(this.skinColor);
out.writeInt(this.job);
out.writeInt(this.hair);
out.writeInt(this.face);
out.writeInt(this.mapid);
out.write(this.initialSpawnPoint);
out.write(this.world);
out.writeInt(this.rank);
out.writeInt(this.rankMove);
out.writeInt(this.jobRank);
out.writeInt(this.jobRankMove);
out.writeInt(this.guildid);
out.write(this.guildrank);
out.write(this.alliancerank);
out.write(this.gmLevel);
out.writeObject(this.BlessOfFairy);
out.writeObject(this.skillmacro);
out.writeObject(this.keymap);
out.writeObject(this.savedlocation);
out.writeObject(this.famedcharacters);
out.writeLong(this.lastfametime);
out.writeObject(this.storage);
out.writeObject(this.rocks);
out.writeObject(this.wishlist);
out.writeInt(this.mount_itemid);
out.writeInt(this.mount_Fatigue);
out.writeInt(this.mount_level);
out.writeInt(this.mount_exp);
out.writeInt(this.partyid);
out.writeInt(this.messengerid);
out.writeInt(this.messengerposition);
out.writeInt(this.mBookCover);
out.writeInt(this.dojo);
out.write(this.dojoRecord);
out.writeObject(this.monsterbook);
out.writeObject(this.inventorys);
out.writeObject(this.InfoQuest);
out.writeShort(this.Skills.size());
for (final Map.Entry<Integer, Object> qs : this.Skills.entrySet()) {
out.writeInt(qs.getKey()); // Questid instead of Skill, as it's huge :(
out.writeObject(qs.getValue());
// Bless of fairy is transported here too.
}
out.writeShort(this.buddysize);
out.writeShort(this.buddies.size());
for (final Map.Entry<Integer, Pair<String, Boolean>> qs : this.buddies.entrySet()) {
out.writeInt(qs.getKey());
out.writeObject(qs.getValue().left);
out.writeBoolean(qs.getValue().right);
}
out.writeShort(this.Quest.size());
for (final Map.Entry<Integer, Object> qs : this.Quest.entrySet()) {
out.writeInt(qs.getKey()); // Questid instead of MapleQuest, as it's huge :(
out.writeObject(qs.getValue());
}
}
}
The repack im using doesn't have a PlayerTransfer.java
What do I do?
Edit 1:I have a changechannelhandler.
Does that count?
You have to create PlayerTransfer.java yourself
Maple player is already defined. I see it, where it saysCode:/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.channel.handler;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import client.BuddylistEntry;
import client.CharacterNameAndId;
import client.MapleCharacter;
import client.MapleClient;
import client.MapleQuestStatus;
import client.SkillFactory;
import constants.skills.SuperGM;
import java.sql.SQLException;
import java.util.List;
import tools.DatabaseConnection;
import net.AbstractMaplePacketHandler;
import net.channel.ChannelServer;
import net.world.CharacterIdChannelPair;
import net.world.MaplePartyCharacter;
import net.world.PartyOperation;
import net.world.PlayerBuffValueHolder;
import net.world.guild.MapleAlliance;
import net.world.guild.MapleGuild;
import net.world.remote.WorldChannelInterface;
import server.PlayerTransfer;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
@Override
public final boolean validateState(MapleClient c) {
return !c.isLoggedIn();
}
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int cid = slea.readInt();
MapleCharacter player = null;
try {
MapleCharacter player = PlayerTransfer.retrieveCharacter(cid, c);
c.setPlayer(player);
} catch (SQLException e) {
e.printStackTrace();
}
c.setAccID(player.getAccountID());
int state = c.getLoginState();
boolean allowLogin = true;
ChannelServer cserv = c.getChannelServer();
synchronized (this) {
try {
WorldChannelInterface worldInterface = cserv.getWorldInterface();
if (state == MapleClient.LOGIN_SERVER_TRANSITION) {
for (String charName : c.loadCharacterNames(c.getWorld())) {
if (worldInterface.isConnected(charName)) {
allowLogin = false;
break;
}
}
}
} catch (RemoteException e) {
cserv.reconnectWorld();
allowLogin = false;
}
if (state != MapleClient.LOGIN_SERVER_TRANSITION || !allowLogin) {
c.setPlayer(null);
c.getSession().close(true);
return;
}
c.updateLoginState(MapleClient.LOGIN_LOGGEDIN);
}
cserv.addPlayer(player);
try {
List<PlayerBuffValueHolder> buffs = cserv.getWorldInterface().getBuffsFromStorage(cid);
if (buffs != null) {
c.getPlayer().silentGiveBuffs(buffs);
}
} catch (RemoteException e) {
cserv.reconnectWorld();
}
Connection con = DatabaseConnection.getConnection();
try {
PreparedStatement ps = con.prepareStatement("SELECT SkillID,StartTime,length FROM cooldowns WHERE charid = ?");
ps.setInt(1, c.getPlayer().getId());
ResultSet rs = ps.executeQuery();
while (rs.next()) {
final int skillid = rs.getInt("SkillID");
final long length = rs.getLong("length"), startTime = rs.getLong("StartTime");
if (length + startTime < System.currentTimeMillis()) {
continue;
}
c.getPlayer().giveCoolDowns(skillid, startTime, length);
}
rs.close();
ps.close();
ps = con.prepareStatement("DELETE FROM cooldowns WHERE charid = ?");
ps.setInt(1, c.getPlayer().getId());
ps.executeUpdate();
ps.close();
ps = con.prepareStatement("SELECT Mesos FROM dueypackages WHERE RecieverId = ? and Checked = 1");
ps.setInt(1, c.getPlayer().getId());
rs = ps.executeQuery();
if (rs.next()) {
try {
PreparedStatement pss = DatabaseConnection.getConnection().prepareStatement("UPDATE dueypackages SET Checked = 0 where RecieverId = ?");
pss.setInt(1, c.getPlayer().getId());
pss.executeUpdate();
pss.close();
} catch (SQLException e) {
}
c.getSession().write(MaplePacketCreator.sendDueyMSG((byte) 0x1B));
}
rs.close();
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
c.getSession().write(MaplePacketCreator.getCharInfo(player));
if (player.isGM()) {
SkillFactory.getSkill(SuperGM.HIDE).getEffect(SkillFactory.getSkill(SuperGM.HIDE).getMaxLevel()).applyTo(player);
}
player.sendKeymap();
c.getPlayer().sendMacros();
player.getMap().addPlayer(player);
try {
int buddyIds[] = player.getBuddylist().getBuddyIds();
cserv.getWorldInterface().loggedOn(player.getName(), player.getId(), c.getChannel(), buddyIds);
for (CharacterIdChannelPair onlineBuddy : cserv.getWorldInterface().multiBuddyFind(player.getId(), buddyIds)) {
BuddylistEntry ble = player.getBuddylist().get(onlineBuddy.getCharacterId());
ble.setChannel(onlineBuddy.getChannel());
player.getBuddylist().put(ble);
}
c.getSession().write(MaplePacketCreator.updateBuddylist(player.getBuddylist().getBuddies()));
} catch (RemoteException e) {
cserv.reconnectWorld();
}
c.getSession().write(MaplePacketCreator.loadFamily(player));
if (player.getFamilyId() > 0) {
c.getSession().write(MaplePacketCreator.getFamilyInfo(player));
}
if (player.getGuildId() > 0) {
try {
MapleGuild playerGuild = cserv.getWorldInterface().getGuild(player.getGuildId(), player.getMGC());
if (playerGuild == null) {
player.deleteGuild(player.getGuildId());
player.resetMGC();
player.setGuildId(0);
} else {
cserv.getWorldInterface().setGuildMemberOnline(player.getMGC(), true, c.getChannel());
c.getSession().write(MaplePacketCreator.showGuildInfo(player));
int allianceId = player.getGuild().getAllianceId();
if (allianceId > 0) {
MapleAlliance newAlliance = cserv.getWorldInterface().getAlliance(allianceId);
if (newAlliance == null) {
newAlliance = MapleAlliance.loadAlliance(allianceId);
if (newAlliance != null) {
cserv.getWorldInterface().addAlliance(allianceId, newAlliance);
} else {
player.getGuild().setAllianceId(0);
}
}
if (newAlliance != null) {
c.getSession().write(MaplePacketCreator.getAllianceInfo(newAlliance));
c.getSession().write(MaplePacketCreator.getGuildAlliances(newAlliance, c));
cserv.getWorldInterface().allianceMessage(allianceId, MaplePacketCreator.allianceMemberOnline(player, true), player.getId(), -1);
}
}
}
} catch (RemoteException e) {
cserv.reconnectWorld();
}
}
try {
c.getPlayer().showNote();
if (player.getParty() != null) {
cserv.getWorldInterface().updateParty(player.getParty().getId(), PartyOperation.LOG_ONOFF, new MaplePartyCharacter(player));
}
player.updatePartyMemberHP();
} catch (RemoteException e) {
cserv.reconnectWorld();
}
for (MapleQuestStatus status : player.getStartedQuests()) {
if (status.hasMobKills()) {
c.getSession().write(MaplePacketCreator.updateQuestMobKills(status));
}
}
CharacterNameAndId pendingBuddyRequest = player.getBuddylist().pollPendingRequest();
if (pendingBuddyRequest != null) {
player.getBuddylist().put(new BuddylistEntry(pendingBuddyRequest.getName(), "Default Group", pendingBuddyRequest.getId(), -1, false));
c.getSession().write(MaplePacketCreator.requestBuddylistAdd(pendingBuddyRequest.getId(), c.getPlayer().getId(), pendingBuddyRequest.getName()));
}
c.getSession().write(MaplePacketCreator.updateBuddylist(player.getBuddylist().getBuddies()));
c.getSession().write(MaplePacketCreator.updateGender(player));
player.checkMessenger();
c.getSession().write(MaplePacketCreator.enableReport());
if (!player.isGM() && !player.hasWatchedCygnusIntro() && player.getLevel() > 19 && !player.isCygnus() && player.getCygnusLinkId() == 0) {
player.startCygnusIntro();
player.setWatchedCygnusIntro(true);
}
player.changeSkillLevel(SkillFactory.getSkill(10000000 * player.getJobType() + 12), player.getLinkedLevel() / 10, 20);
player.checkBerserk();
player.expirationTask();
player.setRates();
}
}
So what do I doCode:MapleCharacter player = null;