Respect charset when loading scripts
This commit is contained in:
@@ -307,7 +307,7 @@ server:
|
|||||||
|
|
||||||
#Miscellaneous Configuration
|
#Miscellaneous Configuration
|
||||||
TIMEZONE: GMT-3
|
TIMEZONE: GMT-3
|
||||||
PACKET_CHARSET: US_ASCII # Defaults to US_ASCII if not set
|
CHARSET: US-ASCII # Defaults to US-ASCII if not set
|
||||||
USE_DISPLAY_NUMBERS_WITH_COMMA: true #Enforce comma on displayed strings (use this when USE_UNITPRICE_WITH_COMMA is active and you still want to display comma-separated values).
|
USE_DISPLAY_NUMBERS_WITH_COMMA: true #Enforce comma on displayed strings (use this when USE_UNITPRICE_WITH_COMMA is active and you still want to display comma-separated values).
|
||||||
USE_UNITPRICE_WITH_COMMA: true #Set this accordingly with the layout of the unitPrices on Item.wz XML's, whether it's using commas or dots to represent fractions.
|
USE_UNITPRICE_WITH_COMMA: true #Set this accordingly with the layout of the unitPrices on Item.wz XML's, whether it's using commas or dots to represent fractions.
|
||||||
MAX_MONITORED_BUFFSTATS: 5 #Limits accounting for "dormant" buff effects, that should take place when stronger stat buffs expires.
|
MAX_MONITORED_BUFFSTATS: 5 #Limits accounting for "dormant" buff effects, that should take place when stronger stat buffs expires.
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ public class ServerConfig {
|
|||||||
|
|
||||||
//Miscellaneous Configuration
|
//Miscellaneous Configuration
|
||||||
public String TIMEZONE;
|
public String TIMEZONE;
|
||||||
public String PACKET_CHARSET;
|
public String CHARSET;
|
||||||
public boolean USE_DISPLAY_NUMBERS_WITH_COMMA;
|
public boolean USE_DISPLAY_NUMBERS_WITH_COMMA;
|
||||||
public boolean USE_UNITPRICE_WITH_COMMA;
|
public boolean USE_UNITPRICE_WITH_COMMA;
|
||||||
public byte MAX_MONITORED_BUFFSTATS;
|
public byte MAX_MONITORED_BUFFSTATS;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import java.util.Optional;
|
|||||||
|
|
||||||
public class CharsetConstants {
|
public class CharsetConstants {
|
||||||
private static final Logger log = LoggerFactory.getLogger(CharsetConstants.class);
|
private static final Logger log = LoggerFactory.getLogger(CharsetConstants.class);
|
||||||
public static final Charset PACKET_CHARSET = loadCharset();
|
public static final Charset CHARSET = loadCharset();
|
||||||
|
|
||||||
private enum Language {
|
private enum Language {
|
||||||
LANGUAGE_US("US-ASCII"),
|
LANGUAGE_US("US-ASCII"),
|
||||||
@@ -56,7 +56,7 @@ public class CharsetConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Charset loadCharset() {
|
private static Charset loadCharset() {
|
||||||
String configCharset = YamlConfig.config.server.PACKET_CHARSET;
|
String configCharset = YamlConfig.config.server.CHARSET;
|
||||||
if (configCharset != null) {
|
if (configCharset != null) {
|
||||||
Language language = Language.fromCharset(configCharset);
|
Language language = Language.fromCharset(configCharset);
|
||||||
return Charset.forName(language.getCharset());
|
return Charset.forName(language.getCharset());
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class ByteBufInPacket implements InPacket {
|
|||||||
short length = readShort();
|
short length = readShort();
|
||||||
byte[] stringBytes = new byte[length];
|
byte[] stringBytes = new byte[length];
|
||||||
byteBuf.readBytes(stringBytes);
|
byteBuf.readBytes(stringBytes);
|
||||||
return new String(stringBytes, CharsetConstants.PACKET_CHARSET);
|
return new String(stringBytes, CharsetConstants.CHARSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -78,12 +78,12 @@ public class ByteBufOutPacket implements OutPacket {
|
|||||||
@Override
|
@Override
|
||||||
public void writeString(String value) {
|
public void writeString(String value) {
|
||||||
writeShort((short) value.length());
|
writeShort((short) value.length());
|
||||||
writeBytes(value.getBytes(CharsetConstants.PACKET_CHARSET));
|
writeBytes(value.getBytes(CharsetConstants.CHARSET));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeFixedString(String value) {
|
public void writeFixedString(String value) {
|
||||||
writeBytes(value.getBytes(CharsetConstants.PACKET_CHARSET));
|
writeBytes(value.getBytes(CharsetConstants.CHARSET));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ package scripting;
|
|||||||
|
|
||||||
import client.MapleClient;
|
import client.MapleClient;
|
||||||
import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine;
|
import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine;
|
||||||
|
import constants.string.CharsetConstants;
|
||||||
import tools.FilePrinter;
|
import tools.FilePrinter;
|
||||||
|
|
||||||
import javax.script.*;
|
import javax.script.*;
|
||||||
@@ -55,7 +56,7 @@ public abstract class AbstractScriptManager {
|
|||||||
|
|
||||||
enableScriptHostAccess(graalScriptEngine);
|
enableScriptHostAccess(graalScriptEngine);
|
||||||
|
|
||||||
try (FileReader fr = new FileReader(scriptFile)) {
|
try (FileReader fr = new FileReader(scriptFile, CharsetConstants.CHARSET)) {
|
||||||
engine.eval(fr);
|
engine.eval(fr);
|
||||||
} catch (final ScriptException | IOException t) {
|
} catch (final ScriptException | IOException t) {
|
||||||
FilePrinter.printError(FilePrinter.INVOCABLE + path.substring(12), t, path);
|
FilePrinter.printError(FilePrinter.INVOCABLE + path.substring(12), t, path);
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ public class HexTool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new String(ret, CharsetConstants.PACKET_CHARSET);
|
return new String(ret, CharsetConstants.CHARSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ class ByteBufInPacketTest {
|
|||||||
void readString() {
|
void readString() {
|
||||||
final String writtenString = "You have gained experience (+3200)";
|
final String writtenString = "You have gained experience (+3200)";
|
||||||
byteBuf.writeShortLE(writtenString.length());
|
byteBuf.writeShortLE(writtenString.length());
|
||||||
byte[] writtenStringBytes = writtenString.getBytes(CharsetConstants.PACKET_CHARSET);
|
byte[] writtenStringBytes = writtenString.getBytes(CharsetConstants.CHARSET);
|
||||||
byteBuf.writeBytes(writtenStringBytes);
|
byteBuf.writeBytes(writtenStringBytes);
|
||||||
|
|
||||||
String readString = inPacket.readString();
|
String readString = inPacket.readString();
|
||||||
|
|||||||
Reference in New Issue
Block a user