from pathlib import Path
import re, sys
server=Path(sys.argv[1])
p=server/'relay_server_clean.py'
s=p.read_text(encoding='utf-8')
s,n=re.subn(r'VERSION\s*=\s*["\'][^"\']+["\']','VERSION  = "2.4.9.391-unified-friend-communication-secure"',s,count=1)
if n!=1: raise SystemExit('VERSION_PATCH_COUNT='+str(n))
marker='\n# BEGIN V249391_UNIFIED_FRIEND_COMMUNICATION_SECURE\n# Frontend controller owns proposal/accept/reject/message/voice/video/secure-lock routing.\n# END V249391_UNIFIED_FRIEND_COMMUNICATION_SECURE\n'
if 'V249391_UNIFIED_FRIEND_COMMUNICATION_SECURE' not in s:s+=marker
p.write_text(s,encoding='utf-8')
print('SERVER_VERSION_V249391=OK')
