Party Search + Conditional Buffs
Revised skillbook drops. New drop chances are related to the holder's level and boss flag. Adjusted party bonus EXP gains. The level difference calculation now only takes into account party members that participated in the action. Implemented Party Search in the source. Refactored command classes initialization to take place when booting up the server. Implemented support for conditional buffs (e.g. card buffs that takes place only in certain areas). Implemented topological sorting when updating buffs to the player, this allows a better vision of buff streaks to the player (buff-applying the original way assumes stat override client-side, to circumvent that this algorithm makes up for the best-fit scenario). Fixed Arans not taking Dojo's attack speed buff properly. Fixed pets being improperly removed from the DB after performing certain inventory actions.
This commit is contained in:
@@ -80,8 +80,10 @@ import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
|
||||
import client.MapleClient;
|
||||
import client.MapleCharacter;
|
||||
import client.SkillFactory;
|
||||
import client.command.CommandsExecutor;
|
||||
import client.inventory.Item;
|
||||
import client.inventory.ItemFactory;
|
||||
import client.inventory.MaplePet;
|
||||
import client.inventory.manipulator.MapleCashidGenerator;
|
||||
import client.newyear.NewYearCardRecord;
|
||||
import constants.ItemConstants;
|
||||
@@ -838,33 +840,6 @@ public class Server {
|
||||
return rankSystem;
|
||||
}
|
||||
|
||||
private static void clearUnreferencedPetIds() {
|
||||
PreparedStatement ps = null;
|
||||
Connection con = null;
|
||||
try {
|
||||
con = DatabaseConnection.getConnection();
|
||||
|
||||
ps = con.prepareStatement("UPDATE inventoryitems SET petid = -1, expiration = 0 WHERE petid != -1 AND petid NOT IN (SELECT petid FROM pets)");
|
||||
ps.executeUpdate();
|
||||
|
||||
ps.close();
|
||||
con.close();
|
||||
} catch(SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if(ps != null && !ps.isClosed()) {
|
||||
ps.close();
|
||||
}
|
||||
if(con != null && !con.isClosed()) {
|
||||
con.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void init() {
|
||||
Properties p = loadWorldINI();
|
||||
if(p == null) {
|
||||
@@ -897,7 +872,7 @@ public class Server {
|
||||
sqle.printStackTrace();
|
||||
}
|
||||
|
||||
clearUnreferencedPetIds();
|
||||
MaplePet.clearMissingPetsFromDb();
|
||||
MapleCashidGenerator.loadExistentCashIdsFromDb();
|
||||
|
||||
IoBuffer.setUseDirectBuffer(false);
|
||||
@@ -971,6 +946,7 @@ public class Server {
|
||||
|
||||
MapleSkillbookInformationProvider.getInstance();
|
||||
OpcodeConstants.generateOpcodeNames();
|
||||
CommandsExecutor.getInstance();
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
|
||||
@@ -65,6 +65,7 @@ public enum MonitoredLockType {
|
||||
PARTY,
|
||||
WORLD_PARTY,
|
||||
WORLD_PARTY_SEARCH_ECHELON,
|
||||
WORLD_PARTY_SEARCH_QUEUE,
|
||||
WORLD_PARTY_SEARCH_STORAGE,
|
||||
WORLD_SRVMESSAGES,
|
||||
WORLD_PETS,
|
||||
|
||||
@@ -35,10 +35,15 @@ public final class DenyPartyRequestHandler extends AbstractMaplePacketHandler {
|
||||
@Override
|
||||
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
|
||||
slea.readByte();
|
||||
MapleCharacter cfrom = c.getChannelServer().getPlayerStorage().getCharacterByName(slea.readMapleAsciiString());
|
||||
String[] cname = slea.readMapleAsciiString().split("PS: ");
|
||||
|
||||
MapleCharacter cfrom = c.getChannelServer().getPlayerStorage().getCharacterByName(cname[cname.length - 1]);
|
||||
if (cfrom != null) {
|
||||
if (MapleInviteCoordinator.answerInvite(InviteType.PARTY, c.getPlayer().getId(), cfrom.getPartyId(), false).getLeft() == InviteResult.DENIED) {
|
||||
cfrom.getClient().announce(MaplePacketCreator.partyStatusMessage(23, c.getPlayer().getName()));
|
||||
MapleCharacter chr = c.getPlayer();
|
||||
|
||||
if (MapleInviteCoordinator.answerInvite(InviteType.PARTY, chr.getId(), cfrom.getPartyId(), false).getLeft() == InviteResult.DENIED) {
|
||||
chr.updatePartySearchAvailability(chr.getParty() == null);
|
||||
cfrom.getClient().announce(MaplePacketCreator.partyStatusMessage(23, chr.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ public class EnterCashShopHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
|
||||
mc.closePlayerInteractions();
|
||||
mc.closePartySearchInteractions();
|
||||
|
||||
mc.unregisterChairBuff();
|
||||
Server.getInstance().getPlayerBuffStorage().addBuffsToStorage(mc.getId(), mc.getAllBuffs());
|
||||
|
||||
@@ -87,6 +87,7 @@ public final class EnterMTSHandler extends AbstractMaplePacketHandler {
|
||||
}
|
||||
|
||||
chr.closePlayerInteractions();
|
||||
chr.closePartySearchInteractions();
|
||||
|
||||
chr.unregisterChairBuff();
|
||||
Server.getInstance().getPlayerBuffStorage().addBuffsToStorage(chr.getId(), chr.getAllBuffs());
|
||||
|
||||
@@ -78,7 +78,8 @@ public final class GuildOperationHandler extends AbstractMaplePacketHandler {
|
||||
Set<MapleCharacter> eligibleMembers = new HashSet<>(MapleGuild.getEligiblePlayersForGuild(mc));
|
||||
if (eligibleMembers.size() < ServerConstants.CREATE_GUILD_MIN_PARTNERS) {
|
||||
if (mc.getMap().getAllPlayers().size() < ServerConstants.CREATE_GUILD_MIN_PARTNERS) {
|
||||
mc.dropMessage(1, "The Guild you are trying to create don't meet the minimum criteria of number of founders.");
|
||||
// thanks NovaStory for noticing message in need of smoother info
|
||||
mc.dropMessage(1, "Your Guild doesn't have enough cofounders present here and therefore cannot be created at this time.");
|
||||
} else {
|
||||
// players may be unaware of not belonging on a party in order to become eligible, thanks Hair (Legalize) for pointing this out
|
||||
mc.dropMessage(1, "Please make sure everyone you are trying to invite is neither on a guild nor on a party.");
|
||||
|
||||
@@ -56,6 +56,7 @@ public final class PartyOperationHandler extends AbstractMaplePacketHandler {
|
||||
List<MapleCharacter> partymembers = player.getPartyMembers();
|
||||
|
||||
MapleParty.leaveParty(party, c);
|
||||
player.updatePartySearchAvailability(true);
|
||||
player.partyOperationUpdate(party, partymembers);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -30,13 +30,7 @@ import client.MapleClient;
|
||||
* @author Quasar
|
||||
*/
|
||||
public class PartySearchRegisterHandler extends AbstractMaplePacketHandler {
|
||||
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
|
||||
return; //Disabling this for now.
|
||||
/* MapleCharacter chr = c.getPlayer();
|
||||
int min = slea.readInt();
|
||||
int max = slea.readInt();
|
||||
if (chr.getLevel() < min || chr.getLevel() > max || (max - min) > 30 || min > max) { // Client editing
|
||||
return;
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {}
|
||||
}
|
||||
@@ -21,108 +21,52 @@
|
||||
*/
|
||||
package net.server.channel.handlers;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.AbstractMaplePacketHandler;
|
||||
import net.server.world.MapleParty;
|
||||
import server.maps.MapleMap;
|
||||
import server.maps.MapleMapObject;
|
||||
import tools.MaplePacketCreator;
|
||||
import tools.data.input.SeekableLittleEndianAccessor;
|
||||
import tools.MaplePacketCreator;
|
||||
import client.MapleCharacter;
|
||||
import client.MapleClient;
|
||||
import client.MapleJob;
|
||||
import constants.ServerConstants;
|
||||
import net.server.world.MaplePartyCharacter;
|
||||
import net.server.world.PartyOperation;
|
||||
import net.server.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author XoticStory
|
||||
* @author BubblesDev
|
||||
* @author Ronan
|
||||
*/
|
||||
public class PartySearchStartHandler extends AbstractMaplePacketHandler {
|
||||
@Override
|
||||
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
|
||||
if(!ServerConstants.USE_PARTY_SEARCH){
|
||||
return;
|
||||
}
|
||||
|
||||
int min = slea.readInt();
|
||||
int max = slea.readInt();
|
||||
slea.readInt(); // members
|
||||
int jobs = slea.readInt();
|
||||
|
||||
MapleParty party = c.getPlayer().getParty();
|
||||
if(party == null) return;
|
||||
|
||||
MapleCharacter chr = c.getPlayer();
|
||||
MapleMap map = chr.getMap();
|
||||
World world = c.getWorldServer();
|
||||
|
||||
Collection<MapleMapObject> mapobjs = map.getPlayers();
|
||||
|
||||
for (MapleMapObject mapobj : mapobjs) {
|
||||
if (party.getMembers().size() > 5) {
|
||||
break;
|
||||
}
|
||||
if (mapobj instanceof MapleCharacter) {
|
||||
MapleCharacter tchar = (MapleCharacter) mapobj;
|
||||
int charlvl = tchar.getLevel();
|
||||
if (charlvl >= min && charlvl <= max && isValidJob(tchar.getJob(), jobs)) {
|
||||
if (tchar.getParty() == null) {
|
||||
MaplePartyCharacter partyplayer = new MaplePartyCharacter(tchar);
|
||||
tchar.getMap().addPartyMember(tchar);
|
||||
int min = slea.readInt();
|
||||
int max = slea.readInt();
|
||||
|
||||
world.updateParty(party.getId(), PartyOperation.JOIN, partyplayer);
|
||||
tchar.receivePartyMemberHP();
|
||||
tchar.updatePartyMemberHP();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
MapleCharacter chr = c.getPlayer();
|
||||
if (min > max) {
|
||||
chr.dropMessage(1, "The min. value is higher than the max!");
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
return;
|
||||
}
|
||||
|
||||
private static boolean isValidJob(MapleJob thejob, int jobs) {
|
||||
int jobid = thejob.getId();
|
||||
if (jobid == 0) {
|
||||
return ((jobs & 2) > 0);
|
||||
} else if (jobid == 100) {
|
||||
return ((jobs & 4) > 0);
|
||||
} else if (jobid > 100 && jobid < 113) {
|
||||
return ((jobs & 8) > 0);
|
||||
} else if (jobid > 110 && jobid < 123) {
|
||||
return ((jobs & 16) > 0);
|
||||
} else if (jobid > 120 && jobid < 133) {
|
||||
return ((jobs & 32) > 0);
|
||||
} else if (jobid == 200) {
|
||||
return ((jobs & 64) > 0);
|
||||
} else if (jobid > 209 && jobid < 213) {
|
||||
return ((jobs & 128) > 0);
|
||||
} else if (jobid > 219 && jobid < 223) {
|
||||
return ((jobs & 256) > 0);
|
||||
} else if (jobid > 229 && jobid < 233) {
|
||||
return ((jobs & 512) > 0);
|
||||
} else if (jobid == 500) {
|
||||
return ((jobs & 1024) > 0);
|
||||
} else if (jobid > 509 && jobid < 513) {
|
||||
return ((jobs & 2048) > 0);
|
||||
} else if (jobid > 519 && jobid < 523) {
|
||||
return ((jobs & 4096) > 0);
|
||||
} else if (jobid == 400) {
|
||||
return ((jobs & 8192) > 0);
|
||||
} else if (jobid > 400 && jobid < 413) {
|
||||
return ((jobs & 16384) > 0);
|
||||
} else if (jobid > 419 && jobid < 423) {
|
||||
return ((jobs & 32768) > 0);
|
||||
} else if (jobid == 300) {
|
||||
return ((jobs & 65536) > 0);
|
||||
} else if (jobid > 300 && jobid < 313) {
|
||||
return ((jobs & 131072) > 0);
|
||||
} else if (jobid > 319 && jobid < 323) {
|
||||
return ((jobs & 262144) > 0);
|
||||
}
|
||||
return false;
|
||||
if (max - min > 30) {
|
||||
chr.dropMessage(1, "You can only search for party members within a range of 30 levels.");
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
return;
|
||||
}
|
||||
|
||||
if (chr.getLevel() < min || chr.getLevel() > max) {
|
||||
chr.dropMessage(1, "The range of level for search has to include your own level.");
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
return;
|
||||
}
|
||||
|
||||
slea.readInt(); // members
|
||||
int jobs = slea.readInt();
|
||||
|
||||
MapleParty party = c.getPlayer().getParty();
|
||||
if (party == null || !c.getPlayer().isPartyLeader()) return;
|
||||
|
||||
World world = c.getWorldServer();
|
||||
world.getPartySearchCoordinator().registerPartyLeader(chr, min, max, jobs);
|
||||
}
|
||||
}
|
||||
@@ -25,8 +25,10 @@ import client.MapleClient;
|
||||
import net.AbstractMaplePacketHandler;
|
||||
import tools.data.input.SeekableLittleEndianAccessor;
|
||||
|
||||
public final class PlayerUpdateHandler extends AbstractMaplePacketHandler {
|
||||
public final class PartySearchUpdateHandler extends AbstractMaplePacketHandler {
|
||||
|
||||
@Override
|
||||
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {}
|
||||
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
|
||||
c.getWorldServer().getPartySearchCoordinator().unregisterPartyLeader(c.getPlayer());
|
||||
}
|
||||
}
|
||||
@@ -608,6 +608,8 @@ public final class PlayerInteractionHandler extends AbstractMaplePacketHandler {
|
||||
MaplePlayerShop shop = chr.getPlayerShop();
|
||||
MapleHiredMerchant merchant = chr.getHiredMerchant();
|
||||
if (shop != null && shop.isOwner(chr)) {
|
||||
System.out.println(shopItem.getItem().getPet() + " " + shopItem.getItem().getPetId());
|
||||
System.out.println(ivItem.getPet() + " " + ivItem.getPetId());
|
||||
if (shop.isOpen() || !shop.addItem(shopItem)) { // thanks Vcoc for pointing an exploit with unlimited shop slots
|
||||
c.announce(MaplePacketCreator.serverNotice(1, "You can't sell it anymore."));
|
||||
return;
|
||||
|
||||
@@ -107,7 +107,7 @@ public final class TakeDamageHandler extends AbstractMaplePacketHandler {
|
||||
if (damage > 0) {
|
||||
loseItems = attacker.getStats().loseItem();
|
||||
if (loseItems != null) {
|
||||
if (chr.getBuffEffect(MapleBuffStat.ARIANT_PQ_SHIELD) == null) {
|
||||
if (chr.getBuffEffect(MapleBuffStat.AURA) == null) {
|
||||
MapleInventoryType type;
|
||||
final int playerpos = chr.getPosition().x;
|
||||
byte d = 1;
|
||||
|
||||
366
src/net/server/coordinator/MaplePartySearchCoordinator.java
Normal file
366
src/net/server/coordinator/MaplePartySearchCoordinator.java
Normal file
@@ -0,0 +1,366 @@
|
||||
/*
|
||||
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 net.server.coordinator;
|
||||
|
||||
import client.MapleCharacter;
|
||||
import client.MapleJob;
|
||||
import constants.ServerConstants;
|
||||
import java.io.File;
|
||||
import net.server.world.MapleParty;
|
||||
import net.server.coordinator.MapleInviteCoordinator.InviteType;
|
||||
import net.server.coordinator.partysearch.PartySearchEchelon;
|
||||
import net.server.coordinator.partysearch.PartySearchStorage;
|
||||
import tools.MaplePacketCreator;
|
||||
import tools.Pair;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
|
||||
import net.server.audit.locks.MonitoredLockType;
|
||||
import net.server.audit.locks.MonitoredReentrantReadWriteLock;
|
||||
import provider.MapleData;
|
||||
import provider.MapleDataProviderFactory;
|
||||
import provider.MapleDataTool;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ronan
|
||||
*/
|
||||
public class MaplePartySearchCoordinator {
|
||||
|
||||
private Map<MapleJob, PartySearchStorage> storage = new HashMap<>();
|
||||
private Map<MapleJob, PartySearchEchelon> upcomers = new HashMap<>();
|
||||
|
||||
private List<MapleCharacter> leaderQueue = new LinkedList<>();
|
||||
private final ReentrantReadWriteLock leaderQueueLock = new MonitoredReentrantReadWriteLock(MonitoredLockType.WORLD_PARTY_SEARCH_QUEUE, true);
|
||||
private final ReadLock leaderQueueRLock = leaderQueueLock.readLock();
|
||||
private final WriteLock leaderQueueWLock = leaderQueueLock.writeLock();
|
||||
|
||||
private Map<Integer, MapleCharacter> searchLeaders = new HashMap<>();
|
||||
private Map<Integer, LeaderSearchMetadata> searchSettings = new HashMap<>();
|
||||
|
||||
private static Map<Integer, Set<Integer>> mapNeighbors = fetchNeighbouringMaps();
|
||||
private static Map<Integer, MapleJob> jobTable = instantiateJobTable();
|
||||
|
||||
private static Map<Integer, Set<Integer>> fetchNeighbouringMaps() {
|
||||
Map<Integer, Set<Integer>> mapLinks = new HashMap<>();
|
||||
|
||||
MapleData data = MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/" + "Etc.wz")).getData("MapNeighbors.img");
|
||||
if (data != null) {
|
||||
for (MapleData mapdata : data.getChildren()) {
|
||||
int mapid = Integer.valueOf(mapdata.getName());
|
||||
|
||||
Set<Integer> neighborMaps = new HashSet<>();
|
||||
mapLinks.put(mapid, neighborMaps);
|
||||
|
||||
for (MapleData neighbordata : mapdata.getChildren()) {
|
||||
int neighborid = MapleDataTool.getInt(neighbordata, 999999999);
|
||||
|
||||
if (neighborid != 999999999) {
|
||||
neighborMaps.add(neighborid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mapLinks;
|
||||
}
|
||||
|
||||
public static boolean isInVicinity(int callerMapid, int calleeMapid) {
|
||||
Set<Integer> vicinityMapids = mapNeighbors.get(calleeMapid);
|
||||
|
||||
if (vicinityMapids != null) {
|
||||
return vicinityMapids.contains(calleeMapid);
|
||||
} else {
|
||||
int callerRange = callerMapid / 10000000;
|
||||
if (callerRange >= 90) {
|
||||
return callerRange == (calleeMapid / 1000000);
|
||||
} else {
|
||||
return callerRange == (calleeMapid / 10000000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<Integer, MapleJob> instantiateJobTable() {
|
||||
Map<Integer, MapleJob> table = new HashMap<>();
|
||||
|
||||
List<Pair<Integer, Integer>> jobSearchTypes = new LinkedList<Pair<Integer, Integer>>() {{
|
||||
add(new Pair<>(MapleJob.MAPLELEAF_BRIGADIER.getId(), 0));
|
||||
add(new Pair<>(0, 0));
|
||||
add(new Pair<>(MapleJob.ARAN1.getId(), 0));
|
||||
add(new Pair<>(100, 3));
|
||||
add(new Pair<>(MapleJob.DAWNWARRIOR1.getId(), 0));
|
||||
add(new Pair<>(200, 3));
|
||||
add(new Pair<>(MapleJob.BLAZEWIZARD1.getId(), 0));
|
||||
add(new Pair<>(500, 2));
|
||||
add(new Pair<>(MapleJob.THUNDERBREAKER1.getId(), 0));
|
||||
add(new Pair<>(400, 2));
|
||||
add(new Pair<>(MapleJob.NIGHTWALKER1.getId(), 0));
|
||||
add(new Pair<>(300, 2));
|
||||
add(new Pair<>(MapleJob.WINDARCHER1.getId(), 0));
|
||||
add(new Pair<>(MapleJob.EVAN1.getId(), 0));
|
||||
}};
|
||||
|
||||
int i = 0;
|
||||
for (Pair<Integer, Integer> p : jobSearchTypes) {
|
||||
table.put(i, MapleJob.getById(p.getLeft()));
|
||||
i++;
|
||||
|
||||
for (int j = 1; j <= p.getRight(); j++) {
|
||||
table.put(i, MapleJob.getById(p.getLeft() + 10 * j));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
private class LeaderSearchMetadata {
|
||||
private int minLevel;
|
||||
private int maxLevel;
|
||||
private List<MapleJob> searchedJobs;
|
||||
|
||||
private int reentryCount;
|
||||
|
||||
private List<MapleJob> decodeSearchedJobs(int jobsSelected) {
|
||||
List<MapleJob> searchedJobs = new LinkedList<>();
|
||||
|
||||
int topByte = (int)((Math.log(jobsSelected) / Math.log(2)) + 1e-5);
|
||||
|
||||
for (int i = 0; i <= topByte; i++) {
|
||||
if (jobsSelected % 2 == 1) {
|
||||
MapleJob job = jobTable.get(i);
|
||||
if (job != null) {
|
||||
searchedJobs.add(job);
|
||||
}
|
||||
}
|
||||
|
||||
jobsSelected = jobsSelected >> 1;
|
||||
if (jobsSelected == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return searchedJobs;
|
||||
}
|
||||
|
||||
private LeaderSearchMetadata(int minLevel, int maxLevel, int jobs) {
|
||||
this.minLevel = minLevel;
|
||||
this.maxLevel = maxLevel;
|
||||
this.searchedJobs = decodeSearchedJobs(jobs);
|
||||
this.reentryCount = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public MaplePartySearchCoordinator() {
|
||||
for (MapleJob job : jobTable.values()) {
|
||||
storage.put(job, new PartySearchStorage());
|
||||
upcomers.put(job, new PartySearchEchelon());
|
||||
}
|
||||
}
|
||||
|
||||
public void attachPlayer(MapleCharacter chr) {
|
||||
upcomers.get(getPartySearchJob(chr.getJob())).attachPlayer(chr);
|
||||
}
|
||||
|
||||
public void detachPlayer(MapleCharacter chr) {
|
||||
MapleJob psJob = getPartySearchJob(chr.getJob());
|
||||
|
||||
if (!upcomers.get(psJob).detachPlayer(chr)) {
|
||||
storage.get(psJob).detachPlayer(chr);
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePartySearchStorage() {
|
||||
for (Entry<MapleJob, PartySearchEchelon> psUpdate : upcomers.entrySet()) {
|
||||
storage.get(psUpdate.getKey()).updateStorage(psUpdate.getValue().exportEchelon());
|
||||
}
|
||||
}
|
||||
|
||||
private static MapleJob getPartySearchJob(MapleJob job) {
|
||||
if (job.getJobNiche() == 0) {
|
||||
return MapleJob.BEGINNER;
|
||||
} else if (job.getId() < 600) { // explorers
|
||||
return MapleJob.getById((job.getId() / 10) * 10);
|
||||
} else if (job.getId() >= 1000) {
|
||||
return MapleJob.getById((job.getId() / 100) * 100);
|
||||
} else {
|
||||
return MapleJob.MAPLELEAF_BRIGADIER;
|
||||
}
|
||||
}
|
||||
|
||||
private MapleCharacter fetchPlayer(int callerCid, int callerMapid, MapleJob job, int minLevel, int maxLevel) {
|
||||
return storage.get(getPartySearchJob(job)).callPlayer(callerCid, callerMapid, minLevel, maxLevel);
|
||||
}
|
||||
|
||||
private void addQueueLeader(MapleCharacter leader) {
|
||||
leaderQueueRLock.lock();
|
||||
try {
|
||||
leaderQueue.add(leader);
|
||||
} finally {
|
||||
leaderQueueRLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private void removeQueueLeader(MapleCharacter leader) {
|
||||
leaderQueueRLock.lock();
|
||||
try {
|
||||
leaderQueue.remove(leader);
|
||||
} finally {
|
||||
leaderQueueRLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void registerPartyLeader(MapleCharacter leader, int minLevel, int maxLevel, int jobs) {
|
||||
if (searchLeaders.containsKey(leader.getId())) return;
|
||||
|
||||
searchSettings.put(leader.getId(), new LeaderSearchMetadata(minLevel, maxLevel, jobs));
|
||||
searchLeaders.put(leader.getId(), leader);
|
||||
addQueueLeader(leader);
|
||||
}
|
||||
|
||||
public void unregisterPartyLeader(MapleCharacter leader) {
|
||||
MapleCharacter toRemove = searchLeaders.remove(leader.getId());
|
||||
if (toRemove != null) {
|
||||
removeQueueLeader(toRemove);
|
||||
searchSettings.remove(leader.getId());
|
||||
}
|
||||
}
|
||||
|
||||
private MapleCharacter searchPlayer(MapleCharacter leader) {
|
||||
LeaderSearchMetadata settings = searchSettings.get(leader.getId());
|
||||
if (settings != null) {
|
||||
int minLevel = settings.minLevel, maxLevel = settings.maxLevel;
|
||||
Collections.shuffle(settings.searchedJobs);
|
||||
|
||||
int leaderCid = leader.getId();
|
||||
int leaderMapid = leader.getMapId();
|
||||
for (MapleJob searchJob : settings.searchedJobs) {
|
||||
MapleCharacter chr = fetchPlayer(leaderCid, leaderMapid, searchJob, minLevel, maxLevel);
|
||||
if (chr != null) {
|
||||
return chr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean sendPartyInviteFromSearch(MapleCharacter chr, MapleCharacter leader) {
|
||||
if (chr == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int partyid = leader.getPartyId();
|
||||
if (partyid < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (MapleInviteCoordinator.createInvite(InviteType.PARTY, leader, partyid, chr.getId())) {
|
||||
chr.disablePartySearchInvite(leader.getId());
|
||||
chr.announce(MaplePacketCreator.partySearchInvite(leader));
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private Pair<List<MapleCharacter>, List<MapleCharacter>> fetchQueuedLeaders() {
|
||||
List<MapleCharacter> queuedLeaders, nextLeaders;
|
||||
|
||||
leaderQueueWLock.lock();
|
||||
try {
|
||||
int splitIdx = Math.min(leaderQueue.size(), 100);
|
||||
|
||||
queuedLeaders = new LinkedList<>(leaderQueue.subList(0, splitIdx));
|
||||
nextLeaders = new LinkedList<>(leaderQueue.subList(splitIdx, leaderQueue.size()));
|
||||
} finally {
|
||||
leaderQueueWLock.unlock();
|
||||
}
|
||||
|
||||
return new Pair<>(queuedLeaders, nextLeaders);
|
||||
}
|
||||
|
||||
public void runPartySearch() {
|
||||
Pair<List<MapleCharacter>, List<MapleCharacter>> queuedLeaders = fetchQueuedLeaders();
|
||||
|
||||
List<MapleCharacter> searchedLeaders = new LinkedList<>();
|
||||
List<MapleCharacter> recalledLeaders = new LinkedList<>();
|
||||
List<MapleCharacter> expiredLeaders = new LinkedList<>();
|
||||
|
||||
for (MapleCharacter leader : queuedLeaders.getLeft()) {
|
||||
MapleCharacter chr = searchPlayer(leader);
|
||||
if (sendPartyInviteFromSearch(chr, leader)) {
|
||||
searchedLeaders.add(leader);
|
||||
} else {
|
||||
LeaderSearchMetadata settings = searchSettings.get(leader.getId());
|
||||
if (settings != null) {
|
||||
if (settings.reentryCount < ServerConstants.PARTY_SEARCH_REENTRY_LIMIT) {
|
||||
settings.reentryCount += 1;
|
||||
recalledLeaders.add(leader);
|
||||
} else {
|
||||
expiredLeaders.add(leader);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
leaderQueueRLock.lock();
|
||||
try {
|
||||
leaderQueue.clear();
|
||||
leaderQueue.addAll(queuedLeaders.getRight());
|
||||
|
||||
try {
|
||||
leaderQueue.addAll(25, recalledLeaders);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
leaderQueue.addAll(recalledLeaders);
|
||||
}
|
||||
} finally {
|
||||
leaderQueueRLock.unlock();
|
||||
}
|
||||
|
||||
for (MapleCharacter leader : searchedLeaders) {
|
||||
MapleParty party = leader.getParty();
|
||||
if (party != null && party.getMembers().size() < 6) {
|
||||
addQueueLeader(leader);
|
||||
} else {
|
||||
if (leader.isLoggedinWorld()) leader.dropMessage(5, "Your Party Search token session has finished as your party reached full capacity.");
|
||||
searchLeaders.remove(leader.getId());
|
||||
searchSettings.remove(leader.getId());
|
||||
}
|
||||
}
|
||||
|
||||
for (MapleCharacter leader : expiredLeaders) {
|
||||
if (leader.isLoggedinWorld()) leader.dropMessage(5, "Your Party Search token session expired, please stop your Party Search and retry again later.");
|
||||
searchLeaders.remove(leader.getId());
|
||||
searchSettings.remove(leader.getId());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
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 net.server.coordinator.partysearch;
|
||||
|
||||
import client.MapleCharacter;
|
||||
import net.server.coordinator.MaplePartySearchCoordinator;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ronan
|
||||
*/
|
||||
public class PartySearchCharacter {
|
||||
|
||||
private WeakReference<MapleCharacter> player;
|
||||
private int level;
|
||||
private boolean queued;
|
||||
|
||||
public PartySearchCharacter(MapleCharacter chr) {
|
||||
player = new WeakReference(chr);
|
||||
level = chr.getLevel();
|
||||
queued = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
MapleCharacter chr = player.get();
|
||||
return chr == null ? "[empty]" : chr.toString();
|
||||
}
|
||||
|
||||
public MapleCharacter callPlayer(int leaderid, int callerMapid) {
|
||||
MapleCharacter chr = player.get();
|
||||
if (chr == null || !MaplePartySearchCoordinator.isInVicinity(callerMapid, chr.getMapId())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (chr.hasDisabledPartySearchInvite(leaderid)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
queued = false;
|
||||
if (chr.isLoggedinWorld() && chr.getParty() == null) {
|
||||
return chr;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public MapleCharacter getPlayer() {
|
||||
return player.get();
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public boolean isQueued() {
|
||||
return queued;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
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 net.server.coordinator.partysearch;
|
||||
|
||||
import client.MapleCharacter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
|
||||
import net.server.audit.locks.MonitoredLockType;
|
||||
import net.server.audit.locks.MonitoredReentrantReadWriteLock;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ronan
|
||||
*/
|
||||
public class PartySearchEchelon {
|
||||
|
||||
private final ReentrantReadWriteLock psLock = new MonitoredReentrantReadWriteLock(MonitoredLockType.WORLD_PARTY_SEARCH_ECHELON, true);
|
||||
private final ReadLock psRLock = psLock.readLock();
|
||||
private final WriteLock psWLock = psLock.writeLock();
|
||||
|
||||
private Map<Integer, WeakReference<MapleCharacter>> echelon = new HashMap<>(20);
|
||||
|
||||
public List<MapleCharacter> exportEchelon() {
|
||||
psWLock.lock(); // reversing read/write actually could provide a lax yet sure performance/precision trade-off here
|
||||
try {
|
||||
List<MapleCharacter> players = new ArrayList<>(echelon.size());
|
||||
|
||||
for (WeakReference<MapleCharacter> chrRef : echelon.values()) {
|
||||
MapleCharacter chr = chrRef.get();
|
||||
if (chr != null) {
|
||||
players.add(chr);
|
||||
}
|
||||
}
|
||||
|
||||
echelon.clear();
|
||||
return players;
|
||||
} finally {
|
||||
psWLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void attachPlayer(MapleCharacter chr) {
|
||||
psRLock.lock();
|
||||
try {
|
||||
echelon.put(chr.getId(), new WeakReference<>(chr));
|
||||
} finally {
|
||||
psRLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean detachPlayer(MapleCharacter chr) {
|
||||
psRLock.lock();
|
||||
try {
|
||||
return echelon.remove(chr.getId()) != null;
|
||||
} finally {
|
||||
psRLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
258
src/net/server/coordinator/partysearch/PartySearchStorage.java
Normal file
258
src/net/server/coordinator/partysearch/PartySearchStorage.java
Normal file
@@ -0,0 +1,258 @@
|
||||
/*
|
||||
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 net.server.coordinator.partysearch;
|
||||
|
||||
import client.MapleCharacter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
|
||||
import net.server.audit.locks.MonitoredLockType;
|
||||
import net.server.audit.locks.MonitoredReentrantReadWriteLock;
|
||||
|
||||
import java.awt.geom.Line2D;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ronan
|
||||
*/
|
||||
public class PartySearchStorage {
|
||||
|
||||
private List<PartySearchCharacter> storage = new ArrayList<>(20);
|
||||
private PartySearchEmptyIntervals emptyManager = new PartySearchEmptyIntervals();
|
||||
|
||||
private class PartySearchEmptyIntervals {
|
||||
|
||||
private List<Line2D> emptyLimits = new ArrayList<>();
|
||||
|
||||
private void refitEmptyIntervals(int st, int en, int minLevel, int maxLevel) {
|
||||
List<Line2D> checkLimits = new ArrayList<>(emptyLimits.subList(st, en));
|
||||
|
||||
float newLimitX1, newLimitX2;
|
||||
if (!checkLimits.isEmpty()) {
|
||||
Line2D firstLimit = checkLimits.get(0);
|
||||
Line2D lastLimit = checkLimits.get(checkLimits.size() - 1);
|
||||
|
||||
newLimitX1 = (float) ((minLevel < firstLimit.getX1()) ? minLevel : firstLimit.getX1());
|
||||
newLimitX2 = (float) ((maxLevel > lastLimit.getX2()) ? maxLevel : lastLimit.getX2());
|
||||
|
||||
for (Line2D limit : checkLimits) {
|
||||
emptyLimits.remove(st);
|
||||
}
|
||||
} else {
|
||||
newLimitX1 = minLevel;
|
||||
newLimitX2 = maxLevel;
|
||||
}
|
||||
|
||||
emptyLimits.add(st, new Line2D.Float((float) newLimitX1, 0, (float) newLimitX2, 0));
|
||||
}
|
||||
|
||||
private int bsearchInterval(int level) {
|
||||
int st = 0, en = emptyLimits.size() - 1;
|
||||
|
||||
int mid, idx;
|
||||
while (en >= st) {
|
||||
idx = (st + en) / 2;
|
||||
mid = (int) emptyLimits.get(idx).getX1();
|
||||
|
||||
if (mid == level) {
|
||||
return idx;
|
||||
} else if (mid < level) {
|
||||
st = idx + 1;
|
||||
} else {
|
||||
en = idx - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return en;
|
||||
}
|
||||
|
||||
public void addEmptyInterval(int fromLevel, int toLevel) {
|
||||
synchronized (emptyLimits) { // adding intervals occurs on a same-thread process, so this is actually not performance grinding
|
||||
int st = bsearchInterval(fromLevel);
|
||||
if (st < 0) {
|
||||
st = 0;
|
||||
} else if (emptyLimits.get(st).getX2() < fromLevel) {
|
||||
st += 1;
|
||||
}
|
||||
|
||||
int en = bsearchInterval(toLevel);
|
||||
if (en < st) en = st - 1;
|
||||
|
||||
refitEmptyIntervals(st, en + 1, fromLevel, toLevel);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInEmptyInterval(int minLevel, int maxLevel) {
|
||||
synchronized (emptyLimits) {
|
||||
int idx = bsearchInterval(minLevel);
|
||||
return idx >= 0 && maxLevel <= emptyLimits.get(idx).getX2();
|
||||
}
|
||||
}
|
||||
|
||||
public void clearEmptyInterval() {
|
||||
synchronized (emptyLimits) {
|
||||
emptyLimits.clear();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final ReentrantReadWriteLock psLock = new MonitoredReentrantReadWriteLock(MonitoredLockType.WORLD_PARTY_SEARCH_STORAGE, true);
|
||||
private final ReadLock psRLock = psLock.readLock();
|
||||
private final WriteLock psWLock = psLock.writeLock();
|
||||
|
||||
public List<PartySearchCharacter> getStorageList() {
|
||||
psRLock.lock();
|
||||
try {
|
||||
return new ArrayList<>(storage);
|
||||
} finally {
|
||||
psRLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private Map<Integer, MapleCharacter> fetchRemainingPlayers() {
|
||||
List<PartySearchCharacter> players = getStorageList();
|
||||
Map<Integer, MapleCharacter> remainingPlayers = new HashMap<>(players.size());
|
||||
|
||||
for (PartySearchCharacter psc : players) {
|
||||
if (psc.isQueued()) {
|
||||
MapleCharacter chr = psc.getPlayer();
|
||||
if (chr != null) {
|
||||
remainingPlayers.put(chr.getId(), chr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return remainingPlayers;
|
||||
}
|
||||
|
||||
public void updateStorage(Collection<MapleCharacter> echelon) {
|
||||
Map<Integer, MapleCharacter> newcomers = new HashMap<>();
|
||||
for (MapleCharacter chr : echelon) {
|
||||
newcomers.put(chr.getId(), chr);
|
||||
}
|
||||
|
||||
Map<Integer, MapleCharacter> curStorage = fetchRemainingPlayers();
|
||||
curStorage.putAll(newcomers);
|
||||
|
||||
List<PartySearchCharacter> pscList = new ArrayList<>(curStorage.size());
|
||||
for (MapleCharacter chr : curStorage.values()) {
|
||||
pscList.add(new PartySearchCharacter(chr));
|
||||
}
|
||||
|
||||
Collections.sort(pscList, new Comparator<PartySearchCharacter>() {
|
||||
@Override
|
||||
public int compare(PartySearchCharacter c1, PartySearchCharacter c2)
|
||||
{
|
||||
int levelP1 = c1.getLevel(), levelP2 = c2.getLevel();
|
||||
return levelP1 > levelP2 ? 1 : (levelP1 == levelP2 ? 0 : -1);
|
||||
}
|
||||
});
|
||||
|
||||
psWLock.lock();
|
||||
try {
|
||||
storage.clear();
|
||||
storage.addAll(pscList);
|
||||
} finally {
|
||||
psWLock.unlock();
|
||||
}
|
||||
|
||||
emptyManager.clearEmptyInterval();
|
||||
}
|
||||
|
||||
private static int bsearchStorage(List<PartySearchCharacter> storage, int level) {
|
||||
int st = 0, en = storage.size() - 1;
|
||||
|
||||
int mid, idx;
|
||||
while (en >= st) {
|
||||
idx = (st + en) / 2;
|
||||
mid = storage.get(idx).getLevel();
|
||||
|
||||
if (mid == level) {
|
||||
return idx;
|
||||
} else if (mid < level) {
|
||||
st = idx + 1;
|
||||
} else {
|
||||
en = idx - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return en;
|
||||
}
|
||||
|
||||
public MapleCharacter callPlayer(int callerCid, int callerMapid, int minLevel, int maxLevel) {
|
||||
if (emptyManager.isInEmptyInterval(minLevel, maxLevel)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<PartySearchCharacter> pscList = getStorageList();
|
||||
|
||||
int idx = bsearchStorage(pscList, maxLevel);
|
||||
for (int i = idx; i >= 0; i--) {
|
||||
PartySearchCharacter psc = pscList.get(i);
|
||||
if (!psc.isQueued()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (psc.getLevel() < minLevel) {
|
||||
break;
|
||||
}
|
||||
|
||||
MapleCharacter chr = psc.callPlayer(callerCid, callerMapid);
|
||||
if (chr != null) {
|
||||
return chr;
|
||||
}
|
||||
}
|
||||
|
||||
emptyManager.addEmptyInterval(minLevel, maxLevel);
|
||||
return null;
|
||||
}
|
||||
|
||||
public void detachPlayer(MapleCharacter chr) {
|
||||
PartySearchCharacter toRemove = null;
|
||||
for (PartySearchCharacter psc : getStorageList()) {
|
||||
MapleCharacter player = psc.getPlayer();
|
||||
|
||||
if (player != null && player.getId() == chr.getId()) {
|
||||
toRemove = psc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (toRemove != null) {
|
||||
psWLock.lock();
|
||||
try {
|
||||
storage.remove(toRemove);
|
||||
} finally {
|
||||
psWLock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
38
src/net/server/worker/PartySearchWorker.java
Normal file
38
src/net/server/worker/PartySearchWorker.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
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 net.server.worker;
|
||||
|
||||
import net.server.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ronan
|
||||
*/
|
||||
public class PartySearchWorker extends BaseWorker implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
wserv.runPartySearchUpdateSchedule();
|
||||
}
|
||||
|
||||
public PartySearchWorker(World world) {
|
||||
super(world);
|
||||
}
|
||||
}
|
||||
@@ -341,7 +341,8 @@ public class MapleParty {
|
||||
player.setMPC(partyplayer);
|
||||
player.getMap().addPartyMember(player);
|
||||
player.silentPartyUpdate();
|
||||
|
||||
|
||||
player.updatePartySearchAvailability(false);
|
||||
player.partyOperationUpdate(party, null);
|
||||
|
||||
player.announce(MaplePacketCreator.partyCreated(party, partyplayer.getId()));
|
||||
@@ -370,7 +371,9 @@ public class MapleParty {
|
||||
world.updateParty(party.getId(), PartyOperation.JOIN, partyplayer);
|
||||
player.receivePartyMemberHP();
|
||||
player.updatePartyMemberHP();
|
||||
|
||||
|
||||
player.resetPartySearchInvite(party.getLeaderId());
|
||||
player.updatePartySearchAvailability(false);
|
||||
player.partyOperationUpdate(party, null);
|
||||
return true;
|
||||
} else {
|
||||
@@ -466,7 +469,8 @@ public class MapleParty {
|
||||
|
||||
emc.setParty(null);
|
||||
world.updateParty(party.getId(), PartyOperation.EXPEL, expelled);
|
||||
|
||||
|
||||
emc.updatePartySearchAvailability(true);
|
||||
emc.partyOperationUpdate(party, partyMembers);
|
||||
} else {
|
||||
world.updateParty(party.getId(), PartyOperation.EXPEL, expelled);
|
||||
|
||||
@@ -70,6 +70,7 @@ import net.server.worker.FishingWorker;
|
||||
import net.server.worker.HiredMerchantWorker;
|
||||
import net.server.worker.MapOwnershipWorker;
|
||||
import net.server.worker.MountTirednessWorker;
|
||||
import net.server.worker.PartySearchWorker;
|
||||
import net.server.worker.PetFullnessWorker;
|
||||
import net.server.worker.ServerMessageWorker;
|
||||
import net.server.worker.TimedMapObjectWorker;
|
||||
@@ -94,6 +95,7 @@ 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;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -115,6 +117,7 @@ public class World {
|
||||
private Map<Integer, MapleGuildSummary> gsStore = new HashMap<>();
|
||||
private PlayerStorage players = new PlayerStorage();
|
||||
private MapleMatchCheckerCoordinator matchChecker = new MapleMatchCheckerCoordinator();
|
||||
private MaplePartySearchCoordinator partySearch = new MaplePartySearchCoordinator();
|
||||
|
||||
private final ReentrantReadWriteLock chnLock = new MonitoredReentrantReadWriteLock(MonitoredLockType.WORLD_CHANNELS, true);
|
||||
private ReadLock chnRLock = chnLock.readLock();
|
||||
@@ -170,6 +173,7 @@ public class World {
|
||||
private ScheduledFuture<?> marriagesSchedule;
|
||||
private ScheduledFuture<?> mapOwnershipSchedule;
|
||||
private ScheduledFuture<?> fishingSchedule;
|
||||
private ScheduledFuture<?> partySearchSchedule;
|
||||
|
||||
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;
|
||||
@@ -202,6 +206,7 @@ public class World {
|
||||
marriagesSchedule = tman.register(new WeddingReservationWorker(this), ServerConstants.WEDDING_RESERVATION_INTERVAL * 60 * 1000, ServerConstants.WEDDING_RESERVATION_INTERVAL * 60 * 1000);
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
@@ -494,6 +499,10 @@ public class World {
|
||||
public MapleMatchCheckerCoordinator getMatchCheckerCoordinator() {
|
||||
return matchChecker;
|
||||
}
|
||||
|
||||
public MaplePartySearchCoordinator getPartySearchCoordinator() {
|
||||
return partySearch;
|
||||
}
|
||||
|
||||
public void addPlayer(MapleCharacter chr) {
|
||||
players.addPlayer(chr);
|
||||
@@ -1975,6 +1984,11 @@ public class World {
|
||||
}
|
||||
}
|
||||
|
||||
public void runPartySearchUpdateSchedule() {
|
||||
partySearch.updatePartySearchStorage();
|
||||
partySearch.runPartySearch();
|
||||
}
|
||||
|
||||
private void clearWorldData() {
|
||||
List<MapleParty> pList;
|
||||
partyLock.lock();
|
||||
@@ -2061,6 +2075,11 @@ public class World {
|
||||
fishingSchedule = null;
|
||||
}
|
||||
|
||||
if(partySearchSchedule != null) {
|
||||
partySearchSchedule.cancel(false);
|
||||
partySearchSchedule = null;
|
||||
}
|
||||
|
||||
players.disconnectAll();
|
||||
players = null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user