class UserFunnel:

    def __init__(self):
        self.hitboxAcct = 'DM53030620EW'
        self.language = 'en-us'
        self.cgRoot = 'ToonTown_Online'
        self.cgBeta = 'Beta'
        self.cgRelease = 'Release'
        self.cgLocation = 'US'
        self.campaignID = ''
        self.cfCookieFile = 'cf.txt'
        self.dynamicVRFunnel = 'http://download.toontown.com/'
        self.hostDict = {0: 'Internal Disney PHP Collector Site',
         1: 'ehg-dig.hitbox.com/HG?',
         2: 'ehg-dig.hitbox.com/HG?',
         3: 'build64.online.disney.com:5020/index.php?'}
        self.CurrentHost = ''
        self.URLtoSend = ''
        self.gameName = 'ToonTown'
        self.browserName = 'Panda3D%20(' + self.gameName + ';%20' + sys.platform + ')'
        self.HTTPUserHeader = [('User-agent', 'Panda3D')]
        self.osMajorver = ''
        self.osMinorver = ''
        self.osRevver = ''
        self.osBuild = ''
        self.osType = ''
        self.osComments = ''
        self.msWinTypeDict = {0: 'Win32s on Windows 3.1',
         1: 'Windows 95/98/ME',
         2: 'Windows NT/2000/XP',
         3: 'Windows CE'}
        self.milestoneDict = {0: 'New User',
         1: 'Create Account',
         2: 'View EULA',
         3: 'Accept EULA',
         4: 'Download Start',
         5: 'Download End',
         6: 'Installer Run',
         7: 'Launcher Start',
         8: 'Launcher Login',
         9: 'Client Opens',
         10: 'Create Pirate Loads',
         11: 'Create Pirate Exit',
         12: 'Cutscene One Start',
         13: 'Cutscene One Ends',
         14: 'Cutscene Two Start',
         15: 'Cutscene Thee Start',
         16: 'Cutscene Three Ends',
         17: 'Access Cannon',
         18: 'Cutscene Four Starts',
         19: 'Cutscene Four Ends',
         20: 'Dock - Start Game'}
        self.macTypeDict = {2: 'Jaguar',
         1: 'Puma',
         3: 'Panther',
         4: 'Tiger',
         5: 'Lepard'}
        self.milestone = ''
        self.pandaHTTPClientVarWSS = []
        self.pandaHTTPClientVarCTG = []
        self.pandaHTTPClientVarDM = []
        self.checkForCFfile()
        self.httpSession = HTTPClient()
        self.whatOSver()

    def checkForCFfile(self):
        if firstRun() == True:
            pass
        elif os.path.isfile(self.cfCookieFile) == False:
            firstRun('write', True)

    def whatOSver(self):
        if sys.platform == 'win32':
            self.osMajorver = str(sys.getwindowsversion()[0])
            self.osMinorver = str(sys.getwindowsversion()[1])
            self.osBuild = str(sys.getwindowsversion()[2])
            self.osType = str(sys.getwindowsversion()[3])
            self.osComments = str(sys.getwindowsversion()[4])
            return
        if sys.platform == 'darwin':
            self.osMajorver = '10'
            osxcmd = '/usr/sbin/system_profiler SPSoftwareDataType |/usr/bin/grep "System Version"'
            infopipe = os.popen(osxcmd, 'r')
            parseLine = infopipe.read()
            infopipe.close()
            del infopipe
            notify.info('parseLine = %s' % str(parseLine))
            versionStringStart = parseLine.find('10.')
            notify.info('versionStringStart = %s' % str(versionStringStart))
            testPlist = False
            try:
                self.osMinorver = parseLine[versionStringStart + 3]
                self.osRevver = parseLine[versionStringStart + 5:versionStringStart + 7].strip(' ')
                self.osBuild = parseLine[int(parseLine.find('(')) + 1:parseLine.find(')')]
            except:
                notify.info("couldn't parse the system_profiler output, using zeros")
                self.osMinorver = '0'
                self.osRevver = '0'
                self.osBuild = '0000'
                testPlist = True

            del versionStringStart
            del parseLine
            del osxcmd
            if testPlist:
                try:
                    import plistlib
                    pl = plistlib.readPlist('/System/Library/CoreServices/SystemVersion.plist')
                    notify.info('pl=%s' % str(pl))
                    parseLine = pl['ProductVersion']
                    numbers = parseLine.split('.')
                    notify.info('parseline =%s numbers =%s' % (parseLine, numbers))
                    self.osMinorver = numbers[1]
                    self.osRevver = numbers[2]
                    self.osBuild = pl['ProductBuildVersion']
                except:
                    notify.info('tried plist but still got exception')
                    self.osMinorver = '0'
                    self.osRevver = '0'
                    self.osBuild = '0000'

            return

    def setmilestone(self, ms):
        if firstRun() == False:
            self.milestone = ms
        else:
            self.milestone = '%s_INITIAL' % ms

    def setgamename(self, gamename):
        self.gameName = gamename

    def printosComments(self):
        return self.osComments

    def setHost(self, hostID):
        self.CurrentHost = hostID

    def getFunnelURL(self):
        if patcherVer() == ['OFFLINE']:
            return
        if patcherVer() == []:
            patcherHTTP = HTTPClient()
            if checkParamFile() == None:
                patcherDoc = patcherHTTP.getDocument(URLSpec('http://download.toontown.com/english/currentVersion/content/patcher.ver'))
                vconGroup('w', self.cgRelease)
            else:
                patcherDoc = patcherHTTP.getDocument(URLSpec(checkParamFile()))
                vconGroup('w', self.cgBeta)
            rf = Ramfile()
            patcherDoc.downloadToRam(rf)
            self.patcherURL = rf.getData()
            if self.patcherURL.find('FUNNEL_LOG') == -1:
                patcherVer('w', 'OFFLINE')
                return
            self.patcherURL = self.patcherURL.split('\n')
            del rf
            del patcherDoc
            del patcherHTTP
            while self.patcherURL:
                self.confLine = self.patcherURL.pop()
                if self.confLine.find('FUNNEL_LOG=') != -1 and self.confLine.find('#FUNNEL_LOG=') == -1:
                    self.dynamicVRFunnel = self.confLine[11:].strip('\n')
                    patcherVer('w', self.confLine[11:].strip('\n'))

        else:
            self.dynamicVRFunnel = patcherVer()[0]
        return

    def isVarSet(self, varInQuestion):
        try:
            tempvar = type(varInQuestion)
            return 1
        except NameError:
            return 0

    def buildURL(self):
        if sys.platform == 'win32':
            hitboxOSType = 'c3'
        else:
            hitboxOSType = 'c4'
        if self.CurrentHost == 1:
            self.URLtoSend = 'http://' + self.hostDict[self.CurrentHost] + 'hb=' + str(self.hitboxAcct) + '&n=' + str(self.milestone) + '&ln=' + self.language + '&gp=STARTGAME&fnl=TOONTOWN_FUNNEL&vcon=/' + self.cgRoot + '/' + self.cgLocation + '/' + str(vconGroup()) + '&c1=' + str(sys.platform) + '&' + str(hitboxOSType) + '=' + str(self.osMajorver) + '_' + str(self.osMinorver) + '_' + str(self.osRevver) + '_' + str(self.osBuild)
        if self.CurrentHost == 2:
            self.URLtoSend = 'http://' + self.hostDict[self.CurrentHost] + 'hb=' + str(self.hitboxAcct) + '&n=' + str(self.milestone) + '&ln=' + self.language + '&vcon=/' + self.cgRoot + '/' + self.cgLocation + '/' + str(vconGroup()) + '&c1=' + str(sys.platform) + '&' + str(hitboxOSType) + '=' + str(self.osMajorver) + '_' + str(self.osMinorver) + '_' + str(self.osRevver) + '_' + str(self.osBuild)
        if self.CurrentHost == 0:
            localMAC = str(getMAC())
            self.URLtoSend = str(self.dynamicVRFunnel) + '?funnel=' + str(self.milestone) + '&platform=' + str(sys.platform) + '&sysver=' + str(self.osMajorver) + '_' + str(self.osMinorver) + '_' + str(self.osRevver) + '_' + str(self.osBuild) + '&mac=' + localMAC + '&username='******'&id=' + str(loggingAvID())

    def readInPandaCookie(self):
        thefile = open(self.cfCookieFile, 'r')
        thedata = thefile.read().split('\n')
        thefile.close()
        del thefile
        if thedata[0].find('Netscape HTTP Cookie File') != -1:
            return
        thedata.pop()
        try:
            while thedata:
                temp = thedata.pop()
                temp = temp.split('\t')
                domain = temp[0]
                loc = temp[1]
                variable = temp[2]
                value = temp[3]
                if variable == 'CTG':
                    self.pandaHTTPClientVarCTG = [domain,
                     loc,
                     variable,
                     value]
                    self.setTheHTTPCookie(self.pandaHTTPClientVarCTG)
                if variable == self.hitboxAcct + 'V6':
                    self.pandaHTTPClientVarDM = [domain,
                     loc,
                     variable,
                     value]
                    self.setTheHTTPCookie(self.pandaHTTPClientVarDM)
                if variable == 'WSS_GW':
                    self.pandaHTTPClientVarWSS = [domain,
                     loc,
                     variable,
                     value]
                    self.setTheHTTPCookie(self.pandaHTTPClientVarWSS)

        except IndexError:
            print 'UserFunnel(Warning): Cookie Data file bad'

        del thedata

    def updateInstanceCookieValues(self):
        a = self.httpSession.getCookie(HTTPCookie('WSS_GW', '/', '.hitbox.com'))
        if a.getName():
            self.pandaHTTPClientVarWSS = ['.hitbox.com',
             '/',
             'WSS_GW',
             a.getValue()]
        b = self.httpSession.getCookie(HTTPCookie('CTG', '/', '.hitbox.com'))
        if b.getName():
            self.pandaHTTPClientVarCTG = ['.hitbox.com',
             '/',
             'CTG',
             b.getValue()]
        c = self.httpSession.getCookie(HTTPCookie(self.hitboxAcct + 'V6', '/', 'ehg-dig.hitbox.com'))
        if c.getName():
            self.pandaHTTPClientVarDM = ['ehg-dig.hitbox.com',
             '/',
             self.hitboxAcct + 'V6',
             c.getValue()]
        del a
        del b
        del c

    def setTheHTTPCookie(self, cookieParams):
        c = HTTPCookie(cookieParams[2], cookieParams[1], cookieParams[0])
        c.setValue(cookieParams[3])
        self.httpSession.setCookie(c)

    def writeOutPandaCookie(self):
        try:
            thefile = open(self.cfCookieFile, 'w')
            if len(self.pandaHTTPClientVarWSS) == 4:
                thefile.write(self.pandaHTTPClientVarWSS[0] + '\t' + self.pandaHTTPClientVarWSS[1] + '\t' + self.pandaHTTPClientVarWSS[2] + '\t' + self.pandaHTTPClientVarWSS[3] + '\n')
            if len(self.pandaHTTPClientVarCTG) == 4:
                thefile.write(self.pandaHTTPClientVarCTG[0] + '\t' + self.pandaHTTPClientVarCTG[1] + '\t' + self.pandaHTTPClientVarCTG[2] + '\t' + self.pandaHTTPClientVarCTG[3] + '\n')
            if len(self.pandaHTTPClientVarDM) == 4:
                thefile.write(self.pandaHTTPClientVarDM[0] + '\t' + self.pandaHTTPClientVarDM[1] + '\t' + self.pandaHTTPClientVarDM[2] + '\t' + self.pandaHTTPClientVarDM[3] + '\n')
            thefile.close()
        except IOError:
            return

    def prerun(self):
        self.getFunnelURL()
        self.buildURL()
        if os.path.isfile(self.cfCookieFile) == True:
            if self.CurrentHost == 1 or self.CurrentHost == 2:
                self.readInPandaCookie()

    def run(self):
        if self.CurrentHost == 0 and patcherVer() == ['OFFLINE']:
            return
        self.nonBlock = self.httpSession.makeChannel(False)
        self.nonBlock.beginGetDocument(DocumentSpec(self.URLtoSend))
        instanceMarker = str(random.randint(1, 1000))
        instanceMarker = 'FunnelLoggingRequest-%s' % instanceMarker
        self.startCheckingAsyncRequest(instanceMarker)

    def startCheckingAsyncRequest(self, name):
        taskMgr.remove(name)
        taskMgr.doMethodLater(0.5, self.pollFunnelTask, name)

    def stopCheckingFunnelTask(self, name):
        taskMgr.remove('pollFunnelTask')

    def pollFunnelTask(self, task):
        result = self.nonBlock.run()
        if result == 0:
            self.stopCheckingFunnelTask(task)
            if self.CurrentHost == 1 or self.CurrentHost == 2:
                self.updateInstanceCookieValues()
                self.writeOutPandaCookie()
        else:
            return Task.again
Ejemplo n.º 2
0
class UserFunnel:

    def __init__(self):
        self.hitboxAcct = 'DM53030620EW'
        self.language = 'en-us'
        self.cgRoot = 'ToonTown_Online'
        self.cgBeta = 'Beta'
        self.cgRelease = 'Release'
        self.cgLocation = 'US'
        self.campaignID = ''
        self.cfCookieFile = 'cf.txt'
        self.dynamicVRFunnel = 'http://download.toontown.com/'
        self.hostDict = {0: 'Internal Disney PHP Collector Site',
         1: 'ehg-dig.hitbox.com/HG?',
         2: 'ehg-dig.hitbox.com/HG?',
         3: 'build64.online.disney.com:5020/index.php?'}
        self.CurrentHost = ''
        self.URLtoSend = ''
        self.gameName = 'ToonTown'
        self.browserName = 'Panda3D%20(' + self.gameName + ';%20' + sys.platform + ')'
        self.HTTPUserHeader = [('User-agent', 'Panda3D')]
        self.osMajorver = ''
        self.osMinorver = ''
        self.osRevver = ''
        self.osBuild = ''
        self.osType = ''
        self.osComments = ''
        self.msWinTypeDict = {0: 'Win32s on Windows 3.1',
         1: 'Windows 95/98/ME',
         2: 'Windows NT/2000/XP',
         3: 'Windows CE'}
        self.milestoneDict = {0: 'New User',
         1: 'Create Account',
         2: 'View EULA',
         3: 'Accept EULA',
         4: 'Download Start',
         5: 'Download End',
         6: 'Installer Run',
         7: 'Launcher Start',
         8: 'Launcher Login',
         9: 'Client Opens',
         10: 'Create Pirate Loads',
         11: 'Create Pirate Exit',
         12: 'Cutscene One Start',
         13: 'Cutscene One Ends',
         14: 'Cutscene Two Start',
         15: 'Cutscene Thee Start',
         16: 'Cutscene Three Ends',
         17: 'Access Cannon',
         18: 'Cutscene Four Starts',
         19: 'Cutscene Four Ends',
         20: 'Dock - Start Game'}
        self.macTypeDict = {2: 'Jaguar',
         1: 'Puma',
         3: 'Panther',
         4: 'Tiger',
         5: 'Lepard'}
        self.milestone = ''
        self.pandaHTTPClientVarWSS = []
        self.pandaHTTPClientVarCTG = []
        self.pandaHTTPClientVarDM = []
        self.checkForCFfile()
        self.httpSession = HTTPClient()
        self.whatOSver()

    def checkForCFfile(self):
        if firstRun():
            pass
        elif not os.path.isfile(self.cfCookieFile):
            firstRun('write', True)

    def whatOSver(self):
        if sys.platform == 'win32':
            self.osMajorver = str(sys.getwindowsversion()[0])
            self.osMinorver = str(sys.getwindowsversion()[1])
            self.osBuild = str(sys.getwindowsversion()[2])
            self.osType = str(sys.getwindowsversion()[3])
            self.osComments = str(sys.getwindowsversion()[4])
            return
        if sys.platform == 'darwin':
            self.osMajorver = '10'
            osxcmd = '/usr/sbin/system_profiler SPSoftwareDataType |/usr/bin/grep "System Version"'
            infopipe = os.popen(osxcmd, 'r')
            parseLine = infopipe.read()
            infopipe.close()
            del infopipe
            notify.info('parseLine = %s' % str(parseLine))
            versionStringStart = parseLine.find('10.')
            notify.info('versionStringStart = %s' % str(versionStringStart))
            testPlist = False
            try:
                self.osMinorver = parseLine[versionStringStart + 3]
                self.osRevver = parseLine[versionStringStart + 5:versionStringStart + 7].strip(' ')
                self.osBuild = parseLine[int(parseLine.find('(')) + 1:parseLine.find(')')]
            except:
                notify.info("couldn't parse the system_profiler output, using zeros")
                self.osMinorver = '0'
                self.osRevver = '0'
                self.osBuild = '0000'
                testPlist = True

            del versionStringStart
            del parseLine
            del osxcmd
            if testPlist:
                try:
                    import plistlib
                    pl = plistlib.readPlist('/System/Library/CoreServices/SystemVersion.plist')
                    notify.info('pl=%s' % str(pl))
                    parseLine = pl['ProductVersion']
                    numbers = parseLine.split('.')
                    notify.info('parseline =%s numbers =%s' % (parseLine, numbers))
                    self.osMinorver = numbers[1]
                    self.osRevver = numbers[2]
                    self.osBuild = pl['ProductBuildVersion']
                except:
                    notify.info('tried plist but still got exception')
                    self.osMinorver = '0'
                    self.osRevver = '0'
                    self.osBuild = '0000'

            return

    def setmilestone(self, ms):
        if not firstRun():
            self.milestone = ms
        else:
            self.milestone = '%s_INITIAL' % ms

    def setgamename(self, gamename):
        self.gameName = gamename

    def printosComments(self):
        return self.osComments

    def setHost(self, hostID):
        self.CurrentHost = hostID

    def getFunnelURL(self):
        if patcherVer() == ['OFFLINE']:
            return
        if not patcherVer():
            patcherHTTP = HTTPClient()
            if checkParamFile() == None:
                patcherDoc = patcherHTTP.getDocument(URLSpec('http://download.toontown.com/english/currentVersion/content/patcher.ver'))
                vconGroup('w', self.cgRelease)
            else:
                patcherDoc = patcherHTTP.getDocument(URLSpec(checkParamFile()))
                vconGroup('w', self.cgBeta)
            rf = Ramfile()
            patcherDoc.downloadToRam(rf)
            self.patcherURL = rf.getData()
            if self.patcherURL.find('FUNNEL_LOG') == -1:
                patcherVer('w', 'OFFLINE')
                return
            self.patcherURL = self.patcherURL.split('\n')
            del rf
            del patcherDoc
            del patcherHTTP
            while self.patcherURL:
                self.confLine = self.patcherURL.pop()
                if self.confLine.find('FUNNEL_LOG=') != -1 and self.confLine.find('#FUNNEL_LOG=') == -1:
                    self.dynamicVRFunnel = self.confLine[11:].strip('\n')
                    patcherVer('w', self.confLine[11:].strip('\n'))

        else:
            self.dynamicVRFunnel = patcherVer()[0]
        return

    def isVarSet(self, varInQuestion):
        try:
            tempvar = type(varInQuestion)
            return 1
        except NameError:
            return 0

    def buildURL(self):
        if sys.platform == 'win32':
            hitboxOSType = 'c3'
        else:
            hitboxOSType = 'c4'
        if self.CurrentHost == 1:
            self.URLtoSend = 'http://' + self.hostDict[self.CurrentHost] + 'hb=' + str(self.hitboxAcct) + '&n=' + str(self.milestone) + '&ln=' + self.language + '&gp=STARTGAME&fnl=TOONTOWN_FUNNEL&vcon=/' + self.cgRoot + '/' + self.cgLocation + '/' + str(vconGroup()) + '&c1=' + str(sys.platform) + '&' + str(hitboxOSType) + '=' + str(self.osMajorver) + '_' + str(self.osMinorver) + '_' + str(self.osRevver) + '_' + str(self.osBuild)
        if self.CurrentHost == 2:
            self.URLtoSend = 'http://' + self.hostDict[self.CurrentHost] + 'hb=' + str(self.hitboxAcct) + '&n=' + str(self.milestone) + '&ln=' + self.language + '&vcon=/' + self.cgRoot + '/' + self.cgLocation + '/' + str(vconGroup()) + '&c1=' + str(sys.platform) + '&' + str(hitboxOSType) + '=' + str(self.osMajorver) + '_' + str(self.osMinorver) + '_' + str(self.osRevver) + '_' + str(self.osBuild)
        if self.CurrentHost == 0:
            localMAC = str(getMAC())
            self.URLtoSend = str(self.dynamicVRFunnel) + '?funnel=' + str(self.milestone) + '&platform=' + str(sys.platform) + '&sysver=' + str(self.osMajorver) + '_' + str(self.osMinorver) + '_' + str(self.osRevver) + '_' + str(self.osBuild) + '&mac=' + localMAC + '&username='******'&id=' + str(loggingAvID())

    def readInPandaCookie(self):
        thefile = open(self.cfCookieFile, 'r')
        thedata = thefile.read().split('\n')
        thefile.close()
        del thefile
        if thedata[0].find('Netscape HTTP Cookie File') != -1:
            return
        thedata.pop()
        try:
            while thedata:
                temp = thedata.pop()
                temp = temp.split('\t')
                domain = temp[0]
                loc = temp[1]
                variable = temp[2]
                value = temp[3]
                if variable == 'CTG':
                    self.pandaHTTPClientVarCTG = [domain,
                     loc,
                     variable,
                     value]
                    self.setTheHTTPCookie(self.pandaHTTPClientVarCTG)
                if variable == self.hitboxAcct + 'V6':
                    self.pandaHTTPClientVarDM = [domain,
                     loc,
                     variable,
                     value]
                    self.setTheHTTPCookie(self.pandaHTTPClientVarDM)
                if variable == 'WSS_GW':
                    self.pandaHTTPClientVarWSS = [domain,
                     loc,
                     variable,
                     value]
                    self.setTheHTTPCookie(self.pandaHTTPClientVarWSS)

        except IndexError:
            print 'UserFunnel(Warning): Cookie Data file bad'

        del thedata

    def updateInstanceCookieValues(self):
        a = self.httpSession.getCookie(HTTPCookie('WSS_GW', '/', '.hitbox.com'))
        if a.getName():
            self.pandaHTTPClientVarWSS = ['.hitbox.com',
             '/',
             'WSS_GW',
             a.getValue()]
        b = self.httpSession.getCookie(HTTPCookie('CTG', '/', '.hitbox.com'))
        if b.getName():
            self.pandaHTTPClientVarCTG = ['.hitbox.com',
             '/',
             'CTG',
             b.getValue()]
        c = self.httpSession.getCookie(HTTPCookie(self.hitboxAcct + 'V6', '/', 'ehg-dig.hitbox.com'))
        if c.getName():
            self.pandaHTTPClientVarDM = ['ehg-dig.hitbox.com',
             '/',
             self.hitboxAcct + 'V6',
             c.getValue()]
        del a
        del b
        del c

    def setTheHTTPCookie(self, cookieParams):
        c = HTTPCookie(cookieParams[2], cookieParams[1], cookieParams[0])
        c.setValue(cookieParams[3])
        self.httpSession.setCookie(c)

    def writeOutPandaCookie(self):
        try:
            thefile = open(self.cfCookieFile, 'w')
            if len(self.pandaHTTPClientVarWSS) == 4:
                thefile.write(self.pandaHTTPClientVarWSS[0] + '\t' + self.pandaHTTPClientVarWSS[1] + '\t' + self.pandaHTTPClientVarWSS[2] + '\t' + self.pandaHTTPClientVarWSS[3] + '\n')
            if len(self.pandaHTTPClientVarCTG) == 4:
                thefile.write(self.pandaHTTPClientVarCTG[0] + '\t' + self.pandaHTTPClientVarCTG[1] + '\t' + self.pandaHTTPClientVarCTG[2] + '\t' + self.pandaHTTPClientVarCTG[3] + '\n')
            if len(self.pandaHTTPClientVarDM) == 4:
                thefile.write(self.pandaHTTPClientVarDM[0] + '\t' + self.pandaHTTPClientVarDM[1] + '\t' + self.pandaHTTPClientVarDM[2] + '\t' + self.pandaHTTPClientVarDM[3] + '\n')
            thefile.close()
        except IOError:
            return

    def prerun(self):
        self.getFunnelURL()
        self.buildURL()
        if os.path.isfile(self.cfCookieFile):
            if self.CurrentHost == 1 or self.CurrentHost == 2:
                self.readInPandaCookie()

    def run(self):
        if self.CurrentHost == 0 and patcherVer() == ['OFFLINE']:
            return
        self.nonBlock = self.httpSession.makeChannel(False)
        self.nonBlock.beginGetDocument(DocumentSpec(self.URLtoSend))
        instanceMarker = str(random.randint(1, 1000))
        instanceMarker = 'FunnelLoggingRequest-%s' % instanceMarker
        self.startCheckingAsyncRequest(instanceMarker)

    def startCheckingAsyncRequest(self, name):
        taskMgr.remove(name)
        taskMgr.doMethodLater(0.5, self.pollFunnelTask, name)

    def stopCheckingFunnelTask(self, name):
        taskMgr.remove('pollFunnelTask')

    def pollFunnelTask(self, task):
        result = self.nonBlock.run()
        if result == 0:
            self.stopCheckingFunnelTask(task)
            if self.CurrentHost == 1 or self.CurrentHost == 2:
                self.updateInstanceCookieValues()
                self.writeOutPandaCookie()
        else:
            return Task.again
Ejemplo n.º 3
0
class UserFunnel:
    def __init__(self):

        # Variables required for acct service access
        # HitBox Account Number.
        # DOL test account = DM510925KJWE
        # Pirates Account = DM560804E8WD
        # ToonTown Account = DM53030620EW

        self.hitboxAcct = 'DM53030620EW'
        # self.hitboxAcct = 'DM510925KJWE'
        # Language Used; example: English (US) = en-us

        self.language = 'en-us'

        # Content Group

        self.cgRoot = 'ToonTown_Online'

        # Content Sub-Groups
        # For now, I've hardcoded the cgLocation to US. In the future
        # we'll need to change this by hand or via a function, to reflect
        # the geolocation that this is being built for.

        self.cgBeta = 'Beta'
        self.cgRelease = 'Release'
        self.cgLocation = 'US'

        # Campaign ID for hitbox
        # Again, this ID has yet to be provided

        self.campaignID = ''

        # Cookie CallBack for HBX, but can be used for others if needed

        # self.cfCookie = cookielib.MozillaCookieJar('cf.txt')
        self.cfCookieFile = 'cf.txt'

        # Host Listing. Access hostnames and paths will be listed here
        # Each item has an int that goes along with it.

        self.dynamicVRFunnel = 'http://download.toontown.com/'
        # self.dynamicVRFunnel = 'http://build64:3120/logging/collector.php'

        self.hostDict = {
            0: 'Internal Disney PHP Collector Site',
            1: 'ehg-dig.hitbox.com/HG?',
            2: 'ehg-dig.hitbox.com/HG?',
            3: 'build64.online.disney.com:5020/index.php?'
        }

        # The current host variable will be an int value that points to an
        # entry in the hostDict. It is used at URL generation time to insert
        # the correct hostname and path into the URL

        self.CurrentHost = ''

        # URLtoSend is the actual URL that will be accessed when run() is called
        self.URLtoSend = ''

        # System Variables to report on. Currently, they are not all being used.
        # Some variables have been put in place for future use.

        # GameName is the name of the game being reported on

        self.gameName = 'ToonTown'

        # BrowserName for ID

        self.browserName = 'Panda3D%20(' + self.gameName + ';%20' + sys.platform + ')'
        # HTTPUserHeader to be transmitted once the http connection is established. This is not part of the URL that is sent. It is part of the header.

        self.HTTPUserHeader = [('User-agent', 'Panda3D')]

        # OS Major Version: Example MS-WinXP = 5, MacOSX Tiger = 10

        self.osMajorver = ''

        # OS Minor Version: Example MS-WinXP = 1, OSX Tiger = 4

        self.osMinorver = ''

        # OS Rev Version: Example OSX Tiger = 1...9

        self.osRevver = ''

        # OS Build Number: Example MS-WinXP = 2600

        self.osBuild = ''

        # OS Type. Example: int value that goes along with the msWinTypeDict

        self.osType = ''

        # The getwindowsversion command returns comments. An example would the a comment about the currently installed service pack

        self.osComments = ''

        # Dict of int to string pairs for self.osType

        self.msWinTypeDict = {
            0: 'Win32s on Windows 3.1',
            1: 'Windows 95/98/ME',
            2: 'Windows NT/2000/XP',
            3: 'Windows CE'
        }

        self.milestoneDict = {
            0: 'New User',
            1: 'Create Account',
            2: 'View EULA',
            3: 'Accept EULA',
            4: 'Download Start',
            5: 'Download End',
            6: 'Installer Run',
            7: 'Launcher Start',
            8: 'Launcher Login',
            9: 'Client Opens',
            10: 'Create Pirate Loads',
            11: 'Create Pirate Exit',
            12: 'Cutscene One Start',
            13: 'Cutscene One Ends',
            14: 'Cutscene Two Start',
            15: 'Cutscene Thee Start',
            16: 'Cutscene Three Ends',
            17: 'Access Cannon',
            18: 'Cutscene Four Starts',
            19: 'Cutscene Four Ends',
            20: 'Dock - Start Game'
        }

        self.macTypeDict = {
            2: 'Jaguar',
            1: 'Puma',
            3: 'Panther',
            4: 'Tiger',
            5: 'Lepard'
        }

        # Milestone string var. Used to hold the funnel location string. This used to be an int (as per the dict above), but later is was decided that it would be a string value; ie. START_GAME or BUILD_PIRATE_START. I have left the milestoneDict in place for reference purposes.

        self.milestone = ''

        # The next three lists hold the cookie vars for the three hitbox based
        # variable / value pairs requred for hitbox.
        # [DOMAIN, /, VARIABLE, VALUE]

        self.pandaHTTPClientVarWSS = []
        self.pandaHTTPClientVarCTG = []
        self.pandaHTTPClientVarDM = []

        # In an effort to determine if this is the first time the client has
        # been executed on the system, we will check for the existance of the
        # cf.txt file. If the file does not exist, we will set the firstRun()
        # to True.

        self.checkForCFfile()

        # Instance an HTTPClient session

        self.httpSession = HTTPClient()

        # Run the whatOSver command at the end of the constructor.
        self.whatOSver()

    def checkForCFfile(self):
        # Check for the existance of the cf.txt file. If it does not exist,
        # then set the firstRun() to True. If it does exist, do nothing.

        if firstRun() == True:
            pass
        else:
            if (os.path.isfile(self.cfCookieFile) == False):
                firstRun('write', True)

    # Populate the osMajor, osMinor, osBuild, osType, osComments, and osRevver vars
    def whatOSver(self):
        if (sys.platform == 'win32'):
            self.osMajorver = str(sys.getwindowsversion()[0])
            self.osMinorver = str(sys.getwindowsversion()[1])
            self.osBuild = str(sys.getwindowsversion()[2])
            self.osType = str(sys.getwindowsversion()[3])
            self.osComments = str(sys.getwindowsversion()[4])
            return

        if (sys.platform == 'darwin'):
            self.osMajorver = '10'
            osxcmd = '/usr/sbin/system_profiler SPSoftwareDataType |/usr/bin/grep "System Version"'
            infopipe = os.popen(osxcmd, 'r')
            parseLine = infopipe.read()
            infopipe.close()
            del infopipe
            notify.info("parseLine = %s" % str(parseLine))
            versionStringStart = parseLine.find('10.')
            notify.info("versionStringStart = %s" % str(versionStringStart))
            testPlist = False
            try:
                # I placed this segment into the try/except pair due to an
                # exception that pops up at most once a day, where these
                # assignments return an out of range error
                # RAU exception always happen in 10.6

                self.osMinorver = parseLine[versionStringStart + 3]
                self.osRevver = parseLine[versionStringStart +
                                          5:versionStringStart + 7].strip(' ')
                self.osBuild = parseLine[int(parseLine.find('(')) +
                                         1:parseLine.find(')')]
            except:
                # This should catch this rare case. It's probably happening
                # due to a corrupt OS install on the client.
                # In this case, we'll just manually assign values
                # RAU so 10.6 will always report as 10.0
                notify.info(
                    "couldn't parse the system_profiler output, using zeros")
                self.osMinorver = '0'
                self.osRevver = '0'
                self.osBuild = '0000'
                testPlist = True
            del versionStringStart
            del parseLine
            del osxcmd

            if testPlist:
                try:
                    import plistlib
                    pl = plistlib.readPlist(
                        "/System/Library/CoreServices/SystemVersion.plist")
                    notify.info("pl=%s" % str(pl))
                    parseLine = pl['ProductVersion']
                    numbers = parseLine.split('.')
                    notify.info("parseline =%s numbers =%s" %
                                (parseLine, numbers))
                    self.osMinorver = numbers[1]
                    self.osRevver = numbers[2]
                    self.osBuild = pl["ProductBuildVersion"]
                except:
                    notify.info("tried plist but still got exception")
                    self.osMinorver = '0'
                    self.osRevver = '0'
                    self.osBuild = '0000'
            return

    def setmilestone(self, ms):
        if firstRun() == False:
            self.milestone = ms
        else:
            self.milestone = '%s_INITIAL' % (ms)

    def setgamename(self, gamename):
        self.gameName = gamename

    def printosComments(self):
        return self.osComments

    def setHost(self, hostID):
        assert hostID < len(
            self.hostDict
        ), "Error: hostID passed in UserTracker.setHost not valid, value to high"
        assert hostID > -1, "Error: hostID must be 0 or positive int"
        self.CurrentHost = hostID

    # This will go out to the download server and get the current Disney Funnel logging URL

    def getFunnelURL(self):
        # print 'VRS URL: ' + self.dynamicVRFunnel
        if (patcherVer() == ['OFFLINE']):
            # print "Funnel System Offline"
            return
        if (patcherVer() == []):
            # print "Funnel URL not set. Setting now"
            patcherHTTP = HTTPClient()
            if checkParamFile() == None:
                patcherDoc = patcherHTTP.getDocument(
                    URLSpec(
                        'http://download.toontown.com/english/currentVersion/content/patcher.ver'
                    ))
                # Now set vcon (Content Group) to the Release string
                vconGroup('w', self.cgRelease)
            else:
                patcherDoc = patcherHTTP.getDocument(URLSpec(checkParamFile()))
                # Set vcon (Content Group) to the Beta string
                vconGroup('w', self.cgBeta)
            # patcherDoc = patcherHTTP.getDocument(URLSpec('http://build64:3120/english/currentVersion/dev/content/patcher.ver'))
            rf = Ramfile()
            patcherDoc.downloadToRam(rf)
            self.patcherURL = rf.getData()
            if self.patcherURL.find('FUNNEL_LOG') == -1:
                # The file did not download, need to set
                # the patcherVer to offline
                patcherVer('w', 'OFFLINE')
                # print 'Patcher system could not be reached'
                return
            self.patcherURL = self.patcherURL.split('\n')
            del rf, patcherDoc, patcherHTTP
            while self.patcherURL:
                self.confLine = self.patcherURL.pop()
                if (self.confLine.find('FUNNEL_LOG=') != -1
                        and self.confLine.find('#FUNNEL_LOG=') == -1):
                    self.dynamicVRFunnel = self.confLine[11:].strip('\n')
                    patcherVer('w', self.confLine[11:].strip('\n'))
        else:
            self.dynamicVRFunnel = patcherVer()[0]

    def isVarSet(self, varInQuestion):
        try:
            tempvar = type(varInQuestion)
            return 1
        except NameError:
            return 0

    def buildURL(self):

        # A recent Hitbox Addition. We need to generate a variable/value pair.
        # The variable name depends on the OS. If the OS is win32, then the
        # variable name is c3. If the OS is darwin, then the variable name
        # is c4. The value to be passed to c3 and c4 is the same:
        # str(self.osMajorver) + '_' + str(self.osMinorver) + '_' + str(self.osRevver) + '_' + str(self.osBuild)

        if sys.platform == 'win32':
            hitboxOSType = 'c3'
        else:
            hitboxOSType = 'c4'

        # This will take all of the required variables and generate
        # A URL to be transmitted to the currently selected service
        # Host 1 is the hitbox URL config

        if (self.CurrentHost == 1):
            self.URLtoSend = 'http://' + self.hostDict[self.CurrentHost] + 'hb=' + str(
                self.hitboxAcct
            ) + '&n=' + str(
                self.milestone
            ) + '&ln=' + self.language + '&gp=STARTGAME&fnl=TOONTOWN_FUNNEL&vcon=/' + self.cgRoot + '/' + self.cgLocation + '/' + str(
                vconGroup()) + '&c1=' + str(
                    sys.platform) + '&' + str(hitboxOSType) + '=' + str(
                        self.osMajorver) + '_' + str(
                            self.osMinorver) + '_' + str(
                                self.osRevver) + '_' + str(self.osBuild)
            # print self.URLtoSend

        # Host 2 is for the Hitbox, with no funnel

        if (self.CurrentHost == 2):
            self.URLtoSend = 'http://' + self.hostDict[self.CurrentHost] + 'hb=' + str(
                self.hitboxAcct
            ) + '&n=' + str(
                self.milestone
            ) + '&ln=' + self.language + '&vcon=/' + self.cgRoot + '/' + self.cgLocation + '/' + str(
                vconGroup()) + '&c1=' + str(
                    sys.platform) + '&' + str(hitboxOSType) + '=' + str(
                        self.osMajorver) + '_' + str(
                            self.osMinorver) + '_' + str(
                                self.osRevver) + '_' + str(self.osBuild)
        # Host 3 is the disney logging server config.

        # if (self.CurrentHost == 3):
        # self.URLtoSend = 'http://' + self.hostDict[self.CurrentHost] + 'some_var_name=' + self.gameName

        #Need to add a bunch more. Just not sure of the variable names yet
        # This host is for the internal server

        if (self.CurrentHost == 0):
            localMAC = str(getMAC())
            self.URLtoSend = str(self.dynamicVRFunnel) + '?funnel=' + str(
                self.milestone
            ) + '&platform=' + str(sys.platform) + '&sysver=' + str(
                self.osMajorver) + '_' + str(self.osMinorver) + '_' + str(
                    self.osRevver) + '_' + str(
                        self.osBuild
                    ) + '&mac=' + localMAC + '&username='******'&id=' + str(loggingAvID())

    def readInPandaCookie(self):
        # This function is designed to read in the cookie format that
        # the panda HTTPClient uses.
        # The format is as follows:
        # DOMAINAME<TAB>/<TAB>VARIABLE<TAB>VALUE<\n>
        # EXAMPLE:
        # .hitbox.com     /     CTG     1181271609

        thefile = open(self.cfCookieFile, 'r')
        thedata = thefile.read().split('\n')
        thefile.close()
        del thefile
        # Before we go any further, lets check to see if the file is using
        # the old Netscape HTTP format the python's MozillaCookie Jar
        # supports. If so, lets delete the file and re-populate with
        # a new cookie from the server
        if (thedata[0].find('Netscape HTTP Cookie File') != -1):
            return
        # Pop off last element; it's blank
        thedata.pop()
        try:
            while thedata:
                temp = thedata.pop()
                # if temp.find('.hitbox.com') != -1 or temp.find('ehg-dig.hitbox.com') != -1:
                temp = temp.split('\t')
                domain = temp[0]
                loc = temp[1]
                variable = temp[2]
                value = temp[3]

                if (variable == 'CTG'):
                    self.pandaHTTPClientVarCTG = [domain, loc, variable, value]
                    self.setTheHTTPCookie(self.pandaHTTPClientVarCTG)
                if (variable == self.hitboxAcct + 'V6'):
                    self.pandaHTTPClientVarDM = [domain, loc, variable, value]
                    self.setTheHTTPCookie(self.pandaHTTPClientVarDM)
                if (variable == 'WSS_GW'):
                    self.pandaHTTPClientVarWSS = [domain, loc, variable, value]
                    self.setTheHTTPCookie(self.pandaHTTPClientVarWSS)
        except IndexError:
            print "UserFunnel(Warning): Cookie Data file bad"

        del thedata

    def updateInstanceCookieValues(self):
        a = self.httpSession.getCookie(HTTPCookie('WSS_GW', '/',
                                                  '.hitbox.com'))
        if a.getName():
            self.pandaHTTPClientVarWSS = [
                '.hitbox.com', '/', 'WSS_GW',
                a.getValue()
            ]
        else:
            # print 'WSS_GW Cookie Value not set'
            pass

        b = self.httpSession.getCookie(HTTPCookie('CTG', '/', '.hitbox.com'))
        if b.getName():
            self.pandaHTTPClientVarCTG = [
                '.hitbox.com', '/', 'CTG',
                b.getValue()
            ]
        else:
            # print 'CTG Cookie Value not set'
            pass

        c = self.httpSession.getCookie(
            HTTPCookie(self.hitboxAcct + 'V6', '/', 'ehg-dig.hitbox.com'))
        if c.getName():
            self.pandaHTTPClientVarDM = [
                'ehg-dig.hitbox.com', '/', self.hitboxAcct + 'V6',
                c.getValue()
            ]
        else:
            #print self.hitboxAcct + 'V6 Cookie Value not set'
            pass

        del a, b, c

    def setTheHTTPCookie(self, cookieParams):
        c = HTTPCookie(cookieParams[2], cookieParams[1], cookieParams[0])
        c.setValue(cookieParams[3])
        self.httpSession.setCookie(c)

    def writeOutPandaCookie(self):
        # This is designed to write out a cookie file in the format that
        # the panda HTTPClient uses.
        # Please see the readInPandaCookie comments for format.

        try:
            thefile = open(self.cfCookieFile, 'w')
            if len(self.pandaHTTPClientVarWSS) == 4:
                thefile.write(self.pandaHTTPClientVarWSS[0] + '\t' +
                              self.pandaHTTPClientVarWSS[1] + '\t' +
                              self.pandaHTTPClientVarWSS[2] + '\t' +
                              self.pandaHTTPClientVarWSS[3] + '\n')
            if len(self.pandaHTTPClientVarCTG) == 4:
                thefile.write(self.pandaHTTPClientVarCTG[0] + '\t' +
                              self.pandaHTTPClientVarCTG[1] + '\t' +
                              self.pandaHTTPClientVarCTG[2] + '\t' +
                              self.pandaHTTPClientVarCTG[3] + '\n')
            if len(self.pandaHTTPClientVarDM) == 4:
                thefile.write(self.pandaHTTPClientVarDM[0] + '\t' +
                              self.pandaHTTPClientVarDM[1] + '\t' +
                              self.pandaHTTPClientVarDM[2] + '\t' +
                              self.pandaHTTPClientVarDM[3] + '\n')
            thefile.close()
        except IOError:
            return

    # The next function spawns another thread and executed the network
    # transaction; i.e. host resolve, open connection, send, close, etc.
    # Update, the threading has been disbaled for the time being.

    def prerun(self):

        # print "Begin Hitbox Thread"
        # Use start() method to execute this run() function in second thread

        # Commented out the next line (if statement) on 9-10-07,
        # and moved the indent on self.getFunnelURL to the left.
        # It looks like due to changes in the function that gets the
        # patcher.ver, it is no longer necessary to only check the FunnelURL
        # status when the CurrentHost is 0. The getFunnelURL() should be
        # called no mater what the CurrentHost is set to. I think that it was
        # only checking when CurrentHost == 0, due to some URLs being
        # hardcoded in previous versions of the logging module. But that
        # is no longer the case for the VRS collector.

        # if (self.CurrentHost == 0):
        self.getFunnelURL()

        # print "build url"
        self.buildURL()
        if (os.path.isfile(self.cfCookieFile) == True):
            # print "load preexisting cookie"
            # self.cfCookie.load()
            if self.CurrentHost == 1 or self.CurrentHost == 2:
                self.readInPandaCookie()
        # print "Cookies before transaction"
        # self.httpSession.writeCookies(ostream)
        # print "Cookie Header Line"
        # self.httpSession.sendCookies(ostream, URLSpec(self.URLtoSend))

    def run(self):

        # Here is where the new Panda based HTTP code starts

        # But before we hit the URL, let make sure we need to.
        # Lets check to see if the VRS Collector is OFFLINE and
        # host type 0 was selected. If that is the case, we can just
        # return here; nothing needs to be done.

        if self.CurrentHost == 0 and patcherVer() == ['OFFLINE']:
            return

        # Hit the URL
        # The next line uses the Panda HTTP lib (blocking)
        # doc = self.httpSession.getDocument(URLSpec(self.URLtoSend))

        # Next line uses non-blocking

        self.nonBlock = self.httpSession.makeChannel(False)
        # nonBlock.setHttpTimeout(1)
        # nonBlock.setConnectTimeout(.5)
        # nonBlock.setBlockingConnect(False)
        # doc = nonBlock.getDocument(DocumentSpec(self.URLtoSend))
        self.nonBlock.beginGetDocument(DocumentSpec(self.URLtoSend))

        instanceMarker = str(random.randint(1, 1000))

        instanceMarker = 'FunnelLoggingRequest-%s' % instanceMarker

        self.startCheckingAsyncRequest(instanceMarker)

        # That's it. The server should have recorded the hit
        # delete the object
        # del doc

        # print "The Funnel URL could not be accessed"
        # if (self.CurrentHost == 0):
        #    patcherVer('w','OFFLINE')
        # For testing, write out all cookies in memory
        # print "Cookies after Transaction"
        # self.httpSession.writeCookies(ostream)

        # Commented out the following, moved it to the taskMgr call
        # if self.CurrentHost == 1 or self.CurrentHost == 2:
        # self.updateInstanceCookieValues()
        # self.writeOutPandaCookie()

        # Now lets do a check to see if the string LEAK is in the milestone
        # If LEAK is present, then we will also call the memory leak report
        # function to submit a report.

        # if self.milestone.find('LEAK') != -1:
        # reportMemoryLeaks()

    def startCheckingAsyncRequest(self, name):
        taskMgr.remove(name)
        # print "Starting Checking Async Request"
        taskMgr.doMethodLater(0.5, self.pollFunnelTask, name)

    def stopCheckingFunnelTask(self, name):
        taskMgr.remove('pollFunnelTask')

    def pollFunnelTask(self, task):
        # print "Polling....."
        result = self.nonBlock.run()
        if result == 0:
            # print "Result = 0, Done"
            # Funnel request complete
            self.stopCheckingFunnelTask(task)
            if self.CurrentHost == 1 or self.CurrentHost == 2:
                self.updateInstanceCookieValues()
                self.writeOutPandaCookie()
        else:
            return Task.again
Ejemplo n.º 4
0
class UserFunnel:
    def __init__(self):
        self.hitboxAcct = 'DM560804E8WD'
        self.omniAccount = 'wdgdolpironl,wdgdsec'
        self.language = 'en-us'
        self.cgRoot = 'Pirates_Online'
        self.cgBeta = 'Beta'
        self.cgRelease = 'Release'
        self.cgLocation = 'US'
        self.ogBeta = 'pir_onl_beta'
        self.ogRelease = 'pir_onl'
        self.ogLocation = 'us'
        self.campaignID = ''
        self.cfCookieFile = 'cf.txt'
        self.cfCookieFileOmniture = 'cf2.txt'
        self.dynamicVRFunnel = 'http://download.pirates.com/'
        self.hostDict = {
            0: 'Internal Disney PHP Collector Site',
            1: 'ehg-dig.hitbox.com/HG?',
            2: 'ehg-dig.hitbox.com/HG?',
            3: 'w88.go.com/b/ss/'
        }
        self.CurrentHost = ''
        self.URLtoSend = ''
        self.gameName = 'Pirates'
        self.browserName = 'Panda3D%20(' + self.gameName + ';%20' + sys.platform + ')'
        self.HTTPUserHeader = [('User-agent', 'Panda3D')]
        self.osMajorver = ''
        self.osMinorver = ''
        self.osRevver = ''
        self.osBuild = ''
        self.osType = ''
        self.osComments = ''
        self.msWinTypeDict = {
            0: 'Win32s on Windows 3.1',
            1: 'Windows 95/98/ME',
            2: 'Windows NT/2000/XP',
            3: 'Windows CE'
        }
        self.milestoneDict = {
            0: 'New User',
            1: 'Create Account',
            2: 'View EULA',
            3: 'Accept EULA',
            4: 'Download Start',
            5: 'Download End',
            6: 'Installer Run',
            7: 'Launcher Start',
            8: 'Launcher Login',
            9: 'Client Opens',
            10: 'Create Pirate Loads',
            11: 'Create Pirate Exit',
            12: 'Cutscene One Start',
            13: 'Cutscene One Ends',
            14: 'Cutscene Two Start',
            15: 'Cutscene Thee Start',
            16: 'Cutscene Three Ends',
            17: 'Access Cannon',
            18: 'Cutscene Four Starts',
            19: 'Cutscene Four Ends',
            20: 'Dock - Start Game'
        }
        self.macTypeDict = {
            2: 'Jaguar',
            1: 'Puma',
            3: 'Panther',
            4: 'Tiger',
            5: 'Lepard'
        }
        self.milestone = ''
        self.pandaHTTPClientVarWSS = []
        self.pandaHTTPClientVarCTG = []
        self.pandaHTTPClientVarDM = []
        self.pandaHTTPClientVarSVI = []
        self.checkForCFfile()
        self.httpSession = HTTPClient()
        self.whatOSver()

    def checkForCFfile(self):
        if firstRun() == True:
            pass
        1
        if os.path.isfile(self.cfCookieFile) == False:
            firstRun('write', True)

    def whatOSver(self):
        if sys.platform == 'win32':
            self.osMajorver = str(sys.getwindowsversion()[0])
            self.osMinorver = str(sys.getwindowsversion()[1])
            self.osBuild = str(sys.getwindowsversion()[2])
            self.osType = str(sys.getwindowsversion()[3])
            self.osComments = str(sys.getwindowsversion()[4])
        elif sys.platform == 'darwin':
            self.osMajorver = '10'
            osxcmd = '/usr/sbin/system_profiler SPSoftwareDataType |/usr/bin/grep "System Version"'
            infopipe = os.popen(osxcmd, 'r')
            parseLine = infopipe.read()
            infopipe.close()
            del infopipe
            versionStringStart = parseLine.find('10.')

            try:
                self.osMinorver = parseLine[versionStringStart + 3]
                self.osRevver = parseLine[versionStringStart +
                                          5:versionStringStart + 7].strip(' ')
                self.osBuild = parseLine[int(parseLine.find('(')) +
                                         1:parseLine.find(')')]
            except:
                self.osMinorver = '0'
                self.osRevver = '0'
                self.osBuild = '0000'

            del versionStringStart
            del parseLine
            del osxcmd
        elif sys.platform == 'linux2':
            self.osMinorver = '0'
            self.osRevver = '0'
            self.osBuild = '0000'

    def setmilestone(self, ms):
        if firstRun() == False:
            self.milestone = ms
        else:
            self.milestone = '%s_INITIAL' % ms

    def setgamename(self, gamename):
        self.gameName = gamename

    def printosComments(self):
        return self.osComments

    def setHost(self, hostID):
        self.CurrentHost = hostID

    def getFunnelURL(self):
        if patcherVer() == ['OFFLINE']:
            return None

        if patcherVer() == []:
            patcherHTTP = HTTPClient()
            if checkParamFile() == None:
                patcherDoc = patcherHTTP.getDocument(
                    URLSpec(
                        'http://download.piratesonline.com/english/currentVersion/content/patcher.ver'
                    ))
                vconGroup('w', self.cgRelease)
                oconGroup('w', self.ogRelease)
            else:
                patcherDoc = patcherHTTP.getDocument(URLSpec(checkParamFile()))
                vconGroup('w', self.cgBeta)
                oconGroup('w', self.ogBeta)
            rf = Ramfile()
            patcherDoc.downloadToRam(rf)
            self.patcherURL = rf.getData()
            if self.patcherURL.find('FUNNEL_LOG') == -1:
                patcherVer('w', 'OFFLINE')
                return None

            self.patcherURL = self.patcherURL.split('\n')
            del rf
            del patcherDoc
            del patcherHTTP
            while self.patcherURL:
                self.confLine = self.patcherURL.pop()
                if self.confLine.find(
                        'FUNNEL_LOG=') != -1 and self.confLine.find(
                            '#FUNNEL_LOG=') == -1:
                    self.dynamicVRFunnel = self.confLine[11:].strip('\n')
                    patcherVer('w', self.confLine[11:].strip('\n'))
                    continue
        else:
            self.dynamicVRFunnel = patcherVer()[0]

    def isVarSet(self, varInQuestion):

        try:
            tempvar = type(varInQuestion)
            return 1
        except NameError:
            return 0

    def buildURL(self):
        if sys.platform == 'win32':
            hitboxOSType = 'c3'
        elif sys.platform == 'darwin':
            hitboxOSType = 'c4'
        elif sys.platform == 'linux2':
            hitboxOSType = 'c4'

        if self.CurrentHost == 1:
            self.URLtoSend = 'http://' + self.hostDict[self.CurrentHost] + 'hb=' + str(
                self.hitboxAcct
            ) + '&n=' + str(
                self.milestone
            ) + '&ln=' + self.language + '&gp=STARTGAME_DOCK&fnl=PIRATES_FUNNEL&vcon=/' + self.cgRoot + '/' + self.cgLocation + '/' + str(
                vconGroup()) + '&c1=' + str(
                    sys.platform) + '&' + str(hitboxOSType) + '=' + str(
                        self.osMajorver) + '_' + str(
                            self.osMinorver) + '_' + str(
                                self.osRevver) + '_' + str(self.osBuild)

        if self.CurrentHost == 2:
            self.URLtoSend = 'http://' + self.hostDict[self.CurrentHost] + 'hb=' + str(
                self.hitboxAcct
            ) + '&n=' + str(
                self.milestone
            ) + '&ln=' + self.language + '&vcon=/' + self.cgRoot + '/' + self.cgLocation + '/' + str(
                vconGroup()) + '&c1=' + str(
                    sys.platform) + '&' + str(hitboxOSType) + '=' + str(
                        self.osMajorver) + '_' + str(
                            self.osMinorver) + '_' + str(
                                self.osRevver) + '_' + str(self.osBuild)

        if self.CurrentHost == 3:
            self.URLtoSend = 'http://' + self.hostDict[
                self.
                CurrentHost] + self.omniAccount + '/1/H.15.1/' + self.cacheBuster(
                ) + '?[AQB]&ns=dol&pageName=dgame%3Apir_onl%3Ammog%3A' + str(
                    self.milestone
                ).lower() + '&c1=' + str(
                    oconGroup()
                ) + '&c14=dgame&h1=mmog&c11=pir&c4=in_game&c25=' + self.ogLocation + '&v25=' + self.ogLocation + '[AQE]'

        if self.CurrentHost == 0:
            localMAC = str(getMAC())
            self.URLtoSend = str(self.dynamicVRFunnel) + '?funnel=' + str(
                self.milestone
            ) + '&platform=' + str(sys.platform) + '&sysver=' + str(
                self.osMajorver) + '_' + str(self.osMinorver) + '_' + str(
                    self.osRevver) + '_' + str(
                        self.osBuild
                    ) + '&mac=' + localMAC + '&username='******'&id=' + str(loggingAvID())

    def readInPandaCookie(self):
        thefile = open(self.cfCookieFile, 'r')
        thedata = thefile.read().split('\n')
        thefile.close()
        del thefile
        if thedata[0].find('Netscape HTTP Cookie File') != -1:
            return None

        thedata.pop()

        try:
            while thedata:
                temp = thedata.pop()
                temp = temp.split('\t')
                domain = temp[0]
                loc = temp[1]
                variable = temp[2]
                value = temp[3]
                if variable == 'CTG':
                    self.pandaHTTPClientVarCTG = [domain, loc, variable, value]
                    self.setTheHTTPCookie(self.pandaHTTPClientVarCTG)

                if variable == self.hitboxAcct + 'V6':
                    self.pandaHTTPClientVarDM = [domain, loc, variable, value]
                    self.setTheHTTPCookie(self.pandaHTTPClientVarDM)

                if variable == 'WSS_GW':
                    self.pandaHTTPClientVarWSS = [domain, loc, variable, value]
                    self.setTheHTTPCookie(self.pandaHTTPClientVarWSS)
                    continue
        except IndexError:
            print 'UserFunnel(Warning): Cookie Data file bad'

        del thedata

    def readInPandaCookieOmniture(self):
        thefile = open(self.cfCookieFileOmniture, 'r')
        thedata = thefile.read().split('\n')
        thefile.close()
        del thefile
        if thedata[0].find('Netscape HTTP Cookie File') != -1:
            return None

        thedata.pop()

        try:
            while thedata:
                temp = thedata.pop()
                temp = temp.split('\t')
                domain = temp[0]
                loc = temp[1]
                variable = temp[2]
                value = temp[3]
                if variable == 's_vi':
                    self.pandaHTTPClientVarSVI = [domain, loc, variable, value]
                    self.setTheHTTPCookie(self.pandaHTTPClientVarSVI)
                    continue
        except IndexError:
            print 'UserFunnel(Warning): Omniture Cookie Data file bad'

        del thedata

    def updateInstanceCookieValues(self):
        a = self.httpSession.getCookie(HTTPCookie('WSS_GW', '/',
                                                  '.hitbox.com'))
        if a.getName():
            self.pandaHTTPClientVarWSS = [
                '.hitbox.com', '/', 'WSS_GW',
                a.getValue()
            ]

        b = self.httpSession.getCookie(HTTPCookie('CTG', '/', '.hitbox.com'))
        if b.getName():
            self.pandaHTTPClientVarCTG = [
                '.hitbox.com', '/', 'CTG',
                b.getValue()
            ]

        c = self.httpSession.getCookie(
            HTTPCookie(self.hitboxAcct + 'V6', '/', '.ehg-dig.hitbox.com'))
        if c.getName():
            self.pandaHTTPClientVarDM = [
                '.ehg-dig.hitbox.com', '/', self.hitboxAcct + 'V6',
                c.getValue()
            ]

        del a
        del b
        del c

    def updateInstanceCookieValuesOmniture(self):
        a = self.httpSession.getCookie(HTTPCookie('s_vi', '/', '.go.com'))
        if a.getName():
            self.pandaHTTPClientVarSVI = ['.go.com', '/', 's_vi', a.getValue()]

        del a

    def setTheHTTPCookie(self, cookieParams):
        c = HTTPCookie(cookieParams[2], cookieParams[1], cookieParams[0])
        c.setValue(cookieParams[3])
        self.httpSession.setCookie(c)

    def writeOutPandaCookie(self):

        try:
            thefile = open(self.cfCookieFile, 'w')
            if len(self.pandaHTTPClientVarWSS) == 4:
                thefile.write(self.pandaHTTPClientVarWSS[0] + '\t' +
                              self.pandaHTTPClientVarWSS[1] + '\t' +
                              self.pandaHTTPClientVarWSS[2] + '\t' +
                              self.pandaHTTPClientVarWSS[3] + '\n')

            if len(self.pandaHTTPClientVarCTG) == 4:
                thefile.write(self.pandaHTTPClientVarCTG[0] + '\t' +
                              self.pandaHTTPClientVarCTG[1] + '\t' +
                              self.pandaHTTPClientVarCTG[2] + '\t' +
                              self.pandaHTTPClientVarCTG[3] + '\n')

            if len(self.pandaHTTPClientVarDM) == 4:
                thefile.write(self.pandaHTTPClientVarDM[0] + '\t' +
                              self.pandaHTTPClientVarDM[1] + '\t' +
                              self.pandaHTTPClientVarDM[2] + '\t' +
                              self.pandaHTTPClientVarDM[3] + '\n')

            thefile.close()
        except IOError:
            return None

    def writeOutPandaCookieOmniture(self):

        try:
            thefile = open(self.cfCookieFileOmniture, 'w')
            if len(self.pandaHTTPClientVarSVI) == 4:
                thefile.write(self.pandaHTTPClientVarSVI[0] + '\t' +
                              self.pandaHTTPClientVarSVI[1] + '\t' +
                              self.pandaHTTPClientVarSVI[2] + '\t' +
                              self.pandaHTTPClientVarSVI[3] + '\n')

            thefile.close()
        except IOError:
            return None

    def prerun(self):
        self.getFunnelURL()
        self.buildURL()
        if os.path.isfile(self.cfCookieFile) == True:
            if self.CurrentHost == 1 or self.CurrentHost == 2:
                self.readInPandaCookie()

        if os.path.isfile(
                self.cfCookieFileOmniture) == True and self.CurrentHost == 3:
            self.readInPandaCookieOmniture()

    def run(self):
        if self.CurrentHost == 0 and patcherVer() == ['OFFLINE']:
            return None

        self.nonBlock = self.httpSession.makeChannel(False)
        self.nonBlock.beginGetDocument(DocumentSpec(self.URLtoSend))
        instanceMarker = str(random.randint(1, 1000))
        instanceMarker = 'FunnelLoggingRequest-%s' % instanceMarker
        self.startCheckingAsyncRequest(instanceMarker)

    def startCheckingAsyncRequest(self, name):
        taskMgr.remove(name)
        taskMgr.doMethodLater(0.5, self.pollFunnelTask, name)

    def stopCheckingFunnelTask(self, name):
        taskMgr.remove('pollFunnelTask')

    def pollFunnelTask(self, task):
        result = self.nonBlock.run()
        if result == 0:
            self.stopCheckingFunnelTask(task)
            if self.CurrentHost == 1 or self.CurrentHost == 2:
                self.updateInstanceCookieValues()
                self.writeOutPandaCookie()

            if self.CurrentHost == 3:
                self.updateInstanceCookieValuesOmniture()
                self.writeOutPandaCookieOmniture()

        else:
            return Task.again

    def cacheBuster(self):
        return str(time.time())
class UserFunnel:

    def __init__(self):
        self.hitboxAcct = 'DM560804E8WD'
        self.omniAccount = 'wdgdolpironl,wdgdsec'
        self.language = 'en-us'
        self.cgRoot = 'Pirates_Online'
        self.cgBeta = 'Beta'
        self.cgRelease = 'Release'
        self.cgLocation = 'US'
        self.ogBeta = 'pir_onl_beta'
        self.ogRelease = 'pir_onl'
        self.ogLocation = 'us'
        self.campaignID = ''
        self.cfCookieFile = 'cf.txt'
        self.cfCookieFileOmniture = 'cf2.txt'
        self.dynamicVRFunnel = 'http://download.pirates.com/'
        self.hostDict = {
            0: 'Internal Disney PHP Collector Site',
            1: 'ehg-dig.hitbox.com/HG?',
            2: 'ehg-dig.hitbox.com/HG?',
            3: 'w88.go.com/b/ss/' }
        self.CurrentHost = ''
        self.URLtoSend = ''
        self.gameName = 'Pirates'
        self.browserName = 'Panda3D%20(' + self.gameName + ';%20' + sys.platform + ')'
        self.HTTPUserHeader = [
            ('User-agent', 'Panda3D')]
        self.osMajorver = ''
        self.osMinorver = ''
        self.osRevver = ''
        self.osBuild = ''
        self.osType = ''
        self.osComments = ''
        self.msWinTypeDict = {
            0: 'Win32s on Windows 3.1',
            1: 'Windows 95/98/ME',
            2: 'Windows NT/2000/XP',
            3: 'Windows CE' }
        self.milestoneDict = {
            0: 'New User',
            1: 'Create Account',
            2: 'View EULA',
            3: 'Accept EULA',
            4: 'Download Start',
            5: 'Download End',
            6: 'Installer Run',
            7: 'Launcher Start',
            8: 'Launcher Login',
            9: 'Client Opens',
            10: 'Create Pirate Loads',
            11: 'Create Pirate Exit',
            12: 'Cutscene One Start',
            13: 'Cutscene One Ends',
            14: 'Cutscene Two Start',
            15: 'Cutscene Thee Start',
            16: 'Cutscene Three Ends',
            17: 'Access Cannon',
            18: 'Cutscene Four Starts',
            19: 'Cutscene Four Ends',
            20: 'Dock - Start Game' }
        self.macTypeDict = {
            2: 'Jaguar',
            1: 'Puma',
            3: 'Panther',
            4: 'Tiger',
            5: 'Lepard' }
        self.milestone = ''
        self.pandaHTTPClientVarWSS = []
        self.pandaHTTPClientVarCTG = []
        self.pandaHTTPClientVarDM = []
        self.pandaHTTPClientVarSVI = []
        self.checkForCFfile()
        self.httpSession = HTTPClient()
        self.whatOSver()


    def checkForCFfile(self):
        if firstRun() == True:
            pass
        1
        if os.path.isfile(self.cfCookieFile) == False:
            firstRun('write', True)



    def whatOSver(self):
        if sys.platform == 'win32':
            self.osMajorver = str(sys.getwindowsversion()[0])
            self.osMinorver = str(sys.getwindowsversion()[1])
            self.osBuild = str(sys.getwindowsversion()[2])
            self.osType = str(sys.getwindowsversion()[3])
            self.osComments = str(sys.getwindowsversion()[4])
        elif sys.platform == 'darwin':
            self.osMajorver = '10'
            osxcmd = '/usr/sbin/system_profiler SPSoftwareDataType |/usr/bin/grep "System Version"'
            infopipe = os.popen(osxcmd, 'r')
            parseLine = infopipe.read()
            infopipe.close()
            del infopipe
            versionStringStart = parseLine.find('10.')

            try:
                self.osMinorver = parseLine[versionStringStart + 3]
                self.osRevver = parseLine[versionStringStart + 5:versionStringStart + 7].strip(' ')
                self.osBuild = parseLine[int(parseLine.find('(')) + 1:parseLine.find(')')]
            except:
                self.osMinorver = '0'
                self.osRevver = '0'
                self.osBuild = '0000'

            del versionStringStart
            del parseLine
            del osxcmd
        elif sys.platform == 'linux2':
            self.osMinorver = '0'
            self.osRevver = '0'
            self.osBuild = '0000'



    def setmilestone(self, ms):
        if firstRun() == False:
            self.milestone = ms
        else:
            self.milestone = '%s_INITIAL' % ms


    def setgamename(self, gamename):
        self.gameName = gamename


    def printosComments(self):
        return self.osComments


    def setHost(self, hostID):
        self.CurrentHost = hostID


    def getFunnelURL(self):
        if patcherVer() == [
            'OFFLINE']:
            return None

        if patcherVer() == []:
            patcherHTTP = HTTPClient()
            if checkParamFile() == None:
                patcherDoc = patcherHTTP.getDocument(URLSpec('http://download.piratesonline.com/english/currentVersion/content/patcher.ver'))
                vconGroup('w', self.cgRelease)
                oconGroup('w', self.ogRelease)
            else:
                patcherDoc = patcherHTTP.getDocument(URLSpec(checkParamFile()))
                vconGroup('w', self.cgBeta)
                oconGroup('w', self.ogBeta)
            rf = Ramfile()
            patcherDoc.downloadToRam(rf)
            self.patcherURL = rf.getData()
            if self.patcherURL.find('FUNNEL_LOG') == -1:
                patcherVer('w', 'OFFLINE')
                return None

            self.patcherURL = self.patcherURL.split('\n')
            del rf
            del patcherDoc
            del patcherHTTP
            while self.patcherURL:
                self.confLine = self.patcherURL.pop()
                if self.confLine.find('FUNNEL_LOG=') != -1 and self.confLine.find('#FUNNEL_LOG=') == -1:
                    self.dynamicVRFunnel = self.confLine[11:].strip('\n')
                    patcherVer('w', self.confLine[11:].strip('\n'))
                    continue
        else:
            self.dynamicVRFunnel = patcherVer()[0]


    def isVarSet(self, varInQuestion):

        try:
            tempvar = type(varInQuestion)
            return 1
        except NameError:
            return 0



    def buildURL(self):
        if sys.platform == 'win32':
            hitboxOSType = 'c3'
        elif sys.platform == 'darwin':
            hitboxOSType = 'c4'
        elif sys.platform == 'linux2':
            hitboxOSType = 'c4'

        if self.CurrentHost == 1:
            self.URLtoSend = 'http://' + self.hostDict[self.CurrentHost] + 'hb=' + str(self.hitboxAcct) + '&n=' + str(self.milestone) + '&ln=' + self.language + '&gp=STARTGAME_DOCK&fnl=PIRATES_FUNNEL&vcon=/' + self.cgRoot + '/' + self.cgLocation + '/' + str(vconGroup()) + '&c1=' + str(sys.platform) + '&' + str(hitboxOSType) + '=' + str(self.osMajorver) + '_' + str(self.osMinorver) + '_' + str(self.osRevver) + '_' + str(self.osBuild)

        if self.CurrentHost == 2:
            self.URLtoSend = 'http://' + self.hostDict[self.CurrentHost] + 'hb=' + str(self.hitboxAcct) + '&n=' + str(self.milestone) + '&ln=' + self.language + '&vcon=/' + self.cgRoot + '/' + self.cgLocation + '/' + str(vconGroup()) + '&c1=' + str(sys.platform) + '&' + str(hitboxOSType) + '=' + str(self.osMajorver) + '_' + str(self.osMinorver) + '_' + str(self.osRevver) + '_' + str(self.osBuild)

        if self.CurrentHost == 3:
            self.URLtoSend = 'http://' + self.hostDict[self.CurrentHost] + self.omniAccount + '/1/H.15.1/' + self.cacheBuster() + '?[AQB]&ns=dol&pageName=dgame%3Apir_onl%3Ammog%3A' + str(self.milestone).lower() + '&c1=' + str(oconGroup()) + '&c14=dgame&h1=mmog&c11=pir&c4=in_game&c25=' + self.ogLocation + '&v25=' + self.ogLocation + '[AQE]'

        if self.CurrentHost == 0:
            localMAC = str(getMAC())
            self.URLtoSend = str(self.dynamicVRFunnel) + '?funnel=' + str(self.milestone) + '&platform=' + str(sys.platform) + '&sysver=' + str(self.osMajorver) + '_' + str(self.osMinorver) + '_' + str(self.osRevver) + '_' + str(self.osBuild) + '&mac=' + localMAC + '&username='******'&id=' + str(loggingAvID())



    def readInPandaCookie(self):
        thefile = open(self.cfCookieFile, 'r')
        thedata = thefile.read().split('\n')
        thefile.close()
        del thefile
        if thedata[0].find('Netscape HTTP Cookie File') != -1:
            return None

        thedata.pop()

        try:
            while thedata:
                temp = thedata.pop()
                temp = temp.split('\t')
                domain = temp[0]
                loc = temp[1]
                variable = temp[2]
                value = temp[3]
                if variable == 'CTG':
                    self.pandaHTTPClientVarCTG = [
                        domain,
                        loc,
                        variable,
                        value]
                    self.setTheHTTPCookie(self.pandaHTTPClientVarCTG)

                if variable == self.hitboxAcct + 'V6':
                    self.pandaHTTPClientVarDM = [
                        domain,
                        loc,
                        variable,
                        value]
                    self.setTheHTTPCookie(self.pandaHTTPClientVarDM)

                if variable == 'WSS_GW':
                    self.pandaHTTPClientVarWSS = [
                        domain,
                        loc,
                        variable,
                        value]
                    self.setTheHTTPCookie(self.pandaHTTPClientVarWSS)
                    continue
        except IndexError:
            print 'UserFunnel(Warning): Cookie Data file bad'

        del thedata


    def readInPandaCookieOmniture(self):
        thefile = open(self.cfCookieFileOmniture, 'r')
        thedata = thefile.read().split('\n')
        thefile.close()
        del thefile
        if thedata[0].find('Netscape HTTP Cookie File') != -1:
            return None

        thedata.pop()

        try:
            while thedata:
                temp = thedata.pop()
                temp = temp.split('\t')
                domain = temp[0]
                loc = temp[1]
                variable = temp[2]
                value = temp[3]
                if variable == 's_vi':
                    self.pandaHTTPClientVarSVI = [
                        domain,
                        loc,
                        variable,
                        value]
                    self.setTheHTTPCookie(self.pandaHTTPClientVarSVI)
                    continue
        except IndexError:
            print 'UserFunnel(Warning): Omniture Cookie Data file bad'

        del thedata


    def updateInstanceCookieValues(self):
        a = self.httpSession.getCookie(HTTPCookie('WSS_GW', '/', '.hitbox.com'))
        if a.getName():
            self.pandaHTTPClientVarWSS = [
                '.hitbox.com',
                '/',
                'WSS_GW',
                a.getValue()]

        b = self.httpSession.getCookie(HTTPCookie('CTG', '/', '.hitbox.com'))
        if b.getName():
            self.pandaHTTPClientVarCTG = [
                '.hitbox.com',
                '/',
                'CTG',
                b.getValue()]

        c = self.httpSession.getCookie(HTTPCookie(self.hitboxAcct + 'V6', '/', '.ehg-dig.hitbox.com'))
        if c.getName():
            self.pandaHTTPClientVarDM = [
                '.ehg-dig.hitbox.com',
                '/',
                self.hitboxAcct + 'V6',
                c.getValue()]

        del a
        del b
        del c


    def updateInstanceCookieValuesOmniture(self):
        a = self.httpSession.getCookie(HTTPCookie('s_vi', '/', '.go.com'))
        if a.getName():
            self.pandaHTTPClientVarSVI = [
                '.go.com',
                '/',
                's_vi',
                a.getValue()]

        del a


    def setTheHTTPCookie(self, cookieParams):
        c = HTTPCookie(cookieParams[2], cookieParams[1], cookieParams[0])
        c.setValue(cookieParams[3])
        self.httpSession.setCookie(c)


    def writeOutPandaCookie(self):

        try:
            thefile = open(self.cfCookieFile, 'w')
            if len(self.pandaHTTPClientVarWSS) == 4:
                thefile.write(self.pandaHTTPClientVarWSS[0] + '\t' + self.pandaHTTPClientVarWSS[1] + '\t' + self.pandaHTTPClientVarWSS[2] + '\t' + self.pandaHTTPClientVarWSS[3] + '\n')

            if len(self.pandaHTTPClientVarCTG) == 4:
                thefile.write(self.pandaHTTPClientVarCTG[0] + '\t' + self.pandaHTTPClientVarCTG[1] + '\t' + self.pandaHTTPClientVarCTG[2] + '\t' + self.pandaHTTPClientVarCTG[3] + '\n')

            if len(self.pandaHTTPClientVarDM) == 4:
                thefile.write(self.pandaHTTPClientVarDM[0] + '\t' + self.pandaHTTPClientVarDM[1] + '\t' + self.pandaHTTPClientVarDM[2] + '\t' + self.pandaHTTPClientVarDM[3] + '\n')

            thefile.close()
        except IOError:
            return None



    def writeOutPandaCookieOmniture(self):

        try:
            thefile = open(self.cfCookieFileOmniture, 'w')
            if len(self.pandaHTTPClientVarSVI) == 4:
                thefile.write(self.pandaHTTPClientVarSVI[0] + '\t' + self.pandaHTTPClientVarSVI[1] + '\t' + self.pandaHTTPClientVarSVI[2] + '\t' + self.pandaHTTPClientVarSVI[3] + '\n')

            thefile.close()
        except IOError:
            return None



    def prerun(self):
        self.getFunnelURL()
        self.buildURL()
        if os.path.isfile(self.cfCookieFile) == True:
            if self.CurrentHost == 1 or self.CurrentHost == 2:
                self.readInPandaCookie()


        if os.path.isfile(self.cfCookieFileOmniture) == True and self.CurrentHost == 3:
            self.readInPandaCookieOmniture()



    def run(self):
        if self.CurrentHost == 0 and patcherVer() == [
            'OFFLINE']:
            return None

        self.nonBlock = self.httpSession.makeChannel(False)
        self.nonBlock.beginGetDocument(DocumentSpec(self.URLtoSend))
        instanceMarker = str(random.randint(1, 1000))
        instanceMarker = 'FunnelLoggingRequest-%s' % instanceMarker
        self.startCheckingAsyncRequest(instanceMarker)


    def startCheckingAsyncRequest(self, name):
        taskMgr.remove(name)
        taskMgr.doMethodLater(0.5, self.pollFunnelTask, name)


    def stopCheckingFunnelTask(self, name):
        taskMgr.remove('pollFunnelTask')


    def pollFunnelTask(self, task):
        result = self.nonBlock.run()
        if result == 0:
            self.stopCheckingFunnelTask(task)
            if self.CurrentHost == 1 or self.CurrentHost == 2:
                self.updateInstanceCookieValues()
                self.writeOutPandaCookie()

            if self.CurrentHost == 3:
                self.updateInstanceCookieValuesOmniture()
                self.writeOutPandaCookieOmniture()

        else:
            return Task.again


    def cacheBuster(self):
        return str(time.time())