Add banning with new login system

This commit is contained in:
DenialMC 2015-04-05 18:28:08 +03:00
parent 5539bf7ca9
commit f1f427a3e8
3 changed files with 24 additions and 44 deletions

View file

@ -1,5 +1,5 @@
from direct.directnotify import DirectNotifyGlobal from direct.directnotify import DirectNotifyGlobal
from toontown.uberdog.ClientServicesManagerUD import executeHttpRequest from toontown.uberdog.ClientServicesManagerUD import executeHttpRequestAndLog
import datetime import datetime
from direct.fsm.FSM import FSM from direct.fsm.FSM import FSM
from direct.distributed.PyDatagram import PyDatagram from direct.distributed.PyDatagram import PyDatagram
@ -7,15 +7,13 @@ from direct.distributed.MsgTypes import *
from otp.ai.MagicWordGlobal import * from otp.ai.MagicWordGlobal import *
from direct.showbase.DirectObject import DirectObject from direct.showbase.DirectObject import DirectObject
class BanFSM(FSM): class BanFSM(FSM):
def __init__(self, air, avId, comment, duration): def __init__(self, air, invokerId, avId, comment, duration):
FSM.__init__(self, 'banFSM-%s' % avId) FSM.__init__(self, 'banFSM-%s' % avId)
self.air = air self.air = air
self.invokerId = invokerId
self.avId = avId self.avId = avId
# Needed variables for the actual banning.
self.comment = comment self.comment = comment
self.duration = duration self.duration = duration
self.DISLid = None self.DISLid = None
@ -23,15 +21,14 @@ class BanFSM(FSM):
self.avName = None self.avName = None
def performBan(self, bannedUntil): def performBan(self, bannedUntil):
executeHttpRequest('accounts/ban/', Id=self.accountId, Release=bannedUntil, executeHttpRequestAndLog('ban', username=self.accountId, enddate=bannedUntil, comment=self.comment)
Reason=self.comment)
def ejectPlayer(self): def ejectPlayer(self):
av = self.air.doId2do.get(self.avId) av = self.air.doId2do.get(self.avId)
if not av: if not av:
return return
# Send the client a 'CLIENTAGENT_EJECT' with the players name.
datagram = PyDatagram() datagram = PyDatagram()
datagram.addServerHeader( datagram.addServerHeader(
av.GetPuppetConnectionChannel(self.avId), av.GetPuppetConnectionChannel(self.avId),
@ -46,21 +43,12 @@ class BanFSM(FSM):
self.accountId = fields.get('ACCOUNT_ID') self.accountId = fields.get('ACCOUNT_ID')
if not self.accountId: if self.accountId:
return self.performBan(0 if self.duration < 0 else datetime.date.now() + (self.duration * 3600000))
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)
def getAvatarDetails(self): def getAvatarDetails(self):
av = self.air.doId2do.get(self.avId) av = self.air.doId2do.get(self.avId)
if not av: if not av:
return return
@ -68,14 +56,14 @@ class BanFSM(FSM):
self.avName = av.getName() self.avName = av.getName()
def log(self): def log(self):
simbase.air.writeServerEvent('ban', self.accountId, self.comment) simbase.air.writeServerEvent('ban', self.invokerId, self.accountId, self.comment)
def cleanup(self): def cleanup(self):
self.air = None self.air = None
self.avId = None self.avId = None
self.DISLid = None self.DISLid = None
self.avName = None self.avName = None
self.invokerId = None
self.accountId = None self.accountId = None
self.comment = None self.comment = None
self.duration = None self.duration = None
@ -83,8 +71,7 @@ class BanFSM(FSM):
def enterStart(self): def enterStart(self):
self.getAvatarDetails() self.getAvatarDetails()
self.air.dbInterface.queryObject(self.air.dbId, self.DISLid, self.air.dbInterface.queryObject(self.air.dbId, self.DISLid, self.dbCallback)
self.dbCallback)
self.ejectPlayer() self.ejectPlayer()
def exitStart(self): def exitStart(self):
@ -105,8 +92,8 @@ class BanManagerAI(DirectObject):
self.air = air self.air = air
self.banFSMs = {} self.banFSMs = {}
def ban(self, avId, duration, comment): def ban(self, invokerId, avId, duration, comment):
self.banFSMs[avId] = BanFSM(self.air, avId, comment, duration) self.banFSMs[avId] = BanFSM(self.air, invokerId, avId, comment, duration)
self.banFSMs[avId].request('Start') self.banFSMs[avId].request('Start')
self.acceptOnce(self.air.getAvatarExitEvent(avId), self.banDone, [avId]) self.acceptOnce(self.air.getAvatarExitEvent(avId), self.banDone, [avId])
@ -122,7 +109,8 @@ def kick(reason):
Kick the target from the game server. Kick the target from the game server.
""" """
target = spellbook.getTarget() target = spellbook.getTarget()
if target == spellbook.getInvoker(): invoker = spellbook.getInvoker()
if target == invoker:
return "You can't kick yourself!" return "You can't kick yourself!"
datagram = PyDatagram() datagram = PyDatagram()
datagram.addServerHeader( datagram.addServerHeader(
@ -131,6 +119,7 @@ def kick(reason):
datagram.addUint16(155) datagram.addUint16(155)
datagram.addString('You were kicked by a moderator for the following reason: "%s"\n\nBehave next time!' % reason) datagram.addString('You were kicked by a moderator for the following reason: "%s"\n\nBehave next time!' % reason)
simbase.air.send(datagram) simbase.air.send(datagram)
simbase.air.writeServerEvent('kick', invoker.doId, target.doId, reason)
return "Kicked %s from the game server!" % target.getName() return "Kicked %s from the game server!" % target.getName()
@ -140,10 +129,8 @@ def ban(reason, duration):
Ban the target from the game server. Ban the target from the game server.
""" """
target = spellbook.getTarget() target = spellbook.getTarget()
if target == spellbook.getInvoker(): invoker = spellbook.getInvoker()
if target == invoker:
return "You can't ban yourself!" return "You can't ban yourself!"
if reason not in ('hacking', 'language', 'other'): simbase.air.banManager.ban(invoker.doId, target.doId, duration, reason)
return "'%s' is not a valid reason." % reason return "Banned %s from the game server!" % target.getName()
simbase.air.banManager.ban(target.doId, duration, reason)
return "Banned %s from the game server!" % target.getName()

View file

@ -10,7 +10,7 @@ from toontown.rpc.ToontownRPCHandlerBase import *
from toontown.suit.SuitInvasionGlobals import INVASION_TYPE_NORMAL from toontown.suit.SuitInvasionGlobals import INVASION_TYPE_NORMAL
from toontown.toon import ToonDNA from toontown.toon import ToonDNA
from toontown.toonbase import TTLocalizer from toontown.toonbase import TTLocalizer
from toontown.uberdog.ClientServicesManagerUD import executeHttpRequest from toontown.uberdog.ClientServicesManagerUD import executeHttpRequestAndLog
class ToontownRPCHandler(ToontownRPCHandlerBase): class ToontownRPCHandler(ToontownRPCHandlerBase):
@ -362,16 +362,9 @@ class ToontownRPCHandler(ToontownRPCHandlerBase):
On success: True On success: True
On failure: False On failure: False
""" """
if reason not in ('hacking', 'language', 'other'):
return False
self.air.writeServerEvent('ban', userId, duration, reason) self.air.writeServerEvent('ban', userId, duration, reason)
if duration > 0: release = 0 if duration < 0 else datetime.date.now() + (duration * 3600000)
now = datetime.date.today() executeHttpRequestAndLog('ban', username=userId, enddate=release, comment=reason)
release = str(now + datetime.timedelta(hours=duration))
else:
release = '0000-00-00' # Permanent ban.
executeHttpRequest('accounts/ban/', Id=userId, Release=release,
Reason=reason)
self.rpc_kickUser(userId, 152, reason) self.rpc_kickUser(userId, 152, reason)
return True return True

View file

@ -39,7 +39,7 @@ http.setVerifySsl(0)
def executeHttpRequest(url, extras): def executeHttpRequest(url, extras):
request = urllib2.Request(accountServerEndpoint + url) request = urllib2.Request(accountServerEndpoint + url)
request.add_header('User-Agent', 'TTU-Uberdog') request.add_header('User-Agent', 'TTU-Game')
request.add_header('Secret-Key', accountServerSecret) request.add_header('Secret-Key', accountServerSecret)
for k, v in extras.items(): for k, v in extras.items():
request.add_header(k, v) request.add_header(k, v)