Poodletooth-iLand/otp/ai/BanManagerAI.py

136 lines
4.1 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from direct.directnotify import DirectNotifyGlobal
2015-04-05 10:28:08 -05:00
from toontown.uberdog.ClientServicesManagerUD import executeHttpRequestAndLog
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
class BanFSM(FSM):
2015-04-05 10:28:08 -05:00
def __init__(self, air, invokerId, avId, comment, duration):
2015-03-03 16:10:12 -06:00
FSM.__init__(self, 'banFSM-%s' % avId)
self.air = air
2015-04-05 10:28:08 -05:00
self.invokerId = invokerId
2015-03-03 16:10:12 -06:00
self.avId = avId
self.comment = comment
self.duration = duration
self.DISLid = None
self.accountId = None
self.avName = None
def performBan(self, bannedUntil):
2015-04-05 10:28:08 -05:00
executeHttpRequestAndLog('ban', username=self.accountId, enddate=bannedUntil, comment=self.comment)
2015-03-03 16:10:12 -06:00
def ejectPlayer(self):
av = self.air.doId2do.get(self.avId)
2015-04-05 10:28:08 -05:00
2015-03-03 16:10:12 -06:00
if not av:
return
datagram = PyDatagram()
datagram.addServerHeader(
av.GetPuppetConnectionChannel(self.avId),
self.air.ourChannel, CLIENTAGENT_EJECT)
datagram.addUint16(103)
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-04-05 10:28:08 -05:00
if self.accountId:
2015-04-05 13:07:59 -05:00
self.performBan(0 if self.duration < 0 else datetime.datetime.now() + (self.duration * 3600000))
2015-03-03 16:10:12 -06:00
def getAvatarDetails(self):
av = self.air.doId2do.get(self.avId)
2015-04-05 10:28:08 -05:00
2015-03-03 16:10:12 -06:00
if not av:
return
self.DISLid = av.getDISLid()
self.avName = av.getName()
def log(self):
2015-04-05 10:28:08 -05:00
simbase.air.writeServerEvent('ban', self.invokerId, self.accountId, self.comment)
2015-03-03 16:10:12 -06:00
def cleanup(self):
self.air = None
self.avId = None
self.DISLid = None
self.avName = None
2015-04-05 10:28:08 -05:00
self.invokerId = None
2015-03-03 16:10:12 -06:00
self.accountId = None
self.comment = None
self.duration = None
self = None
def enterStart(self):
self.getAvatarDetails()
2015-04-05 10:28:08 -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-04-05 10:28:08 -05:00
def ban(self, invokerId, avId, duration, comment):
self.banFSMs[avId] = BanFSM(self.air, invokerId, 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])
def kick(reason):
"""
Kick the target from the game server.
"""
target = spellbook.getTarget()
2015-04-05 10:28:08 -05:00
invoker = spellbook.getInvoker()
if target == invoker:
2015-03-03 16:10:12 -06:00
return "You can't kick yourself!"
datagram = PyDatagram()
datagram.addServerHeader(
target.GetPuppetConnectionChannel(target.doId),
simbase.air.ourChannel, CLIENTAGENT_EJECT)
datagram.addUint16(104)
2015-03-03 16:10:12 -06:00
datagram.addString('You were kicked by a moderator for the following reason: "%s"\n\nBehave next time!' % reason)
simbase.air.send(datagram)
2015-04-05 10:28:08 -05:00
simbase.air.writeServerEvent('kick', invoker.doId, target.doId, reason)
2015-03-03 16:10:12 -06:00
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-04-05 10:28:08 -05:00
invoker = spellbook.getInvoker()
if target == invoker:
2015-03-03 16:10:12 -06:00
return "You can't ban yourself!"
2015-04-05 10:28:08 -05:00
simbase.air.banManager.ban(invoker.doId, target.doId, duration, reason)
2015-04-05 13:07:59 -05:00
return "Banned %s from the game server!" % target.getName()