Login Purification + Optimized currenttime calls + Standardized WZ

Repelled ultimately the game-breaking issue that was introduced recently on the revamp of the login phase.
Optimized the getcurrenttime calls to the OS. Made most of the handler calls fetch directly from the Server object instead, the Server itself delegated with periodically updating the current time value. The result is an slightly delayed currenttime, backed with realtime value update within minutes.
Protected concurrently inventory sort handlers. Expected no more NullPointers from the sorting feature.
Added a server flag to limit cash items being sold on player shops/hired merchants.
Stabilized the MapleTV mechanics, and activities properly split by world.
Normalized Character.wz: equipments supposed to have the "cash" property now implements it.
Normalized String.wz: every item that doesn't have a "name" property now implements it.
Normalized the XMLs that lost indentation on the last source update.
New tool: MapleInvalidItemWithNoNameFetcher. Fetches and reports itemids throughout the XMLs that doesn't contain the "name" property and equipments that lacks "cash" property.

Frolic Omniknight references aside, if you have run into any more issues regarding the new login system, please open an issue and show the steps you've done to reach the problem.
This commit is contained in:
ronancpl
2018-07-18 13:00:53 -03:00
parent ad812de001
commit f439c158e2
252 changed files with 93423 additions and 1459 deletions

View File

@@ -199,7 +199,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
private int expRate = 1, mesoRate = 1, dropRate = 1, expCoupon = 1, mesoCoupon = 1, dropCoupon = 1;
private int omokwins, omokties, omoklosses, matchcardwins, matchcardties, matchcardlosses;
private int owlSearch;
private long lastfametime, lastUsedCashItem, lastHealed, lastBuyback = 0, lastDeathtime, lastMesoDrop = -1, jailExpiration = -1;
private long lastfametime, lastUsedCashItem, lastExpression = 0, lastHealed, lastBuyback = 0, lastDeathtime, lastMesoDrop = -1, jailExpiration = -1;
private transient int localmaxhp, localmaxmp, localstr, localdex, localluk, localint_, magic, watk;
private boolean hidden, canDoor = true, berserk, hasMerchant, hasSandboxItem = false, whiteChat = false;
private int linkedLevel = 0;
@@ -2369,7 +2369,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
}
}
private boolean dispelSkills(int skillid) {
private static boolean dispelSkills(int skillid) {
switch (skillid) {
case DarkKnight.BEHOLDER:
case FPArchMage.ELQUINES:
@@ -2386,6 +2386,14 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
return false;
}
}
public void changeFaceExpression(int emote) {
long timeNow = Server.getInstance().getCurrentTime();
if(timeNow - lastExpression > 2000) {
lastExpression = timeNow;
client.getChannelServer().registerFaceExpression(map, this, emote);
}
}
private void doHurtHp() {
if (!(this.getInventory(MapleInventoryType.EQUIPPED).findById(getMap().getHPDecProtect()) != null || buffMapProtection())) {

View File

@@ -956,6 +956,7 @@ public class MapleClient {
Server.getInstance().unregisterLoginState(this);
this.session.setAttribute(MapleClient.CLIENT_KEY, null);
this.accountName = null;
this.macs = null;
this.hwid = null;
@@ -1153,6 +1154,10 @@ public class MapleClient {
lock.unlock();
}
public boolean trylockClient() {
return lock.tryLock();
}
public void lockEncoder() {
encoderLock.lock();
}
@@ -1356,12 +1361,16 @@ public class MapleClient {
this.sessionId = sessionId;
}
public boolean canRequestCharlist(){
return lastNpcClick + 877 < Server.getInstance().getCurrentTime();
}
public boolean canClickNPC(){
return lastNpcClick + 500 < System.currentTimeMillis();
return lastNpcClick + 500 < Server.getInstance().getCurrentTime();
}
public void setClickedNPC(){
lastNpcClick = System.currentTimeMillis();
lastNpcClick = Server.getInstance().getCurrentTime();
}
public void removeClickedNPC(){

View File

@@ -607,33 +607,40 @@ public class Commands {
case "dex":
case "int":
case "luk":
int amount = (sub.length > 1) ? Integer.parseInt(sub[1]) : player.getRemainingAp();
int remainingAp = player.getRemainingAp();
int amount = (sub.length > 1) ? Math.min(Integer.parseInt(sub[1]), remainingAp) : remainingAp;
boolean str = sub[0].equalsIgnoreCase("str");
boolean Int = sub[0].equalsIgnoreCase("int");
boolean luk = sub[0].equalsIgnoreCase("luk");
boolean dex = sub[0].equalsIgnoreCase("dex");
if (amount > 0 && amount <= player.getRemainingAp() && amount <= 32763 || amount < 0 && amount >= -32763 && Math.abs(amount) + player.getRemainingAp() <= 32767) {
if (str && amount + player.getStr() <= 32767 && amount + player.getStr() >= 4) {
player.setStr(player.getStr() + amount);
player.updateSingleStat(MapleStat.STR, player.getStr());
player.setRemainingAp(player.getRemainingAp() - amount);
player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());
} else if (Int && amount + player.getInt() <= 32767 && amount + player.getInt() >= 4) {
player.setInt(player.getInt() + amount);
player.updateSingleStat(MapleStat.INT, player.getInt());
player.setRemainingAp(player.getRemainingAp() - amount);
player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());
} else if (luk && amount + player.getLuk() <= 32767 && amount + player.getLuk() >= 4) {
player.setLuk(player.getLuk() + amount);
player.updateSingleStat(MapleStat.LUK, player.getLuk());
player.setRemainingAp(player.getRemainingAp() - amount);
player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());
} else if (dex && amount + player.getDex() <= 32767 && amount + player.getDex() >= 4) {
player.setDex(player.getDex() + amount);
player.updateSingleStat(MapleStat.DEX, player.getDex());
player.setRemainingAp(player.getRemainingAp() - amount);
player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());
if (amount > 0 && amount <= remainingAp && amount <= 32763) {
int playerStr = player.getStr();
int playerDex = player.getDex();
int playerInt = player.getInt();
int playerLuk = player.getLuk();
if (str && amount + playerStr <= 32767 && amount + playerStr >= 4) {
player.setStr(playerStr + amount);
player.updateSingleStat(MapleStat.STR, playerStr);
player.setRemainingAp(remainingAp - amount);
player.updateSingleStat(MapleStat.AVAILABLEAP, remainingAp);
} else if (Int && amount + playerInt <= 32767 && amount + playerInt >= 4) {
player.setInt(playerInt + amount);
player.updateSingleStat(MapleStat.INT, playerInt);
player.setRemainingAp(remainingAp - amount);
player.updateSingleStat(MapleStat.AVAILABLEAP, remainingAp);
} else if (luk && amount + playerLuk <= 32767 && amount + playerLuk >= 4) {
player.setLuk(playerLuk + amount);
player.updateSingleStat(MapleStat.LUK, playerLuk);
player.setRemainingAp(remainingAp - amount);
player.updateSingleStat(MapleStat.AVAILABLEAP, remainingAp);
} else if (dex && amount + playerDex <= 32767 && amount + playerDex >= 4) {
player.setDex(playerDex + amount);
player.updateSingleStat(MapleStat.DEX, playerDex);
player.setRemainingAp(remainingAp - amount);
player.updateSingleStat(MapleStat.AVAILABLEAP, remainingAp);
} else {
player.dropMessage("Please make sure the stat you are trying to raise is not over 32,767 or under 4.");
}

View File

@@ -56,7 +56,7 @@ public abstract class CharacterFactory {
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
int top = recipe.getTop(), bottom = recipe.getBottom(), shoes = recipe.getShoes(), weapon = recipe.getWeapon();
if(top > 0) {
Item eq_top = ii.getEquipById(top);
eq_top.setPosition((byte) -5);
@@ -85,7 +85,7 @@ public abstract class CharacterFactory {
return -2;
}
c.announce(MaplePacketCreator.addNewCharEntry(newchar));
Server.getInstance().createCharacterEntry(newchar);
Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.sendYellowTip("[NEW CHAR]: " + c.getAccountName() + " has created a new character with IGN " + name));

View File

@@ -41,7 +41,7 @@ public class BuybackProcessor {
public static void processBuyback(MapleClient c) {
MapleCharacter chr = c.getPlayer();
boolean buyback;
c.lockClient();
try {
buyback = !chr.isAlive() && chr.couldBuyback();

View File

@@ -126,6 +126,11 @@ public final class ItemConstants {
return itemId >= 1110000 && itemId < 1140000;
}
public static boolean isTaming(int itemId) {
int itemType = itemId / 1000;
return itemType == 1902 || itemType == 1912;
}
public static boolean isTownScroll(int itemId) {
return itemId >= 2030000 && itemId < 2030100;
}
@@ -164,7 +169,15 @@ public final class ItemConstants {
public static boolean isPartyAllcure(int itemId) {
return itemId == 2022433;
}
public static boolean isHiredMerchant(int itemId) {
return itemId / 10000 == 503;
}
public static boolean isPlayerShop(int itemId) {
return itemId / 10000 == 514;
}
public static MapleInventoryType getInventoryType(final int itemId) {
if (inventoryTypeCache.containsKey(itemId)) {
return inventoryTypeCache.get(itemId);

View File

@@ -23,7 +23,7 @@ public class ServerConstants {
public static final long PURGING_INTERVAL = 5 * 60 * 1000;
public static final long RANKING_INTERVAL = 60 * 60 * 1000; //60 minutes, 3600000.
public static final long COUPON_INTERVAL = 60 * 60 * 1000; //60 minutes, 3600000.
public static final long UPDATE_INTERVAL = 777;
public static final long UPDATE_INTERVAL = 777; //Dictates the frequency on which the "centralized server time" is updated.
public static final boolean ENABLE_PIC = false; //Pick true/false to enable or disable Pic. Delete character needs this feature ENABLED.
public static final boolean ENABLE_PIN = false; //Pick true/false to enable or disable Pin.
@@ -62,10 +62,12 @@ public class ServerConstants {
public static final boolean USE_AUTOSAVE = true; //Enables server autosaving feature (saves characters to DB each 1 hour).
public static final boolean USE_SERVER_AUTOASSIGNER = true; //HeavenMS-builtin autoassigner, uses algorithm based on distributing AP accordingly with required secondary stat on equipments.
public static final boolean USE_REFRESH_RANK_MOVE = true;
public static final boolean USE_ENFORCE_ADMIN_ACCOUNT = false; //Forces accounts having GM characters to be treated as a "GM account" by the client (localhost). Some of the GM account perks is the ability to FLY, but unable to TRADE.
public static final boolean USE_ENFORCE_HPMP_SWAP = false; //Forces players to reuse stats (via AP Resetting) located on HP/MP pool only inside the HP/MP stats.
public static final boolean USE_ENFORCE_MOB_LEVEL_RANGE = true; //Players N levels below the killed mob will gain no experience from defeating it.
public static final boolean USE_ENFORCE_JOB_LEVEL_RANGE = false;//Caps the player level on the minimum required to advance their current jobs.
public static final boolean USE_ENFORCE_OWL_SUGGESTIONS = false;//Forces the Owl of Minerva to always display the defined item array on GameConstants.OWL_DATA instead of those featured by the players.
public static final boolean USE_ENFORCE_UNMERCHABLE_CASH = true;//Forces players to not sell CASH items via merchants.
public static final boolean USE_ENFORCE_UNMERCHABLE_PET = true; //Forces players to not sell pets via merchants. (since non-named pets gets dirty name and other possible DB-related issues)
public static final boolean USE_ENFORCE_MDOOR_POSITION = false; //Forces mystic door to be spawned near spawnpoints.
public static final boolean USE_ERASE_PERMIT_ON_OPENSHOP = true;//Forces "shop permit" item to be consumed when player deploy his/her player shop.

View File

@@ -1,129 +0,0 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dropspider;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import provider.MapleData;
import provider.MapleDataDirectoryEntry;
import provider.MapleDataFileEntry;
import provider.MapleDataProvider;
import provider.MapleDataProviderFactory;
import provider.MapleDataTool;
import server.MapleItemInformationProvider;
import tools.Pair;
/**
*
* @author Simon
*/
public class DataTool {
private static Map<String, Integer> hardcodedMobs = new HashMap<>();
private static ArrayList<Pair<Integer, String>> npc_list = null;
private static LinkedList<Pair<Integer, String>> mob_pairs = null;
private static MapleDataProvider data = MapleDataProviderFactory.getDataProvider(MapleDataProviderFactory.fileInWZPath("Mob.wz"));
private static HashSet<Integer> bosses = null;
public static void setHardcodedMobNames() {
hardcodedMobs.put("Red Slime [2]", 7120103);
hardcodedMobs.put("Gold Slime", 7120105);
hardcodedMobs.put("Nibelung [3]", 8220015);
}
public static void addMonsterIdsFromHardcodedName(List<Integer> monster_ids, String monster_name) {
Integer id = hardcodedMobs.get(monster_name);
if(id != null) {
monster_ids.add(id);
}
}
public static ArrayList<Integer> monsterIdsFromName(String name) {
MapleData data = null;
MapleDataProvider dataProvider = MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/" + "String.wz"));
ArrayList<Integer> ret = new ArrayList<>();
data = dataProvider.getData("Mob.img");
if (mob_pairs == null) {
mob_pairs = new LinkedList<>();
for (MapleData mobIdData : data.getChildren()) {
int mobIdFromData = Integer.parseInt(mobIdData.getName());
String mobNameFromData = MapleDataTool.getString(mobIdData.getChildByPath("name"), "NO-NAME");
mob_pairs.add(new Pair<>(mobIdFromData, mobNameFromData));
}
}
for (Pair<Integer, String> mobPair : mob_pairs) {
if (mobPair.getRight().toLowerCase().equals(name.toLowerCase())) {
ret.add(mobPair.getLeft());
}
}
return ret;
}
private static void populateBossList() {
bosses = new HashSet<>();
MapleDataDirectoryEntry mob_data = data.getRoot();
for (MapleDataFileEntry mdfe : mob_data.getFiles()) {
MapleData boss_candidate = data.getData(mdfe.getName());
MapleData monsterInfoData = boss_candidate.getChildByPath("info");
int mid = Integer.valueOf(boss_candidate.getName().replaceAll("[^0-9]", ""));
boolean boss = MapleDataTool.getIntConvert("boss", monsterInfoData, 0) > 0 || mid == 8810018 || mid == 9410066;
if (boss) {
bosses.add(mid);
}
}
}
public static boolean isBoss(int mid) {
if (bosses == null) {
populateBossList();
}
return bosses.contains(mid);
}
public static ArrayList<Integer> itemIdsFromName(String name) {
ArrayList<Integer> ret = new ArrayList<>();
for (Pair<Integer, String> itemPair : MapleItemInformationProvider.getInstance().getAllItems()) {
String item_name = itemPair.getRight().toLowerCase().replaceAll("\\&quot;", "");
item_name = item_name.replaceAll("'", "");
item_name = item_name.replaceAll("\\'", "");
name = name.toLowerCase().replaceAll("\\&quot;", "");
name = name.replaceAll("'", "");
name = name.replaceAll("\\'", "");
if (item_name.equals(name)) {
ret.add(itemPair.getLeft());
return ret;
}
}
return ret;
}
public static ArrayList<Integer> npcIdsFromName(String name) {
MapleDataProvider dataProvider = MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/" + "String.wz"));
ArrayList<Integer> ret = new ArrayList<>();
if (npc_list == null) {
ArrayList<Pair<Integer, String>> searchList = new ArrayList<>();
for (MapleData searchData : dataProvider.getData("Npc.img").getChildren()) {
int searchFromData = Integer.parseInt(searchData.getName());
String infoFromData = MapleDataTool.getString(searchData.getChildByPath("name"), "NO-NAME");
searchList.add(new Pair<>(searchFromData, infoFromData));
}
npc_list = searchList;
}
for (Pair<Integer, String> searched : npc_list) {
if (searched.getRight().toLowerCase().contains(name.toLowerCase())) {
ret.add(searched.getLeft());
}
}
return ret;
}
}

View File

@@ -1,177 +0,0 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dropspider;
import client.inventory.MapleInventoryType;
import constants.ItemConstants;
/**
*
* @author Simon
*/
public class DropEntry {
private int version;
private int item_id;
private int monster_id;
private int chance;
private int mindrop;
private int maxdrop;
public DropEntry(int item_id, int monster_id, int version) {
this.item_id = item_id;
this.monster_id = monster_id;
mindrop = 1;
maxdrop = 1;
chance = calculateChance(item_id);
this.version = version;
}
private int calculateChance(int item_id) {
MapleInventoryType mit = ItemConstants.getInventoryType(item_id);
boolean boss = DataTool.isBoss(monster_id);
int number = (item_id / 1000) % 1000;
switch (mit) {
case EQUIP:
if (boss) {
return 40000;
}
return 700;
case USE:
if (boss) {
mindrop = 1;
maxdrop = 4;
}
switch (number) {
case 0: // normal potions
mindrop = 1;
if (version > 98) {
maxdrop = 5;
}
return 40000;
case 1: // watermelons, pills, speed potions, etc
case 2: // same thing
return 10000;
case 3: // advanced potions from crafting (should not drop)
case 4: // same thing
case 11: // poison mushroom
case 28: // cool items
case 30: // return scrolls
case 46: // gallant scrolls
return 0;
case 10: // strange potions like apples, eggs
case 12: // drakes blood, sap of ancient tree (rare use)
case 20: // salad, fried chicken, dews
case 22: // air bubbles and stuff. ALSO nependeath honey but oh well
case 50: // antidotes and stuff
return 3000;
case 290: // mastery books
if(boss)
return 40000;
else
return 1000;
case 40: // Scrolls
case 41: // Scrolls
case 43: // Scrolls
case 44: // Scrolls
case 48: // pet scrolls
if(boss)
return 10000;
else
return 750;
case 100: // summon bags
case 101: // summon bags
case 102: // summon bags
case 109: // summon bags
case 120: // pet food
case 211: // cliffs special potion
case 240: // rings
case 270: // pheromone, additional weird stuff
case 310: // teleport rock
case 320: // weird drops
case 390: // weird
case 430: // Scripted items
case 440: // jukebox
case 460: // magnifying glass
case 470: // golden hammer
case 490: // crystanol
case 500: // sp reset
return 0;
case 47: // tablets from dragon rider
return 220000;
case 49: // clean slats, potential scroll, ees
case 70: // throwing stars
case 210: // rare monster piece drops
case 330: // bullets
if(boss)
return 2500;
else
return 400;
case 60: // bow arrows
case 61: // crossbow arrows
mindrop = 10;
maxdrop = 50;
return 10000;
case 213: // boss transfrom
return 100000;
case 280: // skill books
if(boss)
return 20000;
else
return 1000;
case 381: // monster book things
case 382:
case 383:
case 384:
case 385:
case 386:
case 387:
case 388:
return 20000;
case 510: // recipes
case 511:
case 512:
return 10000;
default:
return 0;
}
case ETC:
switch (number) {
case 0: // monster pieces
return 200000;
case 4: // crystal ores
case 130: // simulators
case 131: // manuals
return 3000;
case 30: // game pieces
return 10000;
case 32: // misc items
return 10000;
default:
return 7000;
}
default:
return 7000;
}
}
public String getQuerySegment() {
StringBuilder sb = new StringBuilder();
sb.append("(");
sb.append(monster_id);
sb.append(", ");
sb.append(item_id);
sb.append(", ");
sb.append(mindrop);//min
sb.append(", ");
sb.append(maxdrop);//max
sb.append(", ");
sb.append(0);//quest
sb.append(", ");
sb.append(chance);
sb.append(")");
return sb.toString();
}
}

View File

@@ -1,19 +0,0 @@
package dropspider;
import java.util.LinkedList;
public class Errors {
public String mobName;
public LinkedList<String> wrong = new LinkedList<>();
public String createErrorLog() {
StringBuilder sb = new StringBuilder();
for (String w : wrong) {
sb.append(mobName).append(" : ").append(w).append("\r\n");
}
return sb.toString();
}
}

View File

@@ -1,329 +0,0 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dropspider;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;
/**
*
* @author Simon
*/
public class Main {
private static ArrayList<DropEntry> drop_entries = new ArrayList<>();
private static HashMap<String, Errors> problems = new HashMap<>();
// private static final String TEST_STRING = " <a href=\"/items/leftover/ligator-skin\" alt=\"/tip.php?nid=2138\">Ligator Skin</a>, <a href=\"/items/leftover/the-magic-rock\" alt=\"/tip.php?nid=3954\">The Magic Rock</a>, <a href=\"/items/quest/witch-grass-leaves\" alt=\"/tip.php?nid=6129\">Witch Grass Leaves</a> </td> ";
private static final String BASE_URL = "http://bbb.hidden-street.net";
private static final int VERSION = 83;
private static String[] pages = {"1-10", "11-20", "21-30", "31-40", "41-50", "51-60", "61-70", "71-80", "81-90", "91-100"};
private static String[] additionalPages88 = {"101-150", "151-200"};
private static String[] additionalPagesBB = {"101-120,", "121-140", "141-160", "161-180", "181-200"};
public static void main(String[] args) {
System.setProperty("wzpath", "wz");
//DataTool.setHardcodedMobNames();
//parsePage("http://bbb.hidden-street.net/monster/nibelung-3");
crawlProgram();
dumpQuery();
dumpErrors();
}
private static void crawlProgram() {
//parseMonsterSection(TEST_STRING);
for (String s : pages) {
crawlPage("http://bbb.hidden-street.net/monster/" + s);
}
if (VERSION > 92) { // big bang
for (String s : additionalPagesBB) {
crawlPage("http://bbb.hidden-street.net/monster/" + s);
}
crawlPage("http://bbb.hidden-street.net/monster/101-120?page=1"); //page 1's bugged
} else {
for (String s : additionalPages88) {
crawlPage("http://bbb.hidden-street.net/monster/" + s);
}
}
}
private static void crawlPage(String url) { //recursive method
try {
URL page = new URL(url);
InputStream is = page.openStream();
Scanner s = new Scanner(is);
String temp_data = "";
while (s.hasNext()) {
temp_data += s.nextLine() + "\n";
}
s.close();
is.close();
while (temp_data.contains("class=\"monster\">")) {
String monster_section = getStringBetween(temp_data, "class=\"monster\">", "</table>");
parseMonsterSection(monster_section);
temp_data = trimUntil(temp_data, "</table>");
}
if (temp_data.contains("Go to next page")) {
String next_url_segment = getStringBetween(temp_data, "<li class=\"pager-next\"><a href=\"", "\" title=\"Go to next page");
String next_url = BASE_URL + next_url_segment;
crawlPage(next_url);
} else {
System.out.println("Finished crawling section.");
}
} catch (MalformedURLException mue) {
mue.printStackTrace();
System.out.println("Error parsing URL: " + url);
return;
} catch (IOException ioe) {
ioe.printStackTrace();
System.out.println("Error reading from URL: " + ioe.getLocalizedMessage());
return;
}
}
private static void parsePage(String url) { //unit method
try {
URL page = new URL(url);
InputStream is = page.openStream();
Scanner s = new Scanner(is);
String temp_data = "";
while (s.hasNext()) {
temp_data += s.nextLine() + "\n";
}
s.close();
is.close();
while (temp_data.contains("class=\"monster\">")) {
String monster_section = getStringBetween(temp_data, "class=\"monster\">", "</table>");
parseMonsterSection(monster_section);
temp_data = trimUntil(temp_data, "</table>");
}
if (temp_data.contains("Go to next page")) {
String next_url_segment = getStringBetween(temp_data, "<li class=\"pager-next\"><a href=\"", "\" title=\"Go to next page");
String next_url = BASE_URL + next_url_segment;
//crawlPage(next_url);
} else {
System.out.println("Finished parsing section.");
}
} catch (MalformedURLException mue) {
mue.printStackTrace();
System.out.println("Error parsing URL: " + url);
return;
} catch (IOException ioe) {
ioe.printStackTrace();
System.out.println("Error reading from URL: " + ioe.getLocalizedMessage());
return;
}
}
private static void parseMonsterSection(String html_data) {
String monster_name = getStringBetween(html_data, "alt=\"", "\" title=");
System.out.println(monster_name);
// System.out.println(html_data);
//parse etc drop
parseItemSection(getStringBetween(html_data, "Etc. drop:</strong>", "</td>"), monster_name);
//parse useable drop
parseItemSection(getStringBetween(html_data, "Useable drop:</strong>", "</td>"), monster_name);
//parse ore drop
parseItemSection(getStringBetween(html_data, "Ore drop:</strong>", "</td>"), monster_name);
//parse equips
parseItemSection(getStringBetween(html_data, "Common equipment:</strong>", "</div>"), monster_name);
parseItemSection(getStringBetween(html_data, "Warrior equipment:</strong>", "</div>"), monster_name);
parseItemSection(getStringBetween(html_data, "Magician equipment:</strong>", "</div>"), monster_name);
parseItemSection(getStringBetween(html_data, "Bowman equipment:</strong>", "</div>"), monster_name);
parseItemSection(getStringBetween(html_data, "Thief equipment:</strong>", "</div>"), monster_name);
parseItemSection(getStringBetween(html_data, "Pirate equipment:</strong>", "</div>"), monster_name);
//System.out.println(monster_name);
}
private static void parseItemSection(String html_data, String monster_name) {
String temp_data = html_data;
while (temp_data.contains("<a href")) {
// System.out.println("Temp_data: " + temp_data);
String s1 = trimUntil(temp_data, ">");
String item_name = getStringBetween(s1, "", "</a>");
temp_data = trimUntil(temp_data, "</a>");
boolean gender_equip = false;
if (item_name.contains("(M)") || item_name.contains("(F)")) {
item_name = item_name.replaceAll("(\\(M\\))|(\\(F\\))", "");
gender_equip = true;
}
item_name = item_name.replaceAll("Throwing-Star", "Throwing-Stars").trim();
item_name = item_name.replaceAll("for Magic Attack", "for Magic Att.").trim();
item_name = item_name.replaceAll("\\(50%\\)", "").trim();
item_name = item_name.replaceAll("\\(70%\\)", "").trim();
item_name = item_name.replaceAll("\\'s", "").trim();
monster_name = monster_name.replaceAll("Horntail\\'s Head B", "Horntail");
// Process scrolls, nexon doesn't have the % on most of the scrolls. So we need to remove it
// Unfortunately they do for some, so we have to handle that too.
boolean scroll = false;
int scrollType = 0;
if(item_name.contains("100%")) {
scroll = true;
item_name = item_name.replaceAll("100%", "").trim();
item_name = item_name.replaceAll("\\(\\)", "").trim(); // Hidden Street has a few scroll %'s with ()s around them.. sigh
} else if(item_name.contains("60%")) {
scroll = true;
scrollType = 1;
item_name = item_name.replaceAll("60%", "").trim();
item_name = item_name.replaceAll("\\(\\)", "").trim();
} else if(item_name.contains("10%")) {
scroll = true;
scrollType = 2;
item_name = item_name.replaceAll("10%", "").trim();
item_name = item_name.replaceAll("\\(\\)", "").trim();
//f(item_name.contains(" ()")) item_name = item_name.substring(0, item_name.lastIndexOf(" ("));
} else if(item_name.contains("70%")) {
scroll = true;
scrollType = 4;
item_name = item_name.replaceAll("70%", "").trim();
item_name = item_name.replaceAll("\\(\\)", "").trim();
} else if(item_name.contains("30%")) {
scroll = true;
scrollType = 5;
item_name = item_name.replaceAll("30%", "").trim();
item_name = item_name.replaceAll("\\(\\)", "").trim();
}
// System.out.println("Item name: " + item_name);
//drop entry
ArrayList<Integer> monster_ids = DataTool.monsterIdsFromName(monster_name);
//DataTool.addMonsterIdsFromHardcodedName(monster_ids, monster_name);
ArrayList<Integer> item_ids = DataTool.itemIdsFromName(item_name);
if(scroll && item_ids.isEmpty()) {
// Try adding on the % again. Thanks nexon...
if(scrollType == 0) item_name += " 100%";
if(scrollType == 1) item_name += " 60%";
if(scrollType == 2) item_name += " 10%";
if(scrollType == 4) item_name += " 70%";
if(scrollType == 5) item_name += " 30%";
item_ids = DataTool.itemIdsFromName(item_name);
}
if (!monster_ids.isEmpty() && !item_ids.isEmpty()) {
int item_id = item_ids.get(0);
if(scroll) {
item_id += scrollType;
}
int item_id_2 = -1;
for (Integer mob_id : monster_ids) {
System.out.println("Monster ID: " + mob_id + ", Item ID: " + item_id);
drop_entries.add(new DropEntry(item_id, mob_id, VERSION));
if (gender_equip && item_ids.size() > 1) {
item_id_2 = item_ids.get(1);
drop_entries.add(new DropEntry(item_id_2, mob_id, VERSION));
}
}
} else {
System.out.println("Error parsing item " + item_name + " dropped by " + monster_name + ".");
if (!monster_ids.isEmpty()) {
if (!problems.containsKey(monster_name)) {
Errors e = new Errors();
e.mobName = monster_name;
problems.put(monster_name, e);
}
problems.get(monster_name).wrong.add(item_name);
}
//System.out.println("Monster ids size: " + monster_ids.size() + ", Item IDs size: " + item_ids.size());
}
}
}
/**
* Returns the string lying between the two specified strings.
*
* @param line The string to parse
* @param start The first string
* @param end The last string
* @return The string between the two specified strings
*/
public static String getStringBetween(String line, String start, String end) {
int start_offset = line.indexOf(start) + start.length();
return line.substring(start_offset, line.substring(start_offset).indexOf(end) + start_offset);
}
public static String trimUntil(String line, String until) {
int until_pos = line.indexOf(until);
if (until_pos == -1) {
return null;
} else {
return line.substring(until_pos + until.length());
}
}
public static void dumpErrors() {
String file = "errors.txt";
try {
File f = new File(file);
BufferedWriter bw = new BufferedWriter(new FileWriter(f));
PrintWriter pw = new PrintWriter(bw);
for (Errors err : problems.values()) {
pw.write(err.createErrorLog());
}
pw.flush();
pw.close();
bw.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void dumpQuery() {
String filename = "drops.sql";
try {
File output = new File(filename);
BufferedWriter bw = new BufferedWriter(new FileWriter(output));
PrintWriter pw = new PrintWriter(bw);
StringBuilder sb = new StringBuilder();
pw.write("TRUNCATE TABLE `drop_data`;\r\n");
pw.write("INSERT INTO `drop_data` (`dropperid`, `itemid`, `minimum_quantity`, `maximum_quantity`, `questid`, `chance`) VALUES ");
for (Iterator<DropEntry> i = drop_entries.iterator(); i.hasNext();) {
DropEntry de = i.next();
pw.write(de.getQuerySegment());
if (i.hasNext()) {
pw.write(", \r\n");
}
}
pw.write(sb.toString());
pw.close();
bw.close();
} catch (IOException ioe) {
ioe.printStackTrace();
System.out.println("Error writing to file: " + ioe.getLocalizedMessage());
}
}
}

View File

@@ -22,10 +22,15 @@
package net;
import client.MapleClient;
import net.server.Server;
public abstract class AbstractMaplePacketHandler implements MaplePacketHandler {
@Override
public boolean validateState(MapleClient c) {
return c.isLoggedIn();
}
protected static long currentServerTime() {
return Server.getInstance().getCurrentTime();
}
}

View File

@@ -114,6 +114,7 @@ public class Server {
private final List<MapleClient> registeredDiseaseAnnouncePlayers = new LinkedList<>();
private final AtomicLong currentTime = new AtomicLong(0);
private long serverCurrentTime = 0;
private boolean availableDeveloperRoom = false;
private boolean online = false;
@@ -126,20 +127,22 @@ public class Server {
return instance;
}
public long getCurrentTime() { // returns a slightly delayed time value, under frequency of UPDATE_INTERVAL
return serverCurrentTime;
}
public void updateCurrentTime() {
currentTime.addAndGet(ServerConstants.UPDATE_INTERVAL);
serverCurrentTime = currentTime.addAndGet(ServerConstants.UPDATE_INTERVAL);
}
public long forceUpdateCurrentTime() {
long timeNow = System.currentTimeMillis();
serverCurrentTime = timeNow;
currentTime.set(timeNow);
return timeNow;
}
public long getCurrentTime() { // returns a slightly delayed time value
return currentTime.get();
}
public boolean isOnline() {
return online;
}
@@ -953,6 +956,34 @@ public class Server {
}
*/
public Pair<Pair<Integer, List<MapleCharacter>>, List<Pair<Integer, List<MapleCharacter>>>> loadAccountCharlist(Integer accountId) {
List<World> wlist = worlds;
List<Pair<Integer, List<MapleCharacter>>> accChars = new ArrayList<>(wlist.size() + 1);
int chrTotal = 0;
List<MapleCharacter> lastwchars = null;
lgnRLock.lock();
try {
for(World w : wlist) {
List<MapleCharacter> wchars = w.getAccountCharactersView(accountId);
if(wchars == null) {
if(!accountChars.containsKey(accountId)) {
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.
lastwchars = wchars;
accChars.add(new Pair<>(w.getId(), wchars));
chrTotal += wchars.size();
}
}
} finally {
lgnRLock.unlock();
}
return new Pair<>(new Pair<>(chrTotal, lastwchars), accChars);
}
private static List<List<MapleCharacter>> loadAccountCharactersViewFromDb(MapleClient c, int wlen) {
List<List<MapleCharacter>> wchars = new ArrayList<>(wlen);
for(int i = 0; i < wlen; i++) wchars.add(i, new LinkedList<MapleCharacter>());
@@ -1003,8 +1034,8 @@ public class Server {
return wchars;
}
public void loadAccountCharactersView(MapleClient c) {
int accId = c.getAccID();
public void loadAccountCharacters(MapleClient c) {
Integer accId = c.getAccID();
int gmLevel = 0;
boolean firstAccountLogin;

View File

@@ -89,6 +89,7 @@ public final class Channel {
private EventScriptManager eventSM;
private MobStatusScheduler mobStatusSchedulers[] = new MobStatusScheduler[4];
private MobAnimationScheduler mobAnimationSchedulers[] = new MobAnimationScheduler[4];
private FaceExpressionScheduler faceExpressionSchedulers[] = new FaceExpressionScheduler[4];
private OverallScheduler channelSchedulers[] = new OverallScheduler[4];
private Map<Integer, MapleHiredMerchant> hiredMerchants = new HashMap<>();
private final Map<Integer, Integer> storedVars = new HashMap<>();
@@ -120,6 +121,8 @@ public final class Channel {
private ReadLock merchRlock = merchantLock.readLock();
private WriteLock merchWlock = merchantLock.writeLock();
private Lock faceLock[] = new MonitoredReentrantLock[4];
private Lock lock = new MonitoredReentrantLock(MonitoredLockType.CHANNEL, true);
public Channel(final int world, final int channel, long startTime) {
@@ -157,8 +160,11 @@ public final class Channel {
}
for(int i = 0; i < 4; i++) {
faceLock[i] = new MonitoredReentrantLock(MonitoredLockType.CHANNEL_FACEEXPRS, true);
mobStatusSchedulers[i] = new MobStatusScheduler();
mobAnimationSchedulers[i] = new MobAnimationScheduler();
faceExpressionSchedulers[i] = new FaceExpressionScheduler(faceLock[i]);
channelSchedulers[i] = new OverallScheduler();
}
@@ -870,6 +876,40 @@ public final class Channel {
channelSchedulers[getChannelSchedulerIndex(mapid)].forceRunDelayedAction(runAction);
}
public void registerFaceExpression(final MapleMap map, final MapleCharacter chr, int emote) {
int lockid = getChannelSchedulerIndex(map.getId());
Runnable cancelAction = new Runnable() {
@Override
public void run() {
if(chr.isLoggedinWorld()) {
map.broadcastMessage(chr, MaplePacketCreator.facialExpression(chr, 0), false);
}
}
};
faceLock[lockid].lock();
try {
if(chr.isLoggedinWorld()) {
faceExpressionSchedulers[lockid].registerFaceExpression(chr.getId(), cancelAction);
map.broadcastMessage(chr, MaplePacketCreator.facialExpression(chr, emote), false);
}
} finally {
faceLock[lockid].unlock();
}
}
public void unregisterFaceExpression(int mapid, MapleCharacter chr) {
int lockid = getChannelSchedulerIndex(mapid);
faceLock[lockid].lock();
try {
faceExpressionSchedulers[lockid].unregisterFaceExpression(chr.getId());
} finally {
faceLock[lockid].unlock();
}
}
public void debugMarriageStatus() {
System.out.println(" ----- WORLD DATA -----");
Server.getInstance().getWorld(world).debugMarriageStatus();

View File

@@ -36,7 +36,7 @@ public class AranComboHandler extends AbstractMaplePacketHandler {
final MapleCharacter player = c.getPlayer();
int skillLevel = player.getSkillLevel(SkillFactory.getSkill(Aran.COMBO_ABILITY));
if (GameConstants.isAran(player.getJob().getId()) && (skillLevel > 0 || player.getJob().getId() == 2000)) {
final long currentTime = System.currentTimeMillis();
final long currentTime = currentServerTime();
short combo = player.getCombo();
if ((currentTime - player.getLastCombo()) > 3000 && combo > 0) {
combo = 0;

View File

@@ -133,7 +133,7 @@ public final class BBSOperationHandler extends AbstractMaplePacketHandler {
ps = con.prepareStatement("INSERT INTO bbs_replies " + "(`threadid`, `postercid`, `timestamp`, `content`) VALUES " + "(?, ?, ?, ?)");
ps.setInt(1, threadid);
ps.setInt(2, c.getPlayer().getId());
ps.setLong(3, System.currentTimeMillis());
ps.setLong(3, currentServerTime());
ps.setString(4, text);
ps.execute();
ps.close();
@@ -157,7 +157,7 @@ public final class BBSOperationHandler extends AbstractMaplePacketHandler {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("UPDATE bbs_threads SET `name` = ?, `timestamp` = ?, " + "`icon` = ?, " + "`startpost` = ? WHERE guildid = ? AND localthreadid = ? AND (postercid = ? OR ?)")) {
ps.setString(1, title);
ps.setLong(2, System.currentTimeMillis());
ps.setLong(2, currentServerTime());
ps.setInt(3, icon);
ps.setString(4, text);
ps.setInt(5, c.getGuildId());
@@ -194,7 +194,7 @@ public final class BBSOperationHandler extends AbstractMaplePacketHandler {
ps = con.prepareStatement("INSERT INTO bbs_threads " + "(`postercid`, `name`, `timestamp`, `icon`, `startpost`, " + "`guildid`, `localthreadid`) " + "VALUES(?, ?, ?, ?, ?, ?, ?)");
ps.setInt(1, c.getId());
ps.setString(2, title);
ps.setLong(3, System.currentTimeMillis());
ps.setLong(3, currentServerTime());
ps.setInt(4, icon);
ps.setString(5, text);
ps.setInt(6, c.getGuildId());

View File

@@ -35,7 +35,7 @@ public final class ChangeMapSpecialHandler extends AbstractMaplePacketHandler {
String startwp = slea.readMapleAsciiString();
slea.readShort();
MaplePortal portal = c.getPlayer().getMap().getPortal(startwp);
if (portal == null || c.getPlayer().portalDelay() > System.currentTimeMillis() || c.getPlayer().getBlockedPortals().contains(portal.getScriptName())) {
if (portal == null || c.getPlayer().portalDelay() > currentServerTime() || c.getPlayer().getBlockedPortals().contains(portal.getScriptName())) {
c.announce(MaplePacketCreator.enableActions());
return;
}

View File

@@ -50,9 +50,9 @@ public final class CloseRangeDamageHandler extends AbstractDealDamageHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
chr.setPetLootCd(System.currentTimeMillis());
chr.setPetLootCd(currentServerTime());
/*long timeElapsed = System.currentTimeMillis() - chr.getAutobanManager().getLastSpam(8);
/*long timeElapsed = currentServerTime() - chr.getAutobanManager().getLastSpam(8);
if(timeElapsed < 300) {
AutobanFactory.FAST_ATTACK.alert(chr, "Time: " + timeElapsed);
}
@@ -115,7 +115,7 @@ public final class CloseRangeDamageHandler extends AbstractDealDamageHandler {
int duration = combo.getEffect(olv).getDuration();
List<Pair<MapleBuffStat, Integer>> stat = Collections.singletonList(new Pair<>(MapleBuffStat.COMBO, neworbcount));
chr.setBuffedValue(MapleBuffStat.COMBO, neworbcount);
duration -= (int) (System.currentTimeMillis() - chr.getBuffedStarttime(MapleBuffStat.COMBO));
duration -= (int) (currentServerTime() - chr.getBuffedStarttime(MapleBuffStat.COMBO));
c.announce(MaplePacketCreator.giveBuff(oid, duration, stat));
chr.getMap().broadcastMessage(chr, MaplePacketCreator.giveForeignBuff(chr.getId(), stat), false);
}
@@ -174,7 +174,7 @@ public final class CloseRangeDamageHandler extends AbstractDealDamageHandler {
return;
} else {
c.announce(MaplePacketCreator.skillCooldown(attack.skill, effect_.getCooldown()));
chr.addCooldown(attack.skill, System.currentTimeMillis(), effect_.getCooldown() * 1000);
chr.addCooldown(attack.skill, currentServerTime(), effect_.getCooldown() * 1000);
}
}
}

View File

@@ -50,7 +50,7 @@ public final class CoconutHandler extends AbstractMaplePacketHandler {
if (event == null){
return;
}
if (System.currentTimeMillis() < nut.getHitTime()){
if (currentServerTime() < nut.getHitTime()){
return;
}
if (nut.getHits() > 2 && Math.random() < 0.4) {

View File

@@ -22,21 +22,32 @@
package net.server.channel.handlers;
import client.MapleClient;
import client.MapleCharacter;
import constants.ItemConstants;
import net.AbstractMaplePacketHandler;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class FaceExpressionHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
int emote = slea.readInt();
if (emote > 7) {
int emoteid = 5159992 + emote;
if (c.getPlayer().getInventory(ItemConstants.getInventoryType(emoteid)).findById(emoteid) == null) {
if (chr.getInventory(ItemConstants.getInventoryType(emoteid)).findById(emoteid) == null) {
return;
}
}
c.getPlayer().getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.facialExpression(c.getPlayer(), emote), false);
if(c.trylockClient()) {
try { // expecting players never intends to wear the emote 0 (default face, that changes back after 5sec timeout)
if (emote != 0 && chr.isLoggedinWorld()) {
chr.changeFaceExpression(emote);
}
} finally {
c.unlockClient();
}
}
}
}

View File

@@ -45,7 +45,7 @@ public final class GeneralChatHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
String s = slea.readMapleAsciiString();
MapleCharacter chr = c.getPlayer();
if(chr.getAutobanManager().getLastSpam(7) + 200 > System.currentTimeMillis()) {
if(chr.getAutobanManager().getLastSpam(7) + 200 > currentServerTime()) {
c.announce(MaplePacketCreator.enableActions());
return;
}

View File

@@ -60,7 +60,7 @@ public final class GuildOperationHandler extends AbstractMaplePacketHandler {
public Invited(String n, int id) {
name = n.toLowerCase();
gid = id;
expiration = System.currentTimeMillis() + 60 * 60 * 1000;
expiration = currentServerTime() + 60 * 60 * 1000;
}
@Override
@@ -81,20 +81,20 @@ public final class GuildOperationHandler extends AbstractMaplePacketHandler {
}
}
private java.util.List<Invited> invited = new java.util.LinkedList<Invited>();
private long nextPruneTime = System.currentTimeMillis() + 20 * 60 * 1000;
private long nextPruneTime = currentServerTime() + 20 * 60 * 1000;
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if (System.currentTimeMillis() >= nextPruneTime) {
if (currentServerTime() >= nextPruneTime) {
Iterator<Invited> itr = invited.iterator();
Invited inv;
while (itr.hasNext()) {
inv = itr.next();
if (System.currentTimeMillis() >= inv.expiration) {
if (currentServerTime() >= inv.expiration) {
itr.remove();
}
}
nextPruneTime = System.currentTimeMillis() + 20 * 60 * 1000;
nextPruneTime = currentServerTime() + 20 * 60 * 1000;
}
MapleCharacter mc = c.getPlayer();
byte type = slea.readByte();

View File

@@ -47,52 +47,57 @@ public final class InventoryMergeHandler extends AbstractMaplePacketHandler {
}
MapleInventory inventory = c.getPlayer().getInventory(inventoryType);
inventory.lockInventory();
try {
//------------------- RonanLana's SLOT MERGER -----------------
//------------------- RonanLana's SLOT MERGER -----------------
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
Item srcItem, dstItem;
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
Item srcItem, dstItem;
for(short dst = 1; dst <= inventory.getSlotLimit(); dst++) {
dstItem = inventory.getItem(dst);
if(dstItem == null) continue;
for(short dst = 1; dst <= inventory.getSlotLimit(); dst++) {
dstItem = inventory.getItem(dst);
if(dstItem == null) continue;
for(short src = (short)(dst + 1); src <= inventory.getSlotLimit(); src++) {
srcItem = inventory.getItem(src);
if(srcItem == null) continue;
for(short src = (short)(dst + 1); src <= inventory.getSlotLimit(); src++) {
srcItem = inventory.getItem(src);
if(srcItem == null) continue;
if(dstItem.getItemId() != srcItem.getItemId()) continue;
if(dstItem.getQuantity() == ii.getSlotMax(c, inventory.getItem(dst).getItemId())) break;
if(dstItem.getItemId() != srcItem.getItemId()) continue;
if(dstItem.getQuantity() == ii.getSlotMax(c, inventory.getItem(dst).getItemId())) break;
MapleInventoryManipulator.move(c, inventoryType, src, dst);
}
}
//------------------------------------------------------------
inventory = c.getPlayer().getInventory(inventoryType);
boolean sorted = false;
while (!sorted) {
short freeSlot = inventory.getNextFreeSlot();
if (freeSlot != -1) {
short itemSlot = -1;
for (short i = (short) (freeSlot + 1); i <= inventory.getSlotLimit(); i = (short) (i + 1)) {
if (inventory.getItem(i) != null) {
itemSlot = i;
break;
}
MapleInventoryManipulator.move(c, inventoryType, src, dst);
}
if (itemSlot > 0) {
MapleInventoryManipulator.move(c, inventoryType, itemSlot, freeSlot);
}
//------------------------------------------------------------
inventory = c.getPlayer().getInventory(inventoryType);
boolean sorted = false;
while (!sorted) {
short freeSlot = inventory.getNextFreeSlot();
if (freeSlot != -1) {
short itemSlot = -1;
for (short i = (short) (freeSlot + 1); i <= inventory.getSlotLimit(); i = (short) (i + 1)) {
if (inventory.getItem(i) != null) {
itemSlot = i;
break;
}
}
if (itemSlot > 0) {
MapleInventoryManipulator.move(c, inventoryType, itemSlot, freeSlot);
} else {
sorted = true;
}
} else {
sorted = true;
}
} else {
sorted = true;
}
} finally {
inventory.unlockInventory();
}
c.announce(MaplePacketCreator.finishedSort(inventoryType.getType()));
c.announce(MaplePacketCreator.enableActions());
}

View File

@@ -199,33 +199,38 @@ public final class InventorySortHandler extends AbstractMaplePacketHandler {
c.disconnect(false, false);
return;
}
MapleInventory inventory = chr.getInventory(MapleInventoryType.getByType(inventoryType));
ArrayList<Item> itemarray = new ArrayList<>();
List<ModifyInventory> mods = new ArrayList<>();
for (short i = 1; i <= inventory.getSlotLimit(); i++) {
Item item = inventory.getItem(i);
if (item != null) {
itemarray.add((Item) item.copy());
MapleInventory inventory = chr.getInventory(MapleInventoryType.getByType(inventoryType));
inventory.lockInventory();
try {
for (short i = 1; i <= inventory.getSlotLimit(); i++) {
Item item = inventory.getItem(i);
if (item != null) {
itemarray.add((Item) item.copy());
}
}
for (Item item : itemarray) {
inventory.removeSlot(item.getPosition());
mods.add(new ModifyInventory(3, item));
}
int invTypeCriteria = (MapleInventoryType.getByType(inventoryType) == MapleInventoryType.EQUIP) ? 3 : 1;
int sortCriteria = (ServerConstants.USE_ITEM_SORT_BY_NAME == true) ? 2 : 0;
PairedQuicksort pq = new PairedQuicksort(itemarray, sortCriteria, invTypeCriteria);
for (Item item : itemarray) {
inventory.addItem(item);
mods.add(new ModifyInventory(0, item.copy()));//to prevent crashes
}
itemarray.clear();
} finally {
inventory.unlockInventory();
}
for (Item item : itemarray) {
inventory.removeSlot(item.getPosition());
mods.add(new ModifyInventory(3, item));
}
int invTypeCriteria = (MapleInventoryType.getByType(inventoryType) == MapleInventoryType.EQUIP) ? 3 : 1;
int sortCriteria = (ServerConstants.USE_ITEM_SORT_BY_NAME == true) ? 2 : 0;
PairedQuicksort pq = new PairedQuicksort(itemarray, sortCriteria, invTypeCriteria);
for (Item item : itemarray) {
inventory.addItem(item);
mods.add(new ModifyInventory(0, item.copy()));//to prevent crashes
}
itemarray.clear();
c.announce(MaplePacketCreator.modifyInventory(true, mods));
c.announce(MaplePacketCreator.finishedSort2(inventoryType));
c.announce(MaplePacketCreator.enableActions());

View File

@@ -36,7 +36,7 @@ public final class ItemMoveHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
slea.skip(4);
if(c.getPlayer().getAutobanManager().getLastSpam(6) + 300 > System.currentTimeMillis()) {
if(c.getPlayer().getAutobanManager().getLastSpam(6) + 300 > currentServerTime()) {
c.announce(MaplePacketCreator.enableActions());
return;
}

View File

@@ -56,7 +56,7 @@ public final class ItemRewardHandler extends AbstractMaplePacketHandler {
if (ItemConstants.getInventoryType(reward.itemid) == MapleInventoryType.EQUIP) {
final Item item = ii.getEquipById(reward.itemid);
if (reward.period != -1) {
item.setExpiration(System.currentTimeMillis() + (reward.period * 60 * 60 * 10));
item.setExpiration(currentServerTime() + (reward.period * 60 * 60 * 10));
}
MapleInventoryManipulator.addFromDrop(c, item, false);
} else {

View File

@@ -39,9 +39,9 @@ public final class MagicDamageHandler extends AbstractDealDamageHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
chr.setPetLootCd(System.currentTimeMillis());
chr.setPetLootCd(currentServerTime());
/*long timeElapsed = System.currentTimeMillis() - chr.getAutobanManager().getLastSpam(8);
/*long timeElapsed = currentServerTime() - chr.getAutobanManager().getLastSpam(8);
if(timeElapsed < 300) {
AutobanFactory.FAST_ATTACK.alert(chr, "Time: " + timeElapsed);
}
@@ -74,7 +74,7 @@ public final class MagicDamageHandler extends AbstractDealDamageHandler {
return;
} else {
c.announce(MaplePacketCreator.skillCooldown(attack.skill, effect_.getCooldown()));
chr.addCooldown(attack.skill, System.currentTimeMillis(), effect_.getCooldown() * 1000);
chr.addCooldown(attack.skill, currentServerTime(), effect_.getCooldown() * 1000);
}
}
applyAttack(attack, chr, effect.getAttackCount());

View File

@@ -26,7 +26,6 @@ import client.MapleClient;
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import net.server.Server;
import server.life.MapleMonster;
import server.life.MapleMonsterInformationProvider;
//import server.life.MobAttackInfo;
@@ -102,7 +101,7 @@ public final class MoveLifeHandler extends AbstractMovementPacketHandler {
toUse = MobSkillFactory.getMobSkill(nextCastSkill, nextCastSkillLevel);
if (!isSkill && !isAttack) {
long curtime = Server.getInstance().getCurrentTime();
long curtime = currentServerTime();
if(curtime >= monster.getNextBasicSkillTime()) { // dont use the special attack too often, chase the player f3
//MobAttackInfo mobAttack = MobAttackInfoFactory.getMobAttackInfo(monster, attackId);
monster.setNextBasicSkillTime(curtime);

View File

@@ -35,7 +35,7 @@ public final class MultiChatHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter player = c.getPlayer();
if(player.getAutobanManager().getLastSpam(7) + 200 > System.currentTimeMillis()) {
if(player.getAutobanManager().getLastSpam(7) + 200 > currentServerTime()) {
return;
}

View File

@@ -41,7 +41,7 @@ public final class NPCTalkHandler extends AbstractMaplePacketHandler {
return;
}
if(System.currentTimeMillis() - c.getPlayer().getNpcCooldown() < ServerConstants.BLOCK_NPC_RACE_CONDT) {
if(currentServerTime() - c.getPlayer().getNpcCooldown() < ServerConstants.BLOCK_NPC_RACE_CONDT) {
c.announce(MaplePacketCreator.enableActions());
return;
}
@@ -53,7 +53,7 @@ public final class NPCTalkHandler extends AbstractMaplePacketHandler {
if(ServerConstants.USE_DEBUG == true) c.getPlayer().dropMessage(5, "Talking to NPC " + npc.getId());
if (npc.getId() == 9010009) { //is duey
c.getPlayer().setNpcCooldown(System.currentTimeMillis());
c.getPlayer().setNpcCooldown(currentServerTime());
DueyProcessor.dueySendTalk(c);
} else {
if (c.getCM() != null || c.getQM() != null) {

View File

@@ -38,7 +38,7 @@ public final class PetFoodHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
AutobanManager abm = chr.getAutobanManager();
if (abm.getLastSpam(2) + 500 > System.currentTimeMillis()) {
if (abm.getLastSpam(2) + 500 > currentServerTime()) {
c.announce(MaplePacketCreator.enableActions());
return;
}

View File

@@ -42,7 +42,7 @@ public final class PetLootHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
if(System.currentTimeMillis() - chr.getPetLootCd() < ServerConstants.PET_LOOT_UPON_ATTACK) {
if(currentServerTime() - chr.getPetLootCd() < ServerConstants.PET_LOOT_UPON_ATTACK) {
c.announce(MaplePacketCreator.enableActions());
return;
}

View File

@@ -201,22 +201,20 @@ public final class PlayerInteractionHandler extends AbstractMaplePacketHandler {
chr.getClient().announce(MaplePacketCreator.getMiniRoomError(6));
return;
}
if (itemId > 5030000 && itemId < 5030012 || itemId > 5140000 && itemId < 5140006) {
if (createType == 4) {
MaplePlayerShop shop = new MaplePlayerShop(chr, desc);
chr.setPlayerShop(shop);
chr.getMap().addMapObject(shop);
shop.sendShop(c);
c.getWorldServer().registerPlayerShop(shop);
//c.announce(MaplePacketCreator.getPlayerShopRemoveVisitor(1));
} else {
MapleHiredMerchant merchant = new MapleHiredMerchant(chr, itemId, desc);
chr.setHiredMerchant(merchant);
c.getWorldServer().registerHiredMerchant(merchant);
chr.getClient().getChannelServer().addHiredMerchant(chr.getId(), merchant);
chr.announce(MaplePacketCreator.getHiredMerchant(chr, merchant, true));
}
if (ItemConstants.isPlayerShop(itemId)) {
MaplePlayerShop shop = new MaplePlayerShop(chr, desc);
chr.setPlayerShop(shop);
chr.getMap().addMapObject(shop);
shop.sendShop(c);
c.getWorldServer().registerPlayerShop(shop);
//c.announce(MaplePacketCreator.getPlayerShopRemoveVisitor(1));
} else if (ItemConstants.isHiredMerchant(itemId)) {
MapleHiredMerchant merchant = new MapleHiredMerchant(chr, itemId, desc);
chr.setHiredMerchant(merchant);
c.getWorldServer().registerHiredMerchant(merchant);
chr.getClient().getChannelServer().addHiredMerchant(chr.getId(), merchant);
chr.announce(MaplePacketCreator.getHiredMerchant(chr, merchant, true));
}
}
} else if (mode == Action.INVITE.getCode()) {
@@ -473,12 +471,18 @@ public final class PlayerInteractionHandler extends AbstractMaplePacketHandler {
FilePrinter.printError(FilePrinter.EXPLOITS + chr.getName() + ".txt", chr.getName() + " might of possibly packet edited Hired Merchants\nperBundle: " + perBundle + "\nperBundle * bundles (This multiplied cannot be greater than 2000): " + perBundle * bundles + "\nbundles: " + bundles + "\nprice: " + price);
return;
}
Item sellItem = ivItem.copy();
if (ServerConstants.USE_ENFORCE_UNMERCHABLE_PET && ItemConstants.isPet(ivItem.getItemId())) {
c.announce(MaplePacketCreator.serverNotice(1, "Pets are not allowed to be sold on the Player Shop."));
if(ServerConstants.USE_ENFORCE_UNMERCHABLE_CASH && MapleItemInformationProvider.getInstance().isCash(ivItem.getItemId())) {
c.announce(MaplePacketCreator.serverNotice(1, "Cash items are not allowed to be sold on the Player Store."));
return;
}
if (ServerConstants.USE_ENFORCE_UNMERCHABLE_PET && ItemConstants.isPet(ivItem.getItemId())) {
c.announce(MaplePacketCreator.serverNotice(1, "Pets are not allowed to be sold on the Player Store."));
return;
}
Item sellItem = ivItem.copy();
if(!ItemConstants.isRechargeable(ivItem.getItemId())) {
sellItem.setQuantity(perBundle);
}

View File

@@ -343,7 +343,7 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
private static List<Pair<Long, PlayerBuffValueHolder>> getLocalStartTimes(List<PlayerBuffValueHolder> lpbvl) {
List<Pair<Long, PlayerBuffValueHolder>> timedBuffs = new ArrayList<>();
long curtime = System.currentTimeMillis();
long curtime = currentServerTime();
for(PlayerBuffValueHolder pb : lpbvl) {
timedBuffs.add(new Pair<>(curtime - pb.usedTime, pb));

View File

@@ -51,9 +51,9 @@ public final class RangedAttackHandler extends AbstractDealDamageHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter chr = c.getPlayer();
chr.setPetLootCd(System.currentTimeMillis());
chr.setPetLootCd(currentServerTime());
/*long timeElapsed = System.currentTimeMillis() - chr.getAutobanManager().getLastSpam(8);
/*long timeElapsed = currentServerTime() - chr.getAutobanManager().getLastSpam(8);
if(timeElapsed < 300) {
AutobanFactory.FAST_ATTACK.alert(chr, "Time: " + timeElapsed);
}
@@ -218,7 +218,7 @@ public final class RangedAttackHandler extends AbstractDealDamageHandler {
return;
} else {
c.announce(MaplePacketCreator.skillCooldown(attack.skill, effect_.getCooldown()));
chr.addCooldown(attack.skill, System.currentTimeMillis(), effect_.getCooldown() * 1000);
chr.addCooldown(attack.skill, currentServerTime(), effect_.getCooldown() * 1000);
}
}
}

View File

@@ -44,10 +44,10 @@ public final class SnowballHandler extends AbstractMaplePacketHandler{
//slea.skip(4);
if (snowball == null || othersnowball == null || snowball.getSnowmanHP() == 0) return;
if ((System.currentTimeMillis() - chr.getLastSnowballAttack()) < 500) return;
if ((currentServerTime() - chr.getLastSnowballAttack()) < 500) return;
if (chr.getTeam() != (what % 2)) return;
chr.setLastSnowballAttack(System.currentTimeMillis());
chr.setLastSnowballAttack(currentServerTime());
int damage = 0;
if (what < 2 && othersnowball.getSnowmanHP() > 0)
damage = 10;

View File

@@ -89,7 +89,7 @@ public final class SpecialMoveHandler extends AbstractMaplePacketHandler {
}
c.announce(MaplePacketCreator.skillCooldown(skillid, cooldownTime));
chr.addCooldown(skillid, System.currentTimeMillis(), cooldownTime * 1000);
chr.addCooldown(skillid, currentServerTime(), cooldownTime * 1000);
}
}
if (skillid == Hero.MONSTER_MAGNET || skillid == Paladin.MONSTER_MAGNET || skillid == DarkKnight.MONSTER_MAGNET) { // Monster Magnet

View File

@@ -67,7 +67,7 @@ public final class UseCashItemHandler extends AbstractMaplePacketHandler {
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
final MapleCharacter player = c.getPlayer();
long timeNow = System.currentTimeMillis();
long timeNow = currentServerTime();
if (timeNow - player.getLastUsedCashItem() < 3000) {
player.dropMessage(1, "You have used a cash item recently. Wait a moment, then try again.");
c.announce(MaplePacketCreator.enableActions());
@@ -310,7 +310,7 @@ public final class UseCashItemHandler extends AbstractMaplePacketHandler {
}
if (period > 0) {
eq.setExpiration(System.currentTimeMillis() + (period * 60 * 60 * 24 * 1000));
eq.setExpiration(currentServerTime() + (period * 60 * 60 * 24 * 1000));
}
remove(c, itemId);
@@ -335,12 +335,13 @@ public final class UseCashItemHandler extends AbstractMaplePacketHandler {
}
} else if (itemType == 507) {
boolean whisper;
switch (itemId / 1000 % 10) {
switch ((itemId / 1000) % 10) {
case 1: // Megaphone
if (player.getLevel() > 9) {
player.getClient().getChannelServer().broadcastPacket(MaplePacketCreator.serverNotice(2, medal + player.getName() + " : " + slea.readMapleAsciiString()));
} else {
player.dropMessage(1, "You may not use this until you're level 10.");
return;
}
break;
case 2: // Super megaphone
@@ -375,15 +376,16 @@ public final class UseCashItemHandler extends AbstractMaplePacketHandler {
messages.add(message);
}
slea.readInt();
if (megassenger) {
Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.serverNotice(3, c.getChannel(), medal + player.getName() + " : " + builder.toString(), ear));
}
if (!MapleTVEffect.isActive()) {
new MapleTVEffect(player, victim, messages, tvType);
} else {
if (!MapleTVEffect.broadcastMapleTVIfNotActive(player, victim, messages, tvType)) {
player.dropMessage(1, "MapleTV is already in use.");
return;
}
if (megassenger) {
Server.getInstance().broadcastMessage(c.getWorld(), MaplePacketCreator.serverNotice(3, c.getChannel(), medal + player.getName() + " : " + builder.toString(), ear));
}
break;
case 6: //item megaphone
String msg = medal + c.getPlayer().getName() + " : " + slea.readMapleAsciiString();

View File

@@ -65,7 +65,7 @@ public final class UseCatchItemHandler extends AbstractMaplePacketHandler {
break;
case 2270001:
if (mob.getId() == 9500197) {
if ((abm.getLastSpam(10) + 1000) < System.currentTimeMillis()) {
if ((abm.getLastSpam(10) + 1000) < currentServerTime()) {
if (mob.getHp() < ((mob.getMaxHp() / 10) * 4)) {
chr.getMap().broadcastMessage(MaplePacketCreator.catchMonster(monsterid, itemId, (byte) 1));
mob.getMap().killMonster(mob, null, false);
@@ -81,7 +81,7 @@ public final class UseCatchItemHandler extends AbstractMaplePacketHandler {
break;
case 2270002:
if (mob.getId() == 9300157) {
if ((abm.getLastSpam(10) + 800) < System.currentTimeMillis()) {
if ((abm.getLastSpam(10) + 800) < currentServerTime()) {
if (mob.getHp() < ((mob.getMaxHp() / 10) * 4)) {
if (Math.random() < 0.5) { // 50% chance
chr.getMap().broadcastMessage(MaplePacketCreator.catchMonster(monsterid, itemId, (byte) 1));
@@ -166,7 +166,7 @@ public final class UseCatchItemHandler extends AbstractMaplePacketHandler {
break;
case 2270008:
if (mob.getId() == 9500336) {
if ((abm.getLastSpam(10) + 3000) < System.currentTimeMillis()) {
if ((abm.getLastSpam(10) + 3000) < currentServerTime()) {
abm.spam(10);
chr.getMap().broadcastMessage(MaplePacketCreator.catchMonster(monsterid, itemId, (byte) 1));
mob.getMap().killMonster(mob, null, false);

View File

@@ -74,7 +74,7 @@ public final class UseItemHandler extends AbstractMaplePacketHandler {
} else if (ItemConstants.isTownScroll(itemId)) {
int banMap = chr.getMapId();
int banSp = chr.getMap().findClosestPlayerSpawnpoint(chr.getPosition()).getId();
long banTime = System.currentTimeMillis();
long banTime = currentServerTime();
if (ii.getItemEffect(toUse.getItemId()).applyTo(chr)) {
if(ServerConstants.USE_BANISHABLE_TOWN_SCROLL) {

View File

@@ -33,7 +33,7 @@ public class UseMapleLifeHandler extends AbstractMaplePacketHandler {
@Override
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleCharacter player = c.getPlayer();
long timeNow = System.currentTimeMillis();
long timeNow = currentServerTime();
if(timeNow - player.getLastUsedCashItem() < 3000) {
player.dropMessage(5, "Please wait a moment before trying again.");

View File

@@ -49,7 +49,7 @@ public final class WhisperHandler extends AbstractMaplePacketHandler {
String recipient = slea.readMapleAsciiString();
String text = slea.readMapleAsciiString();
MapleCharacter player = c.getChannelServer().getPlayerStorage().getCharacterByName(recipient);
if(c.getPlayer().getAutobanManager().getLastSpam(7) + 200 > System.currentTimeMillis()) {
if(c.getPlayer().getAutobanManager().getLastSpam(7) + 200 > currentServerTime()) {
return;
}
if (text.length() > Byte.MAX_VALUE && !player.isGM()) {

View File

@@ -40,6 +40,7 @@ import tools.locks.MonitoredReentrantLock;
public abstract class BaseScheduler {
private int idleProcs = 0;
private List<SchedulerListener> listeners = new LinkedList<>();
private final List<Lock> externalLocks;
private Map<Object, Pair<Runnable, Long>> registeredEntries = new HashMap<>();
private ScheduledFuture<?> schedulerTask = null;
@@ -53,16 +54,43 @@ public abstract class BaseScheduler {
protected BaseScheduler(MonitoredLockType lockType) {
schedulerLock = new MonitoredReentrantLock(lockType, true);
externalLocks = new LinkedList<>();
}
// NOTE: practice EXTREME caution when adding external locks to the scheduler system, if you don't know what you're doing DON'T USE THIS.
protected BaseScheduler(MonitoredLockType lockType, List<Lock> extLocks) {
schedulerLock = new MonitoredReentrantLock(lockType, true);
externalLocks = extLocks;
}
protected void addListener(SchedulerListener listener) {
listeners.add(listener);
}
private void lockScheduler() {
if(!externalLocks.isEmpty()) {
for(Lock l : externalLocks) {
l.lock();
}
}
schedulerLock.lock();
}
private void unlockScheduler() {
if(!externalLocks.isEmpty()) {
for(Lock l : externalLocks) {
l.unlock();
}
}
schedulerLock.unlock();
}
private void runBaseSchedule() {
List<Object> toRemove;
schedulerLock.lock();
lockScheduler();
try {
if(registeredEntries.isEmpty()) {
idleProcs++;
@@ -93,14 +121,14 @@ public abstract class BaseScheduler {
registeredEntries.remove(mse);
}
} finally {
schedulerLock.unlock();
unlockScheduler();
}
dispatchRemovedEntries(toRemove, true);
}
protected void registerEntry(Object key, Runnable removalAction, long duration) {
schedulerLock.lock();
lockScheduler();
try {
idleProcs = 0;
if(schedulerTask == null) {
@@ -109,17 +137,17 @@ public abstract class BaseScheduler {
registeredEntries.put(key, new Pair<>(removalAction, System.currentTimeMillis() + duration));
} finally {
schedulerLock.unlock();
unlockScheduler();
}
}
protected void interruptEntry(Object key) {
schedulerLock.lock();
lockScheduler();
try {
Pair<Runnable, Long> rm = registeredEntries.remove(key);
if(rm != null) rm.getLeft().run();
} finally {
schedulerLock.unlock();
unlockScheduler();
}
dispatchRemovedEntries(Collections.singletonList(key), false);

View File

@@ -0,0 +1,42 @@
/*
This file is part of the HeavenMS MapleStory Server
Copyleft 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.channel.worker;
import java.util.Collections;
import java.util.concurrent.locks.Lock;
import tools.locks.MonitoredLockType;
/**
*
* @author Ronan
*/
public class FaceExpressionScheduler extends BaseScheduler {
public FaceExpressionScheduler(final Lock channelFaceLock) {
super(MonitoredLockType.CHANNEL_FACESCHDL, Collections.singletonList(channelFaceLock));
}
public void registerFaceExpression(Integer characterId, Runnable runAction) {
registerEntry(characterId, runAction, 5000);
}
public void unregisterFaceExpression(Integer characterId) {
interruptEntry(characterId);
}
}

View File

@@ -78,7 +78,7 @@ public final class CreateCharHandler extends AbstractMaplePacketHandler {
int status;
if (job == 0) { // Knights of Cygnus
status = NoblesseCreator.createCharacter(c, name, face, hair + haircolor, skincolor, top, bottom, shoes, weapon, gender);
} else if (job == 1) { // Adventurer
} else if (job == 1) { // Adventurer
status = BeginnerCreator.createCharacter(c, name, face, hair + haircolor, skincolor, top, bottom, shoes, weapon, gender);
} else if (job == 2) { // Aran
status = LegendCreator.createCharacter(c, name, face, hair + haircolor, skincolor, top, bottom, shoes, weapon, gender);

View File

@@ -35,7 +35,7 @@ public final class DeleteCharHandler extends AbstractMaplePacketHandler {
int cid = slea.readInt();
if (c.checkPic(pic)) {
if(c.deleteCharacter(cid, c.getAccID())) {
FilePrinter.printError(FilePrinter.DELETED_CHARACTERS + c.getAccountName() + ".txt", c.getAccountName() + " deleted CID: " + cid + "\r\n");
FilePrinter.print(FilePrinter.DELETED_CHARACTERS + c.getAccountName() + ".txt", c.getAccountName() + " deleted CID: " + cid + "\r\n");
c.announce(MaplePacketCreator.deleteCharResponse(cid, 0));
} else {
c.announce(MaplePacketCreator.deleteCharResponse(cid, 0x14));

View File

@@ -34,6 +34,8 @@ import tools.DatabaseConnection;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
import client.MapleClient;
import java.sql.ResultSet;
import java.sql.Statement;
public final class LoginPasswordHandler implements MaplePacketHandler {
@@ -58,12 +60,17 @@ public final class LoginPasswordHandler implements MaplePacketHandler {
if (ServerConstants.AUTOMATIC_REGISTER && loginok == 5) {
try {
con = DatabaseConnection.getConnection();
ps = con.prepareStatement("INSERT INTO accounts (name, password, birthday, tempban) VALUES (?, ?, ?, ?);"); //Jayd: Added birthday, tempban
ps = con.prepareStatement("INSERT INTO accounts (name, password, birthday, tempban) VALUES (?, ?, ?, ?);", Statement.RETURN_GENERATED_KEYS); //Jayd: Added birthday, tempban
ps.setString(1, login);
ps.setString(2, BCrypt.hashpw(pwd, BCrypt.gensalt(12)));
ps.setString(3, "2018-06-20"); //Jayd: was added to solve the MySQL 5.7 strict checking (birthday)
ps.setString(4, "2018-06-20"); //Jayd: was added to solve the MySQL 5.7 strict checking (tempban)
ps.executeUpdate();
ResultSet rs = ps.getGeneratedKeys();
rs.next();
c.setAccID(rs.getInt(1));
rs.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
@@ -113,9 +120,7 @@ public final class LoginPasswordHandler implements MaplePacketHandler {
}
private static void login(MapleClient c){
Server.getInstance().loadAccountCharactersView(c); // locks the login session until data is recovered from the cache or the DB.
c.announce(MaplePacketCreator.getAuthSuccess(c));//why the fk did I do c.getAccountName()?
Server.getInstance().registerLoginState(c);
}

View File

@@ -34,6 +34,9 @@ public final class ServerlistRequestHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
Server server = Server.getInstance();
server.loadAccountCharacters(c); // locks the login session until data is recovered from the cache or the DB.
c.setClickedNPC();
for (World world : server.getWorlds()) {
c.announce(MaplePacketCreator.getServerList(world.getId(), GameConstants.WORLD_NAMES[world.getId()], world.getFlag(), world.getEventMessage(), world.getChannels()));
}

View File

@@ -24,11 +24,9 @@ package net.server.handlers.login;
import client.MapleCharacter;
import client.MapleClient;
import constants.ServerConstants;
import java.util.ArrayList;
import java.util.List;
import net.AbstractMaplePacketHandler;
import net.server.Server;
import net.server.world.World;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
import tools.Pair;
@@ -37,23 +35,18 @@ public final class ViewAllCharHandler extends AbstractMaplePacketHandler {
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
try {
List<World> wlist = Server.getInstance().getWorlds();
List<Pair<Integer, List<MapleCharacter>>> worldChars = new ArrayList<>(wlist.size() + 1);
int chrTotal = 0;
int accountId = c.getAccID();
List<MapleCharacter> lastwchars = null;
for(World w : wlist) {
List<MapleCharacter> wchars = w.getAccountCharactersView(accountId);
if(!wchars.isEmpty()) {
lastwchars = wchars;
worldChars.add(new Pair<>(w.getId(), wchars));
chrTotal += wchars.size();
}
if(!c.canRequestCharlist()) {
c.announce(MaplePacketCreator.showAllCharacter(0, 0));
return;
}
int accountId = c.getAccID();
Pair<Pair<Integer, List<MapleCharacter>>, List<Pair<Integer, List<MapleCharacter>>>> loginBlob = Server.getInstance().loadAccountCharlist(accountId);
List<Pair<Integer, List<MapleCharacter>>> worldChars = loginBlob.getRight();
int chrTotal = loginBlob.getLeft().getLeft();
List<MapleCharacter> lastwchars = loginBlob.getLeft().getRight();
if (chrTotal > 9) {
int padRight = chrTotal % 3;
if (padRight > 0 && lastwchars != null) {

View File

@@ -322,7 +322,14 @@ public class World {
accountCharsLock.lock();
try {
chrList = new LinkedList<>(accountChars.get(accountId).values());
SortedMap<Integer, MapleCharacter> accChars = accountChars.get(accountId);
if(accChars != null) {
chrList = new LinkedList<>(accChars.values());
} else {
accountChars.put(accountId, new TreeMap<Integer, MapleCharacter>());
chrList = null;
}
} finally {
accountCharsLock.unlock();
}

View File

@@ -1489,7 +1489,12 @@ public class MapleItemInformationProvider {
}
public boolean isCash(int itemId) {
return itemId / 1000000 == 5 || getEquipStats(itemId).get("cash") == 1;
int itemType = itemId / 1000000;
if (itemType == 5) return true;
if (itemType != 1) return false;
Map<String, Integer> eqpStats = getEquipStats(itemId);
return eqpStats != null && eqpStats.get("cash") == 1;
}
public boolean isUpgradeable(int itemId) {

View File

@@ -1066,14 +1066,14 @@ public class MapleMap {
return character;
}
public List<MapleCharacter> getPlayersInRange(Rectangle box, List<MapleCharacter> chr) {
public List<MapleCharacter> getPlayersInRange(Rectangle box, List<MapleCharacter> chrList) {
List<MapleCharacter> character = new LinkedList<>();
chrRLock.lock();
try {
for (MapleCharacter a : characters) {
if (chr.contains(a.getClient().getPlayer())) {
if (box.contains(a.getPosition())) {
character.add(a);
for (MapleCharacter chr : chrList) {
if (characters.contains(chr)) {
if (box.contains(chr.getPosition())) {
character.add(chr);
}
}
}
@@ -2529,6 +2529,9 @@ public class MapleMap {
*/
public void removePlayer(MapleCharacter chr) {
Channel cserv = chr.getClient().getChannelServer();
cserv.unregisterFaceExpression(mapid, chr);
chr.unregisterChairBuff();
chrWLock.lock();
@@ -2540,10 +2543,10 @@ public class MapleMap {
}
if (MapleMiniDungeonInfo.isDungeonMap(mapid)) {
MapleMiniDungeon mmd = chr.getClient().getChannelServer().getMiniDungeon(mapid);
MapleMiniDungeon mmd = cserv.getMiniDungeon(mapid);
if(mmd != null) {
if(!mmd.unregisterPlayer(chr)) {
chr.getClient().getChannelServer().removeMiniDungeon(mapid);
cserv.removeMiniDungeon(mapid);
}
}
}

View File

@@ -22,7 +22,6 @@
package server.maps;
import client.MapleCharacter;
import java.util.ArrayList;
import java.util.List;
import net.server.Server;
import server.TimerManager;
@@ -31,34 +30,28 @@ import tools.MaplePacketCreator;
/*
* MapleTVEffect
* @author MrXotic
* @author Ronan (made MapleTV mechanics synchronous)
*/
public class MapleTVEffect {
private static boolean ACTIVE;
private final static boolean ACTIVE[] = new boolean[Server.getInstance().getWorlds().size()];
private List<String> message = new ArrayList<>(5);
private MapleCharacter user;
private int type;
private MapleCharacter partner;
public MapleTVEffect(MapleCharacter u, MapleCharacter p, List<String> msg, int t) {
this.message = msg;
this.user = u;
this.type = t;
this.partner = p;
broadcastTV(true);
public static synchronized boolean broadcastMapleTVIfNotActive(MapleCharacter player, MapleCharacter victim, List<String> messages, int tvType){
int w = player.getWorld();
if(!ACTIVE[w]) {
broadcastTV(true, w, messages, player, tvType, victim);
return true;
}
return false;
}
public static boolean isActive(){
return ACTIVE;
}
private void broadcastTV(boolean activity) {
private static synchronized void broadcastTV(boolean activity, final int userWorld, List<String> message, MapleCharacter user, int type, MapleCharacter partner) {
Server server = Server.getInstance();
ACTIVE = activity;
if (ACTIVE) {
server.broadcastMessage(user.getWorld(), MaplePacketCreator.enableTV());
server.broadcastMessage(user.getWorld(), MaplePacketCreator.sendTV(user, message, type <= 2 ? type : type - 3, partner));
ACTIVE[userWorld] = activity;
if (activity) {
server.broadcastMessage(userWorld, MaplePacketCreator.enableTV());
server.broadcastMessage(userWorld, MaplePacketCreator.sendTV(user, message, type <= 2 ? type : type - 3, partner));
int delay = 15000;
if (type == 4) {
delay = 30000;
@@ -68,11 +61,11 @@ public class MapleTVEffect {
TimerManager.getInstance().schedule(new Runnable() {
@Override
public void run() {
broadcastTV(false);
broadcastTV(false, userWorld, null, null, -1, null);
}
}, delay);
} else {
server.broadcastMessage(user.getWorld(), MaplePacketCreator.removeTV());
server.broadcastMessage(userWorld, MaplePacketCreator.removeTV());
}
}
}

View File

@@ -684,8 +684,9 @@ public class MaplePacketCreator {
mplew.writeInt(c.getAccID());
mplew.write(c.getGender());
mplew.writeBool(c.getGMLevel() > 1); // thanks Steve(kaito1410) for pointing this out
mplew.write((c.getGMLevel() > 1 && Server.getInstance().canFly(c.getAccID())) ? 0x80 : 0); // Admin Byte. 0x80,0x40,0x20.. Rubbish.
boolean canFly = Server.getInstance().canFly(c.getAccID());
mplew.writeBool((ServerConstants.USE_ENFORCE_ADMIN_ACCOUNT || canFly) ? c.getGMLevel() > 1 : false); // thanks Steve(kaito1410) for pointing the GM account boolean here
mplew.write((c.getGMLevel() > 1 && canFly) ? 0x80 : 0); // Admin Byte. 0x80,0x40,0x20.. Rubbish.
mplew.write(0); // Country Code.
mplew.writeMapleAsciiString(c.getAccountName());

View File

@@ -45,6 +45,8 @@ public enum MonitoredLockType {
SERVER_DISEASES,
MERCHANT,
CHANNEL,
CHANNEL_FACEEXPRS,
CHANNEL_FACESCHDL,
CHANNEL_MOBACTION,
CHANNEL_MOBANIMAT,
CHANNEL_MOBSTATUS,