This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
TheDeathOfRandom's profile picture

Looking for some help with a "Mail" system

Started by TheDeathOfRandom, 03 March 2012 - 04:00 AM
TheDeathOfRandom #1
Posted 03 March 2012 - 05:00 AM
alrighty… I've got some code… I came up with a short and sweet 1 message kinda mail drop box :unsure:/>/>
when a user boots up the pc it asks for their name and saves the name as y variable. and then it asks for the message and saves the message as x variable. then the computer locks and cant be accessed until the owner enters his/her username and password B)/>/>! once the info is entered the name and the message is shown to the owner! Oh and best of all there is NO ctrl+t!

Now for the help that I need:

I need help saving more than one message.

i want it to list the messages kind of like on yahoo… showing unread but maybe automatically deleting read messages?

and really all i want is tips or pointers…

so far thats all i need help with B)/>/> feel free to work on the code… i don't even care if you don't help me out xD i think this is pretty cool.. soyeh here it is…

Spoiler
function os.pullEvent()
local event, p1, p2, p3, p4, p5 = os.pullEventRaw()
if event == "terminate" then
os.reboot()
end
return event, p1, p2, p3, p4, p5
end
term.clear()
term.setCursorPos(1,1)
write("Hello! Please enter your name.nnName: ")
y = io.read()
term.clear()
term.setCursorPos(1,1)
write("Message: ")
x = io.read()
if x ~= "" then
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("Would you like to send this to OWNER?nn"..x.."nny/nn") -- Replace OWNER with owners name B)/>/>
input = read()
  if input == "y" then
  term.clear()
  term.setCursorPos(1,1)
  else
  os.reboot()
  end
	repeat
	print("Please login to view mail.")
	sleep(2)
	term.clear()
	term.setCursorPos(1,1)
	write("Username: ")
	input = read("*")
	  if input ~= "user" then -- replace user with desired owner username here
	  print("User not found in database.")
	  sleep(1)
	  term.clear()
	  term.setCursorPos(1,1)
	  end
	until
	input == "user" -- Replace user with desired owner username here
	term.clear()
	term.setCursorPos(1,1)
	repeat
	write("Password: ")
	input = read("*")
	if input ~= "pass" then -- Replace pass with desired owner password here
	print("Login failed.")
	sleep(1)
	term.clear()
	term.setCursorPos(1,1)
	end
	until
	input == "pass" -- Replace pass with desired owner password here
	sleep(1)
	term.clear()
	term.setCursorPos(1,1)
	print(y.." says:nn"..x.."n")
else
print("Blank messages not accepted.")
sleep(1)
os.reboot()
end

alrighty..
Run the program. see what you think,
I don't care about distribution so long as i get a little credit B)/>/>! tell me what you think. good/bad i don't care… i'm new to programming and this is my first actual program.. besides my loop-based user/pass login thing that i think i made up… haven't seen anyone else do it so yeah B)/>/> i think its original! if you have any suggestions also feel free to let me know!
.
..

KBAI!
Wolvan #2
Posted 03 March 2012 - 06:16 PM
You could do it somehow like this (with rednet): Create 1 central mainframe that has kind of a server program. Each user who has an PC with the client software can type a letter and send it to the receiver ID. This message, along with the reciever ID gets send to the central mainframe. The mainframe saves everything. As soon as the reciever starts his client software it sends a welcome/handshake message like "Hello It is me! Computer …". The mainframe now looks if there is any mail for the client, sends the message and deletes it in it's internal memory.
I could help you with this. This would be much more comfortable for the user I think instead of just 1 message
nitrogenfingers #3
Posted 04 March 2012 - 12:35 PM
Hi, first post!

I actually recently made something very similar to this, it's up on youtube as a video so you can see how I solved the problem there
.
This looks like you're using just the one computer for sharing messages between users. If that's the plan you're not far off- instead of having a single message that's loaded when the application is started you might want to have a file you write the messages to, which is read each time the program is restarted. Then it's a matter of cycling through them by hitting the enter key or something similar and they can be deleted. You'll want to keep a global table near the top of your class and maybe write a function that reads in the file to populate the table with all the messages that have been stored.
If you're trying to do it similar to dropbox, that is to say files shared together on multiple computers you're going to require a server that keeps the master copies of those files (in this case messages) that can be accessed and modified by the user computers. That's a much trickier job and you'll have to think about what access you want your users to have and how your server will handle things like concurrency and storage. The yahoo style you mentioned would be fairly easy to implement, observing if a file was accessed and deleting or archiving after it is read.

Hope that helps.
Deathura #4
Posted 07 March 2012 - 12:52 PM
Idea sounds nice. I'm currently doing database software, which you could use to save more than 1 message. It's separated to API, launcher and my own gui, but for integrating it to this you would need only API. Ofc, there seems to be already another database software, wich I don't know much. You should try it, thought.
Wolvan #5
Posted 07 March 2012 - 01:37 PM
Hi, first post!

I actually recently made something very similar to this, it's up on youtube as a video so you can see how I solved the problem there
.
This looks like you're using just the one computer for sharing messages between users. If that's the plan you're not far off- instead of having a single message that's loaded when the application is started you might want to have a file you write the messages to, which is read each time the program is restarted. Then it's a matter of cycling through them by hitting the enter key or something similar and they can be deleted. You'll want to keep a global table near the top of your class and maybe write a function that reads in the file to populate the table with all the messages that have been stored.
If you're trying to do it similar to dropbox, that is to say files shared together on multiple computers you're going to require a server that keeps the master copies of those files (in this case messages) that can be accessed and modified by the user computers. That's a much trickier job and you'll have to think about what access you want your users to have and how your server will handle things like concurrency and storage. The yahoo style you mentioned would be fairly easy to implement, observing if a file was accessed and deleting or archiving after it is read.

Hope that helps.
That with the master server was my idea too and I already wanted to help him program it but then my minecraft crashed :l
Idea sounds nice. I'm currently doing database software, which you could use to save more than 1 message. It's separated to API, launcher and my own gui, but for integrating it to this you would need only API. Ofc, there seems to be already another database software, wich I don't know much. You should try it, thought.
This would be pretty useful in this case :mellow:/>/>
nitrogenfingers #6
Posted 07 March 2012 - 01:57 PM
That with the master server was my idea too and I already wanted to help him program it but then my minecraft crashed :l

Sorry didn't mean to steal your thunder! It is definitely the best idea.
Wolvan #7
Posted 07 March 2012 - 04:46 PM
That with the master server was my idea too and I already wanted to help him program it but then my minecraft crashed :l

Sorry didn't mean to steal your thunder! It is definitely the best idea.
No problem pro :mellow:/>/> I don't mind and I didn't want to sound like I did