Poodletooth-iLand/toontown/ai/DistributedReportMgrAI.py

44 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
# TODO: FIX
'''
THREADING.TIMER CAUSES CONTROL C NOT TO WORK, AND FOR THE AI NOT TO DIE
'''
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()
2015-04-28 23:01:52 -05:00
#def scheduleReport(self):
# threading.Timer(self.interval, self.sendAllReports).start()
2015-04-28 23:01:52 -05:00
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-28 23:01:52 -05:00
2015-04-08 12:19:02 -05:00
reporter = self.air.doId2do.get(self.air.getAvatarIdFromSender())
2015-04-28 23:01:52 -05:00
2015-04-08 11:43:28 -05:00
if not reporter or reporter.isReported(avId):
return
2015-04-28 23:01:52 -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-28 23:01:52 -05:00
2015-04-08 11:43:28 -05:00
def sendAllReports(self):
#self.scheduleReport()
2015-04-28 23:01:52 -05:00
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
2015-04-28 23:01:52 -05:00
2015-04-08 11:43:28 -05:00
executeHttpRequestAndLog('report', reports=','.join(self.reports))
2015-04-28 23:01:52 -05:00
self.reports = []