30 lines
1.4 KiB
Python
30 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Install the two small command hooks in a server source tree, keeping byte encoding intact."""
|
|
from pathlib import Path
|
|
import shutil
|
|
import sys
|
|
|
|
source, stage = map(Path, sys.argv[1:3])
|
|
here = Path(__file__).resolve().parent
|
|
for filename, marker, insertion in (
|
|
('cmd_general.cpp', b'#include "autohunt_pull.h"', b'\n#include "biolog_remote.h"'),
|
|
('cmd.cpp', b'ACMD(do_server_bonuses);', b'\nACMD(do_port_biolog);'),
|
|
):
|
|
path = source / filename
|
|
data = path.read_bytes()
|
|
if insertion.strip() not in data:
|
|
if data.count(marker) != 1:
|
|
raise RuntimeError('source hook mismatch: ' + str(path))
|
|
data = data.replace(marker, marker + insertion)
|
|
if filename == 'cmd.cpp' and b'{ "biolog",' not in data:
|
|
marker = b'\t{ "server_bonuses",'
|
|
if data.count(marker) != 1:
|
|
raise RuntimeError('command registry mismatch')
|
|
data = data.replace(marker, b'\t{ "biolog", do_port_biolog, 0, POS_DEAD, GM_PLAYER },\n' + marker)
|
|
if filename == 'cmd.cpp' and b'{ "bio",' not in data:
|
|
marker = b'\t{ "biolog",'
|
|
data = data.replace(marker, b'\t{ "bio", do_port_biolog, 0, POS_DEAD, GM_PLAYER },\n' + marker)
|
|
path.write_bytes(data)
|
|
for name, root in [('biolog_remote.h', here), ('ava2_biolog_core.h', here), ('ava2_biolog_shop.h', here)]:
|
|
shutil.copy2(root / name, source / name)
|