Start of cleanup

This commit is contained in:
Alessandro Proto 2024-08-20 18:19:07 +02:00
parent df43059cd2
commit c75639eb2d
11 changed files with 348 additions and 334 deletions

View file

@ -1 +0,0 @@
setfenv(loadstring(http.get("https://raw.githubusercontent.com/SertexTeam/sPhone/master/src/installer.lua").readAll()),getfenv())()

17
install.lua Normal file
View file

@ -0,0 +1,17 @@
local h, err = http.get("https://git.alexdevs.me/Legacy-CC/sPhone/raw/branch/master/src/installer.lua")
if not h then
error(err, 0)
end
local content = h.readAll()
h.close()
local func, err = load(content, "@installer.lua", "t", _ENV)
if not func then
error(err, 0)
end
local ok, err = pcall(func)
if not ok then
error(err, 0)
end

View file

@ -5,22 +5,22 @@ local ind = {}
if not fs.exists(spkList) then
config.list("/.sPhone/config/spklist")
end
for k,v in pairs(config.list(spkList)) do
table.insert(apps,{
for k, v in pairs(config.list(spkList)) do
table.insert(apps, {
id = k,
name = v,
})
end
for k,v in ipairs(apps) do
local hid = config.read(dir..v.id.."/.spk","hidden")
for k, v in ipairs(apps) do
local hid = config.read(dir .. v.id .. "/.spk", "hidden")
if hid then
table.remove(apps,k)
table.remove(apps, k)
end
end
for k,v in ipairs(apps) do
ind[ v.id ] = v.name
for k, v in ipairs(apps) do
ind[v.id] = v.name
end
sPhone.launch(sPhone.list(nil,{
sPhone.launch(sPhone.list(nil, {
list = ind,
pairs = true,
title = " Apps"

View file

@ -3,7 +3,7 @@ local users
local function clear()
term.setBackgroundColor(colors.white)
term.clear()
term.setCursorPos(1,1)
term.setCursorPos(1, 1)
term.setTextColor(colors.black)
end
local function header(aR, xChar)
@ -11,15 +11,15 @@ local function header(aR, xChar)
local xChar = "X"
end
local w, h = term.getSize()
paintutils.drawLine(1,1,w,1,colors.brown)
paintutils.drawLine(1, 1, w, 1, colors.brown)
term.setTextColor(colors.white)
if aR then
term.setCursorPos(2,1)
term.setCursorPos(2, 1)
write("Add")
term.setCursorPos(7,1)
term.setCursorPos(7, 1)
write("Remove")
end
term.setCursorPos(w,1)
term.setCursorPos(w, 1)
write(xChar)
end
@ -39,11 +39,11 @@ local function add()
header(false, "<")
term.setBackgroundColor(colors.white)
term.setTextColor(colors.black)
term.setCursorPos(2,3)
visum.align("center", " Name",false,3)
term.setCursorPos(2,5)
term.setCursorPos(2, 3)
visum.align("center", " Name", false, 3)
term.setCursorPos(2, 5)
term.setCursorBlink(true)
local e,_,x,y = os.pullEvent()
local e, _, x, y = os.pullEvent()
if e == "mouse_click" then
if y == 1 and x == w then
return
@ -51,12 +51,12 @@ local function add()
end
addUser = read()
term.setCursorBlink(false)
local check = http.post("http://sertex.x10.bz/exists.php","user="..addUser).readLine()
local check = http.post("http://sertex.x10.bz/exists.php", "user=" .. addUser).readLine()
if check == "true" then
table.insert(users,add)
table.insert(users, add)
local f = fs.open("/.sPhone/config/buddies", "a")
f.write(addUser.."\n")
f.write(addUser .. "\n")
f.close()
sPhone.winOk("Added!")
else
@ -70,22 +70,22 @@ local function remove()
header(false, "<")
term.setBackgroundColor(colors.white)
term.setTextColor(colors.black)
term.setCursorPos(1,2)
term.setCursorPos(1, 2)
for i = 1, #users do
print(users[i])
end
_,_,x,y = os.pullEvent("mouse_click")
_, _, x, y = os.pullEvent("mouse_click")
if y == 1 and x == w then
return
elseif y ~= 1 then
userToRemove = users[y-1]
userToRemove = users[y - 1]
if userToRemove then
if sPhone.yesNo("Remove "..userToRemove.."?",nil) then
if sPhone.yesNo("Remove " .. userToRemove .. "?", nil) then
local f = fs.open("/.sPhone/config/buddies", "w")
oldUsers = users
users = {}
for i = 1, #oldUsers do
if oldUsers[i] ~= oldUsers[y-1] then
if oldUsers[i] ~= oldUsers[y - 1] then
f.writeLine(oldUsers[i])
table.insert(users, oldUsers[i])
end
@ -105,13 +105,13 @@ while true do
header(true, "X")
term.setBackgroundColor(colors.white)
term.setTextColor(colors.black)
for i = 1, #users do
print(users[i])
end
end
redraw()
local _,_,x,y = os.pullEvent("mouse_click")
local _, _, x, y = os.pullEvent("mouse_click")
if y == 1 then
if x >= 2 and x <= 4 then
add()
@ -121,8 +121,8 @@ while true do
return
end
else
if users[y-1] then
shell.run("/.sPhone/apps/sms", users[y-1])
if users[y - 1] then
shell.run("/.sPhone/apps/sms", users[y - 1])
end
end
end

View file

@ -1,6 +1,6 @@
term.setBackgroundColor(sPhone.theme["backgroundColor"])
term.clear()
term.setCursorPos(1,1)
term.setCursorPos(1, 1)
term.setTextColor(sPhone.theme["text"])
sPhone.header("RedNet Chat")
term.setBackgroundColor(sPhone.theme["backgroundColor"])
@ -13,5 +13,6 @@ if not peripheral.isPresent("back") or not peripheral.getType("back") == "modem"
return
end
write("Host: ")
local h = read() term.setCursorPos(2,6)
local h = read()
term.setCursorPos(2, 6)
shell.run("/rom/programs/rednet/chat", "join", h, sPhone.user)

View file

@ -3,7 +3,7 @@ if not x then
x, y, z = "?", "?", "?"
end
if tonumber(x) then
sPhone.winOk("X Y Z", math.ceil(x).." "..math.ceil(y).." "..math.ceil(z))
sPhone.winOk("X Y Z", math.ceil(x) .. " " .. math.ceil(y) .. " " .. math.ceil(z))
else
sPhone.winOk("X Y Z","? ? ?")
sPhone.winOk("X Y Z", "? ? ?")
end

View file

@ -1,131 +1,129 @@
local buttonsInHome = {
{ "sPhone.header", 23, 1, 25, 1, sPhone.theme["header"], sPhone.theme["headerText"], "vvv" },
{ "sPhone.appsButton", 12, 20, 14, 20, sPhone.theme["backgroundColor"], sPhone.theme["header"], "===" },
{ "sPhone.shell", 2, 3, 8, 5, colors.black, colors.yellow, " Shell", 2 },
{ "sPhone.lock", 19, 3, 24, 5, colors.lightGray, colors.black, " Lock", 2 },
{ "sPhone.chat", 11, 3, 16, 5, colors.black, colors.white, " Chat", 2 },
{ "sPhone.gps", 11, 7, 15, 9, colors.red, colors.black, " GPS", 2 },
{ "sPhone.info", 18, 7, 23, 9, colors.lightGray, colors.black, " Info", 2 },
{ "sPhone.store", 2, 7, 8, 9, colors.orange, colors.white, " Store", 2 },
}
local buttonsInHome = {
{"sPhone.header",23,1,25,1,sPhone.theme["header"],sPhone.theme["headerText"],"vvv"},
{"sPhone.appsButton",12,20,14,20,sPhone.theme["backgroundColor"],sPhone.theme["header"],"==="},
{"sPhone.shell",2,3,8,5,colors.black,colors.yellow," Shell",2},
{"sPhone.lock",19,3,24,5,colors.lightGray,colors.black," Lock",2},
{"sPhone.chat",11,3,16,5,colors.black,colors.white," Chat",2},
{"sPhone.gps",11,7,15,9,colors.red,colors.black," GPS",2},
{"sPhone.info",18,7,23,9,colors.lightGray,colors.black," Info",2},
{"sPhone.store",2,7,8,9,colors.orange,colors.white," Store",2},
}
local appsOnHome = {
["sPhone.shell"] = "/.sPhone/apps/shell",
["sPhone.chat"] = "/.sPhone/apps/chat",
["sPhone.gps"] = "/.sPhone/apps/gps",
["sPhone.info"] = "/.sPhone/apps/system/info",
["sPhone.store"] = "/.sPhone/apps/store",
["sPhone.appsButton"] = "/.sPhone/apps/appList",
}
local function clear()
term.setBackgroundColor(sPhone.theme["backgroundColor"])
term.clear()
term.setCursorPos(1,1)
term.setTextColor(sPhone.theme["text"])
local appsOnHome = {
["sPhone.shell"] = "/.sPhone/apps/shell",
["sPhone.chat"] = "/.sPhone/apps/chat",
["sPhone.gps"] = "/.sPhone/apps/gps",
["sPhone.info"] = "/.sPhone/apps/system/info",
["sPhone.store"] = "/.sPhone/apps/store",
["sPhone.appsButton"] = "/.sPhone/apps/appList",
}
local function clear()
term.setBackgroundColor(sPhone.theme["backgroundColor"])
term.clear()
term.setCursorPos(1, 1)
term.setTextColor(sPhone.theme["text"])
end
local function drawHome()
local function box(x, y, text, bg, colorText, page)
graphics.box(x, y, x + 1 + #text, y + 2, bg)
term.setCursorPos(x + 1, y + 1)
term.setTextColor(colorText)
write(text)
end
clear()
visum.buttons(buttonsInHome, true)
local w, h = term.getSize()
paintutils.drawLine(1, 1, w, 1, sPhone.theme["header"])
term.setTextColor(sPhone.theme["headerText"])
visum.align("right", "vvv ", false, 1)
end
local function footerMenu()
sPhone.isFooterMenuOpen = true
function redraw()
drawHome()
local w, h = term.getSize()
graphics.box(1, 2, w, 4, sPhone.theme["header"])
term.setTextColor(sPhone.theme["headerText"])
term.setBackgroundColor(sPhone.theme["header"])
visum.align("right", "^^^ ", false, 1)
visum.align("right", "Reboot ", false, 3)
term.setCursorPos(11, 3)
write("Settings")
term.setCursorPos(2, 3)
write("Shutdown")
end
local function drawHome()
local function box(x,y,text,bg,colorText,page)
graphics.box(x,y,x+1+#text,y+2,bg)
term.setCursorPos(x+1,y+1)
term.setTextColor(colorText)
write(text)
end
clear()
visum.buttons(buttonsInHome,true)
local w, h = term.getSize()
paintutils.drawLine(1,1,w,1, sPhone.theme["header"])
term.setTextColor(sPhone.theme["headerText"])
visum.align("right","vvv ",false,1)
end
local function footerMenu()
sPhone.isFooterMenuOpen = true
function redraw()
while true do
term.redirect(sPhone.mainTerm)
drawHome()
redraw()
local _, _, x, y = os.pullEvent("mouse_click")
if y == 3 then
if x > 1 and x < 10 then
os.shutdown()
sPhone.inHome = true
elseif x > 19 and x < 26 then
os.reboot()
sPhone.inHome = true
elseif x > 10 and x < 19 then
sPhone.inHome = false
shell.run("/.sPhone/apps/system/settings")
sPhone.inHome = true
drawHome()
local w, h = term.getSize()
graphics.box(1,2,w,4,sPhone.theme["header"])
term.setTextColor(sPhone.theme["headerText"])
term.setBackgroundColor(sPhone.theme["header"])
visum.align("right","^^^ ",false,1)
visum.align("right", "Reboot ",false,3)
term.setCursorPos(11,3)
write("Settings")
term.setCursorPos(2,3)
write("Shutdown")
end
while true do
term.redirect(sPhone.mainTerm)
drawHome()
redraw()
local _,_,x,y = os.pullEvent("mouse_click")
if y == 3 then
if x > 1 and x < 10 then
os.shutdown()
sPhone.inHome = true
elseif x > 19 and x < 26 then
os.reboot()
sPhone.inHome = true
elseif x > 10 and x < 19 then
sPhone.inHome = false
shell.run("/.sPhone/apps/system/settings")
sPhone.inHome = true
drawHome()
end
elseif y == 1 then
if x < 26 and x > 22 then
sPhone.isFooterMenuOpen = false
return
end
end
elseif y == 1 then
if x < 26 and x > 22 then
sPhone.isFooterMenuOpen = false
return
end
end
local function buttonHomeLoop()
while true do
drawHome()
term.setCursorBlink(false)
local autoLockTimer = os.startTimer(10)
local id = visum.buttons(buttonsInHome)
if id == "sPhone.header" then
footerMenu()
elseif id == "sPhone.lock" then
sPhone.inHome = false
sPhone.login()
sPhone.inHome = true
elseif appsOnHome[id] then
sPhone.inHome = false
os.pullEvent = os.oldPullEvent
shell.run(appsOnHome[id])
os.pullEvent = os.pullEventRaw
sPhone.inHome = true
end
end
end
end
local function buttonHomeLoop()
while true do
drawHome()
term.setCursorBlink(false)
local autoLockTimer = os.startTimer(10)
local id = visum.buttons(buttonsInHome)
if id == "sPhone.header" then
footerMenu()
elseif id == "sPhone.lock" then
sPhone.inHome = false
sPhone.login()
sPhone.inHome = true
elseif appsOnHome[id] then
sPhone.inHome = false
os.pullEvent = os.oldPullEvent
shell.run(appsOnHome[id])
os.pullEvent = os.pullEventRaw
sPhone.inHome = true
end
local function updateClock()
while true do
if sPhone.inHome then
term.setCursorPos(1,1)
term.setBackgroundColor(sPhone.theme["header"])
term.setTextColor(sPhone.theme["headerText"])
term.setCursorPos(1,1)
write(" ")
term.setCursorPos(1,1)
write(" "..textutils.formatTime(os.time(),true))
end
sleep(0)
end
end
sPhone.inHome = false
end
local function updateClock()
while true do
if sPhone.inHome then
term.setCursorPos(1, 1)
term.setBackgroundColor(sPhone.theme["header"])
term.setTextColor(sPhone.theme["headerText"])
term.setCursorPos(1, 1)
write(" ")
term.setCursorPos(1, 1)
write(" " .. textutils.formatTime(os.time(), true))
end
parallel.waitForAll(buttonHomeLoop, updateClock)
sleep(0)
end
end
parallel.waitForAll(buttonHomeLoop, updateClock)

View file

@ -1,5 +1,5 @@
local tArgs = {...}
local loading = {"|","/","-","\\","|","/","-","\\"}
local tArgs = { ... }
local loading = { "|", "/", "-", "\\", "|", "/", "-", "\\" }
local server = "http://sertex.x10.bz/"
local sendTo
@ -9,18 +9,18 @@ if not sPhone then
end
--check if the server is down
local isServerUp = http.get(server.."/status.php").readAll()
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)
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.setCursorPos(1, 1)
term.setTextColor(colors.black)
print("sPhone SMS")
if not fs.exists("/.sPhone/config/.sIDpw") then
sPhone.winOk("Sertex ID not set!","Run sID!", colors.lime, colors.green, colors.white, colors.lime)
sPhone.winOk("Sertex ID not set!", "Run sID!", colors.lime, colors.green, colors.white, colors.lime)
return
end
f = fs.open("/.sPhone/config/username", "r")
@ -29,67 +29,67 @@ f.close()
f = fs.open("/.sPhone/config/.sIDpw", "r")
local pass = f.readLine()
f.close()
local head = "user="..user.."&password="..pass.."&hashed=true"
http.request(server.."login.php",head)
local head = "user=" .. user .. "&password=" .. pass .. "&hashed=true"
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
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)
term.setCursorPos(1, y)
write("Send To: ")
sendTo = read()
else
sendTo = tArgs[1]
end
local doesUserExist = http.post(server.."exists.php", "user="..sendTo).readAll()
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)
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
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 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 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 x, y = 1, 1
local mx, my = displayWin.getSize()
local function readMsg()
term.redirect(readWin)
while true do
while true do
term.setCursorBlink(true)
term.setBackgroundColor(colors.green)
term.setTextColor(colors.white)
term.clear()
term.setCursorPos(1,1)
term.write("Send: ")
local msg = read()
local msg = base64.encode(msg)
term.clear()
term.clear()
term.setCursorPos(1, 1)
term.write("Send: ")
local msg = read()
local msg = base64.encode(msg)
term.clear()
if base64.decode(msg) == "/logout" then
term.redirect(mainTerm)
return
@ -97,60 +97,61 @@ local function readMsg()
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")
http.request(server .. "send.php",
"user=" .. user .. "&password=" .. pass .. "&message=" .. msg .. "&to=" .. sendTo .. "&hashed=true")
while true do
term.clear()
term.setCursorPos(1,1)
term.write("Sending "..loading[pos])
e = {os.pullEvent()}
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
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)
term.setCursorPos(1, 1)
sPhone.winOk("Disconnected", nil, colors.lime, colors.green, colors.white, colors.lime)
return
end
end
end
end
end
end
end
local function recMsg()
displayWin.setBackgroundColor(colors.white)
displayWin.setTextColor(colors.black)
displayWin.clear()
local function printMsg(msg)
displayWin.setCursorBlink(false)
displayWin.setCursorPos(1,y)
local nTerm = term.current()
term.redirect(displayWin)
print(msg)
term.redirect(nTerm)
if y == my then displayWin.scroll(1) else y = y + 1 end
end
local function printMsg(msg)
displayWin.setCursorBlink(false)
displayWin.setCursorPos(1, y)
local nTerm = term.current()
term.redirect(displayWin)
print(msg)
term.redirect(nTerm)
if y == my then displayWin.scroll(1) else y = y + 1 end
end
printMsg("Type /logout to exit")
while true do
stream = http.post(server.."update-new.php",head)
if stream then
local newMessages = textutils.unserialize(stream.readAll())
stream.close()
for i,v in pairs(newMessages) do
t = textutils.unserialize(v)
if t then
date = t["date"]
mesg = "<"..t["from"].."> "..base64.decode(t["message"])
printMsg(mesg)
end
end
end
end
while true do
stream = http.post(server .. "update-new.php", head)
if stream then
local newMessages = textutils.unserialize(stream.readAll())
stream.close()
for i, v in pairs(newMessages) do
t = textutils.unserialize(v)
if t then
date = t["date"]
mesg = "<" .. t["from"] .. "> " .. base64.decode(t["message"])
printMsg(mesg)
end
end
end
end
end
parallel.waitForAny(readMsg,recMsg)
parallel.waitForAny(readMsg, recMsg)

View file

@ -1,5 +1,5 @@
local tArgs = {...}
local loading = {"|","/","-","\\","|","/","-","\\"}
local tArgs = { ... }
local loading = { "|", "/", "-", "\\", "|", "/", "-", "\\" }
local server = "http://sertex.x10.bz/"
local sendTo
@ -9,18 +9,18 @@ if not sPhone then
end
--check if the server is down
local isServerUp = http.get(server.."/status.php").readAll()
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)
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.setCursorPos(1, 1)
term.setTextColor(colors.black)
print("sPhone SMS")
if not fs.exists("/.sPhone/config/.sIDpw") then
sPhone.winOk("Sertex ID not set!","Run sID!", colors.lime, colors.green, colors.white, colors.lime)
sPhone.winOk("Sertex ID not set!", "Run sID!", colors.lime, colors.green, colors.white, colors.lime)
return
end
f = fs.open("/.sPhone/config/username", "r")
@ -29,74 +29,74 @@ f.close()
f = fs.open("/.sPhone/config/.sIDpw", "r")
local pass = f.readLine()
f.close()
local head = "user="..user.."&password="..pass.."&hashed=true"
http.request(server.."login.php",head)
local head = "user=" .. user .. "&password=" .. pass .. "&hashed=true"
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
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)
term.setCursorPos(1, y)
print("Leave blank to get unread chat\n")
write("Send To: ")
sendTo = read()
else
sendTo = tArgs[1]
end
local doesUserExist = http.post(server.."exists.php", "user="..sendTo).readAll()
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)
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
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 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 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 x, y = 1, 1
local mx, my = displayWin.getSize()
local function printMsg(msg, save)
displayWin.setCursorBlink(false)
displayWin.setTextColor(colors.black)
local nTerm = term.current()
term.redirect(displayWin)
print(msg)
if save then
f = fs.open("/.sPhone/cache/sms/"..sendTo,"a")
f.write(msg.."\n")
f.close()
end
term.redirect(nTerm)
term.setTextColor(colors.white)
term.setCursorPos(7,1)
term.setCursorBlink(true)
local function printMsg(msg, save)
displayWin.setCursorBlink(false)
displayWin.setTextColor(colors.black)
local nTerm = term.current()
term.redirect(displayWin)
print(msg)
if save then
f = fs.open("/.sPhone/cache/sms/" .. sendTo, "a")
f.write(msg .. "\n")
f.close()
end
term.redirect(nTerm)
term.setTextColor(colors.white)
term.setCursorPos(7, 1)
term.setCursorBlink(true)
end
local function readMsg()
@ -106,7 +106,7 @@ local function readMsg()
term.setBackgroundColor(colors.green)
term.setTextColor(colors.white)
term.clear()
term.setCursorPos(1,1)
term.setCursorPos(1, 1)
if sendTo ~= "" then
term.write("Send: ")
local msg = read()
@ -120,24 +120,25 @@ local function readMsg()
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")
http.request(server .. "send.php",
"user=" .. user .. "&password=" .. pass .. "&message=" .. msg .. "&to=" .. sendTo .. "&hashed=true")
while true do
term.clear()
term.setCursorPos(1,1)
term.write("Sending "..loading[pos])
e = {os.pullEvent()}
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
printMsg("<You> "..rawMsg,true)
printMsg("<You> " .. rawMsg, true)
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)
term.setCursorPos(1, 1)
sPhone.winOk("Disconnected", nil, colors.lime, colors.green, colors.white, colors.lime)
return
end
end
@ -160,40 +161,40 @@ local function recMsg()
displayWin.setTextColor(colors.black)
displayWin.clear()
if sendTo ~= "" then
printMsg("Type /logout to exit",false)
if fs.exists("/.sPhone/cache/sms/"..sendTo) then
local f = fs.open("/.sPhone/cache/sms/"..sendTo,"r")
printMsg("Type /logout to exit", false)
if fs.exists("/.sPhone/cache/sms/" .. sendTo) then
local f = fs.open("/.sPhone/cache/sms/" .. sendTo, "r")
local line = f.readLine()
repeat
printMsg(line,false)
printMsg(line, false)
line = f.readLine()
until not line
f.close()
end
else
printMsg("All messages",false)
printMsg("All messages", false)
end
while true do
if sendTo == "" then
stream = http.post(server .. "update.php?new", head)
else
stream = http.post(server .. "update.php", head .. "&to=" .. sendTo)
end
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"]
mesg = "<" .. t["from"] .. "> " .. base64.decode(t["message"])
printMsg(mesg, true)
end
end
end
while true do
if sendTo == "" then
stream = http.post(server.."update.php?new",head)
else
stream = http.post(server.."update.php",head.."&to="..sendTo)
end
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"]
mesg = "<"..t["from"].."> "..base64.decode(t["message"])
printMsg(mesg,true)
end
end
end
end
parallel.waitForAny(readMsg,recMsg)
parallel.waitForAny(readMsg, recMsg)

View file

@ -1,5 +1,3 @@
if not pocket or not term.isColor() then
print("sPhone is only for Advanced Pocket Computers!")
return
@ -12,7 +10,7 @@ local files = {
["src/init.lua"] = "/.sPhone/init",
["src/sPhone.lua"] = "/.sPhone/sPhone",
["install"] = "/.sPhone/update",
["install.lua"] = "/.sPhone/update",
["LICENSE"] = "/.sPhone/LICENSE",
@ -47,11 +45,10 @@ local files = {
["src/interfaces/login"] = "/.sPhone/interfaces/login",
["src/interfaces/bootImage"] = "/.sPhone/interfaces/bootImage",
["src/startup"] = "/startup",
["src/startup"] = "/.sPhone/startup",
["src/startup.lua"] = "/startup.lua",
}
local githubUser = "SertexTeam"
local githubUser = "CC-Legacy"
local githubRepo = "sPhone"
local githubBranch = "master"
@ -108,7 +105,7 @@ local function get(user, repo, bran, path, save)
if not user or not repo or not bran or not path then
error("not enough arguments, expected 4 or 5", 2)
end
local url = "https://raw.github.com/"..user.."/"..repo.."/"..bran.."/"..path
local url = "https://git.alexdevs.me/"..user.."/"..repo.."/raw/branch/"..bran.."/"..path
local remote = http.get(url)
if not remote then
return false
@ -148,7 +145,7 @@ gui()
term.setCursorPos(2,3)
print("License\n")
printError("You must accept the license to install sPhone\n")
print("The MIT License (MIT)\nCopyright (c) 2017 Sertex\n\nRead full license here:\nhttps://raw.github.com/SertexTeam/sPhone/master/LICENSE")
print("The MIT License (MIT)\nCopyright (c) 2024 AlexDevs\n\nRead full license here:\nhttps://git.alexdevs.me/Legacy-CC/sPhone/src/branch/master/LICENSE")
paintutils.drawFilledBox(2,17,9,19,colors.lime)
term.setCursorPos(3,18)
term.setTextColor(colors.white)