From a7701969d504abc13b32d28cbf287983c2f25936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sun, 16 Mar 2014 10:07:17 +0100 Subject: [PATCH 1/4] updated luaj to cvs snapshot version, to get official fix for string matcher --- src/main/java/org/luaj/vm3/Globals.java | 6 +++--- src/main/java/org/luaj/vm3/LuaString.java | 6 ++++++ src/main/java/org/luaj/vm3/lib/BaseLib.java | 8 +++---- src/main/java/org/luaj/vm3/lib/DebugLib.java | 8 +++++-- .../java/org/luaj/vm3/lib/PackageLib.java | 9 ++++++-- .../java/org/luaj/vm3/lib/ResourceFinder.java | 4 ++-- src/main/java/org/luaj/vm3/lib/StringLib.java | 21 ++++++++++--------- .../java/org/luaj/vm3/lib/jse/JseBaseLib.java | 6 +++--- .../java/org/luaj/vm3/lib/jse/LuajavaLib.java | 2 +- .../org/luaj/vm3/script/LuaScriptEngine.java | 19 +++++++++++++++-- .../java/org/luaj/vm3/script/LuajContext.java | 16 ++++++++++++-- 11 files changed, 74 insertions(+), 31 deletions(-) diff --git a/src/main/java/org/luaj/vm3/Globals.java b/src/main/java/org/luaj/vm3/Globals.java index 829bfdd08..c5161aa84 100644 --- a/src/main/java/org/luaj/vm3/Globals.java +++ b/src/main/java/org/luaj/vm3/Globals.java @@ -80,7 +80,7 @@ import org.luaj.vm3.lib.ResourceFinder; *
  • {@link STDIN} Current value for standard input in the laaded IoLib, if any. *
  • {@link STDOUT} Current value for standard output in the loaded IoLib, if any. *
  • {@link STDERR} Current value for standard error in the loaded IoLib, if any. - *
  • {@link FINDER} Current loaded {@link ResourceFinder}, if any. + *
  • {@link finder} Current loaded {@link ResourceFinder}, if any. *
  • {@link compiler} Current loaded {@link Compiler}, if any. *
  • {@link undumper} Current loaded {@link Undumper}, if any. *
  • {@link loader} Current loaded {@link Loader}, if any. @@ -122,7 +122,7 @@ public class Globals extends LuaTable { public PrintStream STDERR = System.err; /** The installed ResourceFinder for looking files by name. */ - public ResourceFinder FINDER; + public ResourceFinder finder; /** The currently running thread. Should not be changed by non-library code. */ public LuaThread running = new LuaThread(this); @@ -178,7 +178,7 @@ public class Globals extends LuaTable { */ public LuaValue loadfile(String filename) { try { - return load(FINDER.findResource(filename), "@"+filename, "bt", this); + return load(finder.findResource(filename), "@"+filename, "bt", this); } catch (Exception e) { return error("load "+filename+": "+e); } diff --git a/src/main/java/org/luaj/vm3/LuaString.java b/src/main/java/org/luaj/vm3/LuaString.java index f722a9dbf..f54be50a6 100644 --- a/src/main/java/org/luaj/vm3/LuaString.java +++ b/src/main/java/org/luaj/vm3/LuaString.java @@ -387,6 +387,12 @@ public class LuaString extends LuaValue { return this; } + /** Take a substring using Java zero-based indexes for begin and end or range. + * @param beginIndex The zero-based index of the first character to include. + * @param endIndex The zero-based index of position after the last character. + * @return LuaString which is a substring whose first character is at offset + * beginIndex and extending for (endIndex - beginIndex ) characters. + */ public LuaString substring( int beginIndex, int endIndex ) { return valueOf( m_bytes, m_offset + beginIndex, endIndex - beginIndex ); } diff --git a/src/main/java/org/luaj/vm3/lib/BaseLib.java b/src/main/java/org/luaj/vm3/lib/BaseLib.java index ca78b561e..2405105c3 100644 --- a/src/main/java/org/luaj/vm3/lib/BaseLib.java +++ b/src/main/java/org/luaj/vm3/lib/BaseLib.java @@ -38,7 +38,7 @@ import org.luaj.vm3.Varargs; *

    * This contains all library functions listed as "basic functions" in the lua documentation for JME. * The functions dofile and loadfile use the - * {@link #FINDER} instance to find resource files. + * {@link #finder} instance to find resource files. * Since JME has no file system by default, {@link BaseLib} implements * {@link ResourceFinder} using {@link Class#getResource(String)}, * which is the closest equivalent on JME. @@ -69,7 +69,7 @@ import org.luaj.vm3.Varargs; * This is a direct port of the corresponding library in C. * @see JseBaseLib * @see ResourceFinder - * @see #FINDER + * @see #finder * @see LibFunction * @see JsePlatform * @see JmePlatform @@ -81,7 +81,7 @@ public class BaseLib extends TwoArgFunction implements ResourceFinder { public LuaValue call(LuaValue modname, LuaValue env) { globals = env.checkglobals(); - globals.FINDER = this; + globals.finder = this; globals.baselib = this; env.set( "_G", env ); env.set( "_VERSION", Lua._VERSION ); @@ -424,7 +424,7 @@ public class BaseLib extends TwoArgFunction implements ResourceFinder { * @return Varargs containing chunk, or NIL,error-text on error */ public Varargs loadFile(String filename, String mode, LuaValue env) { - InputStream is = globals.FINDER.findResource(filename); + InputStream is = globals.finder.findResource(filename); if ( is == null ) return varargsOf(NIL, valueOf("cannot open "+filename+": No such file or directory")); try { diff --git a/src/main/java/org/luaj/vm3/lib/DebugLib.java b/src/main/java/org/luaj/vm3/lib/DebugLib.java index 59eb63a38..ef4389a19 100644 --- a/src/main/java/org/luaj/vm3/lib/DebugLib.java +++ b/src/main/java/org/luaj/vm3/lib/DebugLib.java @@ -72,8 +72,12 @@ import org.luaj.vm3.Varargs; * @see Lua 5.2 Debug Lib Reference */ public class DebugLib extends TwoArgFunction { - public static final boolean CALLS = (null != System.getProperty("CALLS")); - public static final boolean TRACE = (null != System.getProperty("TRACE")); + public static boolean CALLS; + public static boolean TRACE; + static { + try { CALLS = (null != System.getProperty("CALLS")); } catch (Exception e) {} + try { TRACE = (null != System.getProperty("TRACE")); } catch (Exception e) {} + } private static final LuaString LUA = valueOf("Lua"); private static final LuaString QMARK = valueOf("?"); diff --git a/src/main/java/org/luaj/vm3/lib/PackageLib.java b/src/main/java/org/luaj/vm3/lib/PackageLib.java index 2908bce57..1cae2cb0a 100644 --- a/src/main/java/org/luaj/vm3/lib/PackageLib.java +++ b/src/main/java/org/luaj/vm3/lib/PackageLib.java @@ -81,8 +81,13 @@ public class PackageLib extends TwoArgFunction { /** The default value to use for package.path. This can be set with the system property * "luaj.package.path", and is "?.lua" by default. */ - public static String DEFAULT_LUA_PATH = System.getProperty("luaj.package.path"); + public static String DEFAULT_LUA_PATH; static { + try { + DEFAULT_LUA_PATH = System.getProperty("luaj.package.path"); + } catch (Exception e) { + System.out.println(e.toString()); + } if (DEFAULT_LUA_PATH == null) DEFAULT_LUA_PATH = "?.lua"; } @@ -294,7 +299,7 @@ public class PackageLib extends TwoArgFunction { } // try opening the file - InputStream is = globals.FINDER.findResource(filename); + InputStream is = globals.finder.findResource(filename); if (is != null) { try { is.close(); } catch ( java.io.IOException ioe ) {} return valueOf(filename); diff --git a/src/main/java/org/luaj/vm3/lib/ResourceFinder.java b/src/main/java/org/luaj/vm3/lib/ResourceFinder.java index 32ddfa445..b857a7328 100644 --- a/src/main/java/org/luaj/vm3/lib/ResourceFinder.java +++ b/src/main/java/org/luaj/vm3/lib/ResourceFinder.java @@ -31,13 +31,13 @@ import java.io.InputStream; * for both the Jme and Jse platforms. *

    * The Jme version of base lib {@link BaseLib} - * implements {@link BaseLib#FINDER} via {@link Class#getResourceAsStream(String)}, + * implements {@link Globals#finder} via {@link Class#getResourceAsStream(String)}, * while the Jse version {@link JseBaseLib} implements it using {@link java.io.File#File(String)}. *

    * The io library does not use this API for file manipulation. *

    * @see BaseLib - * @see BaseLib#FINDER + * @see Globals#finder * @see JseBaseLib * @see JmePlatform * @see JsePlatform diff --git a/src/main/java/org/luaj/vm3/lib/StringLib.java b/src/main/java/org/luaj/vm3/lib/StringLib.java index afde5979b..a4a189290 100644 --- a/src/main/java/org/luaj/vm3/lib/StringLib.java +++ b/src/main/java/org/luaj/vm3/lib/StringLib.java @@ -1155,18 +1155,19 @@ public class StringLib extends TwoArgFunction { if ( poff == plen || poff + 1 == plen ) { error( "unbalanced pattern" ); } - if ( soff >= s.length() || s.luaByte( soff ) != p.luaByte( poff ) ) + final int slen = s.length(); + if ( soff >= slen ) return -1; - else { - int b = p.luaByte( poff ); - int e = p.luaByte( poff + 1 ); - int cont = 1; - while ( ++soff < s.length() ) { - if ( s.luaByte( soff ) == e ) { - if ( --cont == 0 ) return soff + 1; - } - else if ( s.luaByte( soff ) == b ) cont++; + final int b = p.luaByte( poff ); + if ( s.luaByte( soff ) != b ) + return -1; + final int e = p.luaByte( poff + 1 ); + int cont = 1; + while ( ++soff < slen ) { + if ( s.luaByte( soff ) == e ) { + if ( --cont == 0 ) return soff + 1; } + else if ( s.luaByte( soff ) == b ) cont++; } return -1; } diff --git a/src/main/java/org/luaj/vm3/lib/jse/JseBaseLib.java b/src/main/java/org/luaj/vm3/lib/jse/JseBaseLib.java index 3bf09200e..5cdb7d9da 100644 --- a/src/main/java/org/luaj/vm3/lib/jse/JseBaseLib.java +++ b/src/main/java/org/luaj/vm3/lib/jse/JseBaseLib.java @@ -33,11 +33,11 @@ import org.luaj.vm3.lib.ResourceFinder; /** * Subclass of {@link BaseLib} and {@link LibFunction} which implements the lua basic library functions - * and provides a directory based {@link ResourceFinder} as the {@link #FINDER}. + * and provides a directory based {@link ResourceFinder} as the {@link #finder}. *

    * Since JME has no file system by default, {@link BaseLib} implements * {@link ResourceFinder} using {@link Class#getResource(String)}. - * The {@link JseBaseLib} implements {@link FINDER} by scanning the current directory + * The {@link JseBaseLib} implements {@link finder} by scanning the current directory * first, then falling back to {@link Class#getResource(String)} if that fails. * Otherwise, the behavior is the same as that of {@link BaseLib}. *

    @@ -62,7 +62,7 @@ import org.luaj.vm3.lib.ResourceFinder; * @see Globals * @see BaseLib * @see ResourceFinder - * @see {@link Globals.FINDER} + * @see {@link Globals.finder} * @see LibFunction * @see JsePlatform * @see org.luaj.vm3.lib.jme.JmePlatform diff --git a/src/main/java/org/luaj/vm3/lib/jse/LuajavaLib.java b/src/main/java/org/luaj/vm3/lib/jse/LuajavaLib.java index 596f7f4f1..8ab4cbd7a 100644 --- a/src/main/java/org/luaj/vm3/lib/jse/LuajavaLib.java +++ b/src/main/java/org/luaj/vm3/lib/jse/LuajavaLib.java @@ -109,7 +109,7 @@ public class LuajavaLib extends VarArgFunction { // LuaValue modname = args.arg1(); LuaValue env = args.arg(2); LuaTable t = new LuaTable(); - bind( t, LuajavaLib.class, NAMES, BINDCLASS ); + bind( t, this.getClass(), NAMES, BINDCLASS ); env.set("luajava", t); env.get("package").get("loaded").set("luajava", t); return t; diff --git a/src/main/java/org/luaj/vm3/script/LuaScriptEngine.java b/src/main/java/org/luaj/vm3/script/LuaScriptEngine.java index 5c03369ad..f20e294fc 100644 --- a/src/main/java/org/luaj/vm3/script/LuaScriptEngine.java +++ b/src/main/java/org/luaj/vm3/script/LuaScriptEngine.java @@ -95,6 +95,21 @@ public class LuaScriptEngine extends AbstractScriptEngine implements ScriptEngin } } + @Override + public Object eval(Reader reader, Bindings bindings) throws ScriptException { + return ((LuajCompiledScript) compile(reader)).eval(context.globals, bindings); + } + + @Override + public Object eval(String script, Bindings bindings) throws ScriptException { + return eval(new StringReader(script), bindings); + } + + @Override + protected ScriptContext getScriptContext(Bindings nn) { + throw new IllegalStateException("LuajScriptEngine should not be allocating contexts."); + } + @Override public Bindings createBindings() { return new SimpleBindings(); @@ -109,7 +124,7 @@ public class LuaScriptEngine extends AbstractScriptEngine implements ScriptEngin @Override public Object eval(Reader reader, ScriptContext context) throws ScriptException { - return compile(reader).eval(); + return compile(reader).eval(context); } @Override @@ -142,7 +157,7 @@ public class LuaScriptEngine extends AbstractScriptEngine implements ScriptEngin return eval(((LuajContext) context).globals, context.getBindings(ScriptContext.ENGINE_SCOPE)); } - private Object eval(Globals g, Bindings b) throws ScriptException { + Object eval(Globals g, Bindings b) throws ScriptException { g.setmetatable(new BindingsMetatable(b)); LuaFunction f = function; if (f.isclosure()) diff --git a/src/main/java/org/luaj/vm3/script/LuajContext.java b/src/main/java/org/luaj/vm3/script/LuajContext.java index b40239829..032fd4a32 100644 --- a/src/main/java/org/luaj/vm3/script/LuajContext.java +++ b/src/main/java/org/luaj/vm3/script/LuajContext.java @@ -103,7 +103,7 @@ public class LuajContext extends SimpleScriptContext implements ScriptContext { @Override public void setWriter(Writer writer) { globals.STDOUT = writer != null? - new PrintStream(new WriterOutputStream(writer)): + new PrintStream(new WriterOutputStream(writer), true): stdout; } @@ -113,7 +113,19 @@ public class LuajContext extends SimpleScriptContext implements ScriptContext { this.w = w; } public void write(int b) throws IOException { - w.write(b); + w.write(new String(new byte[] {(byte)b})); + } + public void write(byte[] b, int o, int l) throws IOException { + w.write(new String(b, o, l)); + } + public void write(byte[] b) throws IOException { + w.write(new String(b)); + } + public void close() throws IOException { + w.close(); + } + public void flush() throws IOException { + w.flush(); } } From 70755c8528622cee59f506ff2dbbfe18576c4ec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sun, 16 Mar 2014 10:31:45 +0100 Subject: [PATCH 2/4] better clean up of no longer valid computer state saves by handling saving in the chunk's save callback (instead of the world's) --- .../scala/li/cil/oc/common/SaveHandler.scala | 56 ++++++++++--------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/src/main/scala/li/cil/oc/common/SaveHandler.scala b/src/main/scala/li/cil/oc/common/SaveHandler.scala index 9df0fc7bd..43fa5a520 100644 --- a/src/main/scala/li/cil/oc/common/SaveHandler.scala +++ b/src/main/scala/li/cil/oc/common/SaveHandler.scala @@ -6,9 +6,12 @@ import li.cil.oc.{OpenComputers, Settings} import net.minecraft.world.ChunkCoordIntPair import net.minecraftforge.common.DimensionManager import net.minecraftforge.event.ForgeSubscribe -import net.minecraftforge.event.world.WorldEvent +import net.minecraftforge.event.world.{ChunkDataEvent, WorldEvent} import scala.collection.mutable +// Used by the native lua state to store kernel and stack data in auxiliary +// files instead of directly in the tile entity data, avoiding potential +// problems with the tile entity data becoming too large. object SaveHandler { val saveData = mutable.Map.empty[ChunkCoordIntPair, mutable.Map[String, Array[Byte]]] @@ -46,32 +49,35 @@ object SaveHandler { } } - // Used by the native lua state to store kernel and stack data in auxiliary - // files instead of directly in the tile entity data, avoiding potential - // problems with the tile entity data becoming too large. + @ForgeSubscribe + def onChunkSave(e: ChunkDataEvent.Save) = saveData.synchronized { + val path = savePath + val chunk = e.getChunk.getChunkCoordIntPair + val chunkPath = new io.File(path, s"${chunk.chunkXPos}.${chunk.chunkZPos}") + if (chunkPath.exists && chunkPath.isDirectory) { + for (file <- chunkPath.listFiles()) file.delete() + } + saveData.get(chunk) match { + case Some(entries) => + chunkPath.mkdirs() + for ((name, data) <- entries) { + val file = new io.File(chunkPath, name) + try { + // val fos = new GZIPOutputStream(new io.FileOutputStream(file)) + val fos = new io.BufferedOutputStream(new io.FileOutputStream(file)) + fos.write(data) + fos.close() + } + catch { + case e: io.IOException => OpenComputers.log.log(Level.WARNING, s"Error saving auxiliary tile entity data to '${file.getAbsolutePath}.", e) + } + } + case _ => chunkPath.delete() + } + } + @ForgeSubscribe def onWorldSave(e: WorldEvent.Save) = saveData.synchronized { - val path = savePath - path.mkdirs() - for ((chunk, entries) <- saveData) { - val chunkPath = new io.File(path, s"${chunk.chunkXPos}.${chunk.chunkZPos}") - chunkPath.mkdirs() - if (chunkPath.exists && chunkPath.isDirectory) { - for (file <- chunkPath.listFiles()) file.delete() - } - for ((name, data) <- entries) { - val file = new io.File(chunkPath, name) - try { - // val fos = new GZIPOutputStream(new io.FileOutputStream(file)) - val fos = new io.BufferedOutputStream(new io.FileOutputStream(file)) - fos.write(data) - fos.close() - } - catch { - case e: io.IOException => OpenComputers.log.log(Level.WARNING, s"Error saving auxiliary tile entity data to '${file.getAbsolutePath}.", e) - } - } - } saveData.clear() } } From 8c1571c1d0c0b258b19cb5a81d117413e4828b7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sun, 16 Mar 2014 17:05:52 +0100 Subject: [PATCH 3/4] added javadoc jar generation; added fingerprint generation/check and jar signing --- build.gradle | 1 + gradle/artifact.gradle | 10 +++++ gradle/forge.gradle | 4 ++ gradle/sign.gradle | 37 +++++++++++++++++++ .../assets/opencomputers/lang/de_DE.lang | 1 + .../assets/opencomputers/lang/en_US.lang | 1 + src/main/scala/li/cil/oc/OpenComputers.scala | 12 ++++-- .../li/cil/oc/common/ConnectionHandler.scala | 6 ++- .../li/cil/oc/common/tileentity/Robot.scala | 2 +- 9 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 gradle/sign.gradle diff --git a/build.gradle b/build.gradle index d285c510f..56fd752b8 100644 --- a/build.gradle +++ b/build.gradle @@ -32,4 +32,5 @@ version = "MC${config.minecraft.version}-${project.version}" apply from: 'gradle/forge.gradle' apply from: 'gradle/artifact.gradle' +apply from: 'gradle/sign.gradle' apply from: 'gradle/release.gradle' diff --git a/gradle/artifact.gradle b/gradle/artifact.gradle index 628ada98f..2d7cd9fca 100644 --- a/gradle/artifact.gradle +++ b/gradle/artifact.gradle @@ -6,6 +6,10 @@ jar { } } +javadoc { + include 'li/cil/oc/api/**' +} + // because the normal default jar task has been modified to be obfuscated task deobfJar(type: Jar) { from sourceSets.main.output @@ -22,7 +26,13 @@ task apiJar(type: Jar) { include 'li/cil/oc/api/**' } +task javadocJar(type: Jar, dependsOn: javadoc) { + from 'build/docs/javadoc' + classifier 'javadoc' +} + artifacts { archives deobfJar archives apiJar + archives javadocJar } diff --git a/gradle/forge.gradle b/gradle/forge.gradle index a8529927b..78112ad1e 100644 --- a/gradle/forge.gradle +++ b/gradle/forge.gradle @@ -13,6 +13,10 @@ compileScala { minecraft { version = "${config.minecraft.version}-${config.forge.version}" + + replaceIn "li/cil/oc/OpenComputers.scala" + if (project.hasProperty("keystore_fingerprint")) + replace "@FINGERPRINT@", keystore_fingerprint } processResources { diff --git a/gradle/sign.gradle b/gradle/sign.gradle new file mode 100644 index 000000000..7bf869cba --- /dev/null +++ b/gradle/sign.gradle @@ -0,0 +1,37 @@ +// Based on the code from TinkersConstruct and Cazzar's repo. +// Thanks ProgWML6 and Cazzar! + +// verify the properties exist... or initialize. +if (!project.hasProperty("keystore_location")) // keystore stuff + ext.keystore_location = "" + +if (!project.hasProperty("keystore_alias")) // keystore stuff + ext.keystore_alias = "" + +if (!project.hasProperty("keystore_password")) // keystore stuff + ext.keystore_password = "" + +task("signJar", dependsOn: "reobf") { + inputs.file jar.getArchivePath() + inputs.file keystore_location + inputs.property "keystore_alias", keystore_alias + inputs.property "keystore_password", keystore_password + outputs.file jar.getArchivePath() + + // only sign if the keystore exists + onlyIf { + return !keystore_location.empty + } + + // the actual action - sign the jar. + doLast { + ant.signjar( + destDir: jar.destinationDir, + jar: jar.getArchivePath(), + keystore: keystore_location, + alias: keystore_alias, + storepass: keystore_password, + keypass: keystore_password + ) + } +} \ No newline at end of file diff --git a/src/main/resources/assets/opencomputers/lang/de_DE.lang b/src/main/resources/assets/opencomputers/lang/de_DE.lang index 0b71756f7..da4830c6f 100644 --- a/src/main/resources/assets/opencomputers/lang/de_DE.lang +++ b/src/main/resources/assets/opencomputers/lang/de_DE.lang @@ -88,6 +88,7 @@ oc:gui.Analyzer.StoredEnergy=§6Gespeicherte Energie§f: %s oc:gui.Analyzer.TotalEnergy=§6Insgesamt gespeicherte Energie§f: %s oc:gui.Analyzer.Users=§6Benutzer§f: %s oc:gui.Chat.NewVersion=Eine neue Version ist verfügbar: %s +oc:gui.Chat.WarningFingerprint=§cWARNUNG§f - ungültige Signatur! Sollte §a'%s'§f sein, aber war §e'%s'§f. Falls du kein Modder bist und die "deobfuscated"-Version des Mods benutzt, solltest du OpenComputers erneut herunterladen, da die JAR die du benutzt vermutlich modifiziert wurde. oc:gui.Chat.WarningLuaFallback=Die native Lua-Implementierung ist nicht verfügbar. Computer können ihren Ausführungszustand nicht speichern. Sie werden automatisch neu starten, sobald ein Chunk neu geladen wird. oc:gui.Chat.WarningPower=Es ist kein unterstützter, Strom erzeugender Mod verfügbar. Computer, Bildschirme und alle anderen Komponenten werden §lkeine§f Energie benötigen. Installiere einen der folgenden Mods, um Stromnutzung zu ermöglichen: BuildCraft, IndustrialCraft2, Thermal Expansion oder Universal Electricity. Deaktiviere Stromverbrauch in der Konfiguration, um diese Warnung zu unterdrücken. oc:gui.Chat.WarningProjectRed=Die verwendete Version von Project: Red ist nicht mit OpenComputers kompatibel. Aktualisiere bitte deine Version von Project: Red. diff --git a/src/main/resources/assets/opencomputers/lang/en_US.lang b/src/main/resources/assets/opencomputers/lang/en_US.lang index 10c6bb9d7..745111e79 100644 --- a/src/main/resources/assets/opencomputers/lang/en_US.lang +++ b/src/main/resources/assets/opencomputers/lang/en_US.lang @@ -88,6 +88,7 @@ oc:gui.Analyzer.StoredEnergy=§6Stored energy§f: %s oc:gui.Analyzer.TotalEnergy=§6Total stored energy§f: %s oc:gui.Analyzer.Users=§6Users§f: %s oc:gui.Chat.NewVersion=A new version is available: %s +oc:gui.Chat.WarningFingerprint=§cWARNING§f - fingerprint mismatch! Expected §a'%s'§f but got §e'%s'§f. Unless you are a modder and are running the deobfuscated version of the mod, it is §lstrongly§f recommended to redownload OpenComputers, because the JAR you are using may have been tampered with. oc:gui.Chat.WarningLuaFallback=Native Lua libraries are not available, computers will not be able to persist their state. They will reboot on chunk reloads. oc:gui.Chat.WarningPower=No supported power providing mod available. Computers, screens and all other components will §lnot§f require energy. Install one of the following mods to enable power: BuildCraft, IndustrialCraft2, Thermal Expansion or Universal Electricity. Disable power in the config to suppress this warning. oc:gui.Chat.WarningProjectRed=You are using a version of Project: Red that is incompatible with OpenComputers. Try updating your version of Project: Red. diff --git a/src/main/scala/li/cil/oc/OpenComputers.scala b/src/main/scala/li/cil/oc/OpenComputers.scala index cf8426273..b09dab4db 100644 --- a/src/main/scala/li/cil/oc/OpenComputers.scala +++ b/src/main/scala/li/cil/oc/OpenComputers.scala @@ -3,9 +3,7 @@ package li.cil.oc import cpw.mods.fml.common.Mod import cpw.mods.fml.common.Mod.EventHandler import cpw.mods.fml.common.SidedProxy -import cpw.mods.fml.common.event.FMLInitializationEvent -import cpw.mods.fml.common.event.FMLPostInitializationEvent -import cpw.mods.fml.common.event.FMLPreInitializationEvent +import cpw.mods.fml.common.event.{FMLFingerprintViolationEvent, FMLInitializationEvent, FMLPostInitializationEvent, FMLPreInitializationEvent} import cpw.mods.fml.common.network.NetworkMod import cpw.mods.fml.common.network.NetworkMod._ import java.util.logging.Logger @@ -13,7 +11,8 @@ import li.cil.oc.client.{PacketHandler => ClientPacketHandler} import li.cil.oc.common.Proxy import li.cil.oc.server.{PacketHandler => ServerPacketHandler} -@Mod(modid = "OpenComputers", modLanguage = "scala", useMetadata = true) +@Mod(modid = "OpenComputers", modLanguage = "scala", + certificateFingerprint = "@FINGERPRINT@", useMetadata = true) @NetworkMod(clientSideRequired = true, serverSideRequired = false, clientPacketHandlerSpec = new SidedPacketHandler( channels = Array("OpenComp"), packetHandler = classOf[ClientPacketHandler]), @@ -25,6 +24,11 @@ object OpenComputers { @SidedProxy(clientSide = "li.cil.oc.client.Proxy", serverSide = "li.cil.oc.server.Proxy") var proxy: Proxy = null + var tampered: Option[FMLFingerprintViolationEvent] = None + + @EventHandler + def invalidFingerprint(e: FMLFingerprintViolationEvent) = tampered = Some(e) + @EventHandler def preInit(e: FMLPreInitializationEvent) = proxy.preInit(e) diff --git a/src/main/scala/li/cil/oc/common/ConnectionHandler.scala b/src/main/scala/li/cil/oc/common/ConnectionHandler.scala index b619540f4..ca7924544 100644 --- a/src/main/scala/li/cil/oc/common/ConnectionHandler.scala +++ b/src/main/scala/li/cil/oc/common/ConnectionHandler.scala @@ -3,7 +3,7 @@ package li.cil.oc.common import cpw.mods.fml.common.network.{Player, IConnectionHandler} import li.cil.oc.util.LuaStateFactory import li.cil.oc.util.mods.ProjectRed -import li.cil.oc.{UpdateCheck, Settings} +import li.cil.oc.{OpenComputers, UpdateCheck, Settings} import net.minecraft.entity.player.EntityPlayerMP import net.minecraft.network.packet.{Packet1Login, NetHandler} import net.minecraft.network.{NetLoginHandler, INetworkManager} @@ -23,6 +23,10 @@ object ConnectionHandler extends IConnectionHandler { if (!Settings.get.pureIgnorePower && Settings.get.ignorePower) { p.sendChatToPlayer(ChatMessageComponent.createFromText("§aOpenComputers§f: ").addKey(Settings.namespace + "gui.Chat.WarningPower")) } + OpenComputers.tampered match { + case Some(event) => p.sendChatToPlayer(ChatMessageComponent.createFromText("§aOpenComputers§f: ").addFormatted(Settings.namespace + "gui.Chat.WarningFingerprint", event.expectedFingerprint, event.fingerprints.toArray.mkString(", "))) + case _ => + } // Do update check in local games and for OPs. if (!MinecraftServer.getServer.isDedicatedServer || MinecraftServer.getServer.getConfigurationManager.isPlayerOpped(p.getCommandSenderName)) { UpdateCheck.checkForPlayer(p) diff --git a/src/main/scala/li/cil/oc/common/tileentity/Robot.scala b/src/main/scala/li/cil/oc/common/tileentity/Robot.scala index 6f566b718..05f84cea5 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Robot.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Robot.scala @@ -618,7 +618,7 @@ object Robot { catch { case t: Throwable => OpenComputers.log.log(Level.WARNING, "Failed loading robot name list.", t) - Array.empty + Array.empty[String] } def randomName = names((math.random * names.length).toInt) From 1ac63d205a900ff836968bfb233858983bdda307 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sun, 16 Mar 2014 17:17:23 +0100 Subject: [PATCH 4/4] some jdoc fixes --- src/main/java/li/cil/oc/api/machine/Machine.java | 2 +- src/main/java/li/cil/oc/api/network/Network.java | 8 ++++---- src/main/java/li/cil/oc/api/network/SidedEnvironment.java | 7 ++++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/li/cil/oc/api/machine/Machine.java b/src/main/java/li/cil/oc/api/machine/Machine.java index df28c65fe..fdb671324 100644 --- a/src/main/java/li/cil/oc/api/machine/Machine.java +++ b/src/main/java/li/cil/oc/api/machine/Machine.java @@ -79,7 +79,7 @@ public interface Machine extends ManagedEnvironment, Context { * The address of the file system that holds the machine's read only data * (rom). This file system is populated based on the backing resource file * systems specified for the machines architecture via - * {@link li.cil.oc.api.Machine#addRomResource(Class, FileSystem, String)}. + * {@link li.cil.oc.api.Machine#addRomResource(Class, java.util.concurrent.Callable, String)}. * This may return null if the creation of the file system * failed. *

    diff --git a/src/main/java/li/cil/oc/api/network/Network.java b/src/main/java/li/cil/oc/api/network/Network.java index 8cb6b7bc3..3d76f0014 100644 --- a/src/main/java/li/cil/oc/api/network/Network.java +++ b/src/main/java/li/cil/oc/api/network/Network.java @@ -178,7 +178,7 @@ public interface Network { * @param name the name of the message. * @param data the message to send. * @throws IllegalArgumentException if the source node is not in this network. - * @see `neighbors` + * @see #neighbors(Node) */ void sendToNeighbors(Node source, String name, Object... data); @@ -196,7 +196,7 @@ public interface Network { * @param source the node that sends the message. * @param data the message to send. * @throws IllegalArgumentException if the source node is not in this network. - * @see {@link #nodes(Node)} + * @see #nodes(Node) */ void sendToReachable(Node source, String name, Object... data); @@ -218,8 +218,8 @@ public interface Network { * @param source the node that sends the message. * @param data the message to send. * @throws IllegalArgumentException if the source node is not in this network. - * @see {@link #nodes(Node)} - * @see {@link Component#canBeSeenFrom(Node)} + * @see #nodes(Node) + * @see Component#canBeSeenFrom(Node) */ void sendToVisible(Node source, String name, Object... data); } diff --git a/src/main/java/li/cil/oc/api/network/SidedEnvironment.java b/src/main/java/li/cil/oc/api/network/SidedEnvironment.java index a650f85df..26fd99edb 100644 --- a/src/main/java/li/cil/oc/api/network/SidedEnvironment.java +++ b/src/main/java/li/cil/oc/api/network/SidedEnvironment.java @@ -2,6 +2,7 @@ package li.cil.oc.api.network; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; /** @@ -11,9 +12,9 @@ import net.minecraftforge.common.ForgeDirection; *

    * This interface is intended to be used on tile entities that are environments. * It is used to determine which neighbors a tile entity can connect to when - * calling {@link li.cil.oc.api.Network#joinOrCreateNetwork}. It is used by the - * keyboard to only interface with the side on which it is attached, as well as - * the router to offer a different node for each side. + * calling {@link li.cil.oc.api.Network#joinOrCreateNetwork(TileEntity)}. It is + * used by the keyboard to only interface with the side on which it is attached, + * as well as the router to offer a different node for each side. */ public interface SidedEnvironment { /**