User:Matthew Cenance/TagSSDraft

print("Please Wait...")

-- Variables local print = print local clear = clear local math = math local io = io -- Files local RootPath = "" local path = "" local DirFile = "DirFile" local Running = 1 -- User Accounts local UserFileDir = "TerUser" local CurUser, UserPiv = "", "NotSignedIn" -- Tables -- TagSS = { }

-- SignIn local Users = { } local UsersSignInCre = { } local SignInTable = { }

--- --- Functions --- ---

-- New in Preview R2.01 function TagSSVersion return "PreR2.03.01" end TagSS.Version = TagSSVersion -- New in Preview R2 local function Wait(Time) local OldTime = os.clock while os.clock < (OldTime + Time) do  end return os.clock - OldTime end

--- -- User Accounts -- ---

-- Used by NUserFile function AddUserToList(UserName) local DirHandle = io.open(RootPath..UserFileDir, "a") DirHandle:write(UserName,"\n") DirHandle:close end

-- Create UserFile for Password function NUserFile(UserName, Password, Privileges, LOBlockTimes, LOBadPwT, LOMaxBlock, LOMaxBad, AUTL ) if AUTL == true then AddUserToList(UserName) end local PassFile = io.open(RootPath..UserFileDir..UserName, "w") PassFile:write(Password.."\n") PassFile:write(Privileges.."\n") PassFile:write(LOBlockTimes.. "\n"..LOBadPwT.. "\n"..LOMaxBlock.. "\n"..LOMaxBad) PassFile:close return "Ok" end

-- Signs in to your user account function SignIn(UserName,Password) local UserIsVa = UserExists(UserName) local UsFileT,CorPassword, Privileges, LOBlockTimes, LOBadPwT, LOMaxBlock, LOMaxBad if UserIsVa then UsFileT = FileText(UserFileDir..UserName) CorPassword, Privileges, LOBlockTimes, LOBadPwT, LOMaxBlock, LOMaxBad = UsFileT[1], UsFileT[2], UsFileT[3], UsFileT[4], UsFileT[5], UsFileT[6] print(CorPassword, Privileges, LOBlockTimes, LOBadPwT, LOMaxBlock, LOMaxBad) if Password == CorPassword then CurUser = UserName UserPiv = Privileges SignInTable = UsFileT NUserFile(UserName, Password, Privileges, 0, 0, LOMaxBlock, LOMaxBad, false) print("Signed In as "..UserName) return true else print("Incorrect Password for "..UserName..", Times: ".. LOBadPwT.."/"..LOMaxBad..", Blocked: "..LOBlockTimes.."/"..LOMaxBlock..".") if LOBadPwT >= LOMaxBad then LOBadPwT = 0 LOBlockTimes = LOBlockTimes + 1 local BlockedTime = LOBlockTimes * LOMaxBad print("You was blocked for "..BlockedTime.." seconds. Please wait.") Wait(BlockedTime) end end else local NewPri if #FileText(UserFileDir) > 0 then NewPri = "Basic" else NewPri = "Advanced" end print(NUserFile(UserName, Password, NewPri, 0, 0, 5, 5, true )) CurUser = UserName UserPiv = NewPri print("User Created") end end

-- Other --

-- Shutdown local function Shutdown Running = nil end

-- OSEnv function OSEnv local running = true while running do     print("OSEnv>") local FAnswer = io.read if FAnswer == "" then running = false end print(os.getenv(FAnswer)) end end

-- Prints table contents. function PrintTable(t) for key,value in pairs(t) do     print(key,value) end end local PrintTable = PrintTable

-- Print the actions usable. local function PrintActions(PrintWhat) PrintTable(TAction) print((#TAction+1),"Clear") print((#TAction+2),"Shutdown","Exit") print((#TAction+3),"Kill") print("Files:") PrintTable(ReturnFiles) end

-- -- File Functions -- --

-- Returns a table containing the files from DirFile. (Actualy it is simply reading the lines of DirFile.) function ReturnFiles local Table = { }  local DirHandle = io.open(RootPath..DirFile, "r") local LineText="" local Lines=0 while(LineText~=nil)do Lines = Lines + 1 LineText = DirHandle:read Table[Lines] = LineText end DirHandle:close return Table end local ReturnFiles = ReturnFiles

-- Like ReturnFiles, but reading the lines of FileName. function FileText(FileName) local FileTextT = { }  local FileHandle = io.open(RootPath..FileName, "r") print("FileHandle "..tostring(FileHandle)) if FileHandle == nil then return FileTextT end local LineText="" local Lines=0 while(LineText~=nil)do Lines = Lines + 1 LineText = FileHandle:read FileTextT[Lines] = LineText end FileHandle:close return FileTextT end local FileText = FileText

-- Find the length of a file --  filename: file name -- returns --  len: length of file --  asserts on error local function FileSize(filename) local fh = assert(io.open(filename, "rb")) local len = assert(fh:seek("end")) fh:close return len end

-- Actualy find the FileSize. local function PrintFileSize(FileName) if FileExists(FileName) then return FileSize(RootPath..FileName) end end

-- Returns if the file exists. function FileExists(FileName) local FileList = ReturnFiles for i=1, #FileList do     ReadFN = FileList[i] if ReadFN == FileName then return true end end return false end local FileExists = FileExists

-- Returns if the user exists. function UserExists(UserName) local UserList = FileText(UserFileDir) for i=1, #UserList do     ReadFN = UserList[i] if ReadFN == UserName then return true end end return false end

-- Used to run the file. function RunFile(FileName, ParT) if FileExists(FileName) then local TempFunction, Errors = loadfile(RootPath..FileName) if TempFunction == nil then print("Compile Error: ".. Errors) return -1, Errors end Success, Errors = pcall(TempFunction, ParT) if(Success==false) then return -2, Errors end return 1, "Ok" end return -3, "File Not Found" end local RunFile = RunFile FileRun = RunFile

-- string.find("Hello Lua user", "Lua")

-- Used to create a file FileName, which is returned by this function. local function NewFile(FileName) if FileName == nil then print("Usage: FileNew FileName") return end local DirHandle = io.open(RootPath..DirFile, "a") DirHandle:write(FileName,"\n") DirHandle:close local File = io.open(RootPath..FileName, "w") return File end local NewFile = NewFile FileNew = NewFile

-- Used to edit Lua Scripts. function FileEdit(FileName) local TextTable = FileText(FileName) local running = true local FActionT = { "Override", "View", "End" }  while running do      print("Editing "..FileName..", "..(#TextTable).." Lines") local FAnswer = io.read if FAnswer == "" then PrintTable(FActionT) elseif FAnswer == FActionT[1] then print("Line To Edit:") local LineToEdit = tonumber(io.read) print("Line Text: "..tostring(TextTable[LineToEdit])) print("Text to replace with:") local ReplaceText = io.read TextTable[LineToEdit] = ReplaceText elseif FAnswer == FActionT[2] then print("Line To View:") local LineToEdit = tonumber(io.read) print("Line Text: "..tostring(TextTable[LineToEdit])) elseif FAnswer == "End" then print("Now Saving..") running = false end end local FileHandle = io.open(RootPath..FileName, "w") for i=1, #TextTable do     clear print(((i/#TextTable)*100).."% ("..i.." out of "..(#TextTable).." lines)...") FileHandle:write(TextTable[i].."\n") end FileHandle:close end

FilePrompt = FileEdit

-- Clears the DirFile. Returns true. local function ClearDirFile local DirHandle = io.open(RootPath..DirFile, "w") DirHandle:close return true end

-- Used by RemoveFile to remove FileName from DirFile. -- Returns the updated FileList (NFileList). local function RemoveFileFromList(FileName) local FileList = ReturnFiles local NFileList = { }  local ReadFN = "" local ToNFiLi = 0 local IsRemoved = 0 for i=1, #FileList do     ReadFN = FileList[i] -- print("File Found is "..tostring(ReadFN == FileName)) -- print(ReadFN,FileName) if ReadFN == FileName then IsRemoved = 1 elseif IsRemoved==1 then ToNFiLi = (i-1) NFileList[ToNFiLi] = FileList[i] else NFileList[i] = FileList[i] end end return NFileList end

-- Removes the file FileName, returning true. local function RemoveFile(FileName) local NFLi = RemoveFileFromList(FileName) local DirHandle = io.open(RootPath..DirFile, "w") for i=1, #NFLi do     DirHandle:write(NFLi[i],"\n") end DirHandle:close local File = os.remove(RootPath..FileName) return true end

-- The FileTest. function Test print("NewFile") File = NewFile("FFile") File:close PrintTable(ReturnFiles)

print("NewFile") File = NewFile("Tag") File:close PrintTable(ReturnFiles)

print("RemoveFile") RemoveFile("FFile") PrintTable(ReturnFiles)

print("RemoveFile") RemoveFile("Tag") PrintTable(ReturnFiles) end

-- Command Prompt function CommandPrompt print("Command Prompt Started") -- Main loop while Running do     print(path..">") Answer = io.read local Par = 0 AnsT = { }     for word in string.gmatch(Answer, "%a+") do         Par = Par + 1 AnsT[Par] = word end if AnsT[1] == TAction[1] then Test elseif AnsT[1] == TAction[2] then FileHandle=NewFile(AnsT[2]) FileHandle:close FilePrompt(AnsT[2]) elseif AnsT[1] == TAction[3] then RemoveFile(AnsT[2]) elseif AnsT[1] == TAction[4] then FilePrompt(AnsT[2]) elseif AnsT[1] == TAction[5] then OSEnv elseif AnsT[1] == TAction[7] then SignIn(AnsT[2],AnsT[3]) elseif(AnsT[1] == "Clear")then clear elseif(AnsT[1]=="Exit")or(AnsT[1]=="Shutdown") then Shutdown elseif(AnsT[1]=="Kill")then Shutdown os.exit(Crash) elseif AnsT[1] == "Actions" then PrintActions elseif Answer == "" then PrintActions else ErrorType = RunFile(AnsT[1], AnsT) if(ErrorType==3)then print("No file or action named "..(AnsT[1]).." exists") end end end end

- -- End of Functions -- -

-- Action Table

TAction = { "FileTest","FileNew","FileRemove","FileEdit","OSEnv","Lua","SignIn"

} local TAction = TAction clear

print("TagSS "..(TagSSVersion))

-- Load a Custom Startup (New in Preview R2.03) RunFile("Startup", nil)

local Error, FailCode = pcall(CommandPrompt)

print("Press Enter to continue...") io.read