Advertisement
xXm0dzXx

GeevanCraft Mailboxes

Oct 13th, 2012
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.05 KB | None | 0 0
  1. --------------------------Server Configure--------------------------
  2. local uPath = "users";
  3. local loggerPath = ".log";
  4. local emailSize = -1; --How much messages can be held in your inbox. Change to -1 for infinity.
  5. local serverLocation = "@g-email.com";
  6. local allowRegistering = true;
  7. local welcomeEmail = false;
  8. local welcomeSubj = "Welcome!";
  9. local welcomeText = [[
  10. Insert message here.
  11. ]]
  12.  
  13. --------------------Don't change anything below---------------------
  14.  
  15. if not fs.exists( uPath ) then
  16.     fs.makeDir(uPath)
  17. end
  18.  
  19. function addEmail( _sName, senderName, messageSubject, messageText )
  20.     emailPath = uPath.. "/" .._sName.. "/messages"
  21.     if emailSize ~= (-1) then
  22.         if emailSize == #fs.list(emailPath) then
  23.             return false
  24.         end
  25.     end
  26.     if fs.exists( emailPath.. "/" ..messageSubject ) then
  27.         currentValue = 1
  28.         repeat
  29.             messageSubject = messageSubject.. " [" ..currentValue.. "]"
  30.             currentValue = currentValue+1
  31.         until fs.exists( emailPath.. "/" ..messageSubject ) ~= true
  32.     end
  33.    
  34.     messageSubject = senderName.. " | " ..messageSubject;
  35.     file = fs.open( emailPath.. "/" ..messageSubject, "w" )
  36.     file.write(messageText)
  37.     file.close()
  38.     return true
  39. end
  40.  
  41. function registerUser( _sName, _sPass )
  42.     userPath = uPath.. "/" .._sName
  43.     if fs.exists(userPath) then
  44.         return "account_exists"
  45.     end
  46.     fs.makeDir( userPath )
  47.     file = fs.open( userPath.. "/info", "w" )
  48.     file.write( _sPass )
  49.     file.close()
  50.     fs.makeDir( userPath.. "/messages")
  51.     fs.makeDir( userPath.. "/blocked")
  52.     fs.makeDir( userPath.. "/contacts")
  53.     if welcomeEmail then
  54.         addEmail( _sName, "no-reply@autocraft.com", welcomeSubj, welcomeText )
  55.     end
  56.     return "account_complete"
  57. end
  58.  
  59. function getEmails( _sName, _sPass )
  60.     userPath = uPath.. "/" .._sName.. "/messages"
  61.     file = fs.open( uPath.. "/" .._sName.. "/info", "w")
  62.     if _sPass == file.readAll() then
  63.         file.close()
  64.         return textutils.serialize( fs.list( userPath ) )
  65.     else
  66.         file.close()
  67.         return false
  68.     end
  69. end
  70.  
  71. function getEmail( _sName, _sPass, subject )
  72.     userPath = uPath.. "/" .._sName.. "/messages"
  73.     file = fs.open( uPath.. "/" .._sName.. "/info", "w")
  74.     if _sPass == file.readAll() then
  75.         file.close()
  76.         file = fs.open( userPath.. "/" ..subject, "w" )
  77.         local text = file.readAll()
  78.         file.close()
  79.         return text
  80.     else
  81.         file.close()
  82.         return false
  83.     end
  84. end
  85.    
  86. function logger( sText )
  87.     file = fs.open(loggerPath, "w")
  88.     file.write( sText.. "\n" )
  89.     file.close()
  90.     print(sText)
  91. end
  92.  
  93. function split( sLine, sCode )
  94.     local tWords = {}
  95.     for match in string.gmatch(sLine, "[^" ..sCode.. "\t]+") do
  96.         table.insert( tWords, match )
  97.     end
  98.     return tWords
  99. end
  100.  
  101. term.clear()
  102. term.setCursorPos(1,1)
  103. print("Size: " ..emailSize)
  104. print("Welcome Message: " ..tostring(welcomeEmail))
  105. print("Users: " ..#fs.list(uPath))
  106. print()
  107. print("Log: ")
  108. rednet.open("top")
  109.  
  110. while true do
  111.     local sEvent, sID, sMessage = os.pullEvent("rednet_message")
  112.     local fMessage = split(sMessage, "<DECRYPTEDCODETROLLFACEANDDONTPUTTHISCODEINYOURFILEORYOURFAICISFKASDIFJAGHARE!=LOL=!DECRYPTEDCODETROLLFACEANDDONTPUTTHISCODEINYOURFILEORYOURFAICISFKASDIFJAGHARE>");
  113.     if fMessage[1] == serverLocation then
  114.         local action = fMessage[2]
  115.         if action == "/send" then
  116.             local receiver = fMessage[3]
  117.             local sender = fMessage[4]
  118.             local messageSubject = fMessage[5]
  119.             local messageText = fMessage[6]
  120.             if messageText then
  121.                 addEmail( receiver, sender, messageSubject, messageText )
  122.             end
  123.         elseif action == "/receive" then
  124.             local sUser = fMessage[3]
  125.             local sPass = fMessage[4]
  126.             if sPass then
  127.                 rednet.send(sID, getEmails( sUser, sPass ))
  128.             end
  129.         elseif action == "/get" then
  130.             local username = fMessage[3]
  131.             local password = fMessage[4]
  132.             local subject = fMessage[5]
  133.             if subject then
  134.                 rednet.send(sID, getEmail( username, password, subject ))
  135.             end
  136.         elseif action == "/register" then
  137.             local username = fMessage[3]
  138.             local password = fMessage[4]
  139.             if password then
  140.                 rednet.send(sID, registerUser)
  141.             end
  142.         elseif action == "/ping_" ..serverLocation then
  143.             rednet.send(sID, serverLocation.. "_PING_RECEIVED")
  144.         end
  145.     end
  146. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement