From a96aa6a997169331c889ab46043d60f5cfa305c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sat, 22 Nov 2014 11:54:25 +0100 Subject: [PATCH] Added a debug item to allow debugging OC component networks better while not in dev-env. --- assets/items.psd | Bin 527962 -> 533920 bytes .../assets/opencomputers/lang/en_US.lang | 2 + .../opencomputers/textures/items/Debugger.png | Bin 0 -> 244 bytes src/main/resources/mcmod.info | 1 - .../cil/oc/common/component/TextBuffer.scala | 38 +++++++-- .../scala/li/cil/oc/common/init/Items.scala | 1 + .../li/cil/oc/common/item/Debugger.scala | 73 ++++++++++++++++++ .../scala/li/cil/oc/integration/Mods.scala | 4 +- .../li/cil/oc/server/network/Network.scala | 2 + 9 files changed, 111 insertions(+), 10 deletions(-) create mode 100644 src/main/resources/assets/opencomputers/textures/items/Debugger.png create mode 100644 src/main/scala/li/cil/oc/common/item/Debugger.scala diff --git a/assets/items.psd b/assets/items.psd index 72232e3390e01a1314d7b91cde25ed4dd735cd31..ad2ca3c3fcf72229de41d9e849f3878dd3e28d90 100644 GIT binary patch delta 3599 zcmai04OA4@6@D|$GNYhwhKNe-vL>df1##JmgJ_EcVY4}rbx~1_1b>S7i~M926mPq?Qp~g=7}7KfS9x+p-D_pl;Fr`{D%~8&pdqM{s_<98@b8H z?zc87e#5BWg;N#Bn8%E-(Ksb6EYcuFjtX~F^cvf9U-6<>PA~m$r5M8pF{348oMen0 z6&4m9J7!dz!7#=UGdgzEgi%sO5&sQ#Tr}nfy}{8@^krn9?$0@92c534?Al?hVC&yw z`u0&$V`*wghpqisog@CTZ?FCg0AC=I3IHDj4+ctH4v9tJ2QMK6g@Sh#LI}Xp83H~(bbMzHm36EP-jQk)-$g2V zC8M``{Dk!%i*-C(hX1jV=`=bwdgHPF<76<>Q}~?{M}FCxP1N?Cs?^AjmMG{po)yRj z1O}Z!gAhZ$CpZ13n`2^9CM8(n%pb=hhQaN9*%$`NU@%a&HB3o!%Ce{W9os;_)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F?vLl|4I9&2L%i-RC`JQSVUdXYb q_)!SU;;e9GIOaIge)~w}FkD9dlG{p5g&#Z=-BLJ4_&r?NGU9J?XF#n0 diff --git a/src/main/resources/assets/opencomputers/lang/en_US.lang b/src/main/resources/assets/opencomputers/lang/en_US.lang index 709e42afe..00c75c635 100644 --- a/src/main/resources/assets/opencomputers/lang/en_US.lang +++ b/src/main/resources/assets/opencomputers/lang/en_US.lang @@ -49,6 +49,7 @@ item.oc.CPU1.name=Central Processing Unit (CPU) (Tier 2) item.oc.CPU2.name=Central Processing Unit (CPU) (Tier 3) item.oc.CuttingWire.name=Cutting Wire item.oc.DebugCard.name=Debug Card +item.oc.Debugger.name=Network Debugger item.oc.Disk.name=Disk Platter item.oc.FloppyDisk.name=Floppy Disk item.oc.GraphicsCard0.name=Graphics Card (Tier 1) @@ -203,6 +204,7 @@ oc:tooltip.CPU=An essential component of all computers. The clock rate is a bit oc:tooltip.CPU.Architecture=Architecture: §f%s§7 oc:tooltip.CuttingWire=Used to cut clay blocks into circuit board shape. Breaks after one use, which probably makes it the most inefficient tool ever. oc:tooltip.DebugCard=Creative mode item, allows manipulating the world to make testing easier. Use at your own peril. +oc:tooltip.Debugger=Can be used to output debug information on OC's internal network grid. Only use if so instructed by a dev. oc:tooltip.Disassembler=Separates items into their original components. §lWarning§7: returned items have a %s%% chance of breaking in the process! oc:tooltip.Disk=Primitive medium that can be used to build persistent storage devices. oc:tooltip.DiskDrive.CC=ComputerCraft floppies are §asupported§7. diff --git a/src/main/resources/assets/opencomputers/textures/items/Debugger.png b/src/main/resources/assets/opencomputers/textures/items/Debugger.png new file mode 100644 index 0000000000000000000000000000000000000000..0ed06e854453c373051e5aa94152f91013626716 GIT binary patch literal 244 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!WQl7;NpOBzNqJ&XDuZK6ep0G} zXKrG8YEWuoN@d~6R2!fo#Q>iWR}L1TOA8+@u|Fc`AGj&z?6LM+=H}*NI%0eF6yChq z^#A|=*yertK*ii8L4LtNE)+0$`7?e33I}<*IEGZ*%IS|5I-tP8ti1I?)qm!2!Jywa zK0NlD;kZTohp@C~V3UZ(3u7n2fC(bMS$dspHz>QzJ+LY8Dzmlo35Ta~FZoM9W}LVb gaqh>zZ$b$S;Sp>yZ99C<08MA`boFyt=akR{08dR_E&u=k literal 0 HcmV?d00001 diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 886e5dd24..6e97bc53c 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -11,7 +11,6 @@ "requiredMods": [ "Forge@[10.13.0.1180,)" ], "dependencies": [ "BuildCraft|Core", - "BuildCraft|Energy", "ComputerCraft", "EnderStorage", "ForgeMultipart", diff --git a/src/main/scala/li/cil/oc/common/component/TextBuffer.scala b/src/main/scala/li/cil/oc/common/component/TextBuffer.scala index 91286fb9e..7746fea92 100644 --- a/src/main/scala/li/cil/oc/common/component/TextBuffer.scala +++ b/src/main/scala/li/cil/oc/common/component/TextBuffer.scala @@ -4,6 +4,7 @@ import com.google.common.base.Strings import cpw.mods.fml.common.eventhandler.SubscribeEvent import cpw.mods.fml.relauncher.Side import cpw.mods.fml.relauncher.SideOnly +import li.cil.oc.OpenComputers import li.cil.oc.Settings import li.cil.oc.api import li.cil.oc.api.component.TextBuffer.ColorDepth @@ -24,6 +25,7 @@ import li.cil.oc.util import li.cil.oc.util.BlockPosition import li.cil.oc.util.PackedColor import li.cil.oc.util.SideTracker +import net.minecraft.client.Minecraft import net.minecraft.entity.player.EntityPlayer import net.minecraft.nbt.NBTTagCompound import net.minecraftforge.event.world.ChunkEvent @@ -551,26 +553,48 @@ object TextBuffer { dirty = true } - override def keyDown(character: Char, code: Int, player: EntityPlayer) = + override def keyDown(character: Char, code: Int, player: EntityPlayer) { + debug(s"{type = keyDown, char = $character, code = $code}") ClientPacketSender.sendKeyDown(nodeAddress, character, code) + } - override def keyUp(character: Char, code: Int, player: EntityPlayer) = + override def keyUp(character: Char, code: Int, player: EntityPlayer) { + debug(s"{type = keyUp, char = $character, code = $code}") ClientPacketSender.sendKeyUp(nodeAddress, character, code) + } - override def clipboard(value: String, player: EntityPlayer) = + override def clipboard(value: String, player: EntityPlayer) { + debug(s"{type = clipboard}") ClientPacketSender.sendClipboard(nodeAddress, value) + } - override def mouseDown(x: Int, y: Int, button: Int, player: EntityPlayer) = + override def mouseDown(x: Int, y: Int, button: Int, player: EntityPlayer) { + debug(s"{type = mouseDown, x = $x, y = $y, button = $button}") ClientPacketSender.sendMouseClick(nodeAddress, x, y, drag = false, button) + } - override def mouseDrag(x: Int, y: Int, button: Int, player: EntityPlayer) = + override def mouseDrag(x: Int, y: Int, button: Int, player: EntityPlayer) { + debug(s"{type = mouseDrag, x = $x, y = $y, button = $button}") ClientPacketSender.sendMouseClick(nodeAddress, x, y, drag = true, button) + } - override def mouseUp(x: Int, y: Int, button: Int, player: EntityPlayer) = + override def mouseUp(x: Int, y: Int, button: Int, player: EntityPlayer) { + debug(s"{type = mouseUp, x = $x, y = $y, button = $button}") ClientPacketSender.sendMouseUp(nodeAddress, x, y, button) + } - override def mouseScroll(x: Int, y: Int, delta: Int, player: EntityPlayer) = + override def mouseScroll(x: Int, y: Int, delta: Int, player: EntityPlayer) { + debug(s"{type = mouseScroll, x = $x, y = $y, delta = $delta}") ClientPacketSender.sendMouseScroll(nodeAddress, x, y, delta) + } + + private lazy val Debugger = api.Items.get("debugger") + + private def debug(message: String) { + if (api.Items.get(Minecraft.getMinecraft.thePlayer.getHeldItem) == Debugger) { + OpenComputers.log.info(s"[NETWORK DEBUGGER] Sending packet to node $nodeAddress: " + message) + } + } } class ServerProxy(val owner: TextBuffer) extends Proxy { diff --git a/src/main/scala/li/cil/oc/common/init/Items.scala b/src/main/scala/li/cil/oc/common/init/Items.scala index 79f07992f..5b64a1def 100644 --- a/src/main/scala/li/cil/oc/common/init/Items.scala +++ b/src/main/scala/li/cil/oc/common/init/Items.scala @@ -255,5 +255,6 @@ object Items extends ItemAPI { Recipes.addItem(new item.UpgradeDatabase(multi, Tier.One), "databaseUpgrade1", "oc:databaseUpgrade1") Recipes.addItem(new item.UpgradeDatabase(multi, Tier.Two), "databaseUpgrade2", "oc:databaseUpgrade2") Recipes.addItem(new item.UpgradeDatabase(multi, Tier.Three), "databaseUpgrade3", "oc:databaseUpgrade3") + registerItem(new item.Debugger(multi), "debugger") } } \ No newline at end of file diff --git a/src/main/scala/li/cil/oc/common/item/Debugger.scala b/src/main/scala/li/cil/oc/common/item/Debugger.scala new file mode 100644 index 000000000..ed56b86d3 --- /dev/null +++ b/src/main/scala/li/cil/oc/common/item/Debugger.scala @@ -0,0 +1,73 @@ +package li.cil.oc.common.item + +import li.cil.oc.OpenComputers +import li.cil.oc.api +import li.cil.oc.api.network._ +import net.minecraft.entity.player.EntityPlayer +import net.minecraft.entity.player.EntityPlayerMP +import net.minecraft.item.ItemStack +import net.minecraft.world.World +import net.minecraftforge.common.util.ForgeDirection + +class Debugger(val parent: Delegator) extends Delegate { + override def onItemUse(stack: ItemStack, player: EntityPlayer, world: World, x: Int, y: Int, z: Int, side: Int, hitX: Float, hitY: Float, hitZ: Float) = { + player match { + case realPlayer: EntityPlayerMP => + world.getTileEntity(x, y, z) match { + case host: SidedEnvironment => + if (!world.isRemote) { + Debugger.reconnect(Array(host.sidedNode(ForgeDirection.getOrientation(side)))) + } + true + case host: Environment => + if (!world.isRemote) { + Debugger.reconnect(Array(host.node)) + } + true + case _ => + if (!world.isRemote) { + Debugger.node.remove() + } + true + } + case _ => false + } + } +} + +object Debugger extends Environment { + var node = api.Network.newNode(this, Visibility.Network).create() + + override def onConnect(node: Node) { + OpenComputers.log.info(s"[NETWORK DEBUGGER] New node in network: ${nodeInfo(node)}") + } + + override def onDisconnect(node: Node) { + OpenComputers.log.info(s"[NETWORK DEBUGGER] Node removed from network: ${nodeInfo(node)}") + } + + override def onMessage(message: Message) { + OpenComputers.log.info(s"[NETWORK DEBUGGER] Received message: ${messageInfo(message)}.") + } + + def reconnect(nodes: Array[Node]) { + node.remove() + api.Network.joinNewNetwork(node) + for (node <- nodes if node != null) { + this.node.connect(node) + } + } + + private def nodeInfo(node: Node) = s"{address = ${node.address}, reachability = ${node.reachability.name}" + (node match { + case componentConnector: ComponentConnector => componentInfo(componentConnector) + connectorInfo(componentConnector) + case component: Component => componentInfo(component) + case connector: Connector => connectorInfo(connector) + case _ => + }) + "}" + + private def componentInfo(component: Component) = s", type = component, name = ${component.name}, visibility = ${component.visibility.name}" + + private def connectorInfo(connector: Connector) = s", type = connector, buffer = ${connector.localBuffer}, bufferSize = ${connector.localBufferSize}" + + private def messageInfo(message: Message) = s"{name = ${message.name()}, source = ${nodeInfo(message.source)}, data = [${message.data.mkString(", ")}]}" +} diff --git a/src/main/scala/li/cil/oc/integration/Mods.scala b/src/main/scala/li/cil/oc/integration/Mods.scala index d6ffbb6a2..1297d40bd 100644 --- a/src/main/scala/li/cil/oc/integration/Mods.scala +++ b/src/main/scala/li/cil/oc/integration/Mods.scala @@ -108,10 +108,10 @@ object Mods { val isBlacklisted = Settings.get.modBlacklist.contains(mod.getMod.id) val alwaysEnabled = mod.getMod == null || mod.getMod == Mods.Minecraft if (!isBlacklisted && (alwaysEnabled || mod.getMod.isAvailable) && handlers.add(mod)) { - li.cil.oc.OpenComputers.log.info(String.format("Initializing mod integration for '%s'.", mod.getMod.id)) + li.cil.oc.OpenComputers.log.info(s"Initializing mod integration for '${mod.getMod.id}'.") try mod.initialize() catch { case e: Throwable => - li.cil.oc.OpenComputers.log.warn(String.format("Error initializing integration for '%s'", mod.getMod.id), e) + li.cil.oc.OpenComputers.log.warn(s"Error initializing integration for '${mod.getMod.id}'", e) } } } diff --git a/src/main/scala/li/cil/oc/server/network/Network.scala b/src/main/scala/li/cil/oc/server/network/Network.scala index 8a9531f2b..02a112d15 100644 --- a/src/main/scala/li/cil/oc/server/network/Network.scala +++ b/src/main/scala/li/cil/oc/server/network/Network.scala @@ -679,6 +679,8 @@ object Network extends api.detail.NetworkAPI { case value => OpenComputers.log.warn("Unexpected type while saving network packet: " + value.getClass.getName) } } + + override def toString = s"{source = $source, destination = $destination, port = $port, data = [${data.mkString(", ")}}]}" } // ----------------------------------------------------------------------- //