diff --git a/L2J_Mobius_1.0_Ertheia/dist/game/config/General.ini b/L2J_Mobius_1.0_Ertheia/dist/game/config/General.ini
index b87d6cfbac..a284270f24 100644
--- a/L2J_Mobius_1.0_Ertheia/dist/game/config/General.ini
+++ b/L2J_Mobius_1.0_Ertheia/dist/game/config/General.ini
@@ -242,8 +242,8 @@ ForceInventoryUpdate = False
# True = Load html's into cache only on first time html is requested.
# False = Load all html's into cache on server startup.
-# Default: True
-LazyCache = True
+# Default: False
+LazyCache = False
# Cache all character names in to memory on server startup
# False - names are loaded from Db when they are requested
diff --git a/L2J_Mobius_1.0_Ertheia/dist/game/config/Server.ini b/L2J_Mobius_1.0_Ertheia/dist/game/config/Server.ini
index 32f67daca1..3208df4a19 100644
--- a/L2J_Mobius_1.0_Ertheia/dist/game/config/Server.ini
+++ b/L2J_Mobius_1.0_Ertheia/dist/game/config/Server.ini
@@ -94,6 +94,9 @@ AcceptAlternateID = True
# Default: .
DatapackRoot = .
+# Scripts root directory.
+ScriptRoot = ./data/scripts
+
# Define how many players are allowed to play simultaneously on your server.
# Default: 2000
MaximumOnlineUsers = 2000
diff --git a/L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java b/L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
index a650883032..0585478f14 100644
--- a/L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
+++ b/L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
@@ -220,7 +220,7 @@ public final class AdminPForge implements IAdminCommandHandler
private void showValuesPage(PlayerInstance activeChar, String[] opCodes, String format)
{
String sendBypass = null;
- String valuesHtml = HtmCache.getInstance().getHtmForce(activeChar, "data/html/admin/pforge/values.htm");
+ String valuesHtml = HtmCache.getInstance().getHtm(activeChar, "data/html/admin/pforge/values.htm");
if (opCodes.length == 3)
{
valuesHtml = valuesHtml.replace("%opformat%", "chd");
diff --git a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/Config.java b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/Config.java
index 6ac7132124..01ad7ace80 100644
--- a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/Config.java
@@ -737,6 +737,7 @@ public final class Config
public static String CLAN_NAME_TEMPLATE;
public static int MAX_CHARACTERS_NUMBER_PER_ACCOUNT;
public static File DATAPACK_ROOT;
+ public static File SCRIPT_ROOT;
public static boolean ACCEPT_ALTERNATE_ID;
public static int REQUEST_ID;
public static boolean RESERVE_HOST_ON_LOGIN = false;
@@ -1232,6 +1233,16 @@ public final class Config
DATAPACK_ROOT = new File(".");
}
+ try
+ {
+ SCRIPT_ROOT = new File(serverSettings.getString("ScriptRoot", "./data/scripts").replaceAll("\\\\", "/")).getCanonicalFile();
+ }
+ catch (Exception e)
+ {
+ LOGGER.log(Level.WARNING, "Error setting script root!", e);
+ SCRIPT_ROOT = new File(".");
+ }
+
Pattern charNamePattern;
try
diff --git a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/cache/HtmCache.java b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/cache/HtmCache.java
index f129626e80..3d8420f5c1 100644
--- a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/cache/HtmCache.java
+++ b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/cache/HtmCache.java
@@ -16,36 +16,31 @@
*/
package com.l2jmobius.gameserver.cache;
+import java.io.BufferedInputStream;
import java.io.File;
-import java.nio.charset.StandardCharsets;
+import java.io.FileInputStream;
import java.util.HashMap;
-import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import com.l2jmobius.Config;
import com.l2jmobius.commons.util.file.filter.HTMLFilter;
import com.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import com.l2jmobius.gameserver.util.BuilderUtil;
-import com.l2jmobius.gameserver.util.Util;
/**
* @author Layane
+ * @author Zoey76
*/
public class HtmCache
{
private static final Logger LOGGER = Logger.getLogger(HtmCache.class.getName());
private static final HTMLFilter HTML_FILTER = new HTMLFilter();
- private static final Pattern EXTEND_PATTERN = Pattern.compile("(.*?)", Pattern.DOTALL);
- private static final Pattern ABSTRACT_BLOCK_PATTERN = Pattern.compile("", Pattern.DOTALL);
- private static final Pattern BLOCK_PATTERN = Pattern.compile("(.*?)", Pattern.DOTALL);
- private static final Map _cache = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
+ private static final Map HTML_CACHE = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
private int _loadedFiles;
private long _bytesBuffLen;
@@ -66,14 +61,14 @@ public class HtmCache
{
LOGGER.info("Html cache start...");
parseDir(f);
- LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded");
+ LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded.");
}
else
{
- _cache.clear();
+ HTML_CACHE.clear();
_loadedFiles = 0;
_bytesBuffLen = 0;
- LOGGER.info("Cache[HTML]: Running lazy cache");
+ LOGGER.info("Cache[HTML]: Running lazy cache.");
}
}
@@ -114,86 +109,65 @@ public class HtmCache
public String loadFile(File file)
{
- if (HTML_FILTER.accept(file))
+ if (!HTML_FILTER.accept(file))
{
- try
+ return null;
+ }
+
+ String content = null;
+ try (FileInputStream fis = new FileInputStream(file);
+ BufferedInputStream bis = new BufferedInputStream(fis))
+ {
+ final int bytes = bis.available();
+ byte[] raw = new byte[bytes];
+
+ bis.read(raw);
+ content = new String(raw, "UTF-8");
+ content = content.replaceAll("(?s)", ""); // Remove html comments
+
+ final String oldContent = HTML_CACHE.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
+ if (oldContent == null)
{
- String content = processHtml(Util.readAllLines(file, StandardCharsets.UTF_8, null));
- content = content.replaceAll("(?s)", ""); // Remove html comments
- // content = content.replaceAll("\r", "").replaceAll("\n", ""); // Remove new lines
-
- final String oldContent = _cache.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
- if (oldContent == null)
- {
- _bytesBuffLen += content.length() * 2;
- _loadedFiles++;
- }
- else
- {
- _bytesBuffLen = (_bytesBuffLen - oldContent.length()) + (content.length() * 2);
- }
- return content;
+ _bytesBuffLen += bytes;
+ _loadedFiles++;
}
- catch (Exception e)
+ else
{
- LOGGER.log(Level.WARNING, "Problem with htm file:", e);
+ _bytesBuffLen = (_bytesBuffLen - oldContent.length()) + bytes;
}
}
- return null;
- }
-
- public String getHtmForce(PlayerInstance player, String path)
- {
- String content = getHtm(player, path);
- if (content == null)
+ catch (Exception e)
{
- content = "My text is missing:
" + path + "";
- LOGGER.warning("Cache[HTML]: Missing HTML page: " + path);
+ LOGGER.log(Level.WARNING, "Problem with htm file:", e);
}
return content;
}
public String getHtm(PlayerInstance player, String path)
{
- final String prefix = player != null ? player.getHtmlPrefix() : "en";
- String newPath = null;
- String content;
- if ((prefix != null) && !prefix.isEmpty())
+ final String prefix = player != null ? player.getHtmlPrefix() : "";
+ final String newPath = prefix + path;
+ String content = HTML_CACHE.get(newPath);
+ if (Config.LAZY_CACHE && (content == null))
{
- newPath = prefix + path;
- content = getHtm(newPath);
- if (content != null)
+ content = loadFile(new File(Config.DATAPACK_ROOT, newPath));
+ if (content == null)
{
- if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
- }
- return content;
+ content = loadFile(new File(Config.SCRIPT_ROOT, newPath));
}
}
- content = getHtm(path);
- if ((content != null) && (newPath != null))
+ if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
{
- _cache.put(newPath, content);
+ BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
}
- if ((player != null) && player.isGM() && (path != null) && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, path.substring(5));
- }
return content;
}
- private String getHtm(String path)
- {
- // TODO: Check why some files do not get in cache on server startup.
- return (path == null) || path.isEmpty() ? "" : _cache.get(path) == null ? loadFile(new File(Config.DATAPACK_ROOT, path)) : _cache.get(path);
- }
-
public boolean contains(String path)
{
- return _cache.containsKey(path);
+ return HTML_CACHE.containsKey(path);
}
/**
@@ -205,88 +179,13 @@ public class HtmCache
return HTML_FILTER.accept(new File(Config.DATAPACK_ROOT, path));
}
- private String parseTemplateName(String name)
- {
- if (!name.startsWith("data/"))
- {
- if (name.startsWith("html/"))
- {
- return "data/" + name;
- }
- else if (name.startsWith("CommunityBoard/"))
- {
- return "data/html/" + name;
- }
- else if (name.startsWith("scripts/"))
- {
- return "data/scripts/" + name;
- }
- }
- return name;
- }
-
- private String processHtml(String result)
- {
- final Matcher extendMatcher = EXTEND_PATTERN.matcher(result);
- if (extendMatcher.find())
- {
- // If extend matcher finds something, process template
- final String templateName = parseTemplateName(extendMatcher.group(1));
-
- // Generate block name -> content map
- final Map blockMap = generateBlockMap(result);
-
- // Attempt to find the template
- String template = getHtm(templateName + "-template.htm");
- if (template != null)
- {
- // Attempt to find the abstract blocks
- final Matcher blockMatcher = ABSTRACT_BLOCK_PATTERN.matcher(template);
- while (blockMatcher.find())
- {
- final String name = blockMatcher.group(1);
- if (!blockMap.containsKey(name))
- {
- LOGGER.warning(getClass().getSimpleName() + ": Abstract block definition [" + name + "] is not implemented!");
- continue;
- }
-
- // Replace the matched content with the block.
- template = template.replace(blockMatcher.group(0), blockMap.get(name));
- }
-
- // Replace the entire extend block
- result = result.replace(extendMatcher.group(0), template);
- }
- else
- {
- LOGGER.warning(getClass().getSimpleName() + ": Missing template: " + templateName + "-template.htm !");
- }
- }
-
- return result;
- }
-
- private Map generateBlockMap(String data)
- {
- final Map blockMap = new LinkedHashMap<>();
- final Matcher blockMatcher = BLOCK_PATTERN.matcher(data);
- while (blockMatcher.find())
- {
- final String name = blockMatcher.group(1);
- final String content = blockMatcher.group(2);
- blockMap.put(name, content);
- }
- return blockMap;
- }
-
public static HtmCache getInstance()
{
- return SingletonHolder._instance;
+ return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
- protected static final HtmCache _instance = new HtmCache();
+ protected static final HtmCache INSTANCE = new HtmCache();
}
}
diff --git a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index d9da6de4e4..0fd63b9018 100644
--- a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -411,7 +411,7 @@ public final class PlayerInstance extends Playable
private Calendar _createDate = Calendar.getInstance();
private String _lang = null;
- private String _htmlPrefix = null;
+ private String _htmlPrefix = "";
private volatile boolean _isOnline = false;
private long _onlineTime;
@@ -12802,7 +12802,7 @@ public final class PlayerInstance extends Playable
{
if (!Config.MULTILANG_ENABLE)
{
- return null;
+ return "";
}
return _htmlPrefix;
@@ -12833,7 +12833,7 @@ public final class PlayerInstance extends Playable
else
{
_lang = null;
- _htmlPrefix = null;
+ _htmlPrefix = "";
}
return result;
diff --git a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/model/quest/Quest.java b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/model/quest/Quest.java
index 039fd732c8..b09ecaf165 100644
--- a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/model/quest/Quest.java
+++ b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/model/quest/Quest.java
@@ -2760,7 +2760,7 @@ public class Quest extends AbstractScript implements IIdentifiable
content = hc.getHtm(player, "data/scripts/" + getPath() + "/" + fileName);
if (content == null)
{
- content = hc.getHtmForce(player, "data/scripts/quests/" + getName() + "/" + fileName);
+ content = hc.getHtm(player, "data/scripts/quests/" + getName() + "/" + fileName);
}
}
return content;
diff --git a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
index 7c6f1f84c2..f3d0215f94 100644
--- a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
+++ b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
@@ -50,7 +50,7 @@ import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
public final class ScriptEngineManager implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
- public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
+ public static final Path SCRIPT_FOLDER = Config.SCRIPT_ROOT.toPath();
public static final Path MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "MasterHandler.java");
public static final Path EFFECT_MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "EffectMasterHandler.java");
public static final Path SKILL_CONDITION_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "SkillConditionMasterHandler.java");
diff --git a/L2J_Mobius_2.5_Underground/dist/game/config/General.ini b/L2J_Mobius_2.5_Underground/dist/game/config/General.ini
index 08b6846b63..aadbfcd534 100644
--- a/L2J_Mobius_2.5_Underground/dist/game/config/General.ini
+++ b/L2J_Mobius_2.5_Underground/dist/game/config/General.ini
@@ -246,8 +246,8 @@ ForceInventoryUpdate = False
# True = Load html's into cache only on first time html is requested.
# False = Load all html's into cache on server startup.
-# Default: True
-LazyCache = True
+# Default: False
+LazyCache = False
# Cache all character names in to memory on server startup
# False - names are loaded from Db when they are requested
diff --git a/L2J_Mobius_2.5_Underground/dist/game/config/Server.ini b/L2J_Mobius_2.5_Underground/dist/game/config/Server.ini
index a392acdde1..a9d82359fb 100644
--- a/L2J_Mobius_2.5_Underground/dist/game/config/Server.ini
+++ b/L2J_Mobius_2.5_Underground/dist/game/config/Server.ini
@@ -94,6 +94,9 @@ AcceptAlternateID = True
# Default: .
DatapackRoot = .
+# Scripts root directory.
+ScriptRoot = ./data/scripts
+
# Define how many players are allowed to play simultaneously on your server.
# Default: 2000
MaximumOnlineUsers = 2000
diff --git a/L2J_Mobius_2.5_Underground/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java b/L2J_Mobius_2.5_Underground/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
index a650883032..0585478f14 100644
--- a/L2J_Mobius_2.5_Underground/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
+++ b/L2J_Mobius_2.5_Underground/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
@@ -220,7 +220,7 @@ public final class AdminPForge implements IAdminCommandHandler
private void showValuesPage(PlayerInstance activeChar, String[] opCodes, String format)
{
String sendBypass = null;
- String valuesHtml = HtmCache.getInstance().getHtmForce(activeChar, "data/html/admin/pforge/values.htm");
+ String valuesHtml = HtmCache.getInstance().getHtm(activeChar, "data/html/admin/pforge/values.htm");
if (opCodes.length == 3)
{
valuesHtml = valuesHtml.replace("%opformat%", "chd");
diff --git a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/Config.java b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/Config.java
index 6aa7f95979..e579f190e0 100644
--- a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/Config.java
@@ -744,6 +744,7 @@ public final class Config
public static String CLAN_NAME_TEMPLATE;
public static int MAX_CHARACTERS_NUMBER_PER_ACCOUNT;
public static File DATAPACK_ROOT;
+ public static File SCRIPT_ROOT;
public static boolean ACCEPT_ALTERNATE_ID;
public static int REQUEST_ID;
public static boolean RESERVE_HOST_ON_LOGIN = false;
@@ -1239,6 +1240,16 @@ public final class Config
DATAPACK_ROOT = new File(".");
}
+ try
+ {
+ SCRIPT_ROOT = new File(serverSettings.getString("ScriptRoot", "./data/scripts").replaceAll("\\\\", "/")).getCanonicalFile();
+ }
+ catch (Exception e)
+ {
+ LOGGER.log(Level.WARNING, "Error setting script root!", e);
+ SCRIPT_ROOT = new File(".");
+ }
+
Pattern charNamePattern;
try
diff --git a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/cache/HtmCache.java b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/cache/HtmCache.java
index f129626e80..3d8420f5c1 100644
--- a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/cache/HtmCache.java
+++ b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/cache/HtmCache.java
@@ -16,36 +16,31 @@
*/
package com.l2jmobius.gameserver.cache;
+import java.io.BufferedInputStream;
import java.io.File;
-import java.nio.charset.StandardCharsets;
+import java.io.FileInputStream;
import java.util.HashMap;
-import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import com.l2jmobius.Config;
import com.l2jmobius.commons.util.file.filter.HTMLFilter;
import com.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import com.l2jmobius.gameserver.util.BuilderUtil;
-import com.l2jmobius.gameserver.util.Util;
/**
* @author Layane
+ * @author Zoey76
*/
public class HtmCache
{
private static final Logger LOGGER = Logger.getLogger(HtmCache.class.getName());
private static final HTMLFilter HTML_FILTER = new HTMLFilter();
- private static final Pattern EXTEND_PATTERN = Pattern.compile("(.*?)", Pattern.DOTALL);
- private static final Pattern ABSTRACT_BLOCK_PATTERN = Pattern.compile("", Pattern.DOTALL);
- private static final Pattern BLOCK_PATTERN = Pattern.compile("(.*?)", Pattern.DOTALL);
- private static final Map _cache = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
+ private static final Map HTML_CACHE = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
private int _loadedFiles;
private long _bytesBuffLen;
@@ -66,14 +61,14 @@ public class HtmCache
{
LOGGER.info("Html cache start...");
parseDir(f);
- LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded");
+ LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded.");
}
else
{
- _cache.clear();
+ HTML_CACHE.clear();
_loadedFiles = 0;
_bytesBuffLen = 0;
- LOGGER.info("Cache[HTML]: Running lazy cache");
+ LOGGER.info("Cache[HTML]: Running lazy cache.");
}
}
@@ -114,86 +109,65 @@ public class HtmCache
public String loadFile(File file)
{
- if (HTML_FILTER.accept(file))
+ if (!HTML_FILTER.accept(file))
{
- try
+ return null;
+ }
+
+ String content = null;
+ try (FileInputStream fis = new FileInputStream(file);
+ BufferedInputStream bis = new BufferedInputStream(fis))
+ {
+ final int bytes = bis.available();
+ byte[] raw = new byte[bytes];
+
+ bis.read(raw);
+ content = new String(raw, "UTF-8");
+ content = content.replaceAll("(?s)", ""); // Remove html comments
+
+ final String oldContent = HTML_CACHE.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
+ if (oldContent == null)
{
- String content = processHtml(Util.readAllLines(file, StandardCharsets.UTF_8, null));
- content = content.replaceAll("(?s)", ""); // Remove html comments
- // content = content.replaceAll("\r", "").replaceAll("\n", ""); // Remove new lines
-
- final String oldContent = _cache.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
- if (oldContent == null)
- {
- _bytesBuffLen += content.length() * 2;
- _loadedFiles++;
- }
- else
- {
- _bytesBuffLen = (_bytesBuffLen - oldContent.length()) + (content.length() * 2);
- }
- return content;
+ _bytesBuffLen += bytes;
+ _loadedFiles++;
}
- catch (Exception e)
+ else
{
- LOGGER.log(Level.WARNING, "Problem with htm file:", e);
+ _bytesBuffLen = (_bytesBuffLen - oldContent.length()) + bytes;
}
}
- return null;
- }
-
- public String getHtmForce(PlayerInstance player, String path)
- {
- String content = getHtm(player, path);
- if (content == null)
+ catch (Exception e)
{
- content = "My text is missing:
" + path + "";
- LOGGER.warning("Cache[HTML]: Missing HTML page: " + path);
+ LOGGER.log(Level.WARNING, "Problem with htm file:", e);
}
return content;
}
public String getHtm(PlayerInstance player, String path)
{
- final String prefix = player != null ? player.getHtmlPrefix() : "en";
- String newPath = null;
- String content;
- if ((prefix != null) && !prefix.isEmpty())
+ final String prefix = player != null ? player.getHtmlPrefix() : "";
+ final String newPath = prefix + path;
+ String content = HTML_CACHE.get(newPath);
+ if (Config.LAZY_CACHE && (content == null))
{
- newPath = prefix + path;
- content = getHtm(newPath);
- if (content != null)
+ content = loadFile(new File(Config.DATAPACK_ROOT, newPath));
+ if (content == null)
{
- if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
- }
- return content;
+ content = loadFile(new File(Config.SCRIPT_ROOT, newPath));
}
}
- content = getHtm(path);
- if ((content != null) && (newPath != null))
+ if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
{
- _cache.put(newPath, content);
+ BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
}
- if ((player != null) && player.isGM() && (path != null) && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, path.substring(5));
- }
return content;
}
- private String getHtm(String path)
- {
- // TODO: Check why some files do not get in cache on server startup.
- return (path == null) || path.isEmpty() ? "" : _cache.get(path) == null ? loadFile(new File(Config.DATAPACK_ROOT, path)) : _cache.get(path);
- }
-
public boolean contains(String path)
{
- return _cache.containsKey(path);
+ return HTML_CACHE.containsKey(path);
}
/**
@@ -205,88 +179,13 @@ public class HtmCache
return HTML_FILTER.accept(new File(Config.DATAPACK_ROOT, path));
}
- private String parseTemplateName(String name)
- {
- if (!name.startsWith("data/"))
- {
- if (name.startsWith("html/"))
- {
- return "data/" + name;
- }
- else if (name.startsWith("CommunityBoard/"))
- {
- return "data/html/" + name;
- }
- else if (name.startsWith("scripts/"))
- {
- return "data/scripts/" + name;
- }
- }
- return name;
- }
-
- private String processHtml(String result)
- {
- final Matcher extendMatcher = EXTEND_PATTERN.matcher(result);
- if (extendMatcher.find())
- {
- // If extend matcher finds something, process template
- final String templateName = parseTemplateName(extendMatcher.group(1));
-
- // Generate block name -> content map
- final Map blockMap = generateBlockMap(result);
-
- // Attempt to find the template
- String template = getHtm(templateName + "-template.htm");
- if (template != null)
- {
- // Attempt to find the abstract blocks
- final Matcher blockMatcher = ABSTRACT_BLOCK_PATTERN.matcher(template);
- while (blockMatcher.find())
- {
- final String name = blockMatcher.group(1);
- if (!blockMap.containsKey(name))
- {
- LOGGER.warning(getClass().getSimpleName() + ": Abstract block definition [" + name + "] is not implemented!");
- continue;
- }
-
- // Replace the matched content with the block.
- template = template.replace(blockMatcher.group(0), blockMap.get(name));
- }
-
- // Replace the entire extend block
- result = result.replace(extendMatcher.group(0), template);
- }
- else
- {
- LOGGER.warning(getClass().getSimpleName() + ": Missing template: " + templateName + "-template.htm !");
- }
- }
-
- return result;
- }
-
- private Map generateBlockMap(String data)
- {
- final Map blockMap = new LinkedHashMap<>();
- final Matcher blockMatcher = BLOCK_PATTERN.matcher(data);
- while (blockMatcher.find())
- {
- final String name = blockMatcher.group(1);
- final String content = blockMatcher.group(2);
- blockMap.put(name, content);
- }
- return blockMap;
- }
-
public static HtmCache getInstance()
{
- return SingletonHolder._instance;
+ return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
- protected static final HtmCache _instance = new HtmCache();
+ protected static final HtmCache INSTANCE = new HtmCache();
}
}
diff --git a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index bbb6f722e3..b402f0230d 100644
--- a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -413,7 +413,7 @@ public final class PlayerInstance extends Playable
private Calendar _createDate = Calendar.getInstance();
private String _lang = null;
- private String _htmlPrefix = null;
+ private String _htmlPrefix = "";
private volatile boolean _isOnline = false;
private long _onlineTime;
@@ -12809,7 +12809,7 @@ public final class PlayerInstance extends Playable
{
if (!Config.MULTILANG_ENABLE)
{
- return null;
+ return "";
}
return _htmlPrefix;
@@ -12840,7 +12840,7 @@ public final class PlayerInstance extends Playable
else
{
_lang = null;
- _htmlPrefix = null;
+ _htmlPrefix = "";
}
return result;
diff --git a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/model/quest/Quest.java b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/model/quest/Quest.java
index fc5f76e926..19420ef0b7 100644
--- a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/model/quest/Quest.java
+++ b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/model/quest/Quest.java
@@ -2762,7 +2762,7 @@ public class Quest extends AbstractScript implements IIdentifiable
content = hc.getHtm(player, "data/scripts/" + getPath() + "/" + fileName);
if (content == null)
{
- content = hc.getHtmForce(player, "data/scripts/quests/" + getName() + "/" + fileName);
+ content = hc.getHtm(player, "data/scripts/quests/" + getName() + "/" + fileName);
}
}
return content;
diff --git a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
index 95409c567a..25a46c93b2 100644
--- a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
+++ b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
@@ -50,7 +50,7 @@ import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
public final class ScriptEngineManager implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
- public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
+ public static final Path SCRIPT_FOLDER = Config.SCRIPT_ROOT.toPath();
public static final Path MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "MasterHandler.java");
public static final Path EFFECT_MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "EffectMasterHandler.java");
public static final Path SKILL_CONDITION_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "SkillConditionMasterHandler.java");
diff --git a/L2J_Mobius_3.0_Helios/dist/game/config/General.ini b/L2J_Mobius_3.0_Helios/dist/game/config/General.ini
index 08b6846b63..aadbfcd534 100644
--- a/L2J_Mobius_3.0_Helios/dist/game/config/General.ini
+++ b/L2J_Mobius_3.0_Helios/dist/game/config/General.ini
@@ -246,8 +246,8 @@ ForceInventoryUpdate = False
# True = Load html's into cache only on first time html is requested.
# False = Load all html's into cache on server startup.
-# Default: True
-LazyCache = True
+# Default: False
+LazyCache = False
# Cache all character names in to memory on server startup
# False - names are loaded from Db when they are requested
diff --git a/L2J_Mobius_3.0_Helios/dist/game/config/Server.ini b/L2J_Mobius_3.0_Helios/dist/game/config/Server.ini
index 9409882359..45f530219a 100644
--- a/L2J_Mobius_3.0_Helios/dist/game/config/Server.ini
+++ b/L2J_Mobius_3.0_Helios/dist/game/config/Server.ini
@@ -94,6 +94,9 @@ AcceptAlternateID = True
# Default: .
DatapackRoot = .
+# Scripts root directory.
+ScriptRoot = ./data/scripts
+
# Define how many players are allowed to play simultaneously on your server.
# Default: 2000
MaximumOnlineUsers = 2000
diff --git a/L2J_Mobius_3.0_Helios/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java b/L2J_Mobius_3.0_Helios/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
index a650883032..0585478f14 100644
--- a/L2J_Mobius_3.0_Helios/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
+++ b/L2J_Mobius_3.0_Helios/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
@@ -220,7 +220,7 @@ public final class AdminPForge implements IAdminCommandHandler
private void showValuesPage(PlayerInstance activeChar, String[] opCodes, String format)
{
String sendBypass = null;
- String valuesHtml = HtmCache.getInstance().getHtmForce(activeChar, "data/html/admin/pforge/values.htm");
+ String valuesHtml = HtmCache.getInstance().getHtm(activeChar, "data/html/admin/pforge/values.htm");
if (opCodes.length == 3)
{
valuesHtml = valuesHtml.replace("%opformat%", "chd");
diff --git a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/Config.java b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/Config.java
index 242c10ad48..1e466328fc 100644
--- a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/Config.java
@@ -745,6 +745,7 @@ public final class Config
public static String CLAN_NAME_TEMPLATE;
public static int MAX_CHARACTERS_NUMBER_PER_ACCOUNT;
public static File DATAPACK_ROOT;
+ public static File SCRIPT_ROOT;
public static boolean ACCEPT_ALTERNATE_ID;
public static int REQUEST_ID;
public static boolean RESERVE_HOST_ON_LOGIN = false;
@@ -1247,6 +1248,16 @@ public final class Config
DATAPACK_ROOT = new File(".");
}
+ try
+ {
+ SCRIPT_ROOT = new File(serverSettings.getString("ScriptRoot", "./data/scripts").replaceAll("\\\\", "/")).getCanonicalFile();
+ }
+ catch (Exception e)
+ {
+ LOGGER.log(Level.WARNING, "Error setting script root!", e);
+ SCRIPT_ROOT = new File(".");
+ }
+
Pattern charNamePattern;
try
diff --git a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/cache/HtmCache.java b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/cache/HtmCache.java
index f129626e80..3d8420f5c1 100644
--- a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/cache/HtmCache.java
+++ b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/cache/HtmCache.java
@@ -16,36 +16,31 @@
*/
package com.l2jmobius.gameserver.cache;
+import java.io.BufferedInputStream;
import java.io.File;
-import java.nio.charset.StandardCharsets;
+import java.io.FileInputStream;
import java.util.HashMap;
-import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import com.l2jmobius.Config;
import com.l2jmobius.commons.util.file.filter.HTMLFilter;
import com.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import com.l2jmobius.gameserver.util.BuilderUtil;
-import com.l2jmobius.gameserver.util.Util;
/**
* @author Layane
+ * @author Zoey76
*/
public class HtmCache
{
private static final Logger LOGGER = Logger.getLogger(HtmCache.class.getName());
private static final HTMLFilter HTML_FILTER = new HTMLFilter();
- private static final Pattern EXTEND_PATTERN = Pattern.compile("(.*?)", Pattern.DOTALL);
- private static final Pattern ABSTRACT_BLOCK_PATTERN = Pattern.compile("", Pattern.DOTALL);
- private static final Pattern BLOCK_PATTERN = Pattern.compile("(.*?)", Pattern.DOTALL);
- private static final Map _cache = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
+ private static final Map HTML_CACHE = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
private int _loadedFiles;
private long _bytesBuffLen;
@@ -66,14 +61,14 @@ public class HtmCache
{
LOGGER.info("Html cache start...");
parseDir(f);
- LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded");
+ LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded.");
}
else
{
- _cache.clear();
+ HTML_CACHE.clear();
_loadedFiles = 0;
_bytesBuffLen = 0;
- LOGGER.info("Cache[HTML]: Running lazy cache");
+ LOGGER.info("Cache[HTML]: Running lazy cache.");
}
}
@@ -114,86 +109,65 @@ public class HtmCache
public String loadFile(File file)
{
- if (HTML_FILTER.accept(file))
+ if (!HTML_FILTER.accept(file))
{
- try
+ return null;
+ }
+
+ String content = null;
+ try (FileInputStream fis = new FileInputStream(file);
+ BufferedInputStream bis = new BufferedInputStream(fis))
+ {
+ final int bytes = bis.available();
+ byte[] raw = new byte[bytes];
+
+ bis.read(raw);
+ content = new String(raw, "UTF-8");
+ content = content.replaceAll("(?s)", ""); // Remove html comments
+
+ final String oldContent = HTML_CACHE.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
+ if (oldContent == null)
{
- String content = processHtml(Util.readAllLines(file, StandardCharsets.UTF_8, null));
- content = content.replaceAll("(?s)", ""); // Remove html comments
- // content = content.replaceAll("\r", "").replaceAll("\n", ""); // Remove new lines
-
- final String oldContent = _cache.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
- if (oldContent == null)
- {
- _bytesBuffLen += content.length() * 2;
- _loadedFiles++;
- }
- else
- {
- _bytesBuffLen = (_bytesBuffLen - oldContent.length()) + (content.length() * 2);
- }
- return content;
+ _bytesBuffLen += bytes;
+ _loadedFiles++;
}
- catch (Exception e)
+ else
{
- LOGGER.log(Level.WARNING, "Problem with htm file:", e);
+ _bytesBuffLen = (_bytesBuffLen - oldContent.length()) + bytes;
}
}
- return null;
- }
-
- public String getHtmForce(PlayerInstance player, String path)
- {
- String content = getHtm(player, path);
- if (content == null)
+ catch (Exception e)
{
- content = "My text is missing:
" + path + "";
- LOGGER.warning("Cache[HTML]: Missing HTML page: " + path);
+ LOGGER.log(Level.WARNING, "Problem with htm file:", e);
}
return content;
}
public String getHtm(PlayerInstance player, String path)
{
- final String prefix = player != null ? player.getHtmlPrefix() : "en";
- String newPath = null;
- String content;
- if ((prefix != null) && !prefix.isEmpty())
+ final String prefix = player != null ? player.getHtmlPrefix() : "";
+ final String newPath = prefix + path;
+ String content = HTML_CACHE.get(newPath);
+ if (Config.LAZY_CACHE && (content == null))
{
- newPath = prefix + path;
- content = getHtm(newPath);
- if (content != null)
+ content = loadFile(new File(Config.DATAPACK_ROOT, newPath));
+ if (content == null)
{
- if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
- }
- return content;
+ content = loadFile(new File(Config.SCRIPT_ROOT, newPath));
}
}
- content = getHtm(path);
- if ((content != null) && (newPath != null))
+ if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
{
- _cache.put(newPath, content);
+ BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
}
- if ((player != null) && player.isGM() && (path != null) && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, path.substring(5));
- }
return content;
}
- private String getHtm(String path)
- {
- // TODO: Check why some files do not get in cache on server startup.
- return (path == null) || path.isEmpty() ? "" : _cache.get(path) == null ? loadFile(new File(Config.DATAPACK_ROOT, path)) : _cache.get(path);
- }
-
public boolean contains(String path)
{
- return _cache.containsKey(path);
+ return HTML_CACHE.containsKey(path);
}
/**
@@ -205,88 +179,13 @@ public class HtmCache
return HTML_FILTER.accept(new File(Config.DATAPACK_ROOT, path));
}
- private String parseTemplateName(String name)
- {
- if (!name.startsWith("data/"))
- {
- if (name.startsWith("html/"))
- {
- return "data/" + name;
- }
- else if (name.startsWith("CommunityBoard/"))
- {
- return "data/html/" + name;
- }
- else if (name.startsWith("scripts/"))
- {
- return "data/scripts/" + name;
- }
- }
- return name;
- }
-
- private String processHtml(String result)
- {
- final Matcher extendMatcher = EXTEND_PATTERN.matcher(result);
- if (extendMatcher.find())
- {
- // If extend matcher finds something, process template
- final String templateName = parseTemplateName(extendMatcher.group(1));
-
- // Generate block name -> content map
- final Map blockMap = generateBlockMap(result);
-
- // Attempt to find the template
- String template = getHtm(templateName + "-template.htm");
- if (template != null)
- {
- // Attempt to find the abstract blocks
- final Matcher blockMatcher = ABSTRACT_BLOCK_PATTERN.matcher(template);
- while (blockMatcher.find())
- {
- final String name = blockMatcher.group(1);
- if (!blockMap.containsKey(name))
- {
- LOGGER.warning(getClass().getSimpleName() + ": Abstract block definition [" + name + "] is not implemented!");
- continue;
- }
-
- // Replace the matched content with the block.
- template = template.replace(blockMatcher.group(0), blockMap.get(name));
- }
-
- // Replace the entire extend block
- result = result.replace(extendMatcher.group(0), template);
- }
- else
- {
- LOGGER.warning(getClass().getSimpleName() + ": Missing template: " + templateName + "-template.htm !");
- }
- }
-
- return result;
- }
-
- private Map generateBlockMap(String data)
- {
- final Map blockMap = new LinkedHashMap<>();
- final Matcher blockMatcher = BLOCK_PATTERN.matcher(data);
- while (blockMatcher.find())
- {
- final String name = blockMatcher.group(1);
- final String content = blockMatcher.group(2);
- blockMap.put(name, content);
- }
- return blockMap;
- }
-
public static HtmCache getInstance()
{
- return SingletonHolder._instance;
+ return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
- protected static final HtmCache _instance = new HtmCache();
+ protected static final HtmCache INSTANCE = new HtmCache();
}
}
diff --git a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index b0bfa71b09..84cfaaee0d 100644
--- a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -415,7 +415,7 @@ public final class PlayerInstance extends Playable
private Calendar _createDate = Calendar.getInstance();
private String _lang = null;
- private String _htmlPrefix = null;
+ private String _htmlPrefix = "";
private volatile boolean _isOnline = false;
private long _onlineTime;
@@ -12811,7 +12811,7 @@ public final class PlayerInstance extends Playable
{
if (!Config.MULTILANG_ENABLE)
{
- return null;
+ return "";
}
return _htmlPrefix;
@@ -12842,7 +12842,7 @@ public final class PlayerInstance extends Playable
else
{
_lang = null;
- _htmlPrefix = null;
+ _htmlPrefix = "";
}
return result;
diff --git a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/model/quest/Quest.java b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/model/quest/Quest.java
index 9e986f2862..794ae17b38 100644
--- a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/model/quest/Quest.java
+++ b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/model/quest/Quest.java
@@ -2763,7 +2763,7 @@ public class Quest extends AbstractScript implements IIdentifiable
content = hc.getHtm(player, "data/scripts/" + getPath() + "/" + fileName);
if (content == null)
{
- content = hc.getHtmForce(player, "data/scripts/quests/" + getName() + "/" + fileName);
+ content = hc.getHtm(player, "data/scripts/quests/" + getName() + "/" + fileName);
}
}
return content;
diff --git a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
index 95409c567a..25a46c93b2 100644
--- a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
+++ b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
@@ -50,7 +50,7 @@ import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
public final class ScriptEngineManager implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
- public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
+ public static final Path SCRIPT_FOLDER = Config.SCRIPT_ROOT.toPath();
public static final Path MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "MasterHandler.java");
public static final Path EFFECT_MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "EffectMasterHandler.java");
public static final Path SKILL_CONDITION_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "SkillConditionMasterHandler.java");
diff --git a/L2J_Mobius_4.0_GrandCrusade/dist/game/config/General.ini b/L2J_Mobius_4.0_GrandCrusade/dist/game/config/General.ini
index 08b6846b63..aadbfcd534 100644
--- a/L2J_Mobius_4.0_GrandCrusade/dist/game/config/General.ini
+++ b/L2J_Mobius_4.0_GrandCrusade/dist/game/config/General.ini
@@ -246,8 +246,8 @@ ForceInventoryUpdate = False
# True = Load html's into cache only on first time html is requested.
# False = Load all html's into cache on server startup.
-# Default: True
-LazyCache = True
+# Default: False
+LazyCache = False
# Cache all character names in to memory on server startup
# False - names are loaded from Db when they are requested
diff --git a/L2J_Mobius_4.0_GrandCrusade/dist/game/config/Server.ini b/L2J_Mobius_4.0_GrandCrusade/dist/game/config/Server.ini
index 7860697805..a458bd3e8f 100644
--- a/L2J_Mobius_4.0_GrandCrusade/dist/game/config/Server.ini
+++ b/L2J_Mobius_4.0_GrandCrusade/dist/game/config/Server.ini
@@ -94,6 +94,9 @@ AcceptAlternateID = True
# Default: .
DatapackRoot = .
+# Scripts root directory.
+ScriptRoot = ./data/scripts
+
# Define how many players are allowed to play simultaneously on your server.
# Default: 2000
MaximumOnlineUsers = 2000
diff --git a/L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java b/L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
index a650883032..0585478f14 100644
--- a/L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
+++ b/L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
@@ -220,7 +220,7 @@ public final class AdminPForge implements IAdminCommandHandler
private void showValuesPage(PlayerInstance activeChar, String[] opCodes, String format)
{
String sendBypass = null;
- String valuesHtml = HtmCache.getInstance().getHtmForce(activeChar, "data/html/admin/pforge/values.htm");
+ String valuesHtml = HtmCache.getInstance().getHtm(activeChar, "data/html/admin/pforge/values.htm");
if (opCodes.length == 3)
{
valuesHtml = valuesHtml.replace("%opformat%", "chd");
diff --git a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/Config.java b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/Config.java
index 6670015016..6837f65336 100644
--- a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/Config.java
@@ -738,6 +738,7 @@ public final class Config
public static String CLAN_NAME_TEMPLATE;
public static int MAX_CHARACTERS_NUMBER_PER_ACCOUNT;
public static File DATAPACK_ROOT;
+ public static File SCRIPT_ROOT;
public static boolean ACCEPT_ALTERNATE_ID;
public static int REQUEST_ID;
public static boolean RESERVE_HOST_ON_LOGIN = false;
@@ -1240,6 +1241,16 @@ public final class Config
DATAPACK_ROOT = new File(".");
}
+ try
+ {
+ SCRIPT_ROOT = new File(serverSettings.getString("ScriptRoot", "./data/scripts").replaceAll("\\\\", "/")).getCanonicalFile();
+ }
+ catch (Exception e)
+ {
+ LOGGER.log(Level.WARNING, "Error setting script root!", e);
+ SCRIPT_ROOT = new File(".");
+ }
+
Pattern charNamePattern;
try
diff --git a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/cache/HtmCache.java b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/cache/HtmCache.java
index f129626e80..3d8420f5c1 100644
--- a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/cache/HtmCache.java
+++ b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/cache/HtmCache.java
@@ -16,36 +16,31 @@
*/
package com.l2jmobius.gameserver.cache;
+import java.io.BufferedInputStream;
import java.io.File;
-import java.nio.charset.StandardCharsets;
+import java.io.FileInputStream;
import java.util.HashMap;
-import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import com.l2jmobius.Config;
import com.l2jmobius.commons.util.file.filter.HTMLFilter;
import com.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import com.l2jmobius.gameserver.util.BuilderUtil;
-import com.l2jmobius.gameserver.util.Util;
/**
* @author Layane
+ * @author Zoey76
*/
public class HtmCache
{
private static final Logger LOGGER = Logger.getLogger(HtmCache.class.getName());
private static final HTMLFilter HTML_FILTER = new HTMLFilter();
- private static final Pattern EXTEND_PATTERN = Pattern.compile("(.*?)", Pattern.DOTALL);
- private static final Pattern ABSTRACT_BLOCK_PATTERN = Pattern.compile("", Pattern.DOTALL);
- private static final Pattern BLOCK_PATTERN = Pattern.compile("(.*?)", Pattern.DOTALL);
- private static final Map _cache = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
+ private static final Map HTML_CACHE = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
private int _loadedFiles;
private long _bytesBuffLen;
@@ -66,14 +61,14 @@ public class HtmCache
{
LOGGER.info("Html cache start...");
parseDir(f);
- LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded");
+ LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded.");
}
else
{
- _cache.clear();
+ HTML_CACHE.clear();
_loadedFiles = 0;
_bytesBuffLen = 0;
- LOGGER.info("Cache[HTML]: Running lazy cache");
+ LOGGER.info("Cache[HTML]: Running lazy cache.");
}
}
@@ -114,86 +109,65 @@ public class HtmCache
public String loadFile(File file)
{
- if (HTML_FILTER.accept(file))
+ if (!HTML_FILTER.accept(file))
{
- try
+ return null;
+ }
+
+ String content = null;
+ try (FileInputStream fis = new FileInputStream(file);
+ BufferedInputStream bis = new BufferedInputStream(fis))
+ {
+ final int bytes = bis.available();
+ byte[] raw = new byte[bytes];
+
+ bis.read(raw);
+ content = new String(raw, "UTF-8");
+ content = content.replaceAll("(?s)", ""); // Remove html comments
+
+ final String oldContent = HTML_CACHE.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
+ if (oldContent == null)
{
- String content = processHtml(Util.readAllLines(file, StandardCharsets.UTF_8, null));
- content = content.replaceAll("(?s)", ""); // Remove html comments
- // content = content.replaceAll("\r", "").replaceAll("\n", ""); // Remove new lines
-
- final String oldContent = _cache.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
- if (oldContent == null)
- {
- _bytesBuffLen += content.length() * 2;
- _loadedFiles++;
- }
- else
- {
- _bytesBuffLen = (_bytesBuffLen - oldContent.length()) + (content.length() * 2);
- }
- return content;
+ _bytesBuffLen += bytes;
+ _loadedFiles++;
}
- catch (Exception e)
+ else
{
- LOGGER.log(Level.WARNING, "Problem with htm file:", e);
+ _bytesBuffLen = (_bytesBuffLen - oldContent.length()) + bytes;
}
}
- return null;
- }
-
- public String getHtmForce(PlayerInstance player, String path)
- {
- String content = getHtm(player, path);
- if (content == null)
+ catch (Exception e)
{
- content = "My text is missing:
" + path + "";
- LOGGER.warning("Cache[HTML]: Missing HTML page: " + path);
+ LOGGER.log(Level.WARNING, "Problem with htm file:", e);
}
return content;
}
public String getHtm(PlayerInstance player, String path)
{
- final String prefix = player != null ? player.getHtmlPrefix() : "en";
- String newPath = null;
- String content;
- if ((prefix != null) && !prefix.isEmpty())
+ final String prefix = player != null ? player.getHtmlPrefix() : "";
+ final String newPath = prefix + path;
+ String content = HTML_CACHE.get(newPath);
+ if (Config.LAZY_CACHE && (content == null))
{
- newPath = prefix + path;
- content = getHtm(newPath);
- if (content != null)
+ content = loadFile(new File(Config.DATAPACK_ROOT, newPath));
+ if (content == null)
{
- if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
- }
- return content;
+ content = loadFile(new File(Config.SCRIPT_ROOT, newPath));
}
}
- content = getHtm(path);
- if ((content != null) && (newPath != null))
+ if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
{
- _cache.put(newPath, content);
+ BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
}
- if ((player != null) && player.isGM() && (path != null) && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, path.substring(5));
- }
return content;
}
- private String getHtm(String path)
- {
- // TODO: Check why some files do not get in cache on server startup.
- return (path == null) || path.isEmpty() ? "" : _cache.get(path) == null ? loadFile(new File(Config.DATAPACK_ROOT, path)) : _cache.get(path);
- }
-
public boolean contains(String path)
{
- return _cache.containsKey(path);
+ return HTML_CACHE.containsKey(path);
}
/**
@@ -205,88 +179,13 @@ public class HtmCache
return HTML_FILTER.accept(new File(Config.DATAPACK_ROOT, path));
}
- private String parseTemplateName(String name)
- {
- if (!name.startsWith("data/"))
- {
- if (name.startsWith("html/"))
- {
- return "data/" + name;
- }
- else if (name.startsWith("CommunityBoard/"))
- {
- return "data/html/" + name;
- }
- else if (name.startsWith("scripts/"))
- {
- return "data/scripts/" + name;
- }
- }
- return name;
- }
-
- private String processHtml(String result)
- {
- final Matcher extendMatcher = EXTEND_PATTERN.matcher(result);
- if (extendMatcher.find())
- {
- // If extend matcher finds something, process template
- final String templateName = parseTemplateName(extendMatcher.group(1));
-
- // Generate block name -> content map
- final Map blockMap = generateBlockMap(result);
-
- // Attempt to find the template
- String template = getHtm(templateName + "-template.htm");
- if (template != null)
- {
- // Attempt to find the abstract blocks
- final Matcher blockMatcher = ABSTRACT_BLOCK_PATTERN.matcher(template);
- while (blockMatcher.find())
- {
- final String name = blockMatcher.group(1);
- if (!blockMap.containsKey(name))
- {
- LOGGER.warning(getClass().getSimpleName() + ": Abstract block definition [" + name + "] is not implemented!");
- continue;
- }
-
- // Replace the matched content with the block.
- template = template.replace(blockMatcher.group(0), blockMap.get(name));
- }
-
- // Replace the entire extend block
- result = result.replace(extendMatcher.group(0), template);
- }
- else
- {
- LOGGER.warning(getClass().getSimpleName() + ": Missing template: " + templateName + "-template.htm !");
- }
- }
-
- return result;
- }
-
- private Map generateBlockMap(String data)
- {
- final Map blockMap = new LinkedHashMap<>();
- final Matcher blockMatcher = BLOCK_PATTERN.matcher(data);
- while (blockMatcher.find())
- {
- final String name = blockMatcher.group(1);
- final String content = blockMatcher.group(2);
- blockMap.put(name, content);
- }
- return blockMap;
- }
-
public static HtmCache getInstance()
{
- return SingletonHolder._instance;
+ return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
- protected static final HtmCache _instance = new HtmCache();
+ protected static final HtmCache INSTANCE = new HtmCache();
}
}
diff --git a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index 1755c69d50..c9db1b1976 100644
--- a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -420,7 +420,7 @@ public final class PlayerInstance extends Playable
private Calendar _createDate = Calendar.getInstance();
private String _lang = null;
- private String _htmlPrefix = null;
+ private String _htmlPrefix = "";
private volatile boolean _isOnline = false;
private long _onlineTime;
@@ -12794,7 +12794,7 @@ public final class PlayerInstance extends Playable
{
if (!Config.MULTILANG_ENABLE)
{
- return null;
+ return "";
}
return _htmlPrefix;
@@ -12825,7 +12825,7 @@ public final class PlayerInstance extends Playable
else
{
_lang = null;
- _htmlPrefix = null;
+ _htmlPrefix = "";
}
return result;
diff --git a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/model/quest/Quest.java b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/model/quest/Quest.java
index 999ad014d8..e3f51b26a5 100644
--- a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/model/quest/Quest.java
+++ b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/model/quest/Quest.java
@@ -2763,7 +2763,7 @@ public class Quest extends AbstractScript implements IIdentifiable
content = hc.getHtm(player, "data/scripts/" + getPath() + "/" + fileName);
if (content == null)
{
- content = hc.getHtmForce(player, "data/scripts/quests/" + getName() + "/" + fileName);
+ content = hc.getHtm(player, "data/scripts/quests/" + getName() + "/" + fileName);
}
}
return content;
diff --git a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
index 95409c567a..25a46c93b2 100644
--- a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
+++ b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
@@ -50,7 +50,7 @@ import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
public final class ScriptEngineManager implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
- public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
+ public static final Path SCRIPT_FOLDER = Config.SCRIPT_ROOT.toPath();
public static final Path MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "MasterHandler.java");
public static final Path EFFECT_MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "EffectMasterHandler.java");
public static final Path SKILL_CONDITION_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "SkillConditionMasterHandler.java");
diff --git a/L2J_Mobius_5.0_Salvation/dist/game/config/General.ini b/L2J_Mobius_5.0_Salvation/dist/game/config/General.ini
index 08b6846b63..aadbfcd534 100644
--- a/L2J_Mobius_5.0_Salvation/dist/game/config/General.ini
+++ b/L2J_Mobius_5.0_Salvation/dist/game/config/General.ini
@@ -246,8 +246,8 @@ ForceInventoryUpdate = False
# True = Load html's into cache only on first time html is requested.
# False = Load all html's into cache on server startup.
-# Default: True
-LazyCache = True
+# Default: False
+LazyCache = False
# Cache all character names in to memory on server startup
# False - names are loaded from Db when they are requested
diff --git a/L2J_Mobius_5.0_Salvation/dist/game/config/Server.ini b/L2J_Mobius_5.0_Salvation/dist/game/config/Server.ini
index 55c484028b..ba28ee2740 100644
--- a/L2J_Mobius_5.0_Salvation/dist/game/config/Server.ini
+++ b/L2J_Mobius_5.0_Salvation/dist/game/config/Server.ini
@@ -94,6 +94,9 @@ AcceptAlternateID = True
# Default: .
DatapackRoot = .
+# Scripts root directory.
+ScriptRoot = ./data/scripts
+
# Define how many players are allowed to play simultaneously on your server.
# Default: 2000
MaximumOnlineUsers = 2000
diff --git a/L2J_Mobius_5.0_Salvation/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java b/L2J_Mobius_5.0_Salvation/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
index a650883032..0585478f14 100644
--- a/L2J_Mobius_5.0_Salvation/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
+++ b/L2J_Mobius_5.0_Salvation/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
@@ -220,7 +220,7 @@ public final class AdminPForge implements IAdminCommandHandler
private void showValuesPage(PlayerInstance activeChar, String[] opCodes, String format)
{
String sendBypass = null;
- String valuesHtml = HtmCache.getInstance().getHtmForce(activeChar, "data/html/admin/pforge/values.htm");
+ String valuesHtml = HtmCache.getInstance().getHtm(activeChar, "data/html/admin/pforge/values.htm");
if (opCodes.length == 3)
{
valuesHtml = valuesHtml.replace("%opformat%", "chd");
diff --git a/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/Config.java b/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/Config.java
index 968fc826f8..6446869d14 100644
--- a/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/Config.java
@@ -733,6 +733,7 @@ public final class Config
public static String CLAN_NAME_TEMPLATE;
public static int MAX_CHARACTERS_NUMBER_PER_ACCOUNT;
public static File DATAPACK_ROOT;
+ public static File SCRIPT_ROOT;
public static boolean ACCEPT_ALTERNATE_ID;
public static int REQUEST_ID;
public static boolean RESERVE_HOST_ON_LOGIN = false;
@@ -1235,6 +1236,16 @@ public final class Config
DATAPACK_ROOT = new File(".");
}
+ try
+ {
+ SCRIPT_ROOT = new File(serverSettings.getString("ScriptRoot", "./data/scripts").replaceAll("\\\\", "/")).getCanonicalFile();
+ }
+ catch (Exception e)
+ {
+ LOGGER.log(Level.WARNING, "Error setting script root!", e);
+ SCRIPT_ROOT = new File(".");
+ }
+
Pattern charNamePattern;
try
diff --git a/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/cache/HtmCache.java b/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/cache/HtmCache.java
index f129626e80..3d8420f5c1 100644
--- a/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/cache/HtmCache.java
+++ b/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/cache/HtmCache.java
@@ -16,36 +16,31 @@
*/
package com.l2jmobius.gameserver.cache;
+import java.io.BufferedInputStream;
import java.io.File;
-import java.nio.charset.StandardCharsets;
+import java.io.FileInputStream;
import java.util.HashMap;
-import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import com.l2jmobius.Config;
import com.l2jmobius.commons.util.file.filter.HTMLFilter;
import com.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import com.l2jmobius.gameserver.util.BuilderUtil;
-import com.l2jmobius.gameserver.util.Util;
/**
* @author Layane
+ * @author Zoey76
*/
public class HtmCache
{
private static final Logger LOGGER = Logger.getLogger(HtmCache.class.getName());
private static final HTMLFilter HTML_FILTER = new HTMLFilter();
- private static final Pattern EXTEND_PATTERN = Pattern.compile("(.*?)", Pattern.DOTALL);
- private static final Pattern ABSTRACT_BLOCK_PATTERN = Pattern.compile("", Pattern.DOTALL);
- private static final Pattern BLOCK_PATTERN = Pattern.compile("(.*?)", Pattern.DOTALL);
- private static final Map _cache = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
+ private static final Map HTML_CACHE = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
private int _loadedFiles;
private long _bytesBuffLen;
@@ -66,14 +61,14 @@ public class HtmCache
{
LOGGER.info("Html cache start...");
parseDir(f);
- LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded");
+ LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded.");
}
else
{
- _cache.clear();
+ HTML_CACHE.clear();
_loadedFiles = 0;
_bytesBuffLen = 0;
- LOGGER.info("Cache[HTML]: Running lazy cache");
+ LOGGER.info("Cache[HTML]: Running lazy cache.");
}
}
@@ -114,86 +109,65 @@ public class HtmCache
public String loadFile(File file)
{
- if (HTML_FILTER.accept(file))
+ if (!HTML_FILTER.accept(file))
{
- try
+ return null;
+ }
+
+ String content = null;
+ try (FileInputStream fis = new FileInputStream(file);
+ BufferedInputStream bis = new BufferedInputStream(fis))
+ {
+ final int bytes = bis.available();
+ byte[] raw = new byte[bytes];
+
+ bis.read(raw);
+ content = new String(raw, "UTF-8");
+ content = content.replaceAll("(?s)", ""); // Remove html comments
+
+ final String oldContent = HTML_CACHE.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
+ if (oldContent == null)
{
- String content = processHtml(Util.readAllLines(file, StandardCharsets.UTF_8, null));
- content = content.replaceAll("(?s)", ""); // Remove html comments
- // content = content.replaceAll("\r", "").replaceAll("\n", ""); // Remove new lines
-
- final String oldContent = _cache.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
- if (oldContent == null)
- {
- _bytesBuffLen += content.length() * 2;
- _loadedFiles++;
- }
- else
- {
- _bytesBuffLen = (_bytesBuffLen - oldContent.length()) + (content.length() * 2);
- }
- return content;
+ _bytesBuffLen += bytes;
+ _loadedFiles++;
}
- catch (Exception e)
+ else
{
- LOGGER.log(Level.WARNING, "Problem with htm file:", e);
+ _bytesBuffLen = (_bytesBuffLen - oldContent.length()) + bytes;
}
}
- return null;
- }
-
- public String getHtmForce(PlayerInstance player, String path)
- {
- String content = getHtm(player, path);
- if (content == null)
+ catch (Exception e)
{
- content = "My text is missing:
" + path + "";
- LOGGER.warning("Cache[HTML]: Missing HTML page: " + path);
+ LOGGER.log(Level.WARNING, "Problem with htm file:", e);
}
return content;
}
public String getHtm(PlayerInstance player, String path)
{
- final String prefix = player != null ? player.getHtmlPrefix() : "en";
- String newPath = null;
- String content;
- if ((prefix != null) && !prefix.isEmpty())
+ final String prefix = player != null ? player.getHtmlPrefix() : "";
+ final String newPath = prefix + path;
+ String content = HTML_CACHE.get(newPath);
+ if (Config.LAZY_CACHE && (content == null))
{
- newPath = prefix + path;
- content = getHtm(newPath);
- if (content != null)
+ content = loadFile(new File(Config.DATAPACK_ROOT, newPath));
+ if (content == null)
{
- if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
- }
- return content;
+ content = loadFile(new File(Config.SCRIPT_ROOT, newPath));
}
}
- content = getHtm(path);
- if ((content != null) && (newPath != null))
+ if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
{
- _cache.put(newPath, content);
+ BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
}
- if ((player != null) && player.isGM() && (path != null) && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, path.substring(5));
- }
return content;
}
- private String getHtm(String path)
- {
- // TODO: Check why some files do not get in cache on server startup.
- return (path == null) || path.isEmpty() ? "" : _cache.get(path) == null ? loadFile(new File(Config.DATAPACK_ROOT, path)) : _cache.get(path);
- }
-
public boolean contains(String path)
{
- return _cache.containsKey(path);
+ return HTML_CACHE.containsKey(path);
}
/**
@@ -205,88 +179,13 @@ public class HtmCache
return HTML_FILTER.accept(new File(Config.DATAPACK_ROOT, path));
}
- private String parseTemplateName(String name)
- {
- if (!name.startsWith("data/"))
- {
- if (name.startsWith("html/"))
- {
- return "data/" + name;
- }
- else if (name.startsWith("CommunityBoard/"))
- {
- return "data/html/" + name;
- }
- else if (name.startsWith("scripts/"))
- {
- return "data/scripts/" + name;
- }
- }
- return name;
- }
-
- private String processHtml(String result)
- {
- final Matcher extendMatcher = EXTEND_PATTERN.matcher(result);
- if (extendMatcher.find())
- {
- // If extend matcher finds something, process template
- final String templateName = parseTemplateName(extendMatcher.group(1));
-
- // Generate block name -> content map
- final Map blockMap = generateBlockMap(result);
-
- // Attempt to find the template
- String template = getHtm(templateName + "-template.htm");
- if (template != null)
- {
- // Attempt to find the abstract blocks
- final Matcher blockMatcher = ABSTRACT_BLOCK_PATTERN.matcher(template);
- while (blockMatcher.find())
- {
- final String name = blockMatcher.group(1);
- if (!blockMap.containsKey(name))
- {
- LOGGER.warning(getClass().getSimpleName() + ": Abstract block definition [" + name + "] is not implemented!");
- continue;
- }
-
- // Replace the matched content with the block.
- template = template.replace(blockMatcher.group(0), blockMap.get(name));
- }
-
- // Replace the entire extend block
- result = result.replace(extendMatcher.group(0), template);
- }
- else
- {
- LOGGER.warning(getClass().getSimpleName() + ": Missing template: " + templateName + "-template.htm !");
- }
- }
-
- return result;
- }
-
- private Map generateBlockMap(String data)
- {
- final Map blockMap = new LinkedHashMap<>();
- final Matcher blockMatcher = BLOCK_PATTERN.matcher(data);
- while (blockMatcher.find())
- {
- final String name = blockMatcher.group(1);
- final String content = blockMatcher.group(2);
- blockMap.put(name, content);
- }
- return blockMap;
- }
-
public static HtmCache getInstance()
{
- return SingletonHolder._instance;
+ return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
- protected static final HtmCache _instance = new HtmCache();
+ protected static final HtmCache INSTANCE = new HtmCache();
}
}
diff --git a/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index b7702ed678..319186058f 100644
--- a/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -418,7 +418,7 @@ public final class PlayerInstance extends Playable
private Calendar _createDate = Calendar.getInstance();
private String _lang = null;
- private String _htmlPrefix = null;
+ private String _htmlPrefix = "";
private volatile boolean _isOnline = false;
private long _onlineTime;
@@ -12784,7 +12784,7 @@ public final class PlayerInstance extends Playable
{
if (!Config.MULTILANG_ENABLE)
{
- return null;
+ return "";
}
return _htmlPrefix;
@@ -12815,7 +12815,7 @@ public final class PlayerInstance extends Playable
else
{
_lang = null;
- _htmlPrefix = null;
+ _htmlPrefix = "";
}
return result;
diff --git a/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/model/quest/Quest.java b/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/model/quest/Quest.java
index 999ad014d8..e3f51b26a5 100644
--- a/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/model/quest/Quest.java
+++ b/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/model/quest/Quest.java
@@ -2763,7 +2763,7 @@ public class Quest extends AbstractScript implements IIdentifiable
content = hc.getHtm(player, "data/scripts/" + getPath() + "/" + fileName);
if (content == null)
{
- content = hc.getHtmForce(player, "data/scripts/quests/" + getName() + "/" + fileName);
+ content = hc.getHtm(player, "data/scripts/quests/" + getName() + "/" + fileName);
}
}
return content;
diff --git a/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java b/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
index 95409c567a..25a46c93b2 100644
--- a/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
+++ b/L2J_Mobius_5.0_Salvation/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
@@ -50,7 +50,7 @@ import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
public final class ScriptEngineManager implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
- public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
+ public static final Path SCRIPT_FOLDER = Config.SCRIPT_ROOT.toPath();
public static final Path MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "MasterHandler.java");
public static final Path EFFECT_MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "EffectMasterHandler.java");
public static final Path SKILL_CONDITION_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "SkillConditionMasterHandler.java");
diff --git a/L2J_Mobius_5.5_EtinasFate/dist/game/config/General.ini b/L2J_Mobius_5.5_EtinasFate/dist/game/config/General.ini
index 08b6846b63..aadbfcd534 100644
--- a/L2J_Mobius_5.5_EtinasFate/dist/game/config/General.ini
+++ b/L2J_Mobius_5.5_EtinasFate/dist/game/config/General.ini
@@ -246,8 +246,8 @@ ForceInventoryUpdate = False
# True = Load html's into cache only on first time html is requested.
# False = Load all html's into cache on server startup.
-# Default: True
-LazyCache = True
+# Default: False
+LazyCache = False
# Cache all character names in to memory on server startup
# False - names are loaded from Db when they are requested
diff --git a/L2J_Mobius_5.5_EtinasFate/dist/game/config/Server.ini b/L2J_Mobius_5.5_EtinasFate/dist/game/config/Server.ini
index 54116691c7..190db44a8b 100644
--- a/L2J_Mobius_5.5_EtinasFate/dist/game/config/Server.ini
+++ b/L2J_Mobius_5.5_EtinasFate/dist/game/config/Server.ini
@@ -94,6 +94,9 @@ AcceptAlternateID = True
# Default: .
DatapackRoot = .
+# Scripts root directory.
+ScriptRoot = ./data/scripts
+
# Define how many players are allowed to play simultaneously on your server.
# Default: 2000
MaximumOnlineUsers = 2000
diff --git a/L2J_Mobius_5.5_EtinasFate/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java b/L2J_Mobius_5.5_EtinasFate/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
index a650883032..0585478f14 100644
--- a/L2J_Mobius_5.5_EtinasFate/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
+++ b/L2J_Mobius_5.5_EtinasFate/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
@@ -220,7 +220,7 @@ public final class AdminPForge implements IAdminCommandHandler
private void showValuesPage(PlayerInstance activeChar, String[] opCodes, String format)
{
String sendBypass = null;
- String valuesHtml = HtmCache.getInstance().getHtmForce(activeChar, "data/html/admin/pforge/values.htm");
+ String valuesHtml = HtmCache.getInstance().getHtm(activeChar, "data/html/admin/pforge/values.htm");
if (opCodes.length == 3)
{
valuesHtml = valuesHtml.replace("%opformat%", "chd");
diff --git a/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/Config.java b/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/Config.java
index 968fc826f8..6446869d14 100644
--- a/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/Config.java
@@ -733,6 +733,7 @@ public final class Config
public static String CLAN_NAME_TEMPLATE;
public static int MAX_CHARACTERS_NUMBER_PER_ACCOUNT;
public static File DATAPACK_ROOT;
+ public static File SCRIPT_ROOT;
public static boolean ACCEPT_ALTERNATE_ID;
public static int REQUEST_ID;
public static boolean RESERVE_HOST_ON_LOGIN = false;
@@ -1235,6 +1236,16 @@ public final class Config
DATAPACK_ROOT = new File(".");
}
+ try
+ {
+ SCRIPT_ROOT = new File(serverSettings.getString("ScriptRoot", "./data/scripts").replaceAll("\\\\", "/")).getCanonicalFile();
+ }
+ catch (Exception e)
+ {
+ LOGGER.log(Level.WARNING, "Error setting script root!", e);
+ SCRIPT_ROOT = new File(".");
+ }
+
Pattern charNamePattern;
try
diff --git a/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/cache/HtmCache.java b/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/cache/HtmCache.java
index f129626e80..3d8420f5c1 100644
--- a/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/cache/HtmCache.java
+++ b/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/cache/HtmCache.java
@@ -16,36 +16,31 @@
*/
package com.l2jmobius.gameserver.cache;
+import java.io.BufferedInputStream;
import java.io.File;
-import java.nio.charset.StandardCharsets;
+import java.io.FileInputStream;
import java.util.HashMap;
-import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import com.l2jmobius.Config;
import com.l2jmobius.commons.util.file.filter.HTMLFilter;
import com.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import com.l2jmobius.gameserver.util.BuilderUtil;
-import com.l2jmobius.gameserver.util.Util;
/**
* @author Layane
+ * @author Zoey76
*/
public class HtmCache
{
private static final Logger LOGGER = Logger.getLogger(HtmCache.class.getName());
private static final HTMLFilter HTML_FILTER = new HTMLFilter();
- private static final Pattern EXTEND_PATTERN = Pattern.compile("(.*?)", Pattern.DOTALL);
- private static final Pattern ABSTRACT_BLOCK_PATTERN = Pattern.compile("", Pattern.DOTALL);
- private static final Pattern BLOCK_PATTERN = Pattern.compile("(.*?)", Pattern.DOTALL);
- private static final Map _cache = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
+ private static final Map HTML_CACHE = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
private int _loadedFiles;
private long _bytesBuffLen;
@@ -66,14 +61,14 @@ public class HtmCache
{
LOGGER.info("Html cache start...");
parseDir(f);
- LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded");
+ LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded.");
}
else
{
- _cache.clear();
+ HTML_CACHE.clear();
_loadedFiles = 0;
_bytesBuffLen = 0;
- LOGGER.info("Cache[HTML]: Running lazy cache");
+ LOGGER.info("Cache[HTML]: Running lazy cache.");
}
}
@@ -114,86 +109,65 @@ public class HtmCache
public String loadFile(File file)
{
- if (HTML_FILTER.accept(file))
+ if (!HTML_FILTER.accept(file))
{
- try
+ return null;
+ }
+
+ String content = null;
+ try (FileInputStream fis = new FileInputStream(file);
+ BufferedInputStream bis = new BufferedInputStream(fis))
+ {
+ final int bytes = bis.available();
+ byte[] raw = new byte[bytes];
+
+ bis.read(raw);
+ content = new String(raw, "UTF-8");
+ content = content.replaceAll("(?s)", ""); // Remove html comments
+
+ final String oldContent = HTML_CACHE.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
+ if (oldContent == null)
{
- String content = processHtml(Util.readAllLines(file, StandardCharsets.UTF_8, null));
- content = content.replaceAll("(?s)", ""); // Remove html comments
- // content = content.replaceAll("\r", "").replaceAll("\n", ""); // Remove new lines
-
- final String oldContent = _cache.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
- if (oldContent == null)
- {
- _bytesBuffLen += content.length() * 2;
- _loadedFiles++;
- }
- else
- {
- _bytesBuffLen = (_bytesBuffLen - oldContent.length()) + (content.length() * 2);
- }
- return content;
+ _bytesBuffLen += bytes;
+ _loadedFiles++;
}
- catch (Exception e)
+ else
{
- LOGGER.log(Level.WARNING, "Problem with htm file:", e);
+ _bytesBuffLen = (_bytesBuffLen - oldContent.length()) + bytes;
}
}
- return null;
- }
-
- public String getHtmForce(PlayerInstance player, String path)
- {
- String content = getHtm(player, path);
- if (content == null)
+ catch (Exception e)
{
- content = "My text is missing:
" + path + "";
- LOGGER.warning("Cache[HTML]: Missing HTML page: " + path);
+ LOGGER.log(Level.WARNING, "Problem with htm file:", e);
}
return content;
}
public String getHtm(PlayerInstance player, String path)
{
- final String prefix = player != null ? player.getHtmlPrefix() : "en";
- String newPath = null;
- String content;
- if ((prefix != null) && !prefix.isEmpty())
+ final String prefix = player != null ? player.getHtmlPrefix() : "";
+ final String newPath = prefix + path;
+ String content = HTML_CACHE.get(newPath);
+ if (Config.LAZY_CACHE && (content == null))
{
- newPath = prefix + path;
- content = getHtm(newPath);
- if (content != null)
+ content = loadFile(new File(Config.DATAPACK_ROOT, newPath));
+ if (content == null)
{
- if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
- }
- return content;
+ content = loadFile(new File(Config.SCRIPT_ROOT, newPath));
}
}
- content = getHtm(path);
- if ((content != null) && (newPath != null))
+ if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
{
- _cache.put(newPath, content);
+ BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
}
- if ((player != null) && player.isGM() && (path != null) && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, path.substring(5));
- }
return content;
}
- private String getHtm(String path)
- {
- // TODO: Check why some files do not get in cache on server startup.
- return (path == null) || path.isEmpty() ? "" : _cache.get(path) == null ? loadFile(new File(Config.DATAPACK_ROOT, path)) : _cache.get(path);
- }
-
public boolean contains(String path)
{
- return _cache.containsKey(path);
+ return HTML_CACHE.containsKey(path);
}
/**
@@ -205,88 +179,13 @@ public class HtmCache
return HTML_FILTER.accept(new File(Config.DATAPACK_ROOT, path));
}
- private String parseTemplateName(String name)
- {
- if (!name.startsWith("data/"))
- {
- if (name.startsWith("html/"))
- {
- return "data/" + name;
- }
- else if (name.startsWith("CommunityBoard/"))
- {
- return "data/html/" + name;
- }
- else if (name.startsWith("scripts/"))
- {
- return "data/scripts/" + name;
- }
- }
- return name;
- }
-
- private String processHtml(String result)
- {
- final Matcher extendMatcher = EXTEND_PATTERN.matcher(result);
- if (extendMatcher.find())
- {
- // If extend matcher finds something, process template
- final String templateName = parseTemplateName(extendMatcher.group(1));
-
- // Generate block name -> content map
- final Map blockMap = generateBlockMap(result);
-
- // Attempt to find the template
- String template = getHtm(templateName + "-template.htm");
- if (template != null)
- {
- // Attempt to find the abstract blocks
- final Matcher blockMatcher = ABSTRACT_BLOCK_PATTERN.matcher(template);
- while (blockMatcher.find())
- {
- final String name = blockMatcher.group(1);
- if (!blockMap.containsKey(name))
- {
- LOGGER.warning(getClass().getSimpleName() + ": Abstract block definition [" + name + "] is not implemented!");
- continue;
- }
-
- // Replace the matched content with the block.
- template = template.replace(blockMatcher.group(0), blockMap.get(name));
- }
-
- // Replace the entire extend block
- result = result.replace(extendMatcher.group(0), template);
- }
- else
- {
- LOGGER.warning(getClass().getSimpleName() + ": Missing template: " + templateName + "-template.htm !");
- }
- }
-
- return result;
- }
-
- private Map generateBlockMap(String data)
- {
- final Map blockMap = new LinkedHashMap<>();
- final Matcher blockMatcher = BLOCK_PATTERN.matcher(data);
- while (blockMatcher.find())
- {
- final String name = blockMatcher.group(1);
- final String content = blockMatcher.group(2);
- blockMap.put(name, content);
- }
- return blockMap;
- }
-
public static HtmCache getInstance()
{
- return SingletonHolder._instance;
+ return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
- protected static final HtmCache _instance = new HtmCache();
+ protected static final HtmCache INSTANCE = new HtmCache();
}
}
diff --git a/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index e1b8d57d34..d2784acee5 100644
--- a/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -418,7 +418,7 @@ public final class PlayerInstance extends Playable
private Calendar _createDate = Calendar.getInstance();
private String _lang = null;
- private String _htmlPrefix = null;
+ private String _htmlPrefix = "";
private volatile boolean _isOnline = false;
private long _onlineTime;
@@ -12784,7 +12784,7 @@ public final class PlayerInstance extends Playable
{
if (!Config.MULTILANG_ENABLE)
{
- return null;
+ return "";
}
return _htmlPrefix;
@@ -12815,7 +12815,7 @@ public final class PlayerInstance extends Playable
else
{
_lang = null;
- _htmlPrefix = null;
+ _htmlPrefix = "";
}
return result;
diff --git a/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/model/quest/Quest.java b/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/model/quest/Quest.java
index 999ad014d8..e3f51b26a5 100644
--- a/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/model/quest/Quest.java
+++ b/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/model/quest/Quest.java
@@ -2763,7 +2763,7 @@ public class Quest extends AbstractScript implements IIdentifiable
content = hc.getHtm(player, "data/scripts/" + getPath() + "/" + fileName);
if (content == null)
{
- content = hc.getHtmForce(player, "data/scripts/quests/" + getName() + "/" + fileName);
+ content = hc.getHtm(player, "data/scripts/quests/" + getName() + "/" + fileName);
}
}
return content;
diff --git a/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java b/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
index 95409c567a..25a46c93b2 100644
--- a/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
+++ b/L2J_Mobius_5.5_EtinasFate/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
@@ -50,7 +50,7 @@ import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
public final class ScriptEngineManager implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
- public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
+ public static final Path SCRIPT_FOLDER = Config.SCRIPT_ROOT.toPath();
public static final Path MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "MasterHandler.java");
public static final Path EFFECT_MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "EffectMasterHandler.java");
public static final Path SKILL_CONDITION_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "SkillConditionMasterHandler.java");
diff --git a/L2J_Mobius_6.0_Fafurion/dist/game/config/General.ini b/L2J_Mobius_6.0_Fafurion/dist/game/config/General.ini
index 08b6846b63..aadbfcd534 100644
--- a/L2J_Mobius_6.0_Fafurion/dist/game/config/General.ini
+++ b/L2J_Mobius_6.0_Fafurion/dist/game/config/General.ini
@@ -246,8 +246,8 @@ ForceInventoryUpdate = False
# True = Load html's into cache only on first time html is requested.
# False = Load all html's into cache on server startup.
-# Default: True
-LazyCache = True
+# Default: False
+LazyCache = False
# Cache all character names in to memory on server startup
# False - names are loaded from Db when they are requested
diff --git a/L2J_Mobius_6.0_Fafurion/dist/game/config/Server.ini b/L2J_Mobius_6.0_Fafurion/dist/game/config/Server.ini
index 9262302184..130bec4905 100644
--- a/L2J_Mobius_6.0_Fafurion/dist/game/config/Server.ini
+++ b/L2J_Mobius_6.0_Fafurion/dist/game/config/Server.ini
@@ -94,6 +94,9 @@ AcceptAlternateID = True
# Default: .
DatapackRoot = .
+# Scripts root directory.
+ScriptRoot = ./data/scripts
+
# Define how many players are allowed to play simultaneously on your server.
# Default: 2000
MaximumOnlineUsers = 2000
diff --git a/L2J_Mobius_6.0_Fafurion/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java b/L2J_Mobius_6.0_Fafurion/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
index a650883032..0585478f14 100644
--- a/L2J_Mobius_6.0_Fafurion/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
+++ b/L2J_Mobius_6.0_Fafurion/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
@@ -220,7 +220,7 @@ public final class AdminPForge implements IAdminCommandHandler
private void showValuesPage(PlayerInstance activeChar, String[] opCodes, String format)
{
String sendBypass = null;
- String valuesHtml = HtmCache.getInstance().getHtmForce(activeChar, "data/html/admin/pforge/values.htm");
+ String valuesHtml = HtmCache.getInstance().getHtm(activeChar, "data/html/admin/pforge/values.htm");
if (opCodes.length == 3)
{
valuesHtml = valuesHtml.replace("%opformat%", "chd");
diff --git a/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/Config.java b/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/Config.java
index f230726d7a..59c1c1b4ee 100644
--- a/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/Config.java
@@ -734,6 +734,7 @@ public final class Config
public static String CLAN_NAME_TEMPLATE;
public static int MAX_CHARACTERS_NUMBER_PER_ACCOUNT;
public static File DATAPACK_ROOT;
+ public static File SCRIPT_ROOT;
public static boolean ACCEPT_ALTERNATE_ID;
public static int REQUEST_ID;
public static boolean RESERVE_HOST_ON_LOGIN = false;
@@ -1242,6 +1243,16 @@ public final class Config
DATAPACK_ROOT = new File(".");
}
+ try
+ {
+ SCRIPT_ROOT = new File(serverSettings.getString("ScriptRoot", "./data/scripts").replaceAll("\\\\", "/")).getCanonicalFile();
+ }
+ catch (Exception e)
+ {
+ LOGGER.log(Level.WARNING, "Error setting script root!", e);
+ SCRIPT_ROOT = new File(".");
+ }
+
Pattern charNamePattern;
try
diff --git a/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/cache/HtmCache.java b/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/cache/HtmCache.java
index f129626e80..3d8420f5c1 100644
--- a/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/cache/HtmCache.java
+++ b/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/cache/HtmCache.java
@@ -16,36 +16,31 @@
*/
package com.l2jmobius.gameserver.cache;
+import java.io.BufferedInputStream;
import java.io.File;
-import java.nio.charset.StandardCharsets;
+import java.io.FileInputStream;
import java.util.HashMap;
-import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import com.l2jmobius.Config;
import com.l2jmobius.commons.util.file.filter.HTMLFilter;
import com.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import com.l2jmobius.gameserver.util.BuilderUtil;
-import com.l2jmobius.gameserver.util.Util;
/**
* @author Layane
+ * @author Zoey76
*/
public class HtmCache
{
private static final Logger LOGGER = Logger.getLogger(HtmCache.class.getName());
private static final HTMLFilter HTML_FILTER = new HTMLFilter();
- private static final Pattern EXTEND_PATTERN = Pattern.compile("(.*?)", Pattern.DOTALL);
- private static final Pattern ABSTRACT_BLOCK_PATTERN = Pattern.compile("", Pattern.DOTALL);
- private static final Pattern BLOCK_PATTERN = Pattern.compile("(.*?)", Pattern.DOTALL);
- private static final Map _cache = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
+ private static final Map HTML_CACHE = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
private int _loadedFiles;
private long _bytesBuffLen;
@@ -66,14 +61,14 @@ public class HtmCache
{
LOGGER.info("Html cache start...");
parseDir(f);
- LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded");
+ LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded.");
}
else
{
- _cache.clear();
+ HTML_CACHE.clear();
_loadedFiles = 0;
_bytesBuffLen = 0;
- LOGGER.info("Cache[HTML]: Running lazy cache");
+ LOGGER.info("Cache[HTML]: Running lazy cache.");
}
}
@@ -114,86 +109,65 @@ public class HtmCache
public String loadFile(File file)
{
- if (HTML_FILTER.accept(file))
+ if (!HTML_FILTER.accept(file))
{
- try
+ return null;
+ }
+
+ String content = null;
+ try (FileInputStream fis = new FileInputStream(file);
+ BufferedInputStream bis = new BufferedInputStream(fis))
+ {
+ final int bytes = bis.available();
+ byte[] raw = new byte[bytes];
+
+ bis.read(raw);
+ content = new String(raw, "UTF-8");
+ content = content.replaceAll("(?s)", ""); // Remove html comments
+
+ final String oldContent = HTML_CACHE.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
+ if (oldContent == null)
{
- String content = processHtml(Util.readAllLines(file, StandardCharsets.UTF_8, null));
- content = content.replaceAll("(?s)", ""); // Remove html comments
- // content = content.replaceAll("\r", "").replaceAll("\n", ""); // Remove new lines
-
- final String oldContent = _cache.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
- if (oldContent == null)
- {
- _bytesBuffLen += content.length() * 2;
- _loadedFiles++;
- }
- else
- {
- _bytesBuffLen = (_bytesBuffLen - oldContent.length()) + (content.length() * 2);
- }
- return content;
+ _bytesBuffLen += bytes;
+ _loadedFiles++;
}
- catch (Exception e)
+ else
{
- LOGGER.log(Level.WARNING, "Problem with htm file:", e);
+ _bytesBuffLen = (_bytesBuffLen - oldContent.length()) + bytes;
}
}
- return null;
- }
-
- public String getHtmForce(PlayerInstance player, String path)
- {
- String content = getHtm(player, path);
- if (content == null)
+ catch (Exception e)
{
- content = "My text is missing:
" + path + "";
- LOGGER.warning("Cache[HTML]: Missing HTML page: " + path);
+ LOGGER.log(Level.WARNING, "Problem with htm file:", e);
}
return content;
}
public String getHtm(PlayerInstance player, String path)
{
- final String prefix = player != null ? player.getHtmlPrefix() : "en";
- String newPath = null;
- String content;
- if ((prefix != null) && !prefix.isEmpty())
+ final String prefix = player != null ? player.getHtmlPrefix() : "";
+ final String newPath = prefix + path;
+ String content = HTML_CACHE.get(newPath);
+ if (Config.LAZY_CACHE && (content == null))
{
- newPath = prefix + path;
- content = getHtm(newPath);
- if (content != null)
+ content = loadFile(new File(Config.DATAPACK_ROOT, newPath));
+ if (content == null)
{
- if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
- }
- return content;
+ content = loadFile(new File(Config.SCRIPT_ROOT, newPath));
}
}
- content = getHtm(path);
- if ((content != null) && (newPath != null))
+ if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
{
- _cache.put(newPath, content);
+ BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
}
- if ((player != null) && player.isGM() && (path != null) && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, path.substring(5));
- }
return content;
}
- private String getHtm(String path)
- {
- // TODO: Check why some files do not get in cache on server startup.
- return (path == null) || path.isEmpty() ? "" : _cache.get(path) == null ? loadFile(new File(Config.DATAPACK_ROOT, path)) : _cache.get(path);
- }
-
public boolean contains(String path)
{
- return _cache.containsKey(path);
+ return HTML_CACHE.containsKey(path);
}
/**
@@ -205,88 +179,13 @@ public class HtmCache
return HTML_FILTER.accept(new File(Config.DATAPACK_ROOT, path));
}
- private String parseTemplateName(String name)
- {
- if (!name.startsWith("data/"))
- {
- if (name.startsWith("html/"))
- {
- return "data/" + name;
- }
- else if (name.startsWith("CommunityBoard/"))
- {
- return "data/html/" + name;
- }
- else if (name.startsWith("scripts/"))
- {
- return "data/scripts/" + name;
- }
- }
- return name;
- }
-
- private String processHtml(String result)
- {
- final Matcher extendMatcher = EXTEND_PATTERN.matcher(result);
- if (extendMatcher.find())
- {
- // If extend matcher finds something, process template
- final String templateName = parseTemplateName(extendMatcher.group(1));
-
- // Generate block name -> content map
- final Map blockMap = generateBlockMap(result);
-
- // Attempt to find the template
- String template = getHtm(templateName + "-template.htm");
- if (template != null)
- {
- // Attempt to find the abstract blocks
- final Matcher blockMatcher = ABSTRACT_BLOCK_PATTERN.matcher(template);
- while (blockMatcher.find())
- {
- final String name = blockMatcher.group(1);
- if (!blockMap.containsKey(name))
- {
- LOGGER.warning(getClass().getSimpleName() + ": Abstract block definition [" + name + "] is not implemented!");
- continue;
- }
-
- // Replace the matched content with the block.
- template = template.replace(blockMatcher.group(0), blockMap.get(name));
- }
-
- // Replace the entire extend block
- result = result.replace(extendMatcher.group(0), template);
- }
- else
- {
- LOGGER.warning(getClass().getSimpleName() + ": Missing template: " + templateName + "-template.htm !");
- }
- }
-
- return result;
- }
-
- private Map generateBlockMap(String data)
- {
- final Map blockMap = new LinkedHashMap<>();
- final Matcher blockMatcher = BLOCK_PATTERN.matcher(data);
- while (blockMatcher.find())
- {
- final String name = blockMatcher.group(1);
- final String content = blockMatcher.group(2);
- blockMap.put(name, content);
- }
- return blockMap;
- }
-
public static HtmCache getInstance()
{
- return SingletonHolder._instance;
+ return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
- protected static final HtmCache _instance = new HtmCache();
+ protected static final HtmCache INSTANCE = new HtmCache();
}
}
diff --git a/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index 8010f04293..7bc22d782c 100644
--- a/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -418,7 +418,7 @@ public final class PlayerInstance extends Playable
private Calendar _createDate = Calendar.getInstance();
private String _lang = null;
- private String _htmlPrefix = null;
+ private String _htmlPrefix = "";
private volatile boolean _isOnline = false;
private long _onlineTime;
@@ -12790,7 +12790,7 @@ public final class PlayerInstance extends Playable
{
if (!Config.MULTILANG_ENABLE)
{
- return null;
+ return "";
}
return _htmlPrefix;
@@ -12821,7 +12821,7 @@ public final class PlayerInstance extends Playable
else
{
_lang = null;
- _htmlPrefix = null;
+ _htmlPrefix = "";
}
return result;
diff --git a/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/model/quest/Quest.java b/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/model/quest/Quest.java
index 999ad014d8..e3f51b26a5 100644
--- a/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/model/quest/Quest.java
+++ b/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/model/quest/Quest.java
@@ -2763,7 +2763,7 @@ public class Quest extends AbstractScript implements IIdentifiable
content = hc.getHtm(player, "data/scripts/" + getPath() + "/" + fileName);
if (content == null)
{
- content = hc.getHtmForce(player, "data/scripts/quests/" + getName() + "/" + fileName);
+ content = hc.getHtm(player, "data/scripts/quests/" + getName() + "/" + fileName);
}
}
return content;
diff --git a/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java b/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
index 95409c567a..25a46c93b2 100644
--- a/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
+++ b/L2J_Mobius_6.0_Fafurion/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
@@ -50,7 +50,7 @@ import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
public final class ScriptEngineManager implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
- public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
+ public static final Path SCRIPT_FOLDER = Config.SCRIPT_ROOT.toPath();
public static final Path MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "MasterHandler.java");
public static final Path EFFECT_MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "EffectMasterHandler.java");
public static final Path SKILL_CONDITION_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "SkillConditionMasterHandler.java");
diff --git a/L2J_Mobius_CT_2.6_HighFive/dist/game/config/General.ini b/L2J_Mobius_CT_2.6_HighFive/dist/game/config/General.ini
index babef8246a..2ca87e22c2 100644
--- a/L2J_Mobius_CT_2.6_HighFive/dist/game/config/General.ini
+++ b/L2J_Mobius_CT_2.6_HighFive/dist/game/config/General.ini
@@ -235,7 +235,7 @@ ForceInventoryUpdate = False
# True = Load html's into cache only on first time html is requested.
# False = Load all html's into cache on server startup.
-# Default: True
+# Default: False
LazyCache = False
# Cache all character names in to memory on server startup
diff --git a/L2J_Mobius_CT_2.6_HighFive/dist/game/config/Server.ini b/L2J_Mobius_CT_2.6_HighFive/dist/game/config/Server.ini
index b33d9e8a8f..b3a51ce2f5 100644
--- a/L2J_Mobius_CT_2.6_HighFive/dist/game/config/Server.ini
+++ b/L2J_Mobius_CT_2.6_HighFive/dist/game/config/Server.ini
@@ -94,6 +94,9 @@ AcceptAlternateID = True
# Default: .
DatapackRoot = .
+# Scripts root directory.
+ScriptRoot = ./data/scripts
+
# Define how many players are allowed to play simultaneously on your server.
# Default: 2000
MaximumOnlineUsers = 2000
diff --git a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
index eb9a99739f..73ec86785b 100644
--- a/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
+++ b/L2J_Mobius_CT_2.6_HighFive/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
@@ -221,7 +221,7 @@ public final class AdminPForge implements IAdminCommandHandler
private void showValuesPage(PlayerInstance activeChar, String[] opCodes, String format)
{
String sendBypass = null;
- String valuesHtml = HtmCache.getInstance().getHtmForce(activeChar, "data/html/admin/pforge/values.htm");
+ String valuesHtml = HtmCache.getInstance().getHtm(activeChar, "data/html/admin/pforge/values.htm");
if (opCodes.length == 3)
{
valuesHtml = valuesHtml.replace("%opformat%", "chd");
diff --git a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/Config.java b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/Config.java
index ccf0a6efb5..cb83db96f9 100644
--- a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/Config.java
@@ -874,6 +874,7 @@ public final class Config
public static String CLAN_NAME_TEMPLATE;
public static int MAX_CHARACTERS_NUMBER_PER_ACCOUNT;
public static File DATAPACK_ROOT;
+ public static File SCRIPT_ROOT;
public static boolean ACCEPT_ALTERNATE_ID;
public static int REQUEST_ID;
public static boolean RESERVE_HOST_ON_LOGIN = false;
@@ -1404,6 +1405,16 @@ public final class Config
DATAPACK_ROOT = new File(".");
}
+ try
+ {
+ SCRIPT_ROOT = new File(serverSettings.getString("ScriptRoot", "./data/scripts").replaceAll("\\\\", "/")).getCanonicalFile();
+ }
+ catch (Exception e)
+ {
+ LOGGER.log(Level.WARNING, "Error setting script root!", e);
+ SCRIPT_ROOT = new File(".");
+ }
+
Pattern charNamePattern;
try
diff --git a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/cache/HtmCache.java b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/cache/HtmCache.java
index e06105718b..bf88bb890e 100644
--- a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/cache/HtmCache.java
+++ b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/cache/HtmCache.java
@@ -29,10 +29,10 @@ import com.l2jmobius.Config;
import com.l2jmobius.commons.util.file.filter.HTMLFilter;
import com.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import com.l2jmobius.gameserver.util.BuilderUtil;
-import com.l2jmobius.gameserver.util.Util;
/**
* @author Layane
+ * @author Zoey76
*/
public class HtmCache
{
@@ -40,7 +40,7 @@ public class HtmCache
private static final HTMLFilter HTML_FILTER = new HTMLFilter();
- private static final Map _cache = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
+ private static final Map HTML_CACHE = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
private int _loadedFiles;
private long _bytesBuffLen;
@@ -61,14 +61,14 @@ public class HtmCache
{
LOGGER.info("Html cache start...");
parseDir(f);
- LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded");
+ LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded.");
}
else
{
- _cache.clear();
+ HTML_CACHE.clear();
_loadedFiles = 0;
_bytesBuffLen = 0;
- LOGGER.info("Cache[HTML]: Running lazy cache");
+ LOGGER.info("Cache[HTML]: Running lazy cache.");
}
}
@@ -114,19 +114,18 @@ public class HtmCache
return null;
}
- final String relpath = Util.getRelativePath(Config.DATAPACK_ROOT, file);
String content = null;
try (FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis))
{
final int bytes = bis.available();
- final byte[] raw = new byte[bytes];
+ byte[] raw = new byte[bytes];
bis.read(raw);
content = new String(raw, "UTF-8");
content = content.replaceAll("(?s)", ""); // Remove html comments
- final String oldContent = _cache.put(relpath, content);
+ final String oldContent = HTML_CACHE.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
if (oldContent == null)
{
_bytesBuffLen += bytes;
@@ -139,63 +138,36 @@ public class HtmCache
}
catch (Exception e)
{
- LOGGER.log(Level.WARNING, "Problem with htm file " + e.getMessage(), e);
- }
- return content;
- }
-
- public String getHtmForce(PlayerInstance player, String path)
- {
- String content = getHtm(player, path);
- if (content == null)
- {
- content = "My text is missing:
" + path + "";
- LOGGER.warning("Cache[HTML]: Missing HTML page: " + path);
+ LOGGER.log(Level.WARNING, "Problem with htm file:", e);
}
return content;
}
public String getHtm(PlayerInstance player, String path)
{
- final String prefix = player != null ? player.getHtmlPrefix() : "en";
- String newPath = null;
- String content;
- if ((prefix != null) && !prefix.isEmpty())
+ final String prefix = player != null ? player.getHtmlPrefix() : "";
+ final String newPath = prefix + path;
+ String content = HTML_CACHE.get(newPath);
+ if (Config.LAZY_CACHE && (content == null))
{
- newPath = prefix + path;
- content = getHtm(newPath);
- if (content != null)
+ content = loadFile(new File(Config.DATAPACK_ROOT, newPath));
+ if (content == null)
{
- if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
- }
- return content;
+ content = loadFile(new File(Config.SCRIPT_ROOT, newPath));
}
}
- content = getHtm(path);
- if ((content != null) && (newPath != null))
+ if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
{
- _cache.put(newPath, content);
+ BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
}
- if ((player != null) && player.isGM() && (path != null) && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, path.substring(5));
- }
return content;
}
- private String getHtm(String path)
- {
- // TODO: Check why some files do not get in cache on server startup.
- return (path == null) || path.isEmpty() ? "" : _cache.get(path) == null ? loadFile(new File(Config.DATAPACK_ROOT, path)) : _cache.get(path);
- }
-
public boolean contains(String path)
{
- return _cache.containsKey(path);
+ return HTML_CACHE.containsKey(path);
}
/**
@@ -209,11 +181,11 @@ public class HtmCache
public static HtmCache getInstance()
{
- return SingletonHolder._instance;
+ return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
- protected static final HtmCache _instance = new HtmCache();
+ protected static final HtmCache INSTANCE = new HtmCache();
}
}
diff --git a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/actor/Npc.java b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/actor/Npc.java
index 75bd374af5..7e4cca76a7 100644
--- a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/actor/Npc.java
+++ b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/actor/Npc.java
@@ -844,12 +844,9 @@ public class Npc extends Creature
return temp;
}
}
- else
+ else if (HtmCache.getInstance().isLoadable(temp))
{
- if (HtmCache.getInstance().isLoadable(temp))
- {
- return temp;
- }
+ return temp;
}
// If the file is not found, the standard message "I have nothing to say to you" is returned
diff --git a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index ebfef58d89..079a340068 100644
--- a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -415,7 +415,7 @@ public final class PlayerInstance extends Playable
private Calendar _createDate = Calendar.getInstance();
private String _lang = null;
- private String _htmlPrefix = null;
+ private String _htmlPrefix = "";
private volatile boolean _isOnline = false;
private long _onlineTime;
@@ -13718,7 +13718,7 @@ public final class PlayerInstance extends Playable
public String getHtmlPrefix()
{
- return Config.MULTILANG_ENABLE ? _htmlPrefix : null;
+ return Config.MULTILANG_ENABLE ? _htmlPrefix : "";
}
public String getLang()
@@ -13746,7 +13746,7 @@ public final class PlayerInstance extends Playable
else
{
_lang = null;
- _htmlPrefix = null;
+ _htmlPrefix = "";
}
return result;
diff --git a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/quest/Quest.java b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/quest/Quest.java
index 0f8c8936fb..810b8f2730 100644
--- a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/quest/Quest.java
+++ b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/model/quest/Quest.java
@@ -2491,7 +2491,7 @@ public class Quest extends AbstractScript implements IIdentifiable
content = hc.getHtm(player, "data/scripts/" + getPath() + "/" + fileName);
if (content == null)
{
- content = hc.getHtmForce(player, "data/scripts/quests/" + getName() + "/" + fileName);
+ content = hc.getHtm(player, "data/scripts/quests/" + getName() + "/" + fileName);
}
}
return content;
diff --git a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
index 648c891242..ad71eabbd4 100644
--- a/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
+++ b/L2J_Mobius_CT_2.6_HighFive/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
@@ -50,7 +50,7 @@ import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
public final class ScriptEngineManager implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
- public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
+ public static final Path SCRIPT_FOLDER = Config.SCRIPT_ROOT.toPath();
public static final Path MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "MasterHandler.java");
public static final Path EFFECT_MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "EffectMasterHandler.java");
@@ -201,7 +201,7 @@ public final class ScriptEngineManager implements IXmlReader
final Map invokationErrors = _javaExecutionContext.executeScripts(files);
for (Entry entry : invokationErrors.entrySet())
- {
+ {
LOGGER.log(Level.WARNING, "ScriptEngine: " + entry.getKey() + " failed execution!", entry.getValue());
}
}
diff --git a/L2J_Mobius_Classic_2.0_Saviors/dist/game/config/General.ini b/L2J_Mobius_Classic_2.0_Saviors/dist/game/config/General.ini
index 933faf5131..595ab5efae 100644
--- a/L2J_Mobius_Classic_2.0_Saviors/dist/game/config/General.ini
+++ b/L2J_Mobius_Classic_2.0_Saviors/dist/game/config/General.ini
@@ -246,8 +246,8 @@ ForceInventoryUpdate = False
# True = Load html's into cache only on first time html is requested.
# False = Load all html's into cache on server startup.
-# Default: True
-LazyCache = True
+# Default: False
+LazyCache = False
# Cache all character names in to memory on server startup
# False - names are loaded from Db when they are requested
diff --git a/L2J_Mobius_Classic_2.0_Saviors/dist/game/config/Server.ini b/L2J_Mobius_Classic_2.0_Saviors/dist/game/config/Server.ini
index 22449647f1..31421caf8c 100644
--- a/L2J_Mobius_Classic_2.0_Saviors/dist/game/config/Server.ini
+++ b/L2J_Mobius_Classic_2.0_Saviors/dist/game/config/Server.ini
@@ -94,6 +94,9 @@ AcceptAlternateID = True
# Default: .
DatapackRoot = .
+# Scripts root directory.
+ScriptRoot = ./data/scripts
+
# Define how many players are allowed to play simultaneously on your server.
# Default: 2000
MaximumOnlineUsers = 2000
diff --git a/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java b/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
index a650883032..0585478f14 100644
--- a/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
+++ b/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
@@ -220,7 +220,7 @@ public final class AdminPForge implements IAdminCommandHandler
private void showValuesPage(PlayerInstance activeChar, String[] opCodes, String format)
{
String sendBypass = null;
- String valuesHtml = HtmCache.getInstance().getHtmForce(activeChar, "data/html/admin/pforge/values.htm");
+ String valuesHtml = HtmCache.getInstance().getHtm(activeChar, "data/html/admin/pforge/values.htm");
if (opCodes.length == 3)
{
valuesHtml = valuesHtml.replace("%opformat%", "chd");
diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/Config.java b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/Config.java
index fdbf84a660..16bb239d39 100644
--- a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/Config.java
@@ -742,6 +742,7 @@ public final class Config
public static String CLAN_NAME_TEMPLATE;
public static int MAX_CHARACTERS_NUMBER_PER_ACCOUNT;
public static File DATAPACK_ROOT;
+ public static File SCRIPT_ROOT;
public static boolean ACCEPT_ALTERNATE_ID;
public static int REQUEST_ID;
public static boolean RESERVE_HOST_ON_LOGIN = false;
@@ -1179,6 +1180,16 @@ public final class Config
DATAPACK_ROOT = new File(".");
}
+ try
+ {
+ SCRIPT_ROOT = new File(serverSettings.getString("ScriptRoot", "./data/scripts").replaceAll("\\\\", "/")).getCanonicalFile();
+ }
+ catch (Exception e)
+ {
+ LOGGER.log(Level.WARNING, "Error setting script root!", e);
+ SCRIPT_ROOT = new File(".");
+ }
+
Pattern charNamePattern;
try
diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/cache/HtmCache.java b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/cache/HtmCache.java
index f129626e80..3d8420f5c1 100644
--- a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/cache/HtmCache.java
+++ b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/cache/HtmCache.java
@@ -16,36 +16,31 @@
*/
package com.l2jmobius.gameserver.cache;
+import java.io.BufferedInputStream;
import java.io.File;
-import java.nio.charset.StandardCharsets;
+import java.io.FileInputStream;
import java.util.HashMap;
-import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import com.l2jmobius.Config;
import com.l2jmobius.commons.util.file.filter.HTMLFilter;
import com.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import com.l2jmobius.gameserver.util.BuilderUtil;
-import com.l2jmobius.gameserver.util.Util;
/**
* @author Layane
+ * @author Zoey76
*/
public class HtmCache
{
private static final Logger LOGGER = Logger.getLogger(HtmCache.class.getName());
private static final HTMLFilter HTML_FILTER = new HTMLFilter();
- private static final Pattern EXTEND_PATTERN = Pattern.compile("(.*?)", Pattern.DOTALL);
- private static final Pattern ABSTRACT_BLOCK_PATTERN = Pattern.compile("", Pattern.DOTALL);
- private static final Pattern BLOCK_PATTERN = Pattern.compile("(.*?)", Pattern.DOTALL);
- private static final Map _cache = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
+ private static final Map HTML_CACHE = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
private int _loadedFiles;
private long _bytesBuffLen;
@@ -66,14 +61,14 @@ public class HtmCache
{
LOGGER.info("Html cache start...");
parseDir(f);
- LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded");
+ LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded.");
}
else
{
- _cache.clear();
+ HTML_CACHE.clear();
_loadedFiles = 0;
_bytesBuffLen = 0;
- LOGGER.info("Cache[HTML]: Running lazy cache");
+ LOGGER.info("Cache[HTML]: Running lazy cache.");
}
}
@@ -114,86 +109,65 @@ public class HtmCache
public String loadFile(File file)
{
- if (HTML_FILTER.accept(file))
+ if (!HTML_FILTER.accept(file))
{
- try
+ return null;
+ }
+
+ String content = null;
+ try (FileInputStream fis = new FileInputStream(file);
+ BufferedInputStream bis = new BufferedInputStream(fis))
+ {
+ final int bytes = bis.available();
+ byte[] raw = new byte[bytes];
+
+ bis.read(raw);
+ content = new String(raw, "UTF-8");
+ content = content.replaceAll("(?s)", ""); // Remove html comments
+
+ final String oldContent = HTML_CACHE.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
+ if (oldContent == null)
{
- String content = processHtml(Util.readAllLines(file, StandardCharsets.UTF_8, null));
- content = content.replaceAll("(?s)", ""); // Remove html comments
- // content = content.replaceAll("\r", "").replaceAll("\n", ""); // Remove new lines
-
- final String oldContent = _cache.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
- if (oldContent == null)
- {
- _bytesBuffLen += content.length() * 2;
- _loadedFiles++;
- }
- else
- {
- _bytesBuffLen = (_bytesBuffLen - oldContent.length()) + (content.length() * 2);
- }
- return content;
+ _bytesBuffLen += bytes;
+ _loadedFiles++;
}
- catch (Exception e)
+ else
{
- LOGGER.log(Level.WARNING, "Problem with htm file:", e);
+ _bytesBuffLen = (_bytesBuffLen - oldContent.length()) + bytes;
}
}
- return null;
- }
-
- public String getHtmForce(PlayerInstance player, String path)
- {
- String content = getHtm(player, path);
- if (content == null)
+ catch (Exception e)
{
- content = "My text is missing:
" + path + "";
- LOGGER.warning("Cache[HTML]: Missing HTML page: " + path);
+ LOGGER.log(Level.WARNING, "Problem with htm file:", e);
}
return content;
}
public String getHtm(PlayerInstance player, String path)
{
- final String prefix = player != null ? player.getHtmlPrefix() : "en";
- String newPath = null;
- String content;
- if ((prefix != null) && !prefix.isEmpty())
+ final String prefix = player != null ? player.getHtmlPrefix() : "";
+ final String newPath = prefix + path;
+ String content = HTML_CACHE.get(newPath);
+ if (Config.LAZY_CACHE && (content == null))
{
- newPath = prefix + path;
- content = getHtm(newPath);
- if (content != null)
+ content = loadFile(new File(Config.DATAPACK_ROOT, newPath));
+ if (content == null)
{
- if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
- }
- return content;
+ content = loadFile(new File(Config.SCRIPT_ROOT, newPath));
}
}
- content = getHtm(path);
- if ((content != null) && (newPath != null))
+ if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
{
- _cache.put(newPath, content);
+ BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
}
- if ((player != null) && player.isGM() && (path != null) && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, path.substring(5));
- }
return content;
}
- private String getHtm(String path)
- {
- // TODO: Check why some files do not get in cache on server startup.
- return (path == null) || path.isEmpty() ? "" : _cache.get(path) == null ? loadFile(new File(Config.DATAPACK_ROOT, path)) : _cache.get(path);
- }
-
public boolean contains(String path)
{
- return _cache.containsKey(path);
+ return HTML_CACHE.containsKey(path);
}
/**
@@ -205,88 +179,13 @@ public class HtmCache
return HTML_FILTER.accept(new File(Config.DATAPACK_ROOT, path));
}
- private String parseTemplateName(String name)
- {
- if (!name.startsWith("data/"))
- {
- if (name.startsWith("html/"))
- {
- return "data/" + name;
- }
- else if (name.startsWith("CommunityBoard/"))
- {
- return "data/html/" + name;
- }
- else if (name.startsWith("scripts/"))
- {
- return "data/scripts/" + name;
- }
- }
- return name;
- }
-
- private String processHtml(String result)
- {
- final Matcher extendMatcher = EXTEND_PATTERN.matcher(result);
- if (extendMatcher.find())
- {
- // If extend matcher finds something, process template
- final String templateName = parseTemplateName(extendMatcher.group(1));
-
- // Generate block name -> content map
- final Map blockMap = generateBlockMap(result);
-
- // Attempt to find the template
- String template = getHtm(templateName + "-template.htm");
- if (template != null)
- {
- // Attempt to find the abstract blocks
- final Matcher blockMatcher = ABSTRACT_BLOCK_PATTERN.matcher(template);
- while (blockMatcher.find())
- {
- final String name = blockMatcher.group(1);
- if (!blockMap.containsKey(name))
- {
- LOGGER.warning(getClass().getSimpleName() + ": Abstract block definition [" + name + "] is not implemented!");
- continue;
- }
-
- // Replace the matched content with the block.
- template = template.replace(blockMatcher.group(0), blockMap.get(name));
- }
-
- // Replace the entire extend block
- result = result.replace(extendMatcher.group(0), template);
- }
- else
- {
- LOGGER.warning(getClass().getSimpleName() + ": Missing template: " + templateName + "-template.htm !");
- }
- }
-
- return result;
- }
-
- private Map generateBlockMap(String data)
- {
- final Map blockMap = new LinkedHashMap<>();
- final Matcher blockMatcher = BLOCK_PATTERN.matcher(data);
- while (blockMatcher.find())
- {
- final String name = blockMatcher.group(1);
- final String content = blockMatcher.group(2);
- blockMap.put(name, content);
- }
- return blockMap;
- }
-
public static HtmCache getInstance()
{
- return SingletonHolder._instance;
+ return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
- protected static final HtmCache _instance = new HtmCache();
+ protected static final HtmCache INSTANCE = new HtmCache();
}
}
diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index 265fc6e442..d5cbf66e62 100644
--- a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -412,7 +412,7 @@ public final class PlayerInstance extends Playable
private Calendar _createDate = Calendar.getInstance();
private String _lang = null;
- private String _htmlPrefix = null;
+ private String _htmlPrefix = "";
private volatile boolean _isOnline = false;
private long _onlineTime;
@@ -12644,7 +12644,7 @@ public final class PlayerInstance extends Playable
{
if (!Config.MULTILANG_ENABLE)
{
- return null;
+ return "";
}
return _htmlPrefix;
@@ -12675,7 +12675,7 @@ public final class PlayerInstance extends Playable
else
{
_lang = null;
- _htmlPrefix = null;
+ _htmlPrefix = "";
}
return result;
diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/model/quest/Quest.java b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/model/quest/Quest.java
index 287e30a3fb..12549045da 100644
--- a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/model/quest/Quest.java
+++ b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/model/quest/Quest.java
@@ -2721,7 +2721,7 @@ public class Quest extends AbstractScript implements IIdentifiable
content = hc.getHtm(player, "data/scripts/" + getPath() + "/" + fileName);
if (content == null)
{
- content = hc.getHtmForce(player, "data/scripts/quests/" + getName() + "/" + fileName);
+ content = hc.getHtm(player, "data/scripts/quests/" + getName() + "/" + fileName);
}
}
return content;
diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
index 95409c567a..25a46c93b2 100644
--- a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
+++ b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
@@ -50,7 +50,7 @@ import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
public final class ScriptEngineManager implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
- public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
+ public static final Path SCRIPT_FOLDER = Config.SCRIPT_ROOT.toPath();
public static final Path MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "MasterHandler.java");
public static final Path EFFECT_MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "EffectMasterHandler.java");
public static final Path SKILL_CONDITION_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "SkillConditionMasterHandler.java");
diff --git a/L2J_Mobius_Classic_2.1_Zaken/dist/game/config/General.ini b/L2J_Mobius_Classic_2.1_Zaken/dist/game/config/General.ini
index 933faf5131..595ab5efae 100644
--- a/L2J_Mobius_Classic_2.1_Zaken/dist/game/config/General.ini
+++ b/L2J_Mobius_Classic_2.1_Zaken/dist/game/config/General.ini
@@ -246,8 +246,8 @@ ForceInventoryUpdate = False
# True = Load html's into cache only on first time html is requested.
# False = Load all html's into cache on server startup.
-# Default: True
-LazyCache = True
+# Default: False
+LazyCache = False
# Cache all character names in to memory on server startup
# False - names are loaded from Db when they are requested
diff --git a/L2J_Mobius_Classic_2.1_Zaken/dist/game/config/Server.ini b/L2J_Mobius_Classic_2.1_Zaken/dist/game/config/Server.ini
index 14a5f41c82..b9b9a3a410 100644
--- a/L2J_Mobius_Classic_2.1_Zaken/dist/game/config/Server.ini
+++ b/L2J_Mobius_Classic_2.1_Zaken/dist/game/config/Server.ini
@@ -94,6 +94,9 @@ AcceptAlternateID = True
# Default: .
DatapackRoot = .
+# Scripts root directory.
+ScriptRoot = ./data/scripts
+
# Define how many players are allowed to play simultaneously on your server.
# Default: 2000
MaximumOnlineUsers = 2000
diff --git a/L2J_Mobius_Classic_2.1_Zaken/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java b/L2J_Mobius_Classic_2.1_Zaken/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
index a650883032..0585478f14 100644
--- a/L2J_Mobius_Classic_2.1_Zaken/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
+++ b/L2J_Mobius_Classic_2.1_Zaken/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
@@ -220,7 +220,7 @@ public final class AdminPForge implements IAdminCommandHandler
private void showValuesPage(PlayerInstance activeChar, String[] opCodes, String format)
{
String sendBypass = null;
- String valuesHtml = HtmCache.getInstance().getHtmForce(activeChar, "data/html/admin/pforge/values.htm");
+ String valuesHtml = HtmCache.getInstance().getHtm(activeChar, "data/html/admin/pforge/values.htm");
if (opCodes.length == 3)
{
valuesHtml = valuesHtml.replace("%opformat%", "chd");
diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/Config.java b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/Config.java
index 2b33efbf5b..de82373b91 100644
--- a/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/Config.java
@@ -742,6 +742,7 @@ public final class Config
public static String CLAN_NAME_TEMPLATE;
public static int MAX_CHARACTERS_NUMBER_PER_ACCOUNT;
public static File DATAPACK_ROOT;
+ public static File SCRIPT_ROOT;
public static boolean ACCEPT_ALTERNATE_ID;
public static int REQUEST_ID;
public static boolean RESERVE_HOST_ON_LOGIN = false;
@@ -1183,6 +1184,16 @@ public final class Config
DATAPACK_ROOT = new File(".");
}
+ try
+ {
+ SCRIPT_ROOT = new File(serverSettings.getString("ScriptRoot", "./data/scripts").replaceAll("\\\\", "/")).getCanonicalFile();
+ }
+ catch (Exception e)
+ {
+ LOGGER.log(Level.WARNING, "Error setting script root!", e);
+ SCRIPT_ROOT = new File(".");
+ }
+
Pattern charNamePattern;
try
diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/cache/HtmCache.java b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/cache/HtmCache.java
index f129626e80..3d8420f5c1 100644
--- a/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/cache/HtmCache.java
+++ b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/cache/HtmCache.java
@@ -16,36 +16,31 @@
*/
package com.l2jmobius.gameserver.cache;
+import java.io.BufferedInputStream;
import java.io.File;
-import java.nio.charset.StandardCharsets;
+import java.io.FileInputStream;
import java.util.HashMap;
-import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import com.l2jmobius.Config;
import com.l2jmobius.commons.util.file.filter.HTMLFilter;
import com.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import com.l2jmobius.gameserver.util.BuilderUtil;
-import com.l2jmobius.gameserver.util.Util;
/**
* @author Layane
+ * @author Zoey76
*/
public class HtmCache
{
private static final Logger LOGGER = Logger.getLogger(HtmCache.class.getName());
private static final HTMLFilter HTML_FILTER = new HTMLFilter();
- private static final Pattern EXTEND_PATTERN = Pattern.compile("(.*?)", Pattern.DOTALL);
- private static final Pattern ABSTRACT_BLOCK_PATTERN = Pattern.compile("", Pattern.DOTALL);
- private static final Pattern BLOCK_PATTERN = Pattern.compile("(.*?)", Pattern.DOTALL);
- private static final Map _cache = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
+ private static final Map HTML_CACHE = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
private int _loadedFiles;
private long _bytesBuffLen;
@@ -66,14 +61,14 @@ public class HtmCache
{
LOGGER.info("Html cache start...");
parseDir(f);
- LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded");
+ LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded.");
}
else
{
- _cache.clear();
+ HTML_CACHE.clear();
_loadedFiles = 0;
_bytesBuffLen = 0;
- LOGGER.info("Cache[HTML]: Running lazy cache");
+ LOGGER.info("Cache[HTML]: Running lazy cache.");
}
}
@@ -114,86 +109,65 @@ public class HtmCache
public String loadFile(File file)
{
- if (HTML_FILTER.accept(file))
+ if (!HTML_FILTER.accept(file))
{
- try
+ return null;
+ }
+
+ String content = null;
+ try (FileInputStream fis = new FileInputStream(file);
+ BufferedInputStream bis = new BufferedInputStream(fis))
+ {
+ final int bytes = bis.available();
+ byte[] raw = new byte[bytes];
+
+ bis.read(raw);
+ content = new String(raw, "UTF-8");
+ content = content.replaceAll("(?s)", ""); // Remove html comments
+
+ final String oldContent = HTML_CACHE.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
+ if (oldContent == null)
{
- String content = processHtml(Util.readAllLines(file, StandardCharsets.UTF_8, null));
- content = content.replaceAll("(?s)", ""); // Remove html comments
- // content = content.replaceAll("\r", "").replaceAll("\n", ""); // Remove new lines
-
- final String oldContent = _cache.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
- if (oldContent == null)
- {
- _bytesBuffLen += content.length() * 2;
- _loadedFiles++;
- }
- else
- {
- _bytesBuffLen = (_bytesBuffLen - oldContent.length()) + (content.length() * 2);
- }
- return content;
+ _bytesBuffLen += bytes;
+ _loadedFiles++;
}
- catch (Exception e)
+ else
{
- LOGGER.log(Level.WARNING, "Problem with htm file:", e);
+ _bytesBuffLen = (_bytesBuffLen - oldContent.length()) + bytes;
}
}
- return null;
- }
-
- public String getHtmForce(PlayerInstance player, String path)
- {
- String content = getHtm(player, path);
- if (content == null)
+ catch (Exception e)
{
- content = "My text is missing:
" + path + "";
- LOGGER.warning("Cache[HTML]: Missing HTML page: " + path);
+ LOGGER.log(Level.WARNING, "Problem with htm file:", e);
}
return content;
}
public String getHtm(PlayerInstance player, String path)
{
- final String prefix = player != null ? player.getHtmlPrefix() : "en";
- String newPath = null;
- String content;
- if ((prefix != null) && !prefix.isEmpty())
+ final String prefix = player != null ? player.getHtmlPrefix() : "";
+ final String newPath = prefix + path;
+ String content = HTML_CACHE.get(newPath);
+ if (Config.LAZY_CACHE && (content == null))
{
- newPath = prefix + path;
- content = getHtm(newPath);
- if (content != null)
+ content = loadFile(new File(Config.DATAPACK_ROOT, newPath));
+ if (content == null)
{
- if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
- }
- return content;
+ content = loadFile(new File(Config.SCRIPT_ROOT, newPath));
}
}
- content = getHtm(path);
- if ((content != null) && (newPath != null))
+ if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
{
- _cache.put(newPath, content);
+ BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
}
- if ((player != null) && player.isGM() && (path != null) && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, path.substring(5));
- }
return content;
}
- private String getHtm(String path)
- {
- // TODO: Check why some files do not get in cache on server startup.
- return (path == null) || path.isEmpty() ? "" : _cache.get(path) == null ? loadFile(new File(Config.DATAPACK_ROOT, path)) : _cache.get(path);
- }
-
public boolean contains(String path)
{
- return _cache.containsKey(path);
+ return HTML_CACHE.containsKey(path);
}
/**
@@ -205,88 +179,13 @@ public class HtmCache
return HTML_FILTER.accept(new File(Config.DATAPACK_ROOT, path));
}
- private String parseTemplateName(String name)
- {
- if (!name.startsWith("data/"))
- {
- if (name.startsWith("html/"))
- {
- return "data/" + name;
- }
- else if (name.startsWith("CommunityBoard/"))
- {
- return "data/html/" + name;
- }
- else if (name.startsWith("scripts/"))
- {
- return "data/scripts/" + name;
- }
- }
- return name;
- }
-
- private String processHtml(String result)
- {
- final Matcher extendMatcher = EXTEND_PATTERN.matcher(result);
- if (extendMatcher.find())
- {
- // If extend matcher finds something, process template
- final String templateName = parseTemplateName(extendMatcher.group(1));
-
- // Generate block name -> content map
- final Map blockMap = generateBlockMap(result);
-
- // Attempt to find the template
- String template = getHtm(templateName + "-template.htm");
- if (template != null)
- {
- // Attempt to find the abstract blocks
- final Matcher blockMatcher = ABSTRACT_BLOCK_PATTERN.matcher(template);
- while (blockMatcher.find())
- {
- final String name = blockMatcher.group(1);
- if (!blockMap.containsKey(name))
- {
- LOGGER.warning(getClass().getSimpleName() + ": Abstract block definition [" + name + "] is not implemented!");
- continue;
- }
-
- // Replace the matched content with the block.
- template = template.replace(blockMatcher.group(0), blockMap.get(name));
- }
-
- // Replace the entire extend block
- result = result.replace(extendMatcher.group(0), template);
- }
- else
- {
- LOGGER.warning(getClass().getSimpleName() + ": Missing template: " + templateName + "-template.htm !");
- }
- }
-
- return result;
- }
-
- private Map generateBlockMap(String data)
- {
- final Map blockMap = new LinkedHashMap<>();
- final Matcher blockMatcher = BLOCK_PATTERN.matcher(data);
- while (blockMatcher.find())
- {
- final String name = blockMatcher.group(1);
- final String content = blockMatcher.group(2);
- blockMap.put(name, content);
- }
- return blockMap;
- }
-
public static HtmCache getInstance()
{
- return SingletonHolder._instance;
+ return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
- protected static final HtmCache _instance = new HtmCache();
+ protected static final HtmCache INSTANCE = new HtmCache();
}
}
diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index 04406690c1..ca252c906a 100644
--- a/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -412,7 +412,7 @@ public final class PlayerInstance extends Playable
private Calendar _createDate = Calendar.getInstance();
private String _lang = null;
- private String _htmlPrefix = null;
+ private String _htmlPrefix = "";
private volatile boolean _isOnline = false;
private long _onlineTime;
@@ -12651,7 +12651,7 @@ public final class PlayerInstance extends Playable
{
if (!Config.MULTILANG_ENABLE)
{
- return null;
+ return "";
}
return _htmlPrefix;
@@ -12682,7 +12682,7 @@ public final class PlayerInstance extends Playable
else
{
_lang = null;
- _htmlPrefix = null;
+ _htmlPrefix = "";
}
return result;
diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/model/quest/Quest.java b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/model/quest/Quest.java
index 287e30a3fb..12549045da 100644
--- a/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/model/quest/Quest.java
+++ b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/model/quest/Quest.java
@@ -2721,7 +2721,7 @@ public class Quest extends AbstractScript implements IIdentifiable
content = hc.getHtm(player, "data/scripts/" + getPath() + "/" + fileName);
if (content == null)
{
- content = hc.getHtmForce(player, "data/scripts/quests/" + getName() + "/" + fileName);
+ content = hc.getHtm(player, "data/scripts/quests/" + getName() + "/" + fileName);
}
}
return content;
diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
index 95409c567a..25a46c93b2 100644
--- a/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
+++ b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
@@ -50,7 +50,7 @@ import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
public final class ScriptEngineManager implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
- public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
+ public static final Path SCRIPT_FOLDER = Config.SCRIPT_ROOT.toPath();
public static final Path MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "MasterHandler.java");
public static final Path EFFECT_MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "EffectMasterHandler.java");
public static final Path SKILL_CONDITION_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "SkillConditionMasterHandler.java");
diff --git a/L2J_Mobius_Classic_2.2_Antharas/dist/game/config/General.ini b/L2J_Mobius_Classic_2.2_Antharas/dist/game/config/General.ini
index 933faf5131..595ab5efae 100644
--- a/L2J_Mobius_Classic_2.2_Antharas/dist/game/config/General.ini
+++ b/L2J_Mobius_Classic_2.2_Antharas/dist/game/config/General.ini
@@ -246,8 +246,8 @@ ForceInventoryUpdate = False
# True = Load html's into cache only on first time html is requested.
# False = Load all html's into cache on server startup.
-# Default: True
-LazyCache = True
+# Default: False
+LazyCache = False
# Cache all character names in to memory on server startup
# False - names are loaded from Db when they are requested
diff --git a/L2J_Mobius_Classic_2.2_Antharas/dist/game/config/Server.ini b/L2J_Mobius_Classic_2.2_Antharas/dist/game/config/Server.ini
index d036ae7b0f..d90f087b01 100644
--- a/L2J_Mobius_Classic_2.2_Antharas/dist/game/config/Server.ini
+++ b/L2J_Mobius_Classic_2.2_Antharas/dist/game/config/Server.ini
@@ -94,6 +94,9 @@ AcceptAlternateID = True
# Default: .
DatapackRoot = .
+# Scripts root directory.
+ScriptRoot = ./data/scripts
+
# Define how many players are allowed to play simultaneously on your server.
# Default: 2000
MaximumOnlineUsers = 2000
diff --git a/L2J_Mobius_Classic_2.2_Antharas/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java b/L2J_Mobius_Classic_2.2_Antharas/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
index a650883032..0585478f14 100644
--- a/L2J_Mobius_Classic_2.2_Antharas/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
+++ b/L2J_Mobius_Classic_2.2_Antharas/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
@@ -220,7 +220,7 @@ public final class AdminPForge implements IAdminCommandHandler
private void showValuesPage(PlayerInstance activeChar, String[] opCodes, String format)
{
String sendBypass = null;
- String valuesHtml = HtmCache.getInstance().getHtmForce(activeChar, "data/html/admin/pforge/values.htm");
+ String valuesHtml = HtmCache.getInstance().getHtm(activeChar, "data/html/admin/pforge/values.htm");
if (opCodes.length == 3)
{
valuesHtml = valuesHtml.replace("%opformat%", "chd");
diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/Config.java b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/Config.java
index 2b33efbf5b..de82373b91 100644
--- a/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/Config.java
@@ -742,6 +742,7 @@ public final class Config
public static String CLAN_NAME_TEMPLATE;
public static int MAX_CHARACTERS_NUMBER_PER_ACCOUNT;
public static File DATAPACK_ROOT;
+ public static File SCRIPT_ROOT;
public static boolean ACCEPT_ALTERNATE_ID;
public static int REQUEST_ID;
public static boolean RESERVE_HOST_ON_LOGIN = false;
@@ -1183,6 +1184,16 @@ public final class Config
DATAPACK_ROOT = new File(".");
}
+ try
+ {
+ SCRIPT_ROOT = new File(serverSettings.getString("ScriptRoot", "./data/scripts").replaceAll("\\\\", "/")).getCanonicalFile();
+ }
+ catch (Exception e)
+ {
+ LOGGER.log(Level.WARNING, "Error setting script root!", e);
+ SCRIPT_ROOT = new File(".");
+ }
+
Pattern charNamePattern;
try
diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/cache/HtmCache.java b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/cache/HtmCache.java
index f129626e80..3d8420f5c1 100644
--- a/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/cache/HtmCache.java
+++ b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/cache/HtmCache.java
@@ -16,36 +16,31 @@
*/
package com.l2jmobius.gameserver.cache;
+import java.io.BufferedInputStream;
import java.io.File;
-import java.nio.charset.StandardCharsets;
+import java.io.FileInputStream;
import java.util.HashMap;
-import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import com.l2jmobius.Config;
import com.l2jmobius.commons.util.file.filter.HTMLFilter;
import com.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import com.l2jmobius.gameserver.util.BuilderUtil;
-import com.l2jmobius.gameserver.util.Util;
/**
* @author Layane
+ * @author Zoey76
*/
public class HtmCache
{
private static final Logger LOGGER = Logger.getLogger(HtmCache.class.getName());
private static final HTMLFilter HTML_FILTER = new HTMLFilter();
- private static final Pattern EXTEND_PATTERN = Pattern.compile("(.*?)", Pattern.DOTALL);
- private static final Pattern ABSTRACT_BLOCK_PATTERN = Pattern.compile("", Pattern.DOTALL);
- private static final Pattern BLOCK_PATTERN = Pattern.compile("(.*?)", Pattern.DOTALL);
- private static final Map _cache = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
+ private static final Map HTML_CACHE = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
private int _loadedFiles;
private long _bytesBuffLen;
@@ -66,14 +61,14 @@ public class HtmCache
{
LOGGER.info("Html cache start...");
parseDir(f);
- LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded");
+ LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded.");
}
else
{
- _cache.clear();
+ HTML_CACHE.clear();
_loadedFiles = 0;
_bytesBuffLen = 0;
- LOGGER.info("Cache[HTML]: Running lazy cache");
+ LOGGER.info("Cache[HTML]: Running lazy cache.");
}
}
@@ -114,86 +109,65 @@ public class HtmCache
public String loadFile(File file)
{
- if (HTML_FILTER.accept(file))
+ if (!HTML_FILTER.accept(file))
{
- try
+ return null;
+ }
+
+ String content = null;
+ try (FileInputStream fis = new FileInputStream(file);
+ BufferedInputStream bis = new BufferedInputStream(fis))
+ {
+ final int bytes = bis.available();
+ byte[] raw = new byte[bytes];
+
+ bis.read(raw);
+ content = new String(raw, "UTF-8");
+ content = content.replaceAll("(?s)", ""); // Remove html comments
+
+ final String oldContent = HTML_CACHE.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
+ if (oldContent == null)
{
- String content = processHtml(Util.readAllLines(file, StandardCharsets.UTF_8, null));
- content = content.replaceAll("(?s)", ""); // Remove html comments
- // content = content.replaceAll("\r", "").replaceAll("\n", ""); // Remove new lines
-
- final String oldContent = _cache.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
- if (oldContent == null)
- {
- _bytesBuffLen += content.length() * 2;
- _loadedFiles++;
- }
- else
- {
- _bytesBuffLen = (_bytesBuffLen - oldContent.length()) + (content.length() * 2);
- }
- return content;
+ _bytesBuffLen += bytes;
+ _loadedFiles++;
}
- catch (Exception e)
+ else
{
- LOGGER.log(Level.WARNING, "Problem with htm file:", e);
+ _bytesBuffLen = (_bytesBuffLen - oldContent.length()) + bytes;
}
}
- return null;
- }
-
- public String getHtmForce(PlayerInstance player, String path)
- {
- String content = getHtm(player, path);
- if (content == null)
+ catch (Exception e)
{
- content = "My text is missing:
" + path + "";
- LOGGER.warning("Cache[HTML]: Missing HTML page: " + path);
+ LOGGER.log(Level.WARNING, "Problem with htm file:", e);
}
return content;
}
public String getHtm(PlayerInstance player, String path)
{
- final String prefix = player != null ? player.getHtmlPrefix() : "en";
- String newPath = null;
- String content;
- if ((prefix != null) && !prefix.isEmpty())
+ final String prefix = player != null ? player.getHtmlPrefix() : "";
+ final String newPath = prefix + path;
+ String content = HTML_CACHE.get(newPath);
+ if (Config.LAZY_CACHE && (content == null))
{
- newPath = prefix + path;
- content = getHtm(newPath);
- if (content != null)
+ content = loadFile(new File(Config.DATAPACK_ROOT, newPath));
+ if (content == null)
{
- if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
- }
- return content;
+ content = loadFile(new File(Config.SCRIPT_ROOT, newPath));
}
}
- content = getHtm(path);
- if ((content != null) && (newPath != null))
+ if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
{
- _cache.put(newPath, content);
+ BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
}
- if ((player != null) && player.isGM() && (path != null) && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, path.substring(5));
- }
return content;
}
- private String getHtm(String path)
- {
- // TODO: Check why some files do not get in cache on server startup.
- return (path == null) || path.isEmpty() ? "" : _cache.get(path) == null ? loadFile(new File(Config.DATAPACK_ROOT, path)) : _cache.get(path);
- }
-
public boolean contains(String path)
{
- return _cache.containsKey(path);
+ return HTML_CACHE.containsKey(path);
}
/**
@@ -205,88 +179,13 @@ public class HtmCache
return HTML_FILTER.accept(new File(Config.DATAPACK_ROOT, path));
}
- private String parseTemplateName(String name)
- {
- if (!name.startsWith("data/"))
- {
- if (name.startsWith("html/"))
- {
- return "data/" + name;
- }
- else if (name.startsWith("CommunityBoard/"))
- {
- return "data/html/" + name;
- }
- else if (name.startsWith("scripts/"))
- {
- return "data/scripts/" + name;
- }
- }
- return name;
- }
-
- private String processHtml(String result)
- {
- final Matcher extendMatcher = EXTEND_PATTERN.matcher(result);
- if (extendMatcher.find())
- {
- // If extend matcher finds something, process template
- final String templateName = parseTemplateName(extendMatcher.group(1));
-
- // Generate block name -> content map
- final Map blockMap = generateBlockMap(result);
-
- // Attempt to find the template
- String template = getHtm(templateName + "-template.htm");
- if (template != null)
- {
- // Attempt to find the abstract blocks
- final Matcher blockMatcher = ABSTRACT_BLOCK_PATTERN.matcher(template);
- while (blockMatcher.find())
- {
- final String name = blockMatcher.group(1);
- if (!blockMap.containsKey(name))
- {
- LOGGER.warning(getClass().getSimpleName() + ": Abstract block definition [" + name + "] is not implemented!");
- continue;
- }
-
- // Replace the matched content with the block.
- template = template.replace(blockMatcher.group(0), blockMap.get(name));
- }
-
- // Replace the entire extend block
- result = result.replace(extendMatcher.group(0), template);
- }
- else
- {
- LOGGER.warning(getClass().getSimpleName() + ": Missing template: " + templateName + "-template.htm !");
- }
- }
-
- return result;
- }
-
- private Map generateBlockMap(String data)
- {
- final Map blockMap = new LinkedHashMap<>();
- final Matcher blockMatcher = BLOCK_PATTERN.matcher(data);
- while (blockMatcher.find())
- {
- final String name = blockMatcher.group(1);
- final String content = blockMatcher.group(2);
- blockMap.put(name, content);
- }
- return blockMap;
- }
-
public static HtmCache getInstance()
{
- return SingletonHolder._instance;
+ return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
- protected static final HtmCache _instance = new HtmCache();
+ protected static final HtmCache INSTANCE = new HtmCache();
}
}
diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index e16391e76c..10be36e87e 100644
--- a/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -410,7 +410,7 @@ public final class PlayerInstance extends Playable
private Calendar _createDate = Calendar.getInstance();
private String _lang = null;
- private String _htmlPrefix = null;
+ private String _htmlPrefix = "";
private volatile boolean _isOnline = false;
private long _onlineTime;
@@ -12636,7 +12636,7 @@ public final class PlayerInstance extends Playable
{
if (!Config.MULTILANG_ENABLE)
{
- return null;
+ return "";
}
return _htmlPrefix;
@@ -12667,7 +12667,7 @@ public final class PlayerInstance extends Playable
else
{
_lang = null;
- _htmlPrefix = null;
+ _htmlPrefix = "";
}
return result;
diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/model/quest/Quest.java b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/model/quest/Quest.java
index 287e30a3fb..12549045da 100644
--- a/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/model/quest/Quest.java
+++ b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/model/quest/Quest.java
@@ -2721,7 +2721,7 @@ public class Quest extends AbstractScript implements IIdentifiable
content = hc.getHtm(player, "data/scripts/" + getPath() + "/" + fileName);
if (content == null)
{
- content = hc.getHtmForce(player, "data/scripts/quests/" + getName() + "/" + fileName);
+ content = hc.getHtm(player, "data/scripts/quests/" + getName() + "/" + fileName);
}
}
return content;
diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
index 95409c567a..25a46c93b2 100644
--- a/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
+++ b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
@@ -50,7 +50,7 @@ import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
public final class ScriptEngineManager implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
- public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
+ public static final Path SCRIPT_FOLDER = Config.SCRIPT_ROOT.toPath();
public static final Path MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "MasterHandler.java");
public static final Path EFFECT_MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "EffectMasterHandler.java");
public static final Path SKILL_CONDITION_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "SkillConditionMasterHandler.java");
diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/config/General.ini b/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/config/General.ini
index 933faf5131..595ab5efae 100644
--- a/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/config/General.ini
+++ b/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/config/General.ini
@@ -246,8 +246,8 @@ ForceInventoryUpdate = False
# True = Load html's into cache only on first time html is requested.
# False = Load all html's into cache on server startup.
-# Default: True
-LazyCache = True
+# Default: False
+LazyCache = False
# Cache all character names in to memory on server startup
# False - names are loaded from Db when they are requested
diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/config/Server.ini b/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/config/Server.ini
index 469ce38779..9e4dcc51b8 100644
--- a/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/config/Server.ini
+++ b/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/config/Server.ini
@@ -94,6 +94,9 @@ AcceptAlternateID = True
# Default: .
DatapackRoot = .
+# Scripts root directory.
+ScriptRoot = ./data/scripts
+
# Define how many players are allowed to play simultaneously on your server.
# Default: 2000
MaximumOnlineUsers = 2000
diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java b/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
index a650883032..0585478f14 100644
--- a/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
+++ b/L2J_Mobius_Classic_2.3_SevenSigns/dist/game/data/scripts/handlers/admincommandhandlers/AdminPForge.java
@@ -220,7 +220,7 @@ public final class AdminPForge implements IAdminCommandHandler
private void showValuesPage(PlayerInstance activeChar, String[] opCodes, String format)
{
String sendBypass = null;
- String valuesHtml = HtmCache.getInstance().getHtmForce(activeChar, "data/html/admin/pforge/values.htm");
+ String valuesHtml = HtmCache.getInstance().getHtm(activeChar, "data/html/admin/pforge/values.htm");
if (opCodes.length == 3)
{
valuesHtml = valuesHtml.replace("%opformat%", "chd");
diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/Config.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/Config.java
index 2b33efbf5b..de82373b91 100644
--- a/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/Config.java
+++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/Config.java
@@ -742,6 +742,7 @@ public final class Config
public static String CLAN_NAME_TEMPLATE;
public static int MAX_CHARACTERS_NUMBER_PER_ACCOUNT;
public static File DATAPACK_ROOT;
+ public static File SCRIPT_ROOT;
public static boolean ACCEPT_ALTERNATE_ID;
public static int REQUEST_ID;
public static boolean RESERVE_HOST_ON_LOGIN = false;
@@ -1183,6 +1184,16 @@ public final class Config
DATAPACK_ROOT = new File(".");
}
+ try
+ {
+ SCRIPT_ROOT = new File(serverSettings.getString("ScriptRoot", "./data/scripts").replaceAll("\\\\", "/")).getCanonicalFile();
+ }
+ catch (Exception e)
+ {
+ LOGGER.log(Level.WARNING, "Error setting script root!", e);
+ SCRIPT_ROOT = new File(".");
+ }
+
Pattern charNamePattern;
try
diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/cache/HtmCache.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/cache/HtmCache.java
index f129626e80..3d8420f5c1 100644
--- a/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/cache/HtmCache.java
+++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/cache/HtmCache.java
@@ -16,36 +16,31 @@
*/
package com.l2jmobius.gameserver.cache;
+import java.io.BufferedInputStream;
import java.io.File;
-import java.nio.charset.StandardCharsets;
+import java.io.FileInputStream;
import java.util.HashMap;
-import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import com.l2jmobius.Config;
import com.l2jmobius.commons.util.file.filter.HTMLFilter;
import com.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import com.l2jmobius.gameserver.util.BuilderUtil;
-import com.l2jmobius.gameserver.util.Util;
/**
* @author Layane
+ * @author Zoey76
*/
public class HtmCache
{
private static final Logger LOGGER = Logger.getLogger(HtmCache.class.getName());
private static final HTMLFilter HTML_FILTER = new HTMLFilter();
- private static final Pattern EXTEND_PATTERN = Pattern.compile("(.*?)", Pattern.DOTALL);
- private static final Pattern ABSTRACT_BLOCK_PATTERN = Pattern.compile("", Pattern.DOTALL);
- private static final Pattern BLOCK_PATTERN = Pattern.compile("(.*?)", Pattern.DOTALL);
- private static final Map _cache = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
+ private static final Map HTML_CACHE = Config.LAZY_CACHE ? new ConcurrentHashMap<>() : new HashMap<>();
private int _loadedFiles;
private long _bytesBuffLen;
@@ -66,14 +61,14 @@ public class HtmCache
{
LOGGER.info("Html cache start...");
parseDir(f);
- LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded");
+ LOGGER.info("Cache[HTML]: " + String.format("%.3f", getMemoryUsage()) + " megabytes on " + _loadedFiles + " files loaded.");
}
else
{
- _cache.clear();
+ HTML_CACHE.clear();
_loadedFiles = 0;
_bytesBuffLen = 0;
- LOGGER.info("Cache[HTML]: Running lazy cache");
+ LOGGER.info("Cache[HTML]: Running lazy cache.");
}
}
@@ -114,86 +109,65 @@ public class HtmCache
public String loadFile(File file)
{
- if (HTML_FILTER.accept(file))
+ if (!HTML_FILTER.accept(file))
{
- try
+ return null;
+ }
+
+ String content = null;
+ try (FileInputStream fis = new FileInputStream(file);
+ BufferedInputStream bis = new BufferedInputStream(fis))
+ {
+ final int bytes = bis.available();
+ byte[] raw = new byte[bytes];
+
+ bis.read(raw);
+ content = new String(raw, "UTF-8");
+ content = content.replaceAll("(?s)", ""); // Remove html comments
+
+ final String oldContent = HTML_CACHE.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
+ if (oldContent == null)
{
- String content = processHtml(Util.readAllLines(file, StandardCharsets.UTF_8, null));
- content = content.replaceAll("(?s)", ""); // Remove html comments
- // content = content.replaceAll("\r", "").replaceAll("\n", ""); // Remove new lines
-
- final String oldContent = _cache.put(file.toURI().getPath().substring(Config.DATAPACK_ROOT.toURI().getPath().length()), content);
- if (oldContent == null)
- {
- _bytesBuffLen += content.length() * 2;
- _loadedFiles++;
- }
- else
- {
- _bytesBuffLen = (_bytesBuffLen - oldContent.length()) + (content.length() * 2);
- }
- return content;
+ _bytesBuffLen += bytes;
+ _loadedFiles++;
}
- catch (Exception e)
+ else
{
- LOGGER.log(Level.WARNING, "Problem with htm file:", e);
+ _bytesBuffLen = (_bytesBuffLen - oldContent.length()) + bytes;
}
}
- return null;
- }
-
- public String getHtmForce(PlayerInstance player, String path)
- {
- String content = getHtm(player, path);
- if (content == null)
+ catch (Exception e)
{
- content = "My text is missing:
" + path + "";
- LOGGER.warning("Cache[HTML]: Missing HTML page: " + path);
+ LOGGER.log(Level.WARNING, "Problem with htm file:", e);
}
return content;
}
public String getHtm(PlayerInstance player, String path)
{
- final String prefix = player != null ? player.getHtmlPrefix() : "en";
- String newPath = null;
- String content;
- if ((prefix != null) && !prefix.isEmpty())
+ final String prefix = player != null ? player.getHtmlPrefix() : "";
+ final String newPath = prefix + path;
+ String content = HTML_CACHE.get(newPath);
+ if (Config.LAZY_CACHE && (content == null))
{
- newPath = prefix + path;
- content = getHtm(newPath);
- if (content != null)
+ content = loadFile(new File(Config.DATAPACK_ROOT, newPath));
+ if (content == null)
{
- if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
- }
- return content;
+ content = loadFile(new File(Config.SCRIPT_ROOT, newPath));
}
}
- content = getHtm(path);
- if ((content != null) && (newPath != null))
+ if ((player != null) && player.isGM() && Config.GM_DEBUG_HTML_PATHS)
{
- _cache.put(newPath, content);
+ BuilderUtil.sendHtmlMessage(player, newPath.substring(5));
}
- if ((player != null) && player.isGM() && (path != null) && Config.GM_DEBUG_HTML_PATHS)
- {
- BuilderUtil.sendHtmlMessage(player, path.substring(5));
- }
return content;
}
- private String getHtm(String path)
- {
- // TODO: Check why some files do not get in cache on server startup.
- return (path == null) || path.isEmpty() ? "" : _cache.get(path) == null ? loadFile(new File(Config.DATAPACK_ROOT, path)) : _cache.get(path);
- }
-
public boolean contains(String path)
{
- return _cache.containsKey(path);
+ return HTML_CACHE.containsKey(path);
}
/**
@@ -205,88 +179,13 @@ public class HtmCache
return HTML_FILTER.accept(new File(Config.DATAPACK_ROOT, path));
}
- private String parseTemplateName(String name)
- {
- if (!name.startsWith("data/"))
- {
- if (name.startsWith("html/"))
- {
- return "data/" + name;
- }
- else if (name.startsWith("CommunityBoard/"))
- {
- return "data/html/" + name;
- }
- else if (name.startsWith("scripts/"))
- {
- return "data/scripts/" + name;
- }
- }
- return name;
- }
-
- private String processHtml(String result)
- {
- final Matcher extendMatcher = EXTEND_PATTERN.matcher(result);
- if (extendMatcher.find())
- {
- // If extend matcher finds something, process template
- final String templateName = parseTemplateName(extendMatcher.group(1));
-
- // Generate block name -> content map
- final Map blockMap = generateBlockMap(result);
-
- // Attempt to find the template
- String template = getHtm(templateName + "-template.htm");
- if (template != null)
- {
- // Attempt to find the abstract blocks
- final Matcher blockMatcher = ABSTRACT_BLOCK_PATTERN.matcher(template);
- while (blockMatcher.find())
- {
- final String name = blockMatcher.group(1);
- if (!blockMap.containsKey(name))
- {
- LOGGER.warning(getClass().getSimpleName() + ": Abstract block definition [" + name + "] is not implemented!");
- continue;
- }
-
- // Replace the matched content with the block.
- template = template.replace(blockMatcher.group(0), blockMap.get(name));
- }
-
- // Replace the entire extend block
- result = result.replace(extendMatcher.group(0), template);
- }
- else
- {
- LOGGER.warning(getClass().getSimpleName() + ": Missing template: " + templateName + "-template.htm !");
- }
- }
-
- return result;
- }
-
- private Map generateBlockMap(String data)
- {
- final Map blockMap = new LinkedHashMap<>();
- final Matcher blockMatcher = BLOCK_PATTERN.matcher(data);
- while (blockMatcher.find())
- {
- final String name = blockMatcher.group(1);
- final String content = blockMatcher.group(2);
- blockMap.put(name, content);
- }
- return blockMap;
- }
-
public static HtmCache getInstance()
{
- return SingletonHolder._instance;
+ return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
- protected static final HtmCache _instance = new HtmCache();
+ protected static final HtmCache INSTANCE = new HtmCache();
}
}
diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index d302cdb196..4ba2253b0a 100644
--- a/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -410,7 +410,7 @@ public final class PlayerInstance extends Playable
private Calendar _createDate = Calendar.getInstance();
private String _lang = null;
- private String _htmlPrefix = null;
+ private String _htmlPrefix = "";
private volatile boolean _isOnline = false;
private long _onlineTime;
@@ -12636,7 +12636,7 @@ public final class PlayerInstance extends Playable
{
if (!Config.MULTILANG_ENABLE)
{
- return null;
+ return "";
}
return _htmlPrefix;
@@ -12667,7 +12667,7 @@ public final class PlayerInstance extends Playable
else
{
_lang = null;
- _htmlPrefix = null;
+ _htmlPrefix = "";
}
return result;
diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/model/quest/Quest.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/model/quest/Quest.java
index 287e30a3fb..12549045da 100644
--- a/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/model/quest/Quest.java
+++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/model/quest/Quest.java
@@ -2721,7 +2721,7 @@ public class Quest extends AbstractScript implements IIdentifiable
content = hc.getHtm(player, "data/scripts/" + getPath() + "/" + fileName);
if (content == null)
{
- content = hc.getHtmForce(player, "data/scripts/quests/" + getName() + "/" + fileName);
+ content = hc.getHtm(player, "data/scripts/quests/" + getName() + "/" + fileName);
}
}
return content;
diff --git a/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java b/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
index 95409c567a..25a46c93b2 100644
--- a/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
+++ b/L2J_Mobius_Classic_2.3_SevenSigns/java/com/l2jmobius/gameserver/scripting/ScriptEngineManager.java
@@ -50,7 +50,7 @@ import com.l2jmobius.gameserver.scripting.java.JavaScriptingEngine;
public final class ScriptEngineManager implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(ScriptEngineManager.class.getName());
- public static final Path SCRIPT_FOLDER = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts");
+ public static final Path SCRIPT_FOLDER = Config.SCRIPT_ROOT.toPath();
public static final Path MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "MasterHandler.java");
public static final Path EFFECT_MASTER_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "EffectMasterHandler.java");
public static final Path SKILL_CONDITION_HANDLER_FILE = Paths.get(SCRIPT_FOLDER.toString(), "handlers", "SkillConditionMasterHandler.java");