Pooled Io Write + EXP loss & Detached morph patch + Storages in World
Fixed autocommit getting called early/unavailable in a few catch blocks, when trying to save player. Fixed the missing variable declaration in several quest scripts that were recently formatted. Reworked the EXP loss formula applied at a knock-out. The new formula follows past discussions in several MS forums. Fixed a deadlock issue related with party HP and party doors management. Refactored management of packets sent to client through an IoSession. New system no longer makes use of a synchronized statement when calling announce(packet), rather makes use of dedicated threads to send queued packets for the respective players. Fixed SP reset allowing increase of unexpected skills. Refactored storages, no longer instantiated as coupled with the character, rather instantiated in a map within the world object, with accountid as key. Reviewed usage of character objects of offline party members, that weren't being properly checked. Fixed some unexpected cases with buffs and morphs (within the enhanced buff system) making the latter show up as another morph figure. Added a "priority buff" perspective within the enhanced buff system, to let such priority items/skills take awareness over other buffs. (This would be vital for some quests, as the one reported in #514 ) Fixed EXP gains in certain scenarios showing up with less amount than the expected (due to float point operations). Fixed a critical bug that have emerged in a recent mount-skill update, issue happened due to an improper object initialization. Fixed mount information packet not being relayed to the player at world login time, rendering some quests not startable until the mob levels up.
This commit is contained in:
@@ -198,6 +198,7 @@ public class MapleServerHandler extends IoHandlerAdapter {
|
||||
FilePrinter.printError(FilePrinter.PACKET_HANDLER + packetHandler.getClass().getName() + ".txt", t, "Error for " + (client.getPlayer() == null ? "" : "player ; " + client.getPlayer() + " on map ; " + client.getPlayer().getMapId() + " - ") + "account ; " + client.getAccountName() + "\r\n" + slea.toString());
|
||||
//client.announce(MaplePacketCreator.enableActions());//bugs sometimes
|
||||
}
|
||||
client.updateLastPacket();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
|
||||
import net.MapleServerHandler;
|
||||
import net.mina.MapleCodecFactory;
|
||||
import net.server.channel.Channel;
|
||||
import net.server.coordinator.MapleSessionCoordinator;
|
||||
import net.server.guild.MapleAlliance;
|
||||
import net.server.guild.MapleGuild;
|
||||
import net.server.guild.MapleGuildCharacter;
|
||||
@@ -70,6 +71,7 @@ import net.server.worker.RankingLoginWorker;
|
||||
import net.server.worker.ReleaseLockWorker;
|
||||
import net.server.worker.RespawnWorker;
|
||||
import net.server.world.World;
|
||||
import net.server.world.announcer.MapleAnnouncerCoordinator;
|
||||
|
||||
import org.apache.mina.core.buffer.IoBuffer;
|
||||
import org.apache.mina.core.buffer.SimpleBufferAllocator;
|
||||
@@ -94,7 +96,6 @@ import constants.GameConstants;
|
||||
import constants.OpcodeConstants;
|
||||
import constants.ServerConstants;
|
||||
import java.util.TimeZone;
|
||||
import net.server.coordinator.MapleSessionCoordinator;
|
||||
import server.CashShop.CashItemFactory;
|
||||
import server.MapleSkillbookInformationProvider;
|
||||
import server.ThreadManager;
|
||||
@@ -949,12 +950,17 @@ public class Server {
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
MapleAnnouncerCoordinator.getInstance().init();
|
||||
System.out.println();
|
||||
|
||||
if(ServerConstants.USE_FAMILY_SYSTEM) {
|
||||
timeToTake = System.currentTimeMillis();
|
||||
MapleFamily.loadAllFamilies();
|
||||
System.out.println("Families loaded in " + ((System.currentTimeMillis() - timeToTake) / 1000.0) + " seconds\r\n");
|
||||
}
|
||||
|
||||
|
||||
System.out.println();
|
||||
|
||||
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 30);
|
||||
acceptor.setHandler(new MapleServerHandler());
|
||||
try {
|
||||
@@ -964,7 +970,7 @@ public class Server {
|
||||
}
|
||||
|
||||
System.out.println("Listening on port 8484\r\n\r\n");
|
||||
|
||||
|
||||
System.out.println("HeavenMS is now online.\r\n");
|
||||
online = true;
|
||||
|
||||
@@ -1446,6 +1452,11 @@ public class Server {
|
||||
} finally {
|
||||
lgnWLock.unlock();
|
||||
}
|
||||
|
||||
for (World wserv : this.getWorlds()) {
|
||||
wserv.clearAccountCharacterView(accountid);
|
||||
wserv.unregisterAccountStorage(accountid);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -1708,6 +1719,32 @@ public class Server {
|
||||
return gmLevel;
|
||||
}
|
||||
|
||||
public void loadAccountStorages(MapleClient c) {
|
||||
int accountId = c.getAccID();
|
||||
Set<Integer> accWorlds = new HashSet<>();
|
||||
lgnWLock.lock();
|
||||
try {
|
||||
Set<Integer> chars = accountChars.get(accountId);
|
||||
|
||||
for (Integer cid : chars) {
|
||||
Integer worldid = worldChars.get(cid);
|
||||
if (worldid != null) {
|
||||
accWorlds.add(worldid);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
lgnWLock.unlock();
|
||||
}
|
||||
|
||||
List<World> worldList = this.getWorlds();
|
||||
for (Integer worldid : accWorlds) {
|
||||
if (worldid < worldList.size()) {
|
||||
World wserv = worldList.get(worldid);
|
||||
wserv.registerAccountStorage(accountId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String getRemoteIp(IoSession session) {
|
||||
return MapleSessionCoordinator.getSessionRemoteAddress(session);
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ public enum MonitoredLockType {
|
||||
CHARACTER_STA,
|
||||
CLIENT,
|
||||
CLIENT_ENCODER,
|
||||
CLIENT_SESSION,
|
||||
CLIENT_LOGIN,
|
||||
BOOK,
|
||||
ITEM,
|
||||
|
||||
@@ -30,7 +30,7 @@ import client.MapleCharacter;
|
||||
import client.MapleClient;
|
||||
import client.inventory.MapleInventoryType;
|
||||
import client.inventory.manipulator.MapleInventoryManipulator;
|
||||
import server.MaplePortal;
|
||||
import server.maps.MaplePortal;
|
||||
import server.MapleTrade;
|
||||
import server.maps.MapleMap;
|
||||
import tools.FilePrinter;
|
||||
|
||||
@@ -23,7 +23,7 @@ package net.server.channel.handlers;
|
||||
|
||||
import client.MapleClient;
|
||||
import net.AbstractMaplePacketHandler;
|
||||
import server.MaplePortal;
|
||||
import server.maps.MaplePortal;
|
||||
import server.MapleTrade;
|
||||
import server.MapleTrade.TradeResult;
|
||||
import tools.MaplePacketCreator;
|
||||
|
||||
@@ -29,7 +29,7 @@ import client.MapleClient;
|
||||
import constants.GameConstants;
|
||||
import java.awt.Point;
|
||||
import net.AbstractMaplePacketHandler;
|
||||
import server.MaplePortal;
|
||||
import server.maps.MaplePortal;
|
||||
import server.maps.MapleMapObject;
|
||||
import server.maps.MapleMapObjectType;
|
||||
import server.maps.MaplePlayerShop;
|
||||
|
||||
@@ -101,16 +101,19 @@ public final class MonsterCarnivalHandler extends AbstractMaplePacketHandler {
|
||||
final MapleDisease dis = skill.getDisease();
|
||||
MapleParty enemies = c.getPlayer().getParty().getEnemy();
|
||||
if (skill.targetsAll) {
|
||||
int chanceAcerto = 0;
|
||||
int hitChance = 0;
|
||||
if (dis.getDisease() == 121 || dis.getDisease() == 122 || dis.getDisease() == 125 || dis.getDisease() == 126) {
|
||||
chanceAcerto = (int) (Math.random() * 100);
|
||||
hitChance = (int) (Math.random() * 100);
|
||||
}
|
||||
if (chanceAcerto <= 80) {
|
||||
for (MaplePartyCharacter chrS : enemies.getPartyMembers()) {
|
||||
if (dis == null) {
|
||||
chrS.getPlayer().dispel();
|
||||
} else {
|
||||
chrS.getPlayer().giveDebuff(dis, skill.getSkill());
|
||||
if (hitChance <= 80) {
|
||||
for (MaplePartyCharacter mpc : enemies.getPartyMembers()) {
|
||||
MapleCharacter mc = mpc.getPlayer();
|
||||
if (mc != null) {
|
||||
if (dis == null) {
|
||||
mc.dispel();
|
||||
} else {
|
||||
mc.giveDebuff(dis, skill.getSkill());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public final class PartyOperationHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
case 2: { // leave/disband
|
||||
if (party != null) {
|
||||
List<MapleCharacter> partymembers = player.getPartyMembers();
|
||||
List<MapleCharacter> partymembers = player.getPartyMembersOnline();
|
||||
|
||||
MapleParty.leaveParty(party, c);
|
||||
player.updatePartySearchAvailability(true);
|
||||
|
||||
@@ -34,7 +34,7 @@ import constants.ServerConstants;
|
||||
|
||||
import net.AbstractMaplePacketHandler;
|
||||
import server.MapleItemInformationProvider;
|
||||
import server.MaplePortal;
|
||||
import server.maps.MaplePortal;
|
||||
import server.MapleTrade;
|
||||
import constants.GameConstants;
|
||||
import server.maps.FieldLimit;
|
||||
|
||||
@@ -53,6 +53,7 @@ import client.MapleDisease;
|
||||
import client.MapleFamily;
|
||||
import client.MapleFamilyEntry;
|
||||
import client.MapleKeyBinding;
|
||||
import client.MapleMount;
|
||||
import client.SkillFactory;
|
||||
import client.inventory.Equip;
|
||||
import client.inventory.Item;
|
||||
@@ -352,8 +353,14 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
|
||||
|
||||
if (newcomer) {
|
||||
for(MaplePet pet : player.getPets()) {
|
||||
if(pet != null)
|
||||
if(pet != null) {
|
||||
wserv.registerPetHunger(player, player.getPetIndex(pet));
|
||||
}
|
||||
}
|
||||
|
||||
MapleMount mount = player.getMount(); // thanks Ari for noticing a scenario where Silver Mane quest couldn't be started
|
||||
if (mount.getItemId() != 0) {
|
||||
player.announce(MaplePacketCreator.updateMount(player.getId(), mount, false));
|
||||
}
|
||||
|
||||
player.reloadQuestExpirations();
|
||||
|
||||
@@ -36,6 +36,7 @@ import client.inventory.ModifyInventory;
|
||||
import client.inventory.manipulator.MapleInventoryManipulator;
|
||||
import client.inventory.manipulator.MapleKarmaManipulator;
|
||||
import client.processor.AssignAPProcessor;
|
||||
import client.processor.AssignSPProcessor;
|
||||
import client.processor.DueyProcessor;
|
||||
import constants.GameConstants;
|
||||
import constants.ItemConstants;
|
||||
@@ -156,6 +157,10 @@ public final class UseCashItemHandler extends AbstractMaplePacketHandler {
|
||||
|
||||
if (itemId > 5050000) {
|
||||
int SPTo = slea.readInt();
|
||||
if (!AssignSPProcessor.canSPAssign(c, SPTo)) { // exploit found thanks to Arnah
|
||||
return;
|
||||
}
|
||||
|
||||
int SPFrom = slea.readInt();
|
||||
Skill skillSPTo = SkillFactory.getSkill(SPTo);
|
||||
Skill skillSPFrom = SkillFactory.getSkill(SPFrom);
|
||||
|
||||
@@ -71,7 +71,9 @@ public class MatchCheckerCPQChallenge implements MatchCheckerListenerRecipe {
|
||||
|
||||
List<MaplePartyCharacter> chrMembers = new LinkedList<>();
|
||||
for (MaplePartyCharacter mpc : chr.getParty().getMembers()) {
|
||||
chrMembers.add(mpc);
|
||||
if (mpc.isOnline()) {
|
||||
chrMembers.add(mpc);
|
||||
}
|
||||
}
|
||||
|
||||
if (message.contentEquals("cpq1")) {
|
||||
|
||||
@@ -91,8 +91,13 @@ public class MapleAlliance {
|
||||
List<MapleCharacter> mcl = new LinkedList<>();
|
||||
|
||||
for(MaplePartyCharacter mpc: party.getMembers()) {
|
||||
if(mpc.getPlayer().getGuildRank() == 1 && mpc.getPlayer().getMapId() == party.getLeader().getPlayer().getMapId())
|
||||
mcl.add(mpc.getPlayer());
|
||||
MapleCharacter chr = mpc.getPlayer();
|
||||
if (chr != null) {
|
||||
MapleCharacter lchr = party.getLeader().getPlayer();
|
||||
if (chr.getGuildRank() == 1 && lchr != null && chr.getMapId() == lchr.getMapId()) {
|
||||
mcl.add(chr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!mcl.isEmpty() && !mcl.get(0).isPartyLeader()) {
|
||||
|
||||
30
src/net/server/worker/TimeoutWorker.java
Normal file
30
src/net/server/worker/TimeoutWorker.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package net.server.worker;
|
||||
|
||||
import client.MapleCharacter;
|
||||
import constants.ServerConstants;
|
||||
import net.server.world.World;
|
||||
import tools.FilePrinter;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Shavit
|
||||
*/
|
||||
public class TimeoutWorker extends BaseWorker implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
long time = System.currentTimeMillis();
|
||||
Collection<MapleCharacter> chars = wserv.getPlayerStorage().getAllCharacters();
|
||||
for(MapleCharacter chr : chars) {
|
||||
if(time - chr.getClient().getLastPacket() > ServerConstants.TIMEOUT_DURATION) {
|
||||
FilePrinter.print(FilePrinter.DCS + chr.getClient().getAccountName(), chr.getName() + " auto-disconnected due to inactivity.");
|
||||
chr.getClient().disconnect(true, chr.getCashShop().isOpened());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TimeoutWorker(World world) {
|
||||
super(world);
|
||||
}
|
||||
}
|
||||
@@ -144,6 +144,23 @@ public class MapleParty {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public List<MaplePartyCharacter> getPartyMembersOnline() {
|
||||
lock.lock();
|
||||
try {
|
||||
List<MaplePartyCharacter> ret = new LinkedList<>();
|
||||
|
||||
for (MaplePartyCharacter mpc : members) {
|
||||
if (mpc.isOnline()) {
|
||||
ret.add(mpc);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
// used whenever entering PQs: will draw every party member that can attempt a target PQ while ingnoring those unfit.
|
||||
public Collection<MaplePartyCharacter> getEligibleMembers() {
|
||||
@@ -452,7 +469,7 @@ public class MapleParty {
|
||||
if (expelled != null) {
|
||||
MapleCharacter emc = expelled.getPlayer();
|
||||
if(emc != null) {
|
||||
List<MapleCharacter> partyMembers = emc.getPartyMembers();
|
||||
List<MapleCharacter> partyMembers = emc.getPartyMembersOnline();
|
||||
|
||||
MapleMap map = emc.getMap();
|
||||
if(map != null) map.removePartyMember(emc);
|
||||
|
||||
@@ -82,6 +82,9 @@ public class MaplePartyCharacter {
|
||||
|
||||
public void setOnline(boolean online) {
|
||||
this.online = online;
|
||||
if (!online) {
|
||||
this.character = null; // thanks Feras for noticing offline party members retaining whole character object unnecessarily
|
||||
}
|
||||
}
|
||||
|
||||
public int getMapId() {
|
||||
|
||||
@@ -60,12 +60,32 @@ import java.util.WeakHashMap;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
import scripting.event.EventInstanceManager;
|
||||
import server.MapleStorage;
|
||||
import server.TimerManager;
|
||||
import server.maps.AbstractMapleMapObject;
|
||||
import server.maps.MapleHiredMerchant;
|
||||
import server.maps.MapleMap;
|
||||
import server.maps.MapleMiniDungeon;
|
||||
import server.maps.MapleMiniDungeonInfo;
|
||||
import server.maps.MaplePlayerShop;
|
||||
import server.maps.MaplePlayerShopItem;
|
||||
import server.maps.AbstractMapleMapObject;
|
||||
import net.server.PlayerStorage;
|
||||
import net.server.Server;
|
||||
import net.server.audit.LockCollector;
|
||||
import net.server.audit.locks.MonitoredLockType;
|
||||
import net.server.audit.locks.MonitoredReentrantLock;
|
||||
import net.server.audit.locks.MonitoredReentrantReadWriteLock;
|
||||
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
|
||||
import net.server.channel.Channel;
|
||||
import net.server.channel.CharacterIdChannelPair;
|
||||
import net.server.coordinator.MapleInviteCoordinator;
|
||||
import net.server.coordinator.MapleInviteCoordinator.InviteResult;
|
||||
import net.server.coordinator.MapleInviteCoordinator.InviteType;
|
||||
import net.server.coordinator.MapleMatchCheckerCoordinator;
|
||||
import net.server.coordinator.MaplePartySearchCoordinator;
|
||||
import net.server.guild.MapleGuild;
|
||||
import net.server.guild.MapleGuildCharacter;
|
||||
import net.server.guild.MapleGuildSummary;
|
||||
import net.server.worker.CharacterAutosaverWorker;
|
||||
import net.server.worker.FamilyDailyResetWorker;
|
||||
import net.server.worker.FishingWorker;
|
||||
@@ -76,30 +96,13 @@ import net.server.worker.PartySearchWorker;
|
||||
import net.server.worker.PetFullnessWorker;
|
||||
import net.server.worker.ServerMessageWorker;
|
||||
import net.server.worker.TimedMapObjectWorker;
|
||||
import net.server.worker.TimeoutWorker;
|
||||
import net.server.worker.WeddingReservationWorker;
|
||||
import net.server.PlayerStorage;
|
||||
import net.server.Server;
|
||||
import net.server.audit.LockCollector;
|
||||
import net.server.channel.Channel;
|
||||
import net.server.channel.CharacterIdChannelPair;
|
||||
import net.server.guild.MapleGuild;
|
||||
import net.server.guild.MapleGuildCharacter;
|
||||
import net.server.guild.MapleGuildSummary;
|
||||
import net.server.world.announcer.MapleAnnouncerCoordinator;
|
||||
import tools.DatabaseConnection;
|
||||
import tools.MaplePacketCreator;
|
||||
import tools.Pair;
|
||||
import tools.packets.Fishing;
|
||||
import net.server.audit.locks.MonitoredLockType;
|
||||
import net.server.audit.locks.MonitoredReentrantLock;
|
||||
import net.server.audit.locks.MonitoredReentrantReadWriteLock;
|
||||
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
|
||||
import net.server.coordinator.MapleInviteCoordinator;
|
||||
import net.server.coordinator.MapleInviteCoordinator.InviteResult;
|
||||
import net.server.coordinator.MapleInviteCoordinator.InviteType;
|
||||
import net.server.coordinator.MapleMatchCheckerCoordinator;
|
||||
import net.server.coordinator.MaplePartySearchCoordinator;
|
||||
import server.maps.MapleMiniDungeon;
|
||||
import server.maps.MapleMiniDungeonInfo;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -122,12 +125,14 @@ public class World {
|
||||
private PlayerStorage players = new PlayerStorage();
|
||||
private MapleMatchCheckerCoordinator matchChecker = new MapleMatchCheckerCoordinator();
|
||||
private MaplePartySearchCoordinator partySearch = new MaplePartySearchCoordinator();
|
||||
private MapleAnnouncerCoordinator announcer = new MapleAnnouncerCoordinator();
|
||||
|
||||
private final ReentrantReadWriteLock chnLock = new MonitoredReentrantReadWriteLock(MonitoredLockType.WORLD_CHANNELS, true);
|
||||
private ReadLock chnRLock = chnLock.readLock();
|
||||
private WriteLock chnWLock = chnLock.writeLock();
|
||||
|
||||
private Map<Integer, SortedMap<Integer, MapleCharacter>> accountChars = new HashMap<>();
|
||||
private Map<Integer, MapleStorage> accountStorages = new HashMap<>();
|
||||
private MonitoredReentrantLock accountCharsLock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.WORLD_CHARS, true);
|
||||
|
||||
private Set<Integer> queuedGuilds = new HashSet<>();
|
||||
@@ -178,6 +183,7 @@ public class World {
|
||||
private ScheduledFuture<?> mapOwnershipSchedule;
|
||||
private ScheduledFuture<?> fishingSchedule;
|
||||
private ScheduledFuture<?> partySearchSchedule;
|
||||
private ScheduledFuture<?> timeoutSchedule;
|
||||
|
||||
public World(int world, int flag, String eventmsg, int exprate, int droprate, int bossdroprate, int mesorate, int questrate, int travelrate, int fishingrate) {
|
||||
this.id = world;
|
||||
@@ -211,12 +217,15 @@ public class World {
|
||||
mapOwnershipSchedule = tman.register(new MapOwnershipWorker(this), 20 * 1000, 20 * 1000);
|
||||
fishingSchedule = tman.register(new FishingWorker(this), 10 * 1000, 10 * 1000);
|
||||
partySearchSchedule = tman.register(new PartySearchWorker(this), 10 * 1000, 10 * 1000);
|
||||
timeoutSchedule = tman.register(new TimeoutWorker(this), 10 * 1000, 10 * 1000);
|
||||
|
||||
if(ServerConstants.USE_FAMILY_SYSTEM) {
|
||||
long timeLeft = Server.getTimeLeftForNextDay();
|
||||
FamilyDailyResetWorker.resetEntitlementUsage(this);
|
||||
tman.register(new FamilyDailyResetWorker(this), 24 * 60 * 60 * 1000, timeLeft);
|
||||
}
|
||||
|
||||
announcer.init();
|
||||
}
|
||||
|
||||
public int getChannelsSize() {
|
||||
@@ -440,6 +449,41 @@ public class World {
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAccountCharacterView(Integer accountId) {
|
||||
accountCharsLock.lock();
|
||||
try {
|
||||
SortedMap<Integer, MapleCharacter> accChars = accountChars.remove(accountId);
|
||||
if (accChars != null) {
|
||||
accChars.clear();
|
||||
}
|
||||
} finally {
|
||||
accountCharsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void registerAccountStorage(Integer accountId) {
|
||||
MapleStorage storage = MapleStorage.loadOrCreateFromDB(accountId, this.id);
|
||||
accountCharsLock.lock();
|
||||
try {
|
||||
accountStorages.put(accountId, storage);
|
||||
} finally {
|
||||
accountCharsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterAccountStorage(Integer accountId) {
|
||||
accountCharsLock.lock();
|
||||
try {
|
||||
accountStorages.remove(accountId);
|
||||
} finally {
|
||||
accountCharsLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public MapleStorage getAccountStorage(Integer accountId) {
|
||||
return accountStorages.get(accountId);
|
||||
}
|
||||
|
||||
private static List<Entry<Integer, SortedMap<Integer, MapleCharacter>>> getSortedAccountCharacterView(Map<Integer, SortedMap<Integer, MapleCharacter>> map) {
|
||||
List<Entry<Integer, SortedMap<Integer, MapleCharacter>>> list = new ArrayList<>(map.size());
|
||||
for(Entry<Integer, SortedMap<Integer, MapleCharacter>> e : map.entrySet()) {
|
||||
@@ -512,6 +556,10 @@ public class World {
|
||||
public MaplePartySearchCoordinator getPartySearchCoordinator() {
|
||||
return partySearch;
|
||||
}
|
||||
|
||||
public MapleAnnouncerCoordinator getAnnouncerCoordinator() {
|
||||
return announcer;
|
||||
}
|
||||
|
||||
public void addPlayer(MapleCharacter chr) {
|
||||
players.addPlayer(chr);
|
||||
@@ -909,7 +957,7 @@ public class World {
|
||||
chr.setParty(party);
|
||||
chr.setMPC(partychar);
|
||||
}
|
||||
chr.getClient().announce(MaplePacketCreator.updateParty(chr.getClient().getChannel(), party, operation, target));
|
||||
chr.announce(MaplePacketCreator.updateParty(chr.getClient().getChannel(), party, operation, target));
|
||||
}
|
||||
}
|
||||
switch (operation) {
|
||||
@@ -917,7 +965,7 @@ public class World {
|
||||
case EXPEL:
|
||||
MapleCharacter chr = getPlayerStorage().getCharacterById(target.getId());
|
||||
if (chr != null) {
|
||||
chr.getClient().announce(MaplePacketCreator.updateParty(chr.getClient().getChannel(), party, operation, target));
|
||||
chr.announce(MaplePacketCreator.updateParty(chr.getClient().getChannel(), party, operation, target));
|
||||
chr.setParty(null);
|
||||
chr.setMPC(null);
|
||||
}
|
||||
@@ -948,25 +996,25 @@ public class World {
|
||||
break;
|
||||
case CHANGE_LEADER:
|
||||
MapleCharacter mc = party.getLeader().getPlayer();
|
||||
MapleCharacter newLeader = target.getPlayer();
|
||||
|
||||
EventInstanceManager eim = mc.getEventInstance();
|
||||
|
||||
if(eim != null && eim.isEventLeader(mc)) {
|
||||
eim.changedLeader(newLeader);
|
||||
} else {
|
||||
int oldLeaderMapid = mc.getMapId();
|
||||
|
||||
if (MapleMiniDungeonInfo.isDungeonMap(oldLeaderMapid)) {
|
||||
if (oldLeaderMapid != newLeader.getMapId()) {
|
||||
MapleMiniDungeon mmd = newLeader.getClient().getChannelServer().getMiniDungeon(oldLeaderMapid);
|
||||
if(mmd != null) {
|
||||
mmd.close();
|
||||
if (mc != null) {
|
||||
EventInstanceManager eim = mc.getEventInstance();
|
||||
|
||||
if(eim != null && eim.isEventLeader(mc)) {
|
||||
eim.changedLeader(target);
|
||||
} else {
|
||||
int oldLeaderMapid = mc.getMapId();
|
||||
|
||||
if (MapleMiniDungeonInfo.isDungeonMap(oldLeaderMapid)) {
|
||||
if (oldLeaderMapid != target.getMapId()) {
|
||||
MapleMiniDungeon mmd = mc.getClient().getChannelServer().getMiniDungeon(oldLeaderMapid);
|
||||
if(mmd != null) {
|
||||
mmd.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
party.setLeader(target);
|
||||
}
|
||||
party.setLeader(target);
|
||||
break;
|
||||
default:
|
||||
System.out.println("Unhandled updateParty operation " + operation.name());
|
||||
@@ -2114,9 +2162,15 @@ public class World {
|
||||
partySearchSchedule = null;
|
||||
}
|
||||
|
||||
if(timeoutSchedule != null) {
|
||||
timeoutSchedule.cancel(false);
|
||||
timeoutSchedule = null;
|
||||
}
|
||||
|
||||
players.disconnectAll();
|
||||
players = null;
|
||||
|
||||
announcer.shutdown();
|
||||
clearWorldData();
|
||||
System.out.println("Finished shutting down world " + id + "\r\n");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
This file is part of the HeavenMS MapleStory Server
|
||||
Copyleft (L) 2016 - 2019 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.world.announcer;
|
||||
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import org.apache.mina.core.session.IoSession;
|
||||
import net.server.world.announcer.MapleAnnouncerEntryPool.SessionPacket;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ronan
|
||||
*/
|
||||
public class MapleAnnouncerCoordinator {
|
||||
|
||||
private static final MapleAnnouncerCoordinator instance = new MapleAnnouncerCoordinator();
|
||||
|
||||
public static MapleAnnouncerCoordinator getInstance() { // world-agnostic Announcer coordinator
|
||||
return instance;
|
||||
}
|
||||
|
||||
private MapleAnnouncerEntryPool pool = new MapleAnnouncerEntryPool();
|
||||
private ConcurrentLinkedQueue<SessionPacket> queue = new ConcurrentLinkedQueue<>();
|
||||
private Thread t;
|
||||
|
||||
public void append(IoSession io, byte[] packet) {
|
||||
queue.offer(pool.getSessionPacket(io, packet));
|
||||
}
|
||||
|
||||
public void init() {
|
||||
final Runnable r = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
while (!Thread.interrupted()) {
|
||||
try {
|
||||
SessionPacket p = queue.poll();
|
||||
if (p != null) {
|
||||
IoSession session = p.getSession();
|
||||
byte[] packet = p.getPacket();
|
||||
|
||||
session.write(packet);
|
||||
pool.returnSessionPacket(p);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
t = new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
t.interrupt();
|
||||
try {
|
||||
t.join();
|
||||
} catch (InterruptedException ie) {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
|
||||
queue.clear();
|
||||
pool.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
74
src/net/server/world/announcer/MapleAnnouncerEntryPool.java
Normal file
74
src/net/server/world/announcer/MapleAnnouncerEntryPool.java
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
This file is part of the HeavenMS MapleStory Server
|
||||
Copyleft (L) 2016 - 2019 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.world.announcer;
|
||||
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import org.apache.mina.core.session.IoSession;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ronan
|
||||
*/
|
||||
public class MapleAnnouncerEntryPool {
|
||||
|
||||
private ConcurrentLinkedQueue<SessionPacket> instancedPairs = new ConcurrentLinkedQueue<>();
|
||||
private final static int initialCount = 20000; // initial length of the instanced pool
|
||||
|
||||
public MapleAnnouncerEntryPool() {
|
||||
for (int i = 0; i < initialCount; i++) {
|
||||
instancedPairs.offer(new SessionPacket());
|
||||
}
|
||||
}
|
||||
|
||||
public class SessionPacket {
|
||||
|
||||
private IoSession session;
|
||||
private byte[] packet;
|
||||
|
||||
public IoSession getSession() {
|
||||
return session;
|
||||
}
|
||||
|
||||
public byte[] getPacket() {
|
||||
return packet;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public SessionPacket getSessionPacket(IoSession session, byte[] packet) {
|
||||
SessionPacket sp = instancedPairs.poll();
|
||||
if (sp == null) {
|
||||
sp = new SessionPacket();
|
||||
}
|
||||
|
||||
sp.session = session;
|
||||
sp.packet = packet;
|
||||
return sp;
|
||||
}
|
||||
|
||||
public void returnSessionPacket(SessionPacket sp) {
|
||||
instancedPairs.offer(sp);
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
instancedPairs.clear();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user