Start parsing options in the new way
This commit is contained in:
parent
3059bde5f0
commit
6eb1e09cc3
@ -32,7 +32,10 @@ wmud_SOURCES = \
|
|||||||
enumtypes.h \
|
enumtypes.h \
|
||||||
enumtypes.c \
|
enumtypes.c \
|
||||||
wmudworld.c \
|
wmudworld.c \
|
||||||
wmudworld.h
|
wmudworld.h \
|
||||||
|
wmud-configuration.c \
|
||||||
|
wmud-configuration.h \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
wmud_LDADD = $(MEMCACHED_LIBS) $(GLIB_LIBS) $(GIO_LIBS) $(GTHREAD_LIBS) $(GDA_LIBS) $(CURL_LIBS)
|
wmud_LDADD = $(MEMCACHED_LIBS) $(GLIB_LIBS) $(GIO_LIBS) $(GTHREAD_LIBS) $(GDA_LIBS) $(CURL_LIBS)
|
||||||
|
|
||||||
|
22
wmud/main.c
22
wmud/main.c
@ -39,6 +39,8 @@
|
|||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "texts.h"
|
#include "texts.h"
|
||||||
|
|
||||||
|
#include "wmud-configuration.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SECTION:utils
|
* SECTION:utils
|
||||||
* @short_description: Utilities and uncategorized functions
|
* @short_description: Utilities and uncategorized functions
|
||||||
@ -193,16 +195,32 @@ wmud_logger(const gchar *log_domain,
|
|||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
GError *err = NULL;
|
|
||||||
GThread *game_thread;
|
GThread *game_thread;
|
||||||
GMainContext *game_context;
|
GMainContext *game_context;
|
||||||
|
GError *err = NULL;
|
||||||
GSList *game_menu = NULL;
|
GSList *game_menu = NULL;
|
||||||
|
WmudConfiguration *current_config = NULL;
|
||||||
|
gchar *filename = NULL;
|
||||||
|
|
||||||
g_log_set_handler(G_LOG_DOMAIN, G_LOG_LEVEL_MASK, wmud_logger, NULL);
|
g_log_set_handler(G_LOG_DOMAIN, G_LOG_LEVEL_MASK, wmud_logger, NULL);
|
||||||
|
|
||||||
/* TODO: Command line parsing */
|
current_config = wmud_configuration_new();
|
||||||
|
|
||||||
|
// Process command line options
|
||||||
|
wmud_configuration_update_from_cmdline(
|
||||||
|
current_config,
|
||||||
|
&argc, &argv,
|
||||||
|
NULL);
|
||||||
|
|
||||||
/* TODO: Create signal handlers! */
|
/* TODO: Create signal handlers! */
|
||||||
|
|
||||||
|
if ((filename = wmud_configuration_get_filename(current_config)) == NULL) {
|
||||||
|
filename = WMUD_CONFDIR "/wmud.conf";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process configuration file
|
||||||
|
wmud_configuration_update_from_file(current_config, filename, NULL);
|
||||||
|
|
||||||
if (!wmud_config_init(&active_config, &err)) {
|
if (!wmud_config_init(&active_config, &err)) {
|
||||||
if (err) {
|
if (err) {
|
||||||
g_critical("Config file parsing error: %s", err->message);
|
g_critical("Config file parsing error: %s", err->message);
|
||||||
|
@ -2,19 +2,21 @@
|
|||||||
|
|
||||||
typedef struct _WmudConfigurationPrivate {
|
typedef struct _WmudConfigurationPrivate {
|
||||||
gchar *file_name;
|
gchar *file_name;
|
||||||
guint port;
|
GKeyFile *key_file;
|
||||||
gchar *database_dsn;
|
|
||||||
gchar *admin_email;
|
gchar *admin_email;
|
||||||
gchar *smtp_server;
|
gboolean *hide_single_race;
|
||||||
gboolean smtp_tls;
|
gboolean *hide_single_class;
|
||||||
gchar *smtp_username;
|
guint *house_occupy_time;
|
||||||
gchar *smtp_password;
|
guint *minimum_deities;
|
||||||
gchar *smtp_sender;
|
gboolean *clan_wars;
|
||||||
|
guint *maximum_group_size;
|
||||||
|
guint *trainable_abilities;
|
||||||
|
gboolean *reborn;
|
||||||
} WmudConfigurationPrivate;
|
} WmudConfigurationPrivate;
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_PRIVATE(WmudConfiguration,
|
G_DEFINE_TYPE_WITH_PRIVATE(WmudConfiguration,
|
||||||
wmud_configuration,
|
wmud_configuration,
|
||||||
G_TYPE_KEY_FILE);
|
G_TYPE_OBJECT);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
wmud_configuration_finalize(GObject *gobject)
|
wmud_configuration_finalize(GObject *gobject)
|
||||||
@ -34,8 +36,97 @@ wmud_configuration_class_init(WmudConfigurationClass *klass)
|
|||||||
static void
|
static void
|
||||||
wmud_configuration_init(WmudConfiguration *configuration)
|
wmud_configuration_init(WmudConfiguration *configuration)
|
||||||
{
|
{
|
||||||
|
WmudConfigurationPrivate *priv = wmud_configuration_get_instance_private(
|
||||||
|
configuration);
|
||||||
|
|
||||||
|
priv->key_file = NULL;
|
||||||
|
priv->file_name = NULL;
|
||||||
|
priv->admin_email = NULL;
|
||||||
|
priv->hide_single_race = NULL;
|
||||||
|
priv->hide_single_class = NULL;
|
||||||
|
priv->house_occupy_time = NULL;
|
||||||
|
priv->minimum_deities = NULL;
|
||||||
|
priv->clan_wars = NULL;
|
||||||
|
priv->maximum_group_size = NULL;
|
||||||
|
priv->trainable_abilities = NULL;
|
||||||
|
priv->reborn = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wmud_configuration_update_from_cmdline(WmudConfiguration *configuration,
|
||||||
|
gint *argc,
|
||||||
|
gchar **argv[],
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
WmudConfigurationPrivate *priv = wmud_configuration_get_instance_private(
|
||||||
|
configuration);
|
||||||
|
GOptionEntry entries[] = {
|
||||||
|
{
|
||||||
|
"config-file", 'c',
|
||||||
|
0,
|
||||||
|
G_OPTION_ARG_FILENAME,
|
||||||
|
&(priv->file_name),
|
||||||
|
"The name of the configuration file to parse",
|
||||||
|
"FILE"
|
||||||
|
},
|
||||||
|
{NULL}
|
||||||
|
};
|
||||||
|
GError *err = NULL;
|
||||||
|
GOptionContext *context;
|
||||||
|
|
||||||
|
context = g_option_context_new("- Yet Another MUD Engine");
|
||||||
|
g_option_context_add_main_entries(context, entries, NULL);
|
||||||
|
|
||||||
|
if (!g_option_context_parse(context, argc, argv, &err)) {
|
||||||
|
g_print("Option parsing failed: %s\n", err->message);
|
||||||
|
|
||||||
|
g_object_unref(configuration);
|
||||||
|
|
||||||
|
// TODO: Update error!
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_print("Config file: %s\n", priv->file_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wmud_configuration_update_from_file(WmudConfiguration *configuration,
|
||||||
|
gchar *filename,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
WmudConfigurationPrivate *priv = wmud_configuration_get_instance_private(
|
||||||
|
configuration);
|
||||||
|
|
||||||
|
// Save the file name for possible later use
|
||||||
|
priv->file_name = g_strdup(filename);
|
||||||
|
|
||||||
|
priv->key_file = g_key_file_new();
|
||||||
|
|
||||||
|
if (!g_key_file_load_from_file(priv->key_file,
|
||||||
|
filename,
|
||||||
|
G_KEY_FILE_NONE,
|
||||||
|
error)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WmudConfiguration *
|
WmudConfiguration *
|
||||||
wmud_configuration_new(gchar *filename)
|
wmud_configuration_new(void)
|
||||||
{}
|
{
|
||||||
|
WmudConfiguration *configuration = g_object_new(
|
||||||
|
WMUD_TYPE_CONFIGURATION, NULL);
|
||||||
|
|
||||||
|
// TODO: Update with built-in defaults
|
||||||
|
|
||||||
|
return configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
gchar *
|
||||||
|
wmud_configuration_get_filename(WmudConfiguration *configuration)
|
||||||
|
{
|
||||||
|
WmudConfigurationPrivate *priv = wmud_configuration_get_instance_private(
|
||||||
|
configuration);
|
||||||
|
|
||||||
|
return priv->file_name;
|
||||||
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef __WMUD_CONFIGURATION_H__
|
#ifndef __WMUD_WMUD_CONFIGURATION_H__
|
||||||
#define __WMUD_CONFIGURATION_H__
|
#define __WMUD_WMUD_CONFIGURATION_H__
|
||||||
|
|
||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
|
|
||||||
@ -17,17 +17,28 @@ typedef struct _WmudConfigurationClass WmudConfigurationClass;
|
|||||||
|
|
||||||
struct _WmudConfiguration {
|
struct _WmudConfiguration {
|
||||||
/* Parent instance structure */
|
/* Parent instance structure */
|
||||||
GKeyFile parent_instance;
|
GObject parent_instance;
|
||||||
|
|
||||||
/* Instance members */
|
/* Instance members */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _WmudConfigurationClass {
|
struct _WmudConfigurationClass {
|
||||||
GKeyFileClass parent_class;
|
GObjectClass parent_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
GType wmud_configuration_get_type(void) G_GNUC_CONST;
|
GType wmud_configuration_get_type(void) G_GNUC_CONST;
|
||||||
|
|
||||||
|
WmudConfiguration *wmud_configuration_new(void);
|
||||||
|
void wmud_configuration_update_from_cmdline(WmudConfiguration *configuration,
|
||||||
|
gint *argc,
|
||||||
|
gchar **argv[],
|
||||||
|
GError **error);
|
||||||
|
void wmud_configuration_update_from_file(WmudConfiguration *configuration,
|
||||||
|
gchar *filename,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
|
gchar *wmud_configuration_get_filename(WmudConfiguration *configuration);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __WMUD_CONFIGURATION_H__ */
|
#endif /* __WMUD_WMUD_CONFIGURATION_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user