Browse Source

Sanitize input

feature-config-parsing2
MagicBot 4 months ago
parent
commit
491a9dbae9
  1. 20
      src/engine/ConfigParsing/EffectsParser.java

20
src/engine/ConfigParsing/EffectsParser.java

@ -14,9 +14,7 @@ import engine.gameManager.ConfigManager; @@ -14,9 +14,7 @@ import engine.gameManager.ConfigManager;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -32,18 +30,26 @@ public class EffectsParser { @@ -32,18 +30,26 @@ public class EffectsParser {
byte[] fileData = Files.readAllBytes(Paths.get(EffectsPath));
String fileContents = new String(fileData);
Matcher matcher = EFFECT_REGEX.matcher(fileContents);
final List<String> effectEntries = new ArrayList<>();
final Matcher matcher = EFFECT_REGEX.matcher(fileContents);
// Iterate effect entries from .wpak config data
while (matcher.find()) {
effectEntries.add(matcher.group(1));
}
EffectEntry effectEntry = parseEffectEntry(matcher.group(1));
if (effectEntry != null)
effect_data.put(effectEntry.id, effectEntry);
}
}
private static void parseEffectEntry(String effectEntry) {
private static EffectEntry parseEffectEntry(String effectData) {
EffectEntry effectEntry = new EffectEntry();
// Remove all lines that contain a #
effectData.replaceAll("(?m)^.*#.*$", "");
return effectEntry;
}
}

Loading…
Cancel
Save