Excellzone

Forum and disscussions since 2010


You are not connected. Please login or register

View previous topic View next topic Go down Message [Page 1 of 1]

#1
Excell

avatar
Head Administer
Head Administer
You figure out what to do with it Smile.

Code:
import net.sf.odinms.client.MapleRing;

Replace getCharInfo packet with:

Code:
public static MaplePacket getCharInfo(MapleCharacter chr) {
MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

mplew.writeShort(SendPacketOpcode.WARP_TO_MAP.getValue()); // 0x49

mplew.writeInt(chr.getClient().getChannel() - 1);
mplew.write(1);
mplew.write(1);
mplew.writeShort(0);
mplew.writeInt(new Random().nextInt()); // seed the maplestory rng with a random number <3

mplew.write(HexTool.getByteArrayFromHexString("F8 17 D7 13 CD C5 AD 78"));
addCharWarp(mplew, chr);
addQuestInfo(mplew, chr);

MapleInventory iv = chr.getInventory(MapleInventoryType.EQUIPPED);
Collection<IItem> equippedC = iv.list();
List<Item> equipped = new ArrayList<Item>(equippedC.size());
for (IItem item : equippedC)
equipped.add((Item) item);
Collections.sort(equipped);
List<MapleRing> rings = new ArrayList<MapleRing>();
for (Item item : equipped)
if (((IEquip) item).getRingId() > -1)
rings.add(MapleRing.loadFromDb(((IEquip) item).getRingId()));
iv = chr.getInventory(MapleInventoryType.EQUIP);
for (IItem item : iv.list())
if (((IEquip) item).getRingId() > -1)
rings.add(MapleRing.loadFromDb(((IEquip) item).getRingId()));
Collections.sort(rings);
boolean FR_last = false;
for (MapleRing ring : rings) {
if ((ring.getItemId() >= 1112800 && ring.getItemId() <= 1112803 || ring.getItemId() <= 1112806 || ring.getItemId() <= 1112807 || ring.getItemId() <= 1112809) && rings.indexOf(ring) == 0)
mplew.writeShort(0);
mplew.writeShort(0);
mplew.writeShort(1);
mplew.writeInt(ring.getPartnerChrId());
mplew.writeAsciiString(StringUtil.getRightPaddedStr(ring.getPartnerName(), '\0', 13));
mplew.writeInt(ring.getRingId());
mplew.writeInt(0);
mplew.writeInt(ring.getPartnerRingId());
if (ring.getItemId() >= 1112800 && ring.getItemId() <= 1112803 || ring.getItemId() <= 1112806 || ring.getItemId() <= 1112807 || ring.getItemId() <= 1112809) {
FR_last = true;
mplew.writeInt(0);
mplew.writeInt(ring.getItemId());
mplew.writeShort(0);
} else {
if (rings.size() > 1)
mplew.writeShort(0);
FR_last = false;
}
}
if (!FR_last)
mplew.writeLong(0);
List<Integer> maps = chr.getVIPRockMaps(0);
for (int map : maps)
mplew.writeInt(map);
for (int i = maps.size(); i < 5; i++)
mplew.write(CHAR_INFO_MAGIC);
maps = chr.getVIPRockMaps(1);
for (int map : maps)
mplew.writeInt(map);
for (int i = maps.size(); i < 10; i++)
mplew.write(CHAR_INFO_MAGIC);
maps.clear();
mplew.writeInt(0);
mplew.writeLong(getTime(System.currentTimeMillis()));
return mplew.getPacket();
}

public static MaplePacket enableActions() {
return updatePlayerStats(EMPTY_STATUPDATE, true);
}

public static MaplePacket updatePlayerStats(List<Pair<MapleStat, Integer>> stats) {
return updatePlayerStats(stats, false);
}

Replace AddItemInfo packet with:
Code:
private static void addItemInfo(MaplePacketLittleEndianWriter mplew, IItem item, boolean zeroPosition, boolean leaveOut) {
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
boolean ring = false;
IEquip equip = null;
if (item.getType() == IItem.EQUIP) {
equip = (IEquip) item;
if (equip.getRingId() > -1)
ring = true;
}
byte pos = item.getPosition();
boolean masking = false;
boolean equipped = false;
if (zeroPosition) {
if (!leaveOut)
mplew.write(0);
} else if (pos <= (byte) -1) {
pos *= -1;
if (pos > 100 || ring) {
masking = true;
mplew.write(0);
mplew.write(pos - 100);
} else
mplew.write(pos);
equipped = true;
} else
mplew.write(item.getPosition());
if (item.getPetId() > -1)
mplew.write(3);
else
mplew.write(item.getType());
mplew.writeInt(item.getItemId());
if (ring) {
mplew.write(1);
mplew.writeInt(equip.getRingId());
mplew.writeInt(0);
}
if (item.getPetId() > -1) {
MaplePet pet = MaplePet.loadFromDb(item.getItemId(), item.getPosition(), item.getPetId());
String petname = pet.getName();
mplew.write(1);
mplew.writeInt(item.getPetId());
mplew.writeInt(0);
mplew.write(0);
mplew.write(ITEM_MAGIC);
mplew.write(HexTool.getByteArrayFromHexString("BB 46 E6 17 02"));
if (petname.length() > 13)
petname = petname.substring(0, 13);
mplew.writeAsciiString(petname);
for (int i = petname.length(); i < 13; i++)
mplew.write(0);
mplew.write(pet.getLevel());
mplew.writeShort(pet.getCloseness());
mplew.write(pet.getFullness());

mplew.writeLong(getKoreanTimestamp((long) (System.currentTimeMillis() * 1.2)));
mplew.writeInt(0);

return;
}
if (masking && !ring) {

mplew.write(HexTool.getByteArrayFromHexString("01 41 B4 38 00 00 00 00 00 80 20 6F"));
addExpirationTime(mplew, 0, false);
} else if (ring)
mplew.writeLong(getKoreanTimestamp((long) (System.currentTimeMillis() * 1.2)));
else {
mplew.writeShort(0);
mplew.write(ITEM_MAGIC);
addExpirationTime(mplew, 0, false);
}
if (item.getType() == IItem.EQUIP) {
mplew.write(equip.getUpgradeSlots());
mplew.write(equip.getLevel());
mplew.writeShort(equip.getStr()); // str

mplew.writeShort(equip.getDex()); // dex

mplew.writeShort(equip.getInt()); // int

mplew.writeShort(equip.getLuk()); // luk

mplew.writeShort(equip.getHp()); // hp

mplew.writeShort(equip.getMp()); // mp

mplew.writeShort(equip.getWatk()); // watk

mplew.writeShort(equip.getMatk()); // matk

mplew.writeShort(equip.getWdef()); // wdef

mplew.writeShort(equip.getMdef()); // mdef

mplew.writeShort(equip.getAcc()); // accuracy

mplew.writeShort(equip.getAvoid()); // avoid

mplew.writeShort(equip.getHands()); // hands

mplew.writeShort(equip.getSpeed()); // speed

mplew.writeShort(equip.getJump()); // jump

mplew.writeMapleAsciiString(equip.getOwner());

// 0 normal; 1 locked
mplew.write(equip.getLocked());

if (ring && !equipped)
mplew.write(0);

if (!masking && !ring) {
mplew.write(0);
mplew.writeLong(0); // values of these don't seem to matter at all
}
} else {
mplew.writeShort(item.getQuantity());
mplew.writeMapleAsciiString(item.getOwner());
mplew.writeShort(0); // this seems to end the item entry
// but only if its not a THROWING STAR Smile)9 O.O!

if (ii.isThrowingStar(item.getItemId()) || ii.isBullet(item.getItemId()))
mplew.write(HexTool.getByteArrayFromHexString("02 00 00 00 54 00 00 34"));
}
}

Under Collections.sort(equipped) add

Code:
List<MapleRing> rings = new ArrayList<MapleRing>();
for (Item item : equipped)
if (((IEquip) item).getRingId() > -1)
rings.add(MapleRing.loadFromDb(((IEquip) item).getRingId()));
Collections.sort(rings);
if (rings.size() > 0) {
mplew.write(0);
for (MapleRing ring : rings)
if (ring != null) {
mplew.write(1);
mplew.writeInt(ring.getRingId());
mplew.writeInt(0);
mplew.writeInt(ring.getPartnerRingId());
mplew.writeInt(0);
mplew.writeInt(ring.getItemId());
}
mplew.writeShort(0);
} else
mplew.writeInt(0);

return mplew.getPacket();

}

Under collections.sort(equipped) in UpdateCharLook add
Code:
List<MapleRing> rings = new ArrayList<MapleRing>();
for (Item item : equipped)
if (((IEquip) item).getRingId() > -1)
rings.add(MapleRing.loadFromDb(((IEquip) item).getRingId()));
Collections.sort(rings);

if (rings.size() > 0)
for (MapleRing ring : rings) {
mplew.write(1);
mplew.writeInt(ring.getRingId());
mplew.writeInt(0);
mplew.writeInt(ring.getPartnerRingId());
mplew.writeInt(0);
mplew.writeInt(ring.getItemId());
}
else
mplew.write(0);
mplew.writeShort(0);

return mplew.getPacket();
}

RingActionHandler:
Code:
package net.sf.odinms.net.channel.handler;

import net.sf.odinms.client.MapleClient;
import net.sf.odinms.client.MapleCharacter;
import net.sf.odinms.net.AbstractMaplePacketHandler;
import net.sf.odinms.tools.data.input.SeekableLittleEndianAccessor;
import net.sf.odinms.scripting.npc.NPCScriptManager;
import net.sf.odinms.scripting.npc.Marriage;

public class RingActionHandler extends AbstractMaplePacketHandler {

private static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(RingActionHandler.class);

@Override
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {

byte mode = slea.readByte();
MapleCharacter player = c.getPlayer();
switch (mode) {
case 0x00: //Send
String partnerName = slea.readMapleAsciiString();
MapleCharacter partner = c.getChannelServer().getPlayerStorage().getCharacterByName(partnerName);
if (partnerName.equalsIgnoreCase(player.getName())) {
player.dropMessage(1, "You cannot put your own name in it.");
} else if (partner == null) {
player.dropMessage(1, partnerName + " was not found on this channel. If you are both logged in, please make sure you are in the same channel.");
} else if (partner.getGender() == player.getGender()) {
player.dropMessage(1, "Your partner is the same gender as you.");
}
break;
case 0x01: //Cancel send
player.dropMessage(1, "You've cancelled the request.");
break;
case 0x03: //Drop Ring
default:
log.info("Unhandled Ring Packet : " + slea.toString());
break;
}
}
}

MapleRing:
Code:
package net.sf.odinms.client;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import net.sf.odinms.database.DatabaseConnection;
import net.sf.odinms.server.MapleInventoryManipulator;
import net.sf.odinms.tools.MaplePacketCreator;

public class MapleRing implements Comparable<MapleRing> {

private int ringId;
private int ringId2;
private int partnerId;
private int itemId;
private String partnerName;
private boolean equipped;

private MapleRing(int id, int id2, int partnerId, int itemid, String partnername) {
this.ringId = id;
this.ringId2 = id2;
this.partnerId = partnerId;
this.itemId = itemid;
this.partnerName = partnername;
}

public static MapleRing loadFromDb(int ringId) {
try {
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT * FROM rings WHERE id = ?");
ps.setInt(1, ringId);
ResultSet rs = ps.executeQuery();
rs.next();
MapleRing ret = new MapleRing(ringId, rs.getInt("partnerRingId"), rs.getInt("partnerChrId"), rs.getInt("itemid"), rs.getString("partnerName"));
rs.close();
ps.close();
return ret;
} catch (Exception ex) {
return null;
}
}

public static int[] createRing(MapleClient c, int itemid, int chrId, String chrName, int partnerId, String partnername, String message) {
try {
MapleCharacter chr = c.getChannelServer().getPlayerStorage().getCharacterById(partnerId);
if (chr == null) {
int[] ret_ = new int[2];
ret_[0] = -1;
ret_[1] = -1;
return ret_;
}
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("INSERT INTO rings (itemid, partnerChrId, partnername) VALUES (?, ?, ?)");
ps.setInt(1, itemid);
ps.setInt(2, partnerId);
ps.setString(3, partnername);
ps.executeUpdate();
ResultSet rs = ps.getGeneratedKeys();
rs.next();
int[] ret = new int[2];
ret[0] = rs.getInt(1);
rs.close();
ps.close();
ps = con.prepareStatement("INSERT INTO rings (itemid, partnerRingId, partnerChrId, partnername) VALUES (?, ?, ?, ?)");
ps.setInt(1, itemid);
ps.setInt(2, ret[0]);
ps.setInt(3, chrId);
ps.setString(4, chrName);
ps.executeUpdate();
rs = ps.getGeneratedKeys();
rs.next();
ret[1] = rs.getInt(1);
rs.close();
ps.close();
ps = con.prepareStatement("UPDATE rings SET partnerRingId = ? WHERE id = ?");
ps.setInt(1, ret[1]);
ps.setInt(2, ret[0]);
ps.executeUpdate();
ps.close();
MapleCharacter player = c.getPlayer();
MapleInventoryManipulator.addRing(player, itemid, ret[0]);
MapleInventoryManipulator.addRing(chr, itemid, ret[1]);
c.getSession().write(MaplePacketCreator.getCharInfo(player));
if (message == null) {
player.getMap().removePlayer(player);
player.getMap().addPlayer(player);
chr.getClient().getSession().write(MaplePacketCreator.getCharInfo(chr));
chr.getMap().removePlayer(chr);
chr.getMap().addPlayer(chr);
}
chr.dropMessage(5, "You have received a ring from " + player.getName() + ". Please log out and log back in again if it does not work correctly.");
if (message != null) {
chr.getClient().getSession().write(MaplePacketCreator.serverNotice(5, "The message that came with the ring is: " + message));
}
return ret;
} catch (Exception ex) {
int[] ret = new int[2];
ret[0] = -1;
ret[1] = -1;
return ret;
}
}

public int getRingId() {
return ringId;
}

public int getPartnerRingId() {
return ringId2;
}

public int getPartnerChrId() {
return partnerId;
}

public int getItemId() {
return itemId;
}

public String getPartnerName() {
return partnerName;
}

public boolean isEquipped() {
return equipped;
}

public void setEquipped(boolean equipped) {
this.equipped = equipped;
}

@Override
public boolean equals(Object o) {
if (o instanceof MapleRing) {
return (((MapleRing) o).getRingId() == getRingId());
}
return false;
}

@Override
public int hashCode() {
int hash = 5;
hash = 53 * hash + this.ringId;
return hash;
}

@Override
public int compareTo(MapleRing other) {
if (ringId < other.getRingId()) {
return -1;
} else if (ringId == other.getRingId()) {
return 0;
} else {
return 1;
}
}
}

MapleCharacter:
Code:
public int getRingRequested() {
return this.ringRequest;
}

public void setRingRequested(int set) {
ringRequest = set;
}

Recvops:
Code:
RING_ACTION = 0x7D

Buying rings from CS(BuyCSItemHandler) ujnder public void handlePacket:
Code:
if (slea.available() > 22) {
slea.skip(1);
int dob = slea.readInt();
int payment = slea.readByte();
slea.skip(3);
int snCS = slea.readInt();
CashItemInfo ring = CashItemFactory.getItem(snCS);
int userLength = slea.readByte();
slea.skip(1);
String partner = slea.readAsciiString(userLength);
slea.skip(2);
int left = (int) slea.available();
String text = slea.readAsciiString(left);
MapleCharacter partnerChar = c.getChannelServer().getPlayerStorage().getCharacterByName(partner);
if (partnerChar == null) {
c.getPlayer().getClient().getSession().write(MaplePacketCreator.serverNotice(1, "The partner you specified cannot be found.\r\nPlease make sure your partner is online and in the same channel."));
} else {
c.getSession().write(MaplePacketCreator.showBoughtCSItem(ring.getId()));
c.getPlayer().modifyCSPoints(payment, -ring.getPrice());
MapleRing.createRing(c, ring.getId(), c.getPlayer().getId(), c.getPlayer().getName(), partnerChar.getId(), partnerChar.getName(), text);
c.getPlayer().getClient().getSession().write(MaplePacketCreator.serverNotice(1, "Successfully created a ring for both you and your partner!\r\nIf you cannot see the effect, please try relogging."));
}
c.getSession().write(MaplePacketCreator.showNXMapleTokens(c.getPlayer()));
c.getSession().write(MaplePacketCreator.enableCSUse0());
c.getSession().write(MaplePacketCreator.enableCSUse1());
c.getSession().write(MaplePacketCreator.enableCSUse2());
c.getSession().write(MaplePacketCreator.enableCSUse3());
} else {
int action = slea.readByte();

Enjoy~

View user profile http://excellzone.mrforum.net

View previous topic View next topic Back to top Message [Page 1 of 1]


Permissions in this forum:
You cannot reply to topics in this forum