redid level access and added that racetimer endpont is read to give a bit torch access

This commit is contained in:
jenz 2024-05-21 00:26:09 +02:00
parent 296d3f4b38
commit 810ee7a86c
2 changed files with 193 additions and 181 deletions

View File

@ -597,7 +597,7 @@ class YouTube(BaseCommand):
def __init__(self, torchlight):
super().__init__(torchlight)
self.Triggers = ["!yt"]
self.Level = 3
self.Level = 6
async def _func(self, message, player):
self.Logger.debug(sys._getframe().f_code.co_name + ' ' + str(message))
@ -628,7 +628,7 @@ class YouTubeSearch(BaseCommand):
def __init__(self, torchlight):
super().__init__(torchlight)
self.Triggers = ["!yts"]
self.Level = 3
self.Level = 6 #adjusting to new levels
async def _func(self, message, player):
self.Logger.debug(sys._getframe().f_code.co_name + ' ' + str(message))
@ -717,7 +717,7 @@ class DECTalk(BaseCommand):
def __init__(self, torchlight):
super().__init__(torchlight)
self.Triggers = ["!dec"]
self.Level = 2
self.Level = 6
async def Say(self, player, message):
message = "[:phoneme on]" + message
@ -770,7 +770,7 @@ class EnableDisable(BaseCommand):
def __init__(self, torchlight):
super().__init__(torchlight)
self.Triggers = ["!enable", "!disable"]
self.Level = 3
self.Level = 6
async def _func(self, message, player):
self.Logger.debug(sys._getframe().f_code.co_name + ' ' + str(message))
@ -797,7 +797,7 @@ class AdminAccess(BaseCommand):
def __init__(self, torchlight):
super().__init__(torchlight)
self.Triggers = ["!access"]
self.Level = 4
self.Level = 7
def ReloadValidUsers(self):
self.Torchlight().Access.Load()
@ -902,27 +902,8 @@ class Reload(BaseCommand):
def __init__(self, torchlight):
super().__init__(torchlight)
self.Triggers = ["!reload"]
self.Level = 4
self.Level = 7
async def _func(self, message, player):
self.Logger.debug(sys._getframe().f_code.co_name + ' ' + str(message))
self.Torchlight().Reload()
return 0
"""
class Exec(BaseCommand):
def __init__(self, torchlight):
super().__init__(torchlight)
self.Triggers = ["!exec"]
self.Level = 100
async def _func(self, message, player):
self.Logger.debug(sys._getframe().f_code.co_name + ' ' + str(message))
try:
Response = eval(message[1])
except Exception as e:
self.Torchlight().SayChat("Error: {0}".format(str(e)))
return 1
self.Torchlight().SayChat(str(Response))
return 0
"""

View File

@ -2,15 +2,31 @@
# -*- coding: utf-8 -*-
import asyncio
import logging
import numpy
import requests
from .Constants import *
def usteamid_to_steamid(usteamid):
for ch in ['[', ']']:
if ch in usteamid:
usteamid = usteamid.replace(ch, '')
usteamid_split = usteamid.split(':')
steamid = []
steamid.append('STEAM_0:')
z = int(usteamid_split[2])
if z % 2 == 0:
steamid.append('0:')
else:
steamid.append('1:')
steamacct = z // 2
steamid.append(str(steamacct))
return ''.join(steamid)
class PlayerManager():
def __init__(self, master):
self.Logger = logging.getLogger(__class__.__name__)
self.Torchlight = master
self.Players = numpy.empty(MAXPLAYERS + 1, dtype = object)
self.Players = [None] * (MAXPLAYERS + 1)
self.Storage = self.StorageManager(self)
self.Torchlight().GameEvents.HookEx("player_connect", self.Event_PlayerConnect)
@ -68,7 +84,7 @@ class PlayerManager():
self.Storage.Reset()
for i in range(1, self.Players.size):
for i in range(1, len(self.Players)):
if self.Players[i]:
self.Players[i].OnDisconnect("mapchange")
self.Players[i].OnConnect()
@ -90,7 +106,7 @@ class PlayerManager():
def __len__(self):
Count = 0
for i in range(1, self.Players.size):
for i in range(1, len(self.Players)):
if self.Players[i]:
Count += 1
return Count
@ -104,7 +120,7 @@ class PlayerManager():
return self.Players[key]
def __iter__(self):
for i in range(1, self.Players.size):
for i in range(1, len(self.Players)):
if self.Players[i]:
yield self.Players[i]
@ -182,11 +198,26 @@ class PlayerManager():
self.PlayerManager.Logger.info("#{0} \"{1}\"({2}) FlagBits: {3}".format(self.UserID, self.Name, self.UniqueID, self.Admin._FlagBits))
if not self.Access:
if self.Admin.RCON():
self.Access = dict({"level": 6, "name": "SAdmin"})
self.Access = dict({"level": 9, "name": "SAdmin"})
elif self.Admin.Generic():
self.Access = dict({"level": 3, "name": "Admin"})
self.Access = dict({"level": 6, "name": "Admin"})
elif self.Admin.Custom1():
self.Access = dict({"level": 1, "name": "VIP"})
self.Access = dict({"level": 5, "name": "VIP"})
elif self.UniqueID != 'BOT':
#self.PlayerManager.Logger.info(f"self.UniqueID: {self.UniqueID}")
#2024 20th may. giving level based on racetimer rank
steam2 = usteamid_to_steamid(self.UniqueID) #converting steam3 to steam2
#if we did more requests than max 64 around the same time i would consider turning it into a session
r = requests.get(f"https://racebackend.unloze.com/racetimer_endpoints-1.0/api/timers/player/{steam2}")
if "Rank" in r.json():
rank = r.json()["Rank"]
#self.PlayerManager.Logger.info(f"rank: {rank}")
if rank <= 250:
self.Access = dict({"level": 4, "name": "top 250"})
elif rank <= 500:
self.Access = dict({"level": 3, "name": "top 500"})
elif rank <= 1000:
self.Access = dict({"level": 2, "name": "top 1000"})
if self.PlayerManager.Torchlight().Config["DefaultLevel"]:
if self.Access and self.Access["level"] < self.PlayerManager.Torchlight().Config["DefaultLevel"]: