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

--Size Check

w, h = term.getSize()

if w >= 51 and h >= 19 then

else
 term.setBackgroundColor(32768)
 term.setTextColor(16384)
 term.clear()
 term.setCursorPos(1,1)
 print("To small!")
 os.reboot()
end


--OS Version und Sprache

file = fs.open("SimSoft/Daten/Config","r")
local fileData = {}
local line = file.readLine()
repeat
table.insert(fileData,line)
line = file.readLine()
until line == nil
file.close()
SS2V = fileData[3]
Sprache = fileData[4]

--OS Update Function (Offline - Benoetigt verbesserung, bzw. Umbau)

local cacheBuster = ("%x"):format(math.random(0, 2 ^ 30))
local datei = http.get("https://pastebin.com/raw/LZch2Xnt" .. "?cb=" .. cacheBuster)
if not datei then
 function UpdateC()
  UpdateCV = true
 end
else

 datei = datei.readAll()
 
 local file = fs.open("SimSoft/Daten/UpdateCheck/S","w")
 file.writeLine(datei)
 file.close()
  
 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 UpdateC()
   UpdateCV = true
  end
 else
  function UpdateC()
   UpdateCV = false
  end
 end
 
 fs.delete("SimSoft/Daten/UpdateCheck/S")
end
 
--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

--Ausgesetzt


--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

function SimSoftBalken(titelzwei, titelzweilange)
 w, h = term.getSize()
 term.setBackgroundColor(32768)
 TC(1)
 
 anz = 0
 hig = 1
 while true do
  anz = (anz+1)
  term.setCursorPos(anz, hig)
  write(" ")
  if anz == w then
   if hig == 3 then
    titelzweilange = (titelzweilange/2)
	w = (w/2)
	w = (w-titelzweilange)
	
	term.setCursorPos(w,2)
	print(titelzwei)
	break
   else
    hig = (hig+1)
	anz = 0
   end
  end
 end
end

--End Functionen

--Start System (Passwort System)

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

PassSystem = fileData[1]

if PassSystem == "t" then

 --Pass System Desin

 BC(128)
 Clear()
 SimSoftBalken("SimSoft 3 - Login", 18)

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

 function PassSS(nr)
 
  file = fs.open("SimSoft/Daten/User/User"..nr,"r")
  local fileData = {}
  local line = file.readLine()
  repeat
  table.insert(fileData,line)
  line = file.readLine()
  until line == nil
  file.close()
 
  name = fileData[1]
  pass = fileData[2]
  ATF = fileData[3]
  
 end

 CP(5,9)
 TC(256)
 print("Username - ")
 TC(32768)
 
 TC(256)
 CP(5,11)
 write("Password - ")
 TC(32768)
 
 
 CP(16,9)
 namee = read()
 CP(16,11)
 passe = read("*")

 PassSS(1)
 if namee == name then
  if passe == pass then
   function Rechte()
	Recht = "Admin"
	RechtH = 1
   end
   shell.run("SimSoft/System/Desktop")
  else
   TC(1)
   CP(3,14)
   print("Wrong name or password")
   sleep(1.5)
   os.reboot()
  end
 else
 
  PassSS(2)
  if namee == name then
   if ATF == "false" then
    TC(1)
    CP(3,14)
    print("This account is offline")
    sleep(1.5)
    os.reboot()
   elseif passe == pass then
    function Rechte()
	 Recht = "Gast"
	 RechtH = 2
	end
    shell.run("SimSoft/System/Desktop")
   else
    TC(1)
    CP(3,14)
    print("Wrong name or password")
    sleep(1.5)
    os.reboot()
   end
  else
 
   PassSS(3)
   if namee == name then
    if ATF == "false" then
    TC(1)
    CP(3,14)
    print("This account is offline")
    sleep(1.5)
    os.reboot()
   elseif passe == pass then
     function Rechte()
	  Recht = "Gast"
	  RechtH = 3
	 end
     shell.run("SimSoft/System/Desktop")
    else
     TC(1)
     CP(3,14)
     print("Wrong name or password")
     sleep(1.5)
     os.reboot()
    end
   else
    TC(1)
    CP(3,14)
    print("Wrong name or password")
    sleep(1.5)
    os.reboot()
   end
  end
 end
 
else
 function Rechte()
  Recht = "Admin"
  RechtH = 0
 end
 shell.run("SimSoft/System/Desktop")
end

--End