Uncrustify sources

This commit is contained in:
Gergely Polonkai 2016-06-22 17:59:53 +02:00
parent 1c88c88b63
commit e820f2308a
7 changed files with 1289 additions and 900 deletions

140
uncrustify.cfg Normal file
View 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

View File

@ -54,23 +54,29 @@ wmud_config_error_quark()
void
wmud_configdata_free(ConfigData **config_data)
{
if ((*config_data)->admin_email)
if ((*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);
}
if ((*config_data)->smtp_server)
if ((*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);
}
if ((*config_data)->smtp_password)
if ((*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);
*config_data = NULL;
@ -100,7 +106,9 @@ wmud_config_init(ConfigData **config_data, GError **err)
if (*config_data) {
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;
}
@ -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);
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_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")) {
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_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")) {
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_string_free(config_file, TRUE);
@ -137,13 +155,22 @@ wmud_config_init(ConfigData **config_data, GError **err)
}
g_clear_error(&in_err);
(*config_data)->port = g_key_file_get_integer(config, "global", "port", &in_err);
if (in_err)
{
if (g_error_matches(in_err, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
(*config_data)->port = g_key_file_get_integer(config,
"global", "port",
&in_err);
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;
} else if (g_error_matches(in_err, 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);
} else if (g_error_matches(in_err,
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_string_free(config_file, TRUE);
(*config_data)->port = 0;
@ -155,9 +182,16 @@ wmud_config_init(ConfigData **config_data, GError **err)
}
g_clear_error(&in_err);
(*config_data)->admin_email = g_key_file_get_string(config, "global", "admin email", &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);
(*config_data)->admin_email = g_key_file_get_string(config,
"global", "admin email",
&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_string_free(config_file, TRUE);
wmud_configdata_free(config_data);
@ -166,9 +200,16 @@ 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 && 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);
(*config_data)->smtp_server = g_key_file_get_string(config,
"smtp", "smtp server",
&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_string_free(config_file, TRUE);
wmud_configdata_free(config_data);
@ -177,9 +218,16 @@ wmud_config_init(ConfigData **config_data, GError **err)
}
g_clear_error(&in_err);
(*config_data)->smtp_sender = g_key_file_get_string(config, "smtp", "smtp sender", &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);
(*config_data)->smtp_sender = g_key_file_get_string(config,
"smtp", "smtp sender",
&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_string_free(config_file, TRUE);
wmud_configdata_free(config_data);
@ -188,9 +236,16 @@ wmud_config_init(ConfigData **config_data, GError **err)
}
g_clear_error(&in_err);
(*config_data)->database_dsn = g_key_file_get_string(config, "database", "dsn", &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);
(*config_data)->database_dsn = g_key_file_get_string(config,
"database", "dsn",
&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_string_free(config_file, TRUE);
wmud_configdata_free(config_data);
@ -198,7 +253,8 @@ wmud_config_init(ConfigData **config_data, GError **err)
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;
GString *tmp = g_string_new((*config_data)->database_dsn);
@ -213,4 +269,3 @@ wmud_config_init(ConfigData **config_data, GError **err)
return TRUE;
}

219
wmud/db.c
View File

@ -63,11 +63,21 @@ wmud_db_init(GError **err)
gda_init();
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "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);
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
"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) {
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;
}
@ -96,17 +106,32 @@ wmud_db_load_players(GError **err)
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading players");
if (dbh == NULL) {
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;
}
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! */
if ((res = gda_connection_statement_execute_select(dbh, 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);
if ((res = gda_connection_statement_execute_select(
dbh,
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;
}
@ -132,7 +157,9 @@ wmud_db_load_players(GError **err)
val = gda_data_model_iter_get_value_at(iter, 3);
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);
@ -166,16 +193,32 @@ wmud_db_save_player(WmudPlayer *player, GError **err)
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Saving player");
if (dbh == NULL) {
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;
}
login_value = gda_value_new_from_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);
login_value = gda_value_new_from_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)) {
g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_BADQUERY, "Error saving player: %s", local_err->message);
if (!gda_connection_insert_row_into_table(dbh,
"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;
}
@ -184,16 +227,22 @@ wmud_db_save_player(WmudPlayer *player, GError **err)
}
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,
*player_id;
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) {
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;
}
@ -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));
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)) {
g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_BADQUERY, "Error saving player password: %s", local_err->message);
if (!gda_connection_update_row_in_table(dbh,
"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;
}
@ -221,12 +278,17 @@ wmud_db_load_planes(GSList **planes, GError **err)
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading planes");
if (dbh == NULL) {
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;
}
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);
iter = gda_data_model_create_iter(res);
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);
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);
@ -266,12 +330,17 @@ wmud_db_load_planets(GSList **planets, GError **err)
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading planets");
if (dbh == NULL) {
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;
}
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);
iter = gda_data_model_create_iter(res);
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);
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);
@ -313,15 +384,26 @@ wmud_db_load_directions(GSList **directions, GError **err)
if (dbh == NULL) {
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;
}
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) {
g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_SELECT_ERROR, "Unable to load directions: %s", local_err->message);
if ((res = gda_connection_statement_execute_select(
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;
}
@ -344,7 +426,9 @@ wmud_db_load_directions(GSList **directions, GError **err)
val = gda_data_model_iter_get_value_at(iter, 2);
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);
@ -367,12 +451,18 @@ wmud_db_load_areas(GSList **areas, GError **err)
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading areas");
if (dbh == NULL) {
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;
}
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);
iter = gda_data_model_create_iter(res);
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");
if (dbh == NULL) {
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;
}
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);
iter = gda_data_model_create_iter(res);
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);
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);
@ -466,12 +565,18 @@ wmud_db_load_exits(GSList **exits, GError **err)
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading exits");
if (dbh == NULL) {
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;
}
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);
iter = gda_data_model_create_iter(res);
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);
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);
@ -511,15 +620,22 @@ wmud_db_load_planet_planes(GSList **planet_planes, GError **err)
GdaDataModel *res = NULL;
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 (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;
}
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);
iter = gda_data_model_create_iter(res);
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);
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);
@ -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");
if (dbh == NULL) {
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;
}
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);
iter = gda_data_model_create_iter(res);
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);
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);
@ -605,4 +733,3 @@ wmud_db_load_menu(GSList **menu_items, GError **err)
return TRUE;
}

View File

@ -26,7 +26,9 @@ GType
{ 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);
}
@ -35,4 +37,3 @@ GType
}
/*** END value-tail ***/

View File

@ -99,7 +99,11 @@ recv_client(WmudClient *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);
remove_client(client, FALSE);
@ -117,15 +121,28 @@ recv_client(WmudClient *client)
if ((r < n) && r) {
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
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;
} else if (n) {
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
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;
}
@ -138,7 +155,10 @@ recv_client(WmudClient *client)
sloc = i;
} else {
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;
}
}
@ -202,7 +222,9 @@ recv_client(WmudClient *client)
* Return value: this function always returns %TRUE
*/
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;
GError *err = NULL;

View File

@ -77,7 +77,9 @@ rl_sec_elapsed(gpointer user_data)
}
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;
@ -120,9 +122,14 @@ wmud_game_init(GThread **game_thread, GMainContext **game_context)
g_clear_error(&err);
#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
*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
return TRUE;

View File

@ -122,11 +122,13 @@ debug_context(char *file, int line)
*/
void
wmud_type_init(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];
struct tm *tm;
@ -140,25 +142,50 @@ wmud_logger(const gchar *log_domain, GLogLevelFlags log_level, const gchar *mess
switch (log_level) {
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
g_warning("Logging a debug-level message without debugging support!");
#endif
break;
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;
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;
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;
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;
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;
}
}
@ -186,31 +213,38 @@ main(int argc, char **argv)
/* TODO: Create signal handlers! */
if (!wmud_config_init(&active_config, &err)) {
if (err)
if (err) {
g_critical("Config file parsing error: %s", err->message);
else
} else {
g_critical("Config file parsing error!");
}
return 1;
}
g_clear_error(&err);
if (!wmud_db_init(&err)) {
if (err)
if (err) {
g_critical("Database initialization error: %s", err->message);
else
} else {
g_critical("Database initialization error!");
}
return 1;
}
g_clear_error(&err);
wmud_db_load_players(&err);
if (!wmud_world_load(&err))
if (!wmud_world_load(&err)) {
return 1;
}
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;
}
@ -222,11 +256,15 @@ main(int argc, char **argv)
wmud_game_init(&game_thread, &game_context);
g_clear_error(&err);
if (!wmud_networking_init(active_config->port, game_context, game_menu, &err)) {
if (err)
if (!wmud_networking_init(active_config->port,
game_context,
game_menu,
&err)) {
if (err) {
g_critical("Database initialization error: %s", err->message);
else
} else {
g_critical("Database initialization error: unknown error!");
}
return 1;
}
@ -239,4 +277,3 @@ main(int argc, char **argv)
return 0;
}