Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------------Server Configure--------------------------
- local uPath = "users";
- local loggerPath = ".log";
- local emailSize = -1; --How much messages can be held in your inbox. Change to -1 for infinity.
- local serverLocation = "@g-email.com";
- local allowRegistering = true;
- local welcomeEmail = false;
- local welcomeSubj = "Welcome!";
- local welcomeText = [[
- Insert message here.
- ]]
- --------------------Don't change anything below---------------------
- if not fs.exists( uPath ) then
- fs.makeDir(uPath)
- end
- function addEmail( _sName, senderName, messageSubject, messageText )
- emailPath = uPath.. "/" .._sName.. "/messages"
- if emailSize ~= (-1) then
- if emailSize == #fs.list(emailPath) then
- return false
- end
- end
- if fs.exists( emailPath.. "/" ..messageSubject ) then
- currentValue = 1
- repeat
- messageSubject = messageSubject.. " [" ..currentValue.. "]"
- currentValue = currentValue+1
- until fs.exists( emailPath.. "/" ..messageSubject ) ~= true
- end
- messageSubject = senderName.. " | " ..messageSubject;
- file = fs.open( emailPath.. "/" ..messageSubject, "w" )
- file.write(messageText)
- file.close()
- return true
- end
- function registerUser( _sName, _sPass )
- userPath = uPath.. "/" .._sName
- if fs.exists(userPath) then
- return "account_exists"
- end
- fs.makeDir( userPath )
- file = fs.open( userPath.. "/info", "w" )
- file.write( _sPass )
- file.close()
- fs.makeDir( userPath.. "/messages")
- fs.makeDir( userPath.. "/blocked")
- fs.makeDir( userPath.. "/contacts")
- if welcomeEmail then
- addEmail( _sName, "no-reply@autocraft.com", welcomeSubj, welcomeText )
- end
- return "account_complete"
- end
- function getEmails( _sName, _sPass )
- userPath = uPath.. "/" .._sName.. "/messages"
- file = fs.open( uPath.. "/" .._sName.. "/info", "w")
- if _sPass == file.readAll() then
- file.close()
- return textutils.serialize( fs.list( userPath ) )
- else
- file.close()
- return false
- end
- end
- function getEmail( _sName, _sPass, subject )
- userPath = uPath.. "/" .._sName.. "/messages"
- file = fs.open( uPath.. "/" .._sName.. "/info", "w")
- if _sPass == file.readAll() then
- file.close()
- file = fs.open( userPath.. "/" ..subject, "w" )
- local text = file.readAll()
- file.close()
- return text
- else
- file.close()
- return false
- end
- end
- function logger( sText )
- file = fs.open(loggerPath, "w")
- file.write( sText.. "\n" )
- file.close()
- print(sText)
- end
- function split( sLine, sCode )
- local tWords = {}
- for match in string.gmatch(sLine, "[^" ..sCode.. "\t]+") do
- table.insert( tWords, match )
- end
- return tWords
- end
- term.clear()
- term.setCursorPos(1,1)
- print("Size: " ..emailSize)
- print("Welcome Message: " ..tostring(welcomeEmail))
- print("Users: " ..#fs.list(uPath))
- print()
- print("Log: ")
- rednet.open("top")
- while true do
- local sEvent, sID, sMessage = os.pullEvent("rednet_message")
- local fMessage = split(sMessage, "<DECRYPTEDCODETROLLFACEANDDONTPUTTHISCODEINYOURFILEORYOURFAICISFKASDIFJAGHARE!=LOL=!DECRYPTEDCODETROLLFACEANDDONTPUTTHISCODEINYOURFILEORYOURFAICISFKASDIFJAGHARE>");
- if fMessage[1] == serverLocation then
- local action = fMessage[2]
- if action == "/send" then
- local receiver = fMessage[3]
- local sender = fMessage[4]
- local messageSubject = fMessage[5]
- local messageText = fMessage[6]
- if messageText then
- addEmail( receiver, sender, messageSubject, messageText )
- end
- elseif action == "/receive" then
- local sUser = fMessage[3]
- local sPass = fMessage[4]
- if sPass then
- rednet.send(sID, getEmails( sUser, sPass ))
- end
- elseif action == "/get" then
- local username = fMessage[3]
- local password = fMessage[4]
- local subject = fMessage[5]
- if subject then
- rednet.send(sID, getEmail( username, password, subject ))
- end
- elseif action == "/register" then
- local username = fMessage[3]
- local password = fMessage[4]
- if password then
- rednet.send(sID, registerUser)
- end
- elseif action == "/ping_" ..serverLocation then
- rednet.send(sID, serverLocation.. "_PING_RECEIVED")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement