use of server.maps.MapleMapObject in project HeavenMS by ronancpl.
the class MapleStatEffect method applyBuff.
private void applyBuff(MapleCharacter applyfrom, boolean useMaxRange) {
if (isPartyBuff() && (applyfrom.getParty() != null || isGmBuff())) {
Rectangle bounds = (!useMaxRange) ? calculateBoundingBox(applyfrom.getPosition(), applyfrom.isFacingLeft()) : new Rectangle(Integer.MIN_VALUE / 2, Integer.MIN_VALUE / 2, Integer.MAX_VALUE, Integer.MAX_VALUE);
List<MapleMapObject> affecteds = applyfrom.getMap().getMapObjectsInRect(bounds, Arrays.asList(MapleMapObjectType.PLAYER));
List<MapleCharacter> affectedp = new ArrayList<>(affecteds.size());
for (MapleMapObject affectedmo : affecteds) {
MapleCharacter affected = (MapleCharacter) affectedmo;
if (affected != applyfrom && (isGmBuff() || applyfrom.getParty().equals(affected.getParty()))) {
if ((!isResurrection() && affected.isAlive()) || (isResurrection() && !affected.isAlive())) {
affectedp.add(affected);
}
}
}
for (MapleCharacter affected : affectedp) {
applyTo(applyfrom, affected, false, null, useMaxRange);
affected.getClient().announce(MaplePacketCreator.showOwnBuffEffect(sourceid, 2));
affected.getMap().broadcastMessage(affected, MaplePacketCreator.showBuffeffect(affected.getId(), sourceid, 2), false);
}
}
}
use of server.maps.MapleMapObject in project HeavenMS by ronancpl.
the class MapleMonster method canUseSkill.
public boolean canUseSkill(MobSkill toUse) {
if (toUse == null) {
return false;
}
monsterLock.lock();
try {
for (Pair<Integer, Integer> skill : usedSkills) {
if (skill.getLeft() == toUse.getSkillId() && skill.getRight() == toUse.getSkillLevel()) {
return false;
}
}
} finally {
monsterLock.unlock();
}
if (toUse.getLimit() > 0) {
monsterLock.lock();
try {
if (this.skillsUsed.containsKey(new Pair<>(toUse.getSkillId(), toUse.getSkillLevel()))) {
int times = this.skillsUsed.get(new Pair<>(toUse.getSkillId(), toUse.getSkillLevel()));
if (times >= toUse.getLimit()) {
return false;
}
}
} finally {
monsterLock.unlock();
}
}
if (toUse.getSkillId() == 200) {
Collection<MapleMapObject> mmo = getMap().getMapObjects();
int i = 0;
for (MapleMapObject mo : mmo) {
if (mo.getType() == MapleMapObjectType.MONSTER) {
i++;
}
}
if (i > 100) {
return false;
}
}
return true;
}
use of server.maps.MapleMapObject in project HeavenMS by ronancpl.
the class Commands method executeHeavenMsCommandLv5.
public static boolean executeHeavenMsCommandLv5(Channel cserv, Server srv, MapleClient c, String[] sub) {
// Developer
MapleCharacter player = c.getPlayer();
MapleMonster monster;
switch(sub[0]) {
case "debugmonster":
List<MapleMapObject> monsters = player.getMap().getMapObjectsInRange(player.getPosition(), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.MONSTER));
for (MapleMapObject monstermo : monsters) {
monster = (MapleMonster) monstermo;
player.message("Monster ID: " + monster.getId() + " Aggro target: " + ((monster.getController() != null) ? monster.getController().getName() : "<none>"));
}
break;
case "debugpacket":
player.getMap().broadcastMessage(MaplePacketCreator.customPacket(joinStringFrom(sub, 1)));
break;
case "debugportal":
MaplePortal portal = player.getMap().findClosestPortal(player.getPosition());
if (portal != null)
player.dropMessage(6, "Closest portal: " + portal.getId() + " '" + portal.getName() + "' Type: " + portal.getType() + " --> toMap: " + portal.getTargetMapId() + " scriptname: '" + portal.getScriptName() + "' state: " + portal.getPortalState() + ".");
else
player.dropMessage(6, "There is no portal on this map.");
break;
case "debugspawnpoint":
SpawnPoint sp = player.getMap().findClosestSpawnpoint(player.getPosition());
if (sp != null)
player.dropMessage(6, "Closest mob spawn point: " + " Position: x " + sp.getPosition().getX() + " y " + sp.getPosition().getY() + " Spawns mobid: '" + sp.getMonsterId() + "' --> canSpawn: " + !sp.getDenySpawn() + " canSpawnRightNow: " + sp.shouldSpawn() + ".");
else
player.dropMessage(6, "There is no mob spawn point on this map.");
break;
case "debugpos":
player.dropMessage(6, "Current map position: (" + player.getPosition().getX() + ", " + player.getPosition().getY() + ").");
break;
case "debugmap":
player.dropMessage(6, "Current map id " + player.getMap().getId() + ", event: '" + ((player.getMap().getEventInstance() != null) ? player.getMap().getEventInstance().getName() : "null") + "'; Players: " + player.getMap().getAllPlayers().size() + ", Mobs: " + player.getMap().countMonsters() + ", Reactors: " + player.getMap().countReactors() + ", Items: " + player.getMap().countItems() + ", Objects: " + player.getMap().getMapObjects().size() + ".");
break;
case "debugmobsp":
player.getMap().reportMonsterSpawnPoints(player);
break;
case "debugevent":
if (player.getEventInstance() == null)
player.dropMessage(6, "Player currently not in an event.");
else
player.dropMessage(6, "Current event name: " + player.getEventInstance().getName() + ".");
break;
case "debugareas":
player.dropMessage(6, "Configured areas on map " + player.getMapId() + ":");
byte index = 0;
for (Rectangle rect : player.getMap().getAreas()) {
player.dropMessage(6, "Id: " + index + " -> posX: " + rect.getX() + " posY: '" + rect.getY() + "' dX: " + rect.getWidth() + " dY: " + rect.getHeight() + ".");
index++;
}
break;
case "debugreactors":
player.dropMessage(6, "Current reactor states on map " + player.getMapId() + ":");
for (MapleMapObject mmo : player.getMap().getReactors()) {
MapleReactor mr = (MapleReactor) mmo;
player.dropMessage(6, "Id: " + mr.getId() + " Oid: " + mr.getObjectId() + " name: '" + mr.getName() + "' -> Type: " + mr.getReactorType() + " State: " + mr.getState() + " Event State: " + mr.getEventState() + " Position: x " + mr.getPosition().getX() + " y " + mr.getPosition().getY() + ".");
}
break;
case "debugservercoupons":
case "debugcoupons":
String s = "Currently active SERVER coupons: ";
for (Integer i : Server.getInstance().getActiveCoupons()) {
s += (i + " ");
}
player.dropMessage(6, s);
break;
case "debugplayercoupons":
String st = "Currently active PLAYER coupons: ";
for (Integer i : player.getActiveCoupons()) {
st += (i + " ");
}
player.dropMessage(6, st);
break;
case "debugtimer":
TimerManager tMan = TimerManager.getInstance();
player.dropMessage(6, "Total Task: " + tMan.getTaskCount() + " Current Task: " + tMan.getQueuedTasks() + " Active Task: " + tMan.getActiveCount() + " Completed Task: " + tMan.getCompletedTaskCount());
break;
default:
return false;
}
return true;
}
use of server.maps.MapleMapObject 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;
}
use of server.maps.MapleMapObject in project HeavenMS by ronancpl.
the class AdminCommandHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if (!c.getPlayer().isGM()) {
return;
}
byte mode = slea.readByte();
String victim;
MapleCharacter target;
switch(mode) {
case // Level1~Level8 & Package1~Package2
0x00:
int[][] toSpawn = MapleItemInformationProvider.getInstance().getSummonMobs(slea.readInt());
for (int z = 0; z < toSpawn.length; z++) {
int[] toSpawnChild = toSpawn[z];
if (Randomizer.nextInt(101) <= toSpawnChild[1]) {
c.getPlayer().getMap().spawnMonsterOnGroundBelow(MapleLifeFactory.getMonster(toSpawnChild[0]), c.getPlayer().getPosition());
}
}
c.announce(MaplePacketCreator.enableActions());
break;
case 0x01:
{
// /d (inv)
byte type = slea.readByte();
MapleInventory in = c.getPlayer().getInventory(MapleInventoryType.getByType(type));
for (short i = 1; i <= in.getSlotLimit(); i++) {
// TODO What is the point of this loop?
if (in.getItem(i) != null) {
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.getByType(type), i, in.getItem(i).getQuantity(), false);
}
return;
}
break;
}
case // Exp
0x02:
c.getPlayer().setExp(slea.readInt());
break;
case // /ban <name>
0x03:
c.getPlayer().yellowMessage("Please use !ban <IGN> <Reason>");
break;
case // /block <name> <duration (in days)> <HACK/BOT/AD/HARASS/CURSE/SCAM/MISCONDUCT/SELL/ICASH/TEMP/GM/IPROGRAM/MEGAPHONE>
0x04:
victim = slea.readMapleAsciiString();
// reason
int type = slea.readByte();
int duration = slea.readInt();
String description = slea.readMapleAsciiString();
String reason = c.getPlayer().getName() + " used /ban to ban";
target = c.getChannelServer().getPlayerStorage().getCharacterByName(victim);
if (target != null) {
String readableTargetName = MapleCharacter.makeMapleReadable(target.getName());
String ip = target.getClient().getSession().getRemoteAddress().toString().split(":")[0];
reason += readableTargetName + " (IP: " + ip + ")";
if (duration == -1) {
target.ban(description + " " + reason);
} else {
target.block(type, duration, description);
target.sendPolice(duration, reason, 6000);
}
c.announce(MaplePacketCreator.getGMEffect(4, (byte) 0));
} else if (MapleCharacter.ban(victim, reason, false)) {
c.announce(MaplePacketCreator.getGMEffect(4, (byte) 0));
} else {
c.announce(MaplePacketCreator.getGMEffect(6, (byte) 1));
}
break;
case // /h, information by vana (and tele mode f1) ... hide ofcourse
0x10:
c.getPlayer().Hide(slea.readByte() == 1);
break;
case // Entering a map
0x11:
switch(slea.readByte()) {
case // /u
0:
StringBuilder sb = new StringBuilder("USERS ON THIS MAP: ");
for (MapleCharacter mc : c.getPlayer().getMap().getCharacters()) {
sb.append(mc.getName());
sb.append(" ");
}
c.getPlayer().message(sb.toString());
break;
case // /uclip and entering a map
12:
break;
}
break;
case // Send
0x12:
victim = slea.readMapleAsciiString();
int mapId = slea.readInt();
c.getChannelServer().getPlayerStorage().getCharacterByName(victim).changeMap(c.getChannelServer().getMapFactory().getMap(mapId));
break;
case // Kill
0x15:
int mobToKill = slea.readInt();
int amount = slea.readInt();
List<MapleMapObject> monsterx = c.getPlayer().getMap().getMapObjectsInRange(c.getPlayer().getPosition(), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.MONSTER));
for (int x = 0; x < amount; x++) {
MapleMonster monster = (MapleMonster) monsterx.get(x);
if (monster.getId() == mobToKill) {
c.getPlayer().getMap().killMonster(monster, c.getPlayer(), true);
monster.giveExpToCharacter(c.getPlayer(), monster.getExp(), true, 1);
}
}
break;
case // Questreset
0x16:
MapleQuest.getInstance(slea.readShort()).reset(c.getPlayer());
break;
case // Summon
0x17:
int mobId = slea.readInt();
int quantity = slea.readInt();
for (int i = 0; i < quantity; i++) {
c.getPlayer().getMap().spawnMonsterOnGroundBelow(MapleLifeFactory.getMonster(mobId), c.getPlayer().getPosition());
}
break;
case // Maple & Mobhp
0x18:
int mobHp = slea.readInt();
c.getPlayer().dropMessage("Monsters HP");
List<MapleMapObject> monsters = c.getPlayer().getMap().getMapObjectsInRange(c.getPlayer().getPosition(), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.MONSTER));
for (MapleMapObject mobs : monsters) {
MapleMonster monster = (MapleMonster) mobs;
if (monster.getId() == mobHp) {
c.getPlayer().dropMessage(monster.getName() + ": " + monster.getHp());
}
}
break;
case // Warn
0x1E:
victim = slea.readMapleAsciiString();
String message = slea.readMapleAsciiString();
target = c.getChannelServer().getPlayerStorage().getCharacterByName(victim);
if (target != null) {
target.getClient().announce(MaplePacketCreator.serverNotice(1, message));
c.announce(MaplePacketCreator.getGMEffect(0x1E, (byte) 1));
} else {
c.announce(MaplePacketCreator.getGMEffect(0x1E, (byte) 0));
}
break;
case // /Artifact Ranking
0x24:
break;
case // Testing purpose
0x77:
if (slea.available() == 4) {
System.out.println(slea.readInt());
} else if (slea.available() == 2) {
System.out.println(slea.readShort());
}
break;
default:
System.out.println("New GM packet encountered (MODE : " + mode + ": " + slea.toString());
break;
}
}
Aggregations