From d5f19c21d8b7184541175644f2e5890b97b498b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 16 Feb 2015 18:17:43 +0100 Subject: [PATCH 1/7] Added event viewing program MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Łukasz Magiera --- .../opencomputers/loot/OpenOS/bin/dmesg.lua | 31 +++++++++++++++++++ .../opencomputers/loot/OpenOS/usr/man/dmesg | 6 ++++ 2 files changed, 37 insertions(+) create mode 100644 src/main/resources/assets/opencomputers/loot/OpenOS/bin/dmesg.lua create mode 100644 src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/dmesg diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/dmesg.lua b/src/main/resources/assets/opencomputers/loot/OpenOS/bin/dmesg.lua new file mode 100644 index 000000000..60bfd71e7 --- /dev/null +++ b/src/main/resources/assets/opencomputers/loot/OpenOS/bin/dmesg.lua @@ -0,0 +1,31 @@ +local event = require "event" +local component = require "component" + +local interactive = io.output() == io.stdout +local color, isPal, evt +if interactive then + color, isPal = component.gpu.getForeground() +end +pcall(function() + repeat + evt = {event.pull()} + if interactive then component.gpu.setForeground(0xCC2200) end + io.write("[" .. os.date("%T") .. "] ") + if interactive then component.gpu.setForeground(0x44CC00) end + io.write(tostring(evt[1]) .. string.rep(" ", math.max(10 - #tostring(evt[1]), 0) + 1)) + if interactive then component.gpu.setForeground(0xB0B00F) end + io.write(tostring(evt[2]) .. string.rep(" ", 37 - #tostring(evt[2]))) + if interactive then component.gpu.setForeground(0xFFFFFF) end + if #evt > 2 then + for i = 3, #evt do + io.write(" " .. tostring(evt[i])) + end + end + + io.write("\n") + until evt[1] == "key_down" and evt[3] == 113 +end) +if interactive then + component.gpu.setForeground(color, isPal) +end + diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/dmesg b/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/dmesg new file mode 100644 index 000000000..89f1f7e10 --- /dev/null +++ b/src/main/resources/assets/opencomputers/loot/OpenOS/usr/man/dmesg @@ -0,0 +1,6 @@ +NAME + dmesg - display messages(events) + +SYNOPIS + dmesg + From d71c52136fdea95fd820e1246be94523c98501eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 16 Feb 2015 18:51:07 +0100 Subject: [PATCH 2/7] Added backwards compatibility to OpenLoader MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Łukasz Magiera --- .../opencomputers/loot/OpenLoader/bin/opl-flash.lua | 13 +++++++++++-- .../assets/opencomputers/loot/OpenLoader/init.lua | 9 ++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/resources/assets/opencomputers/loot/OpenLoader/bin/opl-flash.lua b/src/main/resources/assets/opencomputers/loot/OpenLoader/bin/opl-flash.lua index d13f30063..a8de2204e 100644 --- a/src/main/resources/assets/opencomputers/loot/OpenLoader/bin/opl-flash.lua +++ b/src/main/resources/assets/opencomputers/loot/OpenLoader/bin/opl-flash.lua @@ -1,9 +1,18 @@ +local version = "OpenLoader 0.2EE" + local eeprom = [[ -_G._OSVERSION = "OpenLoader 0.1EE" +_G._OSVERSION = "]] .. version .. [[" local component = component or require('component') local computer = computer or require('computer') local unicode = unicode or require('unicode') +local eeprom = component.list("eeprom")() +computer.getBootAddress = function() + return component.invoke(eeprom, "getData") +end +computer.setBootAddress = function(address) + return component.invoke(eeprom, "setData", address) +end local gpu = component.list("gpu")() local w, h @@ -147,7 +156,7 @@ say ("Do you really want to flash openloader to EEPROM("..tostring(#eeprom).." b if options.q or options.quiet or io.read():lower() == "y" then say("Flashing... Do not reboot now!") component.eeprom.set(eeprom) - component.eeprom.setLabel((type(options.label) == "string" and options.label) or "OpenLoader") + component.eeprom.setLabel((type(options.label) == "string" and options.label) or version) if options.r or options.reboot then computer.shutdown(true) else diff --git a/src/main/resources/assets/opencomputers/loot/OpenLoader/init.lua b/src/main/resources/assets/opencomputers/loot/OpenLoader/init.lua index 2f70d5a3b..037fde921 100644 --- a/src/main/resources/assets/opencomputers/loot/OpenLoader/init.lua +++ b/src/main/resources/assets/opencomputers/loot/OpenLoader/init.lua @@ -1,8 +1,15 @@ -_G._OSVERSION = "OpenLoader 0.1" +_G._OSVERSION = "OpenLoader 0.2" local component = component or require('component') local computer = computer or require('computer') local unicode = unicode or require('unicode') +local eeprom = component.list("eeprom")() +computer.getBootAddress = function() + return component.invoke(eeprom, "getData") +end +computer.setBootAddress = function(address) + return component.invoke(eeprom, "setData", address) +end local gpu = component.list("gpu")() local w, h From bfb1347e8ca188b2cd00900b8385f29838d39dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 16 Feb 2015 20:58:46 +0100 Subject: [PATCH 3/7] Done some suggestions in dmesg.lua --- .../assets/opencomputers/loot/OpenOS/bin/dmesg.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/dmesg.lua b/src/main/resources/assets/opencomputers/loot/OpenOS/bin/dmesg.lua index 60bfd71e7..ab3bb4a0e 100644 --- a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/dmesg.lua +++ b/src/main/resources/assets/opencomputers/loot/OpenOS/bin/dmesg.lua @@ -1,14 +1,16 @@ local event = require "event" local component = require "component" +local keyboard = require "keyboard" local interactive = io.output() == io.stdout local color, isPal, evt if interactive then color, isPal = component.gpu.getForeground() end +io.write("Press 'q' to exit\n") pcall(function() repeat - evt = {event.pull()} + evt = table.pack(event.pull()) if interactive then component.gpu.setForeground(0xCC2200) end io.write("[" .. os.date("%T") .. "] ") if interactive then component.gpu.setForeground(0x44CC00) end @@ -16,14 +18,14 @@ pcall(function() if interactive then component.gpu.setForeground(0xB0B00F) end io.write(tostring(evt[2]) .. string.rep(" ", 37 - #tostring(evt[2]))) if interactive then component.gpu.setForeground(0xFFFFFF) end - if #evt > 2 then - for i = 3, #evt do + if evt.n > 2 then + for i = 3, evt.n do io.write(" " .. tostring(evt[i])) end end io.write("\n") - until evt[1] == "key_down" and evt[3] == 113 + until evt[1] == "key_down" and evt[4] == keyboard.keys.q end) if interactive then component.gpu.setForeground(color, isPal) From aaca5c45929ad58f1474b1f77b1d0fee2908fc5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Mon, 16 Feb 2015 22:01:45 +0100 Subject: [PATCH 4/7] Fixed dangling raid fses. --- src/main/scala/li/cil/oc/common/tileentity/Raid.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/scala/li/cil/oc/common/tileentity/Raid.scala b/src/main/scala/li/cil/oc/common/tileentity/Raid.scala index 296617ecb..def714fda 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Raid.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Raid.scala @@ -77,7 +77,8 @@ class Raid extends traits.Environment with traits.Inventory with traits.Rotatabl } def tryCreateRaid(id: String) { - if (items.count(_.isDefined) == items.length) { + if (items.count(_.isDefined) == items.length && filesystem.fold(true)(fs => fs.node == null || fs.node.address != id)) { + filesystem.foreach(fs => if (fs.node != null) fs.node.remove()) val fs = api.FileSystem.asManagedEnvironment( api.FileSystem.fromSaveDirectory(id, wipeDisksAndComputeSpace, Settings.get.bufferChanges), label, this, Settings.resourceDomain + ":hdd_access"). From 5416ee9f5587f234fb9e9ce2265b702eb4fdf911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Mon, 16 Feb 2015 23:21:53 +0100 Subject: [PATCH 5/7] Fixed two potential NPEs. --- src/main/scala/li/cil/oc/common/block/RobotProxy.scala | 2 +- src/main/scala/li/cil/oc/common/tileentity/Robot.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/scala/li/cil/oc/common/block/RobotProxy.scala b/src/main/scala/li/cil/oc/common/block/RobotProxy.scala index 7bf14710e..987dfee1e 100644 --- a/src/main/scala/li/cil/oc/common/block/RobotProxy.scala +++ b/src/main/scala/li/cil/oc/common/block/RobotProxy.scala @@ -88,7 +88,7 @@ class RobotProxy extends RedstoneAware with traits.SpecialBlock with traits.Stat val components = info.containers ++ info.components if (components.length > 0) { tooltip.addAll(Tooltip.get("Server.Components")) - for (component <- components) { + for (component <- components if component != null) { tooltip.add("- " + component.getDisplayName) } } 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 31f0db864..3a0959bdd 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Robot.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Robot.scala @@ -692,8 +692,8 @@ class Robot extends traits.Computer with traits.PowerInformation with IFluidHand player().inventory.addItemStackToInventory(stack) spawnStackInWorld(stack, Option(facing)) } + setSelectedSlot(oldSelected) } // else: save is screwed and we potentially lose items. Life is hard. - setSelectedSlot(oldSelected) } } finally { From 4000d88231eabceff0f6bdcd42af9dbe20f2cf4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Mon, 16 Feb 2015 23:23:09 +0100 Subject: [PATCH 6/7] Made debug card use actual fake player for running commands. Kinda closes #892. --- .../cil/oc/server/component/DebugCard.scala | 61 ++++++++++++------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/src/main/scala/li/cil/oc/server/component/DebugCard.scala b/src/main/scala/li/cil/oc/server/component/DebugCard.scala index ee94b8f4d..c0c965246 100644 --- a/src/main/scala/li/cil/oc/server/component/DebugCard.scala +++ b/src/main/scala/li/cil/oc/server/component/DebugCard.scala @@ -20,7 +20,6 @@ import li.cil.oc.util.ExtendedArguments._ import li.cil.oc.util.ExtendedWorld._ import li.cil.oc.util.InventoryUtils import net.minecraft.block.Block -import net.minecraft.command.ICommandSender import net.minecraft.entity.player.EntityPlayerMP import net.minecraft.item.Item import net.minecraft.item.ItemStack @@ -33,12 +32,14 @@ import net.minecraft.world.World import net.minecraft.world.WorldServer import net.minecraft.world.WorldSettings.GameType import net.minecraftforge.common.DimensionManager +import net.minecraftforge.common.util.FakePlayer import net.minecraftforge.common.util.FakePlayerFactory import net.minecraftforge.common.util.ForgeDirection import net.minecraftforge.fluids.FluidRegistry import net.minecraftforge.fluids.FluidStack import net.minecraftforge.fluids.IFluidHandler +import scala.collection.convert.WrapAsScala._ import scala.collection.mutable class DebugCard(host: EnvironmentHost) extends prefab.ManagedEnvironment { @@ -56,6 +57,17 @@ class DebugCard(host: EnvironmentHost) extends prefab.ManagedEnvironment { // Player this card is bound to (if any) to use for permissions. var player: Option[String] = None + private lazy val CommandSender = { + def defaultFakePlayer = FakePlayerFactory.get(host.world.asInstanceOf[WorldServer], Settings.get.fakePlayerProfile) + new CommandSender(host, player match { + case Some(name) => Option(MinecraftServer.getServer.getConfigurationManager.func_152612_a(name)) match { + case Some(playerEntity) => playerEntity + case _ => defaultFakePlayer + } + case _ => defaultFakePlayer + }) + } + // ----------------------------------------------------------------------- // import li.cil.oc.server.component.DebugCard.checkEnabled @@ -99,10 +111,18 @@ class DebugCard(host: EnvironmentHost) extends prefab.ManagedEnvironment { @Callback(doc = """function(command:string):number -- Runs an arbitrary command using a fake player.""") def runCommand(context: Context, args: Arguments): Array[AnyRef] = { checkEnabled() - val command = args.checkString(0) - val sender = new CommandSender(host, player) - val value = MinecraftServer.getServer.getCommandManager.executeCommand(sender, command) - result(value, sender.messages.orNull) + val commands = + if (args.isTable(0)) collectionAsScalaIterable(args.checkTable(0).values()) + else Iterable (args.checkString(0)) + + CommandSender.synchronized { + CommandSender.prepare() + var value = 0 + for (command <- commands) { + value = MinecraftServer.getServer.getCommandManager.executeCommand(CommandSender, command.toString) + } + result(value, CommandSender.messages.orNull) + } } @Callback(doc = """function(x:number, y:number, z:number):boolean -- Connect the debug card to the block at the specified coordinates.""") @@ -496,31 +516,28 @@ object DebugCard { } } - class CommandSender(val host: EnvironmentHost, val playerName: Option[String]) extends ICommandSender { - val fakePlayer = { - def defaultFakePlayer = FakePlayerFactory.get(host.world.asInstanceOf[WorldServer], Settings.get.fakePlayerProfile) - playerName match { - case Some(name) => Option(MinecraftServer.getServer.getConfigurationManager.func_152612_a(name)) match { - case Some(player) => player - case _ => defaultFakePlayer - } - case _ => defaultFakePlayer - } - } - + class CommandSender(val host: EnvironmentHost, val underlying: EntityPlayerMP) extends FakePlayer(underlying.getEntityWorld.asInstanceOf[WorldServer], underlying.getGameProfile) { var messages: Option[String] = None - override def getCommandSenderName = fakePlayer.getCommandSenderName + def prepare(): Unit = { + val blockPos = BlockPosition(host) + posX = blockPos.x + posY = blockPos.y + posZ = blockPos.z + messages = None + } + + override def getCommandSenderName = underlying.getCommandSenderName override def getEntityWorld = host.world override def addChatMessage(message: IChatComponent) { - messages = Option(messages.getOrElse("") + message.getUnformattedText) + messages = Option(messages.fold("")(_ + "\n") + message.getUnformattedText) } override def canCommandSenderUseCommand(level: Int, command: String) = { - val profile = fakePlayer.getGameProfile - val server = fakePlayer.mcServer + val profile = underlying.getGameProfile + val server = underlying.mcServer val config = server.getConfigurationManager server.isSinglePlayer || (config.func_152596_g(profile) && (config.func_152603_m.func_152683_b(profile) match { case entry: UserListOpsEntry => entry.func_152644_a >= level @@ -530,7 +547,7 @@ object DebugCard { override def getPlayerCoordinates = BlockPosition(host).toChunkCoordinates - override def func_145748_c_() = fakePlayer.func_145748_c_() + override def func_145748_c_() = underlying.func_145748_c_() } class TestValue extends AbstractValue { From a0b6ff4b6d9ce009518e8e59be7277edbe400455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Mon, 16 Feb 2015 23:31:19 +0100 Subject: [PATCH 7/7] This isn't MC1.8... fixed update in tile entity env prefab. --- .../java/li/cil/oc/api/prefab/TileEntityEnvironment.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/li/cil/oc/api/prefab/TileEntityEnvironment.java b/src/main/java/li/cil/oc/api/prefab/TileEntityEnvironment.java index 1f467dde0..e1fb6fca8 100644 --- a/src/main/java/li/cil/oc/api/prefab/TileEntityEnvironment.java +++ b/src/main/java/li/cil/oc/api/prefab/TileEntityEnvironment.java @@ -6,7 +6,6 @@ import li.cil.oc.api.network.Message; import li.cil.oc.api.network.Node; import li.cil.oc.api.network.Visibility; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.server.gui.IUpdatePlayerListBox; import net.minecraft.tileentity.TileEntity; /** @@ -18,7 +17,7 @@ import net.minecraft.tileentity.TileEntity; * network as an index structure to find other nodes connected to them. */ @SuppressWarnings("UnusedDeclaration") -public abstract class TileEntityEnvironment extends TileEntity implements Environment, IUpdatePlayerListBox { +public abstract class TileEntityEnvironment extends TileEntity implements Environment { /** * This must be set in subclasses to the node that is used to represent * this tile entity. @@ -97,7 +96,7 @@ public abstract class TileEntityEnvironment extends TileEntity implements Enviro // ----------------------------------------------------------------------- // @Override - public void update() { + public void updateEntity() { // On the first update, try to add our node to nearby networks. We do // this in the update logic, not in validate() because we need to access // neighboring tile entities, which isn't possible in validate().