// the real handle starts here
// String selectSql = "select * from accounts_masterdata where email=\"" + packet.getEmail() /* + "\" and password=\"" + password */+
// "\"";
Account account = this.getAccountByEmailAddress(packet.getEmail());
int errorCode = 0;
if (account == null) {
errorCode = 227;
} else if (account.isBanned()) {
errorCode = 45;
}
if (errorCode != 0) {
P003_StreamTerminator streamTerminator = new P003_StreamTerminator();
streamTerminator.setErrorCode(errorCode);
streamTerminator.setLoginCount(serverData.getLoginCount());
ctx.write(streamTerminator);
return;
}
int accountId = account.getAccountId();
int charId = account.getCharId();
// set the chosen character for the account, as it's important for the next step!!
serverData.setCharId(charId);
serverData.setAccId(accountId);
serverData.setStatus(ClientStatus.AT_CHAR_VIEW);
Set<Character> characters = this.getCharactersByAccountId(accountId);
// process all characters
for (Character character : characters) {
// load each character
int mapId = character.getMapId();
if (character.getCharId() == serverData.getCharId()) {
serverData.setMapId(mapId);
}
// send a packet to the client containing the info
P007_CharacterInfo characterInfo = new P007_CharacterInfo();
characterInfo.setLoginCount(serverData.getLoginCount());
characterInfo.setStaticHash(new short[16]);
characterInfo.setStaticData(0);
characterInfo.setCharacterName(character.getCharName());
// create the appearance byte array
short remainderLength = 0;
byte[] armorHead = character.getArmorHead();
byte[] armorChest = character.getArmorChest();
byte[] armorArms = character.getArmorArms();
byte[] armorLegs = character.getArmorLegs();
byte[] armorFeet = character.getArmorFeet();
if (armorHead != null && armorHead.length != 0) {
remainderLength++;
}
if (armorChest != null && armorChest.length != 0) {
remainderLength++;
}
if (armorArms != null && armorArms.length != 0) {
remainderLength++;
}
if (armorLegs != null && armorLegs.length != 0) {
remainderLength++;
}
if (armorFeet != null && armorFeet.length != 0) {
remainderLength++;
}
// appearance!
ByteBuf buffer = Unpooled.buffer(512);
buffer = buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.writeShort(6);
buffer.writeShort(mapId);
RawConverter.writeUnsignedByteArray(new short[] { 0x33, 0x36, 0x31, 0x30 }, buffer);
buffer.writeByte((character.getLookHeight() << 4) | character.getLookSex());
buffer.writeByte((character.getLookHairColor() << 4) | character.getLookSkinColor());
buffer.writeByte((character.getProfessionprimary() << 4) | character.getLookHairStyle());
buffer.writeByte((character.getLookCampaign() << 4) | character.getLookFace());
RawConverter.writeUnsignedByteArray(new short[16], buffer);
buffer.writeByte((character.getLevel() << 4) | character.getLookCampaign());
// RawConverter.writeUnsignedByte((short) ((resultChars.getInt("lookCampaign") << 4) | resultChars.getInt("lookFace")), buffer);
buffer.writeByte(128 | (character.isShowHelm() ? 64 : 0) | (character.getProfessionSecondary() << 2)
| (character.isPVP() ? 2 : 0) | (character.getLevel() > 15 ? 1 : 0));
RawConverter.writeUnsignedByteArray(new short[] { 0xDD, 0xDD }, buffer);
buffer.writeByte(remainderLength);
RawConverter.writeUnsignedByteArray(new short[] { 0xDD, 0xDD, 0xDD, 0xDD }, buffer);
if (armorHead != null && armorHead.length != 0) {
this.writeBlobField(armorHead, buffer);
}
if (armorChest != null && armorChest.length != 0) {
this.writeBlobField(armorChest, buffer);
}
if (armorArms != null && armorArms.length != 0) {
this.writeBlobField(armorArms, buffer);
}
if (armorLegs != null && armorLegs.length != 0) {
this.writeBlobField(armorLegs, buffer);
}
if (armorFeet != null && armorFeet.length != 0) {
this.writeBlobField(armorFeet, buffer);
}
// convert to short.... again
short[] convertedData = new short[buffer.writerIndex() + 1];
StringBuilder sb = new StringBuilder("Appearance: ");
for (int i = 0; i < buffer.writerIndex(); i++) {
convertedData[i] = (short) (buffer.readByte() & 0xFF);
sb.append(convertedData[i]).append(" ");
}
characterInfo.setAppearance(convertedData);
ctx.write(characterInfo);
}
// process an account data packet
P022_AccountGuiInfo accountGuiSettings = new P022_AccountGuiInfo();
accountGuiSettings.setLoginCount(serverData.getLoginCount());
byte[] rawData = account.getGuiSettings();
short[] convertedData = new short[rawData.length];
for (int i = 0; i < rawData.length; i++) {
convertedData[i] = (short) (rawData[i] & 0xFF);
}