Merge branch 'master-MC1.10' into master-MC1.11

# Conflicts:
#	src/main/scala/li/cil/oc/common/init/Items.scala
#	src/main/scala/li/cil/oc/integration/appeng/NetworkControl.scala
This commit is contained in:
payonel 2019-06-23 00:05:21 -07:00
commit eeadbd6a75
7 changed files with 122 additions and 13 deletions

View File

@ -6,10 +6,11 @@ local internet = {}
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
function internet.request(url, data, headers) function internet.request(url, data, headers, method)
checkArg(1, url, "string") checkArg(1, url, "string")
checkArg(2, data, "string", "table", "nil") checkArg(2, data, "string", "table", "nil")
checkArg(3, headers, "table", "nil") checkArg(3, headers, "table", "nil")
checkArg(4, method, "string", "nil")
if not component.isAvailable("internet") then if not component.isAvailable("internet") then
error("no primary internet card found", 2) error("no primary internet card found", 2)
@ -26,7 +27,7 @@ function internet.request(url, data, headers)
end end
end end
local request, reason = inet.request(url, post, headers) local request, reason = inet.request(url, post, headers, method)
if not request then if not request then
error(reason, 2) error(reason, 2)
end end

View File

@ -80,6 +80,7 @@ Kodos # Contributor
Laire # Perry Rhodan Laire # Perry Rhodan
Loader 1340 # Borderlands 2 Loader 1340 # Borderlands 2
LordFokas # Contributor LordFokas # Contributor
Maria # Metropolis
Marvin # Hitchhiker's Guide to the Galaxy Marvin # Hitchhiker's Guide to the Galaxy
Mawhrin-skel # The Player of Games (Iain M Banks) Mawhrin-skel # The Player of Games (Iain M Banks)
Michiyo # Contributor Michiyo # Contributor

View File

@ -296,6 +296,7 @@ object Items extends ItemAPI {
safeGetStack(Constants.ItemName.PistonUpgrade), safeGetStack(Constants.ItemName.PistonUpgrade),
safeGetStack(Constants.BlockName.Geolyzer), safeGetStack(Constants.BlockName.Geolyzer),
safeGetStack(Constants.ItemName.NavigationUpgrade), safeGetStack(Constants.ItemName.NavigationUpgrade),
safeGetStack(Constants.ItemName.Analyzer),
safeGetStack(Constants.ItemName.GraphicsCardTier2), safeGetStack(Constants.ItemName.GraphicsCardTier2),
safeGetStack(Constants.ItemName.RedstoneCardTier2), safeGetStack(Constants.ItemName.RedstoneCardTier2),

View File

@ -0,0 +1,27 @@
package li.cil.oc.integration.opencomputers
import li.cil.oc.Constants
import li.cil.oc.api.driver.EnvironmentProvider
import li.cil.oc.api
import li.cil.oc.api.driver.item.{HostAware, Slot}
import li.cil.oc.api.network.{EnvironmentHost, ManagedEnvironment}
import li.cil.oc.server.component
import li.cil.oc.server.component.UpgradeBarcodeReader
import net.minecraft.item.ItemStack
object DriverUpgradeBarcodeReader extends Item with HostAware {
override def worksWith(stack: ItemStack) = isOneOf(stack,
api.Items.get(Constants.ItemName.Analyzer))
override def createEnvironment(stack: ItemStack, host: EnvironmentHost): ManagedEnvironment =
new UpgradeBarcodeReader(host)
override def slot(stack: ItemStack) = Slot.Upgrade
object Provider extends EnvironmentProvider {
override def getEnvironment(stack: ItemStack): Class[_] =
if (worksWith(stack))
classOf[component.UpgradeBarcodeReader]
else null
}
}

View File

@ -153,6 +153,7 @@ object ModOpenComputers extends ModProxy {
api.Driver.add(DriverTerminalServer) api.Driver.add(DriverTerminalServer)
api.Driver.add(DriverUpgradeAngel) api.Driver.add(DriverUpgradeAngel)
api.Driver.add(DriverUpgradeBarcodeReader)
api.Driver.add(DriverUpgradeBattery) api.Driver.add(DriverUpgradeBattery)
api.Driver.add(DriverUpgradeChunkloader) api.Driver.add(DriverUpgradeChunkloader)
api.Driver.add(DriverUpgradeCrafting) api.Driver.add(DriverUpgradeCrafting)
@ -214,6 +215,7 @@ object ModOpenComputers extends ModProxy {
Constants.BlockName.ScreenTier1, Constants.BlockName.ScreenTier1,
Constants.BlockName.Transposer, Constants.BlockName.Transposer,
Constants.BlockName.CarpetedCapacitor, Constants.BlockName.CarpetedCapacitor,
Constants.ItemName.Analyzer,
Constants.ItemName.AngelUpgrade, Constants.ItemName.AngelUpgrade,
Constants.ItemName.BatteryUpgradeTier1, Constants.ItemName.BatteryUpgradeTier1,
Constants.ItemName.BatteryUpgradeTier2, Constants.ItemName.BatteryUpgradeTier2,
@ -237,6 +239,7 @@ object ModOpenComputers extends ModProxy {
Constants.BlockName.ScreenTier1, Constants.BlockName.ScreenTier1,
Constants.BlockName.Transposer, Constants.BlockName.Transposer,
Constants.BlockName.CarpetedCapacitor, Constants.BlockName.CarpetedCapacitor,
Constants.ItemName.Analyzer,
Constants.ItemName.APUTier1, Constants.ItemName.APUTier1,
Constants.ItemName.APUTier2, Constants.ItemName.APUTier2,
Constants.ItemName.GraphicsCardTier1, Constants.ItemName.GraphicsCardTier1,
@ -252,6 +255,7 @@ object ModOpenComputers extends ModProxy {
Constants.BlockName.Keyboard, Constants.BlockName.Keyboard,
Constants.BlockName.ScreenTier1, Constants.BlockName.ScreenTier1,
Constants.BlockName.CarpetedCapacitor, Constants.BlockName.CarpetedCapacitor,
Constants.ItemName.Analyzer,
Constants.ItemName.APUTier1, Constants.ItemName.APUTier1,
Constants.ItemName.APUTier2, Constants.ItemName.APUTier2,
Constants.ItemName.GraphicsCardTier1, Constants.ItemName.GraphicsCardTier1,
@ -277,6 +281,7 @@ object ModOpenComputers extends ModProxy {
blacklistHost(classOf[internal.Robot], blacklistHost(classOf[internal.Robot],
Constants.BlockName.Transposer, Constants.BlockName.Transposer,
Constants.BlockName.CarpetedCapacitor, Constants.BlockName.CarpetedCapacitor,
Constants.ItemName.Analyzer,
Constants.ItemName.LeashUpgrade) Constants.ItemName.LeashUpgrade)
blacklistHost(classOf[internal.Tablet], blacklistHost(classOf[internal.Tablet],
Constants.BlockName.ScreenTier1, Constants.BlockName.ScreenTier1,

View File

@ -63,7 +63,7 @@ class InternetCard extends AbstractManagedEnvironment with DeviceInfo {
@Callback(direct = true, doc = """function():boolean -- Returns whether HTTP requests can be made (config setting).""") @Callback(direct = true, doc = """function():boolean -- Returns whether HTTP requests can be made (config setting).""")
def isHttpEnabled(context: Context, args: Arguments): Array[AnyRef] = result(Settings.get.httpEnabled) def isHttpEnabled(context: Context, args: Arguments): Array[AnyRef] = result(Settings.get.httpEnabled)
@Callback(doc = """function(url:string[, postData:string[, headers:table]]):userdata -- Starts an HTTP request. If this returns true, further results will be pushed using `http_response` signals.""") @Callback(doc = """function(url:string[, postData:string[, headers:table[, method:string]]]):userdata -- Starts an HTTP request. If this returns true, further results will be pushed using `http_response` signals.""")
def request(context: Context, args: Arguments): Array[AnyRef] = this.synchronized { def request(context: Context, args: Arguments): Array[AnyRef] = this.synchronized {
checkOwner(context) checkOwner(context)
val address = args.checkString(0) val address = args.checkString(0)
@ -81,7 +81,8 @@ class InternetCard extends AbstractManagedEnvironment with DeviceInfo {
if (!Settings.get.httpHeadersEnabled && headers.nonEmpty) { if (!Settings.get.httpHeadersEnabled && headers.nonEmpty) {
return result(Unit, "http request headers are unavailable") return result(Unit, "http request headers are unavailable")
} }
val request = new InternetCard.HTTPRequest(this, checkAddress(address), post, headers) val method = if (args.isString(3)) Option(args.checkString(3)) else None
val request = new InternetCard.HTTPRequest(this, checkAddress(address), post, headers, method)
connections += request connections += request
result(request) result(request)
} }
@ -367,10 +368,10 @@ object InternetCard {
} }
class HTTPRequest extends AbstractValue with Closable { class HTTPRequest extends AbstractValue with Closable {
def this(owner: InternetCard, url: URL, post: Option[String], headers: Map[String, String]) { def this(owner: InternetCard, url: URL, post: Option[String], headers: Map[String, String], method: Option[String]) {
this() this()
this.owner = Some(owner) this.owner = Some(owner)
this.stream = threadPool.submit(new RequestSender(url, post, headers)) this.stream = threadPool.submit(new RequestSender(url, post, headers, method))
} }
private var owner: Option[InternetCard] = None private var owner: Option[InternetCard] = None
@ -469,27 +470,23 @@ object InternetCard {
} }
// This one doesn't (see comment in TCP socket), but I like to keep it consistent. // This one doesn't (see comment in TCP socket), but I like to keep it consistent.
private class RequestSender(val url: URL, val post: Option[String], val headers: Map[String, String]) extends Callable[InputStream] { private class RequestSender(val url: URL, val post: Option[String], val headers: Map[String, String], val method: Option[String]) extends Callable[InputStream] {
override def call() = try { override def call() = try {
checkLists(InetAddress.getByName(url.getHost), url.getHost) checkLists(InetAddress.getByName(url.getHost), url.getHost)
val proxy = Option(FMLCommonHandler.instance.getMinecraftServerInstance.getServerProxy).getOrElse(java.net.Proxy.NO_PROXY) val proxy = Option(FMLCommonHandler.instance.getMinecraftServerInstance.getServerProxy).getOrElse(java.net.Proxy.NO_PROXY)
url.openConnection(proxy) match { url.openConnection(proxy) match {
case http: HttpURLConnection => try { case http: HttpURLConnection => try {
http.setDoInput(true) http.setDoInput(true)
http.setDoOutput(post.isDefined)
http.setRequestMethod(if (method.isDefined) method.get else if (post.isDefined) "POST" else "GET")
headers.foreach(Function.tupled(http.setRequestProperty)) headers.foreach(Function.tupled(http.setRequestProperty))
if (post.isDefined) { if (post.isDefined) {
http.setRequestMethod("POST")
http.setDoOutput(true)
http.setReadTimeout(Settings.get.httpTimeout) http.setReadTimeout(Settings.get.httpTimeout)
val out = new BufferedWriter(new OutputStreamWriter(http.getOutputStream)) val out = new BufferedWriter(new OutputStreamWriter(http.getOutputStream))
out.write(post.get) out.write(post.get)
out.close() out.close()
} }
else {
http.setRequestMethod("GET")
http.setDoOutput(false)
}
val input = http.getInputStream val input = http.getInputStream
HTTPRequest.this.synchronized { HTTPRequest.this.synchronized {

View File

@ -0,0 +1,77 @@
package li.cil.oc.server.component
import java.util
import li.cil.oc.{Constants, OpenComputers, api}
import li.cil.oc.api.driver.DeviceInfo
import li.cil.oc.api.driver.DeviceInfo.DeviceAttribute
import li.cil.oc.api.driver.DeviceInfo.DeviceClass
import li.cil.oc.api.internal
import li.cil.oc.api.network._
import li.cil.oc.api.prefab
import li.cil.oc.api.prefab.AbstractManagedEnvironment
import li.cil.oc.util.BlockPosition
import li.cil.oc.util.ExtendedWorld._
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.nbt.NBTTagList
import net.minecraft.util.EnumFacing
import net.minecraft.world.WorldServer
import scala.collection.convert.WrapAsJava._
class UpgradeBarcodeReader(val host: EnvironmentHost) extends AbstractManagedEnvironment with DeviceInfo {
override val node = api.Network.newNode(this, Visibility.Network).
withComponent("barcode_reader").
withConnector().
create()
private final lazy val deviceInfo = Map(
DeviceAttribute.Class -> DeviceClass.Generic,
DeviceAttribute.Description -> "Barcode reader upgrade",
DeviceAttribute.Vendor -> Constants.DeviceInfo.DefaultVendor,
DeviceAttribute.Product -> "Readerizer Deluxe"
)
override def getDeviceInfo: util.Map[String, String] = deviceInfo
override def onMessage(message: Message): Unit = {
super.onMessage(message)
if (message.name == "tablet.use") message.source.host match {
case machine: api.machine.Machine => (machine.host, message.data) match {
case (tablet: internal.Tablet, Array(nbt: NBTTagCompound, stack: ItemStack, player: EntityPlayer, blockPos: BlockPosition, side: EnumFacing, hitX: java.lang.Float, hitY: java.lang.Float, hitZ: java.lang.Float)) =>
host.world.getTileEntity(blockPos) match {
case analyzable: Analyzable =>
processNodes(analyzable.onAnalyze(player, side, hitX.toFloat, hitY.toFloat, hitZ.toFloat), nbt)
case host: SidedEnvironment =>
processNodes(Array(host.sidedNode(side)), nbt)
case host: Environment =>
processNodes(Array(host.node), nbt)
}
}
}
}
private def processNodes(nodes: Array[Node], nbt: NBTTagCompound): Unit = if (nodes != null) {
val readerNBT = new NBTTagList()
for (node <- nodes if node != null) {
val nodeNBT = new NBTTagCompound()
node match {
case component: Component =>
nodeNBT.setString("type", component.name)
case _ =>
}
val address = node.address()
if (address != null && !address.isEmpty) {
nodeNBT.setString("address", node.address())
}
readerNBT.appendTag(nodeNBT)
}
nbt.setTag("analyzed", readerNBT)
}
}