2015-08-25 17:42:23 +02:00
|
|
|
local tArgs = {...}
|
|
|
|
local loading = {"|","/","-","\\","|","/","-","\\"}
|
2015-08-30 02:21:05 +02:00
|
|
|
local server = "http://sertex.esy.es/"
|
2015-08-25 17:42:23 +02:00
|
|
|
local sendTo
|
2015-08-19 11:45:35 +02:00
|
|
|
|
2015-08-29 16:03:37 +02:00
|
|
|
if not sPhone then
|
|
|
|
printError("This app is for sPhone")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2015-08-25 17:42:23 +02:00
|
|
|
--check if the server is down
|
|
|
|
local isServerUp = http.get(server.."/status.php").readAll()
|
|
|
|
if isServerUp ~= "true" then
|
|
|
|
sPhone.winOk("The service is","currently down!", colors.lime, colors.green, colors.white, colors.lime)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
term.setBackgroundColor(colors.white)
|
|
|
|
term.clear()
|
|
|
|
term.setCursorPos(1,1)
|
|
|
|
term.setTextColor(colors.black)
|
|
|
|
print("sPhone SMS")
|
2015-08-25 18:03:12 +02:00
|
|
|
if not fs.exists("/.sPhone/config/.sIDpw") then
|
|
|
|
sPhone.winOk("Sertex ID not set!","Run sID!", colors.lime, colors.green, colors.white, colors.lime)
|
|
|
|
return
|
|
|
|
end
|
2015-08-25 17:57:33 +02:00
|
|
|
f = fs.open("/.sPhone/config/username", "r")
|
|
|
|
local user = f.readLine()
|
|
|
|
f.close()
|
|
|
|
f = fs.open("/.sPhone/config/.sIDpw", "r")
|
2015-10-05 17:26:48 +02:00
|
|
|
local pass = f.readLine()
|
2015-08-25 17:57:33 +02:00
|
|
|
f.close()
|
2015-10-05 17:43:02 +02:00
|
|
|
local head = "user="..user.."&password="..pass.."&hashed=true"
|
2015-08-25 17:42:23 +02:00
|
|
|
http.request(server.."login.php",head)
|
|
|
|
local update = os.startTimer(0.15)
|
|
|
|
local pos = 1
|
|
|
|
while true do
|
|
|
|
local _,y = term.getCursorPos()
|
|
|
|
term.clearLine()
|
|
|
|
term.setCursorPos(1,y)
|
|
|
|
term.write("Loading "..loading[pos])
|
|
|
|
local e = {os.pullEvent()}
|
|
|
|
if e[1] == "timer" and e[2] == update then
|
|
|
|
pos = pos + 1
|
|
|
|
if pos > #loading then pos = 1 end
|
|
|
|
update = os.startTimer(0.15)
|
|
|
|
elseif e[1] == "http_success" then
|
|
|
|
if e[3].readAll() == "true" then
|
|
|
|
if not tArgs[1] then
|
|
|
|
term.clearLine()
|
|
|
|
term.setCursorPos(1,y)
|
2015-11-01 18:17:28 +01:00
|
|
|
print("Leave blank to get unread chat\n")
|
2015-08-25 17:42:23 +02:00
|
|
|
write("Send To: ")
|
|
|
|
sendTo = read()
|
|
|
|
else
|
|
|
|
sendTo = tArgs[1]
|
|
|
|
end
|
|
|
|
local doesUserExist = http.post(server.."exists.php", "user="..sendTo).readAll()
|
|
|
|
if doesUserExist ~= "true" then
|
|
|
|
sPhone.winOk(sendTo.." does","not exist!", colors.lime, colors.green, colors.white, colors.lime)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
break
|
|
|
|
else
|
|
|
|
sPhone.winOk("Wrong Username","or Password", colors.lime, colors.green, colors.white, colors.lime)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
elseif e[1] == "http_failure" then
|
|
|
|
term.clearLine()
|
|
|
|
term.setCursorPos(1,y)
|
|
|
|
sPhone.winOk("Connection lost!","Check internet!", colors.lime, colors.green, colors.white, colors.lime)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
term.clear()
|
|
|
|
local x,y = term.getSize()
|
|
|
|
local mainTerm = term.current()
|
|
|
|
local displayWin = window.create(term.native(),1,1,x,y-1,true)
|
|
|
|
local readWin = window.create(term.native(),1,y,x,y,true)
|
|
|
|
local ntv = term.redirect(mainTerm)
|
|
|
|
local x,y = 1,1
|
|
|
|
local mx,my = displayWin.getSize()
|
|
|
|
local function readMsg()
|
|
|
|
term.redirect(readWin)
|
2015-11-02 21:44:31 +01:00
|
|
|
while true do
|
|
|
|
term.setCursorBlink(true)
|
|
|
|
term.setBackgroundColor(colors.green)
|
|
|
|
term.setTextColor(colors.white)
|
|
|
|
term.clear()
|
|
|
|
term.setCursorPos(1,1)
|
|
|
|
if sendTo ~= "" then
|
|
|
|
term.write("Send: ")
|
|
|
|
local msg = read()
|
|
|
|
local msg = base64.encode(msg)
|
|
|
|
term.clear()
|
|
|
|
if base64.decode(msg) == "/logout" then
|
|
|
|
term.redirect(mainTerm)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if msg ~= "" then
|
|
|
|
local pos = 1
|
|
|
|
local update = os.startTimer(0.15)
|
|
|
|
http.request(server.."send.php","user="..user.."&password="..pass.."&message="..msg.."&to="..sendTo.."&hashed=true")
|
|
|
|
while true do
|
2015-08-25 17:42:23 +02:00
|
|
|
term.clear()
|
|
|
|
term.setCursorPos(1,1)
|
2015-11-02 21:44:31 +01:00
|
|
|
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")
|
2015-11-02 21:45:45 +01:00
|
|
|
term.setCursorBlink(false)
|
2015-11-02 21:44:31 +01:00
|
|
|
while true do
|
|
|
|
local _, k = os.pullEvent("key")
|
|
|
|
if k == keys.enter then
|
|
|
|
term.redirect(mainTerm)
|
2015-08-25 17:42:23 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
2015-11-02 21:44:31 +01:00
|
|
|
end
|
|
|
|
end
|
2015-08-25 17:42:23 +02:00
|
|
|
end
|
|
|
|
local function recMsg()
|
|
|
|
displayWin.setBackgroundColor(colors.white)
|
|
|
|
displayWin.setTextColor(colors.black)
|
2015-08-31 17:34:33 +02:00
|
|
|
displayWin.clear()
|
2015-08-25 17:42:23 +02:00
|
|
|
local function printMsg(msg)
|
2015-08-31 17:34:33 +02:00
|
|
|
displayWin.setCursorBlink(false)
|
|
|
|
displayWin.setCursorPos(1,y)
|
|
|
|
local nTerm = term.current()
|
|
|
|
term.redirect(displayWin)
|
|
|
|
print(msg)
|
|
|
|
term.redirect(nTerm)
|
2015-10-10 14:22:27 +02:00
|
|
|
if y == my then
|
|
|
|
displayWin.scroll(1)
|
|
|
|
else
|
|
|
|
if #msg < 26 then
|
|
|
|
y = y + 1
|
|
|
|
else
|
|
|
|
y = y + 2
|
|
|
|
end
|
|
|
|
end
|
2015-11-01 18:53:25 +01:00
|
|
|
end
|
2015-11-02 21:44:31 +01:00
|
|
|
if sendTo ~= "" then
|
|
|
|
printMsg("Type /logout to exit")
|
2015-11-02 21:45:45 +01:00
|
|
|
else
|
|
|
|
printMsg("All messages")
|
2015-11-02 21:44:31 +01:00
|
|
|
end
|
2015-08-25 17:42:23 +02:00
|
|
|
while true do
|
|
|
|
stream = http.post(server.."update.php",head)
|
|
|
|
newMessages = {}
|
|
|
|
line = stream.readLine()
|
|
|
|
repeat
|
|
|
|
table.insert(newMessages,line)
|
|
|
|
line = stream.readLine()
|
|
|
|
until not line
|
|
|
|
for i,v in pairs(newMessages) do
|
|
|
|
t = textutils.unserialize(v)
|
|
|
|
if t then
|
|
|
|
date = t["date"]
|
2015-09-26 21:30:49 +02:00
|
|
|
mesg = "<"..t["from"].."> "..base64.decode(t["message"])
|
2015-08-25 17:42:23 +02:00
|
|
|
printMsg(mesg)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
parallel.waitForAny(readMsg,recMsg)
|