Respect charset when loading scripts

This commit is contained in:
P0nk
2021-09-08 18:46:16 +02:00
parent 1803699086
commit c841e9952b
8 changed files with 11 additions and 10 deletions

View File

@@ -307,7 +307,7 @@ server:
#Miscellaneous Configuration
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_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.

View File

@@ -154,7 +154,7 @@ public class ServerConfig {
//Miscellaneous Configuration
public String TIMEZONE;
public String PACKET_CHARSET;
public String CHARSET;
public boolean USE_DISPLAY_NUMBERS_WITH_COMMA;
public boolean USE_UNITPRICE_WITH_COMMA;
public byte MAX_MONITORED_BUFFSTATS;

View File

@@ -24,7 +24,7 @@ import java.util.Optional;
public class CharsetConstants {
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 {
LANGUAGE_US("US-ASCII"),
@@ -56,7 +56,7 @@ public class CharsetConstants {
}
private static Charset loadCharset() {
String configCharset = YamlConfig.config.server.PACKET_CHARSET;
String configCharset = YamlConfig.config.server.CHARSET;
if (configCharset != null) {
Language language = Language.fromCharset(configCharset);
return Charset.forName(language.getCharset());

View File

@@ -50,7 +50,7 @@ public class ByteBufInPacket implements InPacket {
short length = readShort();
byte[] stringBytes = new byte[length];
byteBuf.readBytes(stringBytes);
return new String(stringBytes, CharsetConstants.PACKET_CHARSET);
return new String(stringBytes, CharsetConstants.CHARSET);
}
@Override

View File

@@ -78,12 +78,12 @@ public class ByteBufOutPacket implements OutPacket {
@Override
public void writeString(String value) {
writeShort((short) value.length());
writeBytes(value.getBytes(CharsetConstants.PACKET_CHARSET));
writeBytes(value.getBytes(CharsetConstants.CHARSET));
}
@Override
public void writeFixedString(String value) {
writeBytes(value.getBytes(CharsetConstants.PACKET_CHARSET));
writeBytes(value.getBytes(CharsetConstants.CHARSET));
}
@Override

View File

@@ -23,6 +23,7 @@ package scripting;
import client.MapleClient;
import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine;
import constants.string.CharsetConstants;
import tools.FilePrinter;
import javax.script.*;
@@ -55,7 +56,7 @@ public abstract class AbstractScriptManager {
enableScriptHostAccess(graalScriptEngine);
try (FileReader fr = new FileReader(scriptFile)) {
try (FileReader fr = new FileReader(scriptFile, CharsetConstants.CHARSET)) {
engine.eval(fr);
} catch (final ScriptException | IOException t) {
FilePrinter.printError(FilePrinter.INVOCABLE + path.substring(12), t, path);

View File

@@ -99,7 +99,7 @@ public class HexTool {
}
}
return new String(ret, CharsetConstants.PACKET_CHARSET);
return new String(ret, CharsetConstants.CHARSET);
}
/**

View File

@@ -83,7 +83,7 @@ class ByteBufInPacketTest {
void readString() {
final String writtenString = "You have gained experience (+3200)";
byteBuf.writeShortLE(writtenString.length());
byte[] writtenStringBytes = writtenString.getBytes(CharsetConstants.PACKET_CHARSET);
byte[] writtenStringBytes = writtenString.getBytes(CharsetConstants.CHARSET);
byteBuf.writeBytes(writtenStringBytes);
String readString = inPacket.readString();