We don't need a ClsendTracker

This commit is contained in:
John 2015-05-31 14:27:24 +03:00 committed by Loudrob
parent 8352d31504
commit 7b8e48df78
2 changed files with 1 additions and 63 deletions

View file

@ -6,22 +6,19 @@ from otp.ai.MagicWordGlobal import *
from otp.avatar import DistributedAvatarAI from otp.avatar import DistributedAvatarAI
from otp.avatar import PlayerBase from otp.avatar import PlayerBase
from otp.distributed import OtpDoGlobals from otp.distributed import OtpDoGlobals
from otp.distributed.ClsendTracker import ClsendTracker
from otp.otpbase import OTPLocalizer from otp.otpbase import OTPLocalizer
class DistributedPlayerAI(DistributedAvatarAI.DistributedAvatarAI, PlayerBase.PlayerBase, ClsendTracker): class DistributedPlayerAI(DistributedAvatarAI.DistributedAvatarAI, PlayerBase.PlayerBase):
def __init__(self, air): def __init__(self, air):
DistributedAvatarAI.DistributedAvatarAI.__init__(self, air) DistributedAvatarAI.DistributedAvatarAI.__init__(self, air)
PlayerBase.PlayerBase.__init__(self) PlayerBase.PlayerBase.__init__(self)
ClsendTracker.__init__(self)
self.friendsList = [] self.friendsList = []
self.DISLid = 0 self.DISLid = 0
self.adminAccess = 0 self.adminAccess = 0
def announceGenerate(self): def announceGenerate(self):
DistributedAvatarAI.DistributedAvatarAI.announceGenerate(self) DistributedAvatarAI.DistributedAvatarAI.announceGenerate(self)
ClsendTracker.announceGenerate(self)
self._doPlayerEnter() self._doPlayerEnter()
def _announceArrival(self): def _announceArrival(self):
@ -35,7 +32,6 @@ class DistributedPlayerAI(DistributedAvatarAI.DistributedAvatarAI, PlayerBase.Pl
def delete(self): def delete(self):
self._doPlayerExit() self._doPlayerExit()
ClsendTracker.destroy(self)
DistributedAvatarAI.DistributedAvatarAI.delete(self) DistributedAvatarAI.DistributedAvatarAI.delete(self)
def isPlayerControlled(self): def isPlayerControlled(self):

View file

@ -1,58 +0,0 @@
from pandac.PandaModules import StringStream
from direct.distributed.PyDatagram import PyDatagram
import random
class ClsendTracker:
clsendNotify = directNotify.newCategory('clsend')
NumTrackersLoggingOverflow = 0
MaxTrackersLoggingOverflow = config.GetInt('max-clsend-loggers', 5)
def __init__(self):
self._logClsendOverflow = False
if self.isPlayerControlled():
if simbase.air.getTrackClsends():
if ClsendTracker.NumTrackersLoggingOverflow < ClsendTracker.MaxTrackersLoggingOverflow:
self._logClsendOverflow = random.random() < 1.0 / config.GetFloat('clsend-log-one-av-in-every', choice(0, 4, 50))
if self._logClsendOverflow:
ClsendTracker.NumTrackersLoggingOverflow += 1
self._clsendMsgs = []
self._clsendBufLimit = 100
self._clsendFlushNum = 20
self._clsendCounter = 0
def announceGenerate(self):
if self._logClsendOverflow:
self.clsendNotify.info('logging all clsends for %s' % self.doId)
def destroy(self):
if self._logClsendOverflow:
ClsendTracker.NumTrackersLoggingOverflow -= 1
def trackClientSendMsg(self, dataStr):
self._clsendMsgs.append((self.air.getAvatarIdFromSender(), dataStr))
if len(self._clsendMsgs) >= self._clsendBufLimit:
self._trimClsend()
def _trimClsend(self):
for i in xrange(self._clsendFlushNum):
if self._logClsendOverflow:
self._logClsend(*self._clsendMsgs[0])
self._clsendMsgs = self._clsendMsgs[1:]
self._clsendCounter += 1
def _logClsend(self, senderId, dataStr):
msgStream = StringStream()
simbase.air.describeMessage(msgStream, '', dataStr)
readableStr = msgStream.getData()
sstream = StringStream()
PyDatagram(dataStr).dumpHex(sstream)
hexDump = sstream.getData()
self.clsendNotify.info('%s [%s]: %s%s' % (self.doId,
self._clsendCounter,
readableStr,
hexDump))
def dumpClientSentMsgs(self):
for msg in self._clsendMsgs:
self._logClsend(*msg)
self._clsendCounter += 1