mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 19:25:20 -04:00
Merge branch 'master-MC1.7.10' of github.com:MightyPirates/OpenComputers into master-MC1.8
This commit is contained in:
commit
d952c809af
@ -925,6 +925,14 @@ opencomputers {
|
|||||||
# not apply to HTTP traffic.
|
# not apply to HTTP traffic.
|
||||||
maxNetworkPacketSize: 8192
|
maxNetworkPacketSize: 8192
|
||||||
|
|
||||||
|
# The maximum number of "data parts" a network packet is allowed to have.
|
||||||
|
# When sending a network message, from Lua this may look like so:
|
||||||
|
# component.modem.broadcast(port, "first", true, "third", 123)
|
||||||
|
# This limits how many arguments can be passed and are wrapped into a
|
||||||
|
# packet. This limit mostly serves as a protection for lower-tier
|
||||||
|
# computers, to avoid them getting nuked by more powerful computers.
|
||||||
|
maxNetworkPacketParts: 8
|
||||||
|
|
||||||
# The maximum number of ports a single network card can have opened at
|
# The maximum number of ports a single network card can have opened at
|
||||||
# any given time.
|
# any given time.
|
||||||
maxOpenPorts: 16
|
maxOpenPorts: 16
|
||||||
|
@ -140,7 +140,7 @@ end
|
|||||||
function filesystem.get(path)
|
function filesystem.get(path)
|
||||||
local node, rest = findNode(path)
|
local node, rest = findNode(path)
|
||||||
if node.fs then
|
if node.fs then
|
||||||
local proxy = component.proxy(node.fs)
|
local proxy = node.fs
|
||||||
path = ""
|
path = ""
|
||||||
while node and node.parent do
|
while node and node.parent do
|
||||||
path = filesystem.concat(node.name, path)
|
path = filesystem.concat(node.name, path)
|
||||||
@ -192,7 +192,7 @@ function filesystem.mount(fs, path)
|
|||||||
if vnode.fs then
|
if vnode.fs then
|
||||||
return nil, "another filesystem is already mounted here"
|
return nil, "another filesystem is already mounted here"
|
||||||
end
|
end
|
||||||
vnode.fs = fs.address
|
vnode.fs = fs
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ function filesystem.mounts()
|
|||||||
table.insert(queue, child)
|
table.insert(queue, child)
|
||||||
end
|
end
|
||||||
if node.fs then
|
if node.fs then
|
||||||
return component.proxy(node.fs) or node.fs, path(node)
|
return node.fs, path(node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -288,7 +288,7 @@ function filesystem.exists(path)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
if node and node.fs then
|
if node and node.fs then
|
||||||
return component.proxy(node.fs).exists(rest)
|
return node.fs.exists(rest)
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -299,7 +299,7 @@ function filesystem.size(path)
|
|||||||
return 0 -- virtual directory or symlink
|
return 0 -- virtual directory or symlink
|
||||||
end
|
end
|
||||||
if node.fs and rest then
|
if node.fs and rest then
|
||||||
return component.proxy(node.fs).size(rest)
|
return node.fs.size(rest)
|
||||||
end
|
end
|
||||||
return 0 -- no such file or directory
|
return 0 -- no such file or directory
|
||||||
end
|
end
|
||||||
@ -310,7 +310,7 @@ function filesystem.isDirectory(path)
|
|||||||
return true -- virtual directory
|
return true -- virtual directory
|
||||||
end
|
end
|
||||||
if node.fs then
|
if node.fs then
|
||||||
return not rest or component.proxy(node.fs).isDirectory(rest)
|
return not rest or node.fs.isDirectory(rest)
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -321,7 +321,7 @@ function filesystem.lastModified(path)
|
|||||||
return 0 -- virtual directory
|
return 0 -- virtual directory
|
||||||
end
|
end
|
||||||
if node.fs and rest then
|
if node.fs and rest then
|
||||||
return component.proxy(node.fs).lastModified(rest)
|
return node.fs.lastModified(rest)
|
||||||
end
|
end
|
||||||
return 0 -- no such file or directory
|
return 0 -- no such file or directory
|
||||||
end
|
end
|
||||||
@ -333,7 +333,7 @@ function filesystem.list(path)
|
|||||||
end
|
end
|
||||||
local result, reason
|
local result, reason
|
||||||
if node and node.fs then
|
if node and node.fs then
|
||||||
result, reason = component.proxy(node.fs).list(rest or "")
|
result, reason = node.fs.list(rest or "")
|
||||||
end
|
end
|
||||||
result = result or {}
|
result = result or {}
|
||||||
if not vrest then
|
if not vrest then
|
||||||
@ -367,7 +367,7 @@ function filesystem.makeDirectory(path)
|
|||||||
end
|
end
|
||||||
local node, rest = findNode(path)
|
local node, rest = findNode(path)
|
||||||
if node.fs and rest then
|
if node.fs and rest then
|
||||||
return component.proxy(node.fs).makeDirectory(rest)
|
return node.fs.makeDirectory(rest)
|
||||||
end
|
end
|
||||||
if node.fs then
|
if node.fs then
|
||||||
return nil, "virtual directory with that name already exists"
|
return nil, "virtual directory with that name already exists"
|
||||||
@ -393,7 +393,7 @@ function filesystem.remove(path)
|
|||||||
local function removePhysical()
|
local function removePhysical()
|
||||||
node, rest = findNode(path)
|
node, rest = findNode(path)
|
||||||
if node.fs and rest then
|
if node.fs and rest then
|
||||||
return component.proxy(node.fs).remove(rest)
|
return node.fs.remove(rest)
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -417,8 +417,8 @@ function filesystem.rename(oldPath, newPath)
|
|||||||
local oldNode, oldRest = findNode(oldPath)
|
local oldNode, oldRest = findNode(oldPath)
|
||||||
local newNode, newRest = findNode(newPath)
|
local newNode, newRest = findNode(newPath)
|
||||||
if oldNode.fs and oldRest and newNode.fs and newRest then
|
if oldNode.fs and oldRest and newNode.fs and newRest then
|
||||||
if oldNode.fs == newNode.fs then
|
if oldNode.fs.address == newNode.fs.address then
|
||||||
return component.proxy(oldNode.fs).rename(oldRest, newRest)
|
return oldNode.fs.rename(oldRest, newRest)
|
||||||
else
|
else
|
||||||
local result, reason = filesystem.copy(oldPath, newPath)
|
local result, reason = filesystem.copy(oldPath, newPath)
|
||||||
if result then
|
if result then
|
||||||
@ -465,7 +465,7 @@ end
|
|||||||
|
|
||||||
function fileStream:close()
|
function fileStream:close()
|
||||||
if self.handle then
|
if self.handle then
|
||||||
component.proxy(self.fs).close(self.handle)
|
self.fs.close(self.handle)
|
||||||
self.handle = nil
|
self.handle = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -474,21 +474,21 @@ function fileStream:read(n)
|
|||||||
if not self.handle then
|
if not self.handle then
|
||||||
return nil, "file is closed"
|
return nil, "file is closed"
|
||||||
end
|
end
|
||||||
return component.proxy(self.fs).read(self.handle, n)
|
return self.fs.read(self.handle, n)
|
||||||
end
|
end
|
||||||
|
|
||||||
function fileStream:seek(whence, offset)
|
function fileStream:seek(whence, offset)
|
||||||
if not self.handle then
|
if not self.handle then
|
||||||
return nil, "file is closed"
|
return nil, "file is closed"
|
||||||
end
|
end
|
||||||
return component.proxy(self.fs).seek(self.handle, whence, offset)
|
return self.fs.seek(self.handle, whence, offset)
|
||||||
end
|
end
|
||||||
|
|
||||||
function fileStream:write(str)
|
function fileStream:write(str)
|
||||||
if not self.handle then
|
if not self.handle then
|
||||||
return nil, "file is closed"
|
return nil, "file is closed"
|
||||||
end
|
end
|
||||||
return component.proxy(self.fs).write(self.handle, str)
|
return self.fs.write(self.handle, str)
|
||||||
end
|
end
|
||||||
|
|
||||||
function filesystem.open(path, mode)
|
function filesystem.open(path, mode)
|
||||||
@ -503,7 +503,7 @@ function filesystem.open(path, mode)
|
|||||||
return nil, "file not found"
|
return nil, "file not found"
|
||||||
end
|
end
|
||||||
|
|
||||||
local handle, reason = component.proxy(node.fs).open(rest, mode)
|
local handle, reason = node.fs.open(rest, mode)
|
||||||
if not handle then
|
if not handle then
|
||||||
return nil, reason
|
return nil, reason
|
||||||
end
|
end
|
||||||
@ -512,8 +512,7 @@ function filesystem.open(path, mode)
|
|||||||
|
|
||||||
local function cleanup(self)
|
local function cleanup(self)
|
||||||
if not self.handle then return end
|
if not self.handle then return end
|
||||||
local proxy = component.proxy(self.fs)
|
pcall(self.fs.close, self.handle)
|
||||||
if proxy then pcall(proxy.close, self.handle) end
|
|
||||||
end
|
end
|
||||||
local metatable = {__index = fileStream,
|
local metatable = {__index = fileStream,
|
||||||
__gc = cleanup,
|
__gc = cleanup,
|
||||||
|
@ -32,6 +32,31 @@ local sides = {
|
|||||||
forward = 3
|
forward = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local metatable = getmetatable(sides) or {}
|
||||||
|
|
||||||
|
-- sides[0..5] are mapped to itertable[1..6].
|
||||||
|
local itertable = {
|
||||||
|
sides[0],
|
||||||
|
sides[1],
|
||||||
|
sides[2],
|
||||||
|
sides[3],
|
||||||
|
sides[4],
|
||||||
|
sides[5]
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Future-proofing against the possible introduction of additional
|
||||||
|
-- logical sides (e.g. [7] = "all", [8] = "none", etc.).
|
||||||
|
function metatable.__len(sides)
|
||||||
|
return #itertable
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Allow `sides` to be iterated over like a normal (1-based) array.
|
||||||
|
function metatable.__ipairs(sides)
|
||||||
|
return ipairs(itertable)
|
||||||
|
end
|
||||||
|
|
||||||
|
setmetatable(sides, metatable)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
return sides
|
return sides
|
||||||
|
@ -271,6 +271,7 @@ class Settings(val config: Config) {
|
|||||||
val inputUsername = config.getBoolean("misc.inputUsername")
|
val inputUsername = config.getBoolean("misc.inputUsername")
|
||||||
val maxClipboard = config.getInt("misc.maxClipboard") max 0
|
val maxClipboard = config.getInt("misc.maxClipboard") max 0
|
||||||
val maxNetworkPacketSize = config.getInt("misc.maxNetworkPacketSize") max 0
|
val maxNetworkPacketSize = config.getInt("misc.maxNetworkPacketSize") max 0
|
||||||
|
val maxNetworkPacketParts = config.getInt("misc.maxNetworkPacketParts") max 0
|
||||||
val maxOpenPorts = config.getInt("misc.maxOpenPorts") max 0
|
val maxOpenPorts = config.getInt("misc.maxOpenPorts") max 0
|
||||||
val maxWirelessRange = config.getDouble("misc.maxWirelessRange") max 0
|
val maxWirelessRange = config.getDouble("misc.maxWirelessRange") max 0
|
||||||
val rTreeMaxEntries = 10
|
val rTreeMaxEntries = 10
|
||||||
|
@ -93,7 +93,7 @@ trait Connector extends network.Connector with Node {
|
|||||||
// we get ignored if our size is zero.
|
// we get ignored if our size is zero.
|
||||||
localBufferSize = clampedSize
|
localBufferSize = clampedSize
|
||||||
if (network != null) {
|
if (network != null) {
|
||||||
if (localBufferSize <= 0 && clampedSize > 0) d.addConnector(this)
|
if (oldSize <= 0 && clampedSize > 0) d.addConnector(this)
|
||||||
else if (oldSize > 0 && clampedSize == 0) d.removeConnector(this)
|
else if (oldSize > 0 && clampedSize == 0) d.removeConnector(this)
|
||||||
else d.globalBufferSize = math.max(d.globalBufferSize - oldSize + clampedSize, 0)
|
else d.globalBufferSize = math.max(d.globalBufferSize - oldSize + clampedSize, 0)
|
||||||
}
|
}
|
||||||
|
@ -672,7 +672,11 @@ object Network extends api.detail.NetworkAPI {
|
|||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
class Packet(var source: String, var destination: String, var port: Int, var data: Array[AnyRef], var ttl: Int = 5) extends api.network.Packet {
|
class Packet(var source: String, var destination: String, var port: Int, var data: Array[AnyRef], var ttl: Int = 5) extends api.network.Packet {
|
||||||
val size = Option(data).fold(0)(_.foldLeft(0)((acc, arg) => {
|
val size = Option(data).fold(0)(values => {
|
||||||
|
if (values.length > Settings.get.maxNetworkPacketParts) {
|
||||||
|
throw new IllegalArgumentException("packet has too many parts")
|
||||||
|
}
|
||||||
|
values.length * 2 + values.foldLeft(0)((acc, arg) => {
|
||||||
acc + (arg match {
|
acc + (arg match {
|
||||||
case null | Unit | None => 4
|
case null | Unit | None => 4
|
||||||
case _: java.lang.Boolean => 4
|
case _: java.lang.Boolean => 4
|
||||||
@ -682,7 +686,8 @@ object Network extends api.detail.NetworkAPI {
|
|||||||
case value: Array[Byte] => value.length max 1
|
case value: Array[Byte] => value.length max 1
|
||||||
case _ => throw new IllegalArgumentException("unsupported data type")
|
case _ => throw new IllegalArgumentException("unsupported data type")
|
||||||
})
|
})
|
||||||
}))
|
})
|
||||||
|
})
|
||||||
|
|
||||||
override def hop() = new Packet(source, destination, port, data, ttl - 1)
|
override def hop() = new Packet(source, destination, port, data, ttl - 1)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user