Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed Hired Merchant duplication & Store Remote Controller inventory checking #277

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/constants/id/ItemId.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ public static boolean isWeddingRing(int itemId) {
public static final int WORLD_TRANSFER = 5401000;
public static final int MAPLE_LIFE_B = 5432000;
public static final int VICIOUS_HAMMER = 5570000;
public static final int REMOTE_CONTROLLER = 5470000;

public static final int NX_CARD_100 = 4031865;
public static final int NX_CARD_250 = 4031866;
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/net/server/channel/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public final class Channel {
private Set<Integer> ongoingCathedralGuests = null;
private long ongoingStartTime;

private final Lock lock = new ReentrantLock(true);;
private final Lock lock = new ReentrantLock(true);
;
private final Lock merchRlock;
private final Lock merchWlock;

Expand Down Expand Up @@ -365,10 +366,15 @@ public Map<Integer, HiredMerchant> getHiredMerchants() {
}
}

public void addHiredMerchant(int chrid, HiredMerchant hm) {
public boolean addHiredMerchant(int chrid, HiredMerchant hm) {
merchWlock.lock();
try {
if (hiredMerchants.containsKey(chrid)) {
return false;
}

hiredMerchants.put(chrid, hm);
return true;
} finally {
merchWlock.unlock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,13 @@ public final void handlePacket(InPacket p, Client c) {
//c.sendPacket(PacketCreator.getPlayerShopRemoveVisitor(1));
} else if (ItemConstants.isHiredMerchant(itemId)) {
HiredMerchant merchant = new HiredMerchant(chr, desc, itemId);
chr.setHiredMerchant(merchant);
c.getWorldServer().registerHiredMerchant(merchant);
chr.getClient().getChannelServer().addHiredMerchant(chr.getId(), merchant);
chr.sendPacket(PacketCreator.getHiredMerchant(chr, merchant, true));
boolean merchantAdded = chr.getClient().getChannelServer().addHiredMerchant(chr.getId(), merchant);
if (merchantAdded) {
chr.setHiredMerchant(merchant);
c.getWorldServer().registerHiredMerchant(merchant);
chr.sendPacket(PacketCreator.getHiredMerchant(chr, merchant, true));
System.out.println("new shop creation.");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove println. Should use Slf4j logger if something needs to be logged. This doesn't need it though.

}
}
}
} else if (mode == Action.INVITE.getCode()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import client.Character;
import client.Client;
import client.inventory.InventoryType;
import constants.id.ItemId;
import net.AbstractPacketHandler;
import net.packet.InPacket;
import server.maps.HiredMerchant;
Expand All @@ -39,6 +41,13 @@ public void handlePacket(InPacket p, Client c) {
HiredMerchant hm = getMerchant(c);
if (hm != null && hm.isOwner(chr)) {
if (hm.getChannel() == chr.getClient().getChannel()) {
boolean isPlayerOnMerchantMap = chr.getMapId() == hm.getMapId();
if (!isPlayerOnMerchantMap) {
var remoteControl = chr.getInventory(InventoryType.CASH).findById(ItemId.REMOTE_CONTROLLER);
if (remoteControl == null) {
return;
}
Matan-94 marked this conversation as resolved.
Show resolved Hide resolved
}
hm.visitShop(chr);
} else {
c.sendPacket(PacketCreator.remoteChannelChange((byte) (hm.getChannel() - 1)));
Expand Down
Loading