Made it not crash uberdog lel

This commit is contained in:
Loudrob 2015-04-01 07:39:59 -04:00
parent d251898a11
commit 72b6ef5afd
6 changed files with 119 additions and 44 deletions

View file

@ -43,9 +43,9 @@ def chatmode(mode=-1):
return "You are currently talking in the %s chat mode." % mode2name.get(base.cr.chatAgent.chatMode, "N/A")
if not 0 <= mode <= 3:
return "Invalid chat mode specified."
if mode == 3 and spellbook.getInvoker().getAdminAccess() < 500:
if mode == 3 and spellbook.getInvoker().getAdminAccess() < 600:
return "Chat mode 3 is reserved for system administrators."
if mode == 2 and spellbook.getInvoker().getAdminAccess() < 400:
if mode == 2 and spellbook.getInvoker().getAdminAccess() < 500:
return "Chat mode 2 is reserved for administrators."
if mode == 1 and spellbook.getInvoker().getAdminAccess() < 200:
# Like this will ever happen, but whatever.

View file

@ -27,17 +27,7 @@ class ChatAgentUD(DistributedObjectGlobalUD):
2 : "[ADMIN] ",
3 : "[SYSADMIN] ",
}
self.muted = {}
def muteAccount(self, account, howLong):
print ['muteAccount', account, howLong]
self.muted[account] = int(time.time()/60) + howLong
def unmuteAccount(self, account):
print ['unmuteAccount', account]
if account in self.muted:
del self.muted[account]
# Open chat
def chatMessage(self, message, chatMode):
sender = self.air.getAvatarIdFromSender()
@ -46,9 +36,6 @@ class ChatAgentUD(DistributedObjectGlobalUD):
issue='Account sent chat without an avatar', message=message)
return
if sender in self.muted and int(time.time()/60) < self.muted[sender]:
return
if self.wantWhitelist:
cleanMessage, modifications = self.cleanWhitelist(message)
else:

View file

@ -4,6 +4,10 @@ from direct.fsm import State
from direct.gui.DirectGui import *
from direct.showbase import DirectObject
from pandac.PandaModules import *
from otp.login import LeaveToPayDialog
from otp.login import PrivacyPolicyPanel
from otp.login import SecretFriendsInfoPanel
from otp.otpbase import OTPLocalizer
from toontown.chat.ChatGlobals import *
@ -45,13 +49,17 @@ class ChatManager(DirectObject.DirectObject):
self.__normalObscured = 0
self.openChatWarning = None
self.unpaidChatWarning = None
self.teaser = None
self.paidNoParentPassword = None
self.noSecretChatAtAll = None
self.noSecretChatAtAllAndNoWhitelist = None
self.noSecretChatWarning = None
self.activateChatGui = None
self.chatMoreInfo = None
self.chatPrivacyPolicy = None
self.secretChatActivated = None
self.problemActivatingChat = None
self.leaveToPayDialog = None
self.fsm = ClassicFSM.ClassicFSM('chatManager', [State.State('off', self.enterOff, self.exitOff),
State.State('mainMenu', self.enterMainMenu, self.exitMainMenu),
State.State('speedChat', self.enterSpeedChat, self.exitSpeedChat),
@ -62,6 +70,7 @@ class ChatManager(DirectObject.DirectObject):
State.State('whisperSpeedChat', self.enterWhisperSpeedChat, self.exitWhisperSpeedChat),
State.State('whisperSpeedChatPlayer', self.enterWhisperSpeedChatPlayer, self.exitWhisperSpeedChatPlayer),
State.State('openChatWarning', self.enterOpenChatWarning, self.exitOpenChatWarning),
State.State('leaveToPayDialog', self.enterLeaveToPayDialog, self.exitLeaveToPayDialog),
State.State('unpaidChatWarning', self.enterUnpaidChatWarning, self.exitUnpaidChatWarning),
State.State('noSecretChatAtAll', self.enterNoSecretChatAtAll, self.exitNoSecretChatAtAll),
State.State('noSecretChatAtAllAndNoWhitelist', self.enterNoSecretChatAtAllAndNoWhitelist, self.exitNoSecretChatAtAllAndNoWhitelist),
@ -69,11 +78,14 @@ class ChatManager(DirectObject.DirectObject):
State.State('noFriendsWarning', self.enterNoFriendsWarning, self.exitNoFriendsWarning),
State.State('otherDialog', self.enterOtherDialog, self.exitOtherDialog),
State.State('activateChat', self.enterActivateChat, self.exitActivateChat),
State.State('chatMoreInfo', self.enterChatMoreInfo, self.exitChatMoreInfo),
State.State('chatPrivacyPolicy', self.enterChatPrivacyPolicy, self.exitChatPrivacyPolicy),
State.State('secretChatActivated', self.enterSecretChatActivated, self.exitSecretChatActivated),
State.State('problemActivatingChat', self.enterProblemActivatingChat, self.exitProblemActivatingChat),
State.State('whiteListOpenChat', self.enterWhiteListOpenChat, self.exitWhiteListOpenChat),
State.State('whiteListAvatarChat', self.enterWhiteListAvatarChat, self.exitWhiteListAvatarChat),
State.State('whiteListPlayerChat', self.enterWhiteListPlayerChat, self.exitWhiteListPlayerChat)], 'off', 'off')
State.State('whiteListPlayerChat', self.enterWhiteListPlayerChat, self.exitWhiteListPlayerChat),
State.State('trueFriendTeaserPanel', self.enterTrueFriendTeaserPanel, self.exitTrueFriendTeaserPanel)], 'off', 'off')
self.fsm.enterInitialState()
return
@ -93,6 +105,10 @@ class ChatManager(DirectObject.DirectObject):
self.payButton = None
self.unpaidChatWarning.destroy()
self.unpaidChatWarning = None
if self.teaser:
self.teaser.cleanup()
self.teaser.unload()
self.teaser = None
if self.noSecretChatAtAll:
self.noSecretChatAtAll.destroy()
self.noSecretChatAtAll = None
@ -105,6 +121,12 @@ class ChatManager(DirectObject.DirectObject):
if self.activateChatGui:
self.activateChatGui.destroy()
self.activateChatGui = None
if self.chatMoreInfo:
self.chatMoreInfo.destroy()
self.chatMoreInfo = None
if self.chatPrivacyPolicy:
self.chatPrivacyPolicy.destroy()
self.chatPrivacyPolicy = None
if self.secretChatActivated:
self.secretChatActivated.destroy()
self.secretChatActivated = None
@ -196,6 +218,8 @@ class ChatManager(DirectObject.DirectObject):
if self.wantBackgroundFocus:
self.chatInputNormal.chatEntry['backgroundFocus'] = 1
self.acceptOnce('enterNormalChat', self.fsm.request, ['normalChat'])
if not self.wantBackgroundFocus:
self.accept('t', messenger.send, ['enterNormalChat'])
def checkObscurred(self):
if not self.__scObscured:
@ -387,6 +411,19 @@ class ChatManager(DirectObject.DirectObject):
def exitOpenChatWarning(self):
self.notify.error('called exitOpenChatWarning() on parent class')
def enterLeaveToPayDialog(self):
if self.leaveToPayDialog == None:
self.leaveToPayDialog = LeaveToPayDialog.LeaveToPayDialog(self.paidNoParentPassword)
self.leaveToPayDialog.setCancel(self.__handleLeaveToPayCancel)
self.leaveToPayDialog.show()
return
def exitLeaveToPayDialog(self):
if self.leaveToPayDialog:
self.leaveToPayDialog.destroy()
self.leaveToPayDialog = None
return
def enterUnpaidChatWarning(self):
self.notify.error('called enterUnpaidChatWarning() on parent class')
@ -429,6 +466,30 @@ class ChatManager(DirectObject.DirectObject):
def exitOtherDialog(self):
pass
def enterChatMoreInfo(self):
if self.chatMoreInfo == None:
self.chatMoreInfo = SecretFriendsInfoPanel.SecretFriendsInfoPanel('secretFriendsInfoDone')
self.chatMoreInfo.show()
self.accept('secretFriendsInfoDone', self.__secretFriendsInfoDone)
return
def exitChatMoreInfo(self):
self.chatMoreInfo.hide()
self.ignore('secretFriendsInfoDone')
def enterChatPrivacyPolicy(self):
if self.chatPrivacyPolicy == None:
self.chatPrivacyPolicy = PrivacyPolicyPanel.PrivacyPolicyPanel('privacyPolicyDone')
self.chatPrivacyPolicy.show()
self.accept('privacyPolicyDone', self.__privacyPolicyDone)
return
def exitChatPrivacyPolicy(self):
cleanupDialog('privacyPolicyDialog')
self.chatPrivacyPolicy = None
self.ignore('privacyPolicyDone')
return
def enterSecretChatActivated(self):
self.notify.error('called enterSecretChatActivated() on parent class')
@ -439,4 +500,19 @@ class ChatManager(DirectObject.DirectObject):
self.notify.error('called enterProblemActivatingChat() on parent class')
def exitProblemActivatingChat(self):
self.notify.error('called exitProblemActivatingChat() on parent class')
self.notify.error('called exitProblemActivatingChat() on parent class')
def enterTrueFriendTeaserPanel(self):
self.notify.error('called enterTrueFriendTeaserPanel () on parent class')
def exitTrueFriendTeaserPanel(self):
self.notify.error('called exitTrueFriendTeaserPanel () on parent class')
def __handleLeaveToPayCancel(self):
self.fsm.request('mainMenu')
def __secretFriendsInfoDone(self):
self.fsm.request('activateChat')
def __privacyPolicyDone(self):
self.fsm.request('activateChat')

View file

@ -574,6 +574,10 @@ class TalkAssistant(DirectObject.DirectObject):
def sendOpenTalk(self, message):
error = None
doId = base.localAvatar.doId
try:
message.encode('ascii')
except UnicodeEncodeError:
return
if base.config.GetBool('want-talkative-tyler', False):
if base.localAvatar.zoneId == 2000:
tyler = base.cr.doFind('Talkative Tyler')
@ -606,7 +610,7 @@ class TalkAssistant(DirectObject.DirectObject):
message, scrubbed = base.localAvatar.scrubTalk(cleanMessage, modifications)
base.cr.ttuFriendsManager.sendUpdate('sendTalkWhisper', [receiverAvId, message])
base.cr.ttiFriendsManager.sendUpdate('sendTalkWhisper', [receiverAvId, message])
def sendAccountTalk(self, message, receiverAccount):
error = None
@ -667,8 +671,24 @@ class TalkAssistant(DirectObject.DirectObject):
return error
def sendPlayerWhisperSpeedChat(self, type, messageIndex, receiverId):
# TODO: Remove Player system
return None
error = None
if type == SPEEDCHAT_NORMAL:
base.cr.speedchatRelay.sendSpeedchat(receiverId, messageIndex)
message = self.SCDecoder.decodeSCStaticTextMsg(messageIndex)
elif type == SPEEDCHAT_EMOTE:
base.cr.speedchatRelay.sendSpeedchatEmote(receiverId, messageIndex)
message = self.SCDecoder.decodeSCEmoteWhisperMsg(messageIndex, localAvatar.getName())
return
elif type == SPEEDCHAT_CUSTOM:
base.cr.speedchatRelay.sendSpeedchatCustom(receiverId, messageIndex)
message = self.SCDecoder.decodeSCCustomMsg(messageIndex)
if self.logWhispers:
receiverName = self.findName(receiverId, 1)
newMessage = TalkMessage(self.countMessage(), self.stampTime(), message, localAvatar.doId, localAvatar.getName(), localAvatar.DISLid, localAvatar.DISLname, None, None, receiverId, receiverName, TALK_ACCOUNT, None)
self.historyComplete.append(newMessage)
self.addToHistoryDoId(newMessage, localAvatar.doId)
messenger.send('NewOpenMessage', [newMessage])
return error
def sendGuildSpeedChat(self, type, msgIndex):
error = None

View file

@ -1,41 +1,27 @@
from bisect import bisect_left
import string
import sys
import os
class WhiteList:
def __init__(self, wordlist):
self.words = []
for line in wordlist:
self.words.append(line.strip('\n\r').lower())
self.words.sort()
def __init__(self, words):
self.words = words
self.numWords = len(self.words)
def cleanText(self, text):
text = text.strip('.,?!')
text = text.lower()
return text
return text.lower()
def isWord(self, text):
try:
text = self.cleanText(text)
i = bisect_left(self.words, text)
if i == self.numWords:
return False
return self.words[i] == text
except UnicodeDecodeError:
return False # Lets not open ourselves up to obscure keyboards...
return self.cleanText(text) in self.words
def isPrefix(self, text):
text = self.cleanText(text)
i = bisect_left(self.words, text)
if i == self.numWords:
return False
return self.words[i].startswith(text)
return self.words[i].startswith(text)
def prefixCount(self, text):
text = self.cleanText(text)
i = bisect_left(self.words, text)
@ -52,4 +38,4 @@ class WhiteList:
while j < self.numWords and self.words[j].startswith(text):
j += 1
return self.words[i:j]
return self.words[i:j]

View file

@ -101,6 +101,12 @@ class AccountDB:
def lookup(self, username, callback):
pass # Inheritors should override this.
def persistMessage(self, category, description, sender, receiver):
print ['persistMessage', category, description, sender, receiver]
def persistChat(self, sender, message, channel):
pass
def storeAccountID(self, userId, accountId, callback):
self.dbm[str(userId)] = str(accountId) # anydbm only allows strings.
if getattr(self.dbm, 'sync', None):