210 lines
8.8 KiB
Python
Executable File
210 lines
8.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
"""
|
|
ChaCha DoConfig script
|
|
"""
|
|
|
|
import argparse
|
|
from enum import Enum
|
|
from dataclasses import dataclass
|
|
from collections import OrderedDict
|
|
from os.path import join
|
|
#from abc import ABC, abstractmethod
|
|
|
|
from pprint import pprint
|
|
from ChaChaSimpleINI import ChaChaSimpleINI
|
|
|
|
class OptionType(Enum):
|
|
OT_INVALID = 0
|
|
OT_STRING = 1
|
|
OT_INTEGER = 2
|
|
OT_BOOLEAN = 3
|
|
OT_FLOAT = 4
|
|
|
|
@dataclass
|
|
class GameOptionINI:
|
|
szOptionName:str = ""
|
|
szSectionName:str = ""
|
|
szKeyName:str = ""
|
|
TValueType:OptionType = OptionType.OT_INVALID
|
|
szDefaultValue:str = ""
|
|
szHelp:str = ""
|
|
bForceAdd:bool = False
|
|
|
|
def set(self,inifile:ChaChaSimpleINI,value:str):
|
|
print("set option <{0}> to: {1}".format(self.szOptionName,value))
|
|
if self.TValueType == OptionType.OT_STRING:
|
|
value = str(value)
|
|
elif self.TValueType == OptionType.OT_INTEGER:
|
|
value = int(value)
|
|
elif self.TValueType == OptionType.OT_BOOLEAN:
|
|
value = bool(value)
|
|
elif self.TValueType == OptionType.OT_FLOAT:
|
|
value = float(value)
|
|
else:
|
|
raise RuntimeError("Invalid Option TValueType")
|
|
|
|
inifile.setAddKeyValue(self.szSectionName,self.szKeyName,value)
|
|
|
|
def get(self,inifile:ChaChaSimpleINI):
|
|
print("get option <{0}>".format(self.szOptionName))
|
|
return inifile.getKeyValue(self.szSectionName,self.szKeyName)
|
|
|
|
class GameOptions_UT99_Port(GameOptionINI):
|
|
def __init__(self):
|
|
super().__init__( "Port","URL","Port",OptionType.OT_INTEGER,7777,"Server Listening port",False)
|
|
|
|
class GameOptions_UT99_Map(GameOptionINI):
|
|
def __init__(self):
|
|
super().__init__( "Map","URL","Map",OptionType.OT_STRING,"dm-deck16][","Server Map",False)
|
|
|
|
class GameOptions_UT99_GameType(GameOptionINI):
|
|
def __init__(self):
|
|
super().__init__( "GameType","Engine.Engine","DefaultServerGame",OptionType.OT_STRING,"Botpack.DeathMatchPlus","Server Gametype",False)
|
|
|
|
class GameOptions_UT99_HostName(GameOptionINI):
|
|
def __init__(self):
|
|
super().__init__( "HostName","Engine.GameReplicationInfo","ServerName",OptionType.OT_STRING,"ChaCha Test Server","Server HostName",False)
|
|
def set(self,inifile:ChaChaSimpleINI,value:str):
|
|
super().set(inifile,value)
|
|
inifile.setAddKeyValue("Engine.GameReplicationInfo","ShortName",value)
|
|
|
|
class GameOptions_UT99_MOTD(GameOptionINI):
|
|
def __init__(self):
|
|
super().__init__( "MOTD","Engine.GameReplicationInfo","MOTDLine1",OptionType.OT_STRING,"Welcome to ChaCha's server","Message of the day.",False)
|
|
|
|
class GameOptions_UT99_MOTD2(GameOptionINI):
|
|
def __init__(self):
|
|
super().__init__( "MOTD2","Engine.GameReplicationInfo","MOTDLine2",OptionType.OT_STRING,"Enjoy your stay and have fun","Message of the day (2).",False)
|
|
|
|
class GameOptions_UT99_AdminEmail(GameOptionINI):
|
|
def __init__(self):
|
|
super().__init__( "AdminEmail","Engine.GameReplicationInfo","AdminEmail",OptionType.OT_STRING,"chachacorp@protonmail.com","Admin mail",False)
|
|
|
|
class GameOptions_UT99_AdminName(GameOptionINI):
|
|
def __init__(self):
|
|
super().__init__( "AdminName","Engine.GameReplicationInfo","AdminName",OptionType.OT_STRING,"chacha","Admin name",False)
|
|
def set(self,inifile:ChaChaSimpleINI,value:str):
|
|
super().set(inifile,value)
|
|
inifile.setAddKeyValue("UTServerAdmin.UTServerAdmin","AdminUsername",value)
|
|
|
|
class GameOptions_UT99_HTTPDownloadServer(GameOptionINI):
|
|
def __init__(self):
|
|
super().__init__( "HTTPDownloadServer","IpDrv.HTTPDownload","RedirectToURL",OptionType.OT_STRING,"http://chacha.ddns.net/games/ut99","ut99 url",False)
|
|
def set(self,inifile:ChaChaSimpleINI,value:str):
|
|
super().set(inifile,value)
|
|
inifile.setAddKeyValue("IpDrv.HTTPDownload","UseCompression","True")
|
|
inifile.delKey("IpDrv.HTTPDownload","ProxyServerHost")
|
|
inifile.delKey("IpDrv.HTTPDownload","ProxyServerPort")
|
|
|
|
class GameOptions_UT99_NetServerMaxTickRate(GameOptionINI):
|
|
def __init__(self):
|
|
super().__init__( "NetServerMaxTickRate","IpDrv.TcpNetDriver","NetServerMaxTickRate",OptionType.OT_INTEGER,"60","Server Max TickRate ",False)
|
|
|
|
class GameOptions_UT99_LanServerMaxTickRate(GameOptionINI):
|
|
def __init__(self):
|
|
super().__init__( "LanServerMaxTickRate","IpDrv.TcpNetDriver","LanServerMaxTickRate",OptionType.OT_INTEGER,"60","Lan Server Max TickRate ",False)
|
|
|
|
class GameOptions_UT99_AdminPassword(GameOptionINI):
|
|
def __init__(self):
|
|
super().__init__( "AdminPassword","Engine.GameInfo","AdminPassword",OptionType.OT_STRING,"cfographut","Admin password",False)
|
|
def set(self,inifile:ChaChaSimpleINI,value:str):
|
|
super().set(inifile,value)
|
|
inifile.setAddKeyValue("UTServerAdmin.UTServerAdmin","AdminPassword",value)
|
|
|
|
class GameOptions_UT99_GamePassword(GameOptionINI):
|
|
def __init__(self):
|
|
super().__init__( "GamePassword","Engine.GameInfo","GamePassword",OptionType.OT_STRING,"","Game password",False)
|
|
def set(self,inifile:ChaChaSimpleINI,value:str):
|
|
super().set(inifile,value)
|
|
|
|
class GameOptions_UT99_MaxPlayers(GameOptionINI):
|
|
def __init__(self):
|
|
super().__init__( "MaxPlayers","Engine.GameInfo","MaxPlayers",OptionType.OT_INTEGER,"20","Max Players",False)
|
|
def set(self,inifile:ChaChaSimpleINI,value:str):
|
|
super().set(inifile,value)
|
|
|
|
class GameOptions_UT99_ServerLogName(GameOptionINI):
|
|
def __init__(self):
|
|
super().__init__( "ServerLogName","Engine.GameInfo","ServerLogName",OptionType.OT_STRING,"server.log","Server Log Name",False)
|
|
def set(self,inifile:ChaChaSimpleINI,value:str):
|
|
super().set(inifile,value)
|
|
|
|
class GameOptions_UT99_WebServer(GameOptionINI):
|
|
def __init__(self):
|
|
super().__init__( "WebServer","UWeb.WebServer","ListenPort",OptionType.OT_INTEGER,"8076","enable Web Server",False)
|
|
def set(self,inifile:ChaChaSimpleINI,value:str):
|
|
super().set(inifile,value)
|
|
if value != "0":
|
|
inifile.setAddKeyValue("UWeb.WebServer","bEnabled","True")
|
|
else:
|
|
inifile.setAddKeyValue("UWeb.WebServer","bEnabled","False")
|
|
|
|
OptionList = [
|
|
GameOptions_UT99_Port(),
|
|
GameOptions_UT99_Map(),
|
|
GameOptions_UT99_GameType(),
|
|
GameOptions_UT99_HostName(),
|
|
GameOptions_UT99_MOTD(),
|
|
GameOptions_UT99_MOTD2(),
|
|
GameOptions_UT99_AdminEmail(),
|
|
GameOptions_UT99_AdminName(),
|
|
GameOptions_UT99_HTTPDownloadServer(),
|
|
GameOptions_UT99_NetServerMaxTickRate(),
|
|
GameOptions_UT99_LanServerMaxTickRate(),
|
|
GameOptions_UT99_AdminPassword(),
|
|
GameOptions_UT99_GamePassword(),
|
|
GameOptions_UT99_MaxPlayers(),
|
|
GameOptions_UT99_ServerLogName(),
|
|
GameOptions_UT99_WebServer()
|
|
]
|
|
|
|
def SetOption(inifile,option:str,value:str):
|
|
for _option in OptionList:
|
|
if _option.szOptionName==option:
|
|
_option.set(inifile,value)
|
|
return
|
|
raise RuntimeError("Option not found")
|
|
|
|
def GetOption(inifile,option:str):
|
|
for _option in OptionList:
|
|
if _option.szOptionName==option:
|
|
print(_option.get(inifile))
|
|
return
|
|
raise RuntimeError("Option not found")
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("-v", "--verbosity", action="count",
|
|
help="increase output verbosity")
|
|
|
|
parser.add_argument("-b", "--basegamedir",dest='basegamedir', action="store", help="set the game base dir", default="./")
|
|
parser.add_argument("-c", "--configfile",dest='configfile', action="store", help="set the default config file",default="UnrealTournament.ini")
|
|
|
|
subparsers = parser.add_subparsers(help='command type',dest='command',required=True)
|
|
SetOption_subparser = subparsers.add_parser("SetOption",help="Set/Add a game config file option value (may need reboot)")
|
|
SetOption_subparser.add_argument(dest='option', action="store")
|
|
SetOption_subparser.add_argument(dest='value', action="store")
|
|
|
|
GetOption_subparser = subparsers.add_parser("GetOption",help="Get a game config file option value")
|
|
GetOption_subparser.add_argument(dest='option', action="store")
|
|
|
|
args=parser.parse_args()
|
|
|
|
print("Using base game dir: {0}".format(args.basegamedir))
|
|
print("Using config file: {0}".format(args.configfile))
|
|
|
|
ConfigFilePath = join(args.basegamedir,"System",args.configfile)
|
|
|
|
inifile = ChaChaSimpleINI(ConfigFilePath)
|
|
|
|
|
|
|
|
if args.command == "SetOption":
|
|
SetOption(inifile,args.option,args.value)
|
|
inifile.writeFile(False)
|
|
elif args.command == "GetOption":
|
|
GetOption(inifile,args.option)
|
|
else:
|
|
raise RuntimeError("Invalid argument")
|