Update sms.lua

This commit is contained in:
Ale32bit 2015-11-02 21:44:31 +01:00
parent d9c61565a3
commit fd265bb5a4

View file

@ -81,48 +81,59 @@ local x,y = 1,1
local mx,my = displayWin.getSize() local mx,my = displayWin.getSize()
local function readMsg() local function readMsg()
term.redirect(readWin) term.redirect(readWin)
while true do while true do
term.setCursorBlink(true) term.setCursorBlink(true)
term.setBackgroundColor(colors.green) term.setBackgroundColor(colors.green)
term.setTextColor(colors.white) term.setTextColor(colors.white)
term.clear() term.clear()
term.setCursorPos(1,1) term.setCursorPos(1,1)
term.write("Send: ") if sendTo ~= "" then
local msg = read() term.write("Send: ")
local msg = base64.encode(msg) local msg = read()
term.clear() local msg = base64.encode(msg)
if base64.decode(msg) == "/logout" then term.clear()
term.redirect(mainTerm) if base64.decode(msg) == "/logout" then
return term.redirect(mainTerm)
end return
if msg ~= "" then end
local pos = 1 if msg ~= "" then
local update = os.startTimer(0.15) local pos = 1
http.request(server.."send.php","user="..user.."&password="..pass.."&message="..msg.."&to="..sendTo.."&hashed=true") local update = os.startTimer(0.15)
while true do http.request(server.."send.php","user="..user.."&password="..pass.."&message="..msg.."&to="..sendTo.."&hashed=true")
term.clear() while true do
term.setCursorPos(1,1)
term.write("Sending "..loading[pos])
e = {os.pullEvent()}
if e[1] == "timer" and e[2] == update then
update = os.startTimer(0.15)
pos = pos + 1
if pos > #loading then pos = 1 end
elseif e[1] == "http_success" then
displayWin.setCursorPos(1,y)
displayWin.write("<You> "..base64.decode(msg))
if y == my then displayWin.scroll(1) else y = y + 1 end
break
elseif e[1] == "http_failure" then
term.redirect(ntv)
term.clear() term.clear()
term.setCursorPos(1,1) term.setCursorPos(1,1)
sPhone.winOk("Disconnected",nil, colors.lime, colors.green, colors.white, colors.lime) term.write("Sending "..loading[pos])
e = {os.pullEvent()}
if e[1] == "timer" and e[2] == update then
update = os.startTimer(0.15)
pos = pos + 1
if pos > #loading then pos = 1 end
elseif e[1] == "http_success" then
displayWin.setCursorPos(1,y)
displayWin.write("<You> "..base64.decode(msg))
if y == my then displayWin.scroll(1) else y = y + 1 end
break
elseif e[1] == "http_failure" then
term.redirect(ntv)
term.clear()
term.setCursorPos(1,1)
sPhone.winOk("Disconnected",nil, colors.lime, colors.green, colors.white, colors.lime)
return
end
end
end
else
term.write("Press enter to exit")
while true do
local _, k = os.pullEvent("key")
if k == keys.enter then
term.redirect(mainTerm)
return return
end end
end end
end end
end end
end end
local function recMsg() local function recMsg()
displayWin.setBackgroundColor(colors.white) displayWin.setBackgroundColor(colors.white)
@ -145,7 +156,9 @@ local function recMsg()
end end
end end
end end
printMsg("Type /logout to exit") if sendTo ~= "" then
printMsg("Type /logout to exit")
end
while true do while true do
stream = http.post(server.."update.php",head) stream = http.post(server.."update.php",head)
newMessages = {} newMessages = {}