fix UT2k4 absent bWeaponStay
This commit is contained in:
@@ -13,205 +13,213 @@ import time
|
||||
import unicodedata
|
||||
|
||||
from functools import wraps
|
||||
from functools import lru_cache
|
||||
from functools import lru_cache
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from . import GameStatsInterface
|
||||
from . import RconBase
|
||||
from . import RconUTEngineWebAdmin
|
||||
|
||||
|
||||
def timed_lru_cache(seconds: int, maxsize: int = None):
|
||||
def wrapper_cache(func):
|
||||
func = lru_cache(maxsize=maxsize)(func)
|
||||
func.lifetime = timedelta(seconds=seconds)
|
||||
func.expiration = datetime.utcnow() + func.lifetime
|
||||
|
||||
@wraps(func)
|
||||
def wrapped_func(*args, **kwargs):
|
||||
if datetime.utcnow() >= func.expiration:
|
||||
func.cache_clear()
|
||||
func.expiration = datetime.utcnow() + func.lifetime
|
||||
return func(*args, **kwargs)
|
||||
|
||||
return wrapped_func
|
||||
|
||||
return wrapper_cache
|
||||
|
||||
|
||||
class RconUTEngineWebAdminUT2k4(RconUTEngineWebAdmin.RconUTEngineWebAdminMODCENTRAL):
|
||||
def initConstant(self):
|
||||
super().initConstant()
|
||||
self.gametype = None
|
||||
self.currentplayersUrl = self.BaseUrl + "current_players"
|
||||
self.defaultsserverUrl = self.BaseUrl + "defaults_rules?Filter=Server"
|
||||
self.defaultsGameUrl = self.BaseUrl + "defaults_rules?Filter=Game"
|
||||
self.defaultsrulesUrl = self.BaseUrl + "defaults_rules?Filter=Rules"
|
||||
self.CurrentGameUrl = self.BaseUrl + "current_game"
|
||||
self.defaultmapsUrl = self.BaseUrl + "defaults_maps"
|
||||
self.currentconsoleUrl = self.BaseUrl + "current_console"
|
||||
|
||||
self.gametype = None
|
||||
self.currentplayersUrl = self.BaseUrl + "current_players"
|
||||
self.defaultsserverUrl = self.BaseUrl + "defaults_rules?Filter=Server"
|
||||
self.defaultsGameUrl = self.BaseUrl + "defaults_rules?Filter=Game"
|
||||
self.defaultsrulesUrl = self.BaseUrl + "defaults_rules?Filter=Rules"
|
||||
self.CurrentGameUrl = self.BaseUrl + "current_game"
|
||||
self.defaultmapsUrl = self.BaseUrl + "defaults_maps"
|
||||
self.currentconsoleUrl = self.BaseUrl + "current_console"
|
||||
|
||||
def GetGameServerStatusResult(self) -> GameStatsInterface.GameServerStatusResult_Main:
|
||||
super().GetGameServerStatusResult()
|
||||
|
||||
if self.GameServerStatusResult.status == "UP":
|
||||
if self.GameServerStatusResult.status == "UP":
|
||||
try:
|
||||
PINGstarttime = time.time()
|
||||
self.GetServerCurrentGame()
|
||||
PING = round( (time.time() - PINGstarttime)*1000)
|
||||
PING = round((time.time() - PINGstarttime) * 1000)
|
||||
except RconBase.ExceptionRconTimeout:
|
||||
self.GameServerStatusResult.status = "DOWN"
|
||||
self.GameServerStatusResult.ping = 999
|
||||
self.GameServerStatusResult.status = "DOWN"
|
||||
self.GameServerStatusResult.ping = 999
|
||||
return self.GameServerStatusResult
|
||||
except RconBase.ExceptionWrongRconPassword:
|
||||
self.GameServerStatusResult.status = "REFUSED"
|
||||
self.GameServerStatusResult.ping = 999
|
||||
self.GameServerStatusResult.status = "REFUSED"
|
||||
self.GameServerStatusResult.ping = 999
|
||||
return self.GameServerStatusResult
|
||||
|
||||
self.GameServerStatusResult.name = self.GameServerStatusResult.raw["ServerName"]
|
||||
|
||||
|
||||
self.GameServerStatusResult.name = self.GameServerStatusResult.raw["ServerName"]
|
||||
|
||||
if self.GameServerStatusResult.raw["GameTypeSelect"] == "3SPNv3141.ArenaMaster":
|
||||
self.GameServerStatusResult.gametype = "ArenaMaster v3.141"
|
||||
self.GameServerStatusResult.gametype = "ArenaMaster v3.141"
|
||||
elif self.GameServerStatusResult.raw["GameTypeSelect"] == "UT2k4Assault.ASGameInfo":
|
||||
self.GameServerStatusResult.gametype = "Assault"
|
||||
self.GameServerStatusResult.gametype = "Assault"
|
||||
elif self.GameServerStatusResult.raw["GameTypeSelect"] == "XGame.xBombingRun":
|
||||
self.GameServerStatusResult.gametype = "Bombing Run"
|
||||
self.GameServerStatusResult.gametype = "Bombing Run"
|
||||
elif self.GameServerStatusResult.raw["GameTypeSelect"] == "XGame.xCTFGame":
|
||||
self.GameServerStatusResult.gametype = "Capture the Flag"
|
||||
self.GameServerStatusResult.gametype = "Capture the Flag"
|
||||
elif self.GameServerStatusResult.raw["GameTypeSelect"] == "XGame.xDeathMatch":
|
||||
self.GameServerStatusResult.gametype = "DeathMatch"
|
||||
self.GameServerStatusResult.gametype = "DeathMatch"
|
||||
elif self.GameServerStatusResult.raw["GameTypeSelect"] == "XGame.xDoubleDom":
|
||||
self.GameServerStatusResult.gametype = "Double Domination"
|
||||
self.GameServerStatusResult.gametype = "Double Domination"
|
||||
elif self.GameServerStatusResult.raw["GameTypeSelect"] == "Freeze_Tag_FT5.FreezeTagGame":
|
||||
self.GameServerStatusResult.gametype = "Freeze Tag [PSI]"
|
||||
self.GameServerStatusResult.gametype = "Freeze Tag [PSI]"
|
||||
elif self.GameServerStatusResult.raw["GameTypeSelect"] == "3SPNv3141.Freon":
|
||||
self.GameServerStatusResult.gametype = "Freon"
|
||||
self.GameServerStatusResult.gametype = "Freon"
|
||||
elif self.GameServerStatusResult.raw["GameTypeSelect"] == "XGame.InstagibCTF":
|
||||
self.GameServerStatusResult.gametype = "Instagib CTF"
|
||||
self.GameServerStatusResult.gametype = "Instagib CTF"
|
||||
elif self.GameServerStatusResult.raw["GameTypeSelect"] == "SkaarjPack.Invasion":
|
||||
self.GameServerStatusResult.gametype = "Invasion"
|
||||
self.GameServerStatusResult.gametype = "Invasion"
|
||||
elif self.GameServerStatusResult.raw["GameTypeSelect"] == "BonusPack.xLastManStandingGame":
|
||||
self.GameServerStatusResult.gametype = "Last Man Standing"
|
||||
self.GameServerStatusResult.gametype = "Last Man Standing"
|
||||
elif self.GameServerStatusResult.raw["GameTypeSelect"] == "BonusPack.xMutantGame":
|
||||
self.GameServerStatusResult.gametype = "Mutant"
|
||||
self.GameServerStatusResult.gametype = "Mutant"
|
||||
elif self.GameServerStatusResult.raw["GameTypeSelect"] == "Onslaught.ONSOnslaughtGame":
|
||||
self.GameServerStatusResult.gametype = "Onslaught"
|
||||
self.GameServerStatusResult.gametype = "Onslaught"
|
||||
elif self.GameServerStatusResult.raw["GameTypeSelect"] == "3SPNv3141.TeamArenaMaster":
|
||||
self.GameServerStatusResult.gametype = "Team ArenaMaster v3.141"
|
||||
self.GameServerStatusResult.gametype = "Team ArenaMaster v3.141"
|
||||
elif self.GameServerStatusResult.raw["GameTypeSelect"] == "XGame.xTeamGame":
|
||||
self.GameServerStatusResult.gametype = "Team DeathMatch"
|
||||
self.GameServerStatusResult.gametype = "Team DeathMatch"
|
||||
elif self.GameServerStatusResult.raw["GameTypeSelect"] == "utcompv17a.UTComp_ClanArena":
|
||||
self.GameServerStatusResult.gametype = "UTComp Clan Arena 1.7a"
|
||||
self.GameServerStatusResult.gametype = "UTComp Clan Arena 1.7a"
|
||||
elif self.GameServerStatusResult.raw["GameTypeSelect"] == "XGame.xVehicleCTFGame":
|
||||
self.GameServerStatusResult.gametype = "Vehicle CTF"
|
||||
else:
|
||||
self.GameServerStatusResult.gametype = self.GameServerStatusResult.raw["GameTypeSelect"]
|
||||
|
||||
self.GameServerStatusResult.map = self.GameServerStatusResult.raw["MapSelect"]
|
||||
self.GameServerStatusResult.nplayer = self.GameServerStatusResult.raw["nplayer"]
|
||||
self.GameServerStatusResult.maxplayers = self.GameServerStatusResult.raw["MaxPlayers"]
|
||||
self.GameServerStatusResult.ping = PING
|
||||
self.GameServerStatusResult.version = None
|
||||
self.GameServerStatusResult.players = []
|
||||
if "players" in self.GameServerStatusResult.raw:
|
||||
self.GameServerStatusResult.gametype = "Vehicle CTF"
|
||||
else:
|
||||
self.GameServerStatusResult.gametype = self.GameServerStatusResult.raw["GameTypeSelect"]
|
||||
|
||||
self.GameServerStatusResult.map = self.GameServerStatusResult.raw["MapSelect"]
|
||||
self.GameServerStatusResult.nplayer = self.GameServerStatusResult.raw["nplayer"]
|
||||
self.GameServerStatusResult.maxplayers = self.GameServerStatusResult.raw["MaxPlayers"]
|
||||
self.GameServerStatusResult.ping = PING
|
||||
self.GameServerStatusResult.version = None
|
||||
self.GameServerStatusResult.players = []
|
||||
if "players" in self.GameServerStatusResult.raw:
|
||||
num = 0
|
||||
for player in self.GameServerStatusResult.raw["players"]:
|
||||
newplayer = GameStatsInterface.GameServerStatusResult_Players()
|
||||
newplayer.name = None if "Name" not in player else player["Name"]
|
||||
newplayer.score = None if "Score" not in player else player["Score"]
|
||||
newplayer.ping = None if "Ping" not in player else player["Ping"]
|
||||
newplayer.ip = None if "IP" not in player else player["IP"]
|
||||
newplayer.port = None
|
||||
newplayer.uid = None
|
||||
newplayer.num = num
|
||||
newplayer.name = None if "Name" not in player else player["Name"]
|
||||
newplayer.score = None if "Score" not in player else player["Score"]
|
||||
newplayer.ping = None if "Ping" not in player else player["Ping"]
|
||||
newplayer.ip = None if "IP" not in player else player["IP"]
|
||||
newplayer.port = None
|
||||
newplayer.uid = None
|
||||
newplayer.num = num
|
||||
self.GameServerStatusResult.players.append(newplayer)
|
||||
num+=1
|
||||
num += 1
|
||||
|
||||
return self.GameServerStatusResult
|
||||
|
||||
def GetStatus(self) -> dict():
|
||||
CurrentGame = self.GetServerCurrentGame()
|
||||
self.gametype = CurrentGame["GameTypeSelect"]
|
||||
MapList = self.GetServerMapList()
|
||||
ServerGame = self.GetServerGame()
|
||||
ServerRules = self.GetServerRules()
|
||||
ServerConfig = self.GetServerConfig()
|
||||
PlayerStats = self.GetPlayerStats()
|
||||
|
||||
return self.GameServerStatusResult
|
||||
|
||||
def GetStatus(self) -> dict():
|
||||
CurrentGame = self.GetServerCurrentGame()
|
||||
self.gametype = CurrentGame["GameTypeSelect"]
|
||||
MapList = self.GetServerMapList()
|
||||
ServerGame = self.GetServerGame()
|
||||
ServerRules = self.GetServerRules()
|
||||
ServerConfig = self.GetServerConfig()
|
||||
PlayerStats = self.GetPlayerStats()
|
||||
|
||||
result = dict()
|
||||
result["ServerName"] = unicodedata.normalize("NFKD", ServerConfig["ServerName"])
|
||||
result["GameTypeSelect"] = self.gametype
|
||||
result["TimeLimit"] = ServerGame["TimeLimit"]
|
||||
result["ServerName"] = unicodedata.normalize("NFKD", ServerConfig["ServerName"])
|
||||
result["GameTypeSelect"] = self.gametype
|
||||
result["TimeLimit"] = ServerGame["TimeLimit"]
|
||||
|
||||
#!!! sometime maps are not in the cycle (maybe because of mapvote + map number limit): so map might be None
|
||||
# + convert map file name to map name (using map list)
|
||||
if "MapSelect" in CurrentGame:
|
||||
mapname = [k for k, v in MapList.items() if v == CurrentGame["MapSelect"]][0]
|
||||
result["MapSelect"] = mapname
|
||||
result["MapSelect"] = mapname
|
||||
else:
|
||||
result["MapSelect"] = None
|
||||
|
||||
result["MaxIdleTime"] = ServerConfig["MaxIdleTime"]
|
||||
result["MinNetPlayers"] = ServerConfig["MinNetPlayers"]
|
||||
result["bWeaponStay"] = ServerGame["bWeaponStay"]
|
||||
result["SpawnProtectionTime"] = ServerGame["SpawnProtectionTime"]
|
||||
result["bAllowBehindView"] = ServerRules["bAllowBehindView"]
|
||||
result["bAllowWeaponThrowing"] = ServerRules["bAllowWeaponThrowing"]
|
||||
result["bWeaponShouldViewShake"] = ServerRules["bWeaponShouldViewShake"]
|
||||
result["bAllowPrivateChat"] = ServerRules["bAllowPrivateChat"]
|
||||
result["bAllowTaunts"] = ServerRules["bAllowTaunts"]
|
||||
result["bForceRespawn"] = ServerRules["bForceRespawn"]
|
||||
result["bPlayersMustBeReady"] = ServerRules["bPlayersMustBeReady"]
|
||||
|
||||
result["MaxPlayers"] = ServerConfig["MaxPlayers"]
|
||||
result["MaxSpectators"] = ServerConfig["MaxSpectators"]
|
||||
result["nplayer"] = len(PlayerStats)
|
||||
result["players"] = PlayerStats
|
||||
|
||||
if result["GameTypeSelect"] != "SkaarjPack.Invasion":
|
||||
result["GoalScore"] = ServerGame["GoalScore"]
|
||||
|
||||
if result["GameTypeSelect"] == "SkaarjPack.Invasion":
|
||||
result["FinalWave"] = ServerGame["FinalWave"]
|
||||
result["InitialWave"] = ServerGame["InitialWave"]
|
||||
result["MaxIdleTime"] = ServerConfig["MaxIdleTime"]
|
||||
result["MinNetPlayers"] = ServerConfig["MinNetPlayers"]
|
||||
if "bWeaponStay" in ServerGame:
|
||||
result["bWeaponStay"] = ServerGame["bWeaponStay"]
|
||||
result["SpawnProtectionTime"] = ServerGame["SpawnProtectionTime"]
|
||||
result["bAllowBehindView"] = ServerRules["bAllowBehindView"]
|
||||
result["bAllowWeaponThrowing"] = ServerRules["bAllowWeaponThrowing"]
|
||||
result["bWeaponShouldViewShake"] = ServerRules["bWeaponShouldViewShake"]
|
||||
result["bAllowPrivateChat"] = ServerRules["bAllowPrivateChat"]
|
||||
result["bAllowTaunts"] = ServerRules["bAllowTaunts"]
|
||||
result["bForceRespawn"] = ServerRules["bForceRespawn"]
|
||||
result["bPlayersMustBeReady"] = ServerRules["bPlayersMustBeReady"]
|
||||
|
||||
if result["GameTypeSelect"] != "Onslaught.ONSOnslaughtGame":
|
||||
result["bAllowTrans"] = ServerRules["bAllowTrans"]
|
||||
result["MaxPlayers"] = ServerConfig["MaxPlayers"]
|
||||
result["MaxSpectators"] = ServerConfig["MaxSpectators"]
|
||||
result["nplayer"] = len(PlayerStats)
|
||||
result["players"] = PlayerStats
|
||||
|
||||
if result["GameTypeSelect"] == "Onslaught.ONSOnslaughtGame":
|
||||
result["bAllowPlayerLights"] = ServerGame["bAllowPlayerLights"]
|
||||
result["bRandSetupAfterReset"] = ServerGame["bRandSetupAfterReset"]
|
||||
result["bSwapSidesAfterReset"] = ServerGame["bSwapSidesAfterReset"]
|
||||
result["OvertimeCoreDrainPerSec"] = ServerGame["OvertimeCoreDrainPerSec"]
|
||||
if result["GameTypeSelect"] != "SkaarjPack.Invasion":
|
||||
result["GoalScore"] = ServerGame["GoalScore"]
|
||||
|
||||
if result["GameTypeSelect"] == "SkaarjPack.Invasion":
|
||||
result["FinalWave"] = ServerGame["FinalWave"]
|
||||
result["InitialWave"] = ServerGame["InitialWave"]
|
||||
|
||||
if result["GameTypeSelect"] != "Onslaught.ONSOnslaughtGame":
|
||||
result["bAllowTrans"] = ServerRules["bAllowTrans"]
|
||||
|
||||
if result["GameTypeSelect"] == "Onslaught.ONSOnslaughtGame":
|
||||
result["bAllowPlayerLights"] = ServerGame["bAllowPlayerLights"]
|
||||
result["bRandSetupAfterReset"] = ServerGame["bRandSetupAfterReset"]
|
||||
result["bSwapSidesAfterReset"] = ServerGame["bSwapSidesAfterReset"]
|
||||
result["OvertimeCoreDrainPerSec"] = ServerGame["OvertimeCoreDrainPerSec"]
|
||||
|
||||
# 2-teams gamesmode
|
||||
if (result["GameTypeSelect"] == "UT2k4Assault.ASGameInfo" or
|
||||
result["GameTypeSelect"] == "XGame.xBombingRun" or
|
||||
result["GameTypeSelect"] == "Onslaught.xCTFGame" or
|
||||
result["GameTypeSelect"] == "XGame.xDoubleDom" or
|
||||
result["GameTypeSelect"] == "Freeze_Tag_FT5.FreezeTagGame" or
|
||||
result["GameTypeSelect"] == "XGame.InstagibCTF" or
|
||||
result["GameTypeSelect"] == "Onslaught.ONSOnslaughtGame" or
|
||||
result["GameTypeSelect"] == "XGame.xTeamGame" or
|
||||
result["GameTypeSelect"] == "XGame.xVehicleCTFGame") :
|
||||
result["bPlayersBalanceTeams"] = ServerRules["bPlayersBalanceTeams"]
|
||||
|
||||
if (
|
||||
result["GameTypeSelect"] == "UT2k4Assault.ASGameInfo"
|
||||
or result["GameTypeSelect"] == "XGame.xBombingRun"
|
||||
or result["GameTypeSelect"] == "Onslaught.xCTFGame"
|
||||
or result["GameTypeSelect"] == "XGame.xDoubleDom"
|
||||
or result["GameTypeSelect"] == "Freeze_Tag_FT5.FreezeTagGame"
|
||||
or result["GameTypeSelect"] == "XGame.InstagibCTF"
|
||||
or result["GameTypeSelect"] == "Onslaught.ONSOnslaughtGame"
|
||||
or result["GameTypeSelect"] == "XGame.xTeamGame"
|
||||
or result["GameTypeSelect"] == "XGame.xVehicleCTFGame"
|
||||
):
|
||||
result["bPlayersBalanceTeams"] = ServerRules["bPlayersBalanceTeams"]
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@timed_lru_cache(seconds=120)
|
||||
def GetServerGame(self) -> dict():
|
||||
return self._GetFormGEN(self.defaultsGameUrl,'defaults_rules')
|
||||
|
||||
return self._GetFormGEN(self.defaultsGameUrl, "defaults_rules")
|
||||
|
||||
@timed_lru_cache(seconds=120)
|
||||
def GetServerConfig(self) -> dict():
|
||||
return self._GetFormGEN(self.defaultsserverUrl,'defaults_rules')
|
||||
|
||||
return self._GetFormGEN(self.defaultsserverUrl, "defaults_rules")
|
||||
|
||||
@timed_lru_cache(seconds=20)
|
||||
def GetServerCurrentGame(self) -> dict():
|
||||
return self._GetFormGEN(self.CurrentGameUrl,'current_game')
|
||||
|
||||
return self._GetFormGEN(self.CurrentGameUrl, "current_game")
|
||||
|
||||
@timed_lru_cache(seconds=120)
|
||||
def GetServerRules(self) -> dict():
|
||||
return self._GetFormGEN(self.defaultsrulesUrl,'defaults_rules')
|
||||
|
||||
return self._GetFormGEN(self.defaultsrulesUrl, "defaults_rules")
|
||||
|
||||
def GetPlayerStats(self) -> []:
|
||||
ar_PlayersStats = []
|
||||
tree = self._fetchPageETree(self.currentplayersUrl)
|
||||
ar_PlayersStats = []
|
||||
tree = self._fetchPageETree(self.currentplayersUrl)
|
||||
try:
|
||||
level1 = tree.findall(".//form[@action='current_players']")[0]
|
||||
level2 = level1.findall(".//table")[1]
|
||||
@@ -221,131 +229,89 @@ class RconUTEngineWebAdminUT2k4(RconUTEngineWebAdmin.RconUTEngineWebAdminMODCENT
|
||||
if len(teamcheck) > 1:
|
||||
teamcheck = teamcheck[1]
|
||||
if teamcheck.text.strip() == "Team:":
|
||||
bTeamMode = True
|
||||
bTeamMode = True
|
||||
del player_chart[0]
|
||||
for player_record in player_chart:
|
||||
ar_divs = player_record.findall(".//td");
|
||||
if len(ar_divs) > 1 :
|
||||
newplayer = dict()
|
||||
ar_divs = player_record.findall(".//td")
|
||||
if len(ar_divs) > 1:
|
||||
newplayer = dict()
|
||||
if not bTeamMode:
|
||||
#= ar_divs[0] // Kick BP
|
||||
#= ar_divs[1] // BanIP BP
|
||||
#= ar_divs[2] // Name
|
||||
newplayer["Name"] = unicodedata.normalize("NFKD", ar_divs[2].xpath('./text()')[0]).strip()
|
||||
newplayer["Team"] = "None"
|
||||
#= ar_divs[3] // Ping
|
||||
newplayer["Ping"] = unicodedata.normalize("NFKD", ar_divs[3].xpath('./text()')[0]).strip()
|
||||
#= ar_divs[4] // Score
|
||||
newplayer["Score"] = unicodedata.normalize("NFKD", ar_divs[4].xpath('./text()')[0]).strip()
|
||||
#= ar_divs[5] // IP
|
||||
newplayer["IP"] = unicodedata.normalize("NFKD", ar_divs[5].xpath('./text()')[0]).strip()
|
||||
#= ar_divs[6] // UID
|
||||
newplayer["UID"] = unicodedata.normalize("NFKD", ar_divs[6].xpath('./text()')[0]).strip()
|
||||
# = ar_divs[0] // Kick BP
|
||||
# = ar_divs[1] // BanIP BP
|
||||
# = ar_divs[2] // Name
|
||||
newplayer["Name"] = unicodedata.normalize("NFKD", ar_divs[2].xpath("./text()")[0]).strip()
|
||||
newplayer["Team"] = "None"
|
||||
# = ar_divs[3] // Ping
|
||||
newplayer["Ping"] = unicodedata.normalize("NFKD", ar_divs[3].xpath("./text()")[0]).strip()
|
||||
# = ar_divs[4] // Score
|
||||
newplayer["Score"] = unicodedata.normalize("NFKD", ar_divs[4].xpath("./text()")[0]).strip()
|
||||
# = ar_divs[5] // IP
|
||||
newplayer["IP"] = unicodedata.normalize("NFKD", ar_divs[5].xpath("./text()")[0]).strip()
|
||||
# = ar_divs[6] // UID
|
||||
newplayer["UID"] = unicodedata.normalize("NFKD", ar_divs[6].xpath("./text()")[0]).strip()
|
||||
else:
|
||||
#= ar_divs[0] // Kick BP
|
||||
#= ar_divs[1] // BanIP BP
|
||||
#= ar_divs[2] // Name
|
||||
newplayer["Name"] = unicodedata.normalize("NFKD", ar_divs[2].xpath('./text()')[0]).strip()
|
||||
#= ar_divs[3] // Team
|
||||
newplayer["Team"] = unicodedata.normalize("NFKD", ar_divs[3].xpath('./text()')[0]).strip()
|
||||
#= ar_divs[4] // Ping
|
||||
newplayer["Ping"] = unicodedata.normalize("NFKD", ar_divs[4].xpath('./text()')[0]).strip()
|
||||
#= ar_divs[5] // Score
|
||||
newplayer["Score"] = unicodedata.normalize("NFKD", ar_divs[5].xpath('./text()')[0]).strip()
|
||||
#= ar_divs[6] // IP
|
||||
newplayer["IP"] = unicodedata.normalize("NFKD", ar_divs[6].xpath('./text()')[0]).strip()
|
||||
#= ar_divs[7] // UID
|
||||
newplayer["UID"] = unicodedata.normalize("NFKD", ar_divs[7].xpath('./text()')[0]).strip()
|
||||
if newplayer["IP"] == '': #bot detection
|
||||
continue
|
||||
if re.findall(r'\(Spectator\)',newplayer["Name"]): #spectator detection
|
||||
continue
|
||||
# = ar_divs[0] // Kick BP
|
||||
# = ar_divs[1] // BanIP BP
|
||||
# = ar_divs[2] // Name
|
||||
newplayer["Name"] = unicodedata.normalize("NFKD", ar_divs[2].xpath("./text()")[0]).strip()
|
||||
# = ar_divs[3] // Team
|
||||
newplayer["Team"] = unicodedata.normalize("NFKD", ar_divs[3].xpath("./text()")[0]).strip()
|
||||
# = ar_divs[4] // Ping
|
||||
newplayer["Ping"] = unicodedata.normalize("NFKD", ar_divs[4].xpath("./text()")[0]).strip()
|
||||
# = ar_divs[5] // Score
|
||||
newplayer["Score"] = unicodedata.normalize("NFKD", ar_divs[5].xpath("./text()")[0]).strip()
|
||||
# = ar_divs[6] // IP
|
||||
newplayer["IP"] = unicodedata.normalize("NFKD", ar_divs[6].xpath("./text()")[0]).strip()
|
||||
# = ar_divs[7] // UID
|
||||
newplayer["UID"] = unicodedata.normalize("NFKD", ar_divs[7].xpath("./text()")[0]).strip()
|
||||
if newplayer["IP"] == "": # bot detection
|
||||
continue
|
||||
if re.findall(r"\(Spectator\)", newplayer["Name"]): # spectator detection
|
||||
continue
|
||||
ar_PlayersStats.append(newplayer)
|
||||
except Exception as e:
|
||||
raise RconBase.ExceptionRconResultParse(e)
|
||||
return ar_PlayersStats
|
||||
|
||||
|
||||
|
||||
|
||||
def unitaryTEst(testresult):
|
||||
_RconFactory = RconBase.RconFactory()
|
||||
_RconFactory.register_RconBuilder("ut2k4", RconUTEngineWebAdminUT2k4)
|
||||
_RconFactory.register_RconBuilder("ut2k4", RconUTEngineWebAdminUT2k4)
|
||||
|
||||
ar_servers = dict()
|
||||
|
||||
ar_servers["ut2k4_1"] = {
|
||||
"type" : "ut2k4",
|
||||
"address" : "GAME-UT2K4",
|
||||
"port" : 8075,
|
||||
"username" : "admin",
|
||||
"password" : "cfographut"
|
||||
}
|
||||
ar_servers["ut2k4_2"] = {
|
||||
"type" : "ut2k4",
|
||||
"address" : "GAME-UT2K4",
|
||||
"port" : 8076,
|
||||
"username" : "admin",
|
||||
"password" : "cfographut"
|
||||
}
|
||||
ar_servers["ut2k4_3"] = {
|
||||
"type" : "ut2k4",
|
||||
"address" : "GAME-UT2K4",
|
||||
"port" : 8077,
|
||||
"username" : "admin",
|
||||
"password" : "cfographut"
|
||||
}
|
||||
ar_servers["ut2k4_4"] = {
|
||||
"type" : "ut2k4",
|
||||
"address" : "GAME-UT2K4",
|
||||
"port" : 8078,
|
||||
"username" : "admin",
|
||||
"password" : "cfographut"
|
||||
}
|
||||
ar_servers["ut2k4_5"] = {
|
||||
"type" : "ut2k4",
|
||||
"address" : "GAME-UT2K4",
|
||||
"port" : 8079,
|
||||
"username" : "admin",
|
||||
"password" : "cfographut"
|
||||
}
|
||||
ar_servers["ut2k4_x1"] = {
|
||||
"type" : "ut2k4",
|
||||
"address" : "GAME-UT2K4a",
|
||||
"port" : 8079,
|
||||
"username" : "admin",
|
||||
"password" : "cfographut"
|
||||
}
|
||||
ar_servers["ut2k4_x2"] = {
|
||||
"type" : "ut2k4",
|
||||
"address" : "GAME-UT2K4",
|
||||
"port" : 8079,
|
||||
"username" : "admin",
|
||||
"password" : "cfographuta"
|
||||
}
|
||||
ar_rcon= dict()
|
||||
for key,server in ar_servers.items():
|
||||
ar_rcon[key] = _RconFactory.create(server["type"],server["address"],server["port"],server["username"],server["password"])
|
||||
|
||||
for key,rcon in ar_rcon.items():
|
||||
ar_servers["ut2k4_1"] = {"type": "ut2k4", "address": "GAME-UT2K4", "port": 8075, "username": "admin", "password": "cfographut"}
|
||||
ar_servers["ut2k4_2"] = {"type": "ut2k4", "address": "GAME-UT2K4", "port": 8076, "username": "admin", "password": "cfographut"}
|
||||
ar_servers["ut2k4_3"] = {"type": "ut2k4", "address": "GAME-UT2K4", "port": 8077, "username": "admin", "password": "cfographut"}
|
||||
ar_servers["ut2k4_4"] = {"type": "ut2k4", "address": "GAME-UT2K4", "port": 8078, "username": "admin", "password": "cfographut"}
|
||||
ar_servers["ut2k4_5"] = {"type": "ut2k4", "address": "GAME-UT2K4", "port": 8079, "username": "admin", "password": "cfographut"}
|
||||
ar_servers["ut2k4_x1"] = {"type": "ut2k4", "address": "GAME-UT2K4a", "port": 8079, "username": "admin", "password": "cfographut"}
|
||||
ar_servers["ut2k4_x2"] = {"type": "ut2k4", "address": "GAME-UT2K4", "port": 8079, "username": "admin", "password": "cfographuta"}
|
||||
ar_rcon = dict()
|
||||
for key, server in ar_servers.items():
|
||||
ar_rcon[key] = _RconFactory.create(server["type"], server["address"], server["port"], server["username"], server["password"])
|
||||
|
||||
for key, rcon in ar_rcon.items():
|
||||
print("")
|
||||
print("== Testing: " + key + "==")
|
||||
|
||||
|
||||
try:
|
||||
rcon.connect()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
print("* STEP 1: nominal GetStatus()")
|
||||
try:
|
||||
try:
|
||||
res = rcon.GetStatus()
|
||||
print(res)
|
||||
print(res)
|
||||
except RconBase.ExceptionRconTimeout as e:
|
||||
if key=="ut2k4_x1":
|
||||
print("catch error OK")
|
||||
if key == "ut2k4_x1":
|
||||
print("catch error OK")
|
||||
else:
|
||||
print("FAIL: ExceptionRconTimeout catched(%s)" % e)
|
||||
testresult = False
|
||||
except RconBase.ExceptionWrongRconPassword as e:
|
||||
if key=="ut2k4_x2":
|
||||
if key == "ut2k4_x2":
|
||||
print("catch error OK")
|
||||
else:
|
||||
print("FAIL: ExceptionWrongRconPassword catched(%s)" % e)
|
||||
@@ -355,7 +321,7 @@ def unitaryTEst(testresult):
|
||||
rcon.connect()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
print("* STEP 2: nominal GetGameServerStatusResult()")
|
||||
try:
|
||||
res = rcon.GetGameServerStatusResult()
|
||||
@@ -370,15 +336,16 @@ def unitaryTEst(testresult):
|
||||
except RconBase.ExceptionWrongRconPassword as e:
|
||||
print("FAIL: ExceptionWrongRconPassword catched(%s)" % e)
|
||||
testresult = False
|
||||
|
||||
rcon.disconnect()
|
||||
print("Unitary test finished with status: "+ str(testresult))
|
||||
return testresult
|
||||
|
||||
if __name__ == '__main__':
|
||||
testresult=True;
|
||||
rcon.disconnect()
|
||||
print("Unitary test finished with status: " + str(testresult))
|
||||
return testresult
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
testresult = True
|
||||
nbtest = 1
|
||||
for x in range(nbtest):
|
||||
print("\n\nStarting test %d over %d\n"%(x+1,nbtest))
|
||||
testresult=unitaryTEst(testresult)
|
||||
print("Full test finished with status: "+ str(testresult))
|
||||
print("\n\nStarting test %d over %d\n" % (x + 1, nbtest))
|
||||
testresult = unitaryTEst(testresult)
|
||||
print("Full test finished with status: " + str(testresult))
|
||||
|
||||
@@ -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.9"
|
||||
__version__ = "0.1.10"
|
||||
|
||||
Reference in New Issue
Block a user