From 83ca522a9d1626326b965b5724be9f93c7f69eb9 Mon Sep 17 00:00:00 2001 From: chacha Date: Tue, 18 Apr 2023 00:12:02 +0200 Subject: [PATCH] integrate on ut99 v469c --- ChaChaGameStats/RconUTEngineWebAdmin.py | 61 +++++++++++++-------- ChaChaGameStats/RconUTEngineWebAdminUT99.py | 9 ++- ChaChaGameStats/_version.py | 2 +- sample.py | 21 ++++--- 4 files changed, 57 insertions(+), 36 deletions(-) diff --git a/ChaChaGameStats/RconUTEngineWebAdmin.py b/ChaChaGameStats/RconUTEngineWebAdmin.py index e91f98e..5ebb629 100644 --- a/ChaChaGameStats/RconUTEngineWebAdmin.py +++ b/ChaChaGameStats/RconUTEngineWebAdmin.py @@ -46,7 +46,6 @@ class RconUTEngineWebAdmin(RconBase.RconBase,metaclass=abc.ABCMeta): self.GameServerStatusResult = None self.timeout = timeout self.initConstant() - self.fetchData = {}; def initConstant(self): pass @@ -65,8 +64,7 @@ class RconUTEngineWebAdmin(RconBase.RconBase,metaclass=abc.ABCMeta): def _fetchPageRAW(self,page) -> str: try: - response = self.session.get(page,data=self.fetchData,timeout=self.timeout) - self.fetchData = {} + response = self.session.get(page,timeout=self.timeout) if response.status_code != 200: raise RconBase.ExceptionWrongRconPassword except requests.exceptions.RequestException as e: @@ -150,32 +148,47 @@ class RconUTEngineWebAdminMODCENTRAL(RconUTEngineWebAdmin,metaclass=abc.ABCMeta) tree = self._fetchPageETree(url) try: level1 = tree.findall(".//form[@action='"+element+"']")[0] - level2 = level1.findall(".//table")[0] - infoChart = level2.findall(".//tr") - for info_record in infoChart: - data = info_record.findall(".//td/select") - if data : - attributename = data[0].attrib["name"].split('.')[-1] #get last var name: BLABLA.keyname => keyname - data_value = data[0].findall(".//option[@selected]") + level2 = level1.findall(".//table") + # table based page + if level2: + level2 = level2[0] + infoChart = level2.findall(".//tr") + for info_record in infoChart: + data = info_record.findall(".//td/select") + if data : + attributename = data[0].attrib["name"].split('.')[-1] #get last var name: BLABLA.keyname => keyname + data_value = data[0].findall(".//option[@selected]") + if data_value: + if "value" in data_value[0].attrib: + ar_ServerRules[attributename] = data_value[0].attrib["value"] + else: + ar_ServerRules[attributename] = data_value[0].text + continue + data = info_record.findall(".//td/input") + if data and data[0].attrib["name"]!="Apply": + attributename = data[0].attrib["name"].split('.')[-1] #get last var name: BLABLA.keyname => keyname + if "value" in data[0].attrib: + ar_ServerRules[attributename] = data[0].attrib["value"] + else: + ar_ServerRules[attributename] = data[0].text + if data[0].attrib["type"] == "checkbox" : + if "checked" in data[0].attrib: + ar_ServerRules[attributename] = "true" + else: + ar_ServerRules[attributename] = "false" + continue + else: + #new pages UT99 469c .... :-/ + selects = level1.findall(".//select") + for _select in selects: + attributename = _select.attrib["name"].split('.')[-1] #get last var name: BLABLA.keyname => keyname + data_value = _select.findall(".//option[@selected]") if data_value: if "value" in data_value[0].attrib: ar_ServerRules[attributename] = data_value[0].attrib["value"] else: ar_ServerRules[attributename] = data_value[0].text - continue - data = info_record.findall(".//td/input") - if data and data[0].attrib["name"]!="Apply": - attributename = data[0].attrib["name"].split('.')[-1] #get last var name: BLABLA.keyname => keyname - if "value" in data[0].attrib: - ar_ServerRules[attributename] = data[0].attrib["value"] - else: - ar_ServerRules[attributename] = data[0].text - if data[0].attrib["type"] == "checkbox" : - if "checked" in data[0].attrib: - ar_ServerRules[attributename] = "true" - else: - ar_ServerRules[attributename] = "false" - continue + continue except Exception as e: raise RconBase.ExceptionRconResultParse(e) return ar_ServerRules \ No newline at end of file diff --git a/ChaChaGameStats/RconUTEngineWebAdminUT99.py b/ChaChaGameStats/RconUTEngineWebAdminUT99.py index f0ff261..2e6939d 100644 --- a/ChaChaGameStats/RconUTEngineWebAdminUT99.py +++ b/ChaChaGameStats/RconUTEngineWebAdminUT99.py @@ -171,8 +171,13 @@ class RconUTEngineWebAdminUT99(RconUTEngineWebAdmin.RconUTEngineWebAdminMODCENTR ar_PlayersStats = [] tree = self._fetchPageETree(self.currentplayersUrl) try: - level1 = tree.findall(".//form[@action='current_players']")[0] - level2 = level1.findall(".//table")[1] + level1 = tree.findall(".//form[@action='current_players']") + if len(level1) == 2: #ut469c + level1 = level1[1] + level2 = level1.findall(".//table")[0] + else: + level1 = level1[0] + level2 = level1.findall(".//table")[1] player_chart = level2.findall(".//tr") del player_chart[0] for player_record in player_chart: diff --git a/ChaChaGameStats/_version.py b/ChaChaGameStats/_version.py index ce177ae..d1c6b5b 100644 --- a/ChaChaGameStats/_version.py +++ b/ChaChaGameStats/_version.py @@ -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 . """ -__version__ = "0.1.3" \ No newline at end of file +__version__ = "0.1.4" \ No newline at end of file diff --git a/sample.py b/sample.py index d5b452c..5cd83ab 100644 --- a/sample.py +++ b/sample.py @@ -1,7 +1,7 @@ import os import time from ChaChaGameStats import GameStatsSupervisor - +from pprint import pprint #unitary test if __name__ == '__main__': @@ -37,7 +37,7 @@ if __name__ == '__main__': ) """ - """ + ar_games.append( _GameStatsSupervisorFactory.create( name = "ut99-dm", gametype = "ut99", ip = "172.16.1.41", @@ -50,6 +50,7 @@ if __name__ == '__main__': "password":"cfographut"} ) ) + """ ar_games.append( _GameStatsSupervisorFactory.create( name = "ut99-niut", gametype = "ut99", ip = "172.16.1.40", @@ -73,7 +74,8 @@ if __name__ == '__main__': "username":"chacha", "password":"cfographut"} ) - ) + ) + ar_games.append( _GameStatsSupervisorFactory.create( name = "ut99-utp", gametype = "ut99", ip = "172.16.1.42", @@ -86,7 +88,7 @@ if __name__ == '__main__': "password":"AmL992gxE"} ) ) - """ + ar_games.append( _GameStatsSupervisorFactory.create( name = "codbo2-3", gametype = "codbo2", ip = "GAME-CODBO2", @@ -98,7 +100,8 @@ if __name__ == '__main__': "username":"admin", "password":"cfographut"} ) - ) + ) + """ print("### Unitary test START") timestart = time.time() for i in range(200): @@ -106,12 +109,12 @@ if __name__ == '__main__': print("") print("== Testing: " + game.GameName + "==") res = game.API_GetGameServerStatusResult() - print("res: " + str(res.__dict__)) + pprint("res: " + str(res.__dict__)) for player in res.players: - print(player.__dict__) + pprint(player.__dict__) if 'QuakeStats' in res.raw: - print("res: { 'raw': {'QuakeStats': " + str(res.raw['QuakeStats'].__dict__) +"},...}") + pprint("res: { 'raw': {'QuakeStats': " + str(res.raw['QuakeStats'].__dict__) +"},...}") if 'RconBase' in res.raw: - print("res: { 'raw': {'RconBase': " + str(res.raw['RconBase'].__dict__) +"},...}") + pprint("res: { 'raw': {'RconBase': " + str(res.raw['RconBase'].__dict__) +"},...}") timestop = time.time() - timestart print("### Unitary test END ({})".format(timestop)) \ No newline at end of file