add SOTF suppport

This commit is contained in:
cclecle
2023-06-28 21:16:31 +01:00
parent abb92f0638
commit 85bca5c921
4 changed files with 682 additions and 550 deletions

View File

@@ -24,90 +24,88 @@ from pickle import TRUE
from concurrent.futures import ThreadPoolExecutor
DEF_DefaultTimeout_s = 5
DEF_DefaultTimeout_s = 5
@GameStatsInterface.GameStatsInterface.register #fake warning in pydev
class GameStatsSupervisor(GameStatsInterface.GameStatsInterface,metaclass=abc.ABCMeta):
def __init__(self,**kwargs):
self.GameStatsInterface_QuakeStat = None
self.GameStatsInterface_RconBase = None
@GameStatsInterface.GameStatsInterface.register # fake warning in pydev
class GameStatsSupervisor(GameStatsInterface.GameStatsInterface, metaclass=abc.ABCMeta):
def __init__(self, **kwargs):
self.GameStatsInterface_QuakeStat = None
self.GameStatsInterface_RconBase = None
if "gametype" in kwargs:
self.GameType = kwargs["gametype"]
else:
raise Exception("missing GameType parameter")
if "name" in kwargs:
self.GameName = kwargs["name"]
else:
raise Exception("missing GameName parameter")
if "ip" in kwargs:
self.GameIp= kwargs["ip"]
self.GameIp = kwargs["ip"]
else:
raise Exception("missing Ip parameter")
if "multithread" in kwargs:
self.multithread = kwargs["multithread"]
else:
self.multithread = True
if "timeout" in kwargs:
self.timeout = kwargs["timeout"]
else:
self.timeout = DEF_DefaultTimeout_s
def set_GameStatsInterface_QuakeStat(self,interface: GameStatsInterface.GameStatsInterface):
def set_GameStatsInterface_QuakeStat(self, interface: GameStatsInterface.GameStatsInterface):
self.GameStatsInterface_QuakeStat = interface
def set_GameStatsInterface_RconBase(self,interface: GameStatsInterface.GameStatsInterface):
def set_GameStatsInterface_RconBase(self, interface: GameStatsInterface.GameStatsInterface):
self.GameStatsInterface_RconBase = interface
def API_GetGameServerStatusResult(self) -> str:
result = GameStatsInterface.GameServerStatusResult_Main()
result.raw = dict()
if self.multithread:
pool = ThreadPoolExecutor(max_workers=2) #FixMe: constant
#Getting Data
pool = ThreadPoolExecutor(max_workers=2) # FixMe: constant
# Getting Data
FutureResultQuakeStat = None
if self.GameStatsInterface_QuakeStat:
if self.multithread:
if self.GameStatsInterface_QuakeStat:
if self.multithread:
FutureResultQuakeStat = pool.submit(self.GameStatsInterface_QuakeStat.API_GetGameServerStatusResult)
else:
result.raw["QuakeStats"] = self.GameStatsInterface_QuakeStat.API_GetGameServerStatusResult()
FutureResultRconBase = None
if self.GameStatsInterface_RconBase:
if self.multithread:
if self.GameStatsInterface_RconBase:
if self.multithread:
FutureResultRconBase = pool.submit(self.GameStatsInterface_RconBase.API_GetGameServerStatusResult)
else:
result.raw["RconBase"] = self.GameStatsInterface_RconBase.API_GetGameServerStatusResult()
result.raw["RconBase"] = self.GameStatsInterface_RconBase.API_GetGameServerStatusResult()
#Wait Get finished
if self.multithread:
# Wait Get finished
if self.multithread:
if FutureResultQuakeStat:
result.raw["QuakeStats"] = FutureResultQuakeStat.result()
if FutureResultRconBase:
result.raw["RconBase"] = FutureResultRconBase.result()
#Mix Data
if self.GameStatsInterface_QuakeStat:
# Mix Data
if self.GameStatsInterface_QuakeStat:
result.partialCopy(result.raw["QuakeStats"])
if self.GameStatsInterface_RconBase:
if not self.GameStatsInterface_QuakeStat or ( result.raw["QuakeStats"].status!="UP" and result.raw["RconBase"].status=="UP" ):
if self.GameStatsInterface_RconBase:
if not self.GameStatsInterface_QuakeStat or (result.raw["QuakeStats"].status != "UP" and result.raw["RconBase"].status == "UP"):
result.partialCopy(result.raw["RconBase"])
else:
ResultRconBase = result.raw["RconBase"]
ResultRconBase = result.raw["RconBase"]
result.partialSmartMerge(ResultRconBase)
return result
class GameStatsSupervisor_UTEngine(GameStatsSupervisor):
def API_GetGameServerStatusResult(self) -> str:
result = super().API_GetGameServerStatusResult()
@@ -119,116 +117,127 @@ class GameStatsSupervisor_UTEngine(GameStatsSupervisor):
result.map = result.raw["QuakeStats"].map
return result
class GameStatsSupervisorFactory:
def __init__(self):
self._RconFactory = RconBase.RconFactory()
self.register_GameStatsSupervisorRconBuilder("ut2k4", RconUTEngineWebAdminUT2k4.RconUTEngineWebAdminUT2k4)
self.register_GameStatsSupervisorRconBuilder("ut3", RconUTEngineWebAdminUT3.RconUTEngineWebAdminUT3)
self.register_GameStatsSupervisorRconBuilder("ut99", RconUTEngineWebAdminUT99.RconUTEngineWebAdminUT99)
self.register_GameStatsSupervisorRconBuilder("q2", RconQuakes.RconSourceEngineQuake2)
self.register_GameStatsSupervisorRconBuilder("q3a", RconQuakes.RconSourceEngineQuake3A)
self.register_GameStatsSupervisorRconBuilder("codmw3", RconCODs.RconSourceEngineCODMW3)
self.register_GameStatsSupervisorRconBuilder("codbo2", RconCODs.RconSourceEngineCODBO2)
self.register_GameStatsSupervisorRconBuilder("cod4", RconCODs.RconSourceEngineCOD4)
self.register_GameStatsSupervisorRconBuilder("cod5", RconCODs.RconSourceEngineCOD5)
self.register_GameStatsSupervisorRconBuilder("cry1", RconCryEngines.RconCryEngine)
self.register_GameStatsSupervisorRconBuilder("mc", RconMinecraft.RconMinecraft)
self.register_GameStatsSupervisorRconBuilder("ut2k4", RconUTEngineWebAdminUT2k4.RconUTEngineWebAdminUT2k4)
self.register_GameStatsSupervisorRconBuilder("ut3", RconUTEngineWebAdminUT3.RconUTEngineWebAdminUT3)
self.register_GameStatsSupervisorRconBuilder("ut99", RconUTEngineWebAdminUT99.RconUTEngineWebAdminUT99)
self.register_GameStatsSupervisorRconBuilder("q2", RconQuakes.RconSourceEngineQuake2)
self.register_GameStatsSupervisorRconBuilder("q3a", RconQuakes.RconSourceEngineQuake3A)
self.register_GameStatsSupervisorRconBuilder("codmw3", RconCODs.RconSourceEngineCODMW3)
self.register_GameStatsSupervisorRconBuilder("codbo2", RconCODs.RconSourceEngineCODBO2)
self.register_GameStatsSupervisorRconBuilder("cod4", RconCODs.RconSourceEngineCOD4)
self.register_GameStatsSupervisorRconBuilder("cod5", RconCODs.RconSourceEngineCOD5)
self.register_GameStatsSupervisorRconBuilder("cry1", RconCryEngines.RconCryEngine)
self.register_GameStatsSupervisorRconBuilder("mc", RconMinecraft.RconMinecraft)
self._QuakeStatFactory = QuakeStat.QuakeStatFactory()
self._QuakeStatFactory.add_common_options(timeout=5)
self.register_QuakeStatsBuilder("ut2k4", QuakeStat.QuakeStat_UT2K4)
self.register_QuakeStatsBuilder("ut3", QuakeStat.QuakeStat_UT3)
self.register_QuakeStatsBuilder("ut99", QuakeStat.QuakeStat_UT99)
self.register_QuakeStatsBuilder("q2", QuakeStat.QuakeStat_Q2)
self.register_QuakeStatsBuilder("q3a", QuakeStat.QuakeStat_Q3)
self.register_QuakeStatsBuilder("codmw3", QuakeStat.QuakeStat_CODMW3)
self.register_QuakeStatsBuilder("codbo2", QuakeStat.QuakeStat_CODBO2)
self.register_QuakeStatsBuilder("cod4", QuakeStat.QuakeStat_COD4)
self.register_QuakeStatsBuilder("cod5", QuakeStat.QuakeStat_COD5)
self.register_QuakeStatsBuilder("cry1", QuakeStat.QuakeStat_CRYSIS1)
self.register_QuakeStatsBuilder("mc", QuakeStat.QuakeStat_Minecraft)
self.register_QuakeStatsBuilder("doom3", QuakeStat.QuakeStat_Doom3)
self._QuakeStatFactory.add_common_options(timeout=5)
self.register_QuakeStatsBuilder("ut2k4", QuakeStat.QuakeStat_UT2K4)
self.register_QuakeStatsBuilder("ut3", QuakeStat.QuakeStat_UT3)
self.register_QuakeStatsBuilder("ut99", QuakeStat.QuakeStat_UT99)
self.register_QuakeStatsBuilder("q2", QuakeStat.QuakeStat_Q2)
self.register_QuakeStatsBuilder("q3a", QuakeStat.QuakeStat_Q3)
self.register_QuakeStatsBuilder("codmw3", QuakeStat.QuakeStat_CODMW3)
self.register_QuakeStatsBuilder("codbo2", QuakeStat.QuakeStat_CODBO2)
self.register_QuakeStatsBuilder("cod4", QuakeStat.QuakeStat_COD4)
self.register_QuakeStatsBuilder("cod5", QuakeStat.QuakeStat_COD5)
self.register_QuakeStatsBuilder("cry1", QuakeStat.QuakeStat_CRYSIS1)
self.register_QuakeStatsBuilder("mc", QuakeStat.QuakeStat_Minecraft)
self.register_QuakeStatsBuilder("doom3", QuakeStat.QuakeStat_Doom3)
self.register_QuakeStatsBuilder("sotf", QuakeStat.QuakeStat_SOTF)
self._builders = {}
self.register_GameStatsSupervisorBuilder("ut2k4", GameStatsSupervisor_UTEngine)
self.register_GameStatsSupervisorBuilder("ut3", GameStatsSupervisor_UTEngine)
self.register_GameStatsSupervisorBuilder("ut99", GameStatsSupervisor_UTEngine)
self.register_GameStatsSupervisorBuilder("q2", GameStatsSupervisor)
self.register_GameStatsSupervisorBuilder("q3a", GameStatsSupervisor)
self.register_GameStatsSupervisorBuilder("codmw3", GameStatsSupervisor)
self.register_GameStatsSupervisorBuilder("codbo2", GameStatsSupervisor)
self.register_GameStatsSupervisorBuilder("cod4", GameStatsSupervisor)
self.register_GameStatsSupervisorBuilder("cod5", GameStatsSupervisor)
self.register_GameStatsSupervisorBuilder("cry1", GameStatsSupervisor)
self.register_GameStatsSupervisorBuilder("mc", GameStatsSupervisor)
self.register_GameStatsSupervisorBuilder("doom3", GameStatsSupervisor)
def register_QuakeStatsBuilder(self,Gamekey: str ,QuakeStatsBuilder: QuakeStat.QuakeStat ) -> None:
self._QuakeStatFactory.register_QuakeStatBuilder(Gamekey,QuakeStatsBuilder)
def register_GameStatsSupervisorBuilder(self,Gamekey: str,GameStatsSupervisorBuilder: GameStatsSupervisor) -> None:
self._builders[Gamekey] = GameStatsSupervisorBuilder #add/repace Gamekey Builder
def register_GameStatsSupervisorRconBuilder(self,Gamekey : str,RconBuilder: RconBase.RconBase) -> None:
self._RconFactory.register_RconBuilder(Gamekey, RconBuilder)
def create(self,**kwargs) -> GameStatsSupervisor:
self.register_GameStatsSupervisorBuilder("ut2k4", GameStatsSupervisor_UTEngine)
self.register_GameStatsSupervisorBuilder("ut3", GameStatsSupervisor_UTEngine)
self.register_GameStatsSupervisorBuilder("ut99", GameStatsSupervisor_UTEngine)
self.register_GameStatsSupervisorBuilder("q2", GameStatsSupervisor)
self.register_GameStatsSupervisorBuilder("q3a", GameStatsSupervisor)
self.register_GameStatsSupervisorBuilder("codmw3", GameStatsSupervisor)
self.register_GameStatsSupervisorBuilder("codbo2", GameStatsSupervisor)
self.register_GameStatsSupervisorBuilder("cod4", GameStatsSupervisor)
self.register_GameStatsSupervisorBuilder("cod5", GameStatsSupervisor)
self.register_GameStatsSupervisorBuilder("cry1", GameStatsSupervisor)
self.register_GameStatsSupervisorBuilder("mc", GameStatsSupervisor)
self.register_GameStatsSupervisorBuilder("doom3", GameStatsSupervisor)
self.register_GameStatsSupervisorBuilder("sotf", GameStatsSupervisor)
def register_QuakeStatsBuilder(self, Gamekey: str, QuakeStatsBuilder: QuakeStat.QuakeStat) -> None:
self._QuakeStatFactory.register_QuakeStatBuilder(Gamekey, QuakeStatsBuilder)
def register_GameStatsSupervisorBuilder(self, Gamekey: str, GameStatsSupervisorBuilder: GameStatsSupervisor) -> None:
self._builders[Gamekey] = GameStatsSupervisorBuilder # add/repace Gamekey Builder
def register_GameStatsSupervisorRconBuilder(self, Gamekey: str, RconBuilder: RconBase.RconBase) -> None:
self._RconFactory.register_RconBuilder(Gamekey, RconBuilder)
def create(self, **kwargs) -> GameStatsSupervisor:
if "gametype" in kwargs:
Gamekey = kwargs["gametype"]
else:
raise Exception("missing GameType parameter")
if "name" in kwargs:
name = kwargs["name"]
else:
raise Exception("missing name parameter")
ip = None
if "ip" in kwargs:
ip = kwargs["ip"]
if "timeout" in kwargs:
timeout = kwargs["timeout"]
else :
timeout = kwargs["timeout"]
else:
timeout = DEF_DefaultTimeout_s
#building main supervisor class
# building main supervisor class
builder = self._builders.get(Gamekey)
if not builder:
raise Exception("can not found builder for key : "+Gamekey)
#trying to build Interface_QuakeStats method
if not builder:
raise Exception("can not found builder for key : " + Gamekey)
# trying to build Interface_QuakeStats method
QuakeStatsInterface = None
if "Interface_QuakeStats" in kwargs:
args = kwargs["Interface_QuakeStats"]
args["QStatGameType"] = Gamekey
args["name"] = name
if not "ip" in kwargs["Interface_QuakeStats"]:
if ip:
if ip:
kwargs["Interface_QuakeStats"]["ip"] = ip
try:
QuakeStatsInterface = self._QuakeStatFactory.create(**kwargs["Interface_QuakeStats"])
QuakeStatsInterface = self._QuakeStatFactory.create(**kwargs["Interface_QuakeStats"])
except Exception as e:
print("[WARN] Interface_QuakeStats init failed (%s)" % e)
#trying to build Interface_Rcon method
print("[WARN] Interface_QuakeStats init failed (%s)" % e)
# trying to build Interface_Rcon method
RconBaseInterface = None
if "Interface_RconBase" in kwargs:
if not "address" in kwargs["Interface_RconBase"]:
if ip:
if ip:
kwargs["Interface_RconBase"]["ip"] = ip
try:
RconBaseInterface = self._RconFactory.create(name,Gamekey,kwargs["Interface_RconBase"]["ip"],kwargs["Interface_RconBase"]["port"],kwargs["Interface_RconBase"]["username"],kwargs["Interface_RconBase"]["password"],timeout)
RconBaseInterface = self._RconFactory.create(
name,
Gamekey,
kwargs["Interface_RconBase"]["ip"],
kwargs["Interface_RconBase"]["port"],
kwargs["Interface_RconBase"]["username"],
kwargs["Interface_RconBase"]["password"],
timeout,
)
except Exception as e:
print("[WARN] Interface_RconBase init failed (%s)" % e)
#creating the gamestatsupervisor
# creating the gamestatsupervisor
_GameStatsSupervisor = builder(**kwargs)
if QuakeStatsInterface:
_GameStatsSupervisor.set_GameStatsInterface_QuakeStat(QuakeStatsInterface)
if RconBaseInterface:
_GameStatsSupervisor.set_GameStatsInterface_RconBase(RconBaseInterface)
return _GameStatsSupervisor
return _GameStatsSupervisor

File diff suppressed because it is too large Load Diff

View File

@@ -7,4 +7,4 @@ Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Unported
You should have received a copy of the license along with this
work. If not, see <https://creativecommons.org/licenses/by-nc-sa/4.0/>.
"""
__version__ = "0.1.3"
__version__ = "0.1.4"

View File

@@ -1,22 +1,22 @@
import os
import os
import time
from ChaChaGameStats import GameStatsSupervisor
from ChaChaGameStats import GameStatsSupervisor
from pprint import pprint
# unitary test
if __name__ == "__main__":
#unitary test
if __name__ == '__main__':
_GameStatsSupervisorFactory = GameStatsSupervisor.GameStatsSupervisorFactory()
if os.name == 'nt':
#for windows
if os.name == "nt":
# for windows
dir_path = os.path.dirname(os.path.realpath(__file__))
qstatpath = dir_path+"\\Ext\qstat.exe"
qstatpath = dir_path + "\\Ext\qstat.exe"
print(qstatpath)
_GameStatsSupervisorFactory._QuakeStatFactory.add_common_options(QStatCmd=qstatpath)
_GameStatsSupervisorFactory._QuakeStatFactory.add_common_options(QStatCmd=qstatpath)
ar_games = []
""" duplicate this record for all your games
ar_games.append( _GameStatsSupervisorFactory.create( name = "foo", # game instance name
gametype = "foo", # gametype name: ut99,ut2k4,ut3,cod4,cod5,codmw3,codbo2,cry1,mc,q2,q3a
@@ -36,20 +36,9 @@ if __name__ == '__main__':
)
)
"""
"""
ar_games.append( _GameStatsSupervisorFactory.create( name = "ut99-dm",
gametype = "ut99",
ip = "172.16.1.41",
Interface_QuakeStats = { "port":5000},
Interface_RconBase = { "port":5000,
"username":"chacha",
"password":"cfographut"}
)
)
ar_games.append( _GameStatsSupervisorFactory.create( name = "ut99-niut",
gametype = "ut99",
ip = "172.16.1.40",
@@ -86,7 +75,7 @@ if __name__ == '__main__':
"password":"AmL992gxE"}
)
)
"""
ar_games.append( _GameStatsSupervisorFactory.create( name = "codbo2-3",
gametype = "codbo2",
ip = "GAME-CODBO2",
@@ -98,9 +87,38 @@ if __name__ == '__main__':
"username":"admin",
"password":"cfographut"}
)
)
)
ar_games.append( _GameStatsSupervisorFactory.create( name = "crysis-war",
gametype = "cry1",
ip = "45.89.124.222",
Interface_QuakeStats = { "port":50002},
Interface_RconBase = { "port":50002,
"username":"",
"password":""}
)
)
ar_games.append( _GameStatsSupervisorFactory.create( name = "ut2k4-1",
gametype = "ut2k4",
ip = "172.16.10.1",
Interface_QuakeStats = { "port":8000},
Interface_RconBase = { "port":10000,
"username":"chacha",
"password":"cfographut"}
)
)
"""
ar_games.append(
_GameStatsSupervisorFactory.create(name="SOTF1", gametype="sotf", ip="172.16.1.45", Interface_QuakeStats={"port": 27018})
)
print("### Unitary test START")
timestart = time.time()
timestart = time.time()
for i in range(200):
for game in ar_games:
print("")
@@ -109,9 +127,10 @@ if __name__ == '__main__':
print("res: " + str(res.__dict__))
for player in res.players:
print(player.__dict__)
if 'QuakeStats' in res.raw:
print("res: { 'raw': {'QuakeStats': " + str(res.raw['QuakeStats'].__dict__) +"},...}")
if 'RconBase' in res.raw:
print("res: { 'raw': {'RconBase': " + str(res.raw['RconBase'].__dict__) +"},...}")
if "QuakeStats" in res.raw:
print("res: { 'raw': {'QuakeStats': " + str(res.raw["QuakeStats"].__dict__) + "},...}")
# pprint(res.raw["QuakeStats"].__dict__)
if "RconBase" in res.raw:
print("res: { 'raw': {'RconBase': " + str(res.raw["RconBase"].__dict__) + "},...}")
timestop = time.time() - timestart
print("### Unitary test END ({})".format(timestop))
print("### Unitary test END ({})".format(timestop))