Player/NPC Shop patch + Fredrick/Duey patch + Loot w. time GMS-like

Reading approximated unitPrice value from WZ in such a fashion that the new double value can be represented in float point without losing too much data.
Fixed rechargeables with quantity 0 set on the playershop/hiredmerchant being handed back to the owner with quantity 1.
Solved many concurrecy issues related with items on the field and playershop/hiredmerchant.
Fixed anomalies with waiting time before picking up other players items, now acting GMS-like.
Added/patched copyleft claims in files that are from my own authorship. Please see backtrack_licenses/readme.txt for more info about this move.
Fixed issues with item retrieval when using bundles on playershop/hiredmerchant.
Fixed some exploits with playershop/hiredmerchant.
Fixed a glitch with npcshop when trying to recharge/buy items without having enough mesos.
Added portal sound effect for some scripted portals that still lacked it.
Fixed some exploits with NPCs Fredrick and Duey.
Fixed Body Pressure not displaying damage to other players.
Added a flag that permits town scrolls to act like a "banish" for players. This renders the antibanish scroll effect available.
This commit is contained in:
ronancpl
2018-05-10 13:09:57 -03:00
parent 727dfb2d62
commit 80b1776ad3
348 changed files with 3963 additions and 1597 deletions

View File

@@ -22,6 +22,7 @@
package client;
import java.awt.Point;
import java.lang.ref.WeakReference;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -45,7 +46,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Comparator;
import tools.locks.MonitoredReentrantLock;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.atomic.AtomicInteger;
@@ -106,6 +106,7 @@ import tools.FilePrinter;
import tools.MaplePacketCreator;
import tools.Pair;
import tools.Randomizer;
import tools.locks.MonitoredReentrantLock;
import client.autoban.AutobanManager;
import client.inventory.Equip;
import client.inventory.Item;
@@ -242,6 +243,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
private SavedLocation savedLocations[];
private SkillMacro[] skillMacros = new SkillMacro[5];
private List<Integer> lastmonthfameids;
private List<WeakReference<MapleMap>> lastVisitedMaps = new LinkedList<>();
private final Map<Short, MapleQuestStatus> quests;
private Set<MapleMonster> controlled = new LinkedHashSet<>();
private Map<Integer, String> entered = new LinkedHashMap<>();
@@ -1176,7 +1178,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
this.banishTime = 0;
}
private void setBanishPlayerData(int banishMap, int banishSp, long banishTime) {
public void setBanishPlayerData(int banishMap, int banishSp, long banishTime) {
this.banishMap = banishMap;
this.banishSp = banishSp;
this.banishTime = banishTime;
@@ -1319,6 +1321,74 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
return false;
}
public void updateMapDropsUponPartyOperation(List<MapleCharacter> exPartyMembers) {
List<WeakReference<MapleMap>> mapids;
petLock.lock();
try {
mapids = new LinkedList<>(lastVisitedMaps);
} finally {
petLock.unlock();
}
List<MapleCharacter> partyMembers = new LinkedList<>();
for(MapleCharacter mc : (exPartyMembers != null) ? exPartyMembers : this.getPartyMembers()) {
if(mc.isLoggedinWorld()) {
partyMembers.add(mc);
}
}
MapleCharacter partyLeaver = null;
if(exPartyMembers != null) {
partyMembers.remove(this);
partyLeaver = this;
}
int partyId = exPartyMembers != null ? 0 : this.getPartyId();
for(WeakReference<MapleMap> mapRef : mapids) {
MapleMap mapObj = mapRef.get();
if(mapObj != null) {
mapObj.updatePlayerItemDrops(partyId, id, partyMembers, partyLeaver);
}
}
}
private Integer getVisitedMapIndex(MapleMap map) {
int idx = 0;
for(WeakReference<MapleMap> mapRef : lastVisitedMaps) {
if(map.equals(mapRef.get())) {
return idx;
}
idx++;
}
return -1;
}
public void visitMap(MapleMap map) {
petLock.lock();
try {
int idx = getVisitedMapIndex(map);
if(idx == -1) {
if(lastVisitedMaps.size() == ServerConstants.MAP_VISITED_SIZE) {
lastVisitedMaps.remove(0);
}
} else {
WeakReference<MapleMap> mapRef = lastVisitedMaps.remove(idx);
lastVisitedMaps.add(mapRef);
return;
}
lastVisitedMaps.add(new WeakReference<>(map));
} finally {
petLock.unlock();
}
}
private void changeMapInternal(final MapleMap to, final Point pos, final byte[] warpPacket) {
if(!canWarpMap) return;
@@ -1335,6 +1405,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
map = to;
setPosition(pos);
map.addPlayer(this);
visitMap(map);
prtLock.lock();
try {
@@ -1522,50 +1593,55 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
return;
}
boolean isPet = petIndex > -1;
final byte[] pickupPacket = MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), (isPet) ? 5 : 2, this.getId(), isPet, petIndex);
boolean hasSpaceInventory = true;
if (mapitem.getItemId() == 4031865 || mapitem.getItemId() == 4031866 || mapitem.getMeso() > 0 || ii.isConsumeOnPickup(mapitem.getItemId()) || (hasSpaceInventory = MapleInventoryManipulator.checkSpace(client, mapitem.getItemId(), mapitem.getItem().getQuantity(), mapitem.getItem().getOwner()))) {
if ((this.getMapId() > 209000000 && this.getMapId() < 209000016) || (this.getMapId() >= 990000500 && this.getMapId() <= 990000502)) {//happyville trees and guild PQ
if (!mapitem.isPlayerDrop() || mapitem.getDropper().getObjectId() == client.getPlayer().getObjectId()) {
if(mapitem.getMeso() > 0) {
this.gainMeso(mapitem.getMeso(), true, true, false);
this.getMap().pickItemDrop(pickupPacket, mapitem);
} else if(mapitem.getItemId() == 4031865 || mapitem.getItemId() == 4031866) {
// Add NX to account, show effect and make item disappear
int nxGain = mapitem.getItemId() == 4031865 ? 100 : 250;
this.getCashShop().gainCash(1, nxGain);
showHint("You have earned #e#b" + nxGain + " NX#k#n. (" + this.getCashShop().getCash(1) + " NX)", 300);
this.getMap().pickItemDrop(pickupPacket, mapitem);
} else if (MapleInventoryManipulator.addFromDrop(client, mapitem.getItem(), true)) {
this.getMap().pickItemDrop(pickupPacket, mapitem);
} else {
client.announce(MaplePacketCreator.enableActions());
return;
}
} else {
client.announce(MaplePacketCreator.showItemUnavailable());
client.announce(MaplePacketCreator.enableActions());
return;
}
mapitem.lockItem();
try {
if(mapitem.isPickedUp()) {
client.announce(MaplePacketCreator.showItemUnavailable());
client.announce(MaplePacketCreator.enableActions());
return;
}
boolean isPet = petIndex > -1;
final byte[] pickupPacket = MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), (isPet) ? 5 : 2, this.getId(), isPet, petIndex);
boolean hasSpaceInventory = true;
if (mapitem.getItemId() == 4031865 || mapitem.getItemId() == 4031866 || mapitem.getMeso() > 0 || ii.isConsumeOnPickup(mapitem.getItemId()) || (hasSpaceInventory = MapleInventoryManipulator.checkSpace(client, mapitem.getItemId(), mapitem.getItem().getQuantity(), mapitem.getItem().getOwner()))) {
int mapId = this.getMapId();
if ((mapId > 209000000 && mapId < 209000016) || (mapId >= 990000500 && mapId <= 990000502)) {//happyville trees and guild PQ
if (!mapitem.isPlayerDrop() || mapitem.getDropper().getObjectId() == client.getPlayer().getObjectId()) {
if(mapitem.getMeso() > 0) {
this.gainMeso(mapitem.getMeso(), true, true, false);
this.getMap().pickItemDrop(pickupPacket, mapitem);
} else if(mapitem.getItemId() == 4031865 || mapitem.getItemId() == 4031866) {
// Add NX to account, show effect and make item disappear
int nxGain = mapitem.getItemId() == 4031865 ? 100 : 250;
this.getCashShop().gainCash(1, nxGain);
showHint("You have earned #e#b" + nxGain + " NX#k#n. (" + this.getCashShop().getCash(1) + " NX)", 300);
this.getMap().pickItemDrop(pickupPacket, mapitem);
} else if (MapleInventoryManipulator.addFromDrop(client, mapitem.getItem(), true)) {
this.getMap().pickItemDrop(pickupPacket, mapitem);
} else {
client.announce(MaplePacketCreator.enableActions());
return;
}
} else {
client.announce(MaplePacketCreator.showItemUnavailable());
client.announce(MaplePacketCreator.enableActions());
return;
}
client.announce(MaplePacketCreator.enableActions());
return;
}
synchronized (mapitem) {
if (mapitem.getQuest() > 0 && !this.needQuestItem(mapitem.getQuest(), mapitem.getItemId())) {
client.announce(MaplePacketCreator.showItemUnavailable());
client.announce(MaplePacketCreator.enableActions());
return;
}
if (mapitem.isPickedUp()) {
client.announce(MaplePacketCreator.showItemUnavailable());
client.announce(MaplePacketCreator.enableActions());
return;
}
if (mapitem.getMeso() > 0) {
prtLock.lock();
try {
@@ -1628,10 +1704,12 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
}
this.getMap().pickItemDrop(pickupPacket, mapitem);
} else if(!hasSpaceInventory) {
client.announce(MaplePacketCreator.getInventoryFull());
client.announce(MaplePacketCreator.getShowInventoryFull());
}
} else if(!hasSpaceInventory) {
client.announce(MaplePacketCreator.getInventoryFull());
client.announce(MaplePacketCreator.getShowInventoryFull());
} finally {
mapitem.unlockItem();
}
}
client.announce(MaplePacketCreator.enableActions());
@@ -4746,7 +4824,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
e.printStackTrace();
}
}
public void handleEnergyChargeGain() { // to get here energychargelevel has to be > 0
Skill energycharge = isCygnus() ? SkillFactory.getSkill(ThunderBreaker.ENERGY_CHARGE) : SkillFactory.getSkill(Marauder.ENERGY_CHARGE);
MapleStatEffect ceffect;
@@ -6111,8 +6189,10 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
try {
if (party != null) {
int channel = client.getChannel();
int mapId = getMapId();
for (MaplePartyCharacter partychar : party.getMembers()) {
if (partychar.getMapId() == getMapId() && partychar.getChannel() == channel) {
if (partychar.getMapId() == mapId && partychar.getChannel() == channel) {
MapleCharacter other = Server.getInstance().getWorld(world).getChannel(channel).getPlayerStorage().getCharacterByName(partychar.getName());
if (other != null) {
client.announce(MaplePacketCreator.updatePartyMemberHP(other.getId(), other.getHp(), other.getCurrentMaxHp()));
@@ -6983,6 +7063,23 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
}
merchantmeso = set;
}
public synchronized void withdrawMerchantMesos() {
int merchantMeso = this.getMerchantMeso();
if (merchantMeso > 0) {
int possible = Integer.MAX_VALUE - merchantMeso;
if (possible > 0) {
if (possible < merchantMeso) {
this.gainMeso(possible, false);
this.setMerchantMeso(merchantMeso - possible);
} else {
this.gainMeso(merchantMeso, false);
this.setMerchantMeso(0);
}
}
}
}
public void setHiredMerchant(MapleHiredMerchant merchant) {
this.hiredMerchant = merchant;
@@ -7264,7 +7361,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
if (item == null){ //Basic check
return(0);
}
if (ItemConstants.isRechargable(item.getItemId())) {
if (ItemConstants.isRechargeable(item.getItemId())) {
quantity = item.getQuantity();
}
if (quantity < 0) {
@@ -7540,8 +7637,10 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
private void updatePartyMemberHPInternal() {
if (party != null) {
int channel = client.getChannel();
int mapId = getMapId();
for (MaplePartyCharacter partychar : party.getMembers()) {
if (partychar.getMapId() == getMapId() && partychar.getChannel() == channel) {
if (partychar.getMapId() == mapId && partychar.getChannel() == channel) {
MapleCharacter other = Server.getInstance().getWorld(world).getChannel(channel).getPlayerStorage().getCharacterByName(partychar.getName());
if (other != null) {
other.client.announce(MaplePacketCreator.updatePartyMemberHP(getId(), this.hp, maxhp));

View File

@@ -106,6 +106,7 @@ public class MapleClient {
private byte gender = -1;
private boolean disconnecting = false;
private final Lock lock = new MonitoredReentrantLock(MonitoredLockType.CLIENT, true);
private static final Lock loginLock = new MonitoredReentrantLock(MonitoredLockType.CLIENT, true);
private int votePoints;
private int voteTime = -1;
private long lastNpcClick;
@@ -420,13 +421,17 @@ public class MapleClient {
}
public int finishLogin() {
synchronized (MapleClient.class) {
if (getLoginState() > LOGIN_NOTLOGGEDIN) { // 0 = LOGIN_NOTLOGGEDIN, 1= LOGIN_SERVER_TRANSITION, 2 = LOGIN_LOGGEDIN
loggedIn = false;
return 7;
}
updateLoginState(LOGIN_LOGGEDIN);
}
loginLock.lock();
try {
if (getLoginState() > LOGIN_NOTLOGGEDIN) { // 0 = LOGIN_NOTLOGGEDIN, 1= LOGIN_SERVER_TRANSITION, 2 = LOGIN_LOGGEDIN
loggedIn = false;
return 7;
}
updateLoginState(LOGIN_LOGGEDIN);
} finally {
loginLock.unlock();
}
return 0;
}

View File

@@ -1202,7 +1202,7 @@ public class Commands {
case "heal":
player.setHpMp(30000);
break;
case "item":
case "drop":
if (sub.length < 2){
@@ -2533,23 +2533,31 @@ public class Commands {
case "forcevac":
List<MapleMapObject> items = player.getMap().getMapObjectsInRange(player.getPosition(), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.ITEM));
for (MapleMapObject item : items) {
MapleMapItem mapItem = (MapleMapItem) item;
if (mapItem.getMeso() > 0) {
player.gainMeso(mapItem.getMeso(), true);
} else if(mapItem.getItemId() == 4031865 || mapItem.getItemId() == 4031866) {
// Add NX to account, show effect and make item disappear
player.getCashShop().gainCash(1, mapItem.getItemId() == 4031865 ? 100 : 250);
} else if (mapItem.getItem().getItemId() >= 5000000 && mapItem.getItem().getItemId() <= 5000100) {
int petId = MaplePet.createPet(mapItem.getItem().getItemId());
if (petId == -1) {
continue;
}
MapleInventoryManipulator.addById(c, mapItem.getItem().getItemId(), mapItem.getItem().getQuantity(), null, petId);
} else {
MapleInventoryManipulator.addFromDrop(c, mapItem.getItem(), true);
}
player.getMap().pickItemDrop(MaplePacketCreator.removeItemFromMap(mapItem.getObjectId(), 2, player.getId()), mapItem);
MapleMapItem mapItem = (MapleMapItem) item;
mapItem.lockItem();
try {
if(mapItem.isPickedUp()) continue;
if (mapItem.getMeso() > 0) {
player.gainMeso(mapItem.getMeso(), true);
} else if(mapItem.getItemId() == 4031865 || mapItem.getItemId() == 4031866) {
// Add NX to account, show effect and make item disappear
player.getCashShop().gainCash(1, mapItem.getItemId() == 4031865 ? 100 : 250);
} else if (mapItem.getItem().getItemId() >= 5000000 && mapItem.getItem().getItemId() <= 5000100) {
int petId = MaplePet.createPet(mapItem.getItem().getItemId());
if (petId == -1) {
continue;
}
MapleInventoryManipulator.addById(c, mapItem.getItem().getItemId(), mapItem.getItem().getQuantity(), null, petId);
} else {
MapleInventoryManipulator.addFromDrop(c, mapItem.getItem(), true);
}
player.getMap().pickItemDrop(MaplePacketCreator.removeItemFromMap(mapItem.getObjectId(), 2, player.getId()), mapItem);
} finally {
mapItem.unlockItem();
}
}
break;

View File

@@ -146,7 +146,7 @@ public class MapleInventory implements Iterable<Item> {
List<Item> itemList = listById(itemId);
int openSlot = 0;
if(!ItemConstants.isRechargable(itemId)) {
if(!ItemConstants.isRechargeable(itemId)) {
for (Item item : itemList) {
required -= item.getQuantity();
@@ -246,7 +246,7 @@ public class MapleInventory implements Iterable<Item> {
source.setPosition(dSlot);
inventory.put(dSlot, source);
inventory.remove(sSlot);
} else if (target.getItemId() == source.getItemId() && !ItemConstants.isRechargable(source.getItemId()) && isSameOwner(source, target)) {
} else if (target.getItemId() == source.getItemId() && !ItemConstants.isRechargeable(source.getItemId()) && isSameOwner(source, target)) {
if (type.getType() == MapleInventoryType.EQUIP.getType() || type.getType() == MapleInventoryType.CASH.getType()) {
swap(target, source);
} else if (source.getQuantity() + target.getQuantity() > slotMax) {

View File

@@ -1,21 +1,22 @@
/*
* This file is part of the HeavenMS (MapleSolaxiaV2) Maple Story Server
*
* Copyright (C) 2017 RonanLana
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
This file is part of the HeavenMS MapleStory Server
Copyleft (L) 2016 - 2018 RonanLana
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package client.newyear;
import client.MapleCharacter;

View File

@@ -0,0 +1,493 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
Copyleft (L) 2016 - 2018 RonanLana (HeavenMS)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package client.processor;
import client.MapleCharacter;
import client.MapleClient;
import client.autoban.AutobanFactory;
import client.inventory.Equip;
import client.inventory.Item;
import client.inventory.MapleInventoryType;
import constants.ItemConstants;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;
import net.server.channel.Channel;
import server.DueyPackages;
import server.MapleInventoryManipulator;
import server.MapleItemInformationProvider;
import tools.DatabaseConnection;
import tools.FilePrinter;
import tools.MaplePacketCreator;
/**
*
* @author RonanLana (synchronization of Duey modules)
*/
public class DueyProcessor {
public enum Actions {
TOSERVER_SEND_ITEM(0x02),
TOSERVER_CLAIM_PACKAGE(0x04),
TOSERVER_REMOVE_PACKAGE(0x05),
TOSERVER_CLOSE_DUEY(0x07),
TOCLIENT_OPEN_DUEY(0x08),
TOCLIENT_SEND_ENABLE_ACTIONS(0x09),
TOCLIENT_SEND_NOT_ENOUGH_MESOS(0x0A),
TOCLIENT_SEND_INCORRECT_REQUEST(0x0B),
TOCLIENT_SEND_NAME_DOES_NOT_EXIST(0x0C),
TOCLIENT_SEND_SAMEACC_ERROR(0x0D),
TOCLIENT_SEND_RECEIVER_STORAGE_FULL(0x0E),
TOCLIENT_SEND_RECEIVER_UNABLE_TO_RECV(0x0F),
TOCLIENT_SEND_RECEIVER_STORAGE_WITH_UNIQUE(0x10),
TOCLIENT_SEND_MESO_LIMIT(0x11),
TOCLIENT_SEND_SUCCESSFULLY_SENT(0x12),
TOCLIENT_RECV_UNKNOWN_ERROR(0x13),
TOCLIENT_RECV_ENABLE_ACTIONS(0x14),
TOCLIENT_RECV_NO_FREE_SLOTS(0x15),
TOCLIENT_RECV_RECEIVER_WITH_UNIQUE(0x16),
TOCLIENT_RECV_SUCCESSFUL_MSG(0x17),
TOCLIENT_RECV_PACKAGE_MSG(0x1B);
final byte code;
private Actions(int code) {
this.code = (byte) code;
}
public byte getCode() {
return code;
}
}
private static int getAccIdFromCNAME(String name, boolean accountid) {
try {
PreparedStatement ps;
String text = "SELECT id,accountid FROM characters WHERE name = ?";
Connection con = DatabaseConnection.getConnection();
ps = con.prepareStatement(text);
ps.setString(1, name);
int id_;
try (ResultSet rs = ps.executeQuery()) {
if (!rs.next()) {
rs.close();
ps.close();
return -1;
}
id_ = accountid ? rs.getInt("accountid") : rs.getInt("id");
}
ps.close();
con.close();
return id_;
} catch (SQLException e) {
e.printStackTrace();
}
return -1;
}
private static String getCurrentDate() {
String date = "";
Calendar cal = Calendar.getInstance();
int day = cal.get(Calendar.DATE) - 1; // instant duey ?
int month = cal.get(Calendar.MONTH) + 1; // its an array of months.
int year = cal.get(Calendar.YEAR);
date += day < 9 ? "0" + day + "-" : "" + day + "-";
date += month < 9 ? "0" + month + "-" : "" + month + "-";
date += year;
return date;
}
private static void removeItemFromDB(int packageid) {
Connection con = null;
try {
con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("DELETE FROM dueypackages WHERE PackageId = ?");
ps.setInt(1, packageid);
ps.executeUpdate();
ps.close();
ps = con.prepareStatement("DELETE FROM dueyitems WHERE PackageId = ?");
ps.setInt(1, packageid);
ps.executeUpdate();
ps.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
private static DueyPackages getItemByPID(ResultSet rs) {
try {
DueyPackages dueypack;
if (rs.getInt("type") == 1) {
Equip eq = new Equip(rs.getInt("itemid"), (byte) 0, -1);
eq.setUpgradeSlots((byte) rs.getInt("upgradeslots"));
eq.setLevel((byte) rs.getInt("level"));
eq.setStr((short) rs.getInt("str"));
eq.setDex((short) rs.getInt("dex"));
eq.setInt((short) rs.getInt("int"));
eq.setLuk((short) rs.getInt("luk"));
eq.setHp((short) rs.getInt("hp"));
eq.setMp((short) rs.getInt("mp"));
eq.setWatk((short) rs.getInt("watk"));
eq.setMatk((short) rs.getInt("matk"));
eq.setWdef((short) rs.getInt("wdef"));
eq.setMdef((short) rs.getInt("mdef"));
eq.setAcc((short) rs.getInt("acc"));
eq.setAvoid((short) rs.getInt("avoid"));
eq.setHands((short) rs.getInt("hands"));
eq.setSpeed((short) rs.getInt("speed"));
eq.setJump((short) rs.getInt("jump"));
eq.setOwner(rs.getString("owner"));
dueypack = new DueyPackages(rs.getInt("PackageId"), eq);
} else if (rs.getInt("type") == 2) {
Item newItem = new Item(rs.getInt("itemid"), (short) 0, (short) rs.getInt("quantity"));
newItem.setOwner(rs.getString("owner"));
dueypack = new DueyPackages(rs.getInt("PackageId"), newItem);
} else {
dueypack = new DueyPackages(rs.getInt("PackageId"));
}
return dueypack;
} catch (SQLException se) {
se.printStackTrace();
return null;
}
}
private static void showDueyNotification(MapleClient c, MapleCharacter player) {
Connection con = null;
PreparedStatement ps = null;
PreparedStatement pss = null;
ResultSet rs = null;
try {
con = DatabaseConnection.getConnection();
ps = con.prepareStatement("SELECT Mesos FROM dueypackages WHERE RecieverId = ? and Checked = 1");
ps.setInt(1, player.getId());
rs = ps.executeQuery();
if (rs.next()) {
try {
Connection con2 = DatabaseConnection.getConnection();
pss = con2.prepareStatement("UPDATE dueypackages SET Checked = 0 where RecieverId = ?");
pss.setInt(1, player.getId());
pss.executeUpdate();
pss.close();
con2.close();
} catch (SQLException e) {
e.printStackTrace();
}
c.announce(MaplePacketCreator.sendDueyNotification(false));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (rs != null) {
rs.close();
}
if (pss != null) {
pss.close();
}
if (ps != null) {
ps.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
private static int getFee(int meso) {
int fee = 0;
if (meso >= 10000000) {
fee = meso / 25;
} else if (meso >= 5000000) {
fee = meso * 3 / 100;
} else if (meso >= 1000000) {
fee = meso / 50;
} else if (meso >= 100000) {
fee = meso / 100;
} else if (meso >= 50000) {
fee = meso / 200;
}
return fee;
}
private static void addMesoToDB(int mesos, String sName, int recipientID) {
addItemToDB(null, 1, mesos, sName, recipientID);
}
private static void addItemToDB(Item item, int quantity, int mesos, String sName, int recipientID) {
Connection con = null;
try {
con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("INSERT INTO dueypackages (RecieverId, SenderName, Mesos, TimeStamp, Checked, Type) VALUES (?, ?, ?, ?, ?, ?)")) {
ps.setInt(1, recipientID);
ps.setString(2, sName);
ps.setInt(3, mesos);
ps.setString(4, getCurrentDate());
ps.setInt(5, 1);
if (item == null) {
ps.setInt(6, 3);
ps.executeUpdate();
} else {
ps.setInt(6, item.getItemType());
ps.executeUpdate();
try (ResultSet rs = ps.getGeneratedKeys()) {
rs.next();
PreparedStatement ps2;
if (item.getInventoryType().equals(MapleInventoryType.EQUIP)) {
ps2 = con.prepareStatement("INSERT INTO dueyitems (PackageId, itemid, quantity, upgradeslots, level, str, dex, `int`, luk, hp, mp, watk, matk, wdef, mdef, acc, avoid, hands, speed, jump, owner) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
Equip eq = (Equip) item;
ps2.setInt(2, eq.getItemId());
ps2.setInt(3, 1);
ps2.setInt(4, eq.getUpgradeSlots());
ps2.setInt(5, eq.getLevel());
ps2.setInt(6, eq.getStr());
ps2.setInt(7, eq.getDex());
ps2.setInt(8, eq.getInt());
ps2.setInt(9, eq.getLuk());
ps2.setInt(10, eq.getHp());
ps2.setInt(11, eq.getMp());
ps2.setInt(12, eq.getWatk());
ps2.setInt(13, eq.getMatk());
ps2.setInt(14, eq.getWdef());
ps2.setInt(15, eq.getMdef());
ps2.setInt(16, eq.getAcc());
ps2.setInt(17, eq.getAvoid());
ps2.setInt(18, eq.getHands());
ps2.setInt(19, eq.getSpeed());
ps2.setInt(20, eq.getJump());
ps2.setString(21, eq.getOwner());
} else {
ps2 = con.prepareStatement("INSERT INTO dueyitems (PackageId, itemid, quantity, owner) VALUES (?, ?, ?, ?)");
ps2.setInt(2, item.getItemId());
ps2.setInt(3, quantity);
ps2.setString(4, item.getOwner());
}
ps2.setInt(1, rs.getInt(1));
ps2.executeUpdate();
ps2.close();
}
}
}
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
private static List<DueyPackages> loadItems(MapleCharacter chr) {
List<DueyPackages> packages = new LinkedList<>();
Connection con = null;
try {
con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM dueypackages dp LEFT JOIN dueyitems di ON dp.PackageId=di.PackageId WHERE RecieverId = ?")) {
ps.setInt(1, chr.getId());
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
DueyPackages dueypack = getItemByPID(rs);
dueypack.setSender(rs.getString("SenderName"));
dueypack.setMesos(rs.getInt("Mesos"));
dueypack.setSentTime(rs.getString("TimeStamp"));
packages.add(dueypack);
}
}
}
con.close();
return packages;
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
public static void dueySendItem(MapleClient c, byte inventId, short itemPos, short amount, int mesos, String recipient) {
c.lockClient();
try {
final int fee = 5000;
if (mesos < 0 || ((long) mesos + fee + getFee(mesos)) > Integer.MAX_VALUE || (amount < 1 && mesos == 0)) {
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with duey.");
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to use duey with mesos " + mesos + " and amount " + amount + "\r\n");
c.disconnect(true, false);
return;
}
int finalcost = mesos + fee + getFee(mesos);
boolean send = false;
if (c.getPlayer().getMeso() >= finalcost) {
int accid = getAccIdFromCNAME(recipient, true);
if (accid != -1) {
if (accid != c.getAccID()) {
send = true;
} else {
c.announce(MaplePacketCreator.sendDueyMSG(DueyProcessor.Actions.TOCLIENT_SEND_SAMEACC_ERROR.getCode()));
}
} else {
c.announce(MaplePacketCreator.sendDueyMSG(DueyProcessor.Actions.TOCLIENT_SEND_NAME_DOES_NOT_EXIST.getCode()));
}
} else {
c.announce(MaplePacketCreator.sendDueyMSG(DueyProcessor.Actions.TOCLIENT_SEND_NOT_ENOUGH_MESOS.getCode()));
}
MapleClient rClient = null;
int channel = c.getWorldServer().find(recipient);
if (channel > -1) {
Channel rcserv = c.getWorldServer().getChannel(channel);
rClient = rcserv.getPlayerStorage().getCharacterByName(recipient).getClient();
}
if (send) {
if (inventId > 0) {
MapleInventoryType inv = MapleInventoryType.getByType(inventId);
Item item = c.getPlayer().getInventory(inv).getItem(itemPos);
if (item != null && c.getPlayer().getItemQuantity(item.getItemId(), false) >= amount) {
c.getPlayer().gainMeso(-finalcost, false);
c.announce(MaplePacketCreator.sendDueyMSG(DueyProcessor.Actions.TOCLIENT_SEND_SUCCESSFULLY_SENT.getCode()));
if (ItemConstants.isRechargeable(item.getItemId())) {
MapleInventoryManipulator.removeFromSlot(c, inv, itemPos, item.getQuantity(), true);
} else {
MapleInventoryManipulator.removeFromSlot(c, inv, itemPos, amount, true, false);
}
addItemToDB(item, amount, mesos, c.getPlayer().getName(), getAccIdFromCNAME(recipient, false));
} else {
if (item != null) {
c.announce(MaplePacketCreator.sendDueyMSG(DueyProcessor.Actions.TOCLIENT_SEND_INCORRECT_REQUEST.getCode()));
}
return;
}
} else {
c.getPlayer().gainMeso(-finalcost, false);
c.announce(MaplePacketCreator.sendDueyMSG(DueyProcessor.Actions.TOCLIENT_SEND_SUCCESSFULLY_SENT.getCode()));
addMesoToDB(mesos, c.getPlayer().getName(), getAccIdFromCNAME(recipient, false));
}
if (rClient != null && rClient.isLoggedIn() && !rClient.getPlayer().isAwayFromWorld()) {
showDueyNotification(rClient, rClient.getPlayer());
}
}
} finally {
c.unlockClient();
}
}
public static void dueyRemovePackage(MapleClient c, int packageid) {
c.lockClient();
try {
removeItemFromDB(packageid);
c.announce(MaplePacketCreator.removeItemFromDuey(true, packageid));
} finally {
c.unlockClient();
}
}
public static void dueyClaimPackage(MapleClient c, int packageid) {
c.lockClient();
try {
List<DueyPackages> packages = new LinkedList<>();
DueyPackages dp = null;
Connection con = null;
try {
con = DatabaseConnection.getConnection();
DueyPackages dueypack;
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM dueypackages LEFT JOIN dueyitems USING (PackageId) WHERE PackageId = ?")) {
ps.setInt(1, packageid);
try (ResultSet rs = ps.executeQuery()) {
dueypack = null;
if (rs.next()) {
dueypack = getItemByPID(rs);
dueypack.setSender(rs.getString("SenderName"));
dueypack.setMesos(rs.getInt("Mesos"));
dueypack.setSentTime(rs.getString("TimeStamp"));
packages.add(dueypack);
}
}
}
dp = dueypack;
if(dp == null) {
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_RECV_UNKNOWN_ERROR.getCode()));
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to receive package from duey with id " + packageid + "\r\n");
return;
}
if (dp.getItem() != null) {
if (!MapleInventoryManipulator.checkSpace(c, dp.getItem().getItemId(), dp.getItem().getQuantity(), dp.getItem().getOwner())) {
int itemid = dp.getItem().getItemId();
if(MapleItemInformationProvider.getInstance().isPickupRestricted(itemid) && c.getPlayer().getInventory(ItemConstants.getInventoryType(itemid)).findById(itemid) != null) {
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_RECV_RECEIVER_WITH_UNIQUE.getCode()));
} else {
c.announce(MaplePacketCreator.sendDueyMSG(Actions.TOCLIENT_RECV_NO_FREE_SLOTS.getCode()));
}
return;
} else {
MapleInventoryManipulator.addFromDrop(c, dp.getItem(), false);
}
}
long gainmesos = 0;
long totalmesos = (long) dp.getMesos() + (long) c.getPlayer().getMeso();
if (totalmesos < 0 || dp.getMesos() < 0) gainmesos = 0;
else {
totalmesos = Math.min(totalmesos, Integer.MAX_VALUE);
gainmesos = totalmesos - c.getPlayer().getMeso();
}
c.getPlayer().gainMeso((int)gainmesos, false);
removeItemFromDB(packageid);
c.announce(MaplePacketCreator.removeItemFromDuey(false, packageid));
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
} finally {
c.unlockClient();
}
}
public static void dueySendTalk(MapleClient c) {
c.lockClient();
try {
c.announce(MaplePacketCreator.sendDuey((byte) 8, loadItems(c.getPlayer())));
} finally {
c.unlockClient();
}
}
}

View File

@@ -0,0 +1,111 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
Copyleft (L) 2016 - 2018 RonanLana (HeavenMS)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package client.processor;
import client.MapleCharacter;
import client.MapleClient;
import client.inventory.Item;
import client.inventory.ItemFactory;
import client.inventory.MapleInventory;
import client.inventory.MapleInventoryType;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import server.MapleInventoryManipulator;
import server.MapleItemInformationProvider;
import server.maps.MapleHiredMerchant;
import tools.DatabaseConnection;
import tools.FilePrinter;
import tools.MaplePacketCreator;
import tools.Pair;
/**
*
* @author RonanLana (synchronization of Fredrick modules)
*/
public class FredrickProcessor {
private static boolean canRetrieveFromFredrick(MapleCharacter chr, List<Pair<Item, MapleInventoryType>> items) {
if (chr.getMeso() + chr.getMerchantMeso() < 0) {
return false;
}
return MapleInventory.checkSpotsAndOwnership(chr, items);
}
private static boolean deleteFredrickItems(int cid) {
try {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("DELETE FROM `inventoryitems` WHERE `type` = ? AND `characterid` = ?")) {
ps.setInt(1, ItemFactory.MERCHANT.getValue());
ps.setInt(2, cid);
ps.execute();
}
con.close();
return true;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
public static void fredrickRetrieveItems(MapleClient c) { // thanks Gustav for pointing out the dupe on Fredrick handling
c.lockClient();
try {
MapleCharacter chr = c.getPlayer();
List<Pair<Item, MapleInventoryType>> items;
try {
items = ItemFactory.MERCHANT.loadItems(chr.getId(), false);
if (!canRetrieveFromFredrick(chr, items)) {
chr.announce(MaplePacketCreator.fredrickMessage((byte) 0x21));
return;
}
chr.withdrawMerchantMesos();
if (deleteFredrickItems(chr.getId())) {
MapleHiredMerchant merchant = chr.getHiredMerchant();
if(merchant != null)
merchant.clearItems();
for (Pair<Item, MapleInventoryType> it : items) {
Item item = it.getLeft();
MapleInventoryManipulator.addFromDrop(chr.getClient(), item, false);
String itemName = MapleItemInformationProvider.getInstance().getName(item.getItemId());
FilePrinter.print(FilePrinter.FREDRICK + chr.getName() + ".txt", chr.getName() + " gained " + item.getQuantity() + " " + itemName + " (" + item.getItemId() + ")\r\n");
}
chr.announce(MaplePacketCreator.fredrickMessage((byte) 0x1E));
} else {
chr.message("An unknown error has occured.");
}
} catch (SQLException ex) {
ex.printStackTrace();
}
} finally {
c.unlockClient();
}
}
}