implement REST Stats for UT99
This commit is contained in:
@@ -19,6 +19,7 @@ from . import RconQuakes
|
||||
from . import RconUTEngineWebAdminUT2k4
|
||||
from . import RconUTEngineWebAdminUT3
|
||||
from . import RconUTEngineWebAdminUT99
|
||||
from . import RconUT99_ChaChaRESTStats
|
||||
from . import RconMinecraft
|
||||
from pickle import TRUE
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
@@ -124,7 +125,7 @@ class GameStatsSupervisorFactory:
|
||||
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("ut99", RconUT99_ChaChaRESTStats.RconUT99_ChaChaRESTStats)
|
||||
self.register_GameStatsSupervisorRconBuilder("q2", RconQuakes.RconSourceEngineQuake2)
|
||||
self.register_GameStatsSupervisorRconBuilder("q3a", RconQuakes.RconSourceEngineQuake3A)
|
||||
self.register_GameStatsSupervisorRconBuilder("codmw3", RconCODs.RconSourceEngineCODMW3)
|
||||
|
||||
93
ChaChaGameStats/RconUT99_ChaChaRESTStats.py
Normal file
93
ChaChaGameStats/RconUT99_ChaChaRESTStats.py
Normal file
@@ -0,0 +1,93 @@
|
||||
"""
|
||||
ChaChaGameStats (c) by clement chastanier
|
||||
|
||||
ChaChaGameStats is licensed under a
|
||||
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Unported License.
|
||||
|
||||
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/>.
|
||||
"""
|
||||
|
||||
import time
|
||||
from pprint import pprint
|
||||
|
||||
import requests
|
||||
|
||||
from . import GameStatsInterface
|
||||
from . import RconBase
|
||||
|
||||
|
||||
#class ExceptionRconIncorrectPadding(RconBase.ExceptionRcon):
|
||||
# pass
|
||||
|
||||
class RconUT99_ChaChaRESTStats(RconBase.RconBase):
|
||||
def __init__(self,GameName:str,ip:str,port:int,user:str,password:str,timeout:int):
|
||||
print("INIT ???")
|
||||
super().__init__(GameName,ip,port,user,password,timeout)
|
||||
self.session = None
|
||||
self.BaseUrl = "http://" + self.ip + ":" + str(self.port) + "/api/v1/"
|
||||
self.GameServerStatusResult = None
|
||||
self.timeout = timeout
|
||||
|
||||
def connect(self):
|
||||
self.session = requests.session()
|
||||
super().connect()
|
||||
|
||||
def disconnect(self):
|
||||
try:
|
||||
self.session.close()
|
||||
except Exception as e:
|
||||
print("WARNING: self.session.close() failed: %s" % e)
|
||||
super().disconnect()
|
||||
|
||||
def GetStatus(self) -> dict():
|
||||
PINGstarttime = time.time()
|
||||
default_all=self.session.get(self.BaseUrl + "default_all",timeout=self.timeout)
|
||||
PING = round( (time.time() - PINGstarttime)*1000)
|
||||
current_all=self.session.get(self.BaseUrl + "current_all",timeout=self.timeout)
|
||||
res=dict()
|
||||
res["ping"]=PING
|
||||
res["default_all"]=default_all.json()
|
||||
res["current_all"]=current_all.json()
|
||||
return res
|
||||
|
||||
## interface implementation
|
||||
def GetGameServerStatusResult(self) -> GameStatsInterface.GameServerStatusResult_Main:
|
||||
self.GameServerStatusResult = super().GetGameServerStatusResult()
|
||||
if self.GameServerStatusResult.status != "DOWN":
|
||||
try:
|
||||
self.GameServerStatusResult.raw = self.GetStatus()
|
||||
self.GameServerStatusResult.status = "UP"
|
||||
except RconBase.ExceptionRconTimeout:
|
||||
self.GameServerStatusResult.status = "DOWN"
|
||||
self.GameServerStatusResult.ping = 999
|
||||
return self.GameServerStatusResult
|
||||
except RconBase.ExceptionWrongRconPassword:
|
||||
self.GameServerStatusResult.status = "REFUSED"
|
||||
self.GameServerStatusResult.ping = 999
|
||||
return self.GameServerStatusResult
|
||||
|
||||
self.GameServerStatusResult.name = self.GameServerStatusResult.raw["default_all"]["ServerName"]
|
||||
self.GameServerStatusResult.map = self.GameServerStatusResult.raw["current_all"]["Level"]
|
||||
self.GameServerStatusResult.gametype = self.GameServerStatusResult.raw["current_all"]["GameName"]
|
||||
self.GameServerStatusResult.mods = ",".join(self.GameServerStatusResult.raw["current_all"]["Mutators"])
|
||||
self.GameServerStatusResult.maxplayers = self.GameServerStatusResult.raw["default_all"]["MaxPlayers"]
|
||||
self.GameServerStatusResult.ping = self.GameServerStatusResult.raw["ping"]
|
||||
self.GameServerStatusResult.version = None
|
||||
self.GameServerStatusResult.players = []
|
||||
numplayers = 0
|
||||
for player in self.GameServerStatusResult.raw["current_all"]["player_list"]:
|
||||
if player["bIsSpectator"] or player["bIsABot"]:
|
||||
continue
|
||||
newplayer = GameStatsInterface.GameServerStatusResult_Players()
|
||||
newplayer.name = player["PlayerName"]
|
||||
newplayer.score = player["Score"]
|
||||
newplayer.ping = player["Ping"]
|
||||
newplayer.ip = player["IP"]
|
||||
newplayer.port = None
|
||||
newplayer.uid = None
|
||||
newplayer.num = numplayers
|
||||
self.GameServerStatusResult.players.append(newplayer)
|
||||
numplayers+=1
|
||||
self.GameServerStatusResult.nplayer = numplayers
|
||||
return self.GameServerStatusResult
|
||||
17
sample.py
17
sample.py
@@ -35,7 +35,7 @@ if __name__ == '__main__':
|
||||
"password":"fooo"} # rcon/web password
|
||||
)
|
||||
)
|
||||
"""
|
||||
|
||||
|
||||
|
||||
ar_games.append( _GameStatsSupervisorFactory.create( name = "ut99-dm",
|
||||
@@ -49,7 +49,20 @@ if __name__ == '__main__':
|
||||
"username":"chacha",
|
||||
"password":"cfographut"}
|
||||
)
|
||||
)
|
||||
)
|
||||
"""
|
||||
ar_games.append( _GameStatsSupervisorFactory.create( name = "ut99-dm",
|
||||
gametype = "ut99",
|
||||
ip = "127.0.0.1",
|
||||
|
||||
|
||||
#Interface_QuakeStats = { "port":7777},
|
||||
|
||||
Interface_RconBase = { "port":8080,
|
||||
"username":"",
|
||||
"password":""}
|
||||
)
|
||||
)
|
||||
"""
|
||||
ar_games.append( _GameStatsSupervisorFactory.create( name = "ut99-niut",
|
||||
gametype = "ut99",
|
||||
|
||||
Reference in New Issue
Block a user