Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- server = 2 -- put the server's computer id here
- cursor = "=> " -- this is the cursor for the welcome screen
- cursor2 = ">> " -- this is the cursor for the actual Minebook
- maxUserNameLength = 10 --The max ammount of charecters allowed in a username
- adminPassword = "ADMIN" --The admin password
- --31 18
- function deleteUser()
- shell.run("clear")
- term.write("ENTER USER: ")
- usr = read()
- nmsg = crntname.."!SP!deleteUser!SP!"..usr
- rednet.send(server, nmsg)
- id, msg, d = rednet.receive(5)
- if msg ~= nil then
- shell.run("clear")
- print(msg)
- read()
- loadRandomCrap2()
- else
- shell.run("clear")
- print("SERVER ERROR")
- end
- end
- function listAccounts()
- admsg = crntname.."!SP!listUsers!SP!"
- rednet.send(server, admsg)
- id, msg, d = rednet.receive(5)
- if msg ~= nil then
- t = textutils.unserialize(msg)
- shell.run("clear")
- textutils.tabulate(t)
- read()
- else
- shell.run("clear")
- print("SERVOR ERROR")
- end
- loadRandomCrap2()
- end
- function testLogIn()
- shell.run("clear")
- if msg1 == "YOU HAVE BEEN LOGGED IN" then
- print(msg1..": "..crntname)
- term.setCursorBlink(false)
- read()
- else
- print(msg1)
- term.setCursorBlink(false)
- read()
- end
- if msg1 == "YOU HAVE BEEN LOGGED IN" then
- mineBook()
- else
- loadRandomCrap()
- end
- end
- function errorQuit()
- a = jkfdls+fjdsjfal
- print(a)
- end
- function searchUser()
- shell.run("clear")
- term.write("ENTER USER: ")
- user2 = read()
- if user2 ~= crntname then
- sndsrch = crntname.."!SP!search!SP!"..user2
- rednet.send(server, sndsrch)
- id3, msg3, d3 = rednet.receive(5)
- if msg3 ~= nil then
- srch = split(msg3, "!SP!")
- nuser = srch[1]
- nstatus = srch[2]
- nfriends = srch[3]
- if nstatus == nil then
- nstatus = ""
- end
- shell.run("clear")
- print("|||||||||||||||||||||||||||")
- print("|| ||")
- print("|| USER SEARCH RESULTS ||")
- print("|| ||")
- print("|||||||||||||||||||||||||||")
- print("")
- print("")
- print("User Name: "..nuser)
- print("")
- print("Status: "..nstatus)
- print("")
- print("")
- read()
- else
- shell.run("clear")
- print("SERVER ERROR")
- read()
- loadRandomCrap2()
- end
- else
- shell.run("clear")
- print("YOU CAN NOT SEARCH YOURSELF")
- sleep(1)
- loadRandomCrap2()
- end
- end
- function prntFrq()
- shell.run("clear")
- print("FRIEND REQUESTS")
- print("")
- print(frq[gcur])
- print("")
- print("PRESS A TO ACCEPT OR D TO DECLINE")
- end
- function printFrndReq()
- gcur = 1
- prntFrq()
- while true do
- event2, param2 = os.pullEvent()
- if event2 == "key" and param2 == 30 then
- shell.run("clear")
- print("USER ADDED")
- ju = crntname.."!SP!add friend!SP!"..frq[gcur]
- rednet.send(server, ju)
- gcur = gcur+1
- read()
- if gcur > gmax then
- loadRandomCrap2()
- break
- else
- prntFrq()
- end
- elseif event2 == "key" and param2 == 32 then
- shell.run("clear")
- print("USER DECLINED")
- gcur = gcur+1
- read()
- if gcur > gmax then
- loadRandomCrap2()
- break
- else
- prntFrq()
- end
- end
- end
- end
- function checkFrndReq()
- jk = crntname.."!SP!chck frnd req"
- rednet.send(server, jk)
- id, msg, d = rednet.receive(5)
- if msg ~= nil then
- frq = split(msg, "!SP!")
- gmax = #frq
- gmin = 1
- if gmax >= gmin then
- shell.run("clear")
- printFrndReq()
- else
- shell.run("clear")
- print("NO NEW REQUESTS")
- read()
- end
- loadRandomCrap2()
- end
- end
- function updateStatus()
- shell.run("clear")
- stat = read()
- h = crntname.."!SP!status update!SP!"..stat
- rednet.send(server, h)
- g = fs.open("MINEBOOK/STATUS", "w")
- g.write(stat)
- g.close()
- end
- function listFriends()
- y = "list"
- x = crntname.."!SP!"..y
- rednet.send(server, x)
- id, msg, d = rednet.receive(4)
- if msg == nil then
- shell.run("clear")
- print("ERROR")
- read()
- loadRandomCrap2()
- else
- shell.run("clear")
- r = split(msg, "!SP!")
- print("FRIEND LIST")
- textutils.tabulate(r)
- read()
- loadRandomCrap2()
- end
- end
- function testLogInTwo()
- shell.run("clear")
- print(msg2)
- term.setCursorBlink(false)
- read()
- end
- function OpenAll()
- for _,side in ipairs(rs.getSides()) do
- rednet.open(side)
- end
- end
- function mineBook()
- w1 = "Search"
- w2 = "Change Status"
- w3 = "Delete User"
- w4 = "List Users"
- w5 = "Exit"
- min = 1
- max = 5
- cur = min
- function doThings2()
- if cur == 3 then
- deleteUser()
- elseif cur == 4 then
- listAccounts()
- elseif cur == 1 then
- searchUser()
- elseif cur == 2 then
- updateStatus()
- loadRandomCrap2()
- end
- end
- function loadRandomCrap2()
- OpenAll()
- term.clear()
- term.setCursorPos(1,1)
- y = fs.open("MINEBOOK/STATUS", "a")
- y.close()
- l = fs.open("MINEBOOK/STATUS", "r")
- ju = l.readAll()
- crntstatus = ju
- print("|----------------------| WELLCOME: "..crntname)
- print("| RedBook 1.2 |")
- print("| ADMIN ACCOUNT |")
- print("|----------------------|")
- print("")
- print("")
- print("STATUS: "..ju)
- if cur == 1 then
- term.setCursorPos(1,11)
- print(""..cursor2..""..w1.."")
- else
- term.setCursorPos(1,11)
- print(w1)
- end
- if cur == 2 then
- term.setCursorPos(1,12)
- print(""..cursor2..""..w2.."")
- else
- term.setCursorPos(1,12)
- print(w2)
- end
- if cur == 3 then
- term.setCursorPos(1,13)
- print(""..cursor2..""..w3.."")
- else
- term.setCursorPos(1,13)
- print(w3)
- end
- if cur == 4 then
- term.setCursorPos(1,14)
- print(""..cursor2..""..w4.."")
- else
- term.setCursorPos(1,14)
- print(w4)
- end
- if cur == 5 then
- term.setCursorPos(1,15)
- print(""..cursor2..""..w5.."")
- else
- term.setCursorPos(1,15)
- print(w5)
- end
- end
- function runMineBook()
- loadRandomCrap2()
- while true do
- event, param1 = os.pullEvent()
- if event == "key" and param1 == 200 then
- if cur == min then
- cur = max
- loadRandomCrap2()
- else
- cur = cur-1
- loadRandomCrap2()
- end
- elseif event == "key" and param1 == 208 then
- if cur == max then
- cur = min
- loadRandomCrap2()
- else
- cur = cur+1
- loadRandomCrap2()
- end
- elseif event == "key" and param1 == 28 then
- if cur == 5 then
- shell.run("clear")
- min = 1
- max = 4
- cur = min
- runProgram()
- break
- end
- doThings2()
- end
- end
- end
- runMineBook()
- end
- function split(str, pat)
- local t = { }
- local fpat = "(.-)"..pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- return t
- end
- min = 1
- max = 4
- cur = min
- function makeUser()
- shell.run("clear")
- term.write("ENTER DESIRED USERNAME: ")
- term.setCursorPos(1,3)
- term.write("ENTER DESIRED PASSWORD: ")
- term.setCursorPos(1,5)
- term.write("RE-ENTER DESIRED PASSWORD: ")
- term.setCursorPos(26,1)
- dusrnm = read()
- term.setCursorPos(26,3)
- dpw = read("*")
- term.setCursorPos(29,5)
- rdpw = read("*")
- if dpw == rdpw then
- if #dusrnm <= maxUserNameLength then
- y = dusrnm.."!SP!makeUser!SP!"..dpw
- rednet.send(server, y)
- id2, msg2, d2 = rednet.receive(1)
- if msg2 == nil then
- shell.run("clear")
- print("SERVER ERROR")
- read()
- loadRandomCrap()
- else
- username = dusrnm
- rednet.send(server, username.."!SP!status update!SP!DEFAULT STATUS")
- testLogInTwo()
- end
- else
- shell.run("clear")
- print("USERNAME IS TOO LONG")
- read()
- end
- else
- shell.run("clear")
- print("PASSWORDS DO NOT MATCH")
- read()
- end
- end
- function logIn()
- shell.run("clear")
- term.write("ENTER USERNAME: ")
- term.setCursorPos(1,3)
- term.write("ENTER PASSWORD: ")
- term.setCursorPos(17,1)
- usrnm = read()
- term.setCursorPos(17,3)
- pswrd = read("*")
- x = usrnm.."!SP!logIn!SP!"..pswrd
- rednet.send(server, x)
- id1, msg1, d1 = rednet.receive(1)
- if msg1 == nil then
- shell.run("clear")
- print("SERVER ERROR")
- read()
- runProgram()
- else
- if msg1 == "YOU HAVE BEEN LOGGED IN" then
- crntname = usrnm
- testLogIn()
- else
- testLogIn()
- end
- end
- end
- term.setCursorBlink(false)
- s1 = "Log In"
- s2 = "Make Account"
- s3 = "Open Rednet Ports"
- s4 = "Exit"
- function doThings()
- if cur == 3 then
- OpenAll()
- loadRandomCrap()
- elseif cur == 1 then
- logIn()
- elseif cur == 2 then
- makeUser()
- loadRandomCrap()
- end
- end
- function loadRandomCrap()
- OpenAll()
- term.clear()
- term.setCursorPos(1,1)
- print("|----------------------|")
- print("| RedBook 1.2 |")
- print("| ADMIN ACCOUNT |")
- print("|----------------------|")
- if cur == 1 then
- term.setCursorPos(1,7)
- print(""..cursor..""..s1.."")
- else
- term.setCursorPos(1,7)
- print(s1)
- end
- if cur == 2 then
- term.setCursorPos(1,8)
- print(""..cursor..""..s2.."")
- else
- term.setCursorPos(1,8)
- print(s2)
- end
- if cur == 3 then
- term.setCursorPos(1,9)
- print(""..cursor..""..s3.."")
- else
- term.setCursorPos(1,9)
- print(s3)
- end
- if cur == 4 then
- term.setCursorPos(1,10)
- print(""..cursor..""..s4.."")
- else
- term.setCursorPos(1,10)
- print(s4)
- end
- end
- function runProgram()
- shell.run("clear")
- print("")
- print("")
- print("")
- print("")
- print(" |-------------------|")
- print(" | RedBook Admin |")
- print(" |-------------------|")
- print(" ")
- print(" ")
- term.write(" ENTER PASSWORD: ")
- input = read("*")
- if input == adminPassword then
- crntname = "ADMIN"
- mineBook()
- else
- shell.run("clear")
- print("WRONG PASSWORD")
- read()
- runProgram()
- end
- end
- runProgram()
Add Comment
Please, Sign In to add comment