Poodletooth-iLand/otp/ai/BanManagerAI.py

147 lines
4.3 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from direct.directnotify import DirectNotifyGlobal
2015-06-05 17:39:18 -05:00
from toontown.uberdog.ClientServicesManagerUD import executeHttpRequest
2015-03-03 16:10:12 -06:00
import datetime
from direct.fsm.FSM import FSM
from direct.distributed.PyDatagram import PyDatagram
from direct.distributed.MsgTypes import *
from otp.ai.MagicWordGlobal import *
from direct.showbase.DirectObject import DirectObject
2015-06-05 17:39:18 -05:00
2015-03-03 16:10:12 -06:00
class BanFSM(FSM):
2015-06-05 17:39:18 -05:00
def __init__(self, air, avId, comment, duration):
2015-03-03 16:10:12 -06:00
FSM.__init__(self, 'banFSM-%s' % avId)
self.air = air
self.avId = avId
2015-06-05 17:39:18 -05:00
# Needed variables for the actual banning.
2015-03-03 16:10:12 -06:00
self.comment = comment
self.duration = duration
self.DISLid = None
self.accountId = None
self.avName = None
def performBan(self, bannedUntil):
2015-06-05 17:39:18 -05:00
executeHttpRequest('accounts/ban/', Id=self.accountId, Release=bannedUntil,
Reason=self.comment)
2015-03-03 16:10:12 -06:00
def ejectPlayer(self):
av = self.air.doId2do.get(self.avId)
if not av:
return
2015-06-05 17:39:18 -05:00
# Send the client a 'CLIENTAGENT_EJECT' with the players name.
2015-03-03 16:10:12 -06:00
datagram = PyDatagram()
datagram.addServerHeader(
av.GetPuppetConnectionChannel(self.avId),
self.air.ourChannel, CLIENTAGENT_EJECT)
2015-06-05 17:39:18 -05:00
datagram.addUint16(152)
datagram.addString(self.avName)
2015-03-03 16:10:12 -06:00
simbase.air.send(datagram)
def dbCallback(self, dclass, fields):
if dclass != self.air.dclassesByName['AccountAI']:
return
self.accountId = fields.get('ACCOUNT_ID')
2015-06-05 17:39:18 -05:00
if not self.accountId:
return
date = datetime.date.today()
if simbase.config.GetBool('want-bans', True):
if self.duration == 0:
bannedUntil = "0000-00-00" # Terminated.
else:
bannedUntil = date + datetime.timedelta(days=self.duration)
self.duration = None
self.performBan(bannedUntil)
2015-03-03 16:10:12 -06:00
def getAvatarDetails(self):
av = self.air.doId2do.get(self.avId)
if not av:
return
self.DISLid = av.getDISLid()
self.avName = av.getName()
def log(self):
2015-06-05 17:39:18 -05:00
simbase.air.writeServerEvent('ban', self.accountId, self.comment)
2015-03-03 16:10:12 -06:00
def cleanup(self):
self.air = None
self.avId = None
2015-06-05 17:39:18 -05:00
2015-03-03 16:10:12 -06:00
self.DISLid = None
self.avName = None
self.accountId = None
self.comment = None
self.duration = None
self = None
def enterStart(self):
self.getAvatarDetails()
2015-06-05 17:39:18 -05:00
self.air.dbInterface.queryObject(self.air.dbId, self.DISLid,
self.dbCallback)
2015-03-03 16:10:12 -06:00
self.ejectPlayer()
def exitStart(self):
self.log()
self.cleanup()
def enterOff(self):
pass
def exitOff(self):
pass
class BanManagerAI(DirectObject):
notify = DirectNotifyGlobal.directNotify.newCategory('BanManagerAI')
def __init__(self, air):
self.air = air
self.banFSMs = {}
2015-06-05 17:39:18 -05:00
def ban(self, avId, duration, comment):
self.banFSMs[avId] = BanFSM(self.air, avId, comment, duration)
2015-03-03 16:10:12 -06:00
self.banFSMs[avId].request('Start')
self.acceptOnce(self.air.getAvatarExitEvent(avId), self.banDone, [avId])
def banDone(self, avId):
self.banFSMs[avId].request('Off')
self.banFSMs[avId] = None
@magicWord(category=CATEGORY_MODERATOR, types=[str])
2015-06-05 17:39:18 -05:00
def kick(reason='No reason specified'):
2015-03-03 16:10:12 -06:00
"""
Kick the target from the game server.
"""
target = spellbook.getTarget()
datagram = PyDatagram()
datagram.addServerHeader(
target.GetPuppetConnectionChannel(target.doId),
simbase.air.ourChannel, CLIENTAGENT_EJECT)
2015-06-05 17:39:18 -05:00
datagram.addUint16(155)
datagram.addString('You were kicked by a moderator for the following reason: %s' % reason)
2015-03-03 16:10:12 -06:00
simbase.air.send(datagram)
return "Kicked %s from the game server!" % target.getName()
@magicWord(category=CATEGORY_MODERATOR, types=[str, int])
def ban(reason, duration):
"""
Ban the target from the game server.
"""
target = spellbook.getTarget()
2015-06-05 17:39:18 -05:00
if target == spellbook.getInvoker():
2015-03-03 16:10:12 -06:00
return "You can't ban yourself!"
2015-06-05 17:39:18 -05:00
if reason not in ('hacking', 'language', 'other'):
return "'%s' is not a valid reason." % reason
simbase.air.banManager.ban(target.doId, duration, reason)
2015-04-05 13:07:59 -05:00
return "Banned %s from the game server!" % target.getName()