Files
ChaChaGameStats/sample.py
2023-06-28 21:23:20 +01:00

166 lines
11 KiB
Python

import os
import time
from ChaChaGameStats import GameStatsSupervisor
from pprint import pprint
# unitary test
if __name__ == "__main__":
_GameStatsSupervisorFactory = GameStatsSupervisor.GameStatsSupervisorFactory()
if os.name == "nt":
# for windows
dir_path = os.path.dirname(os.path.realpath(__file__))
qstatpath = dir_path + "\\Ext\qstat.exe"
print(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
ip = "xx.xx.xx.xx", # gameserver ip or dns name
# Stats Interfaces registration:
# - at least one interface must be configured
#[optional] QuakeStat Interface registration:
Interface_QuakeStats = { "port":xxxx}, # quakestat protocol port (usually same as game port)
#[optional] Rcon/Web Interface registration:
# rcon interface is 'real' rcon for cod(s) and quake(s) games, xmlrpc for crysis and http webgui for ut(s)
Interface_RconBase = { "port":xxxx, # rcon/web protocol port
"username":"fooo", # rcon/Web user
"password":"fooo"} # rcon/web password
)
)
"""
"""
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-ctf",
gametype = "ut99",
ip = "127.0.0.1",
#ip = "37.59.37.210",
#Interface_QuakeStats = { "port":5040},
Interface_RconBase = { "port":8080,
"username":"",
"password":""}
)
)
"""
ar_games.append( _GameStatsSupervisorFactory.create( name = "ut99-niut",
gametype = "ut99",
ip = "172.16.1.40",
Interface_QuakeStats = { "port":5010},
Interface_RconBase = { "port":5010,
"username":"chacha",
"password":"cfographut"}
)
)
ar_games.append( _GameStatsSupervisorFactory.create( name = "ut99-mh",
gametype = "ut99",
ip = "172.16.1.43",
Interface_QuakeStats = { "port":5020},
Interface_RconBase = { "port":5020,
"username":"chacha",
"password":"cfographut"}
)
)
ar_games.append( _GameStatsSupervisorFactory.create( name = "ut99-utp",
gametype = "ut99",
ip = "172.16.1.42",
Interface_QuakeStats = { "port":5030},
Interface_RconBase = { "port":5030,
"username":"chacha",
"password":"AmL992gxE"}
)
)
ar_games.append( _GameStatsSupervisorFactory.create( name = "codbo2-3",
gametype = "codbo2",
ip = "GAME-CODBO2",
Interface_QuakeStats = { "port":27118},
Interface_RconBase = { "port":27118,
"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()
for i in range(200):
for game in ar_games:
print("")
print("== Testing: " + game.GameName + "==")
res = game.API_GetGameServerStatusResult()
pprint("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__) + "},...}")
# 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))