--Alle Rechte an SimSoft 2.1 sind "SimlorLP" (oder in Minecraft auch nur "Simlor") vorbehalten.

--OS Version

function Version()
 file = fs.open("SimSoft/Daten/User","r")
 local fileData = {}
 local line = file.readLine()
 repeat
 table.insert(fileData,line)
 line = file.readLine()
 until line == nil
 file.close()
 SS2V = fileData[5]
end

Version()

--Download Function

function Download(CodePB, Pfad)
 local cacheBuster = ("%x"):format(math.random(0, 2 ^ 30))
 local datei = http.get("https://pastebin.com/raw/" .. textutils.urlEncode(CodePB) .. "?cb=" .. cacheBuster)
 datei = datei.readAll()
 
 local file = fs.open(Pfad, "w")
 file.write(datei)
 file.close()
end

--Lade screen

term.setBackgroundColor(32768)
term.setTextColor(128)
term.clear()
term.setCursorPos(1,1)

print(">Run SimSoft in version "..SS2V)
print(">Pleas wait...")

--Updata Check

Download("DrUiPUvq", "SimSoft/Daten/UpdateCheck/S")

file = fs.open("SimSoft/Daten/UpdateCheck/S","r")
local fileData = {}
local line = file.readLine()
repeat
table.insert(fileData,line)
line = file.readLine()
until line == nil
file.close()

v = fileData[1]

if v == SS2V then
 function UpdataC()
  UpdataCV = true
 end
else
 function UpdataC()
  UpdataCV = false
 end
end

fs.delete("SimSoft/Daten/UpdateCheck/S")

--Rednet Check

if peripheral.getType("back") == "modem" then
 rednet.open("back")
end

if peripheral.getType("left") == "modem" then
 rednet.open("left")
end

if peripheral.getType("right") == "modem" then
 rednet.open("right")
end

if peripheral.getType("top") == "modem" then
 rednet.open("top")
end

if peripheral.getType("front") == "modem" then
 rednet.open("front")
end

if peripheral.getType("bottom") == "modem" then
 rednet.open("bottom")
end

--Functionen

function Clear()
 term.clear()
 term.setCursorPos(1,1)
end

function CP(x,y)
 term.setCursorPos(x,y)
end

function TC(farbe)
 term.setTextColor(farbe)
end

function BC(farbe)
 term.setBackgroundColor(farbe)
end

--End Functionen

--Start System (Passwort System)

file = fs.open("SimSoft/Daten/User","r")
local fileData = {}
local line = file.readLine()
repeat
table.insert(fileData,line)
line = file.readLine()
until line == nil
file.close()

hint = fileData[3]

if hint == "t" then

 --Pass System Desin
 BC(128)
 Clear()

 BC(32768)
 CP(1,1)
 print("                                                   ")
 print("                                                   ")
 print("                                                   ")

 CP(15,2)
 TC(1)
 print("SimSoft 2.1 - Login")

 BC(128)
 CP(4,7)
 TC(1)
 print("Login")

 file = fs.open("SimSoft/Daten/User","r")
 local fileData = {}
 local line = file.readLine()
 repeat
 table.insert(fileData,line)
 line = file.readLine()
 until line == nil
 file.close()
 
 name = fileData[1]
 passr = fileData[2]

 
 CP(5,9)
 TC(256)
 write("Username - ")
 TC(32768)
 print(name)

 TC(256)
 CP(5,11)
 write("Password - ")
 TC(32768)
 passe = read("*")

 if passe == passr then
  shell.run("SimSoft/System/Desktop")
 else
  term.setCursorPos(5,14)
  BC(128)
  TC(256)
  print("Wrong password.")
  sleep(0.6)
  shell.run("SimSoft/System/SystemStart")
 end
 
else
 shell.run("SimSoft/System/Desktop")
end

--End