diff --git a/conf/wmud.conf.example b/conf/wmud.conf.example index 74ebf42..73d6f34 100644 --- a/conf/wmud.conf.example +++ b/conf/wmud.conf.example @@ -41,3 +41,23 @@ trainable abilities = true # If set to true, characters can choose to die, and reborn in a new body if # they are old enough (80% of the racial maximum age) reborn = true + +# SMTP related settings go here. SMTP is required to send out initially +# generated passwords +[smtp] + +# The SMTP server's address +smtp server = smtp.gmail.com + +# Set to true if the SMTP server provides or requires TLS connections +smtp tls = true + +# The username to use to send e-mails +smtp username = wmud + +# The password to use to send e-mails +smtp password = wmudPassWD1 + +# The sender's e-mail address. This will appear in all sent e-mails. Should be +# in the form Name , where Name can be omitted +smtp sender = wMUD diff --git a/wmud/configuration.c b/wmud/configuration.c index 52ae275..7499a88 100644 --- a/wmud/configuration.c +++ b/wmud/configuration.c @@ -61,6 +61,18 @@ wmud_configdata_free(ConfigData **config_data) if ((*config_data)->database_file) g_free((*config_data)->database_file); + if ((*config_data)->smtp_server) + g_free((*config_data)->smtp_server); + + if ((*config_data)->smtp_username) + g_free((*config_data)->smtp_username); + + if ((*config_data)->smtp_password) + g_free((*config_data)->smtp_password); + + if ((*config_data)->smtp_sender) + g_free((*config_data)->smtp_sender); + g_free(*config_data); *config_data = NULL; } @@ -110,6 +122,15 @@ wmud_config_init(ConfigData **config_data, GError **err) return FALSE; } + if (!g_key_file_has_group(config, "smtp")) + { + g_set_error(err, WMUD_CONFIG_ERROR, WMUD_CONFIG_ERROR_NOSMTP, "Config file (%s) does not contain an [smtp] group", config_file->str); + g_key_file_free(config); + g_string_free(config_file, TRUE); + + return FALSE; + } + g_clear_error(&in_err); (*config_data)->port = g_key_file_get_integer(config, "global", "port", &in_err); if (in_err) @@ -161,6 +182,36 @@ wmud_config_init(ConfigData **config_data, GError **err) } } + g_clear_error(&in_err); + (*config_data)->smtp_server = g_key_file_get_string(config, "smtp", "smtp server", &in_err); + if (in_err) + { + if (g_error_matches(in_err, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) + { + g_set_error(err, WMUD_CONFIG_ERROR, WMUD_CONFIG_ERROR_NOSMTPSERVER, "Config file (%s) does not contain an smtp server address", config_file->str); + g_key_file_free(config); + g_string_free(config_file, TRUE); + wmud_configdata_free(config_data); + + return FALSE; + } + } + + g_clear_error(&in_err); + (*config_data)->smtp_sender = g_key_file_get_string(config, "smtp", "smtp sender", &in_err); + if (in_err) + { + if (g_error_matches(in_err, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) + { + g_set_error(err, WMUD_CONFIG_ERROR, WMUD_CONFIG_ERROR_NOSMTPSENDER, "Config file (%s) does not contain an smtp sender name", config_file->str); + g_key_file_free(config); + g_string_free(config_file, TRUE); + wmud_configdata_free(config_data); + + return FALSE; + } + } + g_key_file_free(config); g_string_free(config_file, TRUE); diff --git a/wmud/configuration.h b/wmud/configuration.h index c5230c5..34d37ac 100644 --- a/wmud/configuration.h +++ b/wmud/configuration.h @@ -26,7 +26,10 @@ typedef enum { WMUD_CONFIG_ERROR_BADPORT, WMUD_CONFIG_ERROR_NOWORLD, WMUD_CONFIG_ERROR_NOEMAIL, - WMUD_CONFIG_ERROR_REUSE + WMUD_CONFIG_ERROR_REUSE, + WMUD_CONFIG_ERROR_NOSMTP, + WMUD_CONFIG_ERROR_NOSMTPSERVER, + WMUD_CONFIG_ERROR_NOSMTPSENDER } wmudConfigError; /** @@ -40,6 +43,11 @@ typedef struct _ConfigData { guint port; gchar *database_file; gchar *admin_email; + gchar *smtp_server; + gboolean smtp_tls; + gchar *smtp_username; + gchar *smtp_password; + gchar *smtp_sender; } ConfigData; extern ConfigData *active_config;