i am trying to prevent users to ctrl+t my program and i already done the:
Spoiler
os.pullEvent = os.pullEventRaw
184:attempt to compare nil with number
Here's the code i am working on:
Spoiler
os.loadAPI("rodos/apis/defaults/crypt")
shell.run("rm rodos/.data/passwords/admin/rod")
shell.run("cp rodos/.data/passwords/rod rodos/.data/passwords/admin/rod")
--local pullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
function clear(clx, cly)
term.clear()
term.setCursorPos(0, 0)
end
function cprint(txt)
x, y = term.getSize()
half = x/2
textlenght = string.len(txt)
div = textlenght/2
pos = half-div
cx, cy = term.getCursorPos()
term.setCursorPos(pos, cy)
print(txt)
end
function drawvertical(dx, dy, rep)
count = 0
repeat
term.setCursorPos(dx, dy)
print("|")
count = count + 1
dy = dy + 1
until count == rep
end
function read( _sReplaceChar, _tHistory )
term.setCursorBlink( true )
local sLine = ""
local nHistoryPos = nil
local nPos = 0
if _sReplaceChar then
_sReplaceChar = string.sub( _sReplaceChar, 1, 1 )
end
local w, h = term.getSize()
local sx, sy = term.getCursorPos()
local function redraw( _sCustomReplaceChar )
local nScroll = 0
if sx + nPos >= w then
nScroll = (sx + nPos) - w
end
term.setCursorPos( sx, sy )
local sReplace = _sCustomReplaceChar or _sReplaceChar
if sReplace then
term.write( string.rep(sReplace, string.len(sLine) - nScroll) )
else
term.write( string.sub( sLine, nScroll + 1 ) )
end
term.setCursorPos( sx + nPos - nScroll, sy )
end
while true do
local sEvent, param = os.pullEvent()
if sEvent == "char" then
if #sLine < 10 then
sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
nPos = nPos + 1
redraw()
end
elseif sEvent == "key" then
if param == keys.enter then
-- Enter
break
elseif param == keys.left then
-- Left
if nPos > 0 then
nPos = nPos - 1
redraw()
end
elseif param == keys.right then
-- Right
if nPos < string.len(sLine) then
nPos = nPos + 1
redraw()
end
elseif param == keys.up or param == keys.down then
-- Up or down
if _tHistory then
redraw(" ");
if param == keys.up then
-- Up
if nHistoryPos == nil then
if #_tHistory > 0 then
nHistoryPos = #_tHistory
end
elseif nHistoryPos > 1 then
nHistoryPos = nHistoryPos - 1
end
else
-- Down
if nHistoryPos == #_tHistory then
nHistoryPos = nil
elseif nHistoryPos ~= nil then
nHistoryPos = nHistoryPos + 1
end
end
if nHistoryPos then
sLine = _tHistory[nHistoryPos]
nPos = string.len( sLine )
else
sLine = ""
nPos = 0
end
redraw()
end
elseif param == keys.backspace then
-- Backspace
if nPos > 0 then
redraw(" ");
sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 )
nPos = nPos - 1
redraw()
end
elseif param == keys.home then
-- Home
nPos = 0
redraw()
elseif param == keys.delete then
if nPos < string.len(sLine) then
redraw(" ");
sLine = string.sub( sLine, 1, nPos ) .. string.sub( sLine, nPos + 2 )
redraw()
end
elseif param == keys["end"] then
-- End
nPos = string.len(sLine)
redraw()
end
end
end
term.setCursorBlink( false )
term.setCursorPos( w + 1, sy )
print()
return sLine
end
function main(bollean, error)
term.setBackgroundColor(colors.white)
clear()
start = paintutils.loadImage("rodos/images/start")
paintutils.drawImage(start, 0 , 0)
term.setCursorPos(4,4)
cprint("RoDOS ALFA")
term.setCursorPos(14, 14)
cprint("Copyright (c) 2014")
term.setBackgroundColor(colors.orange)
term.setCursorPos(15, 8)
print("login")
term.setCursorPos(27, 8)
print("register")
if bollean == true then
term.setBackgroundColor(colors.red)
term.setCursorPos(5,6)
cprint(error)
sleep(2)
main()
elseif bollean == false then
end
while true do
event, button, xPos, yPos = os.pullEvent("mouse_click")
if xPos >= 15 and xPos <= 19 and yPos == 8 then
login()
elseif xPos >= 27 and xPos <= 35 and yPos == 8 then
register(false)
end
end
end
function login(account)
term.setBackgroundColor(colors.white)
clear()
paintutils.drawImage(start, 0 , 0)
term.setCursorPos(4,4)
cprint("Login")
term.setCursorPos(7,7)
term.setBackgroundColor(colors.orange)
cprint("Username: ")
term.setCursorPos(7,9)
cprint("Password: ")
term.setCursorPos(24,7)
user = read()
term.setCursorPos(24, 9)
pass = read("*")
if account == "admin" then
if fs.exists("rodos/.data/passwords/admin/"..user) then
pfile = fs.open("rodos/.data/passwords/admin/"..user, "r")
passd = pfile.readAll()
pfile.close()
passd = crypt.decrypt(passd, "123")
end
-- print(user.." and "..passd)
if passd == pass then
register(true)
elseif fs.exists("rodos/.data/passwords/admin/"..user) == false then
main(true, "Not admin or inexistent user")
elseif passd ~= pass then
main(true, "Incorrect password")
end
elseif account ~= "admin" then
if fs.exists("rodos/.data/passwords/"..user) then
pfile = fs.open("rodos/.data/passwords/"..user, "r")
passd = pfile.readAll()
pfile.close()
passd = crypt.decrypt(passd, "123")
end
if passd == pass then
term.setBackgroundColor(colors.black)
clear()
os.exit()
elseif not fs.exists("rodos/.data/passwords/"..user) then
main(true, "Inexistent username")
elseif passd ~= pass then
main(true, "Incorrect password")
end
end
end
function register(bollean)
if bollean == false then
login("admin")
elseif bollean == true then
end
term.setBackgroundColor(colors.white)
clear()
paintutils.drawImage(start, 0 , 0)
term.setCursorPos(4,4)
cprint("Register")
term.setCursorPos(7,7)
term.setBackgroundColor(colors.orange)
cprint("Username: ")
term.setCursorPos(7,9)
cprint("Password: ")
term.setCursorPos(24,11)
cprint("Confirm ")
cprint("Password: ")
term.setCursorPos(24,7)
user = read()
term.setCursorPos(24, 9)
pass = read("*")
term.setCursorPos(24, 12)
passconf = read("*")
if fs.exists("rodos/.data/passwords/"..user) then
main(true, "Unavailable username")
elseif pass ~= passconf then
main(true, "Passwords dont match")
elseif pass == passconf then
pass = crypt.encrypt(pass, "123")
file = fs.open("rodos/.data/passwords/"..user, "w")
file.write(pass)
file.close()
main(false)
end
end
main()