daily pastebin goal
1%
SHARE
TWEET

startup

a guest Jan 20th, 2017 115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. rednet.open("front")
  2.  
  3. -- rs.setOutput("top", true)
  4.  
  5. term.clear()
  6. term.setCursorPos(1, 1)
  7. x, y = term.getSize()
  8. x = x - 1
  9. print("Console Log (tekkitMailOS)")
  10. for i = 1, x do
  11.  write("-")
  12. end
  13. print()
  14. print()
  15.  
  16. function isNumber(number, max)
  17.  boolean = false
  18.  for i = 1, max do
  19.   if tostring(number) == tostring(max) then
  20.    boolean = true
  21.   end
  22.  end
  23.  return boolean;
  24. end
  25.  
  26. while true do
  27.  ID, msg = rednet.receive()
  28.  if msg == "ping" then
  29.   rednet.send(ID, "pong")
  30.   print("ID "..ID.." got ponged!")
  31.   print()
  32.  elseif msg == "login" then
  33.   ID, username = rednet.receive()
  34.   ID, password = rednet.receive()
  35.   shell.run("disk/users")
  36.   notDenied = false
  37.   for i = 1, #usernames do
  38.    if username == usernames[i] and password == passwords[i] then
  39.     notDenied = true
  40.     if rank[i] == 5 then
  41.      access = true
  42.      edit = true
  43.      rednet.send(ID, "admin")
  44.     else
  45.      access = true
  46.      edit = false
  47.      rednet.send(ID, "access")
  48.     end
  49.    end
  50.   end
  51.   if notDenied == false then
  52.    access = false
  53.    edit = false
  54.    rednet.send(ID, "denied")
  55.   end
  56.   print("ID "..ID.." logged on!")
  57.   print("Username: "..username)
  58.   print("A = "..tostring(access).." || E = "..tostring(edit))
  59.   print()
  60.  elseif msg == "send" then
  61.   ID, sender = rednet.receive()
  62.   ID, userID = rednet.receive()
  63.   ID, mailText = rednet.receive()
  64.   n = 1
  65.   while fs.exists(userID.."-"..n) do
  66.    n = n + 1
  67.   end
  68.   mail = fs.open(userID.."-"..n, "w")
  69.   shell.run("disk/users")
  70.   mail.writeLine("To: "..tostring(usernames[tonumber(userID)]))
  71.   mail.writeLine("From: "..sender)
  72.   mail.writeLine()
  73.   mail.write(mailText)
  74.   mail.close()
  75.   print(sender.." sent userID #"..userID.." a mail!")
  76.   print()
  77.  elseif msg == "read" then
  78.   controlID, username = rednet.receive()
  79.   shell.run("disk/users")
  80.   for i = 1, #usernames do
  81.    if username == usernames[i] then
  82.     userID = i
  83.    end
  84.   end
  85.   n = 0
  86.   while fs.exists(userID.."-"..n + 1) do
  87.    n = n + 1
  88.   end
  89.   if n == 0 then
  90.    print("User "..username.." checked for his mail.")
  91.    print("No mail found.")
  92.    rednet.send(ID, "no mail")
  93.   else
  94.    print("User "..username.." checked for his mail.")
  95.    print("Found "..n.." mails.")
  96.    mail = fs.open(userID.."-"..tonumber(n), "r")
  97.    rednet.send(ID, mail.readAll())
  98.    mail.close()
  99.    fs.delete(userID.."-"..n)
  100.   end
  101.  
  102.   print()
  103.  elseif msg == "contacts" then
  104.   fs.delete("contacts")
  105.   contactsW = fs.open("contacts", "w")
  106.   shell.run("disk/users")
  107.   for i = 1, #usernames do
  108.    contactsW.writeLine(i.." | "..usernames[i])
  109.   end
  110.   contactsW.close()
  111.   contactsR = fs.open("contacts", "r")
  112.   rednet.send(ID, contactsR.readAll())
  113.   contactsR.close()
  114.  elseif msg == "checkUserID" then
  115.   ID, userID = rednet.receive()
  116.   shell.run("disk/users")
  117.   if isNumber(userID, #usernames) then
  118.    rednet.send(ID, "ok")
  119.    rednet.send(ID, tostring(usernames[userID]))
  120.    okstatus = true
  121.   else
  122.    rednet.send(ID, "not ok")
  123.    okstatus = false
  124.   end
  125.   print("ID "..tostring(ID).." checked userID "..tostring(userID).." - OK: "..tostring(okstatus))
  126.   print()
  127.  end
  128. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top