forked from github/server
updating eressea.db, not with a fixed game-id
This commit is contained in:
parent
1318c8976a
commit
cb458db9a1
|
@ -15,16 +15,17 @@ without prior permission by the authors of Eressea.
|
|||
#include "bind_unit.h"
|
||||
#include "bindings.h"
|
||||
|
||||
#include <kernel/config.h>
|
||||
#include <sqlite3.h>
|
||||
#include <tolua.h>
|
||||
|
||||
#define LTYPE_DB TOLUA_CAST "db"
|
||||
|
||||
extern int db_update_factions(sqlite3 * db, bool force);
|
||||
extern int db_update_factions(sqlite3 * db, bool force, int game);
|
||||
static int tolua_db_update_factions(lua_State * L)
|
||||
{
|
||||
sqlite3 *db = (sqlite3 *) tolua_tousertype(L, 1, 0);
|
||||
db_update_factions(db, tolua_toboolean(L, 2, 0));
|
||||
db_update_factions(db, tolua_toboolean(L, 2, 0), global.game_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -93,6 +93,7 @@ struct settings global = {
|
|||
"Eressea", /* gamename */
|
||||
};
|
||||
|
||||
bool lomem = false;
|
||||
FILE *logfile;
|
||||
FILE *updatelog;
|
||||
const struct race *new_race[MAXRACES];
|
||||
|
@ -1578,10 +1579,6 @@ void freestrlist(strlist * s)
|
|||
}
|
||||
}
|
||||
|
||||
/* - Meldungen und Fehler ------------------------------------------------- */
|
||||
|
||||
bool lomem = false;
|
||||
|
||||
/* - Namen der Strukturen -------------------------------------- */
|
||||
typedef char name[OBJECTIDSIZE + 1];
|
||||
static name idbuf[8];
|
||||
|
@ -3168,7 +3165,6 @@ void load_inifile(dictionary * d)
|
|||
make_locales(str);
|
||||
|
||||
/* excerpt from [config] (the rest is used in bindings.c) */
|
||||
game_name = iniparser_getstring(d, "config:game", game_name);
|
||||
|
||||
global.game_id = iniparser_getint(d, "config:game_id", 0);
|
||||
global.inifile = d;
|
||||
}
|
||||
|
|
|
@ -393,6 +393,7 @@ extern "C" {
|
|||
void *vm_state;
|
||||
float producexpchance;
|
||||
int cookie;
|
||||
int game_id;
|
||||
int data_version; /* TODO: eliminate in favor of gamedata.version */
|
||||
struct _dictionary_ *inifile;
|
||||
|
||||
|
|
|
@ -129,10 +129,20 @@ db_update_email(sqlite3 * db, const faction * f, const db_faction * dbstate,
|
|||
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
int db_update_factions(sqlite3 * db, bool force)
|
||||
/*
|
||||
int db_get_game(sqlite3 *db) {
|
||||
int game_id = 0;
|
||||
const char sql_game[] =
|
||||
"SELECT id FROM game WHERE name=?";
|
||||
sqlite3_stmt *stmt_game = stmt_cache(db, sql_game);
|
||||
res = sqlite3_bind_text(stmt_game, 1, gamename, -1, SQLITE_TRANSIENT);
|
||||
SQL_EXPECT(res, SQLITE_OK);
|
||||
res = sqlite3_step(stmt_select);
|
||||
return game_id;
|
||||
}
|
||||
*/
|
||||
int db_update_factions(sqlite3 * db, bool force, int game_id)
|
||||
{
|
||||
int game_id = 6;
|
||||
const char sql_select[] =
|
||||
"SELECT faction.id, faction.email_id, faction.code, email.email, faction.password_md5, faction.name, faction.lastturn FROM email, faction"
|
||||
" WHERE email.id=faction.email_id AND faction.game_id=? AND (lastturn IS NULL OR lastturn>?)";
|
||||
|
@ -147,6 +157,7 @@ int db_update_factions(sqlite3 * db, bool force)
|
|||
for (;;) {
|
||||
sqlite3_uint64 id_faction;
|
||||
int lastturn;
|
||||
const char * no_b36;
|
||||
|
||||
res = sqlite3_step(stmt_select);
|
||||
if (res != SQLITE_ROW)
|
||||
|
@ -154,9 +165,16 @@ int db_update_factions(sqlite3 * db, bool force)
|
|||
|
||||
id_faction = sqlite3_column_int64(stmt_select, 0);
|
||||
lastturn = sqlite3_column_int(stmt_select, 6);
|
||||
no_b36 = (const char *)sqlite3_column_text(stmt_select, 2);
|
||||
f = get_faction_by_id((int)id_faction);
|
||||
|
||||
if (f == NULL || !f->alive) {
|
||||
if (!f) {
|
||||
int no = atoi36(no_b36);
|
||||
f = findfaction(no);
|
||||
if (f) {
|
||||
f->subscription = (int)id_faction;
|
||||
}
|
||||
}
|
||||
if (!f || !f->alive) {
|
||||
if (lastturn == 0) {
|
||||
const char sql_update[] = "UPDATE faction SET lastturn=? WHERE id=?";
|
||||
sqlite3_stmt *stmt = stmt_cache_get(db, sql_update);
|
||||
|
@ -175,12 +193,10 @@ int db_update_factions(sqlite3 * db, bool force)
|
|||
sqlite3_uint64 id_email;
|
||||
bool update = force;
|
||||
db_faction dbstate;
|
||||
const char *no_b36;
|
||||
|
||||
fset(f, FFL_MARK);
|
||||
dbstate.id_faction = id_faction;
|
||||
dbstate.id_email = sqlite3_column_int64(stmt_select, 1);
|
||||
no_b36 = (const char *)sqlite3_column_text(stmt_select, 2);
|
||||
dbstate.no = no_b36 ? atoi36(no_b36) : -1;
|
||||
dbstate.email = (const char *)sqlite3_column_text(stmt_select, 3);
|
||||
dbstate.passwd_md5 = (const char *)sqlite3_column_text(stmt_select, 4);
|
||||
|
|
Loading…
Reference in New Issue