forked from github/server
adding code to export faction information.
sqlite3 implementation only, not tied to anything yet. add faction.uid remove faction.subscription
This commit is contained in:
parent
d70f05f8db
commit
ccc5556682
|
@ -3659,7 +3659,7 @@ static bool is_calmed(const unit *u, const faction *f) {
|
||||||
|
|
||||||
while (a && a->type == &at_curse) {
|
while (a && a->type == &at_curse) {
|
||||||
curse *c = (curse *)a->data.v;
|
curse *c = (curse *)a->data.v;
|
||||||
if (c->type == &ct_calmmonster && curse_geteffect_int(c) == f->subscription) {
|
if (c->type == &ct_calmmonster && curse_geteffect_int(c) == f->uid) {
|
||||||
if (curse_active(c)) {
|
if (curse_active(c)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -432,7 +432,7 @@ static int tolua_faction_create(lua_State * L)
|
||||||
faction *f = NULL;
|
faction *f = NULL;
|
||||||
const struct race *frace = rc_find(racename ? racename : "human");
|
const struct race *frace = rc_find(racename ? racename : "human");
|
||||||
if (frace != NULL) {
|
if (frace != NULL) {
|
||||||
f = addfaction(email, NULL, frace, loc, 0);
|
f = addfaction(email, NULL, frace, loc);
|
||||||
}
|
}
|
||||||
if (!f) {
|
if (!f) {
|
||||||
log_error("cannot create %s faction for %s, unknown race.", racename, email);
|
log_error("cannot create %s faction for %s, unknown race.", racename, email);
|
||||||
|
@ -528,14 +528,14 @@ static int tolua_faction_set_name(lua_State * L)
|
||||||
static int tolua_faction_get_uid(lua_State * L)
|
static int tolua_faction_get_uid(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *f = (faction *)tolua_tousertype(L, 1, 0);
|
faction *f = (faction *)tolua_tousertype(L, 1, 0);
|
||||||
lua_pushinteger(L, f->subscription);
|
lua_pushinteger(L, f->uid);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_faction_set_uid(lua_State * L)
|
static int tolua_faction_set_uid(lua_State * L)
|
||||||
{
|
{
|
||||||
faction *f = (faction *)tolua_tousertype(L, 1, 0);
|
faction *f = (faction *)tolua_tousertype(L, 1, 0);
|
||||||
f->subscription = (int)tolua_tonumber(L, 2, 0);
|
f->uid = (int)tolua_tonumber(L, 2, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -339,13 +339,6 @@ static int tolua_update_owners(lua_State * L)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tolua_update_subscriptions(lua_State * L)
|
|
||||||
{
|
|
||||||
UNUSED_ARG(L);
|
|
||||||
update_subscriptions();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int tolua_remove_empty_units(lua_State * L)
|
static int tolua_remove_empty_units(lua_State * L)
|
||||||
{
|
{
|
||||||
UNUSED_ARG(L);
|
UNUSED_ARG(L);
|
||||||
|
@ -972,7 +965,6 @@ int tolua_bindings_open(lua_State * L, const dictionary *inifile)
|
||||||
tolua_function(L, TOLUA_CAST "dice_roll", tolua_dice_rand);
|
tolua_function(L, TOLUA_CAST "dice_roll", tolua_dice_rand);
|
||||||
tolua_function(L, TOLUA_CAST "get_nmrs", tolua_get_nmrs);
|
tolua_function(L, TOLUA_CAST "get_nmrs", tolua_get_nmrs);
|
||||||
tolua_function(L, TOLUA_CAST "remove_empty_units", tolua_remove_empty_units);
|
tolua_function(L, TOLUA_CAST "remove_empty_units", tolua_remove_empty_units);
|
||||||
tolua_function(L, TOLUA_CAST "update_subscriptions", tolua_update_subscriptions);
|
|
||||||
tolua_function(L, TOLUA_CAST "update_scores", tolua_update_scores);
|
tolua_function(L, TOLUA_CAST "update_scores", tolua_update_scores);
|
||||||
tolua_function(L, TOLUA_CAST "update_owners", tolua_update_owners);
|
tolua_function(L, TOLUA_CAST "update_owners", tolua_update_owners);
|
||||||
tolua_function(L, TOLUA_CAST "learn_skill", tolua_learn_skill);
|
tolua_function(L, TOLUA_CAST "learn_skill", tolua_learn_skill);
|
||||||
|
|
|
@ -39,6 +39,18 @@
|
||||||
/* manually free() everything at exit? */
|
/* manually free() everything at exit? */
|
||||||
#undef CLEANUP_CODE
|
#undef CLEANUP_CODE
|
||||||
|
|
||||||
|
void game_write_dbstate(void)
|
||||||
|
{
|
||||||
|
faction *f;
|
||||||
|
|
||||||
|
for (f = factions; f; f = f->next) {
|
||||||
|
int uid = dblib_save_faction(f, turn);
|
||||||
|
if (uid > 0) {
|
||||||
|
f->uid = uid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void game_done(void)
|
void game_done(void)
|
||||||
{
|
{
|
||||||
log_dead_factions();
|
log_dead_factions();
|
||||||
|
|
|
@ -6,6 +6,7 @@ extern "C" {
|
||||||
|
|
||||||
void game_init(void);
|
void game_init(void);
|
||||||
void game_done(void);
|
void game_done(void);
|
||||||
|
void game_write_dbstate(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -920,8 +920,7 @@ static void seed_player(state *st, const newfaction *player) {
|
||||||
if (r) {
|
if (r) {
|
||||||
faction *f;
|
faction *f;
|
||||||
addplayer(r, f = addfaction(player->email, player->password,
|
addplayer(r, f = addfaction(player->email, player->password,
|
||||||
player->race, player->lang,
|
player->race, player->lang));
|
||||||
player->subscription));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
cmake_minimum_required(VERSION 2.6)
|
cmake_minimum_required(VERSION 2.6)
|
||||||
project(kernel C)
|
project(kernel C)
|
||||||
|
|
||||||
|
SET(_DBFILES db/critbit.c)
|
||||||
|
|
||||||
|
IF(SQLITE3_FOUND)
|
||||||
|
SET(_DBFILES db/sqlite.c)
|
||||||
|
ELSEIF(DB_FOUND)
|
||||||
|
SET(_DBFILES db/berkeley.c)
|
||||||
|
ENDIF(SQLITE3_FOUND)
|
||||||
|
|
||||||
SET(_TEST_FILES
|
SET(_TEST_FILES
|
||||||
alliance.test.c
|
alliance.test.c
|
||||||
ally.test.c
|
ally.test.c
|
||||||
|
@ -35,14 +43,6 @@ spell.test.c
|
||||||
unit.test.c
|
unit.test.c
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(_DBFILES db/critbit.c)
|
|
||||||
|
|
||||||
IF(SQLITE3_FOUND)
|
|
||||||
SET(_DBFILES db/sqlite.c)
|
|
||||||
ELSEIF(DB_FOUND)
|
|
||||||
SET(_DBFILES db/berkeley.c)
|
|
||||||
ENDIF(SQLITE3_FOUND)
|
|
||||||
|
|
||||||
SET(_FILES
|
SET(_FILES
|
||||||
${_DBFILES}
|
${_DBFILES}
|
||||||
alliance.c
|
alliance.c
|
||||||
|
|
|
@ -440,7 +440,7 @@ static const char *b_nameillusionwall(const connection * b, const region * r,
|
||||||
return (f && fno == f->no) ? "illusionwall" : "wall";
|
return (f && fno == f->no) ? "illusionwall" : "wall";
|
||||||
if (gflags & GF_ARTICLE) {
|
if (gflags & GF_ARTICLE) {
|
||||||
return LOC(f->locale, mkname("border", (f
|
return LOC(f->locale, mkname("border", (f
|
||||||
&& fno == f->subscription) ? "an_illusionwall" : "a_wall"));
|
&& fno == f->uid) ? "an_illusionwall" : "a_wall"));
|
||||||
}
|
}
|
||||||
return LOC(f->locale, mkname("border", (f
|
return LOC(f->locale, mkname("border", (f
|
||||||
&& fno == f->no) ? "illusionwall" : "wall"));
|
&& fno == f->no) ? "illusionwall" : "wall"));
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
|
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
|
#include <kernel/faction.h>
|
||||||
#include <kernel/database.h>
|
#include <kernel/database.h>
|
||||||
#include <kernel/orderdb.h>
|
#include <kernel/orderdb.h>
|
||||||
|
|
||||||
|
@ -27,6 +28,10 @@ int dblib_save_order(order_data *od)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int dblib_save_faction(const faction *f, int turn) {
|
||||||
|
return db_driver_faction_save(f->uid, f->no, turn, f->email, f->_password);
|
||||||
|
}
|
||||||
|
|
||||||
void dblib_open(void)
|
void dblib_open(void)
|
||||||
{
|
{
|
||||||
db_driver_open();
|
db_driver_open();
|
||||||
|
|
|
@ -8,12 +8,14 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct order_data;
|
struct order_data;
|
||||||
|
struct faction;
|
||||||
|
|
||||||
void dblib_open(void);
|
void dblib_open(void);
|
||||||
void dblib_close(void);
|
void dblib_close(void);
|
||||||
|
|
||||||
struct order_data *dblib_load_order(int id);
|
struct order_data *dblib_load_order(int id);
|
||||||
int dblib_save_order(struct order_data *od);
|
int dblib_save_order(struct order_data *od);
|
||||||
|
int dblib_save_faction(const struct faction *f, int turn);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
|
#include <kernel/faction.h>
|
||||||
|
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
#include "orderdb.h"
|
#include "orderdb.h"
|
||||||
|
@ -7,6 +8,7 @@
|
||||||
#include <CuTest.h>
|
#include <CuTest.h>
|
||||||
#include <tests.h>
|
#include <tests.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static void test_save_load_order(CuTest *tc) {
|
static void test_save_load_order(CuTest *tc) {
|
||||||
|
@ -31,10 +33,24 @@ static void test_save_load_order(CuTest *tc) {
|
||||||
test_teardown();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_update_faction(CuTest *tc) {
|
||||||
|
faction *f;
|
||||||
|
int uid;
|
||||||
|
|
||||||
|
test_setup();
|
||||||
|
f = test_create_faction(NULL);
|
||||||
|
uid = dblib_save_faction(f, 0);
|
||||||
|
f->uid = uid;
|
||||||
|
uid = dblib_save_faction(f, 0);
|
||||||
|
CuAssertIntEquals(tc, f->uid, uid);
|
||||||
|
test_teardown();
|
||||||
|
}
|
||||||
|
|
||||||
CuSuite *get_db_suite(void)
|
CuSuite *get_db_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
SUITE_ADD_TEST(suite, test_save_load_order);
|
SUITE_ADD_TEST(suite, test_save_load_order);
|
||||||
|
SUITE_ADD_TEST(suite, test_update_faction);
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,11 @@ int db_driver_order_save(struct order_data *od)
|
||||||
return (int)recno;
|
return (int)recno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int db_driver_faction_save(int id, int no, int turn, const char *email, const char *password)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
struct order_data *db_driver_order_load(int id)
|
struct order_data *db_driver_order_load(int id)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
|
@ -44,6 +44,11 @@ int db_driver_order_save(order_data *od)
|
||||||
return ent.id;
|
return ent.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int db_driver_faction_save(int id, int no, int turn, const char *email, const char *password)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
static int free_data_cb(const void *match, const void *key, size_t keylen,
|
static int free_data_cb(const void *match, const void *key, size_t keylen,
|
||||||
void *udata)
|
void *udata)
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,3 +6,4 @@ void db_driver_open(void);
|
||||||
void db_driver_close(void);
|
void db_driver_close(void);
|
||||||
int db_driver_order_save(struct order_data *od);
|
int db_driver_order_save(struct order_data *od);
|
||||||
struct order_data *db_driver_order_load(int id);
|
struct order_data *db_driver_order_load(int id);
|
||||||
|
int db_driver_faction_save(int id, int no, int turn, const char *email, const char *password);
|
||||||
|
|
|
@ -15,9 +15,12 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static sqlite3 *g_db;
|
static sqlite3 *g_game_db;
|
||||||
static sqlite3_stmt * g_stmt_insert;
|
static sqlite3 *g_temp_db;
|
||||||
static sqlite3_stmt * g_stmt_select;
|
static sqlite3_stmt * g_stmt_insert_order;
|
||||||
|
static sqlite3_stmt * g_stmt_select_order;
|
||||||
|
static sqlite3_stmt * g_stmt_update_faction;
|
||||||
|
static sqlite3_stmt * g_stmt_insert_faction;
|
||||||
|
|
||||||
static int g_order_batchsize;
|
static int g_order_batchsize;
|
||||||
static int g_order_tx_size;
|
static int g_order_tx_size;
|
||||||
|
@ -30,21 +33,21 @@ order_data *db_driver_order_load(int id)
|
||||||
ERRNO_CHECK();
|
ERRNO_CHECK();
|
||||||
if (g_order_tx_size > 0) {
|
if (g_order_tx_size > 0) {
|
||||||
g_order_tx_size = 0;
|
g_order_tx_size = 0;
|
||||||
err = sqlite3_exec(g_db, "COMMIT", NULL, NULL, NULL);
|
err = sqlite3_exec(g_temp_db, "COMMIT", NULL, NULL, NULL);
|
||||||
assert(err == SQLITE_OK);
|
assert(err == SQLITE_OK);
|
||||||
}
|
}
|
||||||
err = sqlite3_reset(g_stmt_select);
|
err = sqlite3_reset(g_stmt_select_order);
|
||||||
assert(err == SQLITE_OK);
|
assert(err == SQLITE_OK);
|
||||||
err = sqlite3_bind_int(g_stmt_select, 1, id);
|
err = sqlite3_bind_int(g_stmt_select_order, 1, id);
|
||||||
assert(err == SQLITE_OK);
|
assert(err == SQLITE_OK);
|
||||||
do {
|
do {
|
||||||
err = sqlite3_step(g_stmt_select);
|
err = sqlite3_step(g_stmt_select_order);
|
||||||
if (err == SQLITE_ROW) {
|
if (err == SQLITE_ROW) {
|
||||||
const unsigned char *text;
|
const unsigned char *text;
|
||||||
int bytes;
|
int bytes;
|
||||||
bytes = sqlite3_column_bytes(g_stmt_select, 0);
|
bytes = sqlite3_column_bytes(g_stmt_select_order, 0);
|
||||||
assert(bytes > 0);
|
assert(bytes > 0);
|
||||||
text = sqlite3_column_text(g_stmt_select, 0);
|
text = sqlite3_column_text(g_stmt_select_order, 0);
|
||||||
odata_create(&od, 1+(size_t)bytes, (const char *)text);
|
odata_create(&od, 1+(size_t)bytes, (const char *)text);
|
||||||
ERRNO_CHECK();
|
ERRNO_CHECK();
|
||||||
return od;
|
return od;
|
||||||
|
@ -66,23 +69,23 @@ int db_driver_order_save(order_data *od)
|
||||||
|
|
||||||
if (g_order_batchsize > 0) {
|
if (g_order_batchsize > 0) {
|
||||||
if (g_order_tx_size == 0) {
|
if (g_order_tx_size == 0) {
|
||||||
err = sqlite3_exec(g_db, "BEGIN TRANSACTION", NULL, NULL, NULL);
|
err = sqlite3_exec(g_temp_db, "BEGIN TRANSACTION", NULL, NULL, NULL);
|
||||||
assert(err == SQLITE_OK);
|
assert(err == SQLITE_OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = sqlite3_reset(g_stmt_insert);
|
err = sqlite3_reset(g_stmt_insert_order);
|
||||||
assert(err == SQLITE_OK);
|
assert(err == SQLITE_OK);
|
||||||
err = sqlite3_bind_text(g_stmt_insert, 1, od->_str, -1, SQLITE_STATIC);
|
err = sqlite3_bind_text(g_stmt_insert_order, 1, od->_str, -1, SQLITE_STATIC);
|
||||||
assert(err == SQLITE_OK);
|
assert(err == SQLITE_OK);
|
||||||
err = sqlite3_step(g_stmt_insert);
|
err = sqlite3_step(g_stmt_insert_order);
|
||||||
assert(err == SQLITE_DONE);
|
assert(err == SQLITE_DONE);
|
||||||
id = sqlite3_last_insert_rowid(g_db);
|
id = sqlite3_last_insert_rowid(g_temp_db);
|
||||||
assert(id <= INT_MAX);
|
assert(id <= INT_MAX);
|
||||||
|
|
||||||
if (g_order_batchsize > 0) {
|
if (g_order_batchsize > 0) {
|
||||||
if (++g_order_tx_size >= g_order_batchsize) {
|
if (++g_order_tx_size >= g_order_batchsize) {
|
||||||
err = sqlite3_exec(g_db, "COMMIT", NULL, NULL, NULL);
|
err = sqlite3_exec(g_temp_db, "COMMIT", NULL, NULL, NULL);
|
||||||
assert(err == SQLITE_OK);
|
assert(err == SQLITE_OK);
|
||||||
g_order_tx_size = 0;
|
g_order_tx_size = 0;
|
||||||
}
|
}
|
||||||
|
@ -91,29 +94,89 @@ int db_driver_order_save(order_data *od)
|
||||||
return (int)id;
|
return (int)id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int db_driver_faction_save(int id, int no, int turn, const char *email, const char *password)
|
||||||
|
{
|
||||||
|
sqlite3_int64 row_id;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
if (!g_game_db) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (id != 0) {
|
||||||
|
int rows;
|
||||||
|
|
||||||
|
err = sqlite3_reset(g_stmt_update_faction);
|
||||||
|
assert(err == SQLITE_OK);
|
||||||
|
err = sqlite3_bind_int(g_stmt_update_faction, 1, no);
|
||||||
|
assert(err == SQLITE_OK);
|
||||||
|
err = sqlite3_bind_int(g_stmt_update_faction, 2, turn);
|
||||||
|
assert(err == SQLITE_OK);
|
||||||
|
err = sqlite3_bind_text(g_stmt_update_faction, 3, email, -1, SQLITE_STATIC);
|
||||||
|
assert(err == SQLITE_OK);
|
||||||
|
err = sqlite3_bind_text(g_stmt_update_faction, 4, password, -1, SQLITE_STATIC);
|
||||||
|
assert(err == SQLITE_OK);
|
||||||
|
err = sqlite3_bind_int(g_stmt_update_faction, 5, id);
|
||||||
|
assert(err == SQLITE_OK);
|
||||||
|
err = sqlite3_step(g_stmt_update_faction);
|
||||||
|
assert(err == SQLITE_DONE);
|
||||||
|
rows = sqlite3_changes(g_game_db);
|
||||||
|
if (rows != 0) {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err = sqlite3_reset(g_stmt_insert_faction);
|
||||||
|
assert(err == SQLITE_OK);
|
||||||
|
err = sqlite3_bind_int(g_stmt_insert_faction, 1, no);
|
||||||
|
assert(err == SQLITE_OK);
|
||||||
|
err = sqlite3_bind_int(g_stmt_insert_faction, 2, turn);
|
||||||
|
assert(err == SQLITE_OK);
|
||||||
|
err = sqlite3_bind_text(g_stmt_insert_faction, 3, email, -1, SQLITE_STATIC);
|
||||||
|
assert(err == SQLITE_OK);
|
||||||
|
err = sqlite3_bind_text(g_stmt_insert_faction, 4, password, -1, SQLITE_STATIC);
|
||||||
|
assert(err == SQLITE_OK);
|
||||||
|
err = sqlite3_step(g_stmt_insert_faction);
|
||||||
|
assert(err == SQLITE_DONE);
|
||||||
|
ERRNO_CHECK();
|
||||||
|
|
||||||
|
row_id = sqlite3_last_insert_rowid(g_game_db);
|
||||||
|
assert(row_id <= INT_MAX);
|
||||||
|
return (int)row_id;
|
||||||
|
}
|
||||||
|
|
||||||
void db_driver_open(void)
|
void db_driver_open(void)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
const char *dbname;
|
const char *dbname, *dbtemp;
|
||||||
|
|
||||||
ERRNO_CHECK();
|
ERRNO_CHECK();
|
||||||
g_order_batchsize = config_get_int("game.dbbatch", 100);
|
|
||||||
dbname = config_get("game.dbname");
|
dbname = config_get("game.dbname");
|
||||||
if (!dbname) {
|
if (!dbname) dbname = "";
|
||||||
dbname = "";
|
err = sqlite3_open(dbname, &g_game_db);
|
||||||
}
|
|
||||||
err = sqlite3_open(dbname, &g_db);
|
|
||||||
assert(err == SQLITE_OK);
|
assert(err == SQLITE_OK);
|
||||||
err = sqlite3_exec(g_db, "PRAGMA journal_mode=OFF", NULL, NULL, NULL);
|
err = sqlite3_exec(g_game_db, "CREATE TABLE IF NOT EXISTS factions (id INTEGER PRIMARY KEY, no INTEGER NOT NULL, email VARCHAR(128), password VARCHAR(128), turn INTEGER NOT NULL)", NULL, NULL, NULL);
|
||||||
assert(err == SQLITE_OK);
|
assert(err == SQLITE_OK);
|
||||||
err = sqlite3_exec(g_db, "PRAGMA synchronous=OFF", NULL, NULL, NULL);
|
err = sqlite3_prepare_v2(g_game_db, "UPDATE factions SET no=?, turn=?, email=?, password=? WHERE id=?", -1, &g_stmt_update_faction, NULL);
|
||||||
assert(err == SQLITE_OK);
|
assert(err == SQLITE_OK);
|
||||||
err = sqlite3_exec(g_db, "CREATE TABLE IF NOT EXISTS orders (id INTEGER PRIMARY KEY, data TEXT NOT NULL)", NULL, NULL, NULL);
|
err = sqlite3_prepare_v2(g_game_db, "INSERT INTO factions (no, turn, email, password) VALUES (?,?,?,?)", -1, &g_stmt_insert_faction, NULL);
|
||||||
assert(err == SQLITE_OK);
|
assert(err == SQLITE_OK);
|
||||||
err = sqlite3_prepare_v2(g_db, "INSERT INTO orders (data) VALUES (?)", -1, &g_stmt_insert, NULL);
|
|
||||||
|
g_order_batchsize = config_get_int("game.dbbatch", 100);
|
||||||
|
dbtemp = config_get("game.db.temp");
|
||||||
|
err = sqlite3_open(dbtemp ? dbtemp : dbname, &g_temp_db);
|
||||||
assert(err == SQLITE_OK);
|
assert(err == SQLITE_OK);
|
||||||
err = sqlite3_prepare_v2(g_db, "SELECT data FROM orders WHERE id = ?", -1, &g_stmt_select, NULL);
|
err = sqlite3_exec(g_temp_db, "PRAGMA journal_mode=OFF", NULL, NULL, NULL);
|
||||||
assert(err == SQLITE_OK);
|
assert(err == SQLITE_OK);
|
||||||
|
err = sqlite3_exec(g_temp_db, "PRAGMA synchronous=OFF", NULL, NULL, NULL);
|
||||||
|
assert(err == SQLITE_OK);
|
||||||
|
err = sqlite3_exec(g_temp_db, "CREATE TABLE IF NOT EXISTS orders (id INTEGER PRIMARY KEY, data TEXT NOT NULL)", NULL, NULL, NULL);
|
||||||
|
assert(err == SQLITE_OK);
|
||||||
|
err = sqlite3_prepare_v2(g_temp_db, "INSERT INTO orders (data) VALUES (?)", -1, &g_stmt_insert_order, NULL);
|
||||||
|
assert(err == SQLITE_OK);
|
||||||
|
err = sqlite3_prepare_v2(g_temp_db, "SELECT data FROM orders WHERE id=?", -1, &g_stmt_select_order, NULL);
|
||||||
|
assert(err == SQLITE_OK);
|
||||||
|
|
||||||
ERRNO_CHECK();
|
ERRNO_CHECK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,12 +185,22 @@ void db_driver_close(void)
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
ERRNO_CHECK();
|
ERRNO_CHECK();
|
||||||
err = sqlite3_finalize(g_stmt_select);
|
if (g_temp_db) {
|
||||||
assert(err == SQLITE_OK);
|
err = sqlite3_finalize(g_stmt_select_order);
|
||||||
err = sqlite3_finalize(g_stmt_insert);
|
assert(err == SQLITE_OK);
|
||||||
assert(err == SQLITE_OK);
|
err = sqlite3_finalize(g_stmt_insert_order);
|
||||||
err = sqlite3_close(g_db);
|
assert(err == SQLITE_OK);
|
||||||
assert(err == SQLITE_OK);
|
err = sqlite3_close(g_temp_db);
|
||||||
|
assert(err == SQLITE_OK);
|
||||||
|
}
|
||||||
|
if (g_game_db) {
|
||||||
|
err = sqlite3_finalize(g_stmt_update_faction);
|
||||||
|
assert(err == SQLITE_OK);
|
||||||
|
err = sqlite3_finalize(g_stmt_insert_faction);
|
||||||
|
assert(err == SQLITE_OK);
|
||||||
|
err = sqlite3_close(g_game_db);
|
||||||
|
assert(err == SQLITE_OK);
|
||||||
|
}
|
||||||
ERRNO_CHECK();
|
ERRNO_CHECK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -230,7 +230,7 @@ static int unused_faction_id(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
faction *addfaction(const char *email, const char *password,
|
faction *addfaction(const char *email, const char *password,
|
||||||
const struct race * frace, const struct locale * loc, int subscription)
|
const struct race * frace, const struct locale * loc)
|
||||||
{
|
{
|
||||||
faction *f = calloc(sizeof(faction), 1);
|
faction *f = calloc(sizeof(faction), 1);
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
@ -249,7 +249,7 @@ faction *addfaction(const char *email, const char *password,
|
||||||
f->race = frace;
|
f->race = frace;
|
||||||
f->magiegebiet = 0;
|
f->magiegebiet = 0;
|
||||||
f->locale = loc;
|
f->locale = loc;
|
||||||
f->subscription = subscription;
|
f->uid = 0;
|
||||||
f->flags = FFL_ISNEW|FFL_PWMSG;
|
f->flags = FFL_ISNEW|FFL_PWMSG;
|
||||||
|
|
||||||
if (!password) password = itoa36(rng_int());
|
if (!password) password = itoa36(rng_int());
|
||||||
|
@ -393,7 +393,7 @@ faction *get_or_create_monsters(void)
|
||||||
if (!f) {
|
if (!f) {
|
||||||
const race *rc = rc_get_or_create("dragon");
|
const race *rc = rc_get_or_create("dragon");
|
||||||
const char *email = config_get("monster.email");
|
const char *email = config_get("monster.email");
|
||||||
f = addfaction(email, NULL, rc, default_locale, 0);
|
f = addfaction(email, NULL, rc, default_locale);
|
||||||
renumber_faction(f, MONSTER_ID);
|
renumber_faction(f, MONSTER_ID);
|
||||||
faction_setname(f, "Monster");
|
faction_setname(f, "Monster");
|
||||||
fset(f, FFL_NPC | FFL_NOIDLEOUT);
|
fset(f, FFL_NPC | FFL_NOIDLEOUT);
|
||||||
|
@ -839,7 +839,7 @@ int writepasswd(void)
|
||||||
|
|
||||||
for (f = factions; f; f = f->next) {
|
for (f = factions; f; f = f->next) {
|
||||||
fprintf(F, "%s:%s:%s:%d\n",
|
fprintf(F, "%s:%s:%s:%d\n",
|
||||||
itoa36(f->no), faction_getemail(f), f->_password, f->subscription);
|
itoa36(f->no), faction_getemail(f), f->_password, f->uid);
|
||||||
}
|
}
|
||||||
fclose(F);
|
fclose(F);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -61,7 +61,7 @@ extern "C" {
|
||||||
struct region *first;
|
struct region *first;
|
||||||
struct region *last;
|
struct region *last;
|
||||||
int no;
|
int no;
|
||||||
int subscription;
|
int uid;
|
||||||
int flags;
|
int flags;
|
||||||
char *name;
|
char *name;
|
||||||
char *banner;
|
char *banner;
|
||||||
|
@ -112,7 +112,7 @@ extern "C" {
|
||||||
const char *factionname(const struct faction *f);
|
const char *factionname(const struct faction *f);
|
||||||
struct unit *addplayer(struct region *r, faction * f);
|
struct unit *addplayer(struct region *r, faction * f);
|
||||||
struct faction *addfaction(const char *email, const char *password,
|
struct faction *addfaction(const char *email, const char *password,
|
||||||
const struct race *frace, const struct locale *loc, int subscription);
|
const struct race *frace, const struct locale *loc);
|
||||||
bool checkpasswd(const faction * f, const char *passwd);
|
bool checkpasswd(const faction * f, const char *passwd);
|
||||||
int writepasswd(void);
|
int writepasswd(void);
|
||||||
void destroyfaction(faction ** f);
|
void destroyfaction(faction ** f);
|
||||||
|
|
|
@ -112,7 +112,7 @@ static void test_addfaction(CuTest *tc) {
|
||||||
test_setup();
|
test_setup();
|
||||||
rc = rc_get_or_create("human");
|
rc = rc_get_or_create("human");
|
||||||
lang = test_create_locale();
|
lang = test_create_locale();
|
||||||
f = addfaction("test@eressea.de", "hurrdurr", rc, lang, 1234);
|
f = addfaction("test@eressea.de", "hurrdurr", rc, lang);
|
||||||
CuAssertPtrNotNull(tc, f);
|
CuAssertPtrNotNull(tc, f);
|
||||||
CuAssertPtrNotNull(tc, f->name);
|
CuAssertPtrNotNull(tc, f->name);
|
||||||
CuAssertPtrEquals(tc, NULL, (void *)f->units);
|
CuAssertPtrEquals(tc, NULL, (void *)f->units);
|
||||||
|
@ -124,7 +124,6 @@ static void test_addfaction(CuTest *tc) {
|
||||||
CuAssertStrEquals(tc, "test@eressea.de", f->email);
|
CuAssertStrEquals(tc, "test@eressea.de", f->email);
|
||||||
CuAssertTrue(tc, checkpasswd(f, "hurrdurr"));
|
CuAssertTrue(tc, checkpasswd(f, "hurrdurr"));
|
||||||
CuAssertPtrEquals(tc, (void *)lang, (void *)f->locale);
|
CuAssertPtrEquals(tc, (void *)lang, (void *)f->locale);
|
||||||
CuAssertIntEquals(tc, 1234, f->subscription);
|
|
||||||
CuAssertIntEquals(tc, FFL_ISNEW|FFL_PWMSG, f->flags);
|
CuAssertIntEquals(tc, FFL_ISNEW|FFL_PWMSG, f->flags);
|
||||||
CuAssertIntEquals(tc, 0, f->age);
|
CuAssertIntEquals(tc, 0, f->age);
|
||||||
CuAssertTrue(tc, faction_alive(f));
|
CuAssertTrue(tc, faction_alive(f));
|
||||||
|
|
|
@ -969,7 +969,10 @@ faction *read_faction(gamedata * data)
|
||||||
a_remove(&f->attribs, f->attribs);
|
a_remove(&f->attribs, f->attribs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
READ_INT(data->store, &f->subscription);
|
READ_INT(data->store, &f->uid);
|
||||||
|
if (data->version < FACTION_UID_VERSION) {
|
||||||
|
f->uid = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (data->version >= SPELL_LEVEL_VERSION) {
|
if (data->version >= SPELL_LEVEL_VERSION) {
|
||||||
READ_INT(data->store, &f->max_spelllevel);
|
READ_INT(data->store, &f->max_spelllevel);
|
||||||
|
@ -1100,7 +1103,7 @@ void write_faction(gamedata *data, const faction * f)
|
||||||
assert(f->_alive);
|
assert(f->_alive);
|
||||||
assert(f->no > 0 && f->no <= MAX_UNIT_NR);
|
assert(f->no > 0 && f->no <= MAX_UNIT_NR);
|
||||||
WRITE_INT(data->store, f->no);
|
WRITE_INT(data->store, f->no);
|
||||||
WRITE_INT(data->store, f->subscription);
|
WRITE_INT(data->store, f->uid);
|
||||||
#if RELEASE_VERSION >= SPELL_LEVEL_VERSION
|
#if RELEASE_VERSION >= SPELL_LEVEL_VERSION
|
||||||
WRITE_INT(data->store, f->max_spelllevel);
|
WRITE_INT(data->store, f->max_spelllevel);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1681,6 +1684,5 @@ int write_game(gamedata *data) {
|
||||||
WRITE_SECTION(store);
|
WRITE_SECTION(store);
|
||||||
write_borders(store);
|
write_borders(store);
|
||||||
WRITE_SECTION(store);
|
WRITE_SECTION(store);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
27
src/laws.c
27
src/laws.c
|
@ -3974,33 +3974,6 @@ void turn_end(void)
|
||||||
update_spells();
|
update_spells();
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_subscriptions(void)
|
|
||||||
{
|
|
||||||
FILE *F;
|
|
||||||
char zText[4096];
|
|
||||||
|
|
||||||
path_join(basepath(), "subscriptions", zText, sizeof(zText));
|
|
||||||
F = fopen(zText, "r");
|
|
||||||
if (F == NULL) {
|
|
||||||
log_warning(0, "could not open %s.\n", zText);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (;;) {
|
|
||||||
char zFaction[5];
|
|
||||||
int subscription, fno;
|
|
||||||
faction *f;
|
|
||||||
|
|
||||||
if (fscanf(F, "%4d %4s", &subscription, zFaction) <= 0)
|
|
||||||
break;
|
|
||||||
fno = atoi36(zFaction);
|
|
||||||
f = findfaction(fno);
|
|
||||||
if (f != NULL) {
|
|
||||||
f->subscription = subscription;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose(F);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** determine if unit can be seen by faction
|
/** determine if unit can be seen by faction
|
||||||
* @param f -- the observiong faction
|
* @param f -- the observiong faction
|
||||||
* @param u -- the unit that is observed
|
* @param u -- the unit that is observed
|
||||||
|
|
|
@ -41,7 +41,6 @@ extern "C" {
|
||||||
void demographics(void);
|
void demographics(void);
|
||||||
void immigration(void);
|
void immigration(void);
|
||||||
void update_guards(void);
|
void update_guards(void);
|
||||||
void update_subscriptions(void);
|
|
||||||
void deliverMail(struct faction *f, struct region *r, struct unit *u,
|
void deliverMail(struct faction *f, struct region *r, struct unit *u,
|
||||||
const char *s, struct unit *receiver);
|
const char *s, struct unit *receiver);
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,7 @@ static const char * valid_keys[] = {
|
||||||
"game.era",
|
"game.era",
|
||||||
"game.sender",
|
"game.sender",
|
||||||
"game.dbname",
|
"game.dbname",
|
||||||
|
"game.db.",
|
||||||
"game.dbbatch",
|
"game.dbbatch",
|
||||||
"editor.color",
|
"editor.color",
|
||||||
"editor.codepage",
|
"editor.codepage",
|
||||||
|
|
|
@ -95,7 +95,7 @@ newfaction *read_newfactions(const char *filename)
|
||||||
faction *f;
|
faction *f;
|
||||||
char race[20], email[64], lang[8], password[16];
|
char race[20], email[64], lang[8], password[16];
|
||||||
newfaction *nf, **nfi;
|
newfaction *nf, **nfi;
|
||||||
int alliance = 0, subscription = 0;
|
int alliance = 0, uid = 0;
|
||||||
|
|
||||||
if (fgets(buf, sizeof(buf), F) == NULL)
|
if (fgets(buf, sizeof(buf), F) == NULL)
|
||||||
break;
|
break;
|
||||||
|
@ -104,7 +104,7 @@ newfaction *read_newfactions(const char *filename)
|
||||||
password[0] = '\0';
|
password[0] = '\0';
|
||||||
|
|
||||||
if (sscanf(buf, "%54s %19s %7s %15s %4d %4d", email, race, lang,
|
if (sscanf(buf, "%54s %19s %7s %15s %4d %4d", email, race, lang,
|
||||||
password, &subscription, &alliance) < 3) {
|
password, &uid, &alliance) < 3) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (email[0] == '#') {
|
if (email[0] == '#') {
|
||||||
|
@ -137,13 +137,13 @@ newfaction *read_newfactions(const char *filename)
|
||||||
if (check_email(email) == 0) {
|
if (check_email(email) == 0) {
|
||||||
nf->email = str_strdup(email);
|
nf->email = str_strdup(email);
|
||||||
} else {
|
} else {
|
||||||
log_error("Invalid email address for subscription %s: %s\n", itoa36(subscription), email);
|
log_error("Invalid email address for subscription %s: %s\n", itoa36(uid), email);
|
||||||
free(nf);
|
free(nf);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
nf->password = str_strdup(password);
|
nf->password = str_strdup(password);
|
||||||
nf->race = rc_find(race);
|
nf->race = rc_find(race);
|
||||||
nf->subscription = subscription;
|
nf->uid = uid;
|
||||||
if (alliances != NULL) {
|
if (alliances != NULL) {
|
||||||
struct alliance *al = findalliance(alliance);
|
struct alliance *al = findalliance(alliance);
|
||||||
if (al == NULL) {
|
if (al == NULL) {
|
||||||
|
@ -557,7 +557,7 @@ int autoseed(newfaction ** players, int nsize, int max_agediff)
|
||||||
++tsize;
|
++tsize;
|
||||||
assert(r->land && r->units == 0);
|
assert(r->land && r->units == 0);
|
||||||
u = addplayer(r, addfaction(nextf->email, nextf->password, nextf->race,
|
u = addplayer(r, addfaction(nextf->email, nextf->password, nextf->race,
|
||||||
nextf->lang, nextf->subscription));
|
nextf->lang));
|
||||||
f = u->faction;
|
f = u->faction;
|
||||||
fset(f, FFL_ISNEW);
|
fset(f, FFL_ISNEW);
|
||||||
f->alliance = nextf->allies;
|
f->alliance = nextf->allies;
|
||||||
|
@ -857,7 +857,7 @@ static void starting_region(newfaction ** players, region * r, region * rn[])
|
||||||
const struct race *rc = nf->race ? nf->race : races;
|
const struct race *rc = nf->race ? nf->race : races;
|
||||||
const struct locale *lang = nf->lang ? nf->lang : default_locale;
|
const struct locale *lang = nf->lang ? nf->lang : default_locale;
|
||||||
const char * passwd = nf->password ? nf->password : itoa36(rng_int());
|
const char * passwd = nf->password ? nf->password : itoa36(rng_int());
|
||||||
addplayer(r, addfaction(nf->email, passwd, rc, lang, 0));
|
addplayer(r, addfaction(nf->email, passwd, rc, lang));
|
||||||
*players = nf->next;
|
*players = nf->next;
|
||||||
free_newfaction(nf);
|
free_newfaction(nf);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ extern "C" {
|
||||||
char *password;
|
char *password;
|
||||||
const struct locale *lang;
|
const struct locale *lang;
|
||||||
const struct race *race;
|
const struct race *race;
|
||||||
int subscription;
|
int uid;
|
||||||
bool oldregions;
|
bool oldregions;
|
||||||
struct alliance *allies;
|
struct alliance *allies;
|
||||||
} newfaction;
|
} newfaction;
|
||||||
|
|
|
@ -4192,7 +4192,7 @@ static int sp_calm_monster(castorder * co)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
effect = mage->faction->subscription;
|
effect = mage->faction->uid;
|
||||||
c = create_curse(mage, &target->attribs, &ct_calmmonster, force,
|
c = create_curse(mage, &target->attribs, &ct_calmmonster, force,
|
||||||
(int)force, effect, 0);
|
(int)force, effect, 0);
|
||||||
if (c == NULL) {
|
if (c == NULL) {
|
||||||
|
|
|
@ -166,7 +166,7 @@ struct locale * test_create_locale(void) {
|
||||||
struct faction *test_create_faction(const struct race *rc)
|
struct faction *test_create_faction(const struct race *rc)
|
||||||
{
|
{
|
||||||
struct locale * loc = test_create_locale();
|
struct locale * loc = test_create_locale();
|
||||||
faction *f = addfaction("nobody@eressea.de", NULL, rc ? rc : test_create_race("human"), loc, 0);
|
faction *f = addfaction("nobody@eressea.de", NULL, rc ? rc : test_create_race("human"), loc);
|
||||||
test_clear_messages(f);
|
test_clear_messages(f);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,10 +37,11 @@
|
||||||
#define SKILLSORT_VERSION 360 /* u->skills is sorted */
|
#define SKILLSORT_VERSION 360 /* u->skills is sorted */
|
||||||
#define LANDDISPLAY_VERSION 360 /* r.display is now in r.land.display */
|
#define LANDDISPLAY_VERSION 360 /* r.display is now in r.land.display */
|
||||||
#define FIXATKEYS_VERSION 361 /* remove global.attribs, fix at_keys */
|
#define FIXATKEYS_VERSION 361 /* remove global.attribs, fix at_keys */
|
||||||
|
#define FACTION_UID_VERSION 362 /* f->uid contains a database id */
|
||||||
/* unfinished: */
|
/* unfinished: */
|
||||||
#define CRYPT_VERSION 400 /* passwords are encrypted */
|
#define CRYPT_VERSION 400 /* passwords are encrypted */
|
||||||
|
|
||||||
#define RELEASE_VERSION FIXATKEYS_VERSION /* current datafile */
|
#define RELEASE_VERSION FACTION_UID_VERSION /* current datafile */
|
||||||
#define MIN_VERSION UIDHASH_VERSION /* minimal datafile we support */
|
#define MIN_VERSION UIDHASH_VERSION /* minimal datafile we support */
|
||||||
#define MAX_VERSION RELEASE_VERSION /* change this if we can need to read the future datafile, and we can do so */
|
#define MAX_VERSION RELEASE_VERSION /* change this if we can need to read the future datafile, and we can do so */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue