From 60e6127725a10733cc526fcec4c5779c1e8483ba Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Sat, 14 Sep 2024 10:02:29 +0200 Subject: [PATCH] Support stream names in 'bname.zip:fname.truck' format. This is a bundle-qualified format, where 'bundle' is ZIP/subdir in modcache. See https://github.com/RigsOfRods/rigs-of-rods/pull/3171 Code changes: - RoR_client: new function `getTruckFilenameFromStreamName()` with commentary. Existing `getTruckInfo()` extended to use it. - services_start: just renamed the banlist-scanning function for clarity --- RoR_client.py | 14 +++++++++++--- services_start.py | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/RoR_client.py b/RoR_client.py index a27540e..16831af 100644 --- a/RoR_client.py +++ b/RoR_client.py @@ -64,6 +64,13 @@ def s(b, encoding="utf-8"): "#999900" ]; +# Name may be in "bname:fname.truck" format, where 'bundle' is ZIP/subdir in modcache. See https://github.com/RigsOfRods/rigs-of-rods/pull/3171 +def getTruckFilenameFromStreamName(streamName): + if ':' in streamName: + return streamName.split(b':')[1] + else: + return streamName + def getTruckName(filename): if filename in TruckToName.list: return TruckToName.list[filename] @@ -72,7 +79,8 @@ def getTruckName(filename): def getTruckType(filename): return filename.split(b'.').pop().lower() -def getTruckInfo(filename): +def getTruckInfo(streamName): + filename = getTruckFilenameFromStreamName(streamName) return { 'type': getTruckType(filename), 'name': getTruckName(filename), @@ -468,8 +476,8 @@ def sayDebug(self, msg): # [game] is now driving a (streams: /) def sayStreamReg(self, uid, stream): truckinfo = getTruckInfo(stream.name); - invalid = self.main.validate(s(truckinfo['file'])) - if invalid: + banned = self.main.isVehicleBanned(s(truckinfo['file'])) + if banned: self.sayInfo("User **%s** with uid **%s** has spawned a **%s** which is a banned vehicle." % (self.sm.getUsername(uid), uid, s(truckinfo['file']))) self.main.queueKick(self.channelID, int(uid)) else: diff --git a/services_start.py b/services_start.py index cd53403..208143f 100644 --- a/services_start.py +++ b/services_start.py @@ -317,7 +317,7 @@ def startRoRclientOnDemand(self, channel): self.RoRclients[ID].setName('RoR_thread_'+ID) self.RoRclients[ID].start() - def validate(self, truck): + def isVehicleBanned(self, truck): if os.path.isfile('truck.blacklist') == False: return False