mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-19 04:06:43 -04:00
Merge remote-tracking branch 'local-1.7/master-MC1.7.10' into master-MC1.12
This commit is contained in:
commit
db082aca09
@ -39,7 +39,7 @@ This mod is [licensed under the **MIT license**](https://github.com/MightyPirate
|
||||
4. **Core Scripts**
|
||||
If you would like to contribute scripts to the "core" Lua code (which basically defines 'OpenOS'), please have a look at the [code conventions][] for Lua to save us all some time. Bug fixes are always welcome. Additional programs and features should be kept small. Bigger programs (rule of thumb: larger than 3KiB) should go onto loot disks.
|
||||
5. **Drivers**
|
||||
As of OC 1.4, mod interaction that was previously provided by OpenComponents it now fully integrated into OC itself. If you wish to contribute a driver for blocks from other mods, cool! Have a look at the [integration][] package to get an idea of how to structure modules and read the readme in that package for more information (in particular on additional criteria to get your PR merged).
|
||||
As of OC 1.4, mod interaction that was previously provided by OpenComponents is now fully integrated into OC itself. If you wish to contribute a driver for blocks from other mods, cool! Have a look at the [integration][] package to get an idea of how to structure modules and read the readme in that package for more information (in particular on additional criteria to get your PR merged).
|
||||
|
||||
#### Pull requests
|
||||
The following are a few quick guidelines on pull requests. That is to say they are not necessarily *rules*, so there may be exceptions and all that. Just try to stick to those points as a baseline.
|
||||
|
@ -0,0 +1,8 @@
|
||||
NAME
|
||||
arp - Inspect local address resolution
|
||||
|
||||
SYNOPSIS
|
||||
arp
|
||||
|
||||
DESCRIPTION
|
||||
Displays the address of each network interface
|
@ -12,5 +12,5 @@ EXAMPLES
|
||||
Output network status information
|
||||
|
||||
ifconfig bind [address]
|
||||
Binds addnitional address to this device. Address should match [A-Za-z0-9%-]+ and be max 64 characters length
|
||||
Binds additional address to this device. Address should match [A-Za-z0-9%-]+ and be max 64 characters length
|
||||
|
||||
|
@ -0,0 +1,15 @@
|
||||
NAME
|
||||
nc - Connect STDIN and STDOUT to the network
|
||||
|
||||
SYNOPSIS
|
||||
nc [-l] port [addr]
|
||||
|
||||
DESCRIPTION
|
||||
Connect STDIN and STDOUT to a network socket so that data can be received from and sent to that socket via STDIN and STDOUT
|
||||
|
||||
EXAMPLES
|
||||
nc -l 1337
|
||||
Open a socket on port 1337. If another program connects, it can receive from STDIN and send to STDOUT.
|
||||
|
||||
nc 1337 host1
|
||||
Connect to an open socket at address 'host1' on port 1337. The running program can send to STDOUT and receive from STDIN
|
@ -0,0 +1,8 @@
|
||||
NAME
|
||||
route - Show routing information
|
||||
|
||||
SYNOPSIS
|
||||
route
|
||||
|
||||
DESCRIPTION
|
||||
Displays the contents of the routing table
|
@ -14,17 +14,17 @@ import scala.util.matching.Regex
|
||||
object Localization {
|
||||
private val nl = Regex.quote("[nl]")
|
||||
|
||||
private def resolveKey(key: String) = if (canLocalize(Settings.namespace + key)) Settings.namespace + key else key
|
||||
private def resolveKey(key: String) = if (canLocalize(Settings.namespace + key)) Option(Settings.namespace + key) else Option.empty
|
||||
|
||||
def canLocalize(key: String): Boolean = I18n.canTranslate(key)
|
||||
|
||||
def localizeLater(formatKey: String, values: AnyRef*) = new TextComponentTranslation(resolveKey(formatKey), values: _*)
|
||||
def localizeLater(formatKey: String, values: AnyRef*) = new TextComponentTranslation(resolveKey(formatKey).getOrElse(formatKey), values: _*)
|
||||
|
||||
def localizeLater(key: String) = new TextComponentTranslation(resolveKey(key))
|
||||
def localizeLater(key: String) = resolveKey(key).map(k => new TextComponentTranslation(k)).getOrElse(new TextComponentString(key))
|
||||
|
||||
def localizeImmediately(formatKey: String, values: AnyRef*): String = I18n.translateToLocalFormatted(resolveKey(formatKey), values: _*).split(nl).map(_.trim).mkString("\n")
|
||||
def localizeImmediately(formatKey: String, values: AnyRef*) = I18n.translateToLocalFormatted(resolveKey(formatKey).getOrElse(formatKey), values: _*).split(nl).map(_.trim).mkString("\n")
|
||||
|
||||
def localizeImmediately(key: String): String = I18n.translateToLocal(resolveKey(key)).split(nl).map(_.trim).mkString("\n")
|
||||
def localizeImmediately(key: String) = resolveKey(key).map(k => I18n.translateToLocal(k)).getOrElse(key).split(nl).map(_.trim).mkString("\n")
|
||||
|
||||
object Analyzer {
|
||||
def Address(value: String): TextComponentTranslation = {
|
||||
|
@ -178,14 +178,14 @@ class TextBuffer(val host: EnvironmentHost) extends AbstractManagedEnvironment w
|
||||
@Callback(direct = true, doc = """function():boolean -- Returns whether the screen is currently on.""")
|
||||
def isOn(computer: Context, args: Arguments): Array[AnyRef] = result(isDisplaying)
|
||||
|
||||
@Callback(doc = """function():boolean -- Turns the screen on. Returns true if it was off.""")
|
||||
@Callback(doc = """function():boolean -- Turns the screen on. Returns whether the state changed, and whether it is now on.""")
|
||||
def turnOn(computer: Context, args: Arguments): Array[AnyRef] = {
|
||||
val oldPowerState = isDisplaying
|
||||
setPowerState(value = true)
|
||||
result(isDisplaying != oldPowerState, isDisplaying)
|
||||
}
|
||||
|
||||
@Callback(doc = """function():boolean -- Turns off the screen. Returns true if it was on.""")
|
||||
@Callback(doc = """function():boolean -- Turns off the screen. Returns whether the state changed, and whether it is now on.""")
|
||||
def turnOff(computer: Context, args: Arguments): Array[AnyRef] = {
|
||||
val oldPowerState = isDisplaying
|
||||
setPowerState(value = false)
|
||||
|
@ -9,7 +9,7 @@ import net.minecraft.item.ItemStack
|
||||
import net.minecraftforge.fml.relauncher.Side
|
||||
import net.minecraftforge.fml.relauncher.SideOnly
|
||||
|
||||
class Drone(playerInventory: InventoryPlayer, drone: entity.Drone) extends Player(playerInventory, drone.mainInventory) {
|
||||
class Drone(playerInventory: InventoryPlayer, val drone: entity.Drone) extends Player(playerInventory, drone.mainInventory) {
|
||||
val deltaY = 0
|
||||
|
||||
for (i <- 0 to 1) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package li.cil.oc.server
|
||||
|
||||
import li.cil.oc.Localization
|
||||
import li.cil.oc.OpenComputers
|
||||
import li.cil.oc.api
|
||||
import li.cil.oc.api.internal.Server
|
||||
import li.cil.oc.api.machine.Machine
|
||||
@ -8,6 +9,7 @@ import li.cil.oc.api.network.Connector
|
||||
import li.cil.oc.common.Achievement
|
||||
import li.cil.oc.common.PacketType
|
||||
import li.cil.oc.common.component.TextBuffer
|
||||
import li.cil.oc.common.container
|
||||
import li.cil.oc.common.entity.Drone
|
||||
import li.cil.oc.common.item.{Delegator, Tablet, TabletWrapper}
|
||||
import li.cil.oc.common.item.data.DriveData
|
||||
@ -23,8 +25,14 @@ import net.minecraft.util.EnumHand
|
||||
import net.minecraftforge.common.DimensionManager
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
|
||||
import net.minecraftforge.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent
|
||||
import org.apache.logging.log4j.MarkerManager
|
||||
|
||||
object PacketHandler extends CommonPacketHandler {
|
||||
private val securityMarker = MarkerManager.getMarker("SuspiciousPackets")
|
||||
|
||||
private def logForgedPacket(player: EntityPlayerMP) =
|
||||
OpenComputers.log.warn(securityMarker, "Player {} tried to send GUI packets without opening them", player.getGameProfile)
|
||||
|
||||
@SubscribeEvent
|
||||
def onPacket(e: ServerCustomPacketEvent): Unit =
|
||||
onPacketData(e.getManager.getNetHandler, e.getPacket.payload, e.getHandler.asInstanceOf[NetHandlerPlayServer].player)
|
||||
@ -61,10 +69,14 @@ object PacketHandler extends CommonPacketHandler {
|
||||
def onComputerPower(p: PacketParser): Unit = {
|
||||
val entity = p.readTileEntity[Computer]()
|
||||
val setPower = p.readBoolean()
|
||||
entity match {
|
||||
case Some(t) => p.player match {
|
||||
case player: EntityPlayerMP => trySetComputerPower(t.machine, setPower, player)
|
||||
case _ =>
|
||||
p.player match {
|
||||
case player: EntityPlayerMP => player.openContainer match {
|
||||
case container: container.Player => (container.otherInventory, entity) match {
|
||||
case (computer: Computer, Some(c2)) if c2.position == computer.position =>
|
||||
trySetComputerPower(computer.machine, setPower, player)
|
||||
case _ => logForgedPacket(player)
|
||||
}
|
||||
case _ => logForgedPacket(player)
|
||||
}
|
||||
case _ => // Invalid packet.
|
||||
}
|
||||
@ -73,17 +85,23 @@ object PacketHandler extends CommonPacketHandler {
|
||||
def onServerPower(p: PacketParser): Unit = {
|
||||
val entity = p.readTileEntity[Rack]()
|
||||
val index = p.readInt()
|
||||
val setPower = p.readBoolean()
|
||||
entity match {
|
||||
case Some(t) => {
|
||||
val mountableIndex = index
|
||||
t.getMountable(mountableIndex) match {
|
||||
case server: Server => p.player match {
|
||||
case player: EntityPlayerMP => trySetComputerPower(server.machine, setPower, player)
|
||||
case _ => // Invalid packet.
|
||||
}
|
||||
case _ => // Invalid packet.
|
||||
val readServer = entity match {
|
||||
case Some(t) =>
|
||||
t.getMountable(index) match {
|
||||
case server: Server => server
|
||||
case _ => return // probably just lag, not invalid packet
|
||||
}
|
||||
case _ => return
|
||||
}
|
||||
val setPower = p.readBoolean()
|
||||
p.player match {
|
||||
case player: EntityPlayerMP => player.openContainer match {
|
||||
case container: container.Server => container.server match {
|
||||
case Some(server) if server == readServer =>
|
||||
trySetComputerPower(server.machine, setPower, player)
|
||||
case _ => logForgedPacket(player)
|
||||
}
|
||||
case _ => logForgedPacket(player)
|
||||
}
|
||||
case _ => // Invalid packet.
|
||||
}
|
||||
@ -125,16 +143,17 @@ object PacketHandler extends CommonPacketHandler {
|
||||
def onDronePower(p: PacketParser): Unit = {
|
||||
val entity = p.readEntity[Drone]()
|
||||
val power = p.readBoolean()
|
||||
entity match {
|
||||
case Some(drone) => p.player match {
|
||||
case player: EntityPlayerMP =>
|
||||
p.player match {
|
||||
case player: EntityPlayerMP => (player.openContainer, entity) match {
|
||||
case (c: container.Drone, Some(readDrone)) if c.drone == readDrone =>
|
||||
val drone = c.drone
|
||||
if (power) {
|
||||
drone.preparePowerUp()
|
||||
}
|
||||
trySetComputerPower(drone.machine, power, player)
|
||||
case _ =>
|
||||
case _ => logForgedPacket(player)
|
||||
}
|
||||
case _ => // Invalid packet.
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
|
||||
@ -245,13 +264,14 @@ object PacketHandler extends CommonPacketHandler {
|
||||
val mountableIndex = p.readInt()
|
||||
val nodeIndex = p.readInt()
|
||||
val side = p.readDirection()
|
||||
entity match {
|
||||
case Some(t) => p.player match {
|
||||
case player: EntityPlayerMP if t.isUsableByPlayer(player) =>
|
||||
t.connect(mountableIndex, nodeIndex - 1, side)
|
||||
case _ =>
|
||||
p.player match {
|
||||
case player: EntityPlayerMP => (player.openContainer, entity) match {
|
||||
case (container: container.Rack, Some(readRack)) if readRack == container.rack =>
|
||||
if (container.rack.isUsableByPlayer(player))
|
||||
container.rack.connect(mountableIndex, nodeIndex - 1, side)
|
||||
case _ => logForgedPacket(player)
|
||||
}
|
||||
case _ => // Invalid packet.
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user