7 con.execute(
"PRAGMA journal_mode=WAL;");
8 con.execute(
"PRAGMA synchronous=NORMAL;");
9 con.execute(
"CREATE TABLE IF NOT EXISTS schema(version INT);");
11 result = con.execute(
"SELECT COALESCE(MAX(version), 0) FROM schema").fetchall();
14 Crossfire.Log(Crossfire.LogInfo,
15 "Initializing factions schema %d->%d" % (curr, version))
18 with open(schema_files[0])
as initfile:
19 con.executescript(initfile.read())
21 for f
in schema_files:
23 if f.split(
"/").pop() == f
"update_schema_{curr}_{curr+1}.sql":
24 with open(f)
as updfile:
25 con.executescript(updfile.read())
30 return os.path.join(Crossfire.DataDirectory(), Crossfire.MapDirectory(),
31 "python/CFReputation/sql", f)
35 schema_files =
map(_get_sql_path, [
"schema.sql",
"update_schema_1_2.sql"])
36 init_files =
map(_get_sql_path, [
"init.sql",
"gods.sql"])
37 db_path = os.path.join(Crossfire.LocalDirectory(),
"factions.db")
38 con = sqlite3.connect(db_path)
41 with open(f)
as initfile:
42 con.executescript(initfile.read())
50 Return tuple with the name and reputation of the player with the given
51 faction. If faction is None, return all known reputations.
56 SELECT faction, CAST(ROUND(reputation*100) as integer) as rep
58 WHERE name=? AND ABS(rep) > 0;
60 result = con.execute(query, (player,)).fetchall()
63 SELECT faction, CAST(ROUND(reputation*100) as integer) as rep
65 WHERE name=? AND faction=? AND ABS(rep) > 0;
67 result = con.execute(query, (player, faction)).fetchall()
71 def record_kill(race, region, player, fraction=0.0001, limit=0.4):
75 SELECT faction, -attitude*? AS change
77 NATURAL JOIN relations
78 WHERE race=? AND (region=? OR region='ALL'))
79 REPLACE INTO reputations
80 SELECT ? AS player, updates.faction,
81 COALESCE(reputation, 0) + change AS new_rep
84 ON updates.faction=reputations.faction AND player=reputations.name
85 WHERE ABS(new_rep) <= ?;
87 con.execute(query, (fraction, race, region, player, limit))