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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,5 @@
local tArgs = {...} local tArgs = { ... }
local loading = {"|","/","-","\\","|","/","-","\\"} local loading = { "|", "/", "-", "\\", "|", "/", "-", "\\" }
local server = "http://sertex.x10.bz/" local server = "http://sertex.x10.bz/"
local sendTo local sendTo
@ -9,18 +9,18 @@ if not sPhone then
end end
--check if the server is down --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 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 return
end end
term.setBackgroundColor(colors.white) term.setBackgroundColor(colors.white)
term.clear() term.clear()
term.setCursorPos(1,1) term.setCursorPos(1, 1)
term.setTextColor(colors.black) term.setTextColor(colors.black)
print("sPhone SMS") print("sPhone SMS")
if not fs.exists("/.sPhone/config/.sIDpw") then 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 return
end end
f = fs.open("/.sPhone/config/username", "r") f = fs.open("/.sPhone/config/username", "r")
@ -29,67 +29,67 @@ f.close()
f = fs.open("/.sPhone/config/.sIDpw", "r") f = fs.open("/.sPhone/config/.sIDpw", "r")
local pass = f.readLine() local pass = f.readLine()
f.close() f.close()
local head = "user="..user.."&password="..pass.."&hashed=true" local head = "user=" .. user .. "&password=" .. pass .. "&hashed=true"
http.request(server.."login.php",head) http.request(server .. "login.php", head)
local update = os.startTimer(0.15) local update = os.startTimer(0.15)
local pos = 1 local pos = 1
while true do while true do
local _,y = term.getCursorPos() local _, y = term.getCursorPos()
term.clearLine() term.clearLine()
term.setCursorPos(1,y) term.setCursorPos(1, y)
term.write("Loading "..loading[pos]) term.write("Loading " .. loading[pos])
local e = {os.pullEvent()} local e = { os.pullEvent() }
if e[1] == "timer" and e[2] == update then if e[1] == "timer" and e[2] == update then
pos = pos + 1 pos = pos + 1
if pos > #loading then pos = 1 end if pos > #loading then pos = 1 end
update = os.startTimer(0.15) update = os.startTimer(0.15)
elseif e[1] == "http_success" then elseif e[1] == "http_success" then
if e[3].readAll() == "true" then if e[3].readAll() == "true" then
if not tArgs[1] then if not tArgs[1] then
term.clearLine() term.clearLine()
term.setCursorPos(1,y) term.setCursorPos(1, y)
write("Send To: ") write("Send To: ")
sendTo = read() sendTo = read()
else else
sendTo = tArgs[1] sendTo = tArgs[1]
end 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 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 return
end end
break break
else else
sPhone.winOk("Wrong Username","or Password", colors.lime, colors.green, colors.white, colors.lime) sPhone.winOk("Wrong Username", "or Password", colors.lime, colors.green, colors.white, colors.lime)
return return
end end
elseif e[1] == "http_failure" then elseif e[1] == "http_failure" then
term.clearLine() term.clearLine()
term.setCursorPos(1,y) term.setCursorPos(1, y)
sPhone.winOk("Connection lost!","Check internet!", colors.lime, colors.green, colors.white, colors.lime) sPhone.winOk("Connection lost!", "Check internet!", colors.lime, colors.green, colors.white, colors.lime)
return return
end end
end end
term.clear() term.clear()
local x,y = term.getSize() local x, y = term.getSize()
local mainTerm = term.current() local mainTerm = term.current()
local displayWin = window.create(term.native(),1,1,x,y-1,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 readWin = window.create(term.native(), 1, y, x, y, true)
local ntv = term.redirect(mainTerm) local ntv = term.redirect(mainTerm)
local x,y = 1,1 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: ") term.write("Send: ")
local msg = read() local msg = read()
local msg = base64.encode(msg) local msg = base64.encode(msg)
term.clear() term.clear()
if base64.decode(msg) == "/logout" then if base64.decode(msg) == "/logout" then
term.redirect(mainTerm) term.redirect(mainTerm)
return return
@ -97,60 +97,61 @@ local function readMsg()
if msg ~= "" then if msg ~= "" then
local pos = 1 local pos = 1
local update = os.startTimer(0.15) 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 while true do
term.clear() term.clear()
term.setCursorPos(1,1) term.setCursorPos(1, 1)
term.write("Sending "..loading[pos]) term.write("Sending " .. loading[pos])
e = {os.pullEvent()} e = { os.pullEvent() }
if e[1] == "timer" and e[2] == update then if e[1] == "timer" and e[2] == update then
update = os.startTimer(0.15) update = os.startTimer(0.15)
pos = pos + 1 pos = pos + 1
if pos > #loading then pos = 1 end if pos > #loading then pos = 1 end
elseif e[1] == "http_success" then elseif e[1] == "http_success" then
displayWin.setCursorPos(1,y) displayWin.setCursorPos(1, y)
displayWin.write("<You> "..base64.decode(msg)) displayWin.write("<You> " .. base64.decode(msg))
if y == my then displayWin.scroll(1) else y = y +1 end if y == my then displayWin.scroll(1) else y = y + 1 end
break break
elseif e[1] == "http_failure" then elseif e[1] == "http_failure" then
term.redirect(ntv) 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) sPhone.winOk("Disconnected", nil, colors.lime, colors.green, colors.white, colors.lime)
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)
displayWin.setTextColor(colors.black) displayWin.setTextColor(colors.black)
displayWin.clear() displayWin.clear()
local function printMsg(msg) local function printMsg(msg)
displayWin.setCursorBlink(false) displayWin.setCursorBlink(false)
displayWin.setCursorPos(1,y) displayWin.setCursorPos(1, y)
local nTerm = term.current() local nTerm = term.current()
term.redirect(displayWin) term.redirect(displayWin)
print(msg) print(msg)
term.redirect(nTerm) term.redirect(nTerm)
if y == my then displayWin.scroll(1) else y = y + 1 end if y == my then displayWin.scroll(1) else y = y + 1 end
end end
printMsg("Type /logout to exit") printMsg("Type /logout to exit")
while true do while true do
stream = http.post(server.."update-new.php",head) stream = http.post(server .. "update-new.php", head)
if stream then if stream then
local newMessages = textutils.unserialize(stream.readAll()) local newMessages = textutils.unserialize(stream.readAll())
stream.close() stream.close()
for i,v in pairs(newMessages) do for i, v in pairs(newMessages) do
t = textutils.unserialize(v) t = textutils.unserialize(v)
if t then if t then
date = t["date"] date = t["date"]
mesg = "<"..t["from"].."> "..base64.decode(t["message"]) mesg = "<" .. t["from"] .. "> " .. base64.decode(t["message"])
printMsg(mesg) printMsg(mesg)
end end
end end
end end
end end
end end
parallel.waitForAny(readMsg,recMsg) parallel.waitForAny(readMsg, recMsg)

View file

@ -1,5 +1,5 @@
local tArgs = {...} local tArgs = { ... }
local loading = {"|","/","-","\\","|","/","-","\\"} local loading = { "|", "/", "-", "\\", "|", "/", "-", "\\" }
local server = "http://sertex.x10.bz/" local server = "http://sertex.x10.bz/"
local sendTo local sendTo
@ -9,18 +9,18 @@ if not sPhone then
end end
--check if the server is down --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 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 return
end end
term.setBackgroundColor(colors.white) term.setBackgroundColor(colors.white)
term.clear() term.clear()
term.setCursorPos(1,1) term.setCursorPos(1, 1)
term.setTextColor(colors.black) term.setTextColor(colors.black)
print("sPhone SMS") print("sPhone SMS")
if not fs.exists("/.sPhone/config/.sIDpw") then 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 return
end end
f = fs.open("/.sPhone/config/username", "r") f = fs.open("/.sPhone/config/username", "r")
@ -29,74 +29,74 @@ f.close()
f = fs.open("/.sPhone/config/.sIDpw", "r") f = fs.open("/.sPhone/config/.sIDpw", "r")
local pass = f.readLine() local pass = f.readLine()
f.close() f.close()
local head = "user="..user.."&password="..pass.."&hashed=true" local head = "user=" .. user .. "&password=" .. pass .. "&hashed=true"
http.request(server.."login.php",head) http.request(server .. "login.php", head)
local update = os.startTimer(0.15) local update = os.startTimer(0.15)
local pos = 1 local pos = 1
while true do while true do
local _,y = term.getCursorPos() local _, y = term.getCursorPos()
term.clearLine() term.clearLine()
term.setCursorPos(1,y) term.setCursorPos(1, y)
term.write("Loading "..loading[pos]) term.write("Loading " .. loading[pos])
local e = {os.pullEvent()} local e = { os.pullEvent() }
if e[1] == "timer" and e[2] == update then if e[1] == "timer" and e[2] == update then
pos = pos + 1 pos = pos + 1
if pos > #loading then pos = 1 end if pos > #loading then pos = 1 end
update = os.startTimer(0.15) update = os.startTimer(0.15)
elseif e[1] == "http_success" then elseif e[1] == "http_success" then
if e[3].readAll() == "true" then if e[3].readAll() == "true" then
if not tArgs[1] then if not tArgs[1] then
term.clearLine() term.clearLine()
term.setCursorPos(1,y) term.setCursorPos(1, y)
print("Leave blank to get unread chat\n") print("Leave blank to get unread chat\n")
write("Send To: ") write("Send To: ")
sendTo = read() sendTo = read()
else else
sendTo = tArgs[1] sendTo = tArgs[1]
end 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 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 return
end end
break break
else else
sPhone.winOk("Wrong Username","or Password", colors.lime, colors.green, colors.white, colors.lime) sPhone.winOk("Wrong Username", "or Password", colors.lime, colors.green, colors.white, colors.lime)
return return
end end
elseif e[1] == "http_failure" then elseif e[1] == "http_failure" then
term.clearLine() term.clearLine()
term.setCursorPos(1,y) term.setCursorPos(1, y)
sPhone.winOk("Connection lost!","Check internet!", colors.lime, colors.green, colors.white, colors.lime) sPhone.winOk("Connection lost!", "Check internet!", colors.lime, colors.green, colors.white, colors.lime)
return return
end end
end end
term.clear() term.clear()
local x,y = term.getSize() local x, y = term.getSize()
local mainTerm = term.current() local mainTerm = term.current()
local displayWin = window.create(term.native(),1,1,x,y-1,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 readWin = window.create(term.native(), 1, y, x, y, true)
local ntv = term.redirect(mainTerm) local ntv = term.redirect(mainTerm)
local x,y = 1,1 local x, y = 1, 1
local mx,my = displayWin.getSize() local mx, my = displayWin.getSize()
local function printMsg(msg, save) local function printMsg(msg, save)
displayWin.setCursorBlink(false) displayWin.setCursorBlink(false)
displayWin.setTextColor(colors.black) displayWin.setTextColor(colors.black)
local nTerm = term.current() local nTerm = term.current()
term.redirect(displayWin) term.redirect(displayWin)
print(msg) print(msg)
if save then if save then
f = fs.open("/.sPhone/cache/sms/"..sendTo,"a") f = fs.open("/.sPhone/cache/sms/" .. sendTo, "a")
f.write(msg.."\n") f.write(msg .. "\n")
f.close() f.close()
end
term.redirect(nTerm)
term.setTextColor(colors.white)
term.setCursorPos(7,1)
term.setCursorBlink(true)
end end
term.redirect(nTerm)
term.setTextColor(colors.white)
term.setCursorPos(7, 1)
term.setCursorBlink(true)
end
local function readMsg() local function readMsg()
@ -106,7 +106,7 @@ local function readMsg()
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)
if sendTo ~= "" then if sendTo ~= "" then
term.write("Send: ") term.write("Send: ")
local msg = read() local msg = read()
@ -120,24 +120,25 @@ local function readMsg()
if msg ~= "" then if msg ~= "" then
local pos = 1 local pos = 1
local update = os.startTimer(0.15) 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 while true do
term.clear() term.clear()
term.setCursorPos(1,1) term.setCursorPos(1, 1)
term.write("Sending "..loading[pos]) term.write("Sending " .. loading[pos])
e = {os.pullEvent()} e = { os.pullEvent() }
if e[1] == "timer" and e[2] == update then if e[1] == "timer" and e[2] == update then
update = os.startTimer(0.15) update = os.startTimer(0.15)
pos = pos + 1 pos = pos + 1
if pos > #loading then pos = 1 end if pos > #loading then pos = 1 end
elseif e[1] == "http_success" then elseif e[1] == "http_success" then
printMsg("<You> "..rawMsg,true) printMsg("<You> " .. rawMsg, true)
break break
elseif e[1] == "http_failure" then elseif e[1] == "http_failure" then
term.redirect(ntv) 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) sPhone.winOk("Disconnected", nil, colors.lime, colors.green, colors.white, colors.lime)
return return
end end
end end
@ -160,40 +161,40 @@ local function recMsg()
displayWin.setTextColor(colors.black) displayWin.setTextColor(colors.black)
displayWin.clear() displayWin.clear()
if sendTo ~= "" then if sendTo ~= "" then
printMsg("Type /logout to exit",false) printMsg("Type /logout to exit", false)
if fs.exists("/.sPhone/cache/sms/"..sendTo) then if fs.exists("/.sPhone/cache/sms/" .. sendTo) then
local f = fs.open("/.sPhone/cache/sms/"..sendTo,"r") local f = fs.open("/.sPhone/cache/sms/" .. sendTo, "r")
local line = f.readLine() local line = f.readLine()
repeat repeat
printMsg(line,false) printMsg(line, false)
line = f.readLine() line = f.readLine()
until not line until not line
f.close() f.close()
end end
else else
printMsg("All messages",false) printMsg("All messages", false)
end end
while true do while true do
if sendTo == "" then if sendTo == "" then
stream = http.post(server.."update.php?new",head) stream = http.post(server .. "update.php?new", head)
else else
stream = http.post(server.."update.php",head.."&to="..sendTo) stream = http.post(server .. "update.php", head .. "&to=" .. sendTo)
end end
newMessages = {} newMessages = {}
line = stream.readLine() line = stream.readLine()
repeat repeat
table.insert(newMessages,line) table.insert(newMessages, line)
line = stream.readLine() line = stream.readLine()
until not line until not line
for i,v in pairs(newMessages) do for i, v in pairs(newMessages) do
t = textutils.unserialize(v) t = textutils.unserialize(v)
if t then if t then
date = t["date"] date = t["date"]
mesg = "<"..t["from"].."> "..base64.decode(t["message"]) mesg = "<" .. t["from"] .. "> " .. base64.decode(t["message"])
printMsg(mesg,true) printMsg(mesg, true)
end end
end end
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 if not pocket or not term.isColor() then
print("sPhone is only for Advanced Pocket Computers!") print("sPhone is only for Advanced Pocket Computers!")
return return
@ -12,7 +10,7 @@ local files = {
["src/init.lua"] = "/.sPhone/init", ["src/init.lua"] = "/.sPhone/init",
["src/sPhone.lua"] = "/.sPhone/sPhone", ["src/sPhone.lua"] = "/.sPhone/sPhone",
["install"] = "/.sPhone/update", ["install.lua"] = "/.sPhone/update",
["LICENSE"] = "/.sPhone/LICENSE", ["LICENSE"] = "/.sPhone/LICENSE",
@ -47,11 +45,10 @@ local files = {
["src/interfaces/login"] = "/.sPhone/interfaces/login", ["src/interfaces/login"] = "/.sPhone/interfaces/login",
["src/interfaces/bootImage"] = "/.sPhone/interfaces/bootImage", ["src/interfaces/bootImage"] = "/.sPhone/interfaces/bootImage",
["src/startup"] = "/startup", ["src/startup.lua"] = "/startup.lua",
["src/startup"] = "/.sPhone/startup",
} }
local githubUser = "SertexTeam" local githubUser = "CC-Legacy"
local githubRepo = "sPhone" local githubRepo = "sPhone"
local githubBranch = "master" 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 if not user or not repo or not bran or not path then
error("not enough arguments, expected 4 or 5", 2) error("not enough arguments, expected 4 or 5", 2)
end 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) local remote = http.get(url)
if not remote then if not remote then
return false return false
@ -148,7 +145,7 @@ gui()
term.setCursorPos(2,3) term.setCursorPos(2,3)
print("License\n") print("License\n")
printError("You must accept the license to install sPhone\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) paintutils.drawFilledBox(2,17,9,19,colors.lime)
term.setCursorPos(3,18) term.setCursorPos(3,18)
term.setTextColor(colors.white) term.setTextColor(colors.white)