Uncrustify sources
This commit is contained in:
parent
1c88c88b63
commit
e820f2308a
140
uncrustify.cfg
Normal file
140
uncrustify.cfg
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
newlines lf
|
||||||
|
|
||||||
|
input_tab_size 8
|
||||||
|
output_tab_size 8
|
||||||
|
|
||||||
|
string_escape_char 92
|
||||||
|
string_escape_char2 0
|
||||||
|
|
||||||
|
# indenting
|
||||||
|
indent_columns 4
|
||||||
|
indent_with_tabs 0
|
||||||
|
indent_align_string True
|
||||||
|
indent_brace 0
|
||||||
|
indent_braces False
|
||||||
|
indent_braces_no_func True
|
||||||
|
indent_func_call_param False
|
||||||
|
indent_func_def_param False
|
||||||
|
indent_func_proto_param False
|
||||||
|
indent_switch_case indent_columns
|
||||||
|
indent_case_brace indent_columns
|
||||||
|
indent_paren_close 1
|
||||||
|
indent_var_def_cont False
|
||||||
|
|
||||||
|
# spacing
|
||||||
|
sp_arith Add
|
||||||
|
sp_assign Add
|
||||||
|
sp_enum_assign Add
|
||||||
|
sp_bool Add
|
||||||
|
sp_compare Add
|
||||||
|
sp_inside_paren Remove
|
||||||
|
sp_inside_fparens Remove
|
||||||
|
sp_func_def_paren Remove
|
||||||
|
sp_func_proto_paren Remove
|
||||||
|
sp_paren_paren Remove
|
||||||
|
sp_balance_nested_parens False
|
||||||
|
sp_paren_brace Remove
|
||||||
|
sp_before_square Remove
|
||||||
|
sp_before_squares Remove
|
||||||
|
sp_inside_square Remove
|
||||||
|
sp_after_comma Add
|
||||||
|
sp_before_comma Remove
|
||||||
|
sp_after_cast Remove
|
||||||
|
sp_sizeof_paren Remove
|
||||||
|
sp_not Remove
|
||||||
|
sp_inv Remove
|
||||||
|
sp_addr Remove
|
||||||
|
sp_member Remove
|
||||||
|
sp_deref Remove
|
||||||
|
sp_sign Remove
|
||||||
|
sp_incdec Remove
|
||||||
|
sp_attribute_paren Remove
|
||||||
|
sp_macro Force
|
||||||
|
sp_func_call_paren Remove
|
||||||
|
sp_brace_typedef add
|
||||||
|
sp_cond_colon add
|
||||||
|
sp_cond_question add
|
||||||
|
sp_defined_paren Remove
|
||||||
|
sp_inside_paren_cast Ignore
|
||||||
|
sp_else_brace Add
|
||||||
|
sp_between_ptr_star Remove
|
||||||
|
sp_before_ptr_star Add
|
||||||
|
|
||||||
|
# alignment
|
||||||
|
align_keep_tabs False
|
||||||
|
align_with_tabs False
|
||||||
|
align_on_tabstop False
|
||||||
|
align_number_left True
|
||||||
|
align_func_params True
|
||||||
|
align_var_def_span 2
|
||||||
|
align_var_def_amp_style 1
|
||||||
|
align_var_def_colon True
|
||||||
|
align_enum_equ_span 0
|
||||||
|
align_var_struct_span 2
|
||||||
|
align_var_def_star_style 1
|
||||||
|
align_var_def_amp_style 1
|
||||||
|
align_typedef_span 2
|
||||||
|
align_typedef_func 0
|
||||||
|
align_typedef_star_style 1
|
||||||
|
align_typedef_amp_style 2
|
||||||
|
align_var_def_inline True
|
||||||
|
align_assign_span 1
|
||||||
|
align_pp_define_together True
|
||||||
|
|
||||||
|
# newlines
|
||||||
|
nl_assign_leave_one_liners True
|
||||||
|
nl_enum_leave_one_liners False
|
||||||
|
nl_func_leave_one_liners False
|
||||||
|
nl_if_leave_one_liners False
|
||||||
|
nl_end_of_file Add
|
||||||
|
nl_end_of_file_min 2
|
||||||
|
nl_assign_brace Remove
|
||||||
|
nl_func_var_def_blk 1
|
||||||
|
nl_fcall_brace Add
|
||||||
|
nl_enum_brace Remove
|
||||||
|
nl_struct_brace Remove
|
||||||
|
nl_union_brace Remove
|
||||||
|
nl_if_brace Remove
|
||||||
|
nl_brace_else Remove
|
||||||
|
nl_elseif_brace Remove
|
||||||
|
nl_else_brace Remove
|
||||||
|
nl_for_brace Remove
|
||||||
|
nl_while_brace Remove
|
||||||
|
nl_do_brace Remove
|
||||||
|
nl_brace_while Remove
|
||||||
|
nl_switch_brace Remove
|
||||||
|
nl_before_case True
|
||||||
|
nl_after_case True
|
||||||
|
nl_func_type_name Force
|
||||||
|
nl_func_proto_type_name Remove
|
||||||
|
nl_func_paren Remove
|
||||||
|
nl_func_decl_start Remove
|
||||||
|
nl_func_decl_args Force
|
||||||
|
nl_func_decl_end Remove
|
||||||
|
nl_fdef_brace Force
|
||||||
|
nl_after_return False
|
||||||
|
nl_define_macro False
|
||||||
|
nl_create_if_one_liner False
|
||||||
|
nl_create_for_one_liner False
|
||||||
|
nl_create_while_one_liner False
|
||||||
|
nl_after_semicolon True
|
||||||
|
nl_multi_line_cond False
|
||||||
|
nl_var_def_blk_in 2
|
||||||
|
nl_multi_line_define True
|
||||||
|
|
||||||
|
# mod
|
||||||
|
mod_full_brace_for Force
|
||||||
|
mod_full_brace_if Force
|
||||||
|
mod_full_brace_while Force
|
||||||
|
mod_full_brace_do Remove
|
||||||
|
mod_full_brace_nl 3
|
||||||
|
mod_paren_on_return Remove
|
||||||
|
|
||||||
|
# line splitting
|
||||||
|
#code_width = 78
|
||||||
|
ls_for_split_full True
|
||||||
|
ls_func_split_full True
|
||||||
|
|
||||||
|
# positioning
|
||||||
|
pos_bool Trail
|
||||||
|
pos_conditional Lead
|
@ -54,23 +54,29 @@ wmud_config_error_quark()
|
|||||||
void
|
void
|
||||||
wmud_configdata_free(ConfigData **config_data)
|
wmud_configdata_free(ConfigData **config_data)
|
||||||
{
|
{
|
||||||
if ((*config_data)->admin_email)
|
if ((*config_data)->admin_email) {
|
||||||
g_free((*config_data)->admin_email);
|
g_free((*config_data)->admin_email);
|
||||||
|
}
|
||||||
|
|
||||||
if ((*config_data)->database_dsn)
|
if ((*config_data)->database_dsn) {
|
||||||
g_free((*config_data)->database_dsn);
|
g_free((*config_data)->database_dsn);
|
||||||
|
}
|
||||||
|
|
||||||
if ((*config_data)->smtp_server)
|
if ((*config_data)->smtp_server) {
|
||||||
g_free((*config_data)->smtp_server);
|
g_free((*config_data)->smtp_server);
|
||||||
|
}
|
||||||
|
|
||||||
if ((*config_data)->smtp_username)
|
if ((*config_data)->smtp_username) {
|
||||||
g_free((*config_data)->smtp_username);
|
g_free((*config_data)->smtp_username);
|
||||||
|
}
|
||||||
|
|
||||||
if ((*config_data)->smtp_password)
|
if ((*config_data)->smtp_password) {
|
||||||
g_free((*config_data)->smtp_password);
|
g_free((*config_data)->smtp_password);
|
||||||
|
}
|
||||||
|
|
||||||
if ((*config_data)->smtp_sender)
|
if ((*config_data)->smtp_sender) {
|
||||||
g_free((*config_data)->smtp_sender);
|
g_free((*config_data)->smtp_sender);
|
||||||
|
}
|
||||||
|
|
||||||
g_free(*config_data);
|
g_free(*config_data);
|
||||||
*config_data = NULL;
|
*config_data = NULL;
|
||||||
@ -100,7 +106,9 @@ wmud_config_init(ConfigData **config_data, GError **err)
|
|||||||
|
|
||||||
if (*config_data) {
|
if (*config_data) {
|
||||||
g_clear_error(err);
|
g_clear_error(err);
|
||||||
g_set_error(err, WMUD_CONFIG_ERROR, WMUD_CONFIG_ERROR_REUSE, "Configuration pointer reuse. Please file a bug report!");
|
g_set_error(err,
|
||||||
|
WMUD_CONFIG_ERROR, WMUD_CONFIG_ERROR_REUSE,
|
||||||
|
"Configuration pointer reuse. Please file a bug report!");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +121,10 @@ wmud_config_init(ConfigData **config_data, GError **err)
|
|||||||
g_key_file_load_from_file(config, config_file->str, 0, &in_err);
|
g_key_file_load_from_file(config, config_file->str, 0, &in_err);
|
||||||
|
|
||||||
if (!g_key_file_has_group(config, "global")) {
|
if (!g_key_file_has_group(config, "global")) {
|
||||||
g_set_error(err, WMUD_CONFIG_ERROR, WMUD_CONFIG_ERROR_NOGLOBAL, "Config file (%s) does not contain a [global] group", config_file->str);
|
g_set_error(err,
|
||||||
|
WMUD_CONFIG_ERROR, WMUD_CONFIG_ERROR_NOGLOBAL,
|
||||||
|
"Config file (%s) does not contain a [global] group",
|
||||||
|
config_file->str);
|
||||||
g_key_file_free(config);
|
g_key_file_free(config);
|
||||||
g_string_free(config_file, TRUE);
|
g_string_free(config_file, TRUE);
|
||||||
|
|
||||||
@ -121,7 +132,10 @@ wmud_config_init(ConfigData **config_data, GError **err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!g_key_file_has_group(config, "smtp")) {
|
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_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_key_file_free(config);
|
||||||
g_string_free(config_file, TRUE);
|
g_string_free(config_file, TRUE);
|
||||||
|
|
||||||
@ -129,7 +143,11 @@ wmud_config_init(ConfigData **config_data, GError **err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!g_key_file_has_group(config, "database")) {
|
if (!g_key_file_has_group(config, "database")) {
|
||||||
g_set_error(err, WMUD_CONFIG_ERROR, WMUD_CONFIG_ERROR_NODATABASE, "Config file (%s) does not contain a [database] group", config_file->str);
|
g_set_error(err,
|
||||||
|
WMUD_CONFIG_ERROR,
|
||||||
|
WMUD_CONFIG_ERROR_NODATABASE,
|
||||||
|
"Config file (%s) does not contain a [database] group",
|
||||||
|
config_file->str);
|
||||||
g_key_file_free(config);
|
g_key_file_free(config);
|
||||||
g_string_free(config_file, TRUE);
|
g_string_free(config_file, TRUE);
|
||||||
|
|
||||||
@ -137,13 +155,22 @@ wmud_config_init(ConfigData **config_data, GError **err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_clear_error(&in_err);
|
g_clear_error(&in_err);
|
||||||
(*config_data)->port = g_key_file_get_integer(config, "global", "port", &in_err);
|
(*config_data)->port = g_key_file_get_integer(config,
|
||||||
if (in_err)
|
"global", "port",
|
||||||
{
|
&in_err);
|
||||||
if (g_error_matches(in_err, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
|
|
||||||
|
if (in_err) {
|
||||||
|
if (g_error_matches(in_err,
|
||||||
|
G_KEY_FILE_ERROR,
|
||||||
|
G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
|
||||||
(*config_data)->port = DEFAULT_PORT;
|
(*config_data)->port = DEFAULT_PORT;
|
||||||
} else if (g_error_matches(in_err, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE)) {
|
} else if (g_error_matches(in_err,
|
||||||
g_set_error(err, WMUD_CONFIG_ERROR, WMUD_CONFIG_ERROR_BADPORT, "Config file (%s) contains an invalid port number", config_file->str);
|
G_KEY_FILE_ERROR,
|
||||||
|
G_KEY_FILE_ERROR_INVALID_VALUE)) {
|
||||||
|
g_set_error(err,
|
||||||
|
WMUD_CONFIG_ERROR, WMUD_CONFIG_ERROR_BADPORT,
|
||||||
|
"Config file (%s) contains an invalid port number",
|
||||||
|
config_file->str);
|
||||||
g_key_file_free(config);
|
g_key_file_free(config);
|
||||||
g_string_free(config_file, TRUE);
|
g_string_free(config_file, TRUE);
|
||||||
(*config_data)->port = 0;
|
(*config_data)->port = 0;
|
||||||
@ -155,9 +182,16 @@ wmud_config_init(ConfigData **config_data, GError **err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_clear_error(&in_err);
|
g_clear_error(&in_err);
|
||||||
(*config_data)->admin_email = g_key_file_get_string(config, "global", "admin email", &in_err);
|
(*config_data)->admin_email = g_key_file_get_string(config,
|
||||||
if (in_err && g_error_matches(in_err, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
|
"global", "admin email",
|
||||||
g_set_error(err, WMUD_CONFIG_ERROR, WMUD_CONFIG_ERROR_NOEMAIL, "Config file (%s) does not contain an admin e-mail address", config_file->str);
|
&in_err);
|
||||||
|
if (in_err && 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_NOEMAIL,
|
||||||
|
"Config file (%s) does not contain an admin e-mail address",
|
||||||
|
config_file->str);
|
||||||
g_key_file_free(config);
|
g_key_file_free(config);
|
||||||
g_string_free(config_file, TRUE);
|
g_string_free(config_file, TRUE);
|
||||||
wmud_configdata_free(config_data);
|
wmud_configdata_free(config_data);
|
||||||
@ -166,9 +200,16 @@ wmud_config_init(ConfigData **config_data, GError **err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_clear_error(&in_err);
|
g_clear_error(&in_err);
|
||||||
(*config_data)->smtp_server = g_key_file_get_string(config, "smtp", "smtp server", &in_err);
|
(*config_data)->smtp_server = g_key_file_get_string(config,
|
||||||
if (in_err && g_error_matches(in_err, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
|
"smtp", "smtp server",
|
||||||
g_set_error(err, WMUD_CONFIG_ERROR, WMUD_CONFIG_ERROR_NOSMTPSERVER, "Config file (%s) does not contain an smtp server address", config_file->str);
|
&in_err);
|
||||||
|
if (in_err && 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_key_file_free(config);
|
||||||
g_string_free(config_file, TRUE);
|
g_string_free(config_file, TRUE);
|
||||||
wmud_configdata_free(config_data);
|
wmud_configdata_free(config_data);
|
||||||
@ -177,9 +218,16 @@ wmud_config_init(ConfigData **config_data, GError **err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_clear_error(&in_err);
|
g_clear_error(&in_err);
|
||||||
(*config_data)->smtp_sender = g_key_file_get_string(config, "smtp", "smtp sender", &in_err);
|
(*config_data)->smtp_sender = g_key_file_get_string(config,
|
||||||
if (in_err && g_error_matches(in_err, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
|
"smtp", "smtp sender",
|
||||||
g_set_error(err, WMUD_CONFIG_ERROR, WMUD_CONFIG_ERROR_NOSMTPSENDER, "Config file (%s) does not contain an smtp sender name", config_file->str);
|
&in_err);
|
||||||
|
if (in_err && 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_key_file_free(config);
|
||||||
g_string_free(config_file, TRUE);
|
g_string_free(config_file, TRUE);
|
||||||
wmud_configdata_free(config_data);
|
wmud_configdata_free(config_data);
|
||||||
@ -188,9 +236,16 @@ wmud_config_init(ConfigData **config_data, GError **err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_clear_error(&in_err);
|
g_clear_error(&in_err);
|
||||||
(*config_data)->database_dsn = g_key_file_get_string(config, "database", "dsn", &in_err);
|
(*config_data)->database_dsn = g_key_file_get_string(config,
|
||||||
if (in_err && g_error_matches(in_err, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
|
"database", "dsn",
|
||||||
g_set_error(err, WMUD_CONFIG_ERROR, WMUD_CONFIG_ERROR_NOWORLD, "Config file (%s) does not contain a database dsn", config_file->str);
|
&in_err);
|
||||||
|
if (in_err && 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_NOWORLD,
|
||||||
|
"Config file (%s) does not contain a database dsn",
|
||||||
|
config_file->str);
|
||||||
g_key_file_free(config);
|
g_key_file_free(config);
|
||||||
g_string_free(config_file, TRUE);
|
g_string_free(config_file, TRUE);
|
||||||
wmud_configdata_free(config_data);
|
wmud_configdata_free(config_data);
|
||||||
@ -198,7 +253,8 @@ wmud_config_init(ConfigData **config_data, GError **err)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pos = g_strstr_len((*config_data)->database_dsn, -1, "{statedir}")) != NULL) {
|
if ((pos = g_strstr_len((*config_data)->database_dsn,
|
||||||
|
-1, "{statedir}")) != NULL) {
|
||||||
guint real_pos = pos - (*config_data)->database_dsn;
|
guint real_pos = pos - (*config_data)->database_dsn;
|
||||||
GString *tmp = g_string_new((*config_data)->database_dsn);
|
GString *tmp = g_string_new((*config_data)->database_dsn);
|
||||||
|
|
||||||
@ -213,4 +269,3 @@ wmud_config_init(ConfigData **config_data, GError **err)
|
|||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
219
wmud/db.c
219
wmud/db.c
@ -63,11 +63,21 @@ wmud_db_init(GError **err)
|
|||||||
|
|
||||||
gda_init();
|
gda_init();
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Database DSN is \"%s\"", active_config->database_dsn);
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
||||||
dbh = gda_connection_open_from_string(NULL, active_config->database_dsn, NULL, GDA_CONNECTION_OPTIONS_THREAD_SAFE, &local_err);
|
"Database DSN is \"%s\"",
|
||||||
|
active_config->database_dsn);
|
||||||
|
dbh = gda_connection_open_from_string(NULL,
|
||||||
|
active_config->database_dsn,
|
||||||
|
NULL,
|
||||||
|
GDA_CONNECTION_OPTIONS_THREAD_SAFE,
|
||||||
|
&local_err);
|
||||||
|
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_CANTOPEN, "Can not open databsae (%s): %s", active_config->database_dsn, local_err->message);
|
g_set_error(err,
|
||||||
|
WMUD_DB_ERROR, WMUD_DB_ERROR_CANTOPEN,
|
||||||
|
"Can not open databsae (%s): %s",
|
||||||
|
active_config->database_dsn,
|
||||||
|
local_err->message);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -96,17 +106,32 @@ wmud_db_load_players(GError **err)
|
|||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading players");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading players");
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
if (err)
|
if (err)
|
||||||
g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT, "Database backend not initialized");
|
g_set_error(err,
|
||||||
|
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
||||||
|
"Database backend not initialized");
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
sth = gda_sql_parser_parse_string(parser, "SELECT id, login, password, email FROM players", NULL, NULL);
|
sth = gda_sql_parser_parse_string(
|
||||||
|
parser,
|
||||||
|
"SELECT id, login, password, email FROM players",
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
|
||||||
/* TODO: error checking! */
|
/* TODO: error checking! */
|
||||||
if ((res = gda_connection_statement_execute_select(dbh, sth, NULL, &local_err)) == NULL) {
|
if ((res = gda_connection_statement_execute_select(
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "Unable to load players: %s", local_err->message);
|
dbh,
|
||||||
g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_SELECT_ERROR, "SELECT error: %s", local_err->message);
|
sth,
|
||||||
|
NULL,
|
||||||
|
&local_err)) == NULL) {
|
||||||
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
|
||||||
|
"Unable to load players: %s",
|
||||||
|
local_err->message);
|
||||||
|
g_set_error(err,
|
||||||
|
WMUD_DB_ERROR, WMUD_DB_ERROR_SELECT_ERROR,
|
||||||
|
"SELECT error: %s",
|
||||||
|
local_err->message);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -132,7 +157,9 @@ wmud_db_load_players(GError **err)
|
|||||||
val = gda_data_model_iter_get_value_at(iter, 3);
|
val = gda_data_model_iter_get_value_at(iter, 3);
|
||||||
wmud_player_set_email(player, g_value_get_string(val));
|
wmud_player_set_email(player, g_value_get_string(val));
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loaded player _%s_", wmud_player_get_player_name(player));
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
||||||
|
"Loaded player _%s_",
|
||||||
|
wmud_player_get_player_name(player));
|
||||||
|
|
||||||
players = g_slist_prepend(players, player);
|
players = g_slist_prepend(players, player);
|
||||||
|
|
||||||
@ -166,16 +193,32 @@ wmud_db_save_player(WmudPlayer *player, GError **err)
|
|||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Saving player");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Saving player");
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
if (err)
|
if (err)
|
||||||
g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT, "Database backend not initialized");
|
g_set_error(err,
|
||||||
|
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
||||||
|
"Database backend not initialized");
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
login_value = gda_value_new_from_string(wmud_player_get_player_name(player), G_TYPE_STRING);
|
login_value = gda_value_new_from_string(
|
||||||
email_value = gda_value_new_from_string(wmud_player_get_email(player), G_TYPE_STRING);
|
wmud_player_get_player_name(player),
|
||||||
|
G_TYPE_STRING);
|
||||||
|
email_value = gda_value_new_from_string(
|
||||||
|
wmud_player_get_email(player),
|
||||||
|
G_TYPE_STRING);
|
||||||
|
|
||||||
if (!gda_connection_insert_row_into_table(dbh, "players", &local_err, "id", NULL, "login", login_value, "password", NULL, "email", email_value, NULL)) {
|
if (!gda_connection_insert_row_into_table(dbh,
|
||||||
g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_BADQUERY, "Error saving player: %s", local_err->message);
|
"players",
|
||||||
|
&local_err,
|
||||||
|
"id", NULL,
|
||||||
|
"login", login_value,
|
||||||
|
"password", NULL,
|
||||||
|
"email", email_value,
|
||||||
|
NULL)) {
|
||||||
|
g_set_error(err,
|
||||||
|
WMUD_DB_ERROR, WMUD_DB_ERROR_BADQUERY,
|
||||||
|
"Error saving player: %s",
|
||||||
|
local_err->message);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -184,16 +227,22 @@ wmud_db_save_player(WmudPlayer *player, GError **err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
wmud_db_update_player_password(WmudPlayer *player, gchar *crypted_password, GError **err)
|
wmud_db_update_player_password(WmudPlayer *player,
|
||||||
|
gchar *crypted_password,
|
||||||
|
GError **err)
|
||||||
{
|
{
|
||||||
GValue *cpw,
|
GValue *cpw,
|
||||||
*player_id;
|
*player_id;
|
||||||
GError *local_err = NULL;
|
GError *local_err = NULL;
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Saving player password for %s", wmud_player_get_player_name(player));
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
||||||
|
"Saving player password for %s",
|
||||||
|
wmud_player_get_player_name(player));
|
||||||
|
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT, "Database backend not initialized");
|
g_set_error(err,
|
||||||
|
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
||||||
|
"Database backend not initialized");
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -202,8 +251,16 @@ wmud_db_update_player_password(WmudPlayer *player, gchar *crypted_password, GErr
|
|||||||
g_value_set_uint(player_id, wmud_player_get_id(player));
|
g_value_set_uint(player_id, wmud_player_get_id(player));
|
||||||
cpw = gda_value_new_from_string(crypted_password, G_TYPE_STRING);
|
cpw = gda_value_new_from_string(crypted_password, G_TYPE_STRING);
|
||||||
|
|
||||||
if (!gda_connection_update_row_in_table(dbh, "players", "id", player_id, &local_err, "password", cpw, NULL)) {
|
if (!gda_connection_update_row_in_table(dbh,
|
||||||
g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_BADQUERY, "Error saving player password: %s", local_err->message);
|
"players",
|
||||||
|
"id", player_id,
|
||||||
|
&local_err,
|
||||||
|
"password", cpw,
|
||||||
|
NULL)) {
|
||||||
|
g_set_error(err,
|
||||||
|
WMUD_DB_ERROR, WMUD_DB_ERROR_BADQUERY,
|
||||||
|
"Error saving player password: %s",
|
||||||
|
local_err->message);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -221,12 +278,17 @@ wmud_db_load_planes(GSList **planes, GError **err)
|
|||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading planes");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading planes");
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
if (err)
|
if (err)
|
||||||
g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT, "Database backend not initialized");
|
g_set_error(err,
|
||||||
|
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
||||||
|
"Database backend not initialized");
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
sth = gda_sql_parser_parse_string(parser, "SELECT id, name FROM planes", NULL, NULL);
|
sth = gda_sql_parser_parse_string(parser,
|
||||||
|
"SELECT id, name FROM planes",
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
||||||
iter = gda_data_model_create_iter(res);
|
iter = gda_data_model_create_iter(res);
|
||||||
gda_data_model_iter_move_next(iter);
|
gda_data_model_iter_move_next(iter);
|
||||||
@ -243,7 +305,9 @@ wmud_db_load_planes(GSList **planes, GError **err)
|
|||||||
val = gda_data_model_iter_get_value_at(iter, 1);
|
val = gda_data_model_iter_get_value_at(iter, 1);
|
||||||
plane->name = g_strdup(g_value_get_string(val));
|
plane->name = g_strdup(g_value_get_string(val));
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loaded plane _%s_", plane->name);
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
||||||
|
"Loaded plane _%s_",
|
||||||
|
plane->name);
|
||||||
|
|
||||||
*planes = g_slist_prepend(*planes, plane);
|
*planes = g_slist_prepend(*planes, plane);
|
||||||
|
|
||||||
@ -266,12 +330,17 @@ wmud_db_load_planets(GSList **planets, GError **err)
|
|||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading planets");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading planets");
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
if (err)
|
if (err)
|
||||||
g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT, "Database backend not initialized");
|
g_set_error(err,
|
||||||
|
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
||||||
|
"Database backend not initialized");
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
sth = gda_sql_parser_parse_string(parser, "SELECT id, name FROM planets", NULL, NULL);
|
sth = gda_sql_parser_parse_string(parser,
|
||||||
|
"SELECT id, name FROM planets",
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
||||||
iter = gda_data_model_create_iter(res);
|
iter = gda_data_model_create_iter(res);
|
||||||
gda_data_model_iter_move_next(iter);
|
gda_data_model_iter_move_next(iter);
|
||||||
@ -288,7 +357,9 @@ wmud_db_load_planets(GSList **planets, GError **err)
|
|||||||
val = gda_data_model_iter_get_value_at(iter, 1);
|
val = gda_data_model_iter_get_value_at(iter, 1);
|
||||||
planet->name = g_strdup(g_value_get_string(val));
|
planet->name = g_strdup(g_value_get_string(val));
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loaded planet _%s_", planet->name);
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
||||||
|
"Loaded planet _%s_",
|
||||||
|
planet->name);
|
||||||
|
|
||||||
*planets = g_slist_prepend(*planets, planet);
|
*planets = g_slist_prepend(*planets, planet);
|
||||||
|
|
||||||
@ -313,15 +384,26 @@ wmud_db_load_directions(GSList **directions, GError **err)
|
|||||||
|
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
if (err)
|
if (err)
|
||||||
g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT, "Database backend not initialized");
|
g_set_error(err,
|
||||||
|
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
||||||
|
"Database backend not initialized");
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
sth = gda_sql_parser_parse_string(parser, "SELECT id, short_name, name FROM directions", NULL, NULL);
|
sth = gda_sql_parser_parse_string(
|
||||||
|
parser,
|
||||||
|
"SELECT id, short_name, name FROM directions",
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
|
||||||
if ((res = gda_connection_statement_execute_select(dbh, sth, NULL, &local_err)) == NULL) {
|
if ((res = gda_connection_statement_execute_select(
|
||||||
g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_SELECT_ERROR, "Unable to load directions: %s", local_err->message);
|
dbh, sth,
|
||||||
|
NULL, &local_err)) == NULL) {
|
||||||
|
g_set_error(err,
|
||||||
|
WMUD_DB_ERROR, WMUD_DB_ERROR_SELECT_ERROR,
|
||||||
|
"Unable to load directions: %s",
|
||||||
|
local_err->message);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -344,7 +426,9 @@ wmud_db_load_directions(GSList **directions, GError **err)
|
|||||||
val = gda_data_model_iter_get_value_at(iter, 2);
|
val = gda_data_model_iter_get_value_at(iter, 2);
|
||||||
dir->name = g_strdup(g_value_get_string(val));
|
dir->name = g_strdup(g_value_get_string(val));
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loaded direction _%s_", dir->name);
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
||||||
|
"Loaded direction _%s_",
|
||||||
|
dir->name);
|
||||||
|
|
||||||
*directions = g_slist_prepend(*directions, dir);
|
*directions = g_slist_prepend(*directions, dir);
|
||||||
|
|
||||||
@ -367,12 +451,18 @@ wmud_db_load_areas(GSList **areas, GError **err)
|
|||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading areas");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading areas");
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
if (err)
|
if (err)
|
||||||
g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT, "Database backend not initialized");
|
g_set_error(err,
|
||||||
|
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
||||||
|
"Database backend not initialized");
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
sth = gda_sql_parser_parse_string(parser, "SELECT id, name FROM areas", NULL, NULL);
|
sth = gda_sql_parser_parse_string(
|
||||||
|
parser,
|
||||||
|
"SELECT id, name FROM areas",
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
||||||
iter = gda_data_model_create_iter(res);
|
iter = gda_data_model_create_iter(res);
|
||||||
gda_data_model_iter_move_next(iter);
|
gda_data_model_iter_move_next(iter);
|
||||||
@ -412,12 +502,18 @@ wmud_db_load_rooms(GSList **rooms, GError **err)
|
|||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading rooms");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading rooms");
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
if (err)
|
if (err)
|
||||||
g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT, "Database backend not initialized");
|
g_set_error(err,
|
||||||
|
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
||||||
|
"Database backend not initialized");
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
sth = gda_sql_parser_parse_string(parser, "SELECT id, area, name, distant_description, close_description FROM rooms", NULL, NULL);
|
sth = gda_sql_parser_parse_string(
|
||||||
|
parser,
|
||||||
|
"SELECT id, area, name, distant_description, close_description FROM rooms",
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
||||||
iter = gda_data_model_create_iter(res);
|
iter = gda_data_model_create_iter(res);
|
||||||
gda_data_model_iter_move_next(iter);
|
gda_data_model_iter_move_next(iter);
|
||||||
@ -443,7 +539,10 @@ wmud_db_load_rooms(GSList **rooms, GError **err)
|
|||||||
val = gda_data_model_iter_get_value_at(iter, 4);
|
val = gda_data_model_iter_get_value_at(iter, 4);
|
||||||
room->close_description = g_strdup(g_value_get_string(val));
|
room->close_description = g_strdup(g_value_get_string(val));
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loaded room %d/_%s_", room->area_id, room->name);
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
||||||
|
"Loaded room %d/_%s_",
|
||||||
|
room->area_id,
|
||||||
|
room->name);
|
||||||
|
|
||||||
*rooms = g_slist_prepend(*rooms, room);
|
*rooms = g_slist_prepend(*rooms, room);
|
||||||
|
|
||||||
@ -466,12 +565,18 @@ wmud_db_load_exits(GSList **exits, GError **err)
|
|||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading exits");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading exits");
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
if (err)
|
if (err)
|
||||||
g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT, "Database backend not initialized");
|
g_set_error(err,
|
||||||
|
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
||||||
|
"Database backend not initialized");
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
sth = gda_sql_parser_parse_string(parser, "SELECT room_id, direction, other_side FROM room_exits", NULL, NULL);
|
sth = gda_sql_parser_parse_string(
|
||||||
|
parser,
|
||||||
|
"SELECT room_id, direction, other_side FROM room_exits",
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
||||||
iter = gda_data_model_create_iter(res);
|
iter = gda_data_model_create_iter(res);
|
||||||
gda_data_model_iter_move_next(iter);
|
gda_data_model_iter_move_next(iter);
|
||||||
@ -491,7 +596,11 @@ wmud_db_load_exits(GSList **exits, GError **err)
|
|||||||
val = gda_data_model_iter_get_value_at(iter, 2);
|
val = gda_data_model_iter_get_value_at(iter, 2);
|
||||||
room_exit->destination_room_id = g_value_get_int(val);
|
room_exit->destination_room_id = g_value_get_int(val);
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loaded exit %d =%d=> %d", room_exit->source_room_id, room_exit->direction_id, room_exit->destination_room_id);
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
||||||
|
"Loaded exit %d =%d=> %d",
|
||||||
|
room_exit->source_room_id,
|
||||||
|
room_exit->direction_id,
|
||||||
|
room_exit->destination_room_id);
|
||||||
|
|
||||||
*exits = g_slist_prepend(*exits, room_exit);
|
*exits = g_slist_prepend(*exits, room_exit);
|
||||||
|
|
||||||
@ -511,15 +620,22 @@ wmud_db_load_planet_planes(GSList **planet_planes, GError **err)
|
|||||||
GdaDataModel *res = NULL;
|
GdaDataModel *res = NULL;
|
||||||
GdaDataModelIter *iter;
|
GdaDataModelIter *iter;
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading planet<->plane associations");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
||||||
|
"Loading planet<->plane associations");
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
if (err)
|
if (err)
|
||||||
g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT, "Database backend not initialized");
|
g_set_error(err,
|
||||||
|
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
||||||
|
"Database backend not initialized");
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
sth = gda_sql_parser_parse_string(parser, "SELECT planet_id, plane_id FROM planet_planes", NULL, NULL);
|
sth = gda_sql_parser_parse_string(
|
||||||
|
parser,
|
||||||
|
"SELECT planet_id, plane_id FROM planet_planes",
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
||||||
iter = gda_data_model_create_iter(res);
|
iter = gda_data_model_create_iter(res);
|
||||||
gda_data_model_iter_move_next(iter);
|
gda_data_model_iter_move_next(iter);
|
||||||
@ -536,7 +652,10 @@ wmud_db_load_planet_planes(GSList **planet_planes, GError **err)
|
|||||||
val = gda_data_model_iter_get_value_at(iter, 1);
|
val = gda_data_model_iter_get_value_at(iter, 1);
|
||||||
planet_plane->plane_id = g_value_get_int(val);
|
planet_plane->plane_id = g_value_get_int(val);
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loaded planet-plane association %d <> %d", planet_plane->planet_id, planet_plane->plane_id);
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
||||||
|
"Loaded planet-plane association %d <> %d",
|
||||||
|
planet_plane->planet_id,
|
||||||
|
planet_plane->plane_id);
|
||||||
|
|
||||||
*planet_planes = g_slist_prepend(*planet_planes, planet_plane);
|
*planet_planes = g_slist_prepend(*planet_planes, planet_plane);
|
||||||
|
|
||||||
@ -559,12 +678,18 @@ wmud_db_load_menu(GSList **menu_items, GError **err)
|
|||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading menu items");
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading menu items");
|
||||||
if (dbh == NULL) {
|
if (dbh == NULL) {
|
||||||
if (err)
|
if (err)
|
||||||
g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT, "Database backend not initialized");
|
g_set_error(err,
|
||||||
|
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
|
||||||
|
"Database backend not initialized");
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
sth = gda_sql_parser_parse_string(parser, "SELECT id, menuchar, need_active_char, placement, display_text, fnctn FROM menu ORDER BY placement", NULL, NULL);
|
sth = gda_sql_parser_parse_string(
|
||||||
|
parser,
|
||||||
|
"SELECT id, menuchar, need_active_char, placement, display_text, fnctn FROM menu ORDER BY placement",
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
|
||||||
iter = gda_data_model_create_iter(res);
|
iter = gda_data_model_create_iter(res);
|
||||||
gda_data_model_iter_move_next(iter);
|
gda_data_model_iter_move_next(iter);
|
||||||
@ -593,7 +718,10 @@ wmud_db_load_menu(GSList **menu_items, GError **err)
|
|||||||
val = gda_data_model_iter_get_value_at(iter, 5);
|
val = gda_data_model_iter_get_value_at(iter, 5);
|
||||||
menu_item->func = g_strdup(g_value_get_string(val));
|
menu_item->func = g_strdup(g_value_get_string(val));
|
||||||
|
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loaded menu item %d: %s(%c)", menu_item->id, menu_item->text, menu_item->menuchar);
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
|
||||||
|
"Loaded menu item %d: %s(%c)",
|
||||||
|
menu_item->id, menu_item->text,
|
||||||
|
menu_item->menuchar);
|
||||||
|
|
||||||
*menu_items = g_slist_prepend(*menu_items, menu_item);
|
*menu_items = g_slist_prepend(*menu_items, menu_item);
|
||||||
|
|
||||||
@ -605,4 +733,3 @@ wmud_db_load_menu(GSList **menu_items, GError **err)
|
|||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,9 @@ GType
|
|||||||
{ 0, NULL, NULL }
|
{ 0, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
GType g_define_type_id = g_@type@_register_static(g_intern_static_string("@EnumName@"), values);
|
GType g_define_type_id = g_@type@_register_static(
|
||||||
|
g_intern_static_string("@EnumName@"),
|
||||||
|
values);
|
||||||
|
|
||||||
g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
|
g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
|
||||||
}
|
}
|
||||||
@ -35,4 +37,3 @@ GType
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*** END value-tail ***/
|
/*** END value-tail ***/
|
||||||
|
|
||||||
|
@ -99,7 +99,11 @@ recv_client(WmudClient *client)
|
|||||||
|
|
||||||
client_socket = wmud_client_get_socket(client);
|
client_socket = wmud_client_get_socket(client);
|
||||||
|
|
||||||
if ((len = g_socket_receive(client_socket, buf, MAX_RECV_LEN, NULL, &err)) == 0) {
|
if ((len = g_socket_receive(client_socket,
|
||||||
|
buf,
|
||||||
|
MAX_RECV_LEN,
|
||||||
|
NULL,
|
||||||
|
&err)) == 0) {
|
||||||
g_free(buf);
|
g_free(buf);
|
||||||
remove_client(client, FALSE);
|
remove_client(client, FALSE);
|
||||||
|
|
||||||
@ -117,15 +121,28 @@ recv_client(WmudClient *client)
|
|||||||
|
|
||||||
if ((r < n) && r) {
|
if ((r < n) && r) {
|
||||||
if (wmud_client_get_buffer_length(client) > 0)
|
if (wmud_client_get_buffer_length(client) > 0)
|
||||||
g_string_append_len(wmud_client_get_buffer(client), buf2, (r - buf2));
|
g_string_append_len(wmud_client_get_buffer(client),
|
||||||
|
buf2,
|
||||||
|
(r - buf2));
|
||||||
else
|
else
|
||||||
g_string_overwrite_len(wmud_client_get_buffer(client), 0, buf2, (r - buf2));
|
g_string_overwrite_len(
|
||||||
|
wmud_client_get_buffer(client),
|
||||||
|
0,
|
||||||
|
buf2,
|
||||||
|
(r - buf2));
|
||||||
buf2 = r;
|
buf2 = r;
|
||||||
} else if (n) {
|
} else if (n) {
|
||||||
if (wmud_client_get_buffer_length(client) > 0)
|
if (wmud_client_get_buffer_length(client) > 0)
|
||||||
g_string_append_len(wmud_client_get_buffer(client), buf2, (n - buf2));
|
g_string_append_len(
|
||||||
|
wmud_client_get_buffer(client),
|
||||||
|
buf2,
|
||||||
|
(n - buf2));
|
||||||
else
|
else
|
||||||
g_string_overwrite_len(wmud_client_get_buffer(client), 0, buf2, (n - buf2));
|
g_string_overwrite_len(
|
||||||
|
wmud_client_get_buffer(client),
|
||||||
|
0,
|
||||||
|
buf2,
|
||||||
|
(n - buf2));
|
||||||
buf2 = n;
|
buf2 = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +155,10 @@ recv_client(WmudClient *client)
|
|||||||
sloc = i;
|
sloc = i;
|
||||||
} else {
|
} else {
|
||||||
if (sloc != -1) {
|
if (sloc != -1) {
|
||||||
g_string_erase(wmud_client_get_buffer(client), sloc, i - sloc);
|
g_string_erase(
|
||||||
|
wmud_client_get_buffer(client),
|
||||||
|
sloc,
|
||||||
|
i - sloc);
|
||||||
sloc = -1;
|
sloc = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -202,7 +222,9 @@ recv_client(WmudClient *client)
|
|||||||
* Return value: this function always returns %TRUE
|
* Return value: this function always returns %TRUE
|
||||||
*/
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
game_source_callback(GSocket *socket, GIOCondition condition, struct AcceptData *accept_data)
|
game_source_callback(GSocket *socket,
|
||||||
|
GIOCondition condition,
|
||||||
|
struct AcceptData *accept_data)
|
||||||
{
|
{
|
||||||
GSocket *client_socket;
|
GSocket *client_socket;
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
|
13
wmud/game.c
13
wmud/game.c
@ -77,7 +77,9 @@ rl_sec_elapsed(gpointer user_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (elapsed_ticks % WMUD_HEARTBEAT_LENGTH == 0) {
|
if (elapsed_ticks % WMUD_HEARTBEAT_LENGTH == 0) {
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, "Heartbeat (%d ticks)", elapsed_ticks);
|
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE,
|
||||||
|
"Heartbeat (%d ticks)",
|
||||||
|
elapsed_ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -120,9 +122,14 @@ wmud_game_init(GThread **game_thread, GMainContext **game_context)
|
|||||||
|
|
||||||
g_clear_error(&err);
|
g_clear_error(&err);
|
||||||
#if GLIB_CHECK_VERSION(2, 32, 0)
|
#if GLIB_CHECK_VERSION(2, 32, 0)
|
||||||
*game_thread = g_thread_new("game", (GThreadFunc)game_thread_func, game_loop);
|
*game_thread = g_thread_new("game",
|
||||||
|
(GThreadFunc)game_thread_func,
|
||||||
|
game_loop);
|
||||||
#else
|
#else
|
||||||
*game_thread = g_thread_create((GThreadFunc)game_thread_func, game_loop, TRUE, &err);
|
*game_thread = g_thread_create((GThreadFunc)game_thread_func,
|
||||||
|
game_loop,
|
||||||
|
TRUE,
|
||||||
|
&err);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
75
wmud/main.c
75
wmud/main.c
@ -122,11 +122,13 @@ debug_context(char *file, int line)
|
|||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
wmud_type_init(void)
|
wmud_type_init(void)
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
wmud_logger(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data)
|
wmud_logger(const gchar *log_domain,
|
||||||
|
GLogLevelFlags log_level,
|
||||||
|
const gchar *message,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
static char timestamp[20];
|
static char timestamp[20];
|
||||||
struct tm *tm;
|
struct tm *tm;
|
||||||
@ -140,25 +142,50 @@ wmud_logger(const gchar *log_domain, GLogLevelFlags log_level, const gchar *mess
|
|||||||
|
|
||||||
switch (log_level) {
|
switch (log_level) {
|
||||||
case G_LOG_LEVEL_DEBUG:
|
case G_LOG_LEVEL_DEBUG:
|
||||||
g_print("[%s] [%s] DEBUG: %s\n", log_domain, timestamp, message);
|
g_print("[%s] [%s] DEBUG: %s\n",
|
||||||
|
log_domain,
|
||||||
|
timestamp,
|
||||||
|
message);
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
g_warning("Logging a debug-level message without debugging support!");
|
g_warning("Logging a debug-level message without debugging support!");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case G_LOG_LEVEL_MESSAGE:
|
case G_LOG_LEVEL_MESSAGE:
|
||||||
g_print("[%s] [%s] MESSAGE: %s\n", log_domain, timestamp, message);
|
g_print("[%s] [%s] MESSAGE: %s\n",
|
||||||
|
log_domain,
|
||||||
|
timestamp,
|
||||||
|
message);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case G_LOG_LEVEL_INFO:
|
case G_LOG_LEVEL_INFO:
|
||||||
g_print("[%s] [%s] INFO: %s\n", log_domain, timestamp, message);
|
g_print("[%s] [%s] INFO: %s\n",
|
||||||
|
log_domain,
|
||||||
|
timestamp,
|
||||||
|
message);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case G_LOG_LEVEL_WARNING:
|
case G_LOG_LEVEL_WARNING:
|
||||||
g_print("[%s] [%s] WARNING: %s\n", log_domain, timestamp, message);
|
g_print("[%s] [%s] WARNING: %s\n",
|
||||||
|
log_domain,
|
||||||
|
timestamp,
|
||||||
|
message);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case G_LOG_LEVEL_CRITICAL:
|
case G_LOG_LEVEL_CRITICAL:
|
||||||
g_print("[%s] [%s] CRITICAL: %s\n", log_domain, timestamp, message);
|
g_print("[%s] [%s] CRITICAL: %s\n",
|
||||||
|
log_domain,
|
||||||
|
timestamp,
|
||||||
|
message);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
g_print("[%s] [%s] UNKNOWN LEVEL %03d: %s\n", log_domain, timestamp, log_level, message);
|
g_print("[%s] [%s] UNKNOWN LEVEL %03d: %s\n",
|
||||||
|
log_domain,
|
||||||
|
timestamp,
|
||||||
|
log_level,
|
||||||
|
message);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -186,31 +213,38 @@ main(int argc, char **argv)
|
|||||||
/* TODO: Create signal handlers! */
|
/* TODO: Create signal handlers! */
|
||||||
|
|
||||||
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);
|
||||||
else
|
} else {
|
||||||
g_critical("Config file parsing error!");
|
g_critical("Config file parsing error!");
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_clear_error(&err);
|
g_clear_error(&err);
|
||||||
|
|
||||||
if (!wmud_db_init(&err)) {
|
if (!wmud_db_init(&err)) {
|
||||||
if (err)
|
if (err) {
|
||||||
g_critical("Database initialization error: %s", err->message);
|
g_critical("Database initialization error: %s", err->message);
|
||||||
else
|
} else {
|
||||||
g_critical("Database initialization error!");
|
g_critical("Database initialization error!");
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_clear_error(&err);
|
g_clear_error(&err);
|
||||||
wmud_db_load_players(&err);
|
wmud_db_load_players(&err);
|
||||||
if (!wmud_world_load(&err))
|
|
||||||
|
if (!wmud_world_load(&err)) {
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (!wmud_menu_init(&game_menu)) {
|
if (!wmud_menu_init(&game_menu)) {
|
||||||
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "An error occured during menu loading.");
|
g_log(G_LOG_DOMAIN,
|
||||||
|
G_LOG_LEVEL_CRITICAL,
|
||||||
|
"An error occured during menu loading.");
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -222,11 +256,15 @@ main(int argc, char **argv)
|
|||||||
wmud_game_init(&game_thread, &game_context);
|
wmud_game_init(&game_thread, &game_context);
|
||||||
|
|
||||||
g_clear_error(&err);
|
g_clear_error(&err);
|
||||||
if (!wmud_networking_init(active_config->port, game_context, game_menu, &err)) {
|
if (!wmud_networking_init(active_config->port,
|
||||||
if (err)
|
game_context,
|
||||||
|
game_menu,
|
||||||
|
&err)) {
|
||||||
|
if (err) {
|
||||||
g_critical("Database initialization error: %s", err->message);
|
g_critical("Database initialization error: %s", err->message);
|
||||||
else
|
} else {
|
||||||
g_critical("Database initialization error: unknown error!");
|
g_critical("Database initialization error: unknown error!");
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -239,4 +277,3 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user