-
Notifications
You must be signed in to change notification settings - Fork 0
net
_G.net
Signature | Return | Description |
---|---|---|
getHWAddr() |
string |
Gets the computer's hardware address (hex string) |
getIPV() |
string |
Gets the type of address the computer uses (currently IPV4) |
ipFormat(ip) |
string |
Format a numeric IPV4 in the the standard format |
ipToNumber(ip) |
NetAddress |
Turns an IP string into a numerical IP address |
getIP() |
NetAddress |
Gets the current IP of the computer (numeric) |
getIPMask() |
number |
Get the address mask of the local network (numeric) |
getMsgId() |
number |
Get the current message ID |
useMsgId() |
number |
Increment and return the current message ID |
realizeHostname(hostname) |
NetAddress |
Gets the IP address associated with a given hostname |
getModem(side) |
table? |
Get a modem on side, and add network functions |
getHostname() |
string |
Returns the network hostname of the computer |
setHostname(new) |
boolean |
Sets the network hostname of the computer |
isSetup() |
boolean |
If the network module has been setup |
getCModem() |
table? |
Gets the currently used modem |
setup(mdm, ip) |
boolean |
Setup the network module, returns false on a failure |
send(port, dest, msgType, body) |
number |
Send a message with a type header |
sendSync(port, dest, msgType, body, timeout?) |
NetMessage|string |
Send a message with a type header, and waits for the reply |
sendAdv(port, dest, head, body) |
number |
Send a message with a custom header |
sendAdvSync(port, dest, head, body, timeout?) |
NetMessage|string |
Send a message with a custom header, and waits for the reply |
reply(port, old, head, body) |
number |
Reply to a message |
waitForMsg(port, time) |
NetMessage|string |
Waits for a message on a particular port, with a timeout |
waitForMsgAdv(port, time, check) |
NetMessage|string |
Waits for a message on a particular port, with a timeout |
waitForMsgAll(check, time) |
NetMessage|string |
Waits for a message based on the check function, or a timeout |
validMsg(port, message) |
boolean |
Checks is a modem message is a valid network message |
registerMsgHandler(func) |
number |
Register a message handler |
unregisterMsgHandler(id) |
nil |
Unregister a message handler |
getCIDofNetHandlers() |
number |
Get the id of the next message handler |
multicastSubscribe(ip, handler) |
integer |
Subscribe to a multicast group |
multicastUnsubscribe(ip, id) |
nil |
Remove a multicast subscription, uses ID from subscription |
stringMessage(msg) |
string |
Returns a string version of the message for debug and logging |
open(port) |
nil |
Open the modem on port |
ping(dest) |
nil |
Ping destination and print time |
splitUrl(url) |
string?, string, string |
Split a url string |
setLogVerbose(vb) |
nil |
Sets if the net module should log all messages |
Variable | Description |
---|---|
standardPorts: table |
Standard Networking ports |
ignoreMsgOnDecryptFail: boolean = true |
If messages that can not be decrypted should be ignored |
DEFAULT_TIMEOUT: number = 5 |
Default message wait time out in seconds |
net.getHWAddr():string
Gets the computer's hardware address (hex string)
-
hwAddress: string
- Hardware address as hex string
net.getIPV():string
Gets the type of address the computer uses (currently IPV4)
-
version: string
- Gets the IP version used by the module
net.ipFormat(ip: NetAddress): string
Format a numeric IPV4 in the the standard format
-
ip: NetAddress
- IP address either as number, or hardware address
-
ip: string
- IP address formatted in IPV4x.x.x.x
net.ipToNumber(ip: string|NetAddress): NetAddress
Turns an IP string into a numerical IP address
-
ip: string|NetAddress
- IP Address asx.x.x.x
-
ip: NetAddress
- Address as number
net.getIP(): NetAddress
Gets the current IP of the computer (numeric)
-
ip: NetAddress
- The numeric IP of the computer
net.getIPMask(): number
Get the address mask of the local network (numeric)
-
mask: number
- Numeric IP subnet mask (ie.0xff00
for255.255.0.0
)
net.getMsgId(): number
Get the current message ID
-
id: number
- Id for last message
net.useMsgId(): number
Increment and return the current message ID
-
id: number
- Id for next message
net.realizeHostname(hostname: string|NetAddress): NetAddress
Gets the IP address associated with a given hostname
-
hostname: string|NetAddress
- Hostname, IP address, or HW address
-
ip: NetAddress
- Numeric IP address or HW address
net.getModem(side: 'front'|'back'|'left'|'right'|'top'|'bottom'): table?
Get a modem on side, and add network functions
-
side: 'front'|'back'|'left'|'right'|'top'|'bottom'
- Side of computer
-
modem: table?
- Modem handle
net.getHostname(): string
Returns the network hostname of the computer
-
hostname: string
- Current hostname (defaults to""
)
net.setHostname(new: string): boolean
Sets the network hostname of the computer. Returns if setting the hostname succeeded
Important
Requires Super User
-
new: string
- New hostname
-
suc: boolean
- If the hostname was set successfully
net.isSetup(): boolean
If the network module has been setup
-
setup: boolean
- If module is setup
net.getCModem(): table?
Gets the currently used modem
-
modem: table?
- Current primary modem
net.setup(mdm?: table, ip?: number): boolean
Setup the network module, returns false on a failure
-
mdm?: table
- (Optional) Primary modem -
ip?: number
- (Optional) Numeric IP address
-
setup: boolean
- If the module is not setup
net.send(port: number, dest: string|NetAddress, msgType: string, body: nil|table|string): number
Send a message with a type header
-
port: number
- Network port for message (seenet.standardPorts
) -
dest: string|NetAddress
- Destination IP address, HW address, or hostname -
msgType: string
- Message type -
body: nil|table|string
- Message body
-
id: number
- Message ID or-1
on error
net.sendSync(port: number, dest: string|NetAddress, msgType: string, body: nil|table|string, timeout?: number): NetMessage|string
Send a message with a type header, and waits for the reply.
Returns the message, "setup_fail"
, "sent_fail"
, or "timeout"
after timeout
-
port: number
- Network port for message (seenet.standardPorts
) -
dest: number|string
- Destination IP address, HW address, or hostname -
msgType: string
- Message type -
body: nil|table|string
- Message body -
timeout?: number
- (Optional) Reply timeout in seconds (default isnet.DEFAULT_TIMEOUT
seconds, set to-1
to disable)
-
rsp: NetMessage|string
- Response message, or error string
net.sendAdv(port: number, dest: NetAddress|string, head: NetMessage.Header, body: nil|table|string): number
Send a message with a custom header
-
port: number
- Network port for message (seenet.standardPorts
) -
dest: NetAddress|string
- Destination IP address, HW address, or hostname -
head: NetMessage.Header
- Message header, should include type parameter -
body: nil|table|string
- Message body
-
id: number
- Message ID or-1
on error
net.sendAdvSync(port: number, dest: NetAddress|string, head: NetMessage.Header, body: nil|table|string, timeout?: number): NetMessage|string
Send a message with a custom header, and waits for the reply.
Returns the message, "setup_fail"
, "send_fail"
, or "timeout"
after timeout
-
port: number
- Network port for message (seenet.standardPorts
) -
dest: NetAddress|string
- Destination IP address, HW address, or hostname -
head: NetMessage.Header
- Message header, should include type parameter -
body: nil|table|string
- Message body -
timeout?: number
- (Optional) Reply timeout in seconds (default isnet.DEFAULT_TIMEOUT
seconds, set to-1
to disable)
-
rsp: NetMessage|string
- Response message, or error string
net.reply(port: number, old: NetMessage, head: NetMessage.Header, body: nil|table|string): number
Reply to a message
-
port: number
- Network port for reply (seenet.standardPorts
) -
old: NetMessage
- Message object to reply to -
head: NetMessage.Header
- Reply header, should includetype
field -
body: nil|table|string
- Reply body
-
id: number
- Reply message id
net.waitForMsg(port: number, time: number): NetMessage|string
Waits for a message on a particular port, with a timeout.
-
port: number
- Network port to listen on (-1
for any) -
time?: number
- (Optional) Timeout in seconds (default isnet.DEFAULT_TIMEOUT
seconds, set to-1
to disable)
-
rsp: NetMessage|string
- Message or error string
net.waitForMsgAdv(port: number, time: number, check: fun(msg: NetMessage): boolean): NetMessage|string
Waits for a message on a particular port, with a timeout.
Check function should return true on the message you want, and takes the message as a parameter.
-
port: number
- Network port to listen on (-1
for any) -
time: number
- Timeout in seconds -
check: fun(msg: NetMessage): boolean
- Message check function, takes message as parameter, and returns continue waiting
-
rsp: NetMessage|string
- Message or error string
-- Wait for the next RTTP message
local rsp = net.waitForMsgAdv(net.standardPorts.rttp, nil, function(message)
if message.header.type == 'rttp' then
return false
end
return true -- Not RTTP, so keep waiting
end)
net.waitForMsgAll(check: fun(port: number, msg: NetMessage): boolean, time: number?): NetMessage|string
Waits for a message based on the check function, or a timeout.
Check function takes the port and message.
-
check: fun(port: number, msg: NetMessage): boolean
- Message check function, takes message as parameter, and returns continue waiting -
time: number?
- Timeout in seconds (default isnet.DEFAULT_TIMEOUT
seconds, set to-1
to disable)
-
rsp: string|NetMessage
- Message or error string
-- Wait for the next message from 0.0.0.0
local rsp = net.waitForMsgAdv(net.standardPorts.rttp, nil, function(port, message)
if message.header.origin == 0 then -- From 0.0.0.0
return false
end
return true -- Not from correct IP, so keep waiting
end)
net.validMsg(port: number, message: table): boolean
Checks is a modem message is a valid network message
-
port: number
- Network port of message -
message: table
- Message to validate
-
valid: boolean
Message is valid
net.registerMsgHandler(func: fun(msg: NetMessage)): number
Register a message handler
-
func: fun(msg: NetMessage)
- Handler function, takes a message object
-
id: number
- Handler Id, used to un-register handlers
-- Count every message for myProtocol that this computer receives without blocking
local count = 0
local id = net.registerMsgHandler(function(message)
if message.header.type == 'myProtocol' then
count = count + 1
end
end)
net.unregisterMsgHandler(id: number): nil
Un-register a message handler
-
id number
- Handler Id
net.getCIDofNetHandlers(): number
Get the id of the next message handler
-
id: number
- Next handler id
net.multicastSubscribe(ip: number, handler: fun(ip: number, msg: NetMessage)): integer
v1.8
Subscribe to a multicast group. IP must be between 224.0.0.0
(0xe0000000
) and 239.255.255.255
(0xefffffff
).
-
ip: number
- Multicast group IP -
handler: fun(ip: number, msg: NetMessage)
- Multicast message handler
-
id: integer
- Handler Id, used to unregister subscriber
net.multicastUnsubscribe(ip: number, id: integer): nil
v1.8
Remove a multicast subscription, uses ID from subscription
-
ip: number
- Multicast group IP -
id: integer
- Handler Id, fromnet.multicastSubscribe(ip, handler)
net.stringMessage(msg: NetMessage): string
Returns a string version of the message for debug and logging. Includes: origin, destination, port, id, connection Id, type, and serialized body
-
msg: NetMessage
- Message to string
-
message: string
- String version of message
net.open(port: number): nil
Open the modem on port
-
port: number
- Network port to open (seenet.standardPorts
)
net.ping(dest: NetAddress|String): nil
Ping destination and print time
-
dest: NetAddress|string
- Destination hostname, IP address, HW address
net.splitUrl(url: string): string?, string, string
Split a url string
-
url: string
- URL string:protocol://domain/path
-
protocol: string?
* Protocol string (if provided, elsenil
) -
domain: string
- Domain, including sub domains -
path: string
- Path with no leading/
local proto, domain, path = net.splitUrl('rttp://xyz.com/abc/def')
print(proto)
print(domain)
print(path)
Prints
rttp
xyz.com
abc/def
net.setLogVerbose(vb: boolean): nil
Sets if the net module should log all messages
-
vb: boolean
- If all messages should be logged
Name | Value | Description |
---|---|---|
network |
10000 |
Network control messages |
rttp |
10080 |
Redstone Text Transfer Protocol (in-game HTTP) messages |
rttps |
10081 |
Redstone Text Transfer Protocol Secure (in-game HTTPS) messages |
ftp |
10021 |
File Transfer Protocol messages |
rmail |
10025 |
RMail messages |
remoteUser |
10234 |
Remote user system |
Networking message struct
Field | Description |
---|---|
origin: NetAddress |
Origin IP or HW of the message |
dest: NetAddress |
Destination IP or HW of message |
port: number |
Networking port for message |
header: NetMessage.Header |
Header table |
body: nil|table|string |
Message body |
msgid: number |
Message ID |
reply: fun(self, port: number, head: NetMessage.Header, body: nil|table|string) |
Reply to this message (equivalent to net.reply() ) |
Networking message header table
Field | Description |
---|---|
type: string |
Net message type |
encrypted: boolean? |
If the message body is encrypted |
publicKey: byteArray? |
Body encryption public key |
domain: string? |
Destination domain name |
conId: number? |
NAT connection ID |
destConId: number? |
Destination NAT connection ID |
originDomain: string? |
REPLY ONLY Domain the request was sent to |
certificate: net.Certificate? |
Certificate |
Alias for number|string
, represents an IP or HW address that can be used to send a message to another computer