Persistent diseases + PQ request system + GuildPQ fix

Implemented persistent diseases. Players now keep their disease status when logging out the game.
Solved several concurrent access issues in MapleMap and MapleMonster.
Implemented an option where an account's character slots can be accounted either by each world or all-server range.
Fixed some issues with character slot count when entering/exiting Cash Shop.
Fixed an exploit with Papulatus, on where players could create cracks of dimension infinitely.
Solved an issue with the "reach" command not working properly when the targeted player is on an event instance.
Devised an advanced and secure "PQ request" system. The service revolves around expecting massive number of players requesting a "pass" simultaneously, and fairly & swiftly responsing as much people as possible.
Improved overall Whisper handler performance.
Fixed GPQ Stage 1 statues not working as expected, which rendered the instance unplayable until now.
Added commands for start, complete and reset quests.
This commit is contained in:
ronancpl
2018-08-18 11:38:55 -03:00
parent cda4433d99
commit 0d47edf1a7
116 changed files with 1596 additions and 703 deletions

View File

@@ -100,6 +100,7 @@ public class Server {
private final Properties subnetInfo = new Properties();
private static Server instance = null;
private final Map<Integer, Set<Integer>> accountChars = new HashMap<>();
private final Map<Integer, Short> accountCharacterCount = new HashMap<>();
private final Map<Integer, Integer> worldChars = new HashMap<>();
private final Map<String, Integer> transitioningChars = new HashMap<>();
private List<Pair<Integer, String>> worldRecommendedList = new LinkedList<>();
@@ -601,9 +602,7 @@ public class Server {
MapleClient c = processDiseaseAnnounceClients.remove(0);
MapleCharacter player = c.getPlayer();
if(player != null && player.isLoggedinWorld()) {
for(MapleCharacter chr : player.getMap().getCharacters()) {
chr.announceDiseases(c);
}
player.announceDiseases();
}
}
@@ -1089,6 +1088,32 @@ public class Server {
}
}
public short getAccountCharacterCount(Integer accountid) {
lgnRLock.lock();
try {
return accountCharacterCount.get(accountid);
} finally {
lgnRLock.unlock();
}
}
public short getAccountWorldCharacterCount(Integer accountid, Integer worldid) {
lgnRLock.lock();
try {
short count = 0;
for(Integer chr : accountChars.get(accountid)) {
if(worldChars.get(chr).equals(worldid)) {
count++;
}
}
return count;
} finally {
lgnRLock.unlock();
}
}
private Set<Integer> getAccountCharacterEntries(Integer accountid) {
lgnRLock.lock();
try {
@@ -1115,6 +1140,8 @@ public class Server {
lgnWLock.lock();
try {
accountCharacterCount.put(accountid, (short)(accountCharacterCount.get(accountid) + 1));
Set<Integer> accChars = accountChars.get(accountid);
accChars.add(chrid);
@@ -1132,6 +1159,8 @@ public class Server {
public void deleteCharacterEntry(Integer accountid, Integer chrid) {
lgnWLock.lock();
try {
accountCharacterCount.put(accountid, (short)(accountCharacterCount.get(accountid) - 1));
Set<Integer> accChars = accountChars.get(accountid);
accChars.remove(chrid);
@@ -1169,6 +1198,7 @@ public class Server {
public void deleteAccountEntry(Integer accountid) { is this even a thing?
lgnWLock.lock();
try {
accountCharacterCount.remove(accountid);
accountChars.remove(accountid);
} finally {
lgnWLock.unlock();
@@ -1190,6 +1220,7 @@ public class Server {
List<MapleCharacter> wchars = w.getAccountCharactersView(accountId);
if(wchars == null) {
if(!accountChars.containsKey(accountId)) {
accountCharacterCount.put(accountId, (short) 0);
accountChars.put(accountId, new HashSet<Integer>()); // not advisable at all to write on the map on a read-protected environment
} // yet it's known there's no problem since no other point in the source does
} else if(!wchars.isEmpty()) { // this action.
@@ -1206,7 +1237,8 @@ public class Server {
return new Pair<>(new Pair<>(chrTotal, lastwchars), accChars);
}
private static List<List<MapleCharacter>> loadAccountCharactersViewFromDb(int accId, int wlen) {
private static Pair<Short, List<List<MapleCharacter>>> loadAccountCharactersViewFromDb(int accId, int wlen) {
short characterCount = 0;
List<List<MapleCharacter>> wchars = new ArrayList<>(wlen);
for(int i = 0; i < wlen; i++) wchars.add(i, new LinkedList<MapleCharacter>());
@@ -1231,8 +1263,10 @@ public class Server {
ps.setInt(1, accId);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
characterCount++;
int cworld = rs.getByte("world");
if(cworld >= wlen) break;
if(cworld >= wlen) continue;
if(cworld > curWorld) {
wchars.add(curWorld, chars);
@@ -1253,7 +1287,7 @@ public class Server {
sqle.printStackTrace();
}
return wchars;
return new Pair<>(characterCount, wchars);
}
public void loadAccountCharacters(MapleClient c) {
@@ -1300,10 +1334,13 @@ public class Server {
private int loadAccountCharactersView(Integer accId, int gmLevel, int fromWorldid) { // returns the maximum gmLevel found
List<World> wlist = this.getWorlds();
List<List<MapleCharacter>> accChars = loadAccountCharactersViewFromDb(accId, wlist.size());
Pair<Short, List<List<MapleCharacter>>> accCharacters = loadAccountCharactersViewFromDb(accId, wlist.size());
lgnWLock.lock();
try {
List<List<MapleCharacter>> accChars = accCharacters.getRight();
accountCharacterCount.put(accId, accCharacters.getLeft());
Set<Integer> chars = accountChars.get(accId);
if(chars == null) {
chars = new HashSet<>(5);

View File

@@ -75,6 +75,7 @@ public enum MonitoredLockType {
EM_LOBBY,
EM_QUEUE,
EM_SCHDL,
EM_START,
CASHSHOP,
VISITOR_PSHOP,
STORAGE,

View File

@@ -37,6 +37,11 @@ public final class OwlWarpHandler extends AbstractMaplePacketHandler {
int ownerid = slea.readInt();
int mapid = slea.readInt();
if(ownerid == c.getPlayer().getId()) {
c.announce(MaplePacketCreator.serverNotice(1, "You cannot visit your own shop."));
return;
}
MapleHiredMerchant hm = c.getWorldServer().getHiredMerchant(ownerid); // if both hired merchant and player shop is on the same map
MaplePlayerShop ps;
if(hm == null || hm.getMapId() != mapid || !hm.hasItem(c.getPlayer().getOwlSearch())) {

View File

@@ -27,6 +27,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import net.AbstractMaplePacketHandler;
import net.server.PlayerBuffValueHolder;
@@ -90,6 +91,7 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
e.printStackTrace();
}
} else {
c.setCharacterSlots((byte) player.getClient().getCharacterSlots());
player.newClient(c);
}
if (player == null) { //If you are still getting null here then please just uninstall the game >.>, we dont need you fucking with the logs
@@ -275,16 +277,6 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
c.announce(MaplePacketCreator.enableReport());
player.changeSkillLevel(SkillFactory.getSkill(10000000 * player.getJobType() + 12), (byte) (player.getLinkedLevel() / 10), 20, -1);
player.checkBerserk(player.isHidden());
player.buffExpireTask();
player.diseaseExpireTask();
player.skillCooldownTask();
player.expirationTask();
player.questExpirationTask();
if (GameConstants.hasSPTable(player.getJob()) && player.getJob().getId() != 2001) {
player.createDragon();
}
player.commitExcludedItems();
if (newcomer){
/*
@@ -295,12 +287,31 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
if (player.isGM()){
Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.earnTitleMessage((player.gmLevel() < 6 ? "GM " : "Admin ") + player.getName() + " has logged in"));
}
if(diseases != null) {
for(Entry<MapleDisease, Pair<Long, MobSkill>> e : diseases.entrySet()) {
final List<Pair<MapleDisease, Integer>> debuff = Collections.singletonList(new Pair<>(e.getKey(), Integer.valueOf(e.getValue().getRight().getX())));
c.announce(MaplePacketCreator.giveDebuff(debuff, e.getValue().getRight()));
}
player.announceDiseases();
}
} else {
if(player.isRidingBattleship()) {
player.announceBattleshipHp();
}
}
player.buffExpireTask();
player.diseaseExpireTask();
player.skillCooldownTask();
player.expirationTask();
player.questExpirationTask();
if (GameConstants.hasSPTable(player.getJob()) && player.getJob().getId() != 2001) {
player.createDragon();
}
player.commitExcludedItems();
showDueyNotification(c, player);
if (player.getMap().getHPDec() > 0) player.resetHpDecreaseTask();

View File

@@ -39,8 +39,8 @@ public final class ScriptedItemHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
slea.readInt(); // trash stamp (thx rmzero)
short itemSlot = slea.readShort(); // item sl0t (thx rmzero)
slea.readInt(); // trash stamp (thanks rmzero)
short itemSlot = slea.readShort(); // item slot (thanks rmzero)
int itemId = slea.readInt(); // itemId
scriptedItem info = ii.getScriptedItemInfo(itemId);
if (info == null) return;

View File

@@ -34,6 +34,7 @@ import client.inventory.ModifyInventory;
import constants.ItemConstants;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.AbstractMaplePacketHandler;
import client.inventory.manipulator.MapleInventoryManipulator;
import server.MapleItemInformationProvider;
@@ -72,10 +73,17 @@ public final class ScrollHandler extends AbstractMaplePacketHandler {
Item scroll = useInventory.getItem(slot);
Item wscroll = null;
if (((Equip) toScroll).getUpgradeSlots() < 1 && !ItemConstants.isCleanSlate(scroll.getItemId())) {
if (ItemConstants.isCleanSlate(scroll.getItemId())) {
Map<String, Integer> eqStats = ii.getEquipStats(scroll.getItemId());
if (eqStats == null || eqStats.get("tuc") == 0) {
c.announce(MaplePacketCreator.getInventoryFull());
return;
}
} else if (((Equip) toScroll).getUpgradeSlots() < 1) {
c.announce(MaplePacketCreator.getInventoryFull());
return;
}
List<Integer> scrollReqs = ii.getScrollReqs(scroll.getItemId());
if (scrollReqs.size() > 0 && !scrollReqs.contains(toScroll.getItemId())) {
c.announce(MaplePacketCreator.getInventoryFull());

View File

@@ -27,7 +27,6 @@ import java.sql.SQLException;
import net.AbstractMaplePacketHandler;
import net.server.world.World;
import tools.LogHelper;
import tools.DatabaseConnection;
import tools.FilePrinter;
import tools.MaplePacketCreator;
@@ -42,7 +41,8 @@ import java.sql.Connection;
* @author Matze
*/
public final class WhisperHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
byte mode = slea.readByte();
if (mode == 6) { // whisper
@@ -92,7 +92,7 @@ public final class WhisperHandler extends AbstractMaplePacketHandler {
} else {
c.announce(MaplePacketCreator.getFindReply(victim.getName(), victim.getMap().getId(), 1));
}
} else { // not found
} else if (c.getPlayer().gmLevel() > 1) { // not found
try {
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT gm FROM characters WHERE name = ?");
@@ -116,6 +116,8 @@ public final class WhisperHandler extends AbstractMaplePacketHandler {
} catch (SQLException e) {
e.printStackTrace();
}
} else {
c.announce(MaplePacketCreator.getWhisperReply(recipient, (byte) 0));
}
} else if (mode == 0x44) {
//Buddy find?

View File

@@ -117,14 +117,16 @@ public class MapleGuild {
return;
}
Set<Integer> chs = Server.getInstance().getOpenChannels(world);
if (notifications.keySet().size() != chs.size()) {
notifications.clear();
for (Integer ch : chs) {
notifications.put(ch, new LinkedList<Integer>());
}
} else {
for (List<Integer> l : notifications.values()) {
l.clear();
synchronized (notifications) {
if (notifications.keySet().size() != chs.size()) {
notifications.clear();
for (Integer ch : chs) {
notifications.put(ch, new LinkedList<Integer>());
}
} else {
for (List<Integer> l : notifications.values()) {
l.clear();
}
}
}
@@ -134,7 +136,11 @@ public class MapleGuild {
if (!mgc.isOnline()) {
continue;
}
List<Integer> chl = notifications.get(mgc.getChannel());
List<Integer> chl;
synchronized (notifications) {
chl = notifications.get(mgc.getChannel());
}
if (chl != null) chl.add(mgc.getId());
//Unable to connect to Channel... error was here
}
@@ -279,26 +285,31 @@ public class MapleGuild {
}
public void broadcast(final byte[] packet, int exceptionId, BCOp bcop) {
synchronized (notifications) {
if (bDirty) {
buildNotifications();
}
try {
for (Integer b : Server.getInstance().getOpenChannels(world)) {
if (notifications.get(b).size() > 0) {
if (bcop == BCOp.DISBAND) {
Server.getInstance().getWorld(world).setGuildAndRank(notifications.get(b), 0, 5, exceptionId);
} else if (bcop == BCOp.EMBLEMCHANGE) {
Server.getInstance().getWorld(world).changeEmblem(this.id, notifications.get(b), new MapleGuildSummary(this));
} else {
Server.getInstance().getWorld(world).sendPacket(notifications.get(b), packet, exceptionId);
membersLock.lock(); // membersLock awareness thanks to ProjectNano dev team
try {
synchronized (notifications) {
if (bDirty) {
buildNotifications();
}
try {
for (Integer b : Server.getInstance().getOpenChannels(world)) {
if (notifications.get(b).size() > 0) {
if (bcop == BCOp.DISBAND) {
Server.getInstance().getWorld(world).setGuildAndRank(notifications.get(b), 0, 5, exceptionId);
} else if (bcop == BCOp.EMBLEMCHANGE) {
Server.getInstance().getWorld(world).changeEmblem(this.id, notifications.get(b), new MapleGuildSummary(this));
} else {
Server.getInstance().getWorld(world).sendPacket(notifications.get(b), packet, exceptionId);
}
}
}
} catch (Exception re) {
re.printStackTrace();
System.out.println("Failed to contact channel(s) for broadcast.");//fu?
}
} catch (Exception re) {
re.printStackTrace();
System.out.println("Failed to contact channel(s) for broadcast.");//fu?
}
} finally {
membersLock.unlock();
}
}