Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- if not component.internet then
- io.stderr("No internet card avaliable")
- return
- end
- if not component.internet.isTcpEnabled() then
- io.stderr("Tcp is not enabled")
- return
- end
- local process = require("process")
- local filesystem = require("filesystem")
- local internet = require("internet")
- local thisFolder = filesystem.path(process.running())
- --local definitions = dofile(filesystem.concat(thisFolder, "definitions.lua"))
- local address = "ADDRESS OF SERVER" -- address of the server, change this
- local port = 25565 -- change if the server isn't on the default port
- local handle = internet.open(address,port)
- --length
- handle:write(string.char(6 + address:len()))
- --packet id
- handle:write(string.char(0))
- --version
- handle:write(string.char(4))
- --address
- handle:write(string.char(address:len()))
- handle:write(address)
- --port
- handle:write(string.char(bit32.band(bit32.rshift(port,8),0xff)))
- handle:write(string.char(bit32.band(port,0xff)))
- --next state
- handle:write(string.char(1))
- --request
- handle:write(string.char(1))
- handle:write(string.char(0))
- handle:flush()
- os.sleep(1)
- local function readNum()
- local num = 0
- local lastRead
- local shift = 0
- repeat
- lastRead = handle:read(1):byte()
- num = num + bit32.lshift(bit32.band(lastRead, 0x7f),shift)
- shift = shift + 8
- until bit32.band(lastRead, 0x80) ~= 0x80
- return num
- end
- --response
- local length = readNum()
- local id = handle:read(1):byte()
- local strLen = readNum()
- local response = handle:read(strLen)
- print(response)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement