Posted 05 January 2013 - 05:59 AM
Hi,
First of all, I apologise in advance just in case I do something wrong when it comes to this post, I have never done anything like this before and I hope you guys like it!
I have been working with ComputerCraft for around 36 hours so I'm pretty proud of this creation myself, and I was helped by my friend who knows a bit of ruby for when it comes to the server side stuff…
I have no idea if this has been done before and if it has, please tell me about it!
Now for the good stuff:
Ok, so basically, I have seen some people who have sent emails with RedNet but obviously that doesn't work as well in a storm or for anyone who is not on the same server…
Well, with this, you can talk to anyone on the same server, different server or even in single player and you don't even need a modem.
I am however using the http api which the server admins would need to enable.
So to the code:
I have made two programs for on the computer, one for sending mail and one for checking your inbox, there is barely any security but that can be added in later.
sendMail {13 lines}:
checkMail {6 lines}:
Server side (Ruby) {6 lines}:
First of all, I apologise in advance just in case I do something wrong when it comes to this post, I have never done anything like this before and I hope you guys like it!
I have been working with ComputerCraft for around 36 hours so I'm pretty proud of this creation myself, and I was helped by my friend who knows a bit of ruby for when it comes to the server side stuff…
I have no idea if this has been done before and if it has, please tell me about it!
Now for the good stuff:
Ok, so basically, I have seen some people who have sent emails with RedNet but obviously that doesn't work as well in a storm or for anyone who is not on the same server…
Well, with this, you can talk to anyone on the same server, different server or even in single player and you don't even need a modem.
I am however using the http api which the server admins would need to enable.
So to the code:
I have made two programs for on the computer, one for sending mail and one for checking your inbox, there is barely any security but that can be added in later.
sendMail {13 lines}:
fs.makeDir('/CCMail')
function input(prompt)
print(prompt)
entered = io.read()
term.clear()
term.setCursorPos(1,1)
return textutils.urlEncode(entered)
end
from = input('Who are you?')
file = fs.open('/CCMail/'..from, 'w')
print(http.post('http://shoalnet.org:4567/', 'from='..from..'&to='..input('Who are you sending a message to?')..'&message='..input('What would you like to say?')).readAll())
file.write(http.post('http://shoalnet.org:4567/', 'from='..from..'&to=checkmail&message=').readAll())
file.close()
checkMail {6 lines}:
print("Who are you?")
from = io.read()
file = fs.open('/CCMail/'..from, 'w')
print(http.post('http://shoalnet.org:4567/', 'from='..from..'&to=checkmail&message=').readAll())
file.write(http.post('http://shoalnet.org:4567/', 'from='..from..'&to=checkmail&message=').readAll())
file.close()
Server side (Ruby) {6 lines}:
require 'sinatra'
messages={}
post '/' do
messages[params['to']]=messages[params['to']].to_s + ['Message From ' + params['from'], 'Message To ' + params['to'], 'Message:', params['message'], '', ''].join("\n")
messages[params['from']]
end