Files
AVA2/tools/expand_python_net.py

48 lines
2.0 KiB
Python

#!/usr/bin/env python3
import re
from pathlib import Path
root = Path(__file__).resolve().parents[1]
net_cpp_src = root / "upstream/ava2-client/UserInterface/PythonNetworkStreamModule.cpp"
with open(net_cpp_src, "r", encoding="latin1") as f:
text = f.read()
methods = re.findall(r'\{\s*"(\w+)"\s*,\s*(\w+)\s*,', text)
upstream_method_names = [m[0] for m in methods]
# Read current python_net.cpp
with open(root / "src/python_net.cpp", "r") as f:
current_net = f.read()
# We already have:
implemented = {
"SetHandler", "SetAccountConnectorHandler", "SetPhaseWindow", "ClearPhaseWindow",
"SetLoginInfo", "ConnectToAccountServer", "Disconnect", "SetPacketSequenceMode",
"SendSelectCharacterPacket", "GetAccountCharacterSlotDataInteger", "GetAccountCharacterSlotDataString",
"GetEmpireID", "Update", "GetConnectionState"
}
missing = [m for m in upstream_method_names if m not in implemented]
print(f"Total upstream methods: {len(upstream_method_names)}, already implemented: {len(implemented)}, missing to add: {len(missing)}")
dummy_functions = """
PyObject* net_dummy_none(PyObject*, PyObject*) { Py_RETURN_NONE; }
PyObject* net_dummy_zero(PyObject*, PyObject*) { return PyInt_FromLong(0); }
PyObject* net_dummy_one(PyObject*, PyObject*) { return PyInt_FromLong(1); }
PyObject* net_dummy_empty_str(PyObject*, PyObject*) { return PyString_FromString(""); }
"""
# Insert dummy functions and missing methods in s_methods
method_entries = []
for name in missing:
if name.startswith("Is") or name.startswith("Get"):
if "Name" in name or "Command" in name or "Info" in name:
method_entries.append(f' {{"{name}", net_dummy_empty_str, METH_VARARGS, nullptr}},')
else:
method_entries.append(f' {{"{name}", net_dummy_zero, METH_VARARGS, nullptr}},')
else:
method_entries.append(f' {{"{name}", net_dummy_none, METH_VARARGS, nullptr}},')
print(f"Prepared {len(method_entries)} missing methods entries.")