Skip to content

Commit

Permalink
Support stream names in 'bname.zip:fname.truck' format.
Browse files Browse the repository at this point in the history
This is a bundle-qualified format, where 'bundle' is ZIP/subdir in modcache. See RigsOfRods/rigs-of-rods#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
  • Loading branch information
ohlidalp committed Sep 14, 2024
1 parent ae6ecfe commit 60e6127
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions RoR_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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),
Expand Down Expand Up @@ -468,8 +476,8 @@ def sayDebug(self, msg):
# [game] <username> is now driving a <truckname> (streams: <number of streams>/<limit of 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:
Expand Down
2 changes: 1 addition & 1 deletion services_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 60e6127

Please sign in to comment.