Water of Life + Fixed GPQ & Buff system

Added Water of Life. Fixed Shuang (GPQ) npc dc'ing the leader when first
trying to enter the waiting area. Fixed some cases with the revamped
buff system, that would not properly check for the best buffs in some
scenarios, and would throw exceptions, caused by not properly protecting
access to critical data.
This commit is contained in:
ronancpl
2017-09-25 02:16:24 -03:00
parent 7bbf512797
commit 28258530e4
47 changed files with 316 additions and 47 deletions

View File

@@ -151,11 +151,12 @@ import scripting.item.ItemScriptManager;
import server.maps.MapleMapItem;
public class MapleCharacter extends AbstractAnimatedMapleMapObject {
private static NumberFormat nf = new DecimalFormat("#,###,###,###");
private static final String LEVEL_200 = "[Congrats] %s has reached Level 200! Congratulate %s on such an amazing achievement!";
private static final String[] BLOCKED_NAMES = {"admin", "owner", "moderator", "intern", "donor", "administrator", "help", "helper", "alert", "notice", "maplestory", "Solaxia", "fuck", "wizet", "fucking", "negro", "fuk", "fuc", "penis", "pussy", "asshole", "gay",
"nigger", "homo", "suck", "cum", "shit", "shitty", "condom", "security", "official", "rape", "nigga", "sex", "tit", "boner", "orgy", "clit", "asshole", "fatass", "bitch", "support", "gamemaster", "cock", "gaay", "gm",
"operate", "master", "sysop", "party", "GameMaster", "community", "message", "event", "test", "meso", "Scania", "renewal", "yata", "AsiaSoft", "henesys"};
private int world;
private int accountid, id;
private int rank, rankMove, jobRank, jobRankMove;
@@ -260,7 +261,6 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
private Lock chrLock = new ReentrantLock();
private Lock effLock = new ReentrantLock();
private Lock petLock = new ReentrantLock();
private NumberFormat nf = new DecimalFormat("#,###,###,###");
private Map<Integer, Set<Integer>> excluded = new LinkedHashMap<>();
private Set<Integer> excludedItems = new LinkedHashSet<>();
private List<MapleRing> crushRings = new ArrayList<>();
@@ -2095,22 +2095,26 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
@Override
public void run() {
Set<Entry<Integer, Long>> es;
List<MapleBuffStatValueHolder> toCancel = new ArrayList<>();
effLock.lock();
chrLock.lock();
try {
es = new LinkedHashSet<>(buffExpires.entrySet());
long curTime = System.currentTimeMillis();
for(Entry<Integer, Long> bel : es) {
if(curTime >= bel.getValue()) {
toCancel.add(buffEffects.get(bel.getKey()).entrySet().iterator().next().getValue()); //rofl
}
}
} finally {
chrLock.unlock();
effLock.unlock();
}
long curTime = System.currentTimeMillis();
for(Entry<Integer, Long> bel : es) {
if(curTime >= bel.getValue()) {
MapleBuffStatValueHolder mbsvh = buffEffects.get(bel.getKey()).entrySet().iterator().next().getValue(); // rofl
cancelEffect(mbsvh.effect, false, mbsvh.startTime);
}
for(MapleBuffStatValueHolder mbsvh : toCancel) {
cancelEffect(mbsvh.effect, false, mbsvh.startTime);
}
}
}, 1500);
@@ -2181,6 +2185,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
for (MapleInventory inv : inventory) {
for (Item item : inv.list()) {
expiration = item.getExpiration();
if (expiration != -1 && (expiration < currenttime) && ((item.getFlag() & ItemConstants.LOCK) == ItemConstants.LOCK)) {
byte aids = item.getFlag();
aids &= ~(ItemConstants.LOCK);
@@ -2188,10 +2193,15 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
item.setExpiration(-1);
forceUpdateItem(item); //TEST :3
} else if (expiration != -1 && expiration < currenttime) {
client.announce(MaplePacketCreator.itemExpired(item.getItemId()));
toberemove.add(item);
if(ItemConstants.isRateCoupon(item.getItemId())) {
deletedCoupon = true;
if(!ItemConstants.isPet(item.getItemId()) || ServerConstants.USE_ERASE_PET_ON_EXPIRATION) {
client.announce(MaplePacketCreator.itemExpired(item.getItemId()));
toberemove.add(item);
if(ItemConstants.isRateCoupon(item.getItemId())) {
deletedCoupon = true;
}
} else {
item.setExpiration(-1);
forceUpdateItem(item);
}
}
}
@@ -2472,7 +2482,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
effLock.lock();
chrLock.lock();
try {
return buffEffects.keySet();
return new LinkedHashSet<>(buffEffects.keySet());
} finally {
chrLock.unlock();
effLock.unlock();
@@ -2500,12 +2510,14 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
effLock.lock();
chrLock.lock();
try {
long curtime = System.currentTimeMillis();
Map<Integer, PlayerBuffValueHolder> ret = new LinkedHashMap<>();
for(Map<MapleBuffStat, MapleBuffStatValueHolder> bel : buffEffects.values()) {
for(MapleBuffStatValueHolder mbsvh : bel.values()) {
int srcid = mbsvh.effect.getBuffSourceId();
if(!ret.containsKey(srcid)) {
ret.put(srcid, new PlayerBuffValueHolder(mbsvh.startTime, mbsvh.effect));
ret.put(srcid, new PlayerBuffValueHolder((int)(curtime - mbsvh.startTime), mbsvh.effect));
}
}
}
@@ -2826,16 +2838,32 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
chrLock.lock();
try {
Map<Integer, Pair<MapleStatEffect, Long>> retrievedEffects = new LinkedHashMap<>();
Map<MapleBuffStat, Pair<Integer, Integer>> maxStatups = new LinkedHashMap<>();
for(Entry<Integer, Map<MapleBuffStat, MapleBuffStatValueHolder>> bel : buffEffects.entrySet()) {
for(Entry<MapleBuffStat, MapleBuffStatValueHolder> belv : bel.getValue().entrySet()) {
if(removedStats.contains(belv.getKey())) {
retrievedEffects.put(bel.getKey(), new Pair<>(belv.getValue().effect, belv.getValue().startTime));
if(!retrievedEffects.containsKey(bel.getKey())) {
retrievedEffects.put(bel.getKey(), new Pair<>(belv.getValue().effect, belv.getValue().startTime));
}
Pair<Integer, Integer> thisStat = maxStatups.get(belv.getKey());
if(thisStat == null || belv.getValue().value > thisStat.getRight()) {
maxStatups.put(belv.getKey(), new Pair<>(bel.getKey(), belv.getValue().value));
}
}
}
}
for(Entry<Integer, Pair<MapleStatEffect, Long>> lmse: retrievedEffects.entrySet()) {
Map<Integer, Pair<MapleStatEffect, Long>> bestEffects = new LinkedHashMap<>();
for(Entry<MapleBuffStat, Pair<Integer, Integer>> lmse: maxStatups.entrySet()) {
Integer srcid = lmse.getValue().getLeft();
if(!bestEffects.containsKey(srcid)) {
bestEffects.put(srcid, retrievedEffects.get(srcid));
}
}
for(Entry<Integer, Pair<MapleStatEffect, Long>> lmse: bestEffects.entrySet()) {
lmse.getValue().getLeft().updateBuffEffect(this, getActiveStatupsFromSourceid(lmse.getKey()), lmse.getValue().getRight());
}
} finally {
@@ -6933,9 +6961,10 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
setHp(getHp(), true);
}
public void silentGiveBuffs(List<PlayerBuffValueHolder> buffs) {
for (PlayerBuffValueHolder mbsvh : buffs) {
mbsvh.effect.silentApplyBuff(this, mbsvh.startTime);
public void silentGiveBuffs(List<Pair<Long, PlayerBuffValueHolder>> buffs) {
for (Pair<Long, PlayerBuffValueHolder> mbsv : buffs) {
PlayerBuffValueHolder mbsvh = mbsv.getRight();
mbsvh.effect.silentApplyBuff(this, mbsv.getLeft());
}
}

View File

@@ -49,6 +49,7 @@ public class ServerConstants {
public static final boolean USE_REFRESH_RANK_MOVE = true;
public static final boolean USE_ENFORCE_MDOOR_POSITION = true; //Forces mystic door to be spawned near spawnpoints. (since things bugs out other way, and this helps players to locate the door faster)
public static final boolean USE_ERASE_UNTRADEABLE_DROP = true; //Forces flagged untradeable items to disappear when dropped.
public static final boolean USE_ERASE_PET_ON_EXPIRATION = false;//Forces pets to be removed from inventory when expire time comes, rather than converting it to a doll.
public static final boolean USE_BUFF_MOST_SIGNIFICANT = true; //When applying buffs, the player will stick with the highest stat boost among the listed, rather than overwriting stats.
//Server Rates And Experience

View File

@@ -245,6 +245,7 @@ public final class PacketProcessor {
registerHandler(RecvOpcode.MONSTER_CARNIVAL, new MonsterCarnivalHandler());
registerHandler(RecvOpcode.REMOTE_STORE, new RemoteStoreHandler());
registerHandler(RecvOpcode.WEDDING_ACTION, new WeddingHandler());
registerHandler(RecvOpcode.WATER_OF_LIFE, new UseWaterOfLifeHandler());
registerHandler(RecvOpcode.ADMIN_CHAT, new AdminChatHandler());
registerHandler(RecvOpcode.MOVE_DRAGON, new MoveDragonHandler());
}

View File

@@ -116,6 +116,7 @@ public enum RecvOpcode {
USE_ITEM_REWARD(0x70),
MAKER_SKILL(0x71),
USE_REMOTE(0x74),
WATER_OF_LIFE(0x75),
ADMIN_CHAT(0x76),
PARTYCHAT(0x77),
WHISPER(0x78),

View File

@@ -28,11 +28,11 @@ import server.MapleStatEffect;
* @author Danny
*/
public class PlayerBuffValueHolder {
public long startTime;
public int usedTime;
public MapleStatEffect effect;
public PlayerBuffValueHolder(long startTime, MapleStatEffect effect) {
this.startTime = startTime;
public PlayerBuffValueHolder(int usedTime, MapleStatEffect effect) {
this.usedTime = usedTime;
this.effect = effect;
}
}

View File

@@ -41,7 +41,6 @@ public final class CancelBuffHandler extends AbstractMaplePacketHandler implemen
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int sourceid = slea.readInt();
if(sourceid < 0) sourceid = -sourceid; //oh my...
switch (sourceid) {
case FPArchMage.BIG_BANG:

View File

@@ -25,6 +25,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import net.AbstractMaplePacketHandler;
@@ -39,9 +40,11 @@ import net.server.world.PartyOperation;
import net.server.world.World;
import tools.DatabaseConnection;
import tools.MaplePacketCreator;
import tools.Pair;
import tools.data.input.SeekableLittleEndianAccessor;
import client.BuddylistEntry;
import client.CharacterNameAndId;
import client.MapleBuffStat;
import client.MapleCharacter;
import client.MapleClient;
import client.MapleFamily;
@@ -50,6 +53,8 @@ import client.inventory.MapleInventoryType;
import client.inventory.MaplePet;
import constants.GameConstants;
import constants.ServerConstants;
import java.util.Collections;
import java.util.Comparator;
public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
@@ -107,7 +112,8 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
List<PlayerBuffValueHolder> buffs = server.getPlayerBuffStorage().getBuffsFromStorage(cid);
if (buffs != null) {
player.silentGiveBuffs(buffs);
List<Pair<Long, PlayerBuffValueHolder>> timedBuffs = getLocalStartTimes(buffs);
player.silentGiveBuffs(timedBuffs);
}
Connection con = null;
PreparedStatement ps = null;
@@ -286,4 +292,22 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
player.receivePartyMemberHP();
}
private List<Pair<Long, PlayerBuffValueHolder>> getLocalStartTimes(List<PlayerBuffValueHolder> lpbvl) {
List<Pair<Long, PlayerBuffValueHolder>> timedBuffs = new ArrayList<>();
long curtime = System.currentTimeMillis();
for(PlayerBuffValueHolder pb : lpbvl) {
timedBuffs.add(new Pair<>(curtime - pb.usedTime, pb));
}
Collections.sort(timedBuffs, new Comparator<Pair<Long, PlayerBuffValueHolder>>() {
@Override
public int compare(Pair<Long, PlayerBuffValueHolder> p1, Pair<Long, PlayerBuffValueHolder> p2) {
return p1.getLeft().compareTo(p2.getLeft());
}
});
return timedBuffs;
}
}

View File

@@ -0,0 +1,34 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.channel.handlers;
import client.MapleClient;
import net.AbstractMaplePacketHandler;
import tools.data.input.SeekableLittleEndianAccessor;
public final class UseWaterOfLifeHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
c.getAbstractPlayerInteraction().openNpc(1032102, "waterOfLife");
}
}

View File

@@ -901,4 +901,21 @@ public class AbstractPlayerInteraction {
public long getJailTimeLeft() {
return getPlayer().getJailExpirationTimeLeft();
}
public List<MaplePet> getDriedPets() {
List<MaplePet> list = new LinkedList<>();
long curTime = System.currentTimeMillis();
for(Item it : getPlayer().getInventory(MapleInventoryType.CASH).list()) {
if(ItemConstants.isPet(it.getItemId()) && it.getExpiration() < curTime) {
MaplePet pet = it.getPet();
if (pet != null) {
list.add(pet);
}
}
}
return list;
}
}

View File

@@ -978,16 +978,14 @@ public class MapleStatEffect {
Rectangle bounds = new Rectangle(mylt.x, mylt.y, myrb.x - mylt.x, myrb.y - mylt.y);
return bounds;
}
public void silentApplyBuff(MapleCharacter chr, long starttime) {
public void silentApplyBuff(MapleCharacter chr, long localStartTime) {
int localDuration = duration;
localDuration = alchemistModifyVal(chr, localDuration, false);
//CancelEffectAction cancelAction = new CancelEffectAction(chr, this, starttime);
//ScheduledFuture<?> schedule = TimerManager.getInstance().schedule(cancelAction, ((starttime + localDuration) - System.currentTimeMillis()));
if(starttime + localDuration <= System.currentTimeMillis()) return;
chr.registerEffect(this, starttime, (starttime + localDuration), true);
chr.registerEffect(this, localStartTime, localStartTime + localDuration, true);
SummonMovementType summonMovementType = getSummonMovementType();
if (summonMovementType != null) {
final MapleSummon tosummon = new MapleSummon(chr, sourceid, chr.getPosition(), summonMovementType);