Search in sources :

Example 11 with Channel

use of net.server.channel.Channel in project HeavenMS by ronancpl.

the class MTSHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    if (!c.getPlayer().getCashShop().isOpened()) {
        return;
    }
    if (slea.available() > 0) {
        byte op = slea.readByte();
        if (op == 2) {
            // put item up for sale
            byte itemtype = slea.readByte();
            int itemid = slea.readInt();
            slea.readShort();
            slea.skip(7);
            short stars = 1;
            if (itemtype == 1) {
                slea.skip(32);
            } else {
                stars = slea.readShort();
            }
            // another useless thing (owner)
            slea.readMapleAsciiString();
            if (itemtype == 1) {
                slea.skip(32);
            } else {
                slea.readShort();
            }
            short slot;
            short quantity;
            if (itemtype != 1) {
                if (itemid / 10000 == 207 || itemid / 10000 == 233) {
                    slea.skip(8);
                }
                slot = (short) slea.readInt();
            } else {
                slot = (short) slea.readInt();
            }
            if (itemtype != 1) {
                if (itemid / 10000 == 207 || itemid / 10000 == 233) {
                    quantity = stars;
                    slea.skip(4);
                } else {
                    quantity = (short) slea.readInt();
                }
            } else {
                quantity = (byte) slea.readInt();
            }
            int price = slea.readInt();
            if (itemtype == 1) {
                quantity = 1;
            }
            if (quantity < 0 || price < 110 || c.getPlayer().getItemQuantity(itemid, false) < quantity) {
                return;
            }
            MapleInventoryType invType = ItemConstants.getInventoryType(itemid);
            Item i = c.getPlayer().getInventory(invType).getItem(slot).copy();
            if (i != null && c.getPlayer().getMeso() >= 5000) {
                Connection con = null;
                try {
                    con = DatabaseConnection.getConnection();
                    PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) FROM mts_items WHERE seller = ?");
                    ps.setInt(1, c.getPlayer().getId());
                    ResultSet rs = ps.executeQuery();
                    if (rs.next()) {
                        if (rs.getInt(1) > 10) {
                            // They have more than 10 items up for sale already!
                            c.getPlayer().dropMessage(1, "You already have 10 items up for auction!");
                            c.announce(getMTS(1, 0, 0));
                            c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
                            c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
                            rs.close();
                            ps.close();
                            return;
                        }
                    }
                    rs.close();
                    ps.close();
                    Calendar calendar = Calendar.getInstance();
                    int year;
                    int month;
                    int day;
                    int oldmax = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
                    int oldday = calendar.get(Calendar.DAY_OF_MONTH) + 7;
                    if (oldmax < oldday) {
                        if (calendar.get(Calendar.MONTH) + 2 > 12) {
                            year = calendar.get(Calendar.YEAR) + 1;
                            month = 1;
                            calendar.set(year, month, 1);
                            day = oldday - oldmax;
                        } else {
                            month = calendar.get(Calendar.MONTH) + 2;
                            year = calendar.get(Calendar.YEAR);
                            calendar.set(year, month, 1);
                            day = oldday - oldmax;
                        }
                    } else {
                        day = calendar.get(Calendar.DAY_OF_MONTH) + 7;
                        month = calendar.get(Calendar.MONTH);
                        year = calendar.get(Calendar.YEAR);
                    }
                    String date = year + "-";
                    if (month < 10) {
                        date += "0" + month + "-";
                    } else {
                        date += month + "-";
                    }
                    if (day < 10) {
                        date += "0" + day;
                    } else {
                        date += day + "";
                    }
                    if (!i.getInventoryType().equals(MapleInventoryType.EQUIP)) {
                        Item item = (Item) i;
                        ps = con.prepareStatement("INSERT INTO mts_items (tab, type, itemid, quantity, seller, price, owner, sellername, sell_ends) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
                        ps.setInt(1, 1);
                        ps.setInt(2, (int) invType.getType());
                        ps.setInt(3, item.getItemId());
                        ps.setInt(4, quantity);
                        ps.setInt(5, c.getPlayer().getId());
                        ps.setInt(6, price);
                        ps.setString(7, item.getOwner());
                        ps.setString(8, c.getPlayer().getName());
                        ps.setString(9, date);
                    } else {
                        Equip equip = (Equip) i;
                        ps = con.prepareStatement("INSERT INTO mts_items (tab, type, itemid, quantity, seller, price, upgradeslots, level, str, dex, `int`, luk, hp, mp, watk, matk, wdef, mdef, acc, avoid, hands, speed, jump, locked, owner, sellername, sell_ends, vicious, flag) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
                        ps.setInt(1, 1);
                        ps.setInt(2, (int) invType.getType());
                        ps.setInt(3, equip.getItemId());
                        ps.setInt(4, quantity);
                        ps.setInt(5, c.getPlayer().getId());
                        ps.setInt(6, price);
                        ps.setInt(7, equip.getUpgradeSlots());
                        ps.setInt(8, equip.getLevel());
                        ps.setInt(9, equip.getStr());
                        ps.setInt(10, equip.getDex());
                        ps.setInt(11, equip.getInt());
                        ps.setInt(12, equip.getLuk());
                        ps.setInt(13, equip.getHp());
                        ps.setInt(14, equip.getMp());
                        ps.setInt(15, equip.getWatk());
                        ps.setInt(16, equip.getMatk());
                        ps.setInt(17, equip.getWdef());
                        ps.setInt(18, equip.getMdef());
                        ps.setInt(19, equip.getAcc());
                        ps.setInt(20, equip.getAvoid());
                        ps.setInt(21, equip.getHands());
                        ps.setInt(22, equip.getSpeed());
                        ps.setInt(23, equip.getJump());
                        ps.setInt(24, 0);
                        ps.setString(25, equip.getOwner());
                        ps.setString(26, c.getPlayer().getName());
                        ps.setString(27, date);
                        ps.setInt(28, equip.getVicious());
                        ps.setInt(29, equip.getFlag());
                    }
                    ps.executeUpdate();
                    ps.close();
                    MapleInventoryManipulator.removeFromSlot(c, invType, slot, quantity, false);
                    con.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                c.getPlayer().gainMeso(-5000, false);
                c.announce(MaplePacketCreator.MTSConfirmSell());
                c.announce(getMTS(1, 0, 0));
                c.announce(MaplePacketCreator.enableCSUse());
                c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
                c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
            }
        } else if (op == 3) {
        // send offer for wanted item
        } else if (op == 4) {
            // list wanted item
            slea.readInt();
            slea.readInt();
            slea.readInt();
            slea.readShort();
            slea.readMapleAsciiString();
        } else if (op == 5) {
            // change page
            int tab = slea.readInt();
            int type = slea.readInt();
            int page = slea.readInt();
            c.getPlayer().changePage(page);
            if (tab == 4 && type == 0) {
                c.announce(getCart(c.getPlayer().getId()));
            } else if (tab == c.getPlayer().getCurrentTab() && type == c.getPlayer().getCurrentType() && c.getPlayer().getSearch() != null) {
                c.announce(getMTSSearch(tab, type, c.getPlayer().getCurrentCI(), c.getPlayer().getSearch(), page));
            } else {
                c.getPlayer().setSearch(null);
                c.announce(getMTS(tab, type, page));
            }
            c.getPlayer().changeTab(tab);
            c.getPlayer().changeType(type);
            c.announce(MaplePacketCreator.enableCSUse());
            c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
            c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
        } else if (op == 6) {
            // search
            int tab = slea.readInt();
            int type = slea.readInt();
            slea.readInt();
            int ci = slea.readInt();
            String search = slea.readMapleAsciiString();
            c.getPlayer().setSearch(search);
            c.getPlayer().changeTab(tab);
            c.getPlayer().changeType(type);
            c.getPlayer().changeCI(ci);
            c.announce(MaplePacketCreator.enableCSUse());
            c.announce(MaplePacketCreator.enableActions());
            c.announce(getMTSSearch(tab, type, ci, search, c.getPlayer().getCurrentPage()));
            c.announce(MaplePacketCreator.showMTSCash(c.getPlayer()));
            c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
            c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
        } else if (op == 7) {
            // cancel sale
            // id of the item
            int id = slea.readInt();
            Connection con = null;
            try {
                con = DatabaseConnection.getConnection();
                PreparedStatement ps = con.prepareStatement("UPDATE mts_items SET transfer = 1 WHERE id = ? AND seller = ?");
                ps.setInt(1, id);
                ps.setInt(2, c.getPlayer().getId());
                ps.executeUpdate();
                ps.close();
                ps = con.prepareStatement("DELETE FROM mts_cart WHERE itemid = ?");
                ps.setInt(1, id);
                ps.executeUpdate();
                ps.close();
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            c.announce(MaplePacketCreator.enableCSUse());
            c.announce(getMTS(c.getPlayer().getCurrentTab(), c.getPlayer().getCurrentType(), c.getPlayer().getCurrentPage()));
            c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
            c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
        } else if (op == 8) {
            // transfer item from transfer inv.
            // id of the item
            int id = slea.readInt();
            Connection con = null;
            PreparedStatement ps;
            ResultSet rs;
            try {
                con = DatabaseConnection.getConnection();
                ps = con.prepareStatement("SELECT * FROM mts_items WHERE seller = ? AND transfer = 1  AND id= ? ORDER BY id DESC");
                ps.setInt(1, c.getPlayer().getId());
                ps.setInt(2, id);
                rs = ps.executeQuery();
                if (rs.next()) {
                    Item i;
                    if (rs.getInt("type") != 1) {
                        Item ii = new Item(rs.getInt("itemid"), (short) 0, (short) rs.getInt("quantity"));
                        ii.setOwner(rs.getString("owner"));
                        ii.setPosition(c.getPlayer().getInventory(ItemConstants.getInventoryType(rs.getInt("itemid"))).getNextFreeSlot());
                        i = ii.copy();
                    } else {
                        Equip equip = new Equip(rs.getInt("itemid"), (byte) rs.getInt("position"), -1);
                        equip.setOwner(rs.getString("owner"));
                        equip.setQuantity((short) 1);
                        equip.setAcc((short) rs.getInt("acc"));
                        equip.setAvoid((short) rs.getInt("avoid"));
                        equip.setDex((short) rs.getInt("dex"));
                        equip.setHands((short) rs.getInt("hands"));
                        equip.setHp((short) rs.getInt("hp"));
                        equip.setInt((short) rs.getInt("int"));
                        equip.setJump((short) rs.getInt("jump"));
                        equip.setLuk((short) rs.getInt("luk"));
                        equip.setMatk((short) rs.getInt("matk"));
                        equip.setMdef((short) rs.getInt("mdef"));
                        equip.setMp((short) rs.getInt("mp"));
                        equip.setSpeed((short) rs.getInt("speed"));
                        equip.setStr((short) rs.getInt("str"));
                        equip.setWatk((short) rs.getInt("watk"));
                        equip.setWdef((short) rs.getInt("wdef"));
                        equip.setUpgradeSlots((byte) rs.getInt("upgradeslots"));
                        equip.setLevel((byte) rs.getInt("level"));
                        equip.setVicious((byte) rs.getInt("vicious"));
                        equip.setFlag((byte) rs.getInt("flag"));
                        equip.setPosition(c.getPlayer().getInventory(ItemConstants.getInventoryType(rs.getInt("itemid"))).getNextFreeSlot());
                        i = equip.copy();
                    }
                    try (PreparedStatement pse = con.prepareStatement("DELETE FROM mts_items WHERE id = ? AND seller = ? AND transfer = 1")) {
                        pse.setInt(1, id);
                        pse.setInt(2, c.getPlayer().getId());
                        pse.executeUpdate();
                    }
                    MapleInventoryManipulator.addFromDrop(c, i, false);
                    c.announce(MaplePacketCreator.enableCSUse());
                    c.announce(getCart(c.getPlayer().getId()));
                    c.announce(getMTS(c.getPlayer().getCurrentTab(), c.getPlayer().getCurrentType(), c.getPlayer().getCurrentPage()));
                    c.announce(MaplePacketCreator.MTSConfirmTransfer(i.getQuantity(), i.getPosition()));
                    c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
                }
                rs.close();
                ps.close();
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
                System.out.println("MTS Transfer error: " + e);
            }
        } else if (op == 9) {
            // add to cart
            // id of the item
            int id = slea.readInt();
            Connection con;
            try {
                con = DatabaseConnection.getConnection();
                try (PreparedStatement ps1 = con.prepareStatement("SELECT id FROM mts_items WHERE id = ? AND seller <> ?")) {
                    // Dummy query, prevents adding to cart self owned items
                    ps1.setInt(1, id);
                    ps1.setInt(2, c.getPlayer().getId());
                    try (ResultSet rs1 = ps1.executeQuery()) {
                        if (rs1.next()) {
                            PreparedStatement ps = con.prepareStatement("SELECT cid FROM mts_cart WHERE cid = ? AND itemid = ?");
                            ps.setInt(1, c.getPlayer().getId());
                            ps.setInt(2, id);
                            try (ResultSet rs = ps.executeQuery()) {
                                if (!rs.next()) {
                                    try (PreparedStatement pse = con.prepareStatement("INSERT INTO mts_cart (cid, itemid) VALUES (?, ?)")) {
                                        pse.setInt(1, c.getPlayer().getId());
                                        pse.setInt(2, id);
                                        pse.executeUpdate();
                                    }
                                }
                            }
                        }
                    }
                }
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            c.announce(getMTS(c.getPlayer().getCurrentTab(), c.getPlayer().getCurrentType(), c.getPlayer().getCurrentPage()));
            c.announce(MaplePacketCreator.enableCSUse());
            c.announce(MaplePacketCreator.enableActions());
            c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
            c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
        } else if (op == 10) {
            // delete from cart
            // id of the item
            int id = slea.readInt();
            Connection con = null;
            try {
                con = DatabaseConnection.getConnection();
                try (PreparedStatement ps = con.prepareStatement("DELETE FROM mts_cart WHERE itemid = ? AND cid = ?")) {
                    ps.setInt(1, id);
                    ps.setInt(2, c.getPlayer().getId());
                    ps.executeUpdate();
                }
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            c.announce(getCart(c.getPlayer().getId()));
            c.announce(MaplePacketCreator.enableCSUse());
            c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
            c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
        } else if (op == 12) {
        // put item up for auction
        } else if (op == 13) {
        // cancel wanted cart thing
        } else if (op == 14) {
        // buy auction item now
        } else if (op == 16) {
            // buy
            // id of the item
            int id = slea.readInt();
            Connection con = null;
            PreparedStatement ps;
            ResultSet rs;
            try {
                con = DatabaseConnection.getConnection();
                ps = con.prepareStatement("SELECT * FROM mts_items WHERE id = ? ORDER BY id DESC");
                ps.setInt(1, id);
                rs = ps.executeQuery();
                if (rs.next()) {
                    // taxes
                    int price = rs.getInt("price") + 100 + (int) (rs.getInt("price") * 0.1);
                    if (c.getPlayer().getCashShop().getCash(4) >= price) {
                        // FIX
                        boolean alwaysnull = true;
                        for (Channel cserv : Server.getInstance().getAllChannels()) {
                            MapleCharacter victim = cserv.getPlayerStorage().getCharacterById(rs.getInt("seller"));
                            if (victim != null) {
                                victim.getCashShop().gainCash(4, rs.getInt("price"));
                                alwaysnull = false;
                            }
                        }
                        if (alwaysnull) {
                            ResultSet rse;
                            try (PreparedStatement pse = con.prepareStatement("SELECT accountid FROM characters WHERE id = ?")) {
                                pse.setInt(1, rs.getInt("seller"));
                                rse = pse.executeQuery();
                                if (rse.next()) {
                                    try (PreparedStatement psee = con.prepareStatement("UPDATE accounts SET nxPrepaid = nxPrepaid + ? WHERE id = ?")) {
                                        psee.setInt(1, rs.getInt("price"));
                                        psee.setInt(2, rse.getInt("accountid"));
                                        psee.executeUpdate();
                                    }
                                }
                            }
                            rse.close();
                        }
                        PreparedStatement pse = con.prepareStatement("UPDATE mts_items SET seller = ?, transfer = 1 WHERE id = ?");
                        pse.setInt(1, c.getPlayer().getId());
                        pse.setInt(2, id);
                        pse.executeUpdate();
                        pse.close();
                        pse = con.prepareStatement("DELETE FROM mts_cart WHERE itemid = ?");
                        pse.setInt(1, id);
                        pse.executeUpdate();
                        pse.close();
                        c.getPlayer().getCashShop().gainCash(4, -price);
                        c.announce(MaplePacketCreator.enableCSUse());
                        c.announce(getMTS(c.getPlayer().getCurrentTab(), c.getPlayer().getCurrentType(), c.getPlayer().getCurrentPage()));
                        c.announce(MaplePacketCreator.MTSConfirmBuy());
                        c.announce(MaplePacketCreator.showMTSCash(c.getPlayer()));
                        c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
                        c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
                        c.announce(MaplePacketCreator.enableActions());
                    } else {
                        c.announce(MaplePacketCreator.MTSFailBuy());
                    }
                }
                rs.close();
                ps.close();
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
                c.announce(MaplePacketCreator.MTSFailBuy());
            }
        } else if (op == 17) {
            // buy from cart
            // id of the item
            int id = slea.readInt();
            Connection con = null;
            PreparedStatement ps;
            ResultSet rs;
            try {
                con = DatabaseConnection.getConnection();
                ps = con.prepareStatement("SELECT * FROM mts_items WHERE id = ? ORDER BY id DESC");
                ps.setInt(1, id);
                rs = ps.executeQuery();
                if (rs.next()) {
                    int price = rs.getInt("price") + 100 + (int) (rs.getInt("price") * 0.1);
                    if (c.getPlayer().getCashShop().getCash(4) >= price) {
                        for (Channel cserv : Server.getInstance().getAllChannels()) {
                            MapleCharacter victim = cserv.getPlayerStorage().getCharacterById(rs.getInt("seller"));
                            if (victim != null) {
                                victim.getCashShop().gainCash(4, rs.getInt("price"));
                            } else {
                                ResultSet rse;
                                try (PreparedStatement pse = con.prepareStatement("SELECT accountid FROM characters WHERE id = ?")) {
                                    pse.setInt(1, rs.getInt("seller"));
                                    rse = pse.executeQuery();
                                    if (rse.next()) {
                                        try (PreparedStatement psee = con.prepareStatement("UPDATE accounts SET nxPrepaid = nxPrepaid + ? WHERE id = ?")) {
                                            psee.setInt(1, rs.getInt("price"));
                                            psee.setInt(2, rse.getInt("accountid"));
                                            psee.executeUpdate();
                                        }
                                    }
                                }
                                rse.close();
                            }
                        }
                        PreparedStatement pse = con.prepareStatement("UPDATE mts_items SET seller = ?, transfer = 1 WHERE id = ?");
                        pse.setInt(1, c.getPlayer().getId());
                        pse.setInt(2, id);
                        pse.executeUpdate();
                        pse.close();
                        pse = con.prepareStatement("DELETE FROM mts_cart WHERE itemid = ?");
                        pse.setInt(1, id);
                        pse.executeUpdate();
                        pse.close();
                        c.getPlayer().getCashShop().gainCash(4, -price);
                        c.announce(getCart(c.getPlayer().getId()));
                        c.announce(MaplePacketCreator.enableCSUse());
                        c.announce(MaplePacketCreator.MTSConfirmBuy());
                        c.announce(MaplePacketCreator.showMTSCash(c.getPlayer()));
                        c.announce(MaplePacketCreator.transferInventory(getTransfer(c.getPlayer().getId())));
                        c.announce(MaplePacketCreator.notYetSoldInv(getNotYetSold(c.getPlayer().getId())));
                    } else {
                        c.announce(MaplePacketCreator.MTSFailBuy());
                    }
                }
                rs.close();
                ps.close();
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
                c.announce(MaplePacketCreator.MTSFailBuy());
            }
        } else {
            System.out.println("Unhandled OP(MTS): " + op + " Packet: " + slea.toString());
        }
    } else {
        c.announce(MaplePacketCreator.showMTSCash(c.getPlayer()));
    }
}
Also used : MapleCharacter(client.MapleCharacter) SQLException(java.sql.SQLException) Calendar(java.util.Calendar) Channel(net.server.channel.Channel) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Item(client.inventory.Item) Equip(client.inventory.Equip) MapleInventoryType(client.inventory.MapleInventoryType) ResultSet(java.sql.ResultSet)

Example 12 with Channel

use of net.server.channel.Channel in project HeavenMS by ronancpl.

the class PlayerLoggedinHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    final int cid = slea.readInt();
    final Server server = Server.getInstance();
    MapleCharacter player = c.getWorldServer().getPlayerStorage().getCharacterById(cid);
    boolean newcomer = false;
    if (player == null) {
        try {
            player = MapleCharacter.loadCharFromDB(cid, c, true);
            newcomer = true;
        } catch (SQLException e) {
            e.printStackTrace();
        }
    } else {
        player.newClient(c);
    }
    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);
        return;
    }
    c.setPlayer(player);
    c.setAccID(player.getAccountID());
    int state = c.getLoginState();
    boolean allowLogin = true;
    Channel cserv = c.getChannelServer();
    if (state == MapleClient.LOGIN_SERVER_TRANSITION || state == MapleClient.LOGIN_NOTLOGGEDIN) {
        for (String charName : c.loadCharacterNames(c.getWorld())) {
            for (Channel ch : c.getWorldServer().getChannels()) {
                if (ch.isConnected(charName)) {
                    allowLogin = false;
                }
            }
            break;
        }
    }
    if (state != MapleClient.LOGIN_SERVER_TRANSITION || !allowLogin) {
        c.setPlayer(null);
        c.announce(MaplePacketCreator.getAfterLoginError(7));
        return;
    }
    c.updateLoginState(MapleClient.LOGIN_LOGGEDIN);
    cserv.addPlayer(player);
    List<PlayerBuffValueHolder> buffs = server.getPlayerBuffStorage().getBuffsFromStorage(cid);
    if (buffs != null) {
        List<Pair<Long, PlayerBuffValueHolder>> timedBuffs = getLocalStartTimes(buffs);
        player.silentGiveBuffs(timedBuffs);
    }
    c.announce(MaplePacketCreator.getCharInfo(player));
    if (!player.isHidden()) {
        player.toggleHide(true);
    }
    player.sendKeymap();
    player.sendMacros();
    if (player.getKeymap().get(91) != null)
        player.announce(MaplePacketCreator.sendAutoHpPot(player.getKeymap().get(91).getAction()));
    if (player.getKeymap().get(92) != null)
        player.announce(MaplePacketCreator.sendAutoMpPot(player.getKeymap().get(92).getAction()));
    player.getMap().addPlayer(player);
    World world = server.getWorld(c.getWorld());
    world.getPlayerStorage().addPlayer(player);
    player.setAwayFromWorld(false);
    int[] buddyIds = player.getBuddylist().getBuddyIds();
    world.loggedOn(player.getName(), player.getId(), c.getChannel(), buddyIds);
    for (CharacterIdChannelPair onlineBuddy : server.getWorld(c.getWorld()).multiBuddyFind(player.getId(), buddyIds)) {
        BuddylistEntry ble = player.getBuddylist().get(onlineBuddy.getCharacterId());
        ble.setChannel(onlineBuddy.getChannel());
        player.getBuddylist().put(ble);
    }
    c.announce(MaplePacketCreator.updateBuddylist(player.getBuddylist().getBuddies()));
    c.announce(MaplePacketCreator.loadFamily(player));
    if (player.getFamilyId() > 0) {
        MapleFamily f = world.getFamily(player.getFamilyId());
        if (f == null) {
            f = new MapleFamily(player.getId());
            world.addFamily(player.getFamilyId(), f);
        }
        player.setFamily(f);
        c.announce(MaplePacketCreator.getFamilyInfo(f.getMember(player.getId())));
    }
    if (player.getGuildId() > 0) {
        MapleGuild playerGuild = server.getGuild(player.getGuildId(), player.getWorld(), player);
        if (playerGuild == null) {
            player.deleteGuild(player.getGuildId());
            player.getMGC().setGuildId(0);
        } else {
            playerGuild.getMGC(player.getId()).setCharacter(player);
            player.setMGC(playerGuild.getMGC(player.getId()));
            server.setGuildMemberOnline(player, true, c.getChannel());
            c.announce(MaplePacketCreator.showGuildInfo(player));
            int allianceId = player.getGuild().getAllianceId();
            if (allianceId > 0) {
                MapleAlliance newAlliance = server.getAlliance(allianceId);
                if (newAlliance == null) {
                    newAlliance = MapleAlliance.loadAlliance(allianceId);
                    if (newAlliance != null) {
                        server.addAlliance(allianceId, newAlliance);
                    } else {
                        player.getGuild().setAllianceId(0);
                    }
                }
                if (newAlliance != null) {
                    c.announce(MaplePacketCreator.updateAllianceInfo(newAlliance, c));
                    c.announce(MaplePacketCreator.allianceNotice(newAlliance.getId(), newAlliance.getNotice()));
                    if (newcomer) {
                        server.allianceMessage(allianceId, MaplePacketCreator.allianceMemberOnline(player, true), player.getId(), -1);
                    }
                }
            }
        }
    }
    player.showNote();
    if (player.getParty() != null) {
        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.
        // c.announce(MaplePacketCreator.partyCreated(pchar));
        pchar.setChannel(c.getChannel());
        pchar.setMapId(player.getMapId());
        pchar.setOnline(true);
        world.updateParty(player.getParty().getId(), PartyOperation.LOG_ONOFF, pchar);
        player.updatePartyMemberHP();
    }
    if (player.getInventory(MapleInventoryType.EQUIPPED).findById(1122017) != null) {
        player.equipPendantOfSpirit();
    }
    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()));
    }
    if (newcomer) {
        for (MaplePet pet : player.getPets()) {
            if (pet != null)
                world.registerPetHunger(player, player.getPetIndex(pet));
        }
        player.reloadQuestExpirations();
    }
    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());
    player.buffExpireTask();
    player.diseaseExpireTask();
    player.skillCooldownTask();
    player.expirationTask();
    player.questExpirationTask();
    if (GameConstants.hasSPTable(player.getJob()) && player.getJob().getId() != 2001) {
        player.createDragon();
    }
    player.commitExcludedItems();
    if (newcomer) {
        /*
            if (!c.hasVotedAlready()){
            	player.announce(MaplePacketCreator.earnTitleMessage("You can vote now! Vote and earn a vote point!"));
            }
                    */
        if (player.isGM()) {
            Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.earnTitleMessage((player.gmLevel() < 6 ? "GM " : "Admin ") + player.getName() + " has logged in"));
        }
    }
    showDueyNotification(c, player);
    if (player.getMap().getHPDec() > 0)
        player.resetHpDecreaseTask();
    player.resetPlayerRates();
    if (ServerConstants.USE_ADD_RATES_BY_LEVEL == true)
        player.setPlayerRates();
    player.setWorldRates();
    player.updateCouponRates();
    player.receivePartyMemberHP();
}
Also used : MapleCharacter(client.MapleCharacter) PlayerBuffValueHolder(net.server.PlayerBuffValueHolder) CharacterIdChannelPair(net.server.channel.CharacterIdChannelPair) Server(net.server.Server) SQLException(java.sql.SQLException) MapleFamily(client.MapleFamily) Channel(net.server.channel.Channel) World(net.server.world.World) BuddylistEntry(client.BuddylistEntry) MapleGuild(net.server.guild.MapleGuild) MapleAlliance(net.server.guild.MapleAlliance) MaplePet(client.inventory.MaplePet) CharacterIdChannelPair(net.server.channel.CharacterIdChannelPair) Pair(tools.Pair) MaplePartyCharacter(net.server.world.MaplePartyCharacter) CharacterNameAndId(client.CharacterNameAndId)

Example 13 with Channel

use of net.server.channel.Channel in project HeavenMS by ronancpl.

the class MaplePacketCreator method getServerList.

/**
 * Gets a packet detailing a server and its channels.
 *
 * @param serverId
 * @param serverName The name of the server.
 * @param channelLoad Load of the channel - 1200 seems to be max.
 * @return The server info packet.
 */
public static byte[] getServerList(int serverId, String serverName, int flag, String eventmsg, List<Channel> channelLoad) {
    final MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
    mplew.writeShort(SendOpcode.SERVERLIST.getValue());
    mplew.write(serverId);
    mplew.writeMapleAsciiString(serverName);
    mplew.write(flag);
    mplew.writeMapleAsciiString(eventmsg);
    // rate modifier, don't ask O.O!
    mplew.write(100);
    // event xp * 2.6 O.O!
    mplew.write(0);
    // rate modifier, don't ask O.O!
    mplew.write(100);
    // drop rate * 2.6
    mplew.write(0);
    mplew.write(0);
    mplew.write(channelLoad.size());
    for (Channel ch : channelLoad) {
        mplew.writeMapleAsciiString(serverName + "-" + ch.getId());
        mplew.writeInt((ch.getConnectedClients() * 1200) / ServerConstants.CHANNEL_LOAD);
        mplew.write(1);
        mplew.writeShort(ch.getId() - 1);
    }
    mplew.writeShort(0);
    return mplew.getPacket();
}
Also used : MaplePacketLittleEndianWriter(tools.data.output.MaplePacketLittleEndianWriter) Channel(net.server.channel.Channel)

Aggregations

Channel (net.server.channel.Channel)13 SQLException (java.sql.SQLException)8 Connection (java.sql.Connection)6 PreparedStatement (java.sql.PreparedStatement)6 DatabaseConnection (tools.DatabaseConnection)6 MapleCharacter (client.MapleCharacter)5 Item (client.inventory.Item)5 Point (java.awt.Point)4 IOException (java.io.IOException)4 ResultSet (java.sql.ResultSet)4 UnknownHostException (java.net.UnknownHostException)3 SpawnPoint (server.life.SpawnPoint)3 MapleMap (server.maps.MapleMap)3 MapleMapItem (server.maps.MapleMapItem)3 MapleInventoryType (client.inventory.MapleInventoryType)2 Properties (java.util.Properties)2 Server (net.server.Server)2 World (net.server.world.World)2 MapleEvent (server.events.gm.MapleEvent)2 MapleMonster (server.life.MapleMonster)2