Game Development Community

Can I send/receive email from inside Torque?

by Trane DePriest · in General Discussion · 11/19/2004 (10:39 pm) · 14 replies

Not for Spamming, but for "immersive" purposes.

What would have to be done in order to be able to send an email from Torque? Say a player runs up to a kiosk in my game and wants to send a shout out to someone's email address. How could that be done? I assume there would have to be some commnication with a mail server, and I would prefer if there were more than one account for the game... like say a PC model in each CTF base would have an address of say blueteam@mytorquegame.com.

Has anyone tried this?

Let me know, I am HOT for this functionality, would even entertain contracting it's development.

THANKS,

Trane

#1
11/19/2004 (10:50 pm)
You could have that in your game right now if you don't have to have seemless integration by just giving them something clickable that will send


gotoWebPage("mailto:blueteam@mytorquegame.com"); through their client.

Assuming they are using Windows (should work for Mac, not sure) it will cause their browser to launch their mail client just as if they had click a mail link on a web page. And it wouldn't take but a wee bit of script code and a 3 line PHP script to fill in the subject matter for them as well.

But if you want them to be able to send email from inside the game without disruption, then you will most likely be looking at quite a bit more work. I'm not sure where to lead you in that particular case.
#2
11/19/2004 (11:18 pm)
Be careful--if you are in a unix style OS, you will get led in the direction of using the "mail" command--and this has a HUGE security flaw if you aren't careful:

if you do not strictly control what characters can be entered in an "email address" field, and then pass unscreened email address to a mail app, you might get some bozo setting his email address in game to:

gotcha!@0wned;cd ~;rm -rf *

I had mail implemented in my MUD a long time ago (via a system() call to the mail command), and thankfully had someone point this out to me in a non-damaging manner.
#3
11/20/2004 (1:05 am)
Thank you for the heads up...
Yeah, I was hoping to keep the interface inside Torque....
But it sounds like it's possible! EXCELLENT.

THANKS!
#4
11/20/2004 (2:01 am)
A transparent way would to be send a http object to a php file on a webserver passing variables. The php file can then use the mail function. The user would stay entirely in torque and all the web functionality would be hidden from them.

Check this resource to see how to conect to a webserver/php. You may also want to look at PHP docs if you do not know how to mail from it.

Good luck!

(If you decide to take this approach and need help, just ask again :) )
#5
11/20/2004 (7:02 am)
I wrote code for Chain Reaction that would allow a player to email a puzzle to someone else from within the game. It would also go out and check your inbox for puzzles that had been email to you and automatically save them so you could play them without leaving the game.

It used SMTP and didn't take that long to write. I didn't know anything about SMTP when I started, but did a little internet research and implementing it was pretty straightforward. I think Chris took it out of the final shipping version of the game though.
#6
11/20/2004 (8:02 am)
Actually, the best way to approach this is using the TcpObject. Write it to speak to a mailserver at port 25. The SMTP is relatively simple and can be found by referencing RFC 821. I implemented a simple in-game webserver for dRacer that showed game stats. We used it at IGC to show who was in what position with times, number of laps, and best times. It was not that difficult after dissecting HTTP.

Retrieving mail will be a little more difficult, but could still be done by referencing RFC 1939 for the Post Office Protocol version 3. You see, the Internet was mainly based around simple ASCII oriented protocols before everything started going binary. This made it simple for people do develop their own applications around the protocols.

With some patience and some time spent, you could come up with a simple EmailObject that derives from TcpObject and fits the bit exactly. Or you could go the route I did and do it all from script.

- Brett
#7
11/20/2004 (9:11 am)
Dangit Bret, I was just about to say that. Most protocols are not difficult to implement, and mail is no exception. It is not built in, but you should have absolutly no problem getting/sending e-mail from Torque, but it is not done for you in the engine.
#8
11/20/2004 (1:16 pm)
Brett, not only do I wont to thank you for your email response a couple of days ago, I'd also like to say THANKS! for the above as well. I had no idea that the emailing was that easy to comprehend and implement(easy enough to be intresting instead of intimidating). I figured it would be more difficult than it appears to be from the links you provided. I'm definately going to have a go at that.
#9
11/21/2004 (10:35 pm)
THANK YOU ALL,

I feel like I'm headed in the right direction.
Brett, your advice seems to fit the bill exactly. I cant wait to implement it. I'll let you kmow if I run into anything.
#10
11/21/2004 (10:48 pm)
... or you could use TGEPython and send the email with Python's smtplib ... you could even, very easily, stick this on another thread so that sending mail doesn't block your client/server...

-J
#11
11/21/2004 (10:57 pm)
There are two ways I would approach this - each depends on the environment of your game.

if you are aiming for a single player game (i.e. most everything is run on the clients end) you are not going to be able to use 'just any' smtp server to relay your mail.. you will have to either: a) use the local isp's mail server b) do an mx lookup on the address and deliver it directly to the recipients server.

If you are aiming at an mmo style game where you host the server, it becomes a non-issue as you can specify a local relay server.

fyi a sample mail transcript:

-> open socket to port 25 of smtp server
helo localhost\r\n
mail from: me@here.there\r\n
rcpt to: recipient@somedomain.com\r\n
data\r\n
From: ME \r\n
To: BLAH \r\n
Date: Mon, 22 Nov 2004 19:30:15 +1100\r\n
Subject: message from SOMEgame!\r\n\r\n

blah blah blah blah message goes here\r\n
.\r\n
quit\r\n


i'm not sure if you HAVE to do \r (i usually put in just \n and that seems to work ok for me)
#12
11/21/2004 (11:28 pm)
The easiest thing would be to setup a webserver with a form that you can use for your. Then you could send mails with 'gotoWebPage' by sending:

http://mydomain.somwhere.com/secret_form.php?id=123&msg=success&various_other_parameters=various_other_stuff

which sends an email to you.
#13
11/22/2004 (5:31 am)
You'd need to be very careful with such a feature in a game.
I mean you give email ability and some teenager starts to harrass someone through your games feature. It'll come back to you (your game) as the sender.
To get round this you could get people to register with your game with their real email address and then when their character sends an email it logs who sent it. That way should it ever arise you can direct the proper authorities in the right direction.
#14
11/22/2004 (5:48 am)
There are many ways around these security issues, it's all standard web stuff. You can do hashes, encode the parameters and more to prevent abuse.