mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-26 22:43:40 -04:00
Merge branch 'master' of https://github.com/MightyPirates/OpenComputers into MC1.7
Conflicts: src/main/java/li/cil/oc/api/network/SidedEnvironment.java src/main/scala/li/cil/oc/OpenComputers.scala src/main/scala/li/cil/oc/common/ConnectionHandler.scala src/main/scala/li/cil/oc/common/SaveHandler.scala
This commit is contained in:
commit
e7f4a32d95
@ -36,4 +36,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'
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -15,6 +15,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 {
|
||||
|
37
gradle/sign.gradle
Normal file
37
gradle/sign.gradle
Normal file
@ -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
|
||||
)
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package li.cil.oc.api.machine;
|
||||
|
||||
import li.cil.oc.api.fs.FileSystem;
|
||||
import li.cil.oc.api.network.Callback;
|
||||
import li.cil.oc.api.network.Context;
|
||||
import li.cil.oc.api.network.ManagedEnvironment;
|
||||
@ -79,7 +78,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 <tt>null</tt> if the creation of the file system
|
||||
* failed.
|
||||
* <p/>
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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.util.ForgeDirection;
|
||||
|
||||
/**
|
||||
@ -11,9 +12,9 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
* <p/>
|
||||
* 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 {
|
||||
/**
|
||||
|
@ -80,7 +80,7 @@ import org.luaj.vm3.lib.ResourceFinder;
|
||||
* <li>{@link STDIN} Current value for standard input in the laaded IoLib, if any.
|
||||
* <li>{@link STDOUT} Current value for standard output in the loaded IoLib, if any.
|
||||
* <li>{@link STDERR} Current value for standard error in the loaded IoLib, if any.
|
||||
* <li>{@link FINDER} Current loaded {@link ResourceFinder}, if any.
|
||||
* <li>{@link finder} Current loaded {@link ResourceFinder}, if any.
|
||||
* <li>{@link compiler} Current loaded {@link Compiler}, if any.
|
||||
* <li>{@link undumper} Current loaded {@link Undumper}, if any.
|
||||
* <li>{@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);
|
||||
}
|
||||
|
@ -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 );
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ import org.luaj.vm3.Varargs;
|
||||
* <p>
|
||||
* 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 {
|
||||
|
@ -72,8 +72,12 @@ import org.luaj.vm3.Varargs;
|
||||
* @see <a href="http://www.lua.org/manual/5.2/manual.html#6.10">Lua 5.2 Debug Lib Reference</a>
|
||||
*/
|
||||
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("?");
|
||||
|
@ -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
|
||||
* <code>"luaj.package.path"</code>, and is <code>"?.lua"</code> 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);
|
||||
|
@ -31,13 +31,13 @@ import java.io.InputStream;
|
||||
* for both the Jme and Jse platforms.
|
||||
* <p>
|
||||
* 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)}.
|
||||
* <p>
|
||||
* The io library does not use this API for file manipulation.
|
||||
* <p>
|
||||
* @see BaseLib
|
||||
* @see BaseLib#FINDER
|
||||
* @see Globals#finder
|
||||
* @see JseBaseLib
|
||||
* @see JmePlatform
|
||||
* @see JsePlatform
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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}.
|
||||
* <p>
|
||||
* 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}.
|
||||
* <p>
|
||||
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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())
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -3,14 +3,13 @@ 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.FMLEventChannel
|
||||
import java.util.logging.Logger
|
||||
import li.cil.oc.common.Proxy
|
||||
|
||||
@Mod(modid = "OpenComputers", modLanguage = "scala", useMetadata = true)
|
||||
@Mod(modid = "OpenComputers", modLanguage = "scala",
|
||||
certificateFingerprint = "@FINGERPRINT@", useMetadata = true)
|
||||
object OpenComputers {
|
||||
val log = Logger.getLogger("OpenComputers")
|
||||
|
||||
@ -19,6 +18,11 @@ object OpenComputers {
|
||||
|
||||
var channel: FMLEventChannel = _
|
||||
|
||||
var tampered: Option[FMLFingerprintViolationEvent] = None
|
||||
|
||||
@EventHandler
|
||||
def invalidFingerprint(e: FMLFingerprintViolationEvent) = tampered = Some(e)
|
||||
|
||||
@EventHandler
|
||||
def preInit(e: FMLPreInitializationEvent) = proxy.preInit(e)
|
||||
|
||||
|
@ -1,15 +1,15 @@
|
||||
package li.cil.oc.common
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent
|
||||
import cpw.mods.fml.common.FMLCommonHandler
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent._
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.ServerTickEvent
|
||||
import cpw.mods.fml.common.{Loader, FMLCommonHandler}
|
||||
import li.cil.oc.api.Network
|
||||
import li.cil.oc.server.driver.Registry
|
||||
import li.cil.oc.util.ExtendedNBT._
|
||||
import li.cil.oc.util.LuaStateFactory
|
||||
import li.cil.oc.util.mods.ProjectRed
|
||||
import li.cil.oc.{UpdateCheck, Items, Settings}
|
||||
import li.cil.oc.{OpenComputers, UpdateCheck, Items, Settings}
|
||||
import net.minecraft.entity.player.EntityPlayerMP
|
||||
import net.minecraft.item.{ItemMap, ItemStack}
|
||||
import net.minecraft.server.MinecraftServer
|
||||
@ -57,6 +57,11 @@ object EventHandler {
|
||||
player.addChatMessage(new ChatComponentText("§aOpenComputers§f: ").appendSibling(
|
||||
new ChatComponentTranslation(Settings.namespace + "gui.Chat.WarningPower")))
|
||||
}
|
||||
OpenComputers.tampered match {
|
||||
case Some(event) => player.addChatMessage(new ChatComponentText("§aOpenComputers§f: ").appendSibling(
|
||||
new ChatComponentTranslation(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(player.getCommandSenderName)) {
|
||||
UpdateCheck.checkForPlayer(player)
|
||||
|
@ -6,9 +6,12 @@ import java.util.logging.Level
|
||||
import li.cil.oc.{OpenComputers, Settings}
|
||||
import net.minecraft.world.ChunkCoordIntPair
|
||||
import net.minecraftforge.common.DimensionManager
|
||||
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.
|
||||
@SubscribeEvent
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ class Robot(val isRemote: Boolean) extends Computer with ISidedInventory with Bu
|
||||
}
|
||||
else {
|
||||
tag = new NBTTagCompound()
|
||||
}
|
||||
}
|
||||
if (name == null) {
|
||||
tag.setNewCompoundTag("display", tag => tag.setString("Name", Robot.randomName))
|
||||
}
|
||||
@ -620,7 +620,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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user