Unicode chat warning

This commit is contained in:
John 2015-05-24 19:04:49 +03:00
parent c100370140
commit ea14534efb
8 changed files with 59 additions and 69 deletions

View file

@ -11,5 +11,7 @@ class AvatarHandle:
return True
def setTalkWhisper(self, fromAV, fromAC, avatarName, chat, mods, flags):
if not base.cr.chatAgent.verifyMessage(chat):
return
newText, scrubbed = localAvatar.scrubTalk(chat, mods)
base.talkAssistant.receiveWhisperTalk(fromAV, avatarName, fromAC, None, self.avatarId, self.getName(), newText, scrubbed)

View file

@ -206,6 +206,8 @@ class DistributedPlayer(DistributedAvatar.DistributedAvatar, PlayerBase.PlayerBa
self.sendUpdate('setChat', [chatString, chatFlags, 0])
def setTalk(self, fromAV, fromAC, avatarName, chat, mods, flags):
if not base.cr.verifyMessage(chat):
return
if base.localAvatar.isIgnored(fromAV):
return
newText, scrubbed = self.scrubTalk(chat, mods)
@ -218,6 +220,8 @@ class DistributedPlayer(DistributedAvatar.DistributedAvatar, PlayerBase.PlayerBa
return
def setTalkWhisper(self, fromAV, fromAC, avatarName, chat, mods, flags):
if not base.cr.verifyMessage(chat):
return
if base.localAvatar.isIgnored(fromAV):
return
newText, scrubbed = self.scrubTalk(chat, mods)

View file

@ -15,17 +15,32 @@ class ChatAgent(DistributedObjectGlobal):
DistributedObjectGlobal.delete(self)
return
def verifyMessage(self, message):
try:
message.decode('ascii')
return True
except:
return False
def adminChat(self, aboutId, message):
if not self.verifyMessage(message):
return
self.notify.warning('Admin Chat(%s): %s' % (aboutId, message))
messenger.send('adminChat', [aboutId, message])
def sendChatMessage(self, message):
if not self.verifyMessage(message):
return
self.sendUpdate('chatMessage', [message, self.chatMode])
def sendWhisperMessage(self, receiverAvId, message):
if not self.verifyMessage(message):
return
self.sendUpdate('whisperMessage', [receiverAvId, message])
def sendSFWhisperMessage(self, receiverAvId, message):
if not self.verifyMessage(message):
return
self.sendUpdate('sfWhisperMessage', [receiverAvId, message])
@magicWord(category=CATEGORY_MODERATOR, types=[int])
@ -51,5 +66,4 @@ def chatmode(mode=-1):
# Like this will ever happen, but whatever.
return "Chat mode 1 is reserved for moderators."
base.cr.chatAgent.chatMode = mode
return "You are now talking in the %s chat mode." % mode2name.get(mode, "N/A")
return "You are now talking in the %s chat mode." % mode2name.get(mode, "N/A")

View file

@ -16,7 +16,6 @@ class ChatInputWhiteListFrame(FSM.FSM, DirectFrame):
def __init__(self, entryOptions, parent = None, **kw):
FSM.FSM.__init__(self, 'ChatInputWhiteListFrame')
self.okayToSubmit = True
self.receiverId = None
DirectFrame.__init__(self, parent=aspect2dp, pos=(0, 0, 0.3), relief=None, image=DGG.getDefaultDialogGeom(), image_scale=(1.6, 1, 1.4), image_pos=(0, 0, -0.05), image_color=OTPGlobals.GlobalDialogColor, borderWidth=(0.01, 0.01))
optiondefs = {'parent': self,
@ -37,7 +36,6 @@ class ChatInputWhiteListFrame(FSM.FSM, DirectFrame):
'suppressKeys': 1,
'suppressMouse': 1,
'command': self.sendChat,
'failedCommand': self.sendFailed,
'focus': 0,
'text': '',
'sortOrder': DGG.FOREGROUND_SORT_INDEX}
@ -50,7 +48,6 @@ class ChatInputWhiteListFrame(FSM.FSM, DirectFrame):
self.historySize = base.config.GetInt('chat-history-size', 10)
self.historyIndex = 0
self.promoteWhiteList = 0
self.checkBeforeSend = base.config.GetBool('white-list-check-before-send', 0)
self.whiteList = None
self.active = 0
self.autoOff = 0
@ -132,7 +129,7 @@ class ChatInputWhiteListFrame(FSM.FSM, DirectFrame):
self.chatEntry['focus'] = 1
self.show()
self.active = 1
self.chatEntry.guiItem.setAcceptEnabled(False)
self.chatEntry.guiItem.setAcceptEnabled(True)
def deactivate(self):
self.chatEntry.set('')
@ -160,9 +157,15 @@ class ChatInputWhiteListFrame(FSM.FSM, DirectFrame):
if text:
self.chatEntry.set('')
self.sendChatBySwitch(text)
if self.wantHistory:
self.addToHistory(text)
try:
text.decode('ascii')
self.sendChatBySwitch(text)
if self.wantHistory:
self.addToHistory(text)
except UnicodeEncodeError:
base.localAvatar.setSystemMessage(0, OTPLocalizer.AsciiNotSupported)
if not overflow:
self.hide()
@ -195,22 +198,6 @@ class ChatInputWhiteListFrame(FSM.FSM, DirectFrame):
else:
base.talkAssistant.sendOpenTalk(text)
def sendFailed(self, text):
if not self.checkBeforeSend:
self.sendChat(text)
return
self.chatEntry['frameColor'] = (0.9, 0.0, 0.0, 0.8)
def resetFrameColor(task = None):
self.chatEntry['frameColor'] = self.origFrameColor
return Task.done
taskMgr.doMethodLater(0.1, resetFrameColor, 'resetFrameColor')
self.applyFilter(keyArgs=None, strict=True)
self.okayToSubmit = True
self.chatEntry.guiItem.setAcceptEnabled(True)
return
def chatOverflow(self, overflowText):
self.notify.debug('chatOverflow')
self.sendChat(self.chatEntry.get(plain=True), overflow=True)
@ -231,21 +218,15 @@ class ChatInputWhiteListFrame(FSM.FSM, DirectFrame):
def applyFilter(self, keyArgs, strict = False):
text = self.chatEntry.get(plain=True)
if text.startswith('~'):
self.okayToSubmit = True
else:
if not text.startswith('~'):
words = text.split(' ')
newwords = []
self.notify.debug('%s' % words)
self.okayToSubmit = True
for word in words:
if word == '' or self.whiteList.isWord(word):
newwords.append(word)
else:
if self.checkBeforeSend:
self.okayToSubmit = False
else:
self.okayToSubmit = True
newwords.append('\x01WLEnter\x01' + word + '\x02')
if not strict:
@ -255,5 +236,4 @@ class ChatInputWhiteListFrame(FSM.FSM, DirectFrame):
else:
newwords[-1] = '\x01WLEnter\x01' + lastword + '\x02'
newtext = ' '.join(newwords)
self.chatEntry.set(newtext)
self.chatEntry.guiItem.setAcceptEnabled(self.okayToSubmit)
self.chatEntry.set(newtext)

View file

@ -36,6 +36,8 @@ class TalkHandle(AvatarHandle):
self.accountName = message.getReceiverAccountName()
def setTalkWhisper(self, fromAV, fromAC, avatarName, chat, mods, flags):
if not base.cr.verifyMessage(chat):
return
if base.localAvatar.isIgnored(fromAV):
return
newText, scrubbed = localAvatar.scrubTalk(chat, mods)

View file

@ -2319,3 +2319,5 @@ def timeElapsedString(timeDelta):
return '1 minute ago'
else:
return '%s minutes ago' % (timeDelta.seconds / 60)
AsciiNotSupported = 'Sorry, but Toontown United does not support non-ASCII characters.'

View file

@ -28,7 +28,6 @@ class TTChatInputWhiteList(ChatInputWhiteListFrame):
'suppressKeys': 0,
'suppressMouse': 1,
'command': self.sendChat,
'failedCommand': self.sendFailed,
'focus': 0,
'text': '',
'sortOrder': DGG.FOREGROUND_SORT_INDEX}
@ -78,17 +77,13 @@ class TTChatInputWhiteList(ChatInputWhiteListFrame):
self.typeGrabbed = 0
def typeCallback(self, extraArgs):
try:
if self.typeGrabbed:
return
self.applyFilter(extraArgs)
if localAvatar.chatMgr.chatInputWhiteList.isActive():
return
else:
messenger.send('wakeup')
messenger.send('enterNormalChat')
except UnicodeDecodeError:
if self.typeGrabbed:
return
self.applyFilter(extraArgs)
if localAvatar.chatMgr.chatInputWhiteList.isActive():
return
messenger.send('wakeup')
messenger.send('enterNormalChat')
def destroy(self):
self.chatEntry.destroy()
@ -132,10 +127,7 @@ class TTChatInputWhiteList(ChatInputWhiteListFrame):
return
def chatButtonPressed(self):
if self.okayToSubmit:
self.sendChat(self.chatEntry.get())
else:
self.sendFailed(self.chatEntry.get())
self.sendChat(self.chatEntry.get())
def cancelButtonPressed(self):
self.requestMode('Off')
@ -166,12 +158,10 @@ class TTChatInputWhiteList(ChatInputWhiteListFrame):
def applyFilter(self, keyArgs, strict = False):
text = self.chatEntry.get(plain=True)
if text.startswith('~'):
self.okayToSubmit = True
else:
if not text.startswith('~'):
words = text.split(' ')
newwords = []
self.okayToSubmit = True
flag = 0
for friendId, flags in base.localAvatar.friendsList:
if flags & ToontownGlobals.FriendChat:
@ -181,10 +171,6 @@ class TTChatInputWhiteList(ChatInputWhiteListFrame):
if word == '' or self.whiteList.isWord(word) or not settings['speedchatPlus']:
newwords.append(word)
else:
if self.checkBeforeSend:
self.okayToSubmit = False
else:
self.okayToSubmit = True
if flag:
newwords.append('\x01WLDisplay\x01' + word + '\x02')
else:
@ -192,15 +178,11 @@ class TTChatInputWhiteList(ChatInputWhiteListFrame):
if not strict:
lastword = words[-1]
try:
if lastword == '' or self.whiteList.isPrefix(lastword) or not settings['speedchatPlus']:
newwords[-1] = lastword
elif flag:
newwords[-1] = '\x01WLDisplay\x01' + lastword + '\x02'
else:
newwords[-1] = '\x01WLEnter\x01' + lastword + '\x02'
except UnicodeDecodeError:
self.okayToSubmit = False
if lastword == '' or self.whiteList.isPrefix(lastword) or not settings['speedchatPlus']:
newwords[-1] = lastword
elif flag:
newwords[-1] = '\x01WLDisplay\x01' + lastword + '\x02'
else:
newwords[-1] = '\x01WLEnter\x01' + lastword + '\x02'
newtext = ' '.join(newwords)
self.chatEntry.set(newtext)
self.chatEntry.guiItem.setAcceptEnabled(self.okayToSubmit)
self.chatEntry.set(newtext)

View file

@ -462,6 +462,8 @@ class DistributedToon(DistributedPlayer.DistributedPlayer, Toon.Toon, Distribute
return Task.cont
def setTalk(self, fromAV, fromAC, avatarName, chat, mods, flags):
if not base.cr.chatAgent.verifyMessage(chat):
return
if base.localAvatar.isIgnored(self.doId if fromAV == 0 else fromAV):
return
timestamp = time.strftime('%m-%d-%Y %H:%M:%S', time.localtime())
@ -480,6 +482,8 @@ class DistributedToon(DistributedPlayer.DistributedPlayer, Toon.Toon, Distribute
return base.cr.isFriend(avId)
def setTalkWhisper(self, fromAV, fromAC, avatarName, chat, mods, flags):
if not base.cr.chatAgent.verifyMessage(chat):
return
if not localAvatar.acceptingNonFriendWhispers:
if not self.isAvFriend(fromAV):
return