From 5871943455a57f42f5eead9186e259d822530d1e Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 26 Nov 2013 11:20:46 +0100 Subject: [PATCH] Create DB function to update a player's password --- wmud/db.c | 28 ++++++++++++++++++++++++++++ wmud/db.h | 1 + 2 files changed, 29 insertions(+) diff --git a/wmud/db.c b/wmud/db.c index 3488177..ab0d85b 100644 --- a/wmud/db.c +++ b/wmud/db.c @@ -183,6 +183,34 @@ wmud_db_save_player(WmudPlayer *player, GError **err) return TRUE; } +gboolean +wmud_db_update_player_password(WmudPlayer *player, gchar *crypted_password, GError **err) +{ + GValue *cpw, + player_id = G_VALUE_INIT; + GError *local_err = NULL; + + 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"); + + return FALSE; + } + + g_value_init(&player_id, G_TYPE_UINT); + 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)) { + g_set_error(err, WMUD_DB_ERROR, WMUD_DB_ERROR_BADQUERY, "Error saving player password: %s", local_err->message); + + return FALSE; + } + + return TRUE; +} + gboolean wmud_db_load_planes(GSList **planes, GError **err) { diff --git a/wmud/db.h b/wmud/db.h index ffe25e3..3acc13b 100644 --- a/wmud/db.h +++ b/wmud/db.h @@ -52,6 +52,7 @@ gboolean wmud_db_load_rooms(GSList **rooms, GError **err); gboolean wmud_db_load_exits(GSList **exits, GError **err); gboolean wmud_db_load_planet_planes(GSList **planet_planes, GError **err); gboolean wmud_db_load_menu(GSList **menu_items, GError **err); +gboolean wmud_db_update_player_password(WmudPlayer *player, gchar *crypted_password, GError **err); #endif /* __WMUD__DB_H__ */