MJ: attack coordinator update / various fixes . captcha and back button and jitterloop 2 secs

This commit is contained in:
2026-05-03 12:40:20 +03:00
parent 47381a9304
commit eb31072c87
16 changed files with 1492 additions and 31 deletions

48
db.py
View File

@@ -123,7 +123,55 @@ def init_db():
''')
c.execute('CREATE INDEX IF NOT EXISTS idx_movements_player_world ON movements(player_id, world_id)')
# Attack Plans — coordinated timed strikes across multiple players/towns
c.execute('''
CREATE TABLE IF NOT EXISTS attack_plans (
id INTEGER PRIMARY KEY AUTOINCREMENT,
world_id TEXT NOT NULL,
plan_name TEXT NOT NULL,
created_by_player_id TEXT NOT NULL,
target_town_id TEXT,
target_town_name TEXT,
target_x REAL,
target_y REAL,
target_arrival_time INTEGER NOT NULL, -- unix epoch (UTC)
status TEXT NOT NULL DEFAULT 'draft',
-- draft | active | completed | cancelled
created_at TEXT NOT NULL DEFAULT (datetime('now')),
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
)
''')
c.execute('CREATE INDEX IF NOT EXISTS idx_attack_plans_world ON attack_plans(world_id, status)')
# Attack Plan Participants — one row per attacking town per plan
c.execute('''
CREATE TABLE IF NOT EXISTS attack_plan_participants (
id INTEGER PRIMARY KEY AUTOINCREMENT,
plan_id INTEGER NOT NULL REFERENCES attack_plans(id) ON DELETE CASCADE,
player_id TEXT NOT NULL,
world_id TEXT NOT NULL,
origin_town_id TEXT NOT NULL,
origin_town_name TEXT,
units TEXT NOT NULL DEFAULT '{}', -- JSON
attack_type TEXT, -- 'attack_land' | 'attack_sea'
transport_needed INTEGER NOT NULL DEFAULT 0,
transport_count INTEGER NOT NULL DEFAULT 0,
travel_time_secs INTEGER,
send_time INTEGER, -- unix epoch (UTC), calculated
return_time INTEGER, -- unix epoch (UTC), calculated
is_feasible INTEGER NOT NULL DEFAULT 1,
error_msg TEXT,
status TEXT NOT NULL DEFAULT 'pending',
-- pending | armed | sent | missed | cancelled
updated_at TEXT NOT NULL DEFAULT (datetime('now')),
UNIQUE(plan_id, origin_town_id)
)
''')
c.execute('CREATE INDEX IF NOT EXISTS idx_app_plan ON attack_plan_participants(plan_id)')
c.execute('CREATE INDEX IF NOT EXISTS idx_app_player ON attack_plan_participants(player_id, world_id)')
# Migration: add new columns if upgrading an existing database
for _col in [
'ALTER TABLE town_state ADD COLUMN player_id TEXT',
'ALTER TABLE town_state ADD COLUMN alliance_id TEXT',