From 9b6676ebc78040266ba367e7b8fce84083705522 Mon Sep 17 00:00:00 2001 From: John Cote Date: Mon, 30 Dec 2019 19:56:05 -0500 Subject: [PATCH] general: fix chat & classic char crashes --- otp/chat/TalkAssistant.py | 3 +-- otp/chat/WhiteList.py | 4 ++-- toontown/chat/TTChatInputWhiteList.py | 4 ++-- toontown/classicchars/DistributedCCharBase.py | 3 +-- toontown/classicchars/DistributedCCharBaseAI.py | 3 ++- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/otp/chat/TalkAssistant.py b/otp/chat/TalkAssistant.py index f52f5e2..0506da2 100644 --- a/otp/chat/TalkAssistant.py +++ b/otp/chat/TalkAssistant.py @@ -1,4 +1,3 @@ -import string import sys from direct.showbase import DirectObject from otp.otpbase import OTPLocalizer @@ -209,7 +208,7 @@ class TalkAssistant(DirectObject.DirectObject): return 0 elif len(message) == 0: return 0 - elif string.find(message, ThoughtPrefix, 0, len(ThoughtPrefix)) >= 0: + elif message.find(ThoughtPrefix, 0, len(ThoughtPrefix)) >= 0: return 1 else: return 0 diff --git a/otp/chat/WhiteList.py b/otp/chat/WhiteList.py index 4d1f82b..af06589 100644 --- a/otp/chat/WhiteList.py +++ b/otp/chat/WhiteList.py @@ -14,8 +14,8 @@ class WhiteList: self.numWords = len(self.words) def cleanText(self, text): - text = text.strip('.,?!') - text = text.lower() + text = text.decode('utf-8').strip('.,?!') + text = text.lower().encode('utf-8') return text def isWord(self, text): diff --git a/toontown/chat/TTChatInputWhiteList.py b/toontown/chat/TTChatInputWhiteList.py index c71f539..4889d3f 100644 --- a/toontown/chat/TTChatInputWhiteList.py +++ b/toontown/chat/TTChatInputWhiteList.py @@ -187,7 +187,7 @@ class TTChatInputWhiteList(ChatInputWhiteListFrame): flag = 1 for word in words: - if word == '' or self.whiteList.isWord(word) or not base.cr.whiteListChatEnabled: + if word == '' or self.whiteList.isWord(word.encode('utf-8')) or not base.cr.whiteListChatEnabled: newwords.append(word) else: if self.checkBeforeSend: @@ -201,7 +201,7 @@ class TTChatInputWhiteList(ChatInputWhiteListFrame): if not strict: lastword = words[-1] - if lastword == '' or self.whiteList.isPrefix(lastword) or not base.cr.whiteListChatEnabled: + if lastword == '' or self.whiteList.isPrefix(lastword.encode('utf-8')) or not base.cr.whiteListChatEnabled: newwords[-1] = lastword elif flag: newwords[-1] = '\x01WLDisplay\x01' + lastword + '\x02' diff --git a/toontown/classicchars/DistributedCCharBase.py b/toontown/classicchars/DistributedCCharBase.py index 65a9938..1702d17 100644 --- a/toontown/classicchars/DistributedCCharBase.py +++ b/toontown/classicchars/DistributedCCharBase.py @@ -14,7 +14,6 @@ from toontown.toonbase.TTLocalizer import Donald, DonaldDock, WesternPluto, Plut from toontown.effects import DustCloud from . import CCharChatter from . import CCharPaths -import string import copy class DistributedCCharBase(DistributedChar.DistributedChar): @@ -180,7 +179,7 @@ class DistributedCCharBase(DistributedChar.DistributedChar): if '%' in str: str = copy.deepcopy(str) avName = avatar.getName() - str = string.replace(str, '%', avName) + str = str.replace('%', avName) track = Sequence() if category != CCharChatter.GOODBYE: curHpr = self.getHpr() diff --git a/toontown/classicchars/DistributedCCharBaseAI.py b/toontown/classicchars/DistributedCCharBaseAI.py index ece19b1..010aa2a 100644 --- a/toontown/classicchars/DistributedCCharBaseAI.py +++ b/toontown/classicchars/DistributedCCharBaseAI.py @@ -5,6 +5,7 @@ from otp.avatar.DistributedPlayerAI import DistributedPlayerAI from direct.directnotify import DirectNotifyGlobal from toontown.toonbase import ToontownGlobals import random +import functools class DistributedCCharBaseAI(DistributedAvatarAI.DistributedAvatarAI): notify = DirectNotifyGlobal.directNotify.newCategory('DistributedCCharBaseAI') @@ -149,7 +150,7 @@ class DistributedCCharBaseAI(DistributedAvatarAI.DistributedAvatarAI): else: return 1 - self.nearbyAvatars.sort(nAv_compare) + self.nearbyAvatars.sort(key=functools.cmp_to_key(nAv_compare)) def getNearbyAvatars(self): return self.nearbyAvatars