Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- wifi B****
- mk2
- ]]--
- local oldError = error
- error = function(...)
- local data = {...}
- local file = fs.open("log","w")
- for i = 1,#data do
- file.write(tostring(data[1].." "))
- end
- file.write("\n")
- file.close()
- oldError(unpack(data))
- end
- local function hold() -- just used for error testing
- print("HOLD")
- local test
- while test ~= 28 do
- local _,bla = os.pullEvent("key")
- test = bla
- end
- end
- local function findDevice(sType)
- for _,sSide in pairs(rs.getSides()) do
- if peripheral.isPresent(sSide) and peripheral.getType(sSide) == sType then
- return sSide,peripheral.wrap(sSide)
- end
- end
- end
- local function printTable(tInput) -- just used for error testing
- if type(tInput) == "table" then
- for i = 1,#tInput do
- write(tostring(tInput[i]).." ")
- end
- print("")
- else
- print(tostring(tInput))
- end
- end
- local modemSide,modem = findDevice("modem")
- local function wifiRedirect(sSide,freq)
- local modem = peripheral.wrap(sSide)
- local freq = freq
- local tFunctions = {
- "scroll","setCursorBlink", -- "setCursorPos" "write"
- "clear","clearLine","setTextColour","setTextColor",
- "setBackgroundColour","setBackgroundColor",
- }
- -- "getCursorPos","getSize","isColour","isColor",
- local posX,posY = 1,1
- local tRemote = {
- getCursorPos = function()
- return posX,posY
- end,
- setCursorPos = function(x,y)
- posX = x
- posY = y
- modem.transmit(freq,freq,textutils.serialize({"setCursorPos",x,y}))
- end,
- getSize = function()
- return 51,19
- end,
- write = function(line,...)
- if line and type(line) == "string" then
- posX = posX + #line
- end
- modem.transmit(freq,freq,textutils.serialize({"write",line,...}))
- end,
- }
- modem.transmit(freq,freq,"ISC")
- local nTimer = os.startTimer(1)
- while true do
- local event = {os.pullEvent()}
- if event[1] == "timer" and event[2] == nTimer then
- error(" ERROR Remote time out")
- elseif event[1] == "modem_message" and event[2] == modemSide and freq == event[3] then
- local test,tInput = pcall(textutils.unserialize,event[5])
- if test and type(tInput) == "table" then
- if tInput.cmd and tInput.cmd == "REPLY-SCP" then
- if tInput.test and tInput.test == true then
- tRemote.isColour = function()
- return true
- end
- tRemote.isColor = function()
- return true
- end
- break
- else
- tRemote.isColour = function()
- return false
- end
- tRemote.isColor = function()
- return false
- end
- break
- end
- end
- end
- end
- end
- for i = 1,#tFunctions do
- local funk = tFunctions[i]
- tRemote[funk] = function(...)
- modem.transmit(freq,freq,textutils.serialize({tFunctions[i],...}))
- end
- end
- os.pullEvent = function(...)
- local event = {os.pullEventRaw(...)}
- if event[1] == "modem_message" and event[2] == modemSide and freq == event[3] then
- local test,tInput = pcall(textutils.unserialize,event[5])
- if test and type(tInput) == "table" then
- if tInput[1] == "INS" then
- table.remove(tInput,1)
- os.queueEvent(unpack(tInput))
- end
- end
- elseif event[1] == "terminate" then
- error("Terminate")
- else
- return unpack(event)
- end
- end
- term.redirect(tRemote)
- end
- --[[
- "getCursorPos","getSize","isColour","isColor"
- ]]--
- local freq
- local user
- local pass
- local function main()
- os.startTimer(0.5)
- while true do
- local event = {os.pullEvent()}
- if event[1] == "modem_message" and event[2] == modemSide and freq == event[3] then
- local test,tInput = pcall(textutils.unserialize,event[5])
- if test and type(tInput) == "table" then
- if tInput.user and tInput.user == user and tInput.password and tInput.password == pass then
- print("Authenticated user!")
- wifiRedirect(modemSide,freq)
- return
- end
- end
- elseif event[1] == "timer" then
- end
- --printTable(event)
- end
- end
- local tArg = {...}
- if modemSide then
- print(" --- Remote access server --- ")
- while true do
- write("Choose Freq : ")
- local temp = tArg[1] or read()
- if string.lower(temp) == "exit" then
- print(" --- Server stoping --- ")
- return
- end
- temp = tonumber(temp)
- if type(temp) == "number" and temp >= 0 and temp <= 65535 then
- freq = temp
- break
- end
- print("ERROR : Range 0 - 65535 or Exit")
- end
- write("User : ")
- user = tArg[2] or read()
- write("Password : ")
- pass = tArg[3] or read("*")
- print("Opening modem : "..modemSide.." Freq : "..tostring(freq))
- modem.open(freq)
- main()
- else
- print("ERROR : Failed to find modem ")
- end
- --[[
- freq
- ]]--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement