Search in sources :

Example 1 with MapleEvent

use of server.events.gm.MapleEvent in project HeavenMS by ronancpl.

the class Commands method executeHeavenMsCommandLv0.

public static boolean executeHeavenMsCommandLv0(Channel cserv, Server srv, MapleClient c, String[] sub) {
    // Player
    MapleCharacter player = c.getPlayer();
    switch(sub[0]) {
        case "help":
        case "commands":
        case "playercommands":
            c.getAbstractPlayerInteraction().openNpc(9201143, "commands");
            break;
        case "droplimit":
            int dropCount = c.getPlayer().getMap().getDroppedItemCount();
            if (((float) dropCount) / ServerConstants.ITEM_LIMIT_ON_MAP < 0.75f) {
                c.getPlayer().showHint("Current drop count: #b" + dropCount + "#k / #e" + ServerConstants.ITEM_LIMIT_ON_MAP + "#n", 300);
            } else {
                c.getPlayer().showHint("Current drop count: #r" + dropCount + "#k / #e" + ServerConstants.ITEM_LIMIT_ON_MAP + "#n", 300);
            }
            break;
        case "time":
            DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
            dateFormat.setTimeZone(TimeZone.getTimeZone(ServerConstants.TIMEZONE));
            player.yellowMessage("Solaxia Server Time: " + dateFormat.format(new Date()));
            break;
        case "credits":
        case "staff":
            c.getAbstractPlayerInteraction().openNpc(2010007, "credits");
            break;
        case "lastrestart":
        case "uptime":
            long milliseconds = System.currentTimeMillis() - Server.uptime;
            int seconds = (int) (milliseconds / 1000) % 60;
            int minutes = (int) ((milliseconds / (1000 * 60)) % 60);
            int hours = (int) ((milliseconds / (1000 * 60 * 60)) % 24);
            int days = (int) ((milliseconds / (1000 * 60 * 60 * 24)));
            player.yellowMessage("Server has been online for " + days + " days " + hours + " hours " + minutes + " minutes and " + seconds + " seconds.");
            break;
        case "gacha":
            Gachapon gacha = null;
            String search = joinStringFrom(sub, 1);
            String gachaName = "";
            String[] names = { "Henesys", "Ellinia", "Perion", "Kerning City", "Sleepywood", "Mushroom Shrine", "Showa Spa Male", "Showa Spa Female", "New Leaf City", "Nautilus Harbor" };
            int[] ids = { 9100100, 9100101, 9100102, 9100103, 9100104, 9100105, 9100106, 9100107, 9100109, 9100117 };
            for (int i = 0; i < names.length; i++) {
                if (search.equalsIgnoreCase(names[i])) {
                    gachaName = names[i];
                    gacha = Gachapon.getByNpcId(ids[i]);
                }
            }
            if (gacha == null) {
                player.yellowMessage("Please use @gacha <name> where name corresponds to one of the below:");
                for (String name : names) {
                    player.yellowMessage(name);
                }
                break;
            }
            String output = "The #b" + gachaName + "#k Gachapon contains the following items.\r\n\r\n";
            for (int i = 0; i < 2; i++) {
                for (int id : gacha.getItems(i)) {
                    output += "-" + MapleItemInformationProvider.getInstance().getName(id) + "\r\n";
                }
            }
            output += "\r\nPlease keep in mind that there are items that are in all gachapons and are not listed here.";
            c.announce(MaplePacketCreator.getNPCTalk(9010000, (byte) 0, output, "00 00", (byte) 0));
            break;
        case "whatdropsfrom":
            if (sub.length < 2) {
                player.dropMessage(5, "Please do @whatdropsfrom <monster name>");
                break;
            }
            String monsterName = joinStringFrom(sub, 1);
            output = "";
            int limit = 3;
            Iterator<Pair<Integer, String>> listIterator = MapleMonsterInformationProvider.getMobsIDsFromName(monsterName).iterator();
            for (int i = 0; i < limit; i++) {
                if (listIterator.hasNext()) {
                    Pair<Integer, String> data = listIterator.next();
                    int mobId = data.getLeft();
                    String mobName = data.getRight();
                    output += mobName + " drops the following items:\r\n\r\n";
                    for (MonsterDropEntry drop : MapleMonsterInformationProvider.getInstance().retrieveDrop(mobId)) {
                        try {
                            String name = MapleItemInformationProvider.getInstance().getName(drop.itemId);
                            if (name.equals("null") || drop.chance == 0) {
                                continue;
                            }
                            float chance = 1000000 / drop.chance / player.getDropRate();
                            output += "- " + name + " (1/" + (int) chance + ")\r\n";
                        } catch (Exception ex) {
                            ex.printStackTrace();
                            continue;
                        }
                    }
                    output += "\r\n";
                }
            }
            c.announce(MaplePacketCreator.getNPCTalk(9010000, (byte) 0, output, "00 00", (byte) 0));
            break;
        case "whodrops":
            if (sub.length < 2) {
                player.dropMessage(5, "Please do @whodrops <item name>");
                break;
            }
            String searchString = joinStringFrom(sub, 1);
            output = "";
            listIterator = MapleItemInformationProvider.getInstance().getItemDataByName(searchString).iterator();
            if (listIterator.hasNext()) {
                int count = 1;
                while (listIterator.hasNext() && count <= 3) {
                    Pair<Integer, String> data = listIterator.next();
                    output += "#b" + data.getRight() + "#k is dropped by:\r\n";
                    try {
                        Connection con = DatabaseConnection.getConnection();
                        PreparedStatement ps = con.prepareStatement("SELECT dropperid FROM drop_data WHERE itemid = ? LIMIT 50");
                        ps.setInt(1, data.getLeft());
                        ResultSet rs = ps.executeQuery();
                        while (rs.next()) {
                            String resultName = MapleMonsterInformationProvider.getMobNameFromID(rs.getInt("dropperid"));
                            if (resultName != null) {
                                output += resultName + ", ";
                            }
                        }
                        rs.close();
                        ps.close();
                        con.close();
                    } catch (Exception e) {
                        player.dropMessage(6, "There was a problem retrieving the required data. Please try again.");
                        e.printStackTrace();
                        break;
                    }
                    output += "\r\n\r\n";
                    count++;
                }
            } else {
                player.dropMessage(5, "The item you searched for doesn't exist.");
                break;
            }
            c.announce(MaplePacketCreator.getNPCTalk(9010000, (byte) 0, output, "00 00", (byte) 0));
            break;
        case "dispose":
            NPCScriptManager.getInstance().dispose(c);
            c.announce(MaplePacketCreator.enableActions());
            c.removeClickedNPC();
            player.message("You've been disposed.");
            break;
        case "equiplv":
            player.showAllEquipFeatures();
            break;
        case "showrates":
            String showMsg = "#eEXP RATE#n" + "\r\n";
            showMsg += "Server EXP Rate: #k" + c.getWorldServer().getExpRate() + "x#k" + "\r\n";
            showMsg += "Player EXP Rate: #k" + player.getRawExpRate() + "x#k" + "\r\n";
            if (player.getCouponExpRate() != 1)
                showMsg += "Coupon EXP Rate: #k" + player.getCouponExpRate() + "x#k" + "\r\n";
            showMsg += "EXP Rate: #e#b" + player.getExpRate() + "x#k#n" + "\r\n";
            showMsg += "\r\n" + "#eMESO RATE#n" + "\r\n";
            showMsg += "Server MESO Rate: #k" + c.getWorldServer().getMesoRate() + "x#k" + "\r\n";
            showMsg += "Player MESO Rate: #k" + player.getRawMesoRate() + "x#k" + "\r\n";
            if (player.getCouponMesoRate() != 1)
                showMsg += "Coupon MESO Rate: #k" + player.getCouponMesoRate() + "x#k" + "\r\n";
            showMsg += "MESO Rate: #e#b" + player.getMesoRate() + "x#k#n" + "\r\n";
            showMsg += "\r\n" + "#eDROP RATE#n" + "\r\n";
            showMsg += "Server DROP Rate: #k" + c.getWorldServer().getDropRate() + "x#k" + "\r\n";
            showMsg += "Player DROP Rate: #k" + player.getRawDropRate() + "x#k" + "\r\n";
            if (player.getCouponDropRate() != 1)
                showMsg += "Coupon DROP Rate: #k" + player.getCouponDropRate() + "x#k" + "\r\n";
            showMsg += "DROP Rate: #e#b" + player.getDropRate() + "x#k#n" + "\r\n";
            if (ServerConstants.USE_QUEST_RATE) {
                showMsg += "\r\n" + "#eQUEST RATE#n" + "\r\n";
                showMsg += "Server QUEST Rate: #e#b" + c.getWorldServer().getQuestRate() + "x#k#n" + "\r\n";
            }
            player.showHint(showMsg, 300);
            break;
        case "rates":
            String showMsg_ = "#eCHARACTER RATES#n" + "\r\n\r\n";
            showMsg_ += "EXP Rate: #e#b" + player.getExpRate() + "x#k#n" + "\r\n";
            showMsg_ += "MESO Rate: #e#b" + player.getMesoRate() + "x#k#n" + "\r\n";
            showMsg_ += "DROP Rate: #e#b" + player.getDropRate() + "x#k#n" + "\r\n";
            if (ServerConstants.USE_QUEST_RATE)
                showMsg_ += "QUEST Rate: #e#b" + c.getWorldServer().getQuestRate() + "x#k#n" + "\r\n";
            player.showHint(showMsg_, 300);
            break;
        case "online":
            for (Channel ch : Server.getInstance().getChannelsFromWorld(player.getWorld())) {
                player.yellowMessage("Players in Channel " + ch.getId() + ":");
                for (MapleCharacter chr : ch.getPlayerStorage().getAllCharacters()) {
                    if (!chr.isGM()) {
                        player.message(" >> " + MapleCharacter.makeMapleReadable(chr.getName()) + " is at " + chr.getMap().getMapName() + ".");
                    }
                }
            }
            break;
        case "gm":
            if (sub.length < 3) {
                // #goodbye 'hi'
                player.dropMessage(5, "Your message was too short. Please provide as much detail as possible.");
                break;
            }
            String message = joinStringFrom(sub, 1);
            Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.sendYellowTip("[GM MESSAGE]:" + MapleCharacter.makeMapleReadable(player.getName()) + ": " + message));
            Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.serverNotice(1, message));
            FilePrinter.printError("gm.txt", MapleCharacter.makeMapleReadable(player.getName()) + ": " + message + "\r\n");
            player.dropMessage(5, "Your message '" + message + "' was sent to GMs.");
            player.dropMessage(5, tips[Randomizer.nextInt(tips.length)]);
            break;
        case "bug":
            if (sub.length < 2) {
                player.dropMessage(5, "Message too short and not sent. Please do @bug <bug>");
                break;
            }
            message = joinStringFrom(sub, 1);
            Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.sendYellowTip("[BUG]:" + MapleCharacter.makeMapleReadable(player.getName()) + ": " + message));
            Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.serverNotice(1, message));
            FilePrinter.printError("bug.txt", MapleCharacter.makeMapleReadable(player.getName()) + ": " + message + "\r\n");
            player.dropMessage(5, "Your bug '" + message + "' was submitted successfully to our developers. Thank you!");
            break;
        /*
                case "points":
			player.dropMessage(5, "You have " + c.getVotePoints() + " vote point(s).");
			if (c.hasVotedAlready()) {
				Date currentDate = new Date();
				int time = (int) ((int) 86400 - ((currentDate.getTime() / 1000) - c.getVoteTime())); //ugly as fuck
				hours = time / 3600;
				minutes = time % 3600 / 60;
				seconds = time % 3600 % 60;
				player.yellowMessage("You have already voted. You can vote again in " + hours + " hours, " + minutes + " minutes, " + seconds + " seconds.");
			} else {
				player.yellowMessage("You are free to vote! Make sure to vote to gain a vote point!");
			}
			break;
                */
        case "joinevent":
            if (!FieldLimit.CANNOTMIGRATE.check(player.getMap().getFieldLimit())) {
                MapleEvent event = c.getChannelServer().getEvent();
                if (event != null) {
                    if (event.getMapId() != player.getMapId()) {
                        if (event.getLimit() > 0) {
                            player.saveLocation("EVENT");
                            if (event.getMapId() == 109080000 || event.getMapId() == 109060001)
                                player.setTeam(event.getLimit() % 2);
                            event.minusLimit();
                            player.changeMap(event.getMapId());
                        } else {
                            player.dropMessage(5, "The limit of players for the event has already been reached.");
                        }
                    } else {
                        player.dropMessage(5, "You are already in the event.");
                    }
                } else {
                    player.dropMessage(5, "There is currently no event in progress.");
                }
            } else {
                player.dropMessage(5, "You are currently in a map where you can't join an event.");
            }
            break;
        case "leaveevent":
            int returnMap = player.getSavedLocation("EVENT");
            if (returnMap != -1) {
                if (player.getOla() != null) {
                    player.getOla().resetTimes();
                    player.setOla(null);
                }
                if (player.getFitness() != null) {
                    player.getFitness().resetTimes();
                    player.setFitness(null);
                }
                player.changeMap(returnMap);
                if (c.getChannelServer().getEvent() != null) {
                    c.getChannelServer().getEvent().addLimit();
                }
            } else {
                player.dropMessage(5, "You are not currently in an event.");
            }
            break;
        case "bosshp":
            for (MapleMonster monster : player.getMap().getMonsters()) {
                if (monster != null && monster.isBoss() && monster.getHp() > 0) {
                    long percent = monster.getHp() * 100L / monster.getMaxHp();
                    String bar = "[";
                    for (int i = 0; i < 100; i++) {
                        bar += i < percent ? "|" : ".";
                    }
                    bar += "]";
                    player.yellowMessage(monster.getName() + " (" + monster.getId() + ") has " + percent + "% HP left.");
                    player.yellowMessage("HP: " + bar);
                }
            }
            break;
        case "ranks":
            PreparedStatement ps = null;
            ResultSet rs = null;
            Connection con = null;
            try {
                con = DatabaseConnection.getConnection();
                ps = con.prepareStatement("SELECT `characters`.`name`, `characters`.`level` FROM `characters` LEFT JOIN accounts ON accounts.id = characters.accountid WHERE `characters`.`gm` = '0' AND `accounts`.`banned` = '0' ORDER BY level DESC, exp DESC LIMIT 50");
                rs = ps.executeQuery();
                player.announce(MaplePacketCreator.showPlayerRanks(9010000, rs));
                ps.close();
                rs.close();
                con.close();
            } catch (SQLException ex) {
                ex.printStackTrace();
            } finally {
                try {
                    if (ps != null && !ps.isClosed()) {
                        ps.close();
                    }
                    if (rs != null && !rs.isClosed()) {
                        rs.close();
                    }
                    if (con != null && !con.isClosed()) {
                        con.close();
                    }
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            break;
        default:
            return false;
    }
    return true;
}
Also used : MapleCharacter(client.MapleCharacter) MapleEvent(server.events.gm.MapleEvent) SQLException(java.sql.SQLException) Channel(net.server.channel.Channel) Connection(java.sql.Connection) DatabaseConnection(tools.DatabaseConnection) Gachapon(server.gachapon.MapleGachapon.Gachapon) PreparedStatement(java.sql.PreparedStatement) Point(java.awt.Point) SpawnPoint(server.life.SpawnPoint) Date(java.util.Date) SQLException(java.sql.SQLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) MonsterDropEntry(server.life.MonsterDropEntry) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) ResultSet(java.sql.ResultSet) SimpleDateFormat(java.text.SimpleDateFormat) MapleMonster(server.life.MapleMonster) Pair(tools.Pair)

Example 2 with MapleEvent

use of server.events.gm.MapleEvent in project HeavenMS by ronancpl.

the class Commands method executeHeavenMsCommandLv3.

public static boolean executeHeavenMsCommandLv3(Channel cserv, Server srv, MapleClient c, String[] sub) {
    // GM
    MapleCharacter player = c.getPlayer();
    MapleCharacter victim;
    switch(sub[0]) {
        case "fly":
            if (sub.length < 2) {
                player.yellowMessage("Syntax: !fly <on/off>");
                break;
            }
            Integer accid = c.getAccID();
            String sendStr = "";
            if (sub[1].equalsIgnoreCase("on")) {
                sendStr += "Enabled Fly feature (F1). With fly active, you cannot attack.";
                if (!srv.canFly(accid))
                    sendStr += " Re-login to take effect.";
                srv.changeFly(c.getAccID(), true);
            } else {
                sendStr += "Disabled Fly feature. You can now attack.";
                if (srv.canFly(accid))
                    sendStr += " Re-login to take effect.";
                srv.changeFly(c.getAccID(), false);
            }
            player.dropMessage(6, sendStr);
            break;
        case "spawn":
            if (sub.length < 2) {
                player.yellowMessage("Syntax: !spawn <mobid>");
                break;
            }
            MapleMonster monster = MapleLifeFactory.getMonster(Integer.parseInt(sub[1]));
            if (monster == null) {
                break;
            }
            if (sub.length > 2) {
                for (int i = 0; i < Integer.parseInt(sub[2]); i++) {
                    player.getMap().spawnMonsterOnGroundBelow(MapleLifeFactory.getMonster(Integer.parseInt(sub[1])), player.getPosition());
                }
            } else {
                player.getMap().spawnMonsterOnGroundBelow(MapleLifeFactory.getMonster(Integer.parseInt(sub[1])), player.getPosition());
            }
            break;
        case "mutemap":
            if (player.getMap().isMuted()) {
                player.getMap().setMuted(false);
                player.dropMessage(5, "The map you are in has been un-muted.");
            } else {
                player.getMap().setMuted(true);
                player.dropMessage(5, "The map you are in has been muted.");
            }
            break;
        case "checkdmg":
            victim = c.getWorldServer().getPlayerStorage().getCharacterByName(sub[1]);
            if (victim != null) {
                int maxBase = victim.calculateMaxBaseDamage(victim.getTotalWatk());
                Integer watkBuff = victim.getBuffedValue(MapleBuffStat.WATK);
                Integer matkBuff = victim.getBuffedValue(MapleBuffStat.MATK);
                Integer blessing = victim.getSkillLevel(10000000 * player.getJobType() + 12);
                if (watkBuff == null)
                    watkBuff = 0;
                if (matkBuff == null)
                    matkBuff = 0;
                player.dropMessage(5, "Cur Str: " + victim.getTotalStr() + " Cur Dex: " + victim.getTotalDex() + " Cur Int: " + victim.getTotalInt() + " Cur Luk: " + victim.getTotalLuk());
                player.dropMessage(5, "Cur WATK: " + victim.getTotalWatk() + " Cur MATK: " + victim.getTotalMagic());
                player.dropMessage(5, "Cur WATK Buff: " + watkBuff + " Cur MATK Buff: " + matkBuff + " Cur Blessing Level: " + blessing);
                player.dropMessage(5, victim.getName() + "'s maximum base damage (before skills) is " + maxBase);
            } else {
                player.message("Player '" + sub[1] + "' could not be found on this world.");
            }
            break;
        case "inmap":
            String st = "";
            for (MapleCharacter chr : player.getMap().getCharacters()) {
                st += chr.getName() + " ";
            }
            player.message(st);
            break;
        case "reloadevents":
            for (Channel ch : Server.getInstance().getAllChannels()) {
                ch.reloadEventScriptManager();
            }
            player.dropMessage(5, "Reloaded Events");
            break;
        case "reloaddrops":
            MapleMonsterInformationProvider.getInstance().clearDrops();
            player.dropMessage(5, "Reloaded Drops");
            break;
        case "reloadportals":
            PortalScriptManager.getInstance().reloadPortalScripts();
            player.dropMessage(5, "Reloaded Portals");
            break;
        case "reloadmap":
            MapleMap oldMap = c.getPlayer().getMap();
            MapleMap newMap = c.getChannelServer().getMapFactory().resetMap(player.getMapId());
            int callerid = c.getPlayer().getId();
            for (MapleCharacter chr : oldMap.getCharacters()) {
                chr.changeMap(newMap);
                if (chr.getId() != callerid)
                    chr.dropMessage("You have been relocated due to map reloading. Sorry for the inconvenience.");
            }
            newMap.respawn();
            break;
        case "hpmp":
            victim = player;
            int statUpdate = 1;
            if (sub.length >= 3) {
                victim = c.getWorldServer().getPlayerStorage().getCharacterByName(sub[1]);
                statUpdate = Integer.valueOf(sub[2]);
            } else if (sub.length == 2) {
                statUpdate = Integer.valueOf(sub[1]);
            } else {
                player.yellowMessage("Syntax: !sethpmp [<playername>] <value>");
            }
            if (victim != null) {
                victim.setHp(statUpdate);
                victim.setMp(statUpdate);
                victim.updateSingleStat(MapleStat.HP, statUpdate);
                victim.updateSingleStat(MapleStat.MP, statUpdate);
                victim.checkBerserk(victim.isHidden());
            } else {
                player.message("Player '" + sub[1] + "' could not be found on this world.");
            }
            break;
        case "music":
            if (sub.length < 2) {
                player.yellowMessage("Syntax: !music <song>");
                for (String s : songs) {
                    player.yellowMessage(s);
                }
                break;
            }
            String song = joinStringFrom(sub, 1);
            for (String s : songs) {
                if (s.equals(song)) {
                    player.getMap().broadcastMessage(MaplePacketCreator.musicChange(s));
                    player.yellowMessage("Now playing song " + song + ".");
                    break;
                }
            }
            player.yellowMessage("Song not found, please enter a song below.");
            for (String s : songs) {
                player.yellowMessage(s);
            }
            break;
        case "monitor":
            if (sub.length < 1) {
                player.yellowMessage("Syntax: !monitor <ign>");
                break;
            }
            victim = c.getWorldServer().getPlayerStorage().getCharacterByName(sub[1]);
            if (victim == null) {
                player.message("Player '" + sub[1] + "' could not be found on this world.");
                break;
            }
            boolean monitored = MapleLogger.monitored.contains(victim.getName());
            if (monitored) {
                MapleLogger.monitored.remove(victim.getName());
            } else {
                MapleLogger.monitored.add(victim.getName());
            }
            player.yellowMessage(victim.getName() + " is " + (!monitored ? "now being monitored." : "no longer being monitored."));
            String message = player.getName() + (!monitored ? " has started monitoring " : " has stopped monitoring ") + victim.getName() + ".";
            Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.serverNotice(5, message));
            break;
        case "monitors":
            for (String ign : MapleLogger.monitored) {
                player.yellowMessage(ign + " is being monitored.");
            }
            break;
        case "ignore":
            if (sub.length < 1) {
                player.yellowMessage("Syntax: !ignore <ign>");
                break;
            }
            victim = c.getWorldServer().getPlayerStorage().getCharacterByName(sub[1]);
            if (victim == null) {
                player.message("Player '" + sub[1] + "' could not be found on this world.");
                break;
            }
            boolean monitored_ = MapleLogger.ignored.contains(victim.getName());
            if (monitored_) {
                MapleLogger.ignored.remove(victim.getName());
            } else {
                MapleLogger.ignored.add(victim.getName());
            }
            player.yellowMessage(victim.getName() + " is " + (!monitored_ ? "now being ignored." : "no longer being ignored."));
            String message_ = player.getName() + (!monitored_ ? " has started ignoring " : " has stopped ignoring ") + victim.getName() + ".";
            Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.serverNotice(5, message_));
            break;
        case "ignored":
            for (String ign : MapleLogger.ignored) {
                player.yellowMessage(ign + " is being ignored.");
            }
            break;
        case "pos":
            float xpos = player.getPosition().x;
            float ypos = player.getPosition().y;
            float fh = player.getMap().getFootholds().findBelow(player.getPosition()).getId();
            player.dropMessage(6, "Position: (" + xpos + ", " + ypos + ")");
            player.dropMessage(6, "Foothold ID: " + fh);
            break;
        case "togglecoupon":
            if (sub.length < 2) {
                player.yellowMessage("Syntax: !togglecoupon <itemid>");
                break;
            }
            Server.getInstance().toggleCoupon(Integer.parseInt(sub[1]));
            break;
        case "chat":
            player.toggleWhiteChat();
            player.message("Your chat is now " + (player.getWhiteChat() ? " white" : "normal") + ".");
            break;
        case "fame":
            if (sub.length < 3) {
                player.yellowMessage("Syntax: !fame <playername> <gainfame>");
                break;
            }
            victim = cserv.getPlayerStorage().getCharacterByName(sub[1]);
            if (victim != null) {
                victim.setFame(Integer.parseInt(sub[2]));
                victim.updateSingleStat(MapleStat.FAME, victim.getFame());
                player.message("FAME given.");
            } else {
                player.message("Player '" + sub[1] + "' could not be found on this channel.");
            }
            break;
        case "givenx":
            if (sub.length < 2) {
                player.yellowMessage("Syntax: !givenx [<playername>] <gainnx>");
                break;
            }
            String recv;
            int value;
            if (sub.length > 2) {
                recv = sub[1];
                value = Integer.parseInt(sub[2]);
            } else {
                recv = c.getPlayer().getName();
                value = Integer.parseInt(sub[1]);
            }
            victim = cserv.getPlayerStorage().getCharacterByName(recv);
            if (victim != null) {
                victim.getCashShop().gainCash(1, value);
                player.message("NX given.");
            } else {
                player.message("Player '" + recv + "' could not be found on this channel.");
            }
            break;
        case "givevp":
            if (sub.length < 3) {
                player.yellowMessage("Syntax: !givevp <playername> <gainvotepoint>");
                break;
            }
            victim = cserv.getPlayerStorage().getCharacterByName(sub[1]);
            if (victim != null) {
                victim.getClient().addVotePoints(Integer.parseInt(sub[2]));
                player.message("VP given.");
            } else {
                player.message("Player '" + sub[1] + "' could not be found on this channel.");
            }
            break;
        case "givems":
            if (sub.length < 2) {
                player.yellowMessage("Syntax: !givems [<playername>] <gainmeso>");
                break;
            }
            String recv_;
            int value_;
            if (sub.length > 2) {
                recv_ = sub[1];
                value_ = Integer.parseInt(sub[2]);
            } else {
                recv_ = c.getPlayer().getName();
                value_ = Integer.parseInt(sub[1]);
            }
            victim = cserv.getPlayerStorage().getCharacterByName(recv_);
            if (victim != null) {
                victim.gainMeso(value_, true);
                player.message("MESO given.");
            } else {
                player.message("Player '" + recv_ + "' could not be found on this channel.");
            }
            break;
        case "id":
            if (sub.length < 2) {
                player.yellowMessage("Syntax: !id <id>");
                break;
            }
            try {
                try (BufferedReader dis = new BufferedReader(new InputStreamReader(new URL("http://www.mapletip.com/search_java.php?search_value=" + sub[1] + "&check=true").openConnection().getInputStream()))) {
                    String s;
                    while ((s = dis.readLine()) != null) {
                        player.dropMessage(s);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            break;
        case "expeds":
            for (Channel ch : Server.getInstance().getChannelsFromWorld(c.getWorld())) {
                if (ch.getExpeditions().size() == 0) {
                    player.yellowMessage("No Expeditions in Channel " + ch.getId());
                    continue;
                }
                player.yellowMessage("Expeditions in Channel " + ch.getId());
                int id = 0;
                for (MapleExpedition exped : ch.getExpeditions()) {
                    id++;
                    player.yellowMessage("> Expedition " + id);
                    player.yellowMessage(">> Type: " + exped.getType().toString());
                    player.yellowMessage(">> Status: " + (exped.isRegistering() ? "REGISTERING" : "UNDERWAY"));
                    player.yellowMessage(">> Size: " + exped.getMembers().size());
                    player.yellowMessage(">> Leader: " + exped.getLeader().getName());
                    int memId = 2;
                    for (MapleCharacter member : exped.getMembers()) {
                        if (exped.isLeader(member)) {
                            continue;
                        }
                        player.yellowMessage(">>> Member " + memId + ": " + member.getName());
                        memId++;
                    }
                }
            }
            break;
        case "kill":
            if (sub.length < 2) {
                player.yellowMessage("Syntax: !kill <playername>");
                break;
            }
            victim = cserv.getPlayerStorage().getCharacterByName(sub[1]);
            if (victim != null) {
                victim.setHpMp(0);
                Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.serverNotice(5, player.getName() + " used !kill on " + victim.getName()));
            } else {
                player.message("Player '" + sub[1] + "' could not be found on this channel.");
            }
            break;
        case "seed":
            if (player.getMapId() != 910010000) {
                player.yellowMessage("This command can only be used in HPQ.");
                break;
            }
            Point[] pos = { new Point(7, -207), new Point(179, -447), new Point(-3, -687), new Point(-357, -687), new Point(-538, -447), new Point(-359, -207) };
            int[] seed = { 4001097, 4001096, 4001095, 4001100, 4001099, 4001098 };
            for (int i = 0; i < pos.length; i++) {
                Item item = new Item(seed[i], (byte) 0, (short) 1);
                player.getMap().spawnItemDrop(player, player, item, pos[i], false, true);
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            break;
        case "energy":
            System.out.println(c.getPlayer().getDojoEnergy());
            break;
        case "maxenergy":
            c.getPlayer().setDojoEnergy(10000);
            c.announce(MaplePacketCreator.getEnergy("energy", 10000));
            break;
        case "killall":
            MapleMap map = player.getMap();
            List<MapleMapObject> monsters = map.getMapObjectsInRange(player.getPosition(), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.MONSTER));
            int count = 0;
            for (MapleMapObject monstermo : monsters) {
                monster = (MapleMonster) monstermo;
                if (!monster.getStats().isFriendly() && !(monster.getId() >= 8810010 && monster.getId() <= 8810018)) {
                    map.damageMonster(player, monster, Integer.MAX_VALUE);
                    count++;
                }
            }
            player.dropMessage(5, "Killed " + count + " monsters.");
            break;
        case "notice":
            Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.serverNotice(6, "[Notice] " + joinStringFrom(sub, 1)));
            break;
        case "rip":
            Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.serverNotice(6, "[RIP]: " + joinStringFrom(sub, 1)));
            break;
        case "openportal":
            if (sub.length < 2) {
                player.yellowMessage("Syntax: !openportal <portalid>");
                break;
            }
            player.getMap().getPortal(sub[1]).setPortalState(true);
            break;
        case "closeportal":
            if (sub.length < 2) {
                player.yellowMessage("Syntax: !closeportal <portalid>");
                break;
            }
            player.getMap().getPortal(sub[1]).setPortalState(false);
            break;
        case "pe":
            String packet = "";
            try {
                InputStreamReader is = new FileReader("pe.txt");
                Properties packetProps = new Properties();
                packetProps.load(is);
                is.close();
                packet = packetProps.getProperty("pe");
            } catch (IOException ex) {
                ex.printStackTrace();
                player.yellowMessage("Failed to load pe.txt");
                break;
            }
            MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
            mplew.write(HexTool.getByteArrayFromHexString(packet));
            SeekableLittleEndianAccessor slea = new GenericSeekableLittleEndianAccessor(new ByteArrayByteStream(mplew.getPacket()));
            short packetId = slea.readShort();
            final MaplePacketHandler packetHandler = PacketProcessor.getProcessor(0, c.getChannel()).getHandler(packetId);
            if (packetHandler != null && packetHandler.validateState(c)) {
                try {
                    player.yellowMessage("Receiving: " + packet);
                    packetHandler.handlePacket(slea, c);
                } catch (final Throwable t) {
                    FilePrinter.printError(FilePrinter.PACKET_HANDLER + packetHandler.getClass().getName() + ".txt", t, "Error for " + (c.getPlayer() == null ? "" : "player ; " + c.getPlayer() + " on map ; " + c.getPlayer().getMapId() + " - ") + "account ; " + c.getAccountName() + "\r\n" + slea.toString());
                    break;
                }
            }
            break;
        case "startevent":
            int players = 50;
            if (sub.length > 1)
                players = Integer.parseInt(sub[1]);
            c.getChannelServer().setEvent(new MapleEvent(player.getMapId(), players));
            player.dropMessage(5, "The event has been set on " + player.getMap().getMapName() + " and will allow " + players + " players to join.");
            break;
        case "endevent":
            c.getChannelServer().setEvent(null);
            player.dropMessage(5, "You have ended the event. No more players may join.");
            break;
        case "online2":
            int total = 0;
            for (Channel ch : srv.getChannelsFromWorld(player.getWorld())) {
                int size = ch.getPlayerStorage().getAllCharacters().size();
                total += size;
                String s = "(Channel " + ch.getId() + " Online: " + size + ") : ";
                if (ch.getPlayerStorage().getAllCharacters().size() < 50) {
                    for (MapleCharacter chr : ch.getPlayerStorage().getAllCharacters()) {
                        s += MapleCharacter.makeMapleReadable(chr.getName()) + ", ";
                    }
                    player.dropMessage(6, s.substring(0, s.length() - 2));
                }
            }
            // player.dropMessage(6, "There are a total of " + total + " players online.");
            player.showHint("Players online: #e#r" + total + "#k#n.", 300);
            break;
        case "warpsnowball":
            List<MapleCharacter> chars = new ArrayList<>(player.getMap().getCharacters());
            for (MapleCharacter chr : chars) {
                chr.changeMap(109060000, chr.getTeam());
            }
            break;
        case "ban":
            if (sub.length < 3) {
                player.yellowMessage("Syntax: !ban <IGN> <Reason> (Please be descriptive)");
                break;
            }
            String ign = sub[1];
            String reason = joinStringFrom(sub, 2);
            MapleCharacter target = c.getChannelServer().getPlayerStorage().getCharacterByName(ign);
            if (target != null) {
                String readableTargetName = MapleCharacter.makeMapleReadable(target.getName());
                String ip = target.getClient().getSession().getRemoteAddress().toString().split(":")[0];
                // Ban ip
                PreparedStatement ps = null;
                try {
                    Connection con = DatabaseConnection.getConnection();
                    if (ip.matches("/[0-9]{1,3}\\..*")) {
                        ps = con.prepareStatement("INSERT INTO ipbans VALUES (DEFAULT, ?, ?)");
                        ps.setString(1, ip);
                        ps.setString(2, String.valueOf(target.getClient().getAccID()));
                        ps.executeUpdate();
                        ps.close();
                    }
                    con.close();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                    c.getPlayer().message("Error occured while banning IP address");
                    c.getPlayer().message(target.getName() + "'s IP was not banned: " + ip);
                }
                target.getClient().banMacs();
                reason = c.getPlayer().getName() + " banned " + readableTargetName + " for " + reason + " (IP: " + ip + ") " + "(MAC: " + c.getMacs() + ")";
                target.ban(reason);
                target.yellowMessage("You have been banned by #b" + c.getPlayer().getName() + " #k.");
                target.yellowMessage("Reason: " + reason);
                c.announce(MaplePacketCreator.getGMEffect(4, (byte) 0));
                final MapleCharacter rip = target;
                TimerManager.getInstance().schedule(new Runnable() {

                    @Override
                    public void run() {
                        rip.getClient().disconnect(false, false);
                    }
                }, // 5 Seconds
                5000);
                Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.serverNotice(6, "[RIP]: " + ign + " has been banned."));
            } else if (MapleCharacter.ban(ign, reason, false)) {
                c.announce(MaplePacketCreator.getGMEffect(4, (byte) 0));
                Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.serverNotice(6, "[RIP]: " + ign + " has been banned."));
            } else {
                c.announce(MaplePacketCreator.getGMEffect(6, (byte) 1));
            }
            break;
        case "unban":
            if (sub.length < 2) {
                player.yellowMessage("Syntax: !unban <playername>");
                break;
            }
            try {
                Connection con = DatabaseConnection.getConnection();
                int aid = MapleCharacter.getAccountIdByName(sub[1]);
                PreparedStatement p = con.prepareStatement("UPDATE accounts SET banned = -1 WHERE id = " + aid);
                p.executeUpdate();
                p = con.prepareStatement("DELETE FROM ipbans WHERE aid = " + aid);
                p.executeUpdate();
                p = con.prepareStatement("DELETE FROM macbans WHERE aid = " + aid);
                p.executeUpdate();
                con.close();
            } catch (Exception e) {
                e.printStackTrace();
                player.message("Failed to unban " + sub[1]);
                return true;
            }
            player.message("Unbanned " + sub[1]);
            break;
        case "healmap":
            for (MapleCharacter mch : player.getMap().getCharacters()) {
                if (mch != null) {
                    mch.setHp(mch.getMaxHp());
                    mch.updateSingleStat(MapleStat.HP, mch.getMaxHp());
                    mch.setMp(mch.getMaxMp());
                    mch.updateSingleStat(MapleStat.MP, mch.getMaxMp());
                }
            }
            break;
        case "healperson":
            victim = cserv.getPlayerStorage().getCharacterByName(sub[1]);
            if (victim != null) {
                victim.setHp(victim.getMaxHp());
                victim.updateSingleStat(MapleStat.HP, victim.getMaxHp());
                victim.setMp(victim.getMaxMp());
                victim.updateSingleStat(MapleStat.MP, victim.getMaxMp());
            } else {
                player.message("Player '" + sub[1] + "' could not be found on this channel.");
            }
            break;
        case "hurt":
            victim = cserv.getPlayerStorage().getCharacterByName(sub[1]);
            if (victim != null) {
                victim.setHp(1);
                victim.updateSingleStat(MapleStat.HP, 1);
            } else {
                player.message("Player '" + sub[1] + "' could not be found on this channel.");
            }
            break;
        case "killmap":
            for (MapleCharacter mch : player.getMap().getCharacters()) {
                mch.setHp(0);
                mch.updateSingleStat(MapleStat.HP, 0);
            }
            break;
        case "night":
            player.getMap().broadcastNightEffect();
            player.yellowMessage("Done.");
            break;
        case "npc":
            if (sub.length < 2) {
                player.yellowMessage("Syntax: !npc <npcid>");
                break;
            }
            MapleNPC npc = MapleLifeFactory.getNPC(Integer.parseInt(sub[1]));
            if (npc != null) {
                npc.setPosition(player.getPosition());
                npc.setCy(player.getPosition().y);
                npc.setRx0(player.getPosition().x + 50);
                npc.setRx1(player.getPosition().x - 50);
                npc.setFh(player.getMap().getFootholds().findBelow(c.getPlayer().getPosition()).getId());
                player.getMap().addMapObject(npc);
                player.getMap().broadcastMessage(MaplePacketCreator.spawnNPC(npc));
            }
            break;
        case "face":
            if (sub.length < 2) {
                player.yellowMessage("Syntax: !face [<playername>] <faceid>");
                break;
            }
            try {
                if (sub.length == 2) {
                    int itemId = Integer.parseInt(sub[1]);
                    if (!(itemId >= 20000 && itemId < 22000) || MapleItemInformationProvider.getInstance().getName(itemId) == null) {
                        player.yellowMessage("Face id '" + sub[1] + "' does not exist.");
                        break;
                    }
                    player.setFace(itemId);
                    player.updateSingleStat(MapleStat.FACE, itemId);
                    player.equipChanged();
                } else {
                    int itemId = Integer.parseInt(sub[2]);
                    if (!(itemId >= 20000 && itemId < 22000) || MapleItemInformationProvider.getInstance().getName(itemId) == null) {
                        player.yellowMessage("Face id '" + sub[2] + "' does not exist.");
                        break;
                    }
                    victim = c.getChannelServer().getPlayerStorage().getCharacterByName(sub[1]);
                    if (victim == null) {
                        victim.setFace(itemId);
                        victim.updateSingleStat(MapleStat.FACE, itemId);
                        victim.equipChanged();
                    } else {
                        player.yellowMessage("Player '" + sub[1] + "' has not been found on this channel.");
                    }
                }
            } catch (Exception e) {
            }
            break;
        case "hair":
            if (sub.length < 2) {
                player.yellowMessage("Syntax: !hair [<playername>] <hairid>");
                break;
            }
            try {
                if (sub.length == 2) {
                    int itemId = Integer.parseInt(sub[1]);
                    if (!(itemId >= 30000 && itemId < 35000) || MapleItemInformationProvider.getInstance().getName(itemId) == null) {
                        player.yellowMessage("Hair id '" + sub[1] + "' does not exist.");
                        break;
                    }
                    player.setHair(itemId);
                    player.updateSingleStat(MapleStat.HAIR, itemId);
                    player.equipChanged();
                } else {
                    int itemId = Integer.parseInt(sub[2]);
                    if (!(itemId >= 30000 && itemId < 35000) || MapleItemInformationProvider.getInstance().getName(itemId) == null) {
                        player.yellowMessage("Hair id '" + sub[2] + "' does not exist.");
                        break;
                    }
                    victim = c.getChannelServer().getPlayerStorage().getCharacterByName(sub[1]);
                    if (victim != null) {
                        victim.setHair(itemId);
                        victim.updateSingleStat(MapleStat.HAIR, itemId);
                        victim.equipChanged();
                    } else {
                        player.yellowMessage("Player '" + sub[1] + "' has not been found on this channel.");
                    }
                }
            } catch (Exception e) {
            }
            break;
        default:
            return false;
    }
    return true;
}
Also used : MapleCharacter(client.MapleCharacter) MaplePacketLittleEndianWriter(tools.data.output.MaplePacketLittleEndianWriter) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) MapleMapObject(server.maps.MapleMapObject) Properties(java.util.Properties) URL(java.net.URL) MapleMap(server.maps.MapleMap) MapleMapItem(server.maps.MapleMapItem) Item(client.inventory.Item) ByteArrayByteStream(tools.data.input.ByteArrayByteStream) FileReader(java.io.FileReader) MapleNPC(server.life.MapleNPC) MapleEvent(server.events.gm.MapleEvent) InputStreamReader(java.io.InputStreamReader) Channel(net.server.channel.Channel) SeekableLittleEndianAccessor(tools.data.input.SeekableLittleEndianAccessor) GenericSeekableLittleEndianAccessor(tools.data.input.GenericSeekableLittleEndianAccessor) Connection(java.sql.Connection) DatabaseConnection(tools.DatabaseConnection) PreparedStatement(java.sql.PreparedStatement) Point(java.awt.Point) SpawnPoint(server.life.SpawnPoint) IOException(java.io.IOException) Point(java.awt.Point) SpawnPoint(server.life.SpawnPoint) SQLException(java.sql.SQLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) GenericSeekableLittleEndianAccessor(tools.data.input.GenericSeekableLittleEndianAccessor) MapleExpedition(server.expeditions.MapleExpedition) BufferedReader(java.io.BufferedReader) MaplePacketHandler(net.MaplePacketHandler) MapleMonster(server.life.MapleMonster)

Aggregations

MapleCharacter (client.MapleCharacter)2 Point (java.awt.Point)2 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 Channel (net.server.channel.Channel)2 MapleEvent (server.events.gm.MapleEvent)2 MapleMonster (server.life.MapleMonster)2 SpawnPoint (server.life.SpawnPoint)2 DatabaseConnection (tools.DatabaseConnection)2 Item (client.inventory.Item)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 ResultSet (java.sql.ResultSet)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1