mirror of
https://github.com/Sneed-Group/Poodletooth-iLand
synced 2024-12-23 11:42:39 -06:00
Add banning with new login system
This commit is contained in:
parent
5539bf7ca9
commit
f1f427a3e8
3 changed files with 24 additions and 44 deletions
|
@ -1,5 +1,5 @@
|
|||
from direct.directnotify import DirectNotifyGlobal
|
||||
from toontown.uberdog.ClientServicesManagerUD import executeHttpRequest
|
||||
from toontown.uberdog.ClientServicesManagerUD import executeHttpRequestAndLog
|
||||
import datetime
|
||||
from direct.fsm.FSM import FSM
|
||||
from direct.distributed.PyDatagram import PyDatagram
|
||||
|
@ -7,15 +7,13 @@ from direct.distributed.MsgTypes import *
|
|||
from otp.ai.MagicWordGlobal import *
|
||||
from direct.showbase.DirectObject import DirectObject
|
||||
|
||||
|
||||
class BanFSM(FSM):
|
||||
|
||||
def __init__(self, air, avId, comment, duration):
|
||||
def __init__(self, air, invokerId, avId, comment, duration):
|
||||
FSM.__init__(self, 'banFSM-%s' % avId)
|
||||
self.air = air
|
||||
self.invokerId = invokerId
|
||||
self.avId = avId
|
||||
|
||||
# Needed variables for the actual banning.
|
||||
self.comment = comment
|
||||
self.duration = duration
|
||||
self.DISLid = None
|
||||
|
@ -23,15 +21,14 @@ class BanFSM(FSM):
|
|||
self.avName = None
|
||||
|
||||
def performBan(self, bannedUntil):
|
||||
executeHttpRequest('accounts/ban/', Id=self.accountId, Release=bannedUntil,
|
||||
Reason=self.comment)
|
||||
executeHttpRequestAndLog('ban', username=self.accountId, enddate=bannedUntil, comment=self.comment)
|
||||
|
||||
def ejectPlayer(self):
|
||||
av = self.air.doId2do.get(self.avId)
|
||||
|
||||
if not av:
|
||||
return
|
||||
|
||||
# Send the client a 'CLIENTAGENT_EJECT' with the players name.
|
||||
datagram = PyDatagram()
|
||||
datagram.addServerHeader(
|
||||
av.GetPuppetConnectionChannel(self.avId),
|
||||
|
@ -46,21 +43,12 @@ class BanFSM(FSM):
|
|||
|
||||
self.accountId = fields.get('ACCOUNT_ID')
|
||||
|
||||
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)
|
||||
if self.accountId:
|
||||
self.performBan(0 if self.duration < 0 else datetime.date.now() + (self.duration * 3600000))
|
||||
|
||||
def getAvatarDetails(self):
|
||||
av = self.air.doId2do.get(self.avId)
|
||||
|
||||
if not av:
|
||||
return
|
||||
|
||||
|
@ -68,14 +56,14 @@ class BanFSM(FSM):
|
|||
self.avName = av.getName()
|
||||
|
||||
def log(self):
|
||||
simbase.air.writeServerEvent('ban', self.accountId, self.comment)
|
||||
simbase.air.writeServerEvent('ban', self.invokerId, self.accountId, self.comment)
|
||||
|
||||
def cleanup(self):
|
||||
self.air = None
|
||||
self.avId = None
|
||||
|
||||
self.DISLid = None
|
||||
self.avName = None
|
||||
self.invokerId = None
|
||||
self.accountId = None
|
||||
self.comment = None
|
||||
self.duration = None
|
||||
|
@ -83,8 +71,7 @@ class BanFSM(FSM):
|
|||
|
||||
def enterStart(self):
|
||||
self.getAvatarDetails()
|
||||
self.air.dbInterface.queryObject(self.air.dbId, self.DISLid,
|
||||
self.dbCallback)
|
||||
self.air.dbInterface.queryObject(self.air.dbId, self.DISLid, self.dbCallback)
|
||||
self.ejectPlayer()
|
||||
|
||||
def exitStart(self):
|
||||
|
@ -105,8 +92,8 @@ class BanManagerAI(DirectObject):
|
|||
self.air = air
|
||||
self.banFSMs = {}
|
||||
|
||||
def ban(self, avId, duration, comment):
|
||||
self.banFSMs[avId] = BanFSM(self.air, avId, comment, duration)
|
||||
def ban(self, invokerId, avId, duration, comment):
|
||||
self.banFSMs[avId] = BanFSM(self.air, invokerId, avId, comment, duration)
|
||||
self.banFSMs[avId].request('Start')
|
||||
|
||||
self.acceptOnce(self.air.getAvatarExitEvent(avId), self.banDone, [avId])
|
||||
|
@ -122,7 +109,8 @@ def kick(reason):
|
|||
Kick the target from the game server.
|
||||
"""
|
||||
target = spellbook.getTarget()
|
||||
if target == spellbook.getInvoker():
|
||||
invoker = spellbook.getInvoker()
|
||||
if target == invoker:
|
||||
return "You can't kick yourself!"
|
||||
datagram = PyDatagram()
|
||||
datagram.addServerHeader(
|
||||
|
@ -131,6 +119,7 @@ def kick(reason):
|
|||
datagram.addUint16(155)
|
||||
datagram.addString('You were kicked by a moderator for the following reason: "%s"\n\nBehave next time!' % reason)
|
||||
simbase.air.send(datagram)
|
||||
simbase.air.writeServerEvent('kick', invoker.doId, target.doId, reason)
|
||||
return "Kicked %s from the game server!" % target.getName()
|
||||
|
||||
|
||||
|
@ -140,10 +129,8 @@ def ban(reason, duration):
|
|||
Ban the target from the game server.
|
||||
"""
|
||||
target = spellbook.getTarget()
|
||||
if target == spellbook.getInvoker():
|
||||
invoker = spellbook.getInvoker()
|
||||
if target == invoker:
|
||||
return "You can't ban yourself!"
|
||||
if reason not in ('hacking', 'language', 'other'):
|
||||
return "'%s' is not a valid reason." % reason
|
||||
simbase.air.banManager.ban(target.doId, duration, reason)
|
||||
return "Banned %s from the game server!" % target.getName()
|
||||
|
||||
simbase.air.banManager.ban(invoker.doId, target.doId, duration, reason)
|
||||
return "Banned %s from the game server!" % target.getName()
|
|
@ -10,7 +10,7 @@ from toontown.rpc.ToontownRPCHandlerBase import *
|
|||
from toontown.suit.SuitInvasionGlobals import INVASION_TYPE_NORMAL
|
||||
from toontown.toon import ToonDNA
|
||||
from toontown.toonbase import TTLocalizer
|
||||
from toontown.uberdog.ClientServicesManagerUD import executeHttpRequest
|
||||
from toontown.uberdog.ClientServicesManagerUD import executeHttpRequestAndLog
|
||||
|
||||
|
||||
class ToontownRPCHandler(ToontownRPCHandlerBase):
|
||||
|
@ -362,16 +362,9 @@ class ToontownRPCHandler(ToontownRPCHandlerBase):
|
|||
On success: True
|
||||
On failure: False
|
||||
"""
|
||||
if reason not in ('hacking', 'language', 'other'):
|
||||
return False
|
||||
self.air.writeServerEvent('ban', userId, duration, reason)
|
||||
if duration > 0:
|
||||
now = datetime.date.today()
|
||||
release = str(now + datetime.timedelta(hours=duration))
|
||||
else:
|
||||
release = '0000-00-00' # Permanent ban.
|
||||
executeHttpRequest('accounts/ban/', Id=userId, Release=release,
|
||||
Reason=reason)
|
||||
release = 0 if duration < 0 else datetime.date.now() + (duration * 3600000)
|
||||
executeHttpRequestAndLog('ban', username=userId, enddate=release, comment=reason)
|
||||
self.rpc_kickUser(userId, 152, reason)
|
||||
return True
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ http.setVerifySsl(0)
|
|||
|
||||
def executeHttpRequest(url, extras):
|
||||
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)
|
||||
for k, v in extras.items():
|
||||
request.add_header(k, v)
|
||||
|
|
Loading…
Reference in a new issue