26 Nov, 2009, quixadhal wrote in the 21st comment:
Votes: 0
I agree David, I was just saying that minimizing the impact of requiring one won't cost you as many players as the old "You can't play until we approve you" scenario. Personally, I like the idea of requiring one AFTER they finish the newbie content. If they finish that, they probably are interested enough to want to keep playing anyways, and tossing you a yahoo or gmail address isn't a big deal to most people.

Here's a quicky SMTP mail client. It's not perfect, and probably needs a bit more stringent error checking, but it works for my single test case. Obviously, you'll want to replace localhost with your mail server's address if you're on windoze (or don't run an MTA locally).

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdarg.h>

#define bomb(s) { perror((s)); return 0; }

void socket_write( int sock, const char *s, … ) {
va_list arg;
int len;
char buf[256];

va_start(arg, s);
vsprintf(buf, s, arg);
va_end(arg);

len = write( sock, buf, strlen( buf ) );
/* fprintf(stderr, "DEBUG socket_write: %d: %s\n", len, buf); */
}

int socket_read( int sock ) {
int len;
int code;
char buf[256];

len = read( sock, buf, 255 );
/* fprintf(stderr, "DEBUG socket_read: %d: %s\n", len, buf); */
code = atoi( buf );
return code;
}

int smtp_send_message( char *ip, int port, char *host, char *from, char *to, char *subject, char *body ) {
int smtp;
struct sockaddr_in smtp_server;
struct hostent *smtp_host;

smtp = socket( AF_INET, SOCK_STREAM, 0 );
if( smtp == -1 )
bomb( "Can't open socket!" );

smtp_server.sin_family = AF_INET;
smtp_host = gethostbyname( ip );
if( !smtp_host )
bomb( "Can't find SMTP host!" );

memcpy( (char *) &smtp_server.sin_addr, (char *) smtp_host->h_addr, smtp_host->h_length );
smtp_server.sin_port = htons( port );
if( connect( smtp, (struct sockaddr *) &smtp_server, sizeof smtp_server ) == -1 )
bomb( "Can't connect to SMTP server!" );

if( socket_read( smtp ) != 220 ) bomb( "Not an SMTP server!" );
socket_write( smtp, "HELO %s\r\n", host );
if( socket_read( smtp ) != 250 ) bomb( "Bad HELO!" );
socket_write( smtp, "MAIL FROM: %s\r\n", from );
if( socket_read( smtp ) != 250 ) bomb( "Bad FROM!" );
socket_write( smtp, "VRFY %s\r\n", to );
if( socket_read( smtp ) != 250 ) perror( "Unverifiable TO!" );
socket_write( smtp, "RCPT TO: %s\r\n", to );
if( socket_read( smtp ) != 250 ) bomb( "Invalid TO!" );
socket_write( smtp, "DATA\r\n" );
if( socket_read( smtp ) != 354 ) bomb( "Invalid DATA Command?" );
socket_write( smtp, "Subject: %s\r\n", subject );
socket_write( smtp, "%s\r\n", body );
socket_write( smtp, ".\r\n");
if( socket_read( smtp ) != 250 ) bomb( "Invalid DATA!" );
socket_write( smtp, "QUIT\r\n" );
if( socket_read( smtp ) != 221 ) perror( "Invalid Closure." );

close( smtp );
return 1;
}

int main( int argc, char **argv ) {
return smtp_send_message( "127.0.0.1", 25,
"localhost", "root@localhost", "victim@localhost",
"Testing 123",
"This is a test.\r\nSend money.\r\n" );
}
20.0/21