| """ |
| Server-side currency tool for YOUR Open-MT2 DB (not official Gameforge live). |
| Usage: |
| python set_player_gold.py --name PlayerName --gold 999999999 |
| python set_player_gold.py --account admin --gold 5000000 --all-chars |
| """ |
| from __future__ import annotations |
|
|
| import argparse |
| import sys |
|
|
| try: |
| import mysql.connector |
| except ImportError: |
| import subprocess |
|
|
| subprocess.check_call([sys.executable, "-m", "pip", "install", "mysql-connector-python", "-q"]) |
| import mysql.connector |
|
|
|
|
| def main() -> None: |
| p = argparse.ArgumentParser(description="Set gold on local Open-MT2 game DB") |
| p.add_argument("--host", default="127.0.0.1") |
| p.add_argument("--port", type=int, default=3306) |
| p.add_argument("--user", default="root") |
| p.add_argument("--password", default="") |
| p.add_argument("--gold", type=int, required=True) |
| p.add_argument("--name", help="player character name") |
| p.add_argument("--account", help="account username (auth.account)") |
| p.add_argument("--all-chars", action="store_true", help="with --account, all characters") |
| args = p.parse_args() |
|
|
| if not args.name and not args.account: |
| p.error("provide --name and/or --account") |
|
|
| cn = mysql.connector.connect( |
| host=args.host, |
| port=args.port, |
| user=args.user, |
| password=args.password, |
| connection_timeout=5, |
| ) |
| cur = cn.cursor(dictionary=True) |
|
|
| if args.name: |
| cur.execute("UPDATE game.player SET gold=%s WHERE name=%s", (args.gold, args.name)) |
| print(f"updated name={args.name} gold={args.gold} rows={cur.rowcount}") |
|
|
| if args.account: |
| cur.execute("SELECT id FROM auth.account WHERE username=%s", (args.account,)) |
| row = cur.fetchone() |
| if not row: |
| print(f"account not found: {args.account}") |
| else: |
| aid = row["id"] |
| if args.all_chars or not args.name: |
| cur.execute("UPDATE game.player SET gold=%s WHERE accountId=%s", (args.gold, aid)) |
| print(f"updated account={args.account} id={aid} gold={args.gold} rows={cur.rowcount}") |
|
|
| cn.commit() |
| cur.close() |
| cn.close() |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|