#!/usr/bin/env python3 # # InspIRCd -- Internet Relay Chat Daemon # # Copyright (C) 2024 Val Lorentz # Copyright (C) 2024 Sadie Powell # # This file is part of InspIRCd. InspIRCd is free software: you can # redistribute it and/or modify it under the terms of the GNU General Public # License as published by the Free Software Foundation, version 2. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # import io import os import sys class UnrealDB: def __init__(self, path): self.error = None try: with open(sys.argv[1], mode="rb") as fh: data = fh.read() if data.startswith(b"UnrealIRCd-DB-v1"): self.data = io.BytesIO(data[40:]) elif data.startswith(b"UnrealIRCd-DB"): self.error = f"Unsupported database version: {data[0:32]}" else: self.data = io.BytesIO(data) except OSError as e: self.error = f"Read error: {e}" def read_i16(self): return int.from_bytes(self.data.read(2), byteorder="little") def read_i32(self): return int.from_bytes(self.data.read(4), byteorder="little") def read_i64(self): return int.from_bytes(self.data.read(8), byteorder="little") def read_str(self): len = self.read_i16() if len == 0 or len == 0xFFFF: return "" return self.data.read(len).decode("utf-8") def error(msg): print(msg, file=sys.stderr) sys.exit(1) if len(sys.argv) < 3: program = os.path.basename(__file__) error(f"Usage: {program} ") db = UnrealDB(sys.argv[1]) if db.error: error(db.error) version = db.read_i32() if version != 100: error(f"Unrecognised channel database version: {version}") count = db.read_i64() print(f"Converting {count} channels ...") try: with open(sys.argv[2], mode="w") as fh: for i in range(count): magic = db.read_i32() if magic != 0x11111111: error(f"Unrecognised database start magic: {magic}") channel = db.read_str() print(f'", file=fh) except OSError as e: error(f"Write error: {e}")