server/src/gamedb.c

47 lines
1.1 KiB
C
Raw Normal View History

2018-09-25 18:07:02 +02:00
#ifdef _MSC_VER
#include <platform.h>
#endif
#include "gamedb.h"
#include "kernel/config.h"
#include "kernel/calendar.h"
2018-09-25 18:07:02 +02:00
#include "kernel/faction.h"
#include "kernel/db/driver.h"
2018-09-25 18:07:02 +02:00
#include "util/strings.h"
static int generate_factions(void *data, db_faction *results, int nresults)
{
int i;
faction **iter = (faction **)data;
for (i = 0; *iter && i != nresults; ++i) {
faction *f = *iter;
2019-04-25 16:31:35 +02:00
const char *pwhash;
results[i].p_uid = &f->uid;
results[i].no = f->no;
results[i].email = faction_getemail(f);
2019-04-25 16:31:35 +02:00
pwhash = faction_getpassword(f);
str_strlcpy(results[i].pwhash, pwhash ? pwhash : "", sizeof(results[i].pwhash));
*iter = f->next;
}
return i;
}
int gamedb_update(void)
2018-09-25 18:07:02 +02:00
{
int err;
const char *dbname;
2018-09-25 18:07:02 +02:00
dbname = config_get("game.dbname");
err = db_driver_open(DB_GAME, dbname);
if (err == 0) {
faction *list = factions;
db_driver_update_factions(generate_factions, &list);
db_driver_compact(turn);
db_driver_close(DB_GAME);
2018-09-25 18:07:02 +02:00
}
return err;
2018-09-25 18:07:02 +02:00
}