From ed7f2f0a21e34fb53cc6b267b54a1385ccda2a58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sat, 8 Mar 2014 21:34:14 +0100 Subject: [PATCH 1/2] aaand fixed the return route, too... (cc -> oc networking) --- src/main/scala/li/cil/oc/common/Proxy.scala | 1 - src/main/scala/li/cil/oc/common/tileentity/Router.scala | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/scala/li/cil/oc/common/Proxy.scala b/src/main/scala/li/cil/oc/common/Proxy.scala index de8dcca59..c1f709403 100644 --- a/src/main/scala/li/cil/oc/common/Proxy.scala +++ b/src/main/scala/li/cil/oc/common/Proxy.scala @@ -41,7 +41,6 @@ class Proxy { def call = FileSystem.fromClass(OpenComputers.getClass, Settings.resourceDomain, "lua/rom") }, Settings.resourceDomain + "/lua/rom") - } def init(e: FMLInitializationEvent): Unit = { diff --git a/src/main/scala/li/cil/oc/common/tileentity/Router.scala b/src/main/scala/li/cil/oc/common/tileentity/Router.scala index edcdd58de..cf94622e2 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Router.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Router.scala @@ -52,7 +52,10 @@ class Router extends Hub with IPeripheral { case "transmit" => val sendPort = checkPort(arguments, 0) val answerPort = checkPort(arguments, 1) - plugs.foreach(_.node.sendToReachable("network.message", Seq(Int.box(sendPort), Int.box(answerPort)) ++ arguments.drop(2): _*)) + val data = Seq(Int.box(answerPort)) ++ arguments.drop(2) + plugs.foreach(plug => { + plug.node.sendToReachable("network.message", new Packet(plug.node.address, None, sendPort, data)) + }) null case "isWireless" => Array(java.lang.Boolean.FALSE) case _ => null From 0fe1d6893599de1487ea426e0487692fd20293f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sat, 8 Mar 2014 21:45:06 +0100 Subject: [PATCH 2/2] properly checking index bounds in hologram callbacks, avoids potential crash in update when invalid ones are passed --- src/main/scala/li/cil/oc/common/tileentity/Hologram.scala | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/scala/li/cil/oc/common/tileentity/Hologram.scala b/src/main/scala/li/cil/oc/common/tileentity/Hologram.scala index f0c52a935..5b49f3177 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Hologram.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Hologram.scala @@ -82,14 +82,18 @@ class Hologram extends Environment with SidedEnvironment with Analyzable { @Callback(direct = true, doc = """function(x:number, z:number):number -- Returns the bit mask representing the specified column.""") def get(computer: Context, args: Arguments): Array[AnyRef] = this.synchronized { val x = args.checkInteger(0) - 1 + if (x < 0 || x >= width) throw new ArrayIndexOutOfBoundsException() val z = args.checkInteger(1) - 1 + if (z < 0 || z >= width) throw new ArrayIndexOutOfBoundsException() result(volume(x + z * width)) } @Callback(direct = true, limit = 256, doc = """function(x:number, z:number, value:number) -- Set the bit mask for the specified column.""") def set(computer: Context, args: Arguments): Array[AnyRef] = this.synchronized { val x = args.checkInteger(0) - 1 + if (x < 0 || x >= width) throw new ArrayIndexOutOfBoundsException() val z = args.checkInteger(1) - 1 + if (z < 0 || z >= width) throw new ArrayIndexOutOfBoundsException() val value = args.checkInteger(2) volume(x + z * width) = value setDirty(x, z) @@ -99,7 +103,9 @@ class Hologram extends Environment with SidedEnvironment with Analyzable { @Callback(direct = true, limit = 128, doc = """function(x:number, z:number, height:number) -- Fills a column to the specified height.""") def fill(computer: Context, args: Arguments): Array[AnyRef] = this.synchronized { val x = args.checkInteger(0) - 1 + if (x < 0 || x >= width) throw new ArrayIndexOutOfBoundsException() val z = args.checkInteger(1) - 1 + if (z < 0 || z >= width) throw new ArrayIndexOutOfBoundsException() val height = math.min(32, math.max(0, args.checkInteger(2))) // Bit shifts in the JVM only use the lowest five bits... so we have to // manually check the height, to avoid the shift being a no-op.