Create DB function to update a player's password

This commit is contained in:
Gergely Polonkai 2013-11-26 11:20:46 +01:00
parent 003b56f6a0
commit 5871943455
2 changed files with 29 additions and 0 deletions

View File

@ -183,6 +183,34 @@ wmud_db_save_player(WmudPlayer *player, GError **err)
return TRUE; 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 gboolean
wmud_db_load_planes(GSList **planes, GError **err) wmud_db_load_planes(GSList **planes, GError **err)
{ {

View File

@ -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_exits(GSList **exits, GError **err);
gboolean wmud_db_load_planet_planes(GSList **planet_planes, 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_load_menu(GSList **menu_items, GError **err);
gboolean wmud_db_update_player_password(WmudPlayer *player, gchar *crypted_password, GError **err);
#endif /* __WMUD__DB_H__ */ #endif /* __WMUD__DB_H__ */