Trade results + Map-Ownership & Fishing + P. EXP distribution rework

Fixed an issue where players could lose priority over recently dropped items after switching maps.
Adjusted EXP bonus buffs to also cover party bonus gains.
Fixed items taken back from merchants not properly checking for stacking opportunities in player inventory.
Fixed some merchant references in visitors' player object not being properly cleared when owner closes shop.
Adjusted merchants to automatically close as soon as the merchant owner finishes maintenance process with it having no items in store.
Added trade result opcodes. Trade results now should work almost as intended originally.
Implemented server-side check for portal distance when deploying player shops and merchants.
Implemented server-side check for whether local or remote IP is being used when logging in a local/remote server (this should mitigate a few of the issues people may find when trying to log in game world).
Implemented commands designed for management of opened IO sessions.
Fixed chalkboard not showing up for owner player when changing maps.
Added "time left" functionality for merchant owners managing the opened store.
Fixed skillbooks not showing properly for other players in the map.
Fixed commands using lowercased-version of content inputted by player.
Implemented the Fredrick expected fee on using the Store Bank service.
Implemented "exclusive invitation management" in the system. Inviters are notified the invited players are already managing an invite, should it be visually "in-progress" for that one.
Implemented "map ownership". Non-map owners are unable to farm in an area if they are not party members with the owner or until the ownership rescinds.
Adjusted inventory sort feature, now sorting projectile items in such a fashion that commonly stronger versions comes before the basic ones.
Added a visual effect that shows up when obtaining Aran skills.
Revised party EXP gain system. Party bonuses now accounts a fraction of the accumulated EXP gained by members when defeating a mob, and raw EXP gained by a player is kept the same regardless of him/her being in a party or not (thus a bonus being REALLY a bonus).
Implemented a custom fishing system in the source, on which during "seasonal" times (that gets arbitrarily defined by both day-of-year and time-of-day) fishes are more likely to be hooked. Such likelihood also improved depending on the amount of mesos spent as lure.
This commit is contained in:
ronancpl
2019-03-10 01:30:22 -03:00
parent 799870df63
commit 9538c415e1
86 changed files with 2992 additions and 887 deletions

View File

@@ -54,6 +54,7 @@ import java.util.regex.Pattern;
import net.server.PlayerBuffValueHolder;
import net.server.PlayerCoolDownValueHolder;
import net.server.Server;
import net.server.coordinator.MapleInviteCoordinator;
import net.server.guild.MapleAlliance;
import net.server.guild.MapleGuild;
import net.server.guild.MapleGuildCharacter;
@@ -125,6 +126,7 @@ import client.inventory.PetDataFactory;
import client.inventory.manipulator.MapleCashidGenerator;
import client.inventory.manipulator.MapleInventoryManipulator;
import client.newyear.NewYearCardRecord;
import client.processor.FredrickProcessor;
import constants.ExpTable;
import constants.GameConstants;
import constants.ItemConstants;
@@ -167,7 +169,7 @@ import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
public class MapleCharacter extends AbstractMapleCharacterObject {
private static final MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
private static final String LEVEL_200 = "[Congrats] %s has reached Level %d! Congratulate %s on such an amazing achievement!";
private static final String[] BLOCKED_NAMES = {"admin", "owner", "moderator", "intern", "donor", "administrator", "help", "helper", "alert", "notice", "maplestory", "fuck", "wizet", "fucking", "negro", "fuk", "fuc", "penis", "pussy", "asshole", "gay",
private static final String[] BLOCKED_NAMES = {"admin", "owner", "moderator", "intern", "donor", "administrator", "FREDRICK", "help", "helper", "alert", "notice", "maplestory", "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", "yata", "AsiaSoft", "henesys"};
@@ -208,6 +210,7 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
private boolean usedStorage = false;
private String name;
private String chalktext;
private String commandtext;
private String dataString;
private String search = null;
private AtomicBoolean mapTransitioning = new AtomicBoolean(true); // player client is currently trying to change maps or log in the game map
@@ -313,7 +316,7 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
private short extraRecInterval;
private int targetHpBarHash = 0;
private long targetHpBarTime = 0;
private long nextUnderlevelTime = 0;
private long nextWarningTime = 0;
private int banishMap = -1;
private int banishSp = -1;
private long banishTime = 0;
@@ -1055,9 +1058,12 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
gainSp(spGain, GameConstants.getSkillBook(newJob.getId()), true);
}
if (newJob.getId() % 10 > 1) {
// thanks xinyifly for finding out job advancements awarding APs
/*
if (newJob.getId() % 10 >= 1) {
gainAp(5, true);
}
*/
if (!isGM()) {
for (byte i = 1; i < 5; i++) {
@@ -1578,6 +1584,10 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
}
}
}
public void removeIncomingInvites() {
MapleInviteCoordinator.removePlayerIncomingInvites(id);
}
private void changeMapInternal(final MapleMap to, final Point pos, final byte[] warpPacket) {
if(!canWarpMap) return;
@@ -1586,6 +1596,7 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
this.unregisterChairBuff();
this.clearBanishPlayerData();
MapleTrade.cancelTrade(this, MapleTrade.TradeResult.UNSUCCESSFUL_ANOTHER_MAP);
this.closePlayerInteractions();
client.announce(warpPacket);
@@ -1947,6 +1958,16 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
public boolean canHold(int itemid, int quantity) {
return client.getAbstractPlayerInteraction().canHold(itemid, quantity);
}
public boolean canHoldUniques(List<Integer> itemids) {
for (Integer itemid : itemids) {
if (ii.isPickupRestricted(itemid) && this.haveItem(itemid)) {
return false;
}
}
return true;
}
public boolean isRidingBattleship() {
Integer bv = getBuffedValue(MapleBuffStat.MONSTER_RIDING);
@@ -4131,15 +4152,15 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
public int getChair() {
return chair.get();
}
public String getChalkboard() {
return this.chalktext;
}
public MapleClient getClient() {
return client;
}
public final List<MapleQuestStatus> getCompletedQuests() {
synchronized (quests) {
List<MapleQuestStatus> ret = new LinkedList<>();
@@ -4738,6 +4759,32 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
public int getMerchantMeso() {
return merchantmeso;
}
public int getMerchantNetMeso() {
int elapsedDays = 0;
try {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("SELECT `timestamp` FROM `fredstorage` WHERE `cid` = ?")) {
ps.setInt(1, id);
try (ResultSet rs = ps.executeQuery()) {
if (rs.next()) {
elapsedDays = FredrickProcessor.timestampElapsedDays(rs.getTimestamp(1), System.currentTimeMillis());
}
}
}
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
if (elapsedDays > 100) elapsedDays = 100;
int netMeso = (merchantmeso * (100 - elapsedDays)) / 100;
return netMeso;
}
public int getMesosTraded() {
return mesosTraded;
@@ -4980,7 +5027,7 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
}
public void closeTrade() {
MapleTrade.cancelTrade(this);
MapleTrade.cancelTrade(this, MapleTrade.TradeResult.PARTNER_CANCEL);
}
public void closePlayerShop() {
@@ -5024,9 +5071,13 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
MapleHiredMerchant merchant = this.getHiredMerchant();
if(merchant == null) return;
if(closeMerchant) {
merchant.removeVisitor(this);
this.setHiredMerchant(null);
if (closeMerchant) {
if (merchant.isOwner(this) && merchant.getItems().isEmpty()) {
merchant.forceClose();
} else {
merchant.removeVisitor(this);
this.setHiredMerchant(null);
}
} else {
if (merchant.isOwner(this)) {
merchant.setOpen(true);
@@ -5674,6 +5725,10 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
return guildid > 0 && guildRank < 3;
}
public boolean attemptCatchFish(int baitLevel) {
return GameConstants.isFishingArea(mapid) && this.getPosition().getY() > 0 && ItemConstants.isFishingChair(chair.get()) && this.getWorldServer().registerFisherPlayer(this, baitLevel);
}
public void leaveMap() {
releaseControlledMonsters();
visibleMapObjects.clear();
@@ -5681,6 +5736,10 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
if (hpDecreaseTask != null) {
hpDecreaseTask.cancel(false);
}
if (map.unclaimOwnership(this)) {
map.dropMessage(5, "This lawn is now free real estate.");
}
}
private int getChangedJobSp(MapleJob newJob) {
@@ -6950,7 +7009,12 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
}
private void unsitChairInternal() {
if (chair.get() != 0) {
int chairid = chair.get();
if (chairid != 0) {
if (ItemConstants.isFishingChair(chairid)) {
this.getWorldServer().unregisterFisherPlayer(this);
}
setChair(0);
if (unregisterChairBuff()) {
getMap().broadcastMessage(this, MaplePacketCreator.cancelForeignChairSkillEffect(this.getId()), false);
@@ -8085,10 +8149,14 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
}
public void sendNote(String to, String msg, byte fame) throws SQLException {
sendNote(to, this.getName(), msg, fame);
}
public static void sendNote(String to, String from, String msg, byte fame) throws SQLException {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("INSERT INTO notes (`to`, `from`, `message`, `timestamp`, `fame`) VALUES (?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) {
ps.setString(1, to);
ps.setString(2, this.getName());
ps.setString(2, from);
ps.setString(3, msg);
ps.setLong(4, Server.getInstance().getCurrentTime());
ps.setByte(5, fame);
@@ -8262,7 +8330,7 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
}
public synchronized void withdrawMerchantMesos() {
int merchantMeso = this.getMerchantMeso();
int merchantMeso = this.getMerchantNetMeso();
if (merchantMeso > 0) {
int possible = Integer.MAX_VALUE - merchantMeso;
@@ -8275,6 +8343,17 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
this.setMerchantMeso(0);
}
}
} else {
int playerMeso = this.getMeso();
int nextMeso = playerMeso + merchantMeso;
if (nextMeso < 0) {
this.gainMeso(-playerMeso, false);
this.setMerchantMeso(merchantMeso + playerMeso);
} else {
this.gainMeso(merchantMeso, false);
this.setMerchantMeso(0);
}
}
}
@@ -8461,6 +8540,8 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
}
public void changeName(String name) {
FredrickProcessor.removeFredrickReminders(this.getId());
this.name = name;
try {
Connection con = DatabaseConnection.getConnection();
@@ -8830,16 +8911,32 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
}
public void showUnderleveledInfo(MapleMonster mob) {
chrLock.lock();
try {
long curTime = Server.getInstance().getCurrentTime();
if(nextUnderlevelTime < curTime) {
nextUnderlevelTime = curTime + (60 * 1000); // show underlevel info again after 1 minute
showHint("You have gained #rno experience#k from defeating #e#b" + mob.getName() + "#k#n (lv. #b" + mob.getLevel() + "#k)! Take note you must have around the same level as the mob to start earning EXP from it.");
long curTime = Server.getInstance().getCurrentTime();
if(nextWarningTime < curTime) {
nextWarningTime = curTime + (60 * 1000); // show underlevel info again after 1 minute
showHint("You have gained #rno experience#k from defeating #e#b" + mob.getName() + "#k#n (lv. #b" + mob.getLevel() + "#k)! Take note you must have around the same level as the mob to start earning EXP from it.");
}
}
public void showMapOwnershipInfo(MapleCharacter mapOwner) {
long curTime = Server.getInstance().getCurrentTime();
if(nextWarningTime < curTime) {
nextWarningTime = curTime + (60 * 1000); // show underlevel info again after 1 minute
String medal = "";
Item medalItem = mapOwner.getInventory(MapleInventoryType.EQUIPPED).getItem((short) -49);
if (medalItem != null) {
medal = "<" + ii.getName(medalItem.getItemId()) + "> ";
}
} finally {
chrLock.unlock();
List<String> strLines = new LinkedList<>();
strLines.add("");
strLines.add("");
strLines.add("");
strLines.add(this.getClient().getChannelServer().getServerMessage().isEmpty() ? 0 : 1, "Get off my lawn!!");
this.announce(MaplePacketCreator.getAvatarMega(mapOwner, medal, this.getClient().getChannel(), 5390006, strLines, true));
}
}
@@ -9844,6 +9941,14 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
public void removeJailExpirationTime() {
jailExpiration = 0;
}
public String getLastCommandMessage() {
return this.commandtext;
}
public void setLastCommandMessage(String text) {
this.commandtext = text;
}
public int getRewardPoints() {
Connection con = null;

View File

@@ -118,12 +118,18 @@ public class MapleClient {
private final Semaphore actionsSemaphore = new Semaphore(7);
private final Lock lock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.CLIENT, true);
private final Lock encoderLock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.CLIENT_ENCODER, true);
private static final Lock loginLock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.CLIENT_LOGIN, true);
private static final Lock loginLocks[] = new Lock[200]; // thanks Masterrulax & try2hack for pointing out a bottleneck issue here
private int votePoints;
private int voteTime = -1;
private int visibleWorlds;
private long lastNpcClick;
private long sessionId;
static {
for (int i = 0; i < 200; i++) {
loginLocks[i] = MonitoredReentrantLockFactory.createLock(MonitoredLockType.CLIENT_LOGIN, true);
}
}
public MapleClient(MapleAESOFB send, MapleAESOFB receive, IoSession session) {
this.send = send;
@@ -434,6 +440,7 @@ public class MapleClient {
}
public int finishLogin() {
Lock loginLock = loginLocks[this.getAccID() % 200];
loginLock.lock();
try {
if (getLoginState() > LOGIN_NOTLOGGEDIN) { // 0 = LOGIN_NOTLOGGEDIN, 1= LOGIN_SERVER_TRANSITION, 2 = LOGIN_LOGGEDIN
@@ -535,8 +542,15 @@ public class MapleClient {
ps.setString(1, login);
rs = ps.executeQuery();
if (rs.next()) {
boolean banned = (rs.getByte("banned") == 1);
accId = rs.getInt("id");
if (accId == 0) {
// odd case where accId is actually attributed as 0 (further on this leads to getLoginState ACCID = 0, an absurd), thanks Thora for finding this issue
return 15;
} else if (accId < 0) {
FilePrinter.printError(FilePrinter.LOGIN_EXCEPTION, "Tried to login with accid " + accId);
}
boolean banned = (rs.getByte("banned") == 1);
gmlevel = 0;
pin = rs.getString("pin");
pic = rs.getString("pic");
@@ -861,6 +875,7 @@ public class MapleClient {
try {
player.setDisconnectedFromChannelWorld();
player.notifyMapTransferToPartner(-1);
player.removeIncomingInvites();
player.cancelAllBuffs(true);
player.closePlayerInteractions();
@@ -1000,8 +1015,8 @@ public class MapleClient {
MapleSessionCoordinator.getInstance().closeSession(session, false);
session.removeAttribute(MapleClient.CLIENT_KEY);
}
engines.clear();
engines = null; // thanks Tochi for pointing out a NPE here
}
}
@@ -1413,7 +1428,7 @@ public class MapleClient {
}
if (player.getTrade() != null) {
MapleTrade.cancelTrade(getPlayer());
MapleTrade.cancelTrade(getPlayer(), MapleTrade.TradeResult.PARTNER_CANCEL);
}
MapleHiredMerchant merchant = player.getHiredMerchant();
@@ -1429,6 +1444,7 @@ public class MapleClient {
server.getPlayerBuffStorage().addDiseasesToStorage(player.getId(), player.getAllDiseases());
player.setDisconnectedFromChannelWorld();
player.notifyMapTransferToPartner(-1);
player.removeIncomingInvites();
player.cancelAllBuffs(true);
player.cancelAllDebuffs();
player.cancelBuffExpireTask();

View File

@@ -93,8 +93,16 @@ public class CommandsExecutor {
}
private void handleInternal(MapleClient client, String message){
final String[] spitedMessage = message.toLowerCase().substring(1).split("[ ]");
final String commandName = spitedMessage[0];
final String splitRegex = "[ ]";
String[] splitedMessage = message.substring(1).split(splitRegex, 2);
if (splitedMessage.length < 2) {
splitedMessage = new String[]{splitedMessage[0], ""};
}
client.getPlayer().setLastCommandMessage(splitedMessage[1]); // thanks Tochi & Nulliphite for noticing string messages being marshalled lowercase
final String commandName = splitedMessage[0].toLowerCase();
final String[] lowercaseParams = splitedMessage[1].toLowerCase().split(splitRegex);
final RegisteredCommand command = registeredCommands.get(commandName);
if (command == null){
client.getPlayer().yellowMessage("Command '" + commandName + "' is not available. See @commands for a list of available commands.");
@@ -105,8 +113,8 @@ public class CommandsExecutor {
return;
}
String[] params;
if (spitedMessage.length > 1) {
params = Arrays.copyOfRange(spitedMessage, 1, spitedMessage.length);
if (lowercaseParams.length > 0) {
params = Arrays.copyOfRange(lowercaseParams, 0, lowercaseParams.length);
} else {
params = new String[]{};
}
@@ -194,6 +202,7 @@ public class CommandsExecutor {
addCommand("luk", StatLukCommand.class);
addCommand("enableauth", EnableAuthCommand.class);
addCommand("toggleexp", ToggleExpCommand.class);
addCommand("mylawn", MapOwnerClaimCommand.class);
commandsNameDesc.add(levelCommandsCursor);
}
@@ -331,6 +340,7 @@ public class CommandsExecutor {
addCommand("droprate", 4, DropRateCommand.class);
addCommand("questrate", 4, QuestRateCommand.class);
addCommand("travelrate", 4, TravelRateCommand.class);
addCommand("fishrate", 4, FishingRateCommand.class);
addCommand("itemvac", 4, ItemVacCommand.class);
addCommand("forcevac", 4, ForceVacCommand.class);
addCommand("zakum", 4, ZakumCommand.class);
@@ -356,6 +366,8 @@ public class CommandsExecutor {
addCommand("set", 5, SetCommand.class);
addCommand("showpackets", 5, ShowPacketsCommand.class);
addCommand("showmovelife", 5, ShowMoveLifeCommand.class);
addCommand("showsessions", 5, ShowSessionsCommand.class);
addCommand("iplist", 5, IpListCommand.class);
commandsNameDesc.add(levelCommandsCursor);
}

View File

@@ -27,7 +27,6 @@ import client.command.Command;
import client.MapleClient;
import server.MapleItemInformationProvider;
import server.gachapon.MapleGachapon;
import tools.MaplePacketCreator;
public class GachaCommand extends Command {
{
@@ -37,7 +36,7 @@ public class GachaCommand extends Command {
@Override
public void execute(MapleClient c, String[] params) {
MapleGachapon.Gachapon gacha = null;
String search = joinStringFrom(params,0);
String search = c.getPlayer().getLastCommandMessage();
String gachaName = "";
String [] names = {"Henesys", "Ellinia", "Perion", "Kerning City", "Sleepywood", "Mushroom Shrine", "Showa Spa Male", "Showa Spa Female", "New Leaf City", "Nautilus Harbor"};
int [] ids = {9100100, 9100101, 9100102, 9100103, 9100104, 9100105, 9100106, 9100107, 9100109, 9100117};

View File

@@ -50,7 +50,7 @@ public class GmCommand extends Command {
player.dropMessage(5, "Your message was too short. Please provide as much detail as possible.");
return;
}
String message = joinStringFrom(params, 0);
String message = player.getLastCommandMessage();
Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.sendYellowTip("[GM MESSAGE]:" + MapleCharacter.makeMapleReadable(player.getName()) + ": " + message));
Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.serverNotice(1, message));
FilePrinter.printError(FilePrinter.COMMAND_GM, MapleCharacter.makeMapleReadable(player.getName()) + ": " + message);

View File

@@ -0,0 +1,62 @@
/*
This file is part of the HeavenMS MapleStory Server, commands OdinMS-based
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/>.
*/
/*
@Author: Ronan
*/
package client.command.commands.gm0;
import client.command.Command;
import client.MapleCharacter;
import client.MapleClient;
import constants.ServerConstants;
public class MapOwnerClaimCommand extends Command {
{
setDescription("");
}
@Override
public void execute(MapleClient c, String[] params) {
if (c.tryacquireClient()) {
try {
MapleCharacter chr = c.getPlayer();
if (ServerConstants.USE_MAP_OWNERSHIP_SYSTEM) {
if (chr.getEventInstance() == null) {
if (chr.getMap().unclaimOwnership(chr)) {
chr.dropMessage(5, "This lawn is now free real estate.");
} else if (chr.getMap().claimOwnership(chr)) {
chr.dropMessage(5, "You have leased this lawn for a while, until you leave here or after 1 minute of inactivity.");
} else {
chr.dropMessage(5, "This lawn has already been leased by another player.");
}
} else {
chr.dropMessage(5, "This lawn cannot be leased.");
}
} else {
chr.dropMessage(5, "Feature unavailable.");
}
} finally {
c.releaseClient();
}
}
}
}

View File

@@ -43,7 +43,7 @@ public class ReportBugCommand extends Command {
player.dropMessage(5, "Message too short and not sent. Please do @bug <bug>");
return;
}
String message = joinStringFrom(params, 0);
String message = player.getLastCommandMessage();
Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.sendYellowTip("[BUG]:" + MapleCharacter.makeMapleReadable(player.getName()) + ": " + message));
Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.serverNotice(1, message));
FilePrinter.printError(FilePrinter.COMMAND_BUG, MapleCharacter.makeMapleReadable(player.getName()) + ": " + message);

View File

@@ -46,7 +46,7 @@ public class WhatDropsFromCommand extends Command {
player.dropMessage(5, "Please do @whatdropsfrom <monster name>");
return;
}
String monsterName = joinStringFrom(params, 0);
String monsterName = player.getLastCommandMessage();
String output = "";
int limit = 3;
Iterator<Pair<Integer, String>> listIterator = MapleMonsterInformationProvider.getMobsIDsFromName(monsterName).iterator();

View File

@@ -51,7 +51,7 @@ public class WhoDropsCommand extends Command {
if (c.tryacquireClient()) {
try {
String searchString = joinStringFrom(params, 0);
String searchString = player.getLastCommandMessage();
String output = "";
Iterator<Pair<Integer, String>> listIterator = MapleItemInformationProvider.getInstance().getItemDataByName(searchString).iterator();
if(listIterator.hasNext()) {

View File

@@ -36,15 +36,37 @@ public class GiveNxCommand extends Command {
public void execute(MapleClient c, String[] params) {
MapleCharacter player = c.getPlayer();
if (params.length < 1) {
player.yellowMessage("Syntax: !givenx [<playername>] <gainnx>");
player.yellowMessage("Syntax: !givenx [nx, mp, np] [<playername>] <gainnx>");
return;
}
String recv;
int value;
String recv, typeStr = "nx";
int value, type = 1;
if (params.length > 1) {
recv = params[0];
value = Integer.parseInt(params[1]);
if (params[0].length() == 2) {
switch (params[0]) {
case "mp": // maplePoint
type = 2;
break;
case "np": // nxPrepaid
type = 4;
break;
default:
type = 1;
}
typeStr = params[0];
if (params.length > 2) {
recv = params[1];
value = Integer.parseInt(params[2]);
} else {
recv = c.getPlayer().getName();
value = Integer.parseInt(params[1]);
}
} else {
recv = params[0];
value = Integer.parseInt(params[1]);
}
} else {
recv = c.getPlayer().getName();
value = Integer.parseInt(params[0]);
@@ -52,8 +74,8 @@ public class GiveNxCommand extends Command {
MapleCharacter victim = c.getWorldServer().getPlayerStorage().getCharacterByName(recv);
if (victim != null) {
victim.getCashShop().gainCash(1, value);
player.message("NX given.");
victim.getCashShop().gainCash(type, value);
player.message(typeStr.toUpperCase() + " given.");
} else {
player.message("Player '" + recv + "' could not be found.");
}

View File

@@ -57,7 +57,7 @@ public class MusicCommand extends Command {
return;
}
String song = joinStringFrom(params, 0);
String song = player.getLastCommandMessage();
for (String s : GameConstants.GAME_SONGS) {
if (s.equalsIgnoreCase(song)) { // thanks Masterrulax for finding an issue here
player.getMap().broadcastMessage(MaplePacketCreator.musicChange(s));

View File

@@ -37,6 +37,6 @@ public class NoticeCommand extends Command {
@Override
public void execute(MapleClient c, String[] params) {
MapleCharacter player = c.getPlayer();
Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.serverNotice(6, "[Notice] " + joinStringFrom(params, 0)));
Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.serverNotice(6, "[Notice] " + player.getLastCommandMessage()));
}
}

View File

@@ -0,0 +1,48 @@
/*
This file is part of the HeavenMS MapleStory Server, commands OdinMS-based
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/>.
*/
/*
@Author: Ronan
*/
package client.command.commands.gm4;
import client.command.Command;
import client.MapleClient;
import client.MapleCharacter;
import tools.MaplePacketCreator;
public class FishingRateCommand extends Command {
{
setDescription("");
}
@Override
public void execute(MapleClient c, String[] params) {
MapleCharacter player = c.getPlayer();
if (params.length < 1) {
player.yellowMessage("Syntax: !fishrate <newrate>");
return;
}
int fishrate = Math.max(Integer.parseInt(params[0]), 1);
c.getWorldServer().setFishingRate(fishrate);
c.getWorldServer().broadcastPacket(MaplePacketCreator.serverNotice(6, "[Rate] Fishing Rate has been changed to " + fishrate + "x."));
}
}

View File

@@ -34,7 +34,7 @@ public class ServerMessageCommand extends Command {
@Override
public void execute(MapleClient c, String[] params) {
//MapleCharacter player = c.getPlayer();
c.getWorldServer().setServerMessage(joinStringFrom(params, 0));
MapleCharacter player = c.getPlayer();
c.getWorldServer().setServerMessage(player.getLastCommandMessage());
}
}

View File

@@ -77,7 +77,7 @@ public class DebugCommand extends Command {
break;
case "packet":
player.getMap().broadcastMessage(MaplePacketCreator.customPacket(joinStringFrom(params, 1)));
//player.getMap().broadcastMessage(MaplePacketCreator.customPacket(joinStringFrom(params, 1)));
break;
case "portal":

View File

@@ -0,0 +1,60 @@
/*
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 client.command.commands.gm5;
import java.util.Collection;
import client.MapleClient;
import client.MapleCharacter;
import client.command.Command;
import constants.GameConstants;
import net.server.Server;
import net.server.world.World;
/**
*
* @author Mist
* @author Blood (Tochi)
* @author Ronan
*/
public class IpListCommand extends Command {
{
setDescription("");
}
@Override
public void execute(MapleClient c, String[] params) {
String str = "Player-IP relation:";
for (World w : Server.getInstance().getWorlds()) {
Collection<MapleCharacter> chars = w.getPlayerStorage().getAllCharacters();
if (!chars.isEmpty()) {
str += "\r\n" + GameConstants.WORLD_NAMES[w.getId()] + "\r\n";
for (MapleCharacter chr : chars) {
str += " " + chr.getName() + " - " + chr.getClient().getSession().getRemoteAddress() + "\r\n";
}
}
}
c.getAbstractPlayerInteraction().npcTalk(22000, str);
}
}

View File

@@ -0,0 +1,39 @@
/*
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 client.command.commands.gm5;
import client.MapleClient;
import client.command.Command;
import net.server.coordinator.MapleSessionCoordinator;
/**
*
* @author Ronan
*/
public class ShowSessionsCommand extends Command {
{
setDescription("");
}
@Override
public void execute(MapleClient c, String[] params) {
MapleSessionCoordinator.getInstance().printSessionTrace(c);
}
}

View File

@@ -28,10 +28,10 @@ import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Lock;
import tools.DatabaseConnection;
import tools.Pair;
import net.server.audit.locks.MonitoredLockType;
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
import tools.DatabaseConnection;
import tools.Pair;
/**
*
@@ -48,8 +48,14 @@ public enum ItemFactory {
CASH_OVERALL(7, true);
private final int value;
private final boolean account;
private static final Lock lock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.ITEM, true);
private static final Lock locks[] = new Lock[200]; // thanks Masterrulax for pointing out a bottleneck issue here
static {
for (int i = 0; i < 200; i++) {
locks[i] = MonitoredReentrantLockFactory.createLock(MonitoredLockType.ITEM, true);
}
}
private ItemFactory(int value, boolean account) {
this.value = value;
this.account = account;
@@ -192,6 +198,7 @@ public enum ItemFactory {
PreparedStatement pse = null;
ResultSet rs = null;
Lock lock = locks[id % 200];
lock.lock();
try {
StringBuilder query = new StringBuilder();
@@ -357,6 +364,7 @@ public enum ItemFactory {
PreparedStatement pse = null;
ResultSet rs = null;
Lock lock = locks[id % 200];
lock.lock();
try {
ps = con.prepareStatement("DELETE FROM `inventorymerchant` WHERE `characterid` = ?");

View File

@@ -435,8 +435,8 @@ public class MapleInventory implements Iterable<Item> {
}
}
public static boolean checkSpot(MapleCharacter chr, Item item) {
return !chr.getInventory(item.getInventoryType()).isFull();
public static boolean checkSpot(MapleCharacter chr, Item item) { // thanks Vcoc for noticing pshops not checking item stacks when taking item back
return checkSpotsAndOwnership(chr, Collections.singletonList(new Pair<>(item, item.getInventoryType())));
}
public static boolean checkSpots(MapleCharacter chr, List<Pair<Item, MapleInventoryType>> items) {

View File

@@ -31,9 +31,16 @@ import client.inventory.MapleInventory;
import client.inventory.MapleInventoryType;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.LinkedList;
import java.util.List;
import client.inventory.manipulator.MapleInventoryManipulator;
import constants.ServerConstants;
import java.util.Collections;
import net.server.Server;
import net.server.world.World;
import server.MapleItemInformationProvider;
import server.maps.MapleHiredMerchant;
import tools.DatabaseConnection;
@@ -43,14 +50,220 @@ import tools.Pair;
/**
*
* @author RonanLana - synchronization of Fredrick modules
* @author RonanLana - synchronization of Fredrick modules & operation results
*/
public class FredrickProcessor {
private static boolean canRetrieveFromFredrick(MapleCharacter chr, List<Pair<Item, MapleInventoryType>> items) {
if (!chr.canHoldMeso(chr.getMerchantMeso())) {
return false;
private static int[] dailyReminders = new int[]{2, 5, 10, 15, 30, 60, 90, Integer.MAX_VALUE};
private static byte canRetrieveFromFredrick(MapleCharacter chr, List<Pair<Item, MapleInventoryType>> items) {
if (!MapleInventory.checkSpotsAndOwnership(chr, items)) {
List<Integer> itemids = new LinkedList<>();
for (Pair<Item, MapleInventoryType> it : items) {
itemids.add(it.getLeft().getItemId());
}
if (chr.canHoldUniques(itemids)) {
return 0x22;
} else {
return 0x20;
}
}
int netMeso = chr.getMerchantNetMeso();
if (netMeso > 0) {
if (!chr.canHoldMeso(netMeso)) {
return 0x1F;
}
} else {
if (chr.getMeso() < -1 * netMeso) {
return 0x21;
}
}
return 0x0;
}
public static int timestampElapsedDays(Timestamp then, long timeNow) {
return (int) ((timeNow - then.getTime()) / (1000 * 60 * 60 * 24));
}
private static String fredrickReminderMessage(int daynotes) {
String msg;
if (daynotes < 4) {
msg = "Hi customer! I am Fredrick, the Union Chief of the Hired Merchant Union. A reminder that " + dailyReminders[daynotes] + " days have passed since you used our service. Please reclaim your stored goods at FM Entrance.";
} else {
msg = "Hi customer! I am Fredrick, the Union Chief of the Hired Merchant Union. " + dailyReminders[daynotes] + " days have passed since you used our service. Consider claiming back the items before we move them away for refund.";
}
return msg;
}
private static void removeFredrickLog(int cid) {
try {
Connection con = DatabaseConnection.getConnection();
removeFredrickLog(con, cid);
con.close();
} catch (SQLException sqle) {
sqle.printStackTrace();
}
}
private static void removeFredrickLog(Connection con, int cid) throws SQLException {
try (PreparedStatement ps = con.prepareStatement("DELETE FROM `fredstorage` WHERE `cid` = ?")) {
ps.setInt(1, cid);
ps.execute();
}
}
public static void insertFredrickLog(int cid) {
try {
Connection con = DatabaseConnection.getConnection();
removeFredrickLog(con, cid);
try (PreparedStatement ps = con.prepareStatement("INSERT INTO `fredstorage` (`cid`, `daynotes`, `timestamp`) VALUES (?, 0, ?)")) {
ps.setInt(1, cid);
ps.setTimestamp(2, new Timestamp(System.currentTimeMillis()));
ps.execute();
}
con.close();
} catch (SQLException sqle) {
sqle.printStackTrace();
}
}
public static void removeFredrickReminders(int cid) {
removeFredrickReminders(Collections.singletonList(new Pair<>(cid, 0)));
}
private static void removeFredrickReminders(List<Pair<Integer, Integer>> expiredCids) {
List<String> expiredCnames = new LinkedList<>();
for (Pair<Integer, Integer> id : expiredCids) {
String name = MapleCharacter.getNameById(id.getLeft());
if (name != null) {
expiredCnames.add(name);
}
}
try {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("DELETE FROM `notes` WHERE `from` LIKE ? AND `to` LIKE ?")) {
ps.setString(1, "FREDRICK");
for (String cname : expiredCnames) {
ps.setString(2, cname);
ps.executeBatch();
}
}
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void runFredrickSchedule() {
try {
Connection con = DatabaseConnection.getConnection();
List<Pair<Integer, Integer>> expiredCids = new LinkedList<>();
List<Pair<Pair<Integer, String>, Integer>> notifCids = new LinkedList<>();
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM fredstorage f LEFT JOIN (SELECT id, name, world, lastLogoutTime FROM characters) AS c ON c.id = f.cid")) {
try (ResultSet rs = ps.executeQuery()) {
long curTime = System.currentTimeMillis();
while (rs.next()) {
int cid = rs.getInt("cid");
int world = rs.getInt("world");
Timestamp ts = rs.getTimestamp("timestamp");
int daynotes = Math.min(dailyReminders.length - 1, rs.getInt("daynotes"));
int elapsedDays = timestampElapsedDays(ts, curTime);
if (elapsedDays > 100) {
expiredCids.add(new Pair<>(cid, world));
} else {
int notifDay = dailyReminders[daynotes];
if (elapsedDays >= notifDay) {
do {
daynotes++;
notifDay = dailyReminders[daynotes];
} while (elapsedDays >= notifDay);
Timestamp logoutTs = rs.getTimestamp("lastLogoutTime");
int inactivityDays = timestampElapsedDays(logoutTs, curTime);
if (inactivityDays < 7 || daynotes >= dailyReminders.length - 1) { // don't spam inactive players
String name = rs.getString("name");
notifCids.add(new Pair<>(new Pair<>(cid, name), daynotes));
}
}
}
}
}
}
if (!expiredCids.isEmpty()) {
try (PreparedStatement ps = con.prepareStatement("DELETE FROM `inventoryitems` WHERE `type` = ? AND `characterid` = ?")) {
ps.setInt(1, ItemFactory.MERCHANT.getValue());
for (Pair<Integer, Integer> cid : expiredCids) {
ps.setInt(2, cid.getLeft());
ps.addBatch();
}
ps.executeBatch();
}
try (PreparedStatement ps = con.prepareStatement("UPDATE `characters` SET `MerchantMesos` = 0 WHERE `id` = ?")) {
for (Pair<Integer, Integer> cid : expiredCids) {
ps.setInt(1, cid.getLeft());
ps.addBatch();
World wserv = Server.getInstance().getWorld(cid.getRight());
if (wserv != null) {
MapleCharacter chr = wserv.getPlayerStorage().getCharacterById(cid.getLeft());
if (chr != null) {
chr.setMerchantMeso(0);
}
}
}
ps.executeBatch();
}
removeFredrickReminders(expiredCids);
try (PreparedStatement ps = con.prepareStatement("DELETE FROM `fredstorage` WHERE `cid` = ?")) {
for (Pair<Integer, Integer> cid : expiredCids) {
ps.setInt(1, cid.getLeft());
ps.addBatch();
}
ps.executeBatch();
}
}
if (!notifCids.isEmpty()) {
try (PreparedStatement ps = con.prepareStatement("UPDATE `fredstorage` SET `daynotes` = ? WHERE `cid` = ?")) {
for (Pair<Pair<Integer, String>, Integer> cid : notifCids) {
ps.setInt(1, cid.getRight());
ps.setInt(2, cid.getLeft().getLeft());
ps.addBatch();
String msg = fredrickReminderMessage(cid.getRight() - 1);
MapleCharacter.sendNote(cid.getLeft().getRight(), "FREDRICK", msg, (byte) 0);
}
ps.executeBatch();
}
}
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
return MapleInventory.checkSpotsAndOwnership(chr, items);
}
private static boolean deleteFredrickItems(int cid) {
@@ -77,13 +290,15 @@ public class FredrickProcessor {
List<Pair<Item, MapleInventoryType>> items;
try {
items = ItemFactory.MERCHANT.loadItems(chr.getId(), false);
if (!canRetrieveFromFredrick(chr, items)) {
chr.announce(MaplePacketCreator.fredrickMessage((byte) 0x21));
byte response = canRetrieveFromFredrick(chr, items);
if (response != 0) {
chr.announce(MaplePacketCreator.fredrickMessage(response));
return;
}
chr.withdrawMerchantMesos();
if (deleteFredrickItems(chr.getId())) {
MapleHiredMerchant merchant = chr.getHiredMerchant();
@@ -98,6 +313,7 @@ public class FredrickProcessor {
}
chr.announce(MaplePacketCreator.fredrickMessage((byte) 0x1E));
removeFredrickLog(chr.getId());
} else {
chr.message("An unknown error has occured.");
}