Buff System & Map skipping fix + properly disposing Storage + Fairness to locks
Fixed buff system behaving oddly if a buff has value zero, that would render some skills "broken". Fixed players skipping maps when trying to access portals while under a poor Internet connection. Fixed storage not disposing players properly in cases where the players does not meet the storage conditions. Set some locks to use fairness strategy when dealing with atomic code, in order to make the calls to it properly synchronized. Fixed Aran introductory questline stucking players when certain conditions were met. Added drop data for some mob versions of Fairy, Yeti and Pepe.
This commit is contained in:
@@ -33,24 +33,24 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
*/
|
||||
public class PlayerBuffStorage {
|
||||
private int id = (int) (Math.random() * 100);
|
||||
private final Lock mutex = new ReentrantLock();
|
||||
private Map<Integer, List<PlayerBuffValueHolder>> buffs = new HashMap<Integer, List<PlayerBuffValueHolder>>();
|
||||
private final Lock lock = new ReentrantLock(true);
|
||||
private Map<Integer, List<PlayerBuffValueHolder>> buffs = new HashMap<>();
|
||||
|
||||
public void addBuffsToStorage(int chrid, List<PlayerBuffValueHolder> toStore) {
|
||||
mutex.lock();
|
||||
lock.lock();
|
||||
try {
|
||||
buffs.put(chrid, toStore);//Old one will be replaced if it's in here.
|
||||
} finally {
|
||||
mutex.unlock();
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public List<PlayerBuffValueHolder> getBuffsFromStorage(int chrid) {
|
||||
mutex.lock();
|
||||
lock.lock();
|
||||
try {
|
||||
return buffs.remove(chrid);
|
||||
} finally {
|
||||
mutex.unlock();
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -90,11 +90,11 @@ public final class Channel {
|
||||
private Map<Integer, Integer> dojoParty = new HashMap<>();
|
||||
private Map<Integer, MapleMiniDungeon> dungeons = new HashMap<>();
|
||||
|
||||
private ReentrantReadWriteLock merchant_lock = new ReentrantReadWriteLock(true);
|
||||
private ReadLock merchRlock = merchant_lock.readLock();
|
||||
private WriteLock merchWlock = merchant_lock.writeLock();
|
||||
private ReentrantReadWriteLock merchantLock = new ReentrantReadWriteLock(true);
|
||||
private ReadLock merchRlock = merchantLock.readLock();
|
||||
private WriteLock merchWlock = merchantLock.writeLock();
|
||||
|
||||
private Lock lock = new ReentrantLock();
|
||||
private Lock lock = new ReentrantLock(true);
|
||||
|
||||
public Channel(final int world, final int channel) {
|
||||
this.world = world;
|
||||
|
||||
@@ -41,7 +41,8 @@ public final class ChangeMapHandler extends AbstractMaplePacketHandler {
|
||||
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
|
||||
MapleCharacter chr = c.getPlayer();
|
||||
|
||||
if (chr.isBanned()) {
|
||||
if (chr.isChangingMaps() || chr.isBanned()) {
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
return;
|
||||
}
|
||||
if (chr.getTrade() != null) {
|
||||
|
||||
@@ -31,20 +31,21 @@ import tools.data.input.SeekableLittleEndianAccessor;
|
||||
public final class ChangeMapSpecialHandler extends AbstractMaplePacketHandler {
|
||||
@Override
|
||||
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
|
||||
slea.readByte();
|
||||
String startwp = slea.readMapleAsciiString();
|
||||
slea.readShort();
|
||||
MaplePortal portal = c.getPlayer().getMap().getPortal(startwp);
|
||||
if (portal == null || c.getPlayer().portalDelay() > System.currentTimeMillis() || c.getPlayer().getBlockedPortals().contains(portal.getScriptName())) {
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
return;
|
||||
}
|
||||
if (c.getPlayer().isBanned()) {
|
||||
return;
|
||||
}
|
||||
if (c.getPlayer().getTrade() != null) {
|
||||
MapleTrade.cancelTrade(c.getPlayer());
|
||||
}
|
||||
portal.enterPortal(c);
|
||||
slea.readByte();
|
||||
String startwp = slea.readMapleAsciiString();
|
||||
slea.readShort();
|
||||
MaplePortal portal = c.getPlayer().getMap().getPortal(startwp);
|
||||
if (portal == null || c.getPlayer().portalDelay() > System.currentTimeMillis() || c.getPlayer().getBlockedPortals().contains(portal.getScriptName())) {
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
return;
|
||||
}
|
||||
if (c.getPlayer().isChangingMaps() || c.getPlayer().isBanned()) {
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
return;
|
||||
}
|
||||
if (c.getPlayer().getTrade() != null) {
|
||||
MapleTrade.cancelTrade(c.getPlayer());
|
||||
}
|
||||
portal.enterPortal(c);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,11 +229,10 @@ public final class PlayerInteractionHandler extends AbstractMaplePacketHandler {
|
||||
} else if (!merchant.isOpen()) {
|
||||
c.announce(MaplePacketCreator.hiredMerchantMaintenanceMessage());
|
||||
return;
|
||||
} else if (merchant.getFreeSlotThreadsafe() == -1) {
|
||||
} else if (!merchant.addVisitor(c.getPlayer())) {
|
||||
chr.dropMessage(1, "This shop has reached it's maximum capacity, please come by later.");
|
||||
return;
|
||||
} else {
|
||||
merchant.addVisitor(c.getPlayer());
|
||||
c.announce(MaplePacketCreator.getHiredMerchant(c.getPlayer(), merchant, false));
|
||||
}
|
||||
chr.setHiredMerchant(merchant);
|
||||
|
||||
34
src/net/server/channel/handlers/PlayerUpdateHandler.java
Normal file
34
src/net/server/channel/handlers/PlayerUpdateHandler.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
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>
|
||||
|
||||
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 net.server.channel.handlers;
|
||||
|
||||
import client.MapleClient;
|
||||
import net.AbstractMaplePacketHandler;
|
||||
import tools.data.input.SeekableLittleEndianAccessor;
|
||||
|
||||
public final class PlayerUpdateHandler extends AbstractMaplePacketHandler {
|
||||
|
||||
@Override
|
||||
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
|
||||
c.getPlayer().setMapTransitionComplete();
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,7 @@ public final class StorageHandler extends AbstractMaplePacketHandler {
|
||||
|
||||
if (chr.getLevel() < 15){
|
||||
chr.message("You may only use the storage once you have reached level 15.");
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
return;
|
||||
}
|
||||
if (mode == 4) { // take out
|
||||
@@ -103,6 +104,7 @@ public final class StorageHandler extends AbstractMaplePacketHandler {
|
||||
return;
|
||||
}
|
||||
if (quantity < 1 || chr.getItemQuantity(itemId, false) < quantity) {
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
return;
|
||||
}
|
||||
if (storage.isFull()) {
|
||||
@@ -139,11 +141,13 @@ public final class StorageHandler extends AbstractMaplePacketHandler {
|
||||
if (meso < 0 && (storageMesos - meso) < 0) {
|
||||
meso = -2147483648 + storageMesos;
|
||||
if (meso < playerMesos) {
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
return;
|
||||
}
|
||||
} else if (meso > 0 && (playerMesos + meso) < 0) {
|
||||
meso = 2147483647 - playerMesos;
|
||||
if (meso > storageMesos) {
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -151,6 +155,7 @@ public final class StorageHandler extends AbstractMaplePacketHandler {
|
||||
chr.gainMeso(meso, false, true, false);
|
||||
FilePrinter.print(FilePrinter.STORAGE + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + (meso > 0 ? " took out " : " stored ") + Math.abs(meso) + " mesos\r\n");
|
||||
} else {
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
return;
|
||||
}
|
||||
storage.sendMeso(c);
|
||||
|
||||
@@ -43,7 +43,7 @@ public class MapleParty {
|
||||
private Map<Integer, Integer> histMembers = new HashMap<>();
|
||||
private int nextEntry = 0;
|
||||
|
||||
private Lock lock = new ReentrantLock();
|
||||
private Lock lock = new ReentrantLock(true);
|
||||
|
||||
public MapleParty(int id, MaplePartyCharacter chrfor) {
|
||||
this.leaderId = chrfor.getId();
|
||||
|
||||
@@ -79,31 +79,38 @@ public class World {
|
||||
private int id, flag, exprate, droprate, mesorate, bossdroprate;
|
||||
private String eventmsg;
|
||||
private List<Channel> channels = new ArrayList<>();
|
||||
private Map<Integer, MapleParty> parties = new HashMap<>();
|
||||
private AtomicInteger runningPartyId = new AtomicInteger();
|
||||
private Map<Integer, MapleMessenger> messengers = new HashMap<>();
|
||||
private AtomicInteger runningMessengerId = new AtomicInteger();
|
||||
private Map<Integer, MapleFamily> families = new LinkedHashMap<>();
|
||||
private Map<Integer, MapleGuildSummary> gsStore = new HashMap<>();
|
||||
private PlayerStorage players = new PlayerStorage();
|
||||
|
||||
private Set<Integer> queuedGuilds = new HashSet<>();
|
||||
|
||||
private Map<Integer, MapleParty> parties = new HashMap<>();
|
||||
private AtomicInteger runningPartyId = new AtomicInteger();
|
||||
private Lock partyLock = new ReentrantLock(true);
|
||||
|
||||
private Map<Integer, Integer> owlSearched = new LinkedHashMap<>();
|
||||
private Lock owlLock = new ReentrantLock();
|
||||
|
||||
private Lock activePetsLock = new ReentrantLock(true);
|
||||
private Map<Integer, Byte> activePets = new LinkedHashMap<>();
|
||||
private ScheduledFuture<?> petsSchedule;
|
||||
private long petUpdate;
|
||||
|
||||
private Lock activeMountsLock = new ReentrantLock(true);
|
||||
private Map<Integer, Byte> activeMounts = new LinkedHashMap<>();
|
||||
private ScheduledFuture<?> mountsSchedule;
|
||||
private long mountUpdate;
|
||||
|
||||
private Lock activePlayerShopsLock = new ReentrantLock(true);
|
||||
private Map<Integer, MaplePlayerShop> activePlayerShops = new LinkedHashMap<>();
|
||||
|
||||
private Lock activeMerchantsLock = new ReentrantLock(true);
|
||||
private Map<Integer, Pair<MapleHiredMerchant, Byte>> activeMerchants = new LinkedHashMap<>();
|
||||
private long merchantUpdate;
|
||||
|
||||
private Map<Integer, MaplePlayerShop> activePlayerShops = new LinkedHashMap<>();
|
||||
|
||||
private ScheduledFuture<?> charactersSchedule;
|
||||
|
||||
public World(int world, int flag, String eventmsg, int exprate, int droprate, int mesorate, int bossdroprate) {
|
||||
@@ -366,21 +373,32 @@ public class World {
|
||||
public MapleParty createParty(MaplePartyCharacter chrfor) {
|
||||
int partyid = runningPartyId.getAndIncrement();
|
||||
MapleParty party = new MapleParty(partyid, chrfor);
|
||||
synchronized(parties) {
|
||||
|
||||
partyLock.lock();
|
||||
try {
|
||||
parties.put(party.getId(), party);
|
||||
} finally {
|
||||
partyLock.unlock();
|
||||
}
|
||||
|
||||
return party;
|
||||
}
|
||||
|
||||
public MapleParty getParty(int partyid) {
|
||||
synchronized(parties) {
|
||||
partyLock.lock();
|
||||
try {
|
||||
return parties.get(partyid);
|
||||
} finally {
|
||||
partyLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public MapleParty disbandParty(int partyid) {
|
||||
synchronized(parties) {
|
||||
partyLock.lock();
|
||||
try {
|
||||
return parties.remove(partyid);
|
||||
} finally {
|
||||
partyLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -766,27 +784,39 @@ public class World {
|
||||
}
|
||||
|
||||
Integer key = getPetKey(chr, petSlot);
|
||||
synchronized(activePets) {
|
||||
|
||||
activePetsLock.lock();
|
||||
try {
|
||||
byte initProc;
|
||||
if(System.currentTimeMillis() - petUpdate > 55000) initProc = ServerConstants.PET_EXHAUST_COUNT - 2;
|
||||
else initProc = ServerConstants.PET_EXHAUST_COUNT - 1;
|
||||
|
||||
activePets.put(key, initProc);
|
||||
} finally {
|
||||
activePetsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterPetHunger(MapleCharacter chr, byte petSlot) {
|
||||
Integer key = getPetKey(chr, petSlot);
|
||||
synchronized(activePets) {
|
||||
|
||||
activePetsLock.lock();
|
||||
try {
|
||||
activePets.remove(key);
|
||||
} finally {
|
||||
activePetsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void runPetSchedule() {
|
||||
Map<Integer, Byte> deployedPets;
|
||||
synchronized(activePets) {
|
||||
|
||||
activePetsLock.lock();
|
||||
try {
|
||||
petUpdate = System.currentTimeMillis();
|
||||
deployedPets = Collections.unmodifiableMap(activePets);
|
||||
} finally {
|
||||
activePetsLock.unlock();
|
||||
}
|
||||
|
||||
for(Map.Entry<Integer, Byte> dp: deployedPets.entrySet()) {
|
||||
@@ -799,8 +829,11 @@ public class World {
|
||||
dpVal = 0;
|
||||
}
|
||||
|
||||
synchronized(activePets) {
|
||||
activePetsLock.lock();
|
||||
try {
|
||||
activePets.put(dp.getKey(), dpVal);
|
||||
} finally {
|
||||
activePetsLock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -811,27 +844,37 @@ public class World {
|
||||
}
|
||||
|
||||
Integer key = chr.getId();
|
||||
synchronized(activeMounts) {
|
||||
activeMountsLock.lock();
|
||||
try {
|
||||
byte initProc;
|
||||
if(System.currentTimeMillis() - mountUpdate > 45000) initProc = ServerConstants.MOUNT_EXHAUST_COUNT - 2;
|
||||
else initProc = ServerConstants.MOUNT_EXHAUST_COUNT - 1;
|
||||
|
||||
activeMounts.put(key, initProc);
|
||||
} finally {
|
||||
activeMountsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterMountHunger(MapleCharacter chr) {
|
||||
Integer key = chr.getId();
|
||||
synchronized(activeMounts) {
|
||||
|
||||
activeMountsLock.lock();
|
||||
try {
|
||||
activeMounts.remove(key);
|
||||
} finally {
|
||||
activeMountsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void runMountSchedule() {
|
||||
Map<Integer, Byte> deployedMounts;
|
||||
synchronized(activeMounts) {
|
||||
activeMountsLock.lock();
|
||||
try {
|
||||
mountUpdate = System.currentTimeMillis();
|
||||
deployedMounts = Collections.unmodifiableMap(activeMounts);
|
||||
} finally {
|
||||
activeMountsLock.unlock();
|
||||
}
|
||||
|
||||
for(Map.Entry<Integer, Byte> dp: deployedMounts.entrySet()) {
|
||||
@@ -844,60 +887,82 @@ public class World {
|
||||
dpVal = 0;
|
||||
}
|
||||
|
||||
synchronized(activeMounts) {
|
||||
activeMountsLock.lock();
|
||||
try {
|
||||
activeMounts.put(dp.getKey(), dpVal);
|
||||
} finally {
|
||||
activeMountsLock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void registerPlayerShop(MaplePlayerShop ps) {
|
||||
synchronized(activePlayerShops) {
|
||||
activePlayerShopsLock.lock();
|
||||
try {
|
||||
activePlayerShops.put(ps.getOwner().getId(), ps);
|
||||
} finally {
|
||||
activePlayerShopsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterPlayerShop(MaplePlayerShop ps) {
|
||||
synchronized(activePlayerShops) {
|
||||
activePlayerShopsLock.lock();
|
||||
try {
|
||||
activePlayerShops.remove(ps.getOwner().getId());
|
||||
} finally {
|
||||
activePlayerShopsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public List<MaplePlayerShop> getActivePlayerShops() {
|
||||
List<MaplePlayerShop> psList = new ArrayList<>();
|
||||
synchronized(activePlayerShops) {
|
||||
activePlayerShopsLock.lock();
|
||||
try {
|
||||
for(MaplePlayerShop mps : activePlayerShops.values()) {
|
||||
psList.add(mps);
|
||||
}
|
||||
|
||||
return psList;
|
||||
} finally {
|
||||
activePlayerShopsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public MaplePlayerShop getPlayerShop(int ownerid) {
|
||||
synchronized(activePlayerShops) {
|
||||
activePlayerShopsLock.lock();
|
||||
try {
|
||||
return activePlayerShops.get(ownerid);
|
||||
} finally {
|
||||
activePlayerShopsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void registerHiredMerchant(MapleHiredMerchant hm) {
|
||||
synchronized(activeMerchants) {
|
||||
activeMerchantsLock.lock();
|
||||
try {
|
||||
byte initProc;
|
||||
if(System.currentTimeMillis() - merchantUpdate > 5 * 60 * 1000) initProc = 1;
|
||||
else initProc = 0;
|
||||
|
||||
activeMerchants.put(hm.getOwnerId(), new Pair<>(hm, initProc));
|
||||
} finally {
|
||||
activeMerchantsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterHiredMerchant(MapleHiredMerchant hm) {
|
||||
synchronized(activeMerchants) {
|
||||
activeMerchantsLock.lock();
|
||||
try {
|
||||
activeMerchants.remove(hm.getOwnerId());
|
||||
} finally {
|
||||
activeMerchantsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void runHiredMerchantSchedule() {
|
||||
Map<Integer, Pair<MapleHiredMerchant, Byte>> deployedMerchants;
|
||||
synchronized(activeMerchants) {
|
||||
activeMerchantsLock.lock();
|
||||
try {
|
||||
merchantUpdate = System.currentTimeMillis();
|
||||
deployedMerchants = new LinkedHashMap<>(activeMerchants);
|
||||
|
||||
@@ -914,12 +979,15 @@ public class World {
|
||||
activeMerchants.remove(dm.getKey());
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
activeMerchantsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public List<MapleHiredMerchant> getActiveMerchants() {
|
||||
List<MapleHiredMerchant> hmList = new ArrayList<>();
|
||||
synchronized(activeMerchants) {
|
||||
activeMerchantsLock.lock();
|
||||
try {
|
||||
for(Pair<MapleHiredMerchant, Byte> hmp : activeMerchants.values()) {
|
||||
MapleHiredMerchant hm = hmp.getLeft();
|
||||
if(hm.isOpen()) {
|
||||
@@ -928,16 +996,21 @@ public class World {
|
||||
}
|
||||
|
||||
return hmList;
|
||||
} finally {
|
||||
activeMerchantsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public MapleHiredMerchant getHiredMerchant(int ownerid) {
|
||||
synchronized(activeMerchants) {
|
||||
activeMerchantsLock.lock();
|
||||
try {
|
||||
if(activeMerchants.containsKey(ownerid)) {
|
||||
return activeMerchants.get(ownerid).getLeft();
|
||||
}
|
||||
|
||||
return null;
|
||||
} finally {
|
||||
activeMerchantsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user