forked from github/server
made some changes on a blanket by the river.
This commit is contained in:
parent
7302f7cd4c
commit
e21a670a93
|
@ -104,7 +104,7 @@ FILE *logfile;
|
||||||
FILE *updatelog;
|
FILE *updatelog;
|
||||||
const struct race * new_race[MAXRACES];
|
const struct race * new_race[MAXRACES];
|
||||||
boolean sqlpatch = false;
|
boolean sqlpatch = false;
|
||||||
int turn;
|
int turn = 0;
|
||||||
|
|
||||||
#if XECMD_MODULE
|
#if XECMD_MODULE
|
||||||
attrib_type at_xontormiaexpress = {
|
attrib_type at_xontormiaexpress = {
|
||||||
|
@ -2203,7 +2203,9 @@ init_data(const char * filename)
|
||||||
l = read_xml(zText);
|
l = read_xml(zText);
|
||||||
if (l) return l;
|
if (l) return l;
|
||||||
|
|
||||||
if (turn<first_turn) turn = first_turn;
|
if (turn<0) {
|
||||||
|
turn = first_turn;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3020,7 +3022,7 @@ kernel_init(void)
|
||||||
attrib_init();
|
attrib_init();
|
||||||
translation_init();
|
translation_init();
|
||||||
|
|
||||||
if (!turn) turn = lastturn();
|
if (turn<0) turn = lastturn();
|
||||||
if (sqlpatch) {
|
if (sqlpatch) {
|
||||||
sprintf(zBuffer, "%s/patch-%d.sql", datapath(), turn);
|
sprintf(zBuffer, "%s/patch-%d.sql", datapath(), turn);
|
||||||
sql_init(zBuffer);
|
sql_init(zBuffer);
|
||||||
|
|
|
@ -55,13 +55,11 @@ stmt_cache_get(sqlite3 * db, const char * sql)
|
||||||
}
|
}
|
||||||
i = cache_insert;
|
i = cache_insert;
|
||||||
res = sqlite3_finalize(cache[i].stmt);
|
res = sqlite3_finalize(cache[i].stmt);
|
||||||
SQL_EXPECT(res, SQLITE_OK);
|
|
||||||
}
|
}
|
||||||
cache[i].inuse = 1;
|
cache[i].inuse = 1;
|
||||||
cache[i].db = db;
|
cache[i].db = db;
|
||||||
cache[i].sql = sql;
|
cache[i].sql = sql;
|
||||||
res = sqlite3_prepare_v2(db, sql, -1, &cache[i].stmt, NULL);
|
res = sqlite3_prepare_v2(db, sql, -1, &cache[i].stmt, NULL);
|
||||||
SQL_EXPECT(res, SQLITE_OK);
|
|
||||||
return cache[i].stmt;
|
return cache[i].stmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,3 +227,30 @@ db_update_factions(sqlite3 * db, boolean force)
|
||||||
}
|
}
|
||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
db_update_scores(sqlite3 * db, boolean force)
|
||||||
|
{
|
||||||
|
const char * sql_ins = "INSERT OR FAIL INTO score (value,faction_id,turn) VALUES (?,?,?)";
|
||||||
|
sqlite3_stmt * stmt_ins = stmt_cache_get(db, sql_ins);
|
||||||
|
const char * sql_upd = "UPDATE score set value=? WHERE faction_id=? AND turn=?";
|
||||||
|
sqlite3_stmt * stmt_upd = stmt_cache_get(db, sql_upd);
|
||||||
|
faction * f;
|
||||||
|
for (f=factions;f;f=f->next) {
|
||||||
|
int res;
|
||||||
|
sqlite3_bind_int(stmt_ins, 1, f->score);
|
||||||
|
sqlite3_bind_int64(stmt_ins, 2, f->subscription);
|
||||||
|
sqlite3_bind_int(stmt_ins, 3, turn);
|
||||||
|
res = sqlite3_step(stmt_ins);
|
||||||
|
if (res==SQLITE_CONSTRAINT) {
|
||||||
|
sqlite3_bind_int(stmt_upd, 1, f->score);
|
||||||
|
sqlite3_bind_int64(stmt_upd, 2, f->subscription);
|
||||||
|
sqlite3_bind_int(stmt_upd, 3, turn);
|
||||||
|
res = sqlite3_step(stmt_upd);
|
||||||
|
sqlite3_reset(stmt_upd);
|
||||||
|
}
|
||||||
|
SQL_EXPECT(res, SQLITE_DONE);
|
||||||
|
sqlite3_reset(stmt_ins);
|
||||||
|
}
|
||||||
|
return SQLITE_OK;
|
||||||
|
}
|
|
@ -124,7 +124,7 @@
|
||||||
/>
|
/>
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCCLCompilerTool"
|
Name="VCCLCompilerTool"
|
||||||
AdditionalIncludeDirectories=".;common"
|
AdditionalIncludeDirectories=".;common;external"
|
||||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||||
RuntimeLibrary="2"
|
RuntimeLibrary="2"
|
||||||
UsePrecompiledHeader="2"
|
UsePrecompiledHeader="2"
|
||||||
|
|
|
@ -592,6 +592,7 @@ load_inifile(const char * filename)
|
||||||
if (str) enc_gamedata = xmlParseCharEncoding(str);
|
if (str) enc_gamedata = xmlParseCharEncoding(str);
|
||||||
|
|
||||||
verbosity = iniparser_getint(d, "eressea:verbose", 2);
|
verbosity = iniparser_getint(d, "eressea:verbose", 2);
|
||||||
|
sqlpatch = iniparser_getint(d, "eressea:sqlpatch", false);
|
||||||
battledebug = iniparser_getint(d, "eressea:debug", battledebug)?1:0;
|
battledebug = iniparser_getint(d, "eressea:debug", battledebug)?1:0;
|
||||||
|
|
||||||
preload = iniparser_getstring(d, "eressea:preload", preload);
|
preload = iniparser_getstring(d, "eressea:preload", preload);
|
||||||
|
@ -665,11 +666,10 @@ main(int argc, char *argv[])
|
||||||
char * lc_ctype;
|
char * lc_ctype;
|
||||||
char * lc_numeric;
|
char * lc_numeric;
|
||||||
lua_State * L = lua_init();
|
lua_State * L = lua_init();
|
||||||
static int write_csv = 1;
|
static int write_csv = 0;
|
||||||
|
|
||||||
setup_signal_handler();
|
setup_signal_handler();
|
||||||
|
|
||||||
sqlpatch = true;
|
|
||||||
log_open("eressea.log");
|
log_open("eressea.log");
|
||||||
|
|
||||||
lc_ctype = setlocale(LC_CTYPE, "");
|
lc_ctype = setlocale(LC_CTYPE, "");
|
||||||
|
@ -716,7 +716,7 @@ main(int argc, char *argv[])
|
||||||
filename = strtok(NULL, ":");
|
filename = strtok(NULL, ":");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (luafile==NULL) lua_console(L);
|
if (luafile==NULL || turn==0) lua_console(L);
|
||||||
else {
|
else {
|
||||||
char buf[MAX_PATH];
|
char buf[MAX_PATH];
|
||||||
if (script_path) {
|
if (script_path) {
|
||||||
|
|
|
@ -479,8 +479,9 @@ tolua_faction_open(lua_State* L)
|
||||||
{
|
{
|
||||||
tolua_function(L, TOLUA_CAST "__tostring", tolua_faction_tostring);
|
tolua_function(L, TOLUA_CAST "__tostring", tolua_faction_tostring);
|
||||||
|
|
||||||
tolua_variable(L, TOLUA_CAST "name", &tolua_faction_get_name, &tolua_faction_set_name);
|
tolua_variable(L, TOLUA_CAST "id", tolua_faction_get_id, tolua_faction_set_id);
|
||||||
tolua_variable(L, TOLUA_CAST "uid", &tolua_faction_get_uid, &tolua_faction_set_uid);
|
tolua_variable(L, TOLUA_CAST "uid", &tolua_faction_get_uid, &tolua_faction_set_uid);
|
||||||
|
tolua_variable(L, TOLUA_CAST "name", &tolua_faction_get_name, &tolua_faction_set_name);
|
||||||
tolua_variable(L, TOLUA_CAST "info", &tolua_faction_get_info, &tolua_faction_set_info);
|
tolua_variable(L, TOLUA_CAST "info", &tolua_faction_get_info, &tolua_faction_set_info);
|
||||||
tolua_variable(L, TOLUA_CAST "units", tolua_faction_get_units, NULL);
|
tolua_variable(L, TOLUA_CAST "units", tolua_faction_get_units, NULL);
|
||||||
tolua_variable(L, TOLUA_CAST "heroes", tolua_faction_get_heroes, NULL);
|
tolua_variable(L, TOLUA_CAST "heroes", tolua_faction_get_heroes, NULL);
|
||||||
|
@ -492,7 +493,6 @@ tolua_faction_open(lua_State* L)
|
||||||
tolua_variable(L, TOLUA_CAST "race", tolua_faction_get_race, tolua_faction_set_race);
|
tolua_variable(L, TOLUA_CAST "race", tolua_faction_get_race, tolua_faction_set_race);
|
||||||
tolua_variable(L, TOLUA_CAST "alliance", tolua_faction_get_alliance, tolua_faction_set_alliance);
|
tolua_variable(L, TOLUA_CAST "alliance", tolua_faction_get_alliance, tolua_faction_set_alliance);
|
||||||
tolua_variable(L, TOLUA_CAST "score", tolua_faction_get_score, NULL);
|
tolua_variable(L, TOLUA_CAST "score", tolua_faction_get_score, NULL);
|
||||||
tolua_variable(L, TOLUA_CAST "id", tolua_faction_get_id, tolua_faction_set_id);
|
|
||||||
tolua_variable(L, TOLUA_CAST "age", tolua_faction_get_age, tolua_faction_set_age);
|
tolua_variable(L, TOLUA_CAST "age", tolua_faction_get_age, tolua_faction_set_age);
|
||||||
tolua_variable(L, TOLUA_CAST "options", tolua_faction_get_options, tolua_faction_set_options);
|
tolua_variable(L, TOLUA_CAST "options", tolua_faction_get_options, tolua_faction_set_options);
|
||||||
tolua_variable(L, TOLUA_CAST "flags", tolua_faction_get_flags, NULL);
|
tolua_variable(L, TOLUA_CAST "flags", tolua_faction_get_flags, NULL);
|
||||||
|
|
|
@ -34,6 +34,7 @@ without prior permission by the authors of Eressea.
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
#include <util/base36.h>
|
#include <util/base36.h>
|
||||||
#include <util/language.h>
|
#include <util/language.h>
|
||||||
|
#include <util/log.h>
|
||||||
|
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
#include <tolua.h>
|
#include <tolua.h>
|
||||||
|
@ -265,14 +266,21 @@ tolua_region_get_resourcelevel(lua_State* L)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define LUA_ASSERT(c, s) if (!(c)) { log_error(("%s(%d): %s\n", __FILE__, __LINE__, (s))); return 0; }
|
||||||
static int
|
static int
|
||||||
tolua_region_get_resource(lua_State* L)
|
tolua_region_get_resource(lua_State* L)
|
||||||
{
|
{
|
||||||
region * r = (region *)tolua_tousertype(L, 1, 0);
|
region * r;
|
||||||
const char * type = tolua_tostring(L, 2, 0);
|
const char * type;
|
||||||
const resource_type * rtype = rt_find(type);
|
const resource_type * rtype;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
|
r = (region *)tolua_tousertype(L, 1, 0);
|
||||||
|
LUA_ASSERT(r!=NULL, "invalid parameter");
|
||||||
|
type = tolua_tostring(L, 2, 0);
|
||||||
|
LUA_ASSERT(type!=NULL, "invalid parameter");
|
||||||
|
rtype = rt_find(type);
|
||||||
|
|
||||||
if (!rtype) {
|
if (!rtype) {
|
||||||
if (strcmp(type, "seed")==0) result = rtrees(r, 0);
|
if (strcmp(type, "seed")==0) result = rtrees(r, 0);
|
||||||
if (strcmp(type, "sapling")==0) result = rtrees(r, 1);
|
if (strcmp(type, "sapling")==0) result = rtrees(r, 1);
|
||||||
|
|
|
@ -30,6 +30,27 @@ tolua_db_update_factions(lua_State* L)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern int db_update_scores(sqlite3 * db, boolean force);
|
||||||
|
static int
|
||||||
|
tolua_db_update_scores(lua_State* L)
|
||||||
|
{
|
||||||
|
sqlite3 * db = (sqlite3 *)tolua_tousertype(L, 1, 0);
|
||||||
|
db_update_scores(db, tolua_toboolean(L, 2, 0));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
tolua_db_execute(lua_State* L)
|
||||||
|
{
|
||||||
|
sqlite3 * db = (sqlite3 *)tolua_tousertype(L, 1, 0);
|
||||||
|
const char * sql = tolua_tostring(L, 2, 0);
|
||||||
|
|
||||||
|
int res = sqlite3_exec(db, sql, 0, 0, 0);
|
||||||
|
|
||||||
|
tolua_pushnumber(L, (LUA_NUMBER)res);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
tolua_db_close(lua_State* L)
|
tolua_db_close(lua_State* L)
|
||||||
{
|
{
|
||||||
|
@ -68,6 +89,8 @@ tolua_sqlite_open(lua_State * L)
|
||||||
tolua_function(L, TOLUA_CAST "close", &tolua_db_close);
|
tolua_function(L, TOLUA_CAST "close", &tolua_db_close);
|
||||||
|
|
||||||
tolua_function(L, TOLUA_CAST "update_factions", &tolua_db_update_factions);
|
tolua_function(L, TOLUA_CAST "update_factions", &tolua_db_update_factions);
|
||||||
|
tolua_function(L, TOLUA_CAST "update_scores", &tolua_db_update_scores);
|
||||||
|
tolua_function(L, TOLUA_CAST "execute", &tolua_db_execute);
|
||||||
}
|
}
|
||||||
tolua_endmodule(L);
|
tolua_endmodule(L);
|
||||||
|
|
||||||
|
|
|
@ -61,8 +61,26 @@ end
|
||||||
function write_files(locales)
|
function write_files(locales)
|
||||||
write_passwords()
|
write_passwords()
|
||||||
write_reports()
|
write_reports()
|
||||||
write_emails(locales)
|
|
||||||
write_aliases()
|
|
||||||
write_summary()
|
write_summary()
|
||||||
write_addresses()
|
-- write_emails(locales)
|
||||||
|
-- write_aliases()
|
||||||
|
-- write_addresses()
|
||||||
|
end
|
||||||
|
|
||||||
|
function write_scores()
|
||||||
|
scores = {}
|
||||||
|
for r in regions() do
|
||||||
|
f = r.owner
|
||||||
|
if f~=nil then
|
||||||
|
value = scores[f.id]
|
||||||
|
if value==nil then value=0 end
|
||||||
|
value = value + r:get_resource("money")/100
|
||||||
|
scores[f.id] = value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for f in factions() do
|
||||||
|
score=scores[f.id]
|
||||||
|
if score==nil then score=0 end
|
||||||
|
print(math.floor(score)..":"..f.name..":"..itoa36(f.id))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,5 +2,5 @@ CREATE TABLE email(id INTEGER PRIMARY KEY, md5 VARCHAR(32) UNIQUE NOT NULL, emai
|
||||||
CREATE TABLE faction (id INTEGER PRIMARY KEY, user_id INTEGER REFERENCES user(id), no INTEGER, name VARCHAR(64), game_id INTEGER REFERENCES game(id), race VARCHAR(10), lang CHAR(2));
|
CREATE TABLE faction (id INTEGER PRIMARY KEY, user_id INTEGER REFERENCES user(id), no INTEGER, name VARCHAR(64), game_id INTEGER REFERENCES game(id), race VARCHAR(10), lang CHAR(2));
|
||||||
CREATE TABLE faction_email (faction_id INTEGER REFERENCES faction(id), email_id INTEGER REFERENCES email(id));
|
CREATE TABLE faction_email (faction_id INTEGER REFERENCES faction(id), email_id INTEGER REFERENCES email(id));
|
||||||
CREATE TABLE game (id INTEGER PRIMARY KEY, name VARCHAR(20), last_turn INTEGER);
|
CREATE TABLE game (id INTEGER PRIMARY KEY, name VARCHAR(20), last_turn INTEGER);
|
||||||
CREATE TABLE score (turn INTEGER, faction_id INTEGER REFERENCES faction(id), value INTEGER, game_id INTEGER REFERENCES game(id));
|
CREATE TABLE score (turn INTEGER, faction_id INTEGER REFERENCES faction(id), value INTEGER, UNIQUE(turn, faction_id));
|
||||||
CREATE TABLE user(id INTEGER PRIMARY KEY, email_id INTEGER REFERENCES email(id), creation TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
|
CREATE TABLE user(id INTEGER PRIMARY KEY, email_id INTEGER REFERENCES email(id), creation TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
|
||||||
|
|
Loading…
Reference in New Issue