Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function main()
- -- *************************************
- -- * Hier muss das Hauptprogramm rein! *
- -- * Put your main program in here! *
- -- *************************************
- while true do
- sleep(1)
- end
- end
- function transferModule()
- --**************************
- --* Standart Einstellungen *
- --* Default Settings *
- --**************************
- local pcName = "HOMEPC"
- local pcPass = ""
- local passActivated = false
- local allowedIDs = {}
- local onlyAllowedID = false
- --**********************************
- --* Hier nichts ändern! *
- --* Don't change anything below! *
- --**********************************
- local allowedPCs = {}
- checked = false
- accessAllowed = false
- while true do
- id, message, range = rednet.receive()
- if onlyAllowedID then
- for _, v in pairs(allowedIDs) do
- if id == v then
- accessAllowed = true
- break
- end
- end
- end
- if not onlyAllowedID or accessAllowed then
- if message == "$CHECK_COMPATIBLE_PCS" then
- check_message = "$FIRST"
- writeToLog("\(\'"..id.."\'\) spottet you.\n")
- while checked == false and check_message ~= nil do
- if passActivated then
- rednet.send(id, "$COMPATIBLEPASS;" .. pcName)
- else
- rednet.send(id, "$COMPATIBLE;" .. pcName)
- end
- a, check_message, range = rednet.receive(0.5)
- if check_message == "$GOTYA" then
- checked = true
- end
- end
- checked = false
- elseif string.len(message) > 4 then
- if string.sub(message, 1, 4) == "$DIR" then
- if passActivated then
- if not searchInTable(id, allowedPCs) then
- rednet.send(id, "$PASS")
- writeToLog("\(\'"..id.."\'\) tried to login.\n")
- idC, password, range = rednet.receive(20)
- if password ~= nil then
- if string.find(password.."", "$PASS", 1, true) then
- password = string.sub(password, string.find(password.."", ";") + 1, -1)
- if password == pcPass then
- table.insert(allowedPCs, id)
- writeToLog("\(\'"..id.."\'\) logged in.\n")
- else
- rednet.send(idC, "DENIED")
- end
- end
- end
- end
- end
- if not passActivated or searchInTable(id, allowedPCs) then
- programMessage = {}
- progs = {}
- dirs = {}
- message = string.gsub(message, pcName, "")
- path = string.sub(message, string.find(message.."", ";") + 1, -1)
- for i,v in pairs(fs.list(path)) do
- if fs.isDir(path.."/"..v) and v ~= "rom" then
- table.insert(dirs, v)
- elseif v ~= "rom" then
- table.insert(progs, v)
- end
- end
- table.insert(programMessage, dirs)
- table.insert(programMessage, progs)
- rednet.send(id, "$AVAIDIR;" .. textutils.serialize(programMessage))
- else
- rednet.send(id, "DENIED")
- end
- elseif string.len(message) > 12 then
- if not passActivated or searchInTable(id, allowedPCs) then
- if string.sub(message, 1, 12) == "$GETPROGCODE" then
- message = string.gsub(message, "/"..pcName, "")
- file = fs.open(string.sub(message, string.find(message.."", ";") + 1, -1), "r")
- tempProgCode = file.readAll()
- file.close()
- writeToLog("\(\'"..id.."\'\) has uploaded ".. string.sub(message, string.find(message.."", ";") + 1, -1) ..".\n")
- rednet.send(id, "$PROGCODE;"..tempProgCode)
- end
- end
- end
- elseif string.len(message) > 12 then
- if not passActivated or searchInTable(id, allowedPCs) then
- if string.sub(message, 1, 11) == "$GETPROGCODE" then
- message = string.gsub(message, "/"..pcName, "")
- fs.delete(string.sub(message, string.find(message.."", ";") + 1, -1))
- writeToLog("\(\'"..id.."\'\) has deleted ".. string.sub(message, string.find(message.."", ";") + 1, -1) ..".\n")
- end
- end
- else
- rednet.send(id, "DENIED")
- end
- end
- end
- end
- function searchInTable(value, table)
- for _, v in pairs(table) do
- if value == v then
- return true
- end
- end
- return false
- end
- function writeToLog(logtext)
- file = fs.open("log.txt", "a")
- file.writeLine(logtext)
- file.close()
- end
- function transferModuleCheckRednet()
- local checkStatus = false;
- local modemPresent = false;
- tekkitLite = {
- "top",
- "bottom",
- "left",
- "right",
- "front",
- "back"
- }
- while true do
- for i, side in pairs(tekkitLite) do
- if (peripheral.getType(side) == "modem" and checkStatus == false) then
- rednet.open(side);
- modemPresent = true;
- checkStatus = true;
- end
- if (peripheral.getType(side) ~= "modem" and checkStatus == false) then
- modemPresent = false;
- end
- end
- modemPresent = false;
- checkStatus = false;
- sleep(2);
- end
- end
- parallel.waitForAny(transferModule, transferModuleCheckRednet, main)
Advertisement
Add Comment
Please, Sign In to add comment