Poodletooth-iLand/toontown/ai/DistributedReportMgrAI.py

37 lines
1.4 KiB
Python
Raw Normal View History

2015-04-08 11:43:28 -05:00
from direct.directnotify import DirectNotifyGlobal
from direct.distributed.DistributedObjectAI import DistributedObjectAI
from toontown.uberdog.ClientServicesManagerUD import executeHttpRequestAndLog
2015-04-08 12:19:02 -05:00
import ReportGlobals, threading, time
2015-04-08 11:43:28 -05:00
class DistributedReportMgrAI(DistributedObjectAI):
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedReportMgrAI")
def __init__(self, air):
2015-04-08 12:19:02 -05:00
DistributedObjectAI.__init__(self, air)
2015-04-08 11:43:28 -05:00
self.reports = []
self.interval = config.GetInt('report-interval', 600)
self.scheduleReport()
def scheduleReport(self):
2015-04-08 12:19:02 -05:00
threading.Timer(self.interval, self.sendAllReports).start()
2015-04-08 11:43:28 -05:00
def sendReport(self, avId, category):
if not ReportGlobals.isValidCategoryName(category) or not len(str(avId)) == 9:
return
2015-04-08 12:19:02 -05:00
reporter = self.air.doId2do.get(self.air.getAvatarIdFromSender())
2015-04-08 11:43:28 -05:00
if not reporter or reporter.isReported(avId):
return
2015-04-08 12:22:13 -05:00
2015-04-08 11:43:28 -05:00
timestamp = int(round(time.time() * 1000))
2015-04-08 12:19:02 -05:00
self.reports.append('%s|%s|%s|%s' % (timestamp, reporter.doId, avId, category))
2015-04-08 11:43:28 -05:00
def sendAllReports(self):
2015-04-08 12:22:13 -05:00
self.scheduleReport()
2015-04-08 12:09:38 -05:00
if not self.reports or config.GetString('accountdb-type', 'developer') != 'remote':
2015-04-08 11:43:28 -05:00
return
executeHttpRequestAndLog('report', reports=','.join(self.reports))
2015-04-08 12:22:13 -05:00
self.reports = []