public static final void Character_WithoutSecondPassword( final LittleEndianAccessor slea, final MapleClient c, final boolean haspic, final boolean view) { slea.readByte(); // 1? slea.readByte(); // 1? final int charId = slea.readInt(); if (view) { c.setChannel(1); c.setWorld(slea.readInt()); } final String currentpw = c.getSecondPassword(); if (!c.isLoggedIn() || loginFailCount(c) || (currentpw != null && (!currentpw.equals("") || haspic)) || !c.login_Auth(charId) || ChannelServer.getInstance(c.getChannel()) == null || c.getWorld() != 0) { // TODOO: MULTI WORLDS c.getSession().close(); return; } c.updateMacs(slea.readMapleAsciiString()); slea.readMapleAsciiString(); if (slea.available() != 0) { final String setpassword = slea.readMapleAsciiString(); if (setpassword.length() >= 6 && setpassword.length() <= 16) { c.setSecondPassword(setpassword); c.updateSecondPassword(); } else { c.getSession().write(LoginPacket.secondPwError((byte) 0x14)); return; } } else if (GameConstants.GMS && haspic) { return; } if (c.getIdleTask() != null) { c.getIdleTask().cancel(true); } final String s = c.getSessionIPAddress(); LoginServer.putLoginAuth( charId, s.substring(s.indexOf('/') + 1, s.length()), c.getTempIP(), c.getChannel()); c.updateLoginState(MapleClient.LOGIN_SERVER_TRANSITION, s); c.getSession() .write( CField.getServerIP( c, Integer.parseInt(ChannelServer.getInstance(c.getChannel()).getIP().split(":")[1]), charId)); }
public static final void updateCCards(LittleEndianAccessor slea, MapleClient c) { if ((slea.available() != 36) || (!c.isLoggedIn())) { c.getSession().close(true); return; } Map<Integer, Integer> cids = new LinkedHashMap(); for (int i = 1; i <= 9; i++) { int charId = slea.readInt(); if (((!c.login_Auth(charId)) && (charId != 0)) || (ChannelServer.getInstance(c.getChannel()) == null) || (c.getWorld() != 0)) { c.getSession().close(true); return; } cids.put(Integer.valueOf(i), Integer.valueOf(charId)); } c.updateCharacterCards(cids); }
public static final void updateCCards(final LittleEndianAccessor slea, final MapleClient c) { if (slea.available() != 24 || !c.isLoggedIn()) { c.getSession().close(); return; } final Map<Integer, Integer> cids = new LinkedHashMap<>(); for (int i = 1; i <= 6; i++) { // 6 chars final int charId = slea.readInt(); if ((!c.login_Auth(charId) && charId != 0) || ChannelServer.getInstance(c.getChannel()) == null || c.getWorld() != 0) { c.getSession().close(); return; } cids.put(i, charId); } c.updateCharacterCards(cids); }
/* * Ex. * 0A 00 31 30 32 30 33 30 34 30 35 30 to mapleasciistring */ public static void main(String[] args) { String packet = "0A 00 31 30 40 30 32 30 33 30 34 30 35 30"; byte[] bytes = getByteArrayFromHexString(packet); final LittleEndianAccessor slea = new LittleEndianAccessor(new ByteArrayByteStream((byte[]) bytes)); byte next; short next_short; int next_int; long next_long; for (int length = 0; length < bytes.length; length++) { if (slea.readInt() % 100 < 10 && slea.available() >= 4) { System.out.println(slea.readLastInt()); } else { slea.unReadInt(); System.out.println(slea.readByte()); } } // System.out.println(slea.readMapleAsciiString()); }
public static void MTSOperation(final LittleEndianAccessor slea, final MapleClient c) { final MTSCart cart = MTSStorage.getInstance().getCart(c.getPlayer().getId()); // System.out.println(slea.toString()); if (slea.available() <= 0) { doMTSPackets(cart, c); return; } final byte op = slea.readByte(); if (op == 2) { // put up for sale final byte invType = slea.readByte(); // 1 = equip 2 = everything else if (invType != 1 && invType != 2) { // pet? c.getSession().write(MTSCSPacket.getMTSFailSell()); doMTSPackets(cart, c); return; } final int itemid = slea.readInt(); // itemid if (slea.readByte() != 0) { c.getSession().write(MTSCSPacket.getMTSFailSell()); doMTSPackets(cart, c); return; // we don't like uniqueIDs } slea.skip(12); // expiration, -1, don't matter short stars = 1, quantity = 1; byte slot = 0; if (invType == 1) { slea.skip(32); } else { stars = slea.readShort(); // the entire quantity of the item } slea.readMapleAsciiString(); // owner // again? =/ if (invType == 1) { slea.skip(50); slot = (byte) slea.readInt(); slea.skip(4); // skip the quantity int, equips are always 1 } else { slea.readShort(); // flag if (GameConstants.isThrowingStar(itemid) || GameConstants.isBullet(itemid)) { slea.skip(8); // recharge ID thing } slot = (byte) slea.readInt(); if (GameConstants.isThrowingStar(itemid) || GameConstants.isBullet(itemid)) { quantity = stars; // this is due to stars you need to use the entire quantity, not specified slea.skip(4); // so just skip the quantity int } else { quantity = (short) slea.readInt(); // specified quantity } } final int price = slea.readInt(); final MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance(); final MapleInventoryType type = GameConstants.getInventoryType(itemid); final Item item = c.getPlayer().getInventory(type).getItem(slot).copy(); if (ii.isCash(itemid) || quantity <= 0 || item == null || item.getQuantity() <= 0 || item.getItemId() != itemid || item.getUniqueId() > 0 || item.getQuantity() < quantity || price < ServerConstants.MIN_MTS || c.getPlayer().getMeso() < ServerConstants.MTS_MESO || cart.getNotYetSold().size() >= 10 || ii.isDropRestricted(itemid) || ii.isAccountShared(itemid) || item.getExpiration() > -1 || item.getFlag() > 0) { c.getSession().write(MTSCSPacket.getMTSFailSell()); doMTSPackets(cart, c); return; } if (type == MapleInventoryType.EQUIP) { final Equip eq = (Equip) item; if (eq.getState() > 0 || eq.getEnhance() > 0 || eq.getDurability() > -1) { c.getSession().write(MTSCSPacket.getMTSFailSell()); doMTSPackets(cart, c); return; } } if (quantity >= 50 && item.getItemId() == 2340000) { c.setMonitored(true); // hack check } final long expiration = (System.currentTimeMillis() + (7L * 24 * 60 * 60 * 1000)); item.setQuantity(quantity); MTSStorage.getInstance() .addToBuyNow( cart, item, price, c.getPlayer().getId(), c.getPlayer().getName(), expiration); MapleInventoryManipulator.removeFromSlot(c, type, slot, quantity, false); c.getPlayer().gainMeso(-ServerConstants.MTS_MESO, false); c.getSession().write(MTSCSPacket.getMTSConfirmSell()); } else if (op == 5) { // change page/tab cart.changeInfo(slea.readInt(), slea.readInt(), slea.readInt()); } else if (op == 6) { // search cart.changeInfo(slea.readInt(), slea.readInt(), 0); slea.readInt(); // always 0? cart.changeCurrentView( MTSStorage.getInstance() .getSearch( slea.readInt() > 0, slea.readMapleAsciiString(), cart.getType(), cart.getTab())); } else if (op == 7) { // cancel sale if (!MTSStorage.getInstance().removeFromBuyNow(slea.readInt(), c.getPlayer().getId(), true)) { c.getSession().write(MTSCSPacket.getMTSFailCancel()); } else { c.getSession().write(MTSCSPacket.getMTSConfirmCancel()); sendMTSPackets(cart, c, true); return; } } else if (op == 8) { // transfer item final int id = Integer.MAX_VALUE - slea.readInt(); // fake id if (id >= cart.getInventory().size()) { c.getPlayer().dropMessage(1, "Please try it again later."); sendMTSPackets(cart, c, true); return; } final Item item = cart.getInventory().get(id); // by index // System.out.println("NumItems: " + cart.getInventory().size() + ", ID: " + id + ", // ItemExists?: " + (item != null)); if (item != null && item.getQuantity() > 0 && MapleInventoryManipulator.checkSpace( c, item.getItemId(), item.getQuantity(), item.getOwner())) { Item item_ = item.copy(); short pos = MapleInventoryManipulator.addbyItem(c, item_, true); if (pos >= 0) { if (item_.getPet() != null) { item_.getPet().setInventoryPosition(pos); c.getPlayer().addPet(item_.getPet()); } cart.removeFromInventory(item); c.getSession() .write( MTSCSPacket.getMTSConfirmTransfer( GameConstants.getInventoryType(item_.getItemId()).getType(), pos)); // IF this is actually pos and pos sendMTSPackets(cart, c, true); return; } else { // System.out.println("addByItem is less than 0"); c.getSession().write(MTSCSPacket.getMTSFailBuy()); } } else { // System.out.println("CheckSpace return false"); c.getSession().write(MTSCSPacket.getMTSFailBuy()); } } else if (op == 9) { // add to cart final int id = slea.readInt(); if (MTSStorage.getInstance().checkCart(id, c.getPlayer().getId()) && cart.addToCart(id)) { c.getSession().write(MTSCSPacket.addToCartMessage(false, false)); } else { c.getSession().write(MTSCSPacket.addToCartMessage(true, false)); } } else if (op == 10) { // delete from cart final int id = slea.readInt(); if (cart.getCart().contains(id)) { cart.removeFromCart(id); c.getSession().write(MTSCSPacket.addToCartMessage(false, true)); } else { c.getSession().write(MTSCSPacket.addToCartMessage(true, true)); } } else if (op == 16 || op == 17) { // buyNow, buy from cart final MTSItemInfo mts = MTSStorage.getInstance().getSingleItem(slea.readInt()); if (mts != null && mts.getCharacterId() != c.getPlayer().getId()) { if (c.getPlayer().getCSPoints(1) > mts.getRealPrice()) { if (MTSStorage.getInstance() .removeFromBuyNow(mts.getId(), c.getPlayer().getId(), false)) { c.getPlayer().modifyCSPoints(1, -mts.getRealPrice(), false); MTSStorage.getInstance().getCart(mts.getCharacterId()).increaseOwedNX(mts.getPrice()); c.getSession().write(MTSCSPacket.getMTSConfirmBuy()); sendMTSPackets(cart, c, true); return; } else { c.getSession().write(MTSCSPacket.getMTSFailBuy()); } } else { c.getSession().write(MTSCSPacket.getMTSFailBuy()); } } else { c.getSession().write(MTSCSPacket.getMTSFailBuy()); } } else if (c.getPlayer().isAdmin()) { // System.out.println("New MTS Op " + op + ", \n" + slea.toString()); } doMTSPackets(cart, c); }
public static final void SummonPVP(final LittleEndianAccessor slea, final MapleClient c) { final MapleCharacter chr = c.getPlayer(); if (chr == null || chr.isHidden() || !chr.isAlive() || chr.hasBlockedInventory() || chr.getMap() == null || !chr.inPVP() || !chr.getEventInstance().getProperty("started").equals("1")) { return; } final MapleMap map = chr.getMap(); final MapleMapObject obj = map.getMapObject(slea.readInt(), MapleMapObjectType.SUMMON); if (obj == null || !(obj instanceof MapleSummon)) { chr.dropMessage(5, "The summon has disappeared."); return; } int tick = -1; if (slea.available() == 27) { slea.skip(23); tick = slea.readInt(); } final MapleSummon summon = (MapleSummon) obj; if (summon.getOwnerId() != chr.getId() || summon.getSkillLevel() <= 0) { chr.dropMessage(5, "Error."); return; } final Skill skil = SkillFactory.getSkill(summon.getSkill()); final MapleStatEffect effect = skil.getEffect(summon.getSkillLevel()); final int lvl = Integer.parseInt(chr.getEventInstance().getProperty("lvl")); final int type = Integer.parseInt(chr.getEventInstance().getProperty("type")); final int ourScore = Integer.parseInt(chr.getEventInstance().getProperty(String.valueOf(chr.getId()))); int addedScore = 0; final boolean magic = skil.isMagic(); boolean killed = false, didAttack = false; double maxdamage = lvl == 3 ? chr.getStat().getCurrentMaxBasePVPDamageL() : chr.getStat().getCurrentMaxBasePVPDamage(); maxdamage *= (effect.getDamage() + chr.getStat().getDamageIncrease(summon.getSkill())) / 100.0; int mobCount = 1, attackCount = 1, ignoreDEF = chr.getStat().ignoreTargetDEF; final SummonSkillEntry sse = SkillFactory.getSummonData(summon.getSkill()); if (summon.getSkill() / 1000000 != 35 && summon.getSkill() != 33101008 && sse == null) { chr.dropMessage(5, "Error in processing attack."); return; } Point lt, rb; if (sse != null) { if (sse.delay > 0) { if (tick != -1) { summon.CheckSummonAttackFrequency(chr, tick); chr.updateTick(tick); } else { summon.CheckPVPSummonAttackFrequency(chr); } chr.getCheatTracker().checkSummonAttack(); } mobCount = sse.mobCount; attackCount = sse.attackCount; lt = sse.lt; rb = sse.rb; } else { lt = new Point(-100, -100); rb = new Point(100, 100); } final Rectangle box = MapleStatEffect.calculateBoundingBox(chr.getTruePosition(), chr.isFacingLeft(), lt, rb, 0); List<AttackPair> ourAttacks = new ArrayList<AttackPair>(); List<Pair<Integer, Boolean>> attacks; maxdamage *= chr.getStat().dam_r / 100.0; for (MapleMapObject mo : chr.getMap().getCharactersIntersect(box)) { final MapleCharacter attacked = (MapleCharacter) mo; if (attacked.getId() != chr.getId() && attacked.isAlive() && !attacked.isHidden() && (type == 0 || attacked.getTeam() != chr.getTeam())) { double rawDamage = maxdamage / Math.max( 0, ((magic ? attacked.getStat().mdef : attacked.getStat().wdef) * Math.max(1.0, 100.0 - ignoreDEF) / 100.0) * (type == 3 ? 0.1 : 0.25)); if (attacked.getBuffedValue(MapleBuffStat.INVINCIBILITY) != null || PlayersHandler.inArea(attacked)) { rawDamage = 0; } rawDamage += (rawDamage * chr.getDamageIncrease(attacked.getId()) / 100.0); rawDamage *= attacked.getStat().mesoGuard / 100.0; rawDamage = attacked.modifyDamageTaken(rawDamage, attacked).left; final double min = (rawDamage * chr.getStat().trueMastery / 100); attacks = new ArrayList<Pair<Integer, Boolean>>(attackCount); int totalMPLoss = 0, totalHPLoss = 0; for (int i = 0; i < attackCount; i++) { int mploss = 0; double ourDamage = Randomizer.nextInt((int) Math.abs(Math.round(rawDamage - min)) + 1) + min; if (attacked.getStat().dodgeChance > 0 && Randomizer.nextInt(100) < attacked.getStat().dodgeChance) { ourDamage = 0; // i dont think level actually matters or it'd be too op // } else if (attacked.getLevel() > chr.getLevel() && Randomizer.nextInt(100) < // (attacked.getLevel() - chr.getLevel())) { // ourDamage = 0; } if (attacked.getBuffedValue(MapleBuffStat.MAGIC_GUARD) != null) { mploss = (int) Math.min( attacked.getStat().getMp(), (ourDamage * attacked.getBuffedValue(MapleBuffStat.MAGIC_GUARD).doubleValue() / 100.0)); } ourDamage -= mploss; if (attacked.getBuffedValue(MapleBuffStat.INFINITY) != null) { mploss = 0; } attacks.add(new Pair<Integer, Boolean>((int) Math.floor(ourDamage), false)); totalHPLoss += Math.floor(ourDamage); totalMPLoss += mploss; } attacked.addMPHP(-totalHPLoss, -totalMPLoss); ourAttacks.add(new AttackPair(attacked.getId(), attacked.getPosition(), attacks)); attacked.getCheatTracker().setAttacksWithoutHit(false); if (totalHPLoss > 0) { didAttack = true; } if (attacked.getStat().getHPPercent() <= 20) { SkillFactory.getSkill(attacked.getStat().getSkillByJob(93, attacked.getJob())) .getEffect(1) .applyTo(attacked); } if (effect != null) { if (effect.getMonsterStati().size() > 0 && effect.makeChanceResult()) { for (Map.Entry<MonsterStatus, Integer> z : effect.getMonsterStati().entrySet()) { MapleDisease d = MonsterStatus.getLinkedDisease(z.getKey()); if (d != null) { attacked.giveDebuff(d, z.getValue(), effect.getDuration(), d.getDisease(), 1); } } } effect.handleExtraPVP(chr, attacked); } chr.getClient() .getSession() .write( CField.getPVPHPBar( attacked.getId(), attacked.getStat().getHp(), attacked.getStat().getCurrentMaxHp())); addedScore += (totalHPLoss / 100) + (totalMPLoss / 100); // ive NO idea if (!attacked.isAlive()) { killed = true; } if (ourAttacks.size() >= mobCount) { break; } } } if (killed || addedScore > 0) { chr.getEventInstance().addPVPScore(chr, addedScore); chr.getClient().getSession().write(CField.getPVPScore(ourScore + addedScore, killed)); } if (didAttack) { chr.getMap() .broadcastMessage( SummonPacket.pvpSummonAttack( chr.getId(), chr.getLevel(), summon.getObjectId(), summon.isFacingLeft() ? 4 : 0x84, summon.getTruePosition(), ourAttacks)); if (!summon.isMultiAttack()) { chr.getMap().broadcastMessage(SummonPacket.removeSummon(summon, true)); chr.getMap().removeMapObject(summon); chr.removeVisibleMapObject(summon); chr.removeSummon(summon); if (summon.getSkill() != 35121011) { chr.cancelEffectFromBuffStat(MapleBuffStat.SUMMON); } } } }
public static final void HandleAlliance( final LittleEndianAccessor slea, final MapleClient c, boolean denied) { if (c.getPlayer().getGuildId() <= 0) { c.getSession().write(CWvsContext.enableActions()); return; } final MapleGuild gs = World.Guild.getGuild(c.getPlayer().getGuildId()); if (gs == null) { c.getSession().write(CWvsContext.enableActions()); return; } // System.out.println("Unhandled GuildAlliance \n" + slea.toString()); byte op = slea.readByte(); if (c.getPlayer().getGuildRank() != 1 && op != 1) { // only updating doesn't need guild leader return; } if (op == 22) { denied = true; } int leaderid = 0; if (gs.getAllianceId() > 0) { leaderid = World.Alliance.getAllianceLeader(gs.getAllianceId()); } // accept invite, and deny invite don't need allianceid. if (op != 4 && !denied) { if (gs.getAllianceId() <= 0 || leaderid <= 0) { return; } } else if (leaderid > 0 || gs.getAllianceId() > 0) { // infact, if they have allianceid it's suspicious return; } if (denied) { DenyInvite(c, gs); return; } MapleCharacter chr; int inviteid; switch (op) { case 1: // load... must be in world op for (byte[] pack : World.Alliance.getAllianceInfo(gs.getAllianceId(), false)) { if (pack != null) { c.getSession().write(pack); } } break; case 3: // invite final int newGuild = World.Guild.getGuildLeader(slea.readMapleAsciiString()); if (newGuild > 0 && c.getPlayer().getAllianceRank() == 1 && leaderid == c.getPlayer().getId()) { chr = c.getChannelServer().getPlayerStorage().getCharacterById(newGuild); if (chr != null && chr.getGuildId() > 0 && World.Alliance.canInvite(gs.getAllianceId())) { chr.getClient() .getSession() .write( AlliancePacket.sendAllianceInvite( World.Alliance.getAlliance(gs.getAllianceId()).getName(), c.getPlayer())); World.Guild.setInvitedId(chr.getGuildId(), gs.getAllianceId()); } else { c.getPlayer() .dropMessage(1, "Make sure the leader of the guild is online and in your channel."); } } else { c.getPlayer() .dropMessage( 1, "That Guild was not found. Please enter the correct Guild Name. (Not the player name)"); } break; case 4: // accept invite... guildid that invited(int, a/b check) -> guildname that was // invited? but we dont care about that inviteid = World.Guild.getInvitedId(c.getPlayer().getGuildId()); if (inviteid > 0) { if (!World.Alliance.addGuildToAlliance(inviteid, c.getPlayer().getGuildId())) { c.getPlayer().dropMessage(5, "An error occured when adding guild."); } World.Guild.setInvitedId(c.getPlayer().getGuildId(), 0); } break; case 2: // leave; nothing case 6: // expel, guildid(int) -> allianceid(don't care, a/b check) final int gid; if (op == 6 && slea.available() >= 4) { gid = slea.readInt(); if (slea.available() >= 4 && gs.getAllianceId() != slea.readInt()) { break; } } else { gid = c.getPlayer().getGuildId(); } if (c.getPlayer().getAllianceRank() <= 2 && (c.getPlayer().getAllianceRank() == 1 || c.getPlayer().getGuildId() == gid)) { if (!World.Alliance.removeGuildFromAlliance( gs.getAllianceId(), gid, c.getPlayer().getGuildId() != gid)) { c.getPlayer().dropMessage(5, "An error occured when removing guild."); } } break; case 7: // change leader if (c.getPlayer().getAllianceRank() == 1 && leaderid == c.getPlayer().getId()) { if (!World.Alliance.changeAllianceLeader(gs.getAllianceId(), slea.readInt())) { c.getPlayer().dropMessage(5, "An error occured when changing leader."); } } break; case 8: // title update if (c.getPlayer().getAllianceRank() == 1 && leaderid == c.getPlayer().getId()) { String[] ranks = new String[5]; for (int i = 0; i < 5; i++) { ranks[i] = slea.readMapleAsciiString(); } World.Alliance.updateAllianceRanks(gs.getAllianceId(), ranks); } break; case 9: if (c.getPlayer().getAllianceRank() <= 2) { if (!World.Alliance.changeAllianceRank( gs.getAllianceId(), slea.readInt(), slea.readByte())) { c.getPlayer().dropMessage(5, "An error occured when changing rank."); } } break; case 10: // notice update if (c.getPlayer().getAllianceRank() <= 2) { final String notice = slea.readMapleAsciiString(); if (notice.length() > 100) { break; } World.Alliance.updateAllianceNotice(gs.getAllianceId(), notice); } break; default: System.out.println("Unhandled GuildAlliance op: " + op + ", \n" + slea.toString()); break; } // c.getSession().write(CWvsContext.enableActions()); }