Abstract channel schedulers + Mob animation track + More portal SFX
Implemented an improved scheduler system for channels, on where Runnables objects are "registered in" to run on a scheduled future time (effective run time will depend on the proc time of the worker acting under-the-hood). Implemented a channel scheduler for detecting "mobs currently on animation state". This allows the server to send info to the client about whether a mob should cast a skill or not at that moment. Improved concurrent protection on MapleMonster listeners registry. Improved resource deallocation when destroying a monster object. Added a server flag to allow clean slates to be used on equipments even on the "only successfully used scroll slots" case. Fixed a critical deadlock case with MapleServerHandler. Added the portal SFX for many scripted portals that still lacked the sound effect.
This commit is contained in:
@@ -21,7 +21,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.server.channel;
|
||||
|
||||
import net.server.channel.worker.MobStatusScheduler;
|
||||
import java.io.File;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
@@ -43,9 +42,12 @@ import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
|
||||
|
||||
import net.MapleServerHandler;
|
||||
import net.mina.MapleCodecFactory;
|
||||
import net.server.Server;
|
||||
import net.server.world.World;
|
||||
|
||||
import net.server.PlayerStorage;
|
||||
import net.server.Server;
|
||||
import net.server.channel.worker.*;
|
||||
|
||||
import net.server.world.World;
|
||||
import net.server.world.MapleParty;
|
||||
import net.server.world.MaplePartyCharacter;
|
||||
|
||||
@@ -86,6 +88,8 @@ public final class Channel {
|
||||
private MapleMapFactory mapFactory;
|
||||
private EventScriptManager eventSM;
|
||||
private MobStatusScheduler mobStatusSchedulers[] = new MobStatusScheduler[4];
|
||||
private MobAnimationScheduler mobAnimationSchedulers[] = new MobAnimationScheduler[4];
|
||||
private OverallScheduler channelSchedulers[] = new OverallScheduler[4];
|
||||
private Map<Integer, MapleHiredMerchant> hiredMerchants = new HashMap<>();
|
||||
private final Map<Integer, Integer> storedVars = new HashMap<>();
|
||||
private List<MapleExpedition> expeditions = new ArrayList<>();
|
||||
@@ -154,6 +158,8 @@ public final class Channel {
|
||||
|
||||
for(int i = 0; i < 4; i++) {
|
||||
mobStatusSchedulers[i] = new MobStatusScheduler();
|
||||
mobAnimationSchedulers[i] = new MobAnimationScheduler();
|
||||
channelSchedulers[i] = new OverallScheduler();
|
||||
}
|
||||
|
||||
System.out.println(" Channel " + getId() + ": Listening on port " + port);
|
||||
@@ -824,7 +830,7 @@ public final class Channel {
|
||||
}
|
||||
}
|
||||
|
||||
private static int getMobStatusSchedulerIndex(int mapid) {
|
||||
private static int getChannelSchedulerIndex(int mapid) {
|
||||
if(mapid >= 250000000) {
|
||||
if(mapid >= 900000000) {
|
||||
return 3;
|
||||
@@ -845,11 +851,23 @@ public final class Channel {
|
||||
}
|
||||
|
||||
public void registerMobStatus(int mapid, MonsterStatusEffect mse, Runnable cancelAction, long duration, Runnable overtimeAction, int overtimeDelay) {
|
||||
mobStatusSchedulers[getMobStatusSchedulerIndex(mapid)].registerMobStatus(mse, cancelAction, duration, overtimeAction, overtimeDelay);
|
||||
mobStatusSchedulers[getChannelSchedulerIndex(mapid)].registerMobStatus(mse, cancelAction, duration, overtimeAction, overtimeDelay);
|
||||
}
|
||||
|
||||
public void interruptMobStatus(int mapid, MonsterStatusEffect mse) {
|
||||
mobStatusSchedulers[getMobStatusSchedulerIndex(mapid)].interruptMobStatus(mse);
|
||||
mobStatusSchedulers[getChannelSchedulerIndex(mapid)].interruptMobStatus(mse);
|
||||
}
|
||||
|
||||
public boolean registerMobOnAnimationEffect(int mapid, int mobHash, long delay) {
|
||||
return mobAnimationSchedulers[getChannelSchedulerIndex(mapid)].registerAnimationMode(mobHash, delay);
|
||||
}
|
||||
|
||||
public void registerOverallAction(int mapid, Runnable runAction, long delay) {
|
||||
channelSchedulers[getChannelSchedulerIndex(mapid)].registerDelayedAction(runAction, delay);
|
||||
}
|
||||
|
||||
public void forceRunOverallAction(int mapid, Runnable runAction) {
|
||||
channelSchedulers[getChannelSchedulerIndex(mapid)].forceRunDelayedAction(runAction);
|
||||
}
|
||||
|
||||
public void debugMarriageStatus() {
|
||||
|
||||
@@ -43,6 +43,7 @@ import tools.data.input.SeekableLittleEndianAccessor;
|
||||
/**
|
||||
* @author Danny (Leifde)
|
||||
* @author ExtremeDevilz
|
||||
* @author Ronan (HeavenMS)
|
||||
*/
|
||||
public final class MoveLifeHandler extends AbstractMovementPacketHandler {
|
||||
@Override
|
||||
@@ -76,49 +77,62 @@ public final class MoveLifeHandler extends AbstractMovementPacketHandler {
|
||||
|
||||
int nextCastSkill = useSkillId;
|
||||
int nextCastSkillLevel = useSkillLevel;
|
||||
|
||||
MobSkill toUse = null;
|
||||
|
||||
int percHpLeft = (int) (((float) monster.getHp() / monster.getMaxHp()) * 100);
|
||||
|
||||
if (nextMovementCouldBeSkill && monster.getNoSkills() > 0) {
|
||||
int Random = Randomizer.nextInt(monster.getNoSkills());
|
||||
Pair<Integer, Integer> skillToUse = monster.getSkills().get(Random);
|
||||
nextCastSkill = skillToUse.getLeft();
|
||||
nextCastSkillLevel = skillToUse.getRight();
|
||||
toUse = MobSkillFactory.getMobSkill(nextCastSkill, nextCastSkillLevel);
|
||||
MobSkill toUse = null;
|
||||
int rndSkill = -1;
|
||||
|
||||
if(monster.getNoSkills() > 0) {
|
||||
if(nextMovementCouldBeSkill) {
|
||||
rndSkill = Randomizer.nextInt(monster.getNoSkills());
|
||||
}
|
||||
} else {
|
||||
nextMovementCouldBeSkill = false;
|
||||
}
|
||||
|
||||
if(monster.applyAnimationIfRoaming((attackId - 13) / 2, rndSkill)) {
|
||||
if (rndSkill > -1) {
|
||||
Pair<Integer, Integer> skillToUse = monster.getSkills().get(rndSkill);
|
||||
nextCastSkill = skillToUse.getLeft();
|
||||
nextCastSkillLevel = skillToUse.getRight();
|
||||
toUse = MobSkillFactory.getMobSkill(nextCastSkill, nextCastSkillLevel);
|
||||
|
||||
if (isSkill || isAttack) {
|
||||
if (nextCastSkill != toUse.getSkillId() || nextCastSkillLevel != toUse.getSkillLevel()) {
|
||||
//toUse.resetAnticipatedSkill();
|
||||
return;
|
||||
} else if (toUse.getHP() < percHpLeft) {
|
||||
toUse = null;
|
||||
} else if (monster.canUseSkill(toUse)) {
|
||||
int animationTime = MapleMonsterInformationProvider.getInstance().getMobSkillAnimationTime(monster.getId(), Random);
|
||||
if(animationTime > 0) {
|
||||
toUse.applyDelayedEffect(c.getPlayer(), monster, true, banishPlayers, animationTime);
|
||||
if (isSkill || isAttack) {
|
||||
int percHpLeft = (int) (((float) monster.getHp() / monster.getMaxHp()) * 100);
|
||||
if (nextCastSkill != toUse.getSkillId() || nextCastSkillLevel != toUse.getSkillLevel()) {
|
||||
//toUse.resetAnticipatedSkill();
|
||||
return;
|
||||
} else if (toUse.getHP() < percHpLeft) {
|
||||
toUse = null;
|
||||
} else if (monster.canUseSkill(toUse)) {
|
||||
int animationTime = MapleMonsterInformationProvider.getInstance().getMobSkillAnimationTime(monster.getId(), rndSkill);
|
||||
if(animationTime > 0) {
|
||||
toUse.applyDelayedEffect(c.getPlayer(), monster, true, banishPlayers, animationTime);
|
||||
} else {
|
||||
toUse.applyEffect(c.getPlayer(), monster, true, banishPlayers);
|
||||
}
|
||||
} else {
|
||||
toUse.applyEffect(c.getPlayer(), monster, true, banishPlayers);
|
||||
toUse = null;
|
||||
}
|
||||
} else {
|
||||
toUse = null;
|
||||
}
|
||||
} else {
|
||||
toUse = null; // paliative measure for suspicious mob movement
|
||||
|
||||
/*
|
||||
long curtime = System.currentTimeMillis();
|
||||
if(curtime >= monster.getNextBasicSkillTime()) { // dont use the special attack too often, chase the player f3
|
||||
MobAttackInfo mobAttack = MobAttackInfoFactory.getMobAttackInfo(monster, attackId);
|
||||
monster.setNextBasicSkillTime(curtime);
|
||||
} else {
|
||||
toUse = null;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
toUse = null; // paliative measure for suspicious mob movement
|
||||
|
||||
/*
|
||||
long curtime = System.currentTimeMillis();
|
||||
if(curtime >= monster.getNextBasicSkillTime()) { // dont use the special attack too often, chase the player f3
|
||||
MobAttackInfo mobAttack = MobAttackInfoFactory.getMobAttackInfo(monster, attackId);
|
||||
monster.setNextBasicSkillTime(curtime);
|
||||
} else {
|
||||
toUse = null;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(rndSkill > -1) {
|
||||
nextMovementCouldBeSkill = false;
|
||||
}
|
||||
}
|
||||
|
||||
slea.readByte();
|
||||
slea.readInt(); // whatever
|
||||
short start_x = slea.readShort(); // hmm.. startpos?
|
||||
|
||||
@@ -35,6 +35,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.AbstractMaplePacketHandler;
|
||||
import client.inventory.manipulator.MapleInventoryManipulator;
|
||||
import constants.ServerConstants;
|
||||
import server.MapleItemInformationProvider;
|
||||
import tools.MaplePacketCreator;
|
||||
import tools.data.input.SeekableLittleEndianAccessor;
|
||||
@@ -91,9 +92,10 @@ public final class ScrollHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
}
|
||||
|
||||
if (ItemConstants.isCleanSlate(scroll.getItemId()) && !(toScroll.getLevel() + toScroll.getUpgradeSlots() < ii.getEquipStats(toScroll.getItemId()).get("tuc"))) { //upgrade slots can be over because of hammers
|
||||
if (ItemConstants.isCleanSlate(scroll.getItemId()) && !ii.canUseCleanSlate(toScroll)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Equip scrolled = (Equip) ii.scrollEquipWithId(toScroll, scroll.getItemId(), whiteScroll, 0, c.getPlayer().isGM());
|
||||
ScrollResult scrollSuccess = Equip.ScrollResult.FAIL; // fail
|
||||
if (scrolled == null) {
|
||||
|
||||
131
src/net/server/channel/worker/BaseScheduler.java
Normal file
131
src/net/server/channel/worker/BaseScheduler.java
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
This file is part of the HeavenMS MapleStory Server
|
||||
Copyleft 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 net.server.channel.worker;
|
||||
|
||||
import constants.ServerConstants;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import server.TimerManager;
|
||||
import tools.Pair;
|
||||
import tools.locks.MonitoredLockType;
|
||||
import tools.locks.MonitoredReentrantLock;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ronan
|
||||
*/
|
||||
public abstract class BaseScheduler {
|
||||
private int idleProcs = 0;
|
||||
private List<SchedulerListener> listeners = new LinkedList<>();
|
||||
private Map<Object, Pair<Runnable, Long>> registeredEntries = new HashMap<>();
|
||||
|
||||
private ScheduledFuture<?> schedulerTask = null;
|
||||
private Lock schedulerLock;
|
||||
private Runnable monitorTask = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
runBaseSchedule();
|
||||
}
|
||||
};
|
||||
|
||||
protected BaseScheduler(MonitoredLockType lockType) {
|
||||
schedulerLock = new MonitoredReentrantLock(lockType, true);
|
||||
}
|
||||
|
||||
protected void addListener(SchedulerListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
private void runBaseSchedule() {
|
||||
schedulerLock.lock();
|
||||
try {
|
||||
if(registeredEntries.isEmpty()) {
|
||||
idleProcs++;
|
||||
|
||||
if(idleProcs >= ServerConstants.MOB_STATUS_MONITOR_LIFE) {
|
||||
if(schedulerTask != null) {
|
||||
schedulerTask.cancel(false);
|
||||
schedulerTask = null;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
idleProcs = 0;
|
||||
|
||||
long timeNow = System.currentTimeMillis();
|
||||
List<Object> toRemove = new LinkedList<>();
|
||||
for(Entry<Object, Pair<Runnable, Long>> rmd : registeredEntries.entrySet()) {
|
||||
Pair<Runnable, Long> r = rmd.getValue();
|
||||
|
||||
if(r.getRight() < timeNow) {
|
||||
r.getLeft().run(); // runs the cancel action
|
||||
toRemove.add(rmd.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
for(Object mse : toRemove) {
|
||||
registeredEntries.remove(mse);
|
||||
}
|
||||
|
||||
dispatchRemovedEntries(toRemove, true);
|
||||
} finally {
|
||||
schedulerLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private void dispatchRemovedEntries(List<Object> toRemove, boolean fromUpdate) {
|
||||
for (SchedulerListener listener : listeners.toArray(new SchedulerListener[listeners.size()])) {
|
||||
listener.removedScheduledEntries(toRemove, fromUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
protected void registerEntry(Object key, Runnable removalAction, long duration) {
|
||||
schedulerLock.lock();
|
||||
try {
|
||||
idleProcs = 0;
|
||||
if(schedulerTask == null) {
|
||||
schedulerTask = TimerManager.getInstance().register(monitorTask, ServerConstants.MOB_STATUS_MONITOR_PROC, ServerConstants.MOB_STATUS_MONITOR_PROC);
|
||||
}
|
||||
|
||||
registeredEntries.put(key, new Pair<>(removalAction, System.currentTimeMillis() + duration));
|
||||
} finally {
|
||||
schedulerLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
protected void interruptEntry(Object key) {
|
||||
schedulerLock.lock();
|
||||
try {
|
||||
Pair<Runnable, Long> rm = registeredEntries.remove(key);
|
||||
if(rm != null) rm.getLeft().run();
|
||||
|
||||
dispatchRemovedEntries(Collections.singletonList(key), false);
|
||||
} finally {
|
||||
schedulerLock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
74
src/net/server/channel/worker/MobAnimationScheduler.java
Normal file
74
src/net/server/channel/worker/MobAnimationScheduler.java
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
This file is part of the HeavenMS MapleStory Server
|
||||
Copyleft 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 net.server.channel.worker;
|
||||
|
||||
import tools.locks.MonitoredLockType;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import tools.locks.MonitoredReentrantLock;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ronan
|
||||
*/
|
||||
public class MobAnimationScheduler extends BaseScheduler {
|
||||
Set<Integer> onAnimationMobs = new HashSet<>(1000);
|
||||
private Lock animationLock = new MonitoredReentrantLock(MonitoredLockType.CHANNEL_MOBANIMAT, true);
|
||||
|
||||
private static Runnable r = new Runnable() {
|
||||
@Override
|
||||
public void run() {} // do nothing
|
||||
};
|
||||
|
||||
public MobAnimationScheduler() {
|
||||
super(MonitoredLockType.CHANNEL_MOBACTION);
|
||||
|
||||
super.addListener(new SchedulerListener() {
|
||||
@Override
|
||||
public void removedScheduledEntries(List<Object> toRemove, boolean update) {
|
||||
animationLock.lock();
|
||||
try {
|
||||
for(Object hashObj : toRemove) {
|
||||
Integer mobHash = (Integer) hashObj;
|
||||
onAnimationMobs.remove(mobHash);
|
||||
}
|
||||
} finally {
|
||||
animationLock.unlock();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean registerAnimationMode(Integer mobHash, long animationTime) {
|
||||
animationLock.lock();
|
||||
try {
|
||||
if(onAnimationMobs.contains(mobHash)) return false;
|
||||
|
||||
registerEntry(mobHash, r, animationTime);
|
||||
onAnimationMobs.add(mobHash);
|
||||
return true;
|
||||
} finally {
|
||||
animationLock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,14 +23,9 @@ import client.status.MonsterStatusEffect;
|
||||
import constants.ServerConstants;
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import server.TimerManager;
|
||||
import tools.Pair;
|
||||
import tools.locks.MonitoredLockType;
|
||||
import tools.locks.MonitoredReentrantLock;
|
||||
|
||||
@@ -38,10 +33,9 @@ import tools.locks.MonitoredReentrantLock;
|
||||
*
|
||||
* @author Ronan
|
||||
*/
|
||||
public class MobStatusScheduler {
|
||||
private int idleProcs = 0;
|
||||
private Map<MonsterStatusEffect, Pair<Runnable, Long>> registeredMobStatus = new HashMap<>();
|
||||
public class MobStatusScheduler extends BaseScheduler {
|
||||
private Map<MonsterStatusEffect, MobStatusOvertimeEntry> registeredMobStatusOvertime = new HashMap<>();
|
||||
private Lock overtimeStatusLock = new MonitoredReentrantLock(MonitoredLockType.CHANNEL_OVTSTATUS, true);
|
||||
|
||||
private class MobStatusOvertimeEntry {
|
||||
private int procCount;
|
||||
@@ -63,86 +57,49 @@ public class MobStatusScheduler {
|
||||
}
|
||||
}
|
||||
|
||||
private ScheduledFuture<?> mobStatusSchedule = null;
|
||||
private Lock mobStatusLock = new MonitoredReentrantLock(MonitoredLockType.CHANNEL_MOBSTATUS, true);
|
||||
private Runnable monitorTask = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
runMobStatusSchedule();
|
||||
}
|
||||
};
|
||||
|
||||
private void runMobStatusSchedule() {
|
||||
mobStatusLock.lock();
|
||||
try {
|
||||
if(registeredMobStatus.isEmpty()) {
|
||||
idleProcs++;
|
||||
|
||||
if(idleProcs >= ServerConstants.MOB_STATUS_MONITOR_LIFE) {
|
||||
if(mobStatusSchedule != null) {
|
||||
mobStatusSchedule.cancel(false);
|
||||
mobStatusSchedule = null;
|
||||
public MobStatusScheduler() {
|
||||
super(MonitoredLockType.CHANNEL_MOBSTATUS);
|
||||
|
||||
super.addListener(new SchedulerListener() {
|
||||
@Override
|
||||
public void removedScheduledEntries(List<Object> toRemove, boolean update) {
|
||||
overtimeStatusLock.lock();
|
||||
try {
|
||||
for(Object mseo : toRemove) {
|
||||
MonsterStatusEffect mse = (MonsterStatusEffect) mseo;
|
||||
registeredMobStatusOvertime.remove(mse);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
idleProcs = 0;
|
||||
|
||||
long timeNow = System.currentTimeMillis();
|
||||
List<MonsterStatusEffect> toRemove = new LinkedList<>();
|
||||
for(Entry<MonsterStatusEffect, Pair<Runnable, Long>> rmd : registeredMobStatus.entrySet()) {
|
||||
Pair<Runnable, Long> r = rmd.getValue();
|
||||
|
||||
if(r.getRight() < timeNow) {
|
||||
r.getLeft().run(); // runs the cancel action
|
||||
toRemove.add(rmd.getKey());
|
||||
|
||||
if(update) {
|
||||
// it's probably ok to use one thread for both management & overtime actions
|
||||
List<MobStatusOvertimeEntry> mdoeList = new ArrayList<>(registeredMobStatusOvertime.values());
|
||||
for(MobStatusOvertimeEntry mdoe : mdoeList) {
|
||||
mdoe.update();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
overtimeStatusLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
for(MonsterStatusEffect mse : toRemove) {
|
||||
registeredMobStatus.remove(mse);
|
||||
registeredMobStatusOvertime.remove(mse);
|
||||
}
|
||||
|
||||
// it's probably ok to use one thread for both management & overtime actions
|
||||
List<MobStatusOvertimeEntry> mdoeList = new ArrayList<>(registeredMobStatusOvertime.values());
|
||||
for(MobStatusOvertimeEntry mdoe : mdoeList) {
|
||||
mdoe.update();
|
||||
}
|
||||
} finally {
|
||||
mobStatusLock.unlock();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void registerMobStatus(MonsterStatusEffect mse, Runnable cancelStatus, long duration, Runnable overtimeStatus, int overtimeDelay) {
|
||||
mobStatusLock.lock();
|
||||
try {
|
||||
idleProcs = 0;
|
||||
if(mobStatusSchedule == null) {
|
||||
mobStatusSchedule = TimerManager.getInstance().register(monitorTask, ServerConstants.MOB_STATUS_MONITOR_PROC, ServerConstants.MOB_STATUS_MONITOR_PROC);
|
||||
}
|
||||
if(overtimeStatus != null) {
|
||||
MobStatusOvertimeEntry mdoe = new MobStatusOvertimeEntry(overtimeDelay, overtimeStatus);
|
||||
|
||||
registeredMobStatus.put(mse, new Pair<>(cancelStatus, System.currentTimeMillis() + duration));
|
||||
|
||||
if(overtimeStatus != null) {
|
||||
MobStatusOvertimeEntry mdoe = new MobStatusOvertimeEntry(overtimeDelay, overtimeStatus);
|
||||
overtimeStatusLock.lock();
|
||||
try {
|
||||
registeredMobStatusOvertime.put(mse, mdoe);
|
||||
} finally {
|
||||
overtimeStatusLock.unlock();
|
||||
}
|
||||
} finally {
|
||||
mobStatusLock.unlock();
|
||||
}
|
||||
|
||||
registerEntry(mse, cancelStatus, duration);
|
||||
}
|
||||
|
||||
public void interruptMobStatus(MonsterStatusEffect mse) {
|
||||
mobStatusLock.lock();
|
||||
try {
|
||||
Pair<Runnable, Long> rmd = registeredMobStatus.remove(mse);
|
||||
if(rmd != null) rmd.getLeft().run();
|
||||
|
||||
registeredMobStatusOvertime.remove(mse);
|
||||
} finally {
|
||||
mobStatusLock.unlock();
|
||||
}
|
||||
interruptEntry(mse);
|
||||
}
|
||||
}
|
||||
|
||||
40
src/net/server/channel/worker/OverallScheduler.java
Normal file
40
src/net/server/channel/worker/OverallScheduler.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
This file is part of the HeavenMS MapleStory Server
|
||||
Copyleft 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 net.server.channel.worker;
|
||||
|
||||
import tools.locks.MonitoredLockType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ronan
|
||||
*/
|
||||
public class OverallScheduler extends BaseScheduler {
|
||||
public OverallScheduler() {
|
||||
super(MonitoredLockType.CHANNEL_OVERALL);
|
||||
}
|
||||
|
||||
public void registerDelayedAction(Runnable runAction, long delay) {
|
||||
registerEntry(runAction, runAction, delay);
|
||||
}
|
||||
|
||||
public void forceRunDelayedAction(Runnable runAction) {
|
||||
interruptEntry(runAction);
|
||||
}
|
||||
}
|
||||
30
src/net/server/channel/worker/SchedulerListener.java
Normal file
30
src/net/server/channel/worker/SchedulerListener.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
This file is part of the HeavenMS MapleStory Server
|
||||
Copyleft 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 net.server.channel.worker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ronan
|
||||
*/
|
||||
public interface SchedulerListener {
|
||||
public void removedScheduledEntries(List<Object> entries, boolean update);
|
||||
}
|
||||
Reference in New Issue
Block a user