sequence asslist and chathoes

This commit is contained in:
Loudrob 2015-04-02 08:23:24 -04:00
parent c8f5d19c11
commit 233dbd4ba9
12 changed files with 255 additions and 33 deletions

3
.gitignore vendored
View file

@ -22,4 +22,5 @@ screenshots/
backups/
contentpacks/
resources/
save.dat
save.dat
ai-crash.txt

View file

@ -255,8 +255,10 @@ dclass MagicWordManager : DistributedObject {
};
dclass ChatAgent : DistributedObject {
adminChat(uint32, string);
chatMessage(string(0-256)) clsend;
adminChat(uint32 aboutId, string message);
chatMessage(string(0-256) message, uint8 chatMode) clsend;
whisperMessage(uint32 receiverAvId, string(0-256) message) clsend;
sfWhisperMessage(uint32 receiverAvId, string(0-256) message) clsend;
};
dclass FriendManager : DistributedObject {

View file

@ -1,14 +1,17 @@
from direct.distributed.DistributedObjectGlobal import DistributedObjectGlobal
from pandac.PandaModules import *
from otp.otpbase import OTPGlobals
from otp.ai.MagicWordGlobal import *
class ChatAgent(DistributedObjectGlobal):
def __init__(self, cr):
DistributedObjectGlobal.__init__(self, cr)
self.chatMode = 0
def delete(self):
self.ignoreAll()
self.cr.chatManager = None
self.cr.chatAgent = None
DistributedObjectGlobal.delete(self)
return
@ -17,4 +20,36 @@ class ChatAgent(DistributedObjectGlobal):
messenger.send('adminChat', [aboutId, message])
def sendChatMessage(self, message):
self.sendUpdate('chatMessage', [message])
self.sendUpdate('chatMessage', [message, self.chatMode])
def sendWhisperMessage(self, receiverAvId, message):
self.sendUpdate('whisperMessage', [receiverAvId, message])
def sendSFWhisperMessage(self, receiverAvId, message):
self.sendUpdate('sfWhisperMessage', [receiverAvId, message])
@magicWord(category=CATEGORY_MODERATOR, types=[int])
def chatmode(mode=-1):
""" Set the chat mode of the current avatar. """
mode2name = {
0 : "user",
1 : "moderator",
2 : "administrator",
3 : "system administrator",
}
if base.cr.chatAgent is None:
return "No ChatAgent found."
if 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:
return "Chat mode 3 is reserved for system administrators."
if mode == 2 and spellbook.getInvoker().getAdminAccess() < 400:
return "Chat mode 2 is reserved for administrators."
if mode == 1 and spellbook.getInvoker().getAdminAccess() < 200:
# 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")

View file

@ -2,41 +2,138 @@ from direct.directnotify import DirectNotifyGlobal
from direct.distributed.DistributedObjectGlobalUD import DistributedObjectGlobalUD
# TODO: OTP should not depend on Toontown... Hrrm.
from toontown.chat.TTWhiteList import TTWhiteList
from toontown.chat.TTSequenceList import TTSequenceList
from otp.distributed import OtpDoGlobals
class ChatAgentUD(DistributedObjectGlobalUD):
notify = DirectNotifyGlobal.directNotify.newCategory("ChatAgentUD")
def announceGenerate(self):
DistributedObjectGlobalUD.announceGenerate(self)
self.whiteList = TTWhiteList()
def chatMessage(self, message):
self.wantBlacklistSequence = config.GetBool('want-blacklist-sequence', True)
self.wantWhitelist = config.GetBool('want-whitelist', True)
if self.wantWhitelist:
self.whiteList = TTWhiteList()
if self.wantBlacklistSequence:
self.sequenceList = TTSequenceList()
self.chatMode2channel = {
1 : OtpDoGlobals.OTP_MOD_CHANNEL,
2 : OtpDoGlobals.OTP_ADMIN_CHANNEL,
3 : OtpDoGlobals.OTP_SYSADMIN_CHANNEL,
}
self.chatMode2prefix = {
1 : "[MOD] ",
2 : "[ADMIN] ",
3 : "[SYSADMIN] ",
}
# Open chat
def chatMessage(self, message, chatMode):
sender = self.air.getAvatarIdFromSender()
if sender == 0:
self.air.writeServerEvent('suspicious', self.air.getAccountIdFromSender(),
'Account sent chat without an avatar', message)
self.air.writeServerEvent('suspicious', accId=self.air.getAccountIdFromSender(),
issue='Account sent chat without an avatar', message=message)
return
if self.wantWhitelist:
cleanMessage, modifications = self.cleanWhitelist(message)
else:
cleanMessage, modifications = message, []
self.air.writeServerEvent('chat-said', avId=sender, chatMode=chatMode, msg=message, cleanMsg=cleanMessage)
# TODO: The above is probably a little too ugly for my taste... Maybe AIR
# should be given an API for sending updates for unknown objects?
if chatMode != 0:
# Staff messages do not need to be cleaned. [TODO: Blacklist this?]
if message.startswith('.'):
# This is a thought bubble, move the point to the start.
cleanMessage = '.' + self.chatMode2prefix.get(chatMode, "") + message[1:]
else:
cleanMessage = self.chatMode2prefix.get(chatMode, "") + message
modifications = []
DistributedAvatar = self.air.dclassesByName['DistributedAvatarUD']
dg = DistributedAvatar.aiFormatUpdate('setTalk', sender, self.chatMode2channel.get(chatMode, sender),
self.air.ourChannel,
[0, 0, '', cleanMessage, modifications, 0])
self.air.send(dg)
# Regular filtered chat
def whisperMessage(self, receiverAvId, message):
sender = self.air.getAvatarIdFromSender()
if sender == 0:
self.air.writeServerEvent('suspicious', accId=self.air.getAccountIdFromSender(),
issue='Account sent chat without an avatar', message=message)
return
cleanMessage, modifications = self.cleanWhitelist(message)
# Maybe a better "cleaner" way of doing this, but it works
self.air.writeServerEvent('whisper-said', avId=sender, reciever=receiverAvId, msg=message, cleanMsg=cleanMessage)
DistributedAvatar = self.air.dclassesByName['DistributedAvatarUD']
dg = DistributedAvatar.aiFormatUpdate('setTalkWhisper', receiverAvId, receiverAvId, self.air.ourChannel,
[sender, sender, '', cleanMessage, modifications, 0])
self.air.send(dg)
# True friend unfiltered chat
def sfWhisperMessage(self, receiverAvId, message):
sender = self.air.getAvatarIdFromSender()
if sender == 0:
self.air.writeServerEvent('suspicious', accId=self.air.getAccountIdFromSender(),
issue='Account sent chat without an avatar', message=message)
return
cleanMessage = self.cleanBlacklist(message)
self.air.writeServerEvent('sf-whisper-said', avId=sender, reciever=receiverAvId, msg=message, cleanMsg=cleanMessage)
DistributedAvatar = self.air.dclassesByName['DistributedAvatarUD']
dg = DistributedAvatar.aiFormatUpdate('setTalkWhisper', receiverAvId, receiverAvId, self.air.ourChannel,
[sender, sender, '', cleanMessage, [], 0])
self.air.send(dg)
# Filter the chat message
def cleanWhitelist(self, message):
modifications = []
words = message.split(' ')
offset = 0
WantWhitelist = config.GetBool('want-whitelist', 1)
for word in words:
if word and not self.whiteList.isWord(word) and WantWhitelist:
if word and not self.whiteList.isWord(word):
modifications.append((offset, offset+len(word)-1))
offset += len(word) + 1
cleanMessage = message
if self.wantBlacklistSequence:
modifications += self.cleanSequences(cleanMessage)
for modStart, modStop in modifications:
cleanMessage = cleanMessage[:modStart] + '*'*(modStop-modStart+1) + cleanMessage[modStop+1:]
# Traverse through modification list and replace the characters of non-whitelisted words and/or blacklisted sequences with asterisks.
cleanMessage = cleanMessage[:modStart] + '*' * (modStop - modStart + 1) + cleanMessage[modStop + 1:]
return (cleanMessage, modifications)
# Check the black list for black-listed words
def cleanBlacklist(self, message):
# We don't have a black list so we just return the full message
return message
# Check for black-listed word sequences and scrub accordingly.
def cleanSequences(self, message):
modifications = []
offset = 0
words = message.split()
for wordit in xrange(len(words)):
word = words[wordit].lower()
seqlist = self.sequenceList.getList(word)
if len(seqlist) > 0:
for seqit in xrange(len(seqlist)):
sequence = seqlist[seqit]
splitseq = sequence.split()
if len(words) - (wordit + 1) >= len(splitseq):
cmplist = words[wordit + 1:]
del cmplist[len(splitseq):]
cmplist = [word.lower() for word in cmplist]
if cmp(cmplist, splitseq) == 0:
modifications.append((offset, offset + len(word) + len(sequence) - 1))
offset += len(word) + 1
return modifications
self.air.writeServerEvent('chat-said', sender, message, cleanMessage)
# TODO: The above is probably a little too ugly for my taste... Maybe AIR
# should be given an API for sending updates for unknown objects?
DistributedAvatar = self.air.dclassesByName['DistributedAvatarUD']
dg = DistributedAvatar.aiFormatUpdate('setTalk', sender, sender,
self.air.ourChannel,
[0, 0, '', cleanMessage, modifications, 0])
self.air.send(dg)

15
otp/chat/SequenceList.py Normal file
View file

@ -0,0 +1,15 @@
class SequenceList:
def __init__(self, wordlist):
self.list = {}
for line in wordlist:
if line is '':
continue
split = line.split(':')
self.list[split[0].lower()] = [word.rstrip('\r\n').lower() for word in split[1].split(',')]
def getList(self, word):
if word in self.list:
return self.list[word]
else:
return []

View file

@ -19,4 +19,22 @@ class WhiteList:
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)
j = i
while j < self.numWords and self.words[j].startswith(text):
j += 1
return j - i
def prefixList(self, text):
text = self.cleanText(text)
i = bisect_left(self.words, text)
j = i
while j < self.numWords and self.words[j].startswith(text):
j += 1
return self.words[i:j]

View file

@ -2,7 +2,7 @@
from pandac.PandaModules import *
hashVal = 598642574
hashVal = 4270694562L
from toontown.coghq import DistributedCashbotBossSafe, DistributedCashbotBossCrane, DistributedBattleFactory, DistributedCashbotBossTreasure, DistributedCogHQDoor, DistributedSellbotHQDoor, DistributedFactoryElevatorExt, DistributedMintElevatorExt, DistributedLawOfficeElevatorExt, DistributedLawOfficeElevatorInt, LobbyManager, DistributedMegaCorp, DistributedFactory, DistributedLawOffice, DistributedLawOfficeFloor, DistributedLift, DistributedDoorEntity, DistributedSwitch, DistributedButton, DistributedTrigger, DistributedCrushableEntity, DistributedCrusherEntity, DistributedStomper, DistributedStomperPair, DistributedLaserField, DistributedGolfGreenGame, DistributedSecurityCamera, DistributedMover, DistributedElevatorMarker, DistributedBarrelBase, DistributedGagBarrel, DistributedBeanBarrel, DistributedHealBarrel, DistributedGrid, ActiveCell, DirectionalCell, CrusherCell, DistributedCrate, DistributedSinkingPlatform, BattleBlocker, DistributedMint, DistributedMintRoom, DistributedMintBattle, DistributedStage, DistributedStageRoom, DistributedStageBattle, DistributedLawbotBossGavel, DistributedLawbotCannon, DistributedLawbotChair, DistributedCogKart, DistributedCountryClub, DistributedCountryClubRoom, DistributedMoleField, DistributedCountryClubBattle, DistributedMaze, DistributedFoodBelt, DistributedBanquetTable, DistributedGolfSpot

View file

@ -88,4 +88,7 @@ OTP_ZONE_ID_DISTRICTS = 3
OTP_ZONE_ID_DISTRICTS_STATS = 4
OTP_ZONE_ID_ELEMENTS = 5
OTP_NET_MESSENGER_CHANNEL = (OTP_DO_ID_UBER_DOG << 32) + OTP_ZONE_ID_MANAGEMENT
OTP_STAFF_CHANNEL = 6200
OTP_MOD_CHANNEL = 6200
OTP_ADMIN_CHANNEL = 6400
OTP_SYSADMIN_CHANNEL = 6500

View file

@ -54,5 +54,7 @@ except SystemExit:
raise
except Exception:
info = PythonUtil.describeException()
simbase.air.writeServerEvent('ai-exception', simbase.air.getAvatarIdFromSender(), simbase.air.getAccountIdFromSender(), info)
simbase.air.writeServerEvent('ai-exception', avId=simbase.air.getAvatarIdFromSender(), accId=simbase.air.getAccountIdFromSender(), exception=info)
with open(config.GetString('ai-crash-log-name', 'ai-crash.txt'), 'w+') as file:
file.write(info + "\n")
raise

View file

@ -0,0 +1,36 @@
from pandac.PandaModules import *
from otp.chat.SequenceList import SequenceList
from direct.directnotify import DirectNotifyGlobal
class TTSequenceList(SequenceList):
def __init__(self):
self.notify = DirectNotifyGlobal.directNotify.newCategory('TTSequenceList')
sequenceListURL = config.GetString('blacklist-sequence-url', '')
if sequenceListURL == '':
self.notify.warning('No Sequence BL URL specified! Continuing with local sequence.')
SequenceList.__init__(self, self.loadSquencesLocally())
else:
SequenceList.__init__(self, self.downloadSequences(sequenceListURL))
def downloadSequences(self, url):
fs = Ramfile()
http = HTTPClient.getGlobalPtr()
self.ch = http.makeChannel(True)
self.ch.getHeader(DocumentSpec(url))
doc = self.ch.getDocumentSpec()
self.ch.getDocument(doc)
self.ch.downloadToRam(fs)
return fs.getData().split('\r\n')
def loadSquencesLocally(self):
vfs = VirtualFileSystem.getGlobalPtr()
filename = Filename('tsequence.dat')
searchPath = DSearchPath()
searchPath.appendDirectory(Filename('/server'))
found = vfs.resolveFilename(filename, searchPath)
if not found:
self.notify.warning("Couldn't find blacklist sequence data file!")
return
data = vfs.readFile(filename, True)
return data.split('\n')

View file

@ -178,7 +178,7 @@ HoodHierarchy = {ToontownCentral: (SillyStreet, LoopyLane, PunchlinePlace),
TheBrrrgh: (WalrusWay, SleetStreet, PolarPlace),
MinniesMelodyland: (AltoAvenue, BaritoneBoulevard, TenorTerrace),
DaisyGardens: (ElmStreet, MapleStreet, OakStreet),
DonaldsDreamland: (LullabyLane, PajamaPlace, RockAByeRoad),
DonaldsDreamland: (LullabyLane, PajamaPlace),
GoofySpeedway: ()}
WelcomeValleyToken = 0
BossbotHQ = 10000

View file

@ -422,13 +422,26 @@ class LoginAccountFSM(OperationFSM):
datagram.addChannel(self.csm.GetAccountConnectionChannel(self.accountId))
self.csm.air.send(datagram)
# Add this connection to extra channels which may be useful:
if self.accessLevel > 100:
datagram = PyDatagram()
datagram.addServerHeader(self.target, self.csm.air.ourChannel,
CLIENTAGENT_OPEN_CHANNEL)
datagram.addChannel(OtpDoGlobals.OTP_STAFF_CHANNEL)
self.csm.air.send(datagram)
# Subscribe to any "staff" channels that the account has access to.
access = self.account.get('ADMIN_ACCESS', 0)
if access >= 200:
# Subscribe to the moderator channel.
dg = PyDatagram()
dg.addServerHeader(self.target, self.csm.air.ourChannel, CLIENTAGENT_OPEN_CHANNEL)
dg.addChannel(OtpDoGlobals.OTP_MOD_CHANNEL)
self.csm.air.send(dg)
if access >= 400:
# Subscribe to the administrator channel.
dg = PyDatagram()
dg.addServerHeader(self.target, self.csm.air.ourChannel, CLIENTAGENT_OPEN_CHANNEL)
dg.addChannel(OtpDoGlobals.OTP_ADMIN_CHANNEL)
self.csm.air.send(dg)
if access >= 500:
# Subscribe to the system administrator channel.
dg = PyDatagram()
dg.addServerHeader(self.target, self.csm.air.ourChannel, CLIENTAGENT_OPEN_CHANNEL)
dg.addChannel(OtpDoGlobals.OTP_SYSADMIN_CHANNEL)
self.csm.air.send(dg)
# Now set their sender channel to represent their account affiliation:
datagram = PyDatagram()