Poodletooth-iLand/toontown/launcher/TTSLauncher.py

63 lines
1.7 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from pandac.PandaModules import *
from direct.directnotify import DirectNotifyGlobal
2015-05-15 07:27:32 -05:00
import os
import sys
import time
2015-03-03 16:10:12 -06:00
class LogAndOutput:
def __init__(self, orig, log):
self.orig = orig
self.log = log
def write(self, str):
self.log.write(str)
self.log.flush()
self.orig.write(str)
self.orig.flush()
def flush(self):
self.log.flush()
self.orig.flush()
2015-05-16 20:04:41 -05:00
class TTSLauncher:
notify = DirectNotifyGlobal.directNotify.newCategory('TTSLauncher')
2015-03-03 16:10:12 -06:00
def __init__(self):
self.http = HTTPClient()
2015-05-15 07:27:32 -05:00
2015-05-16 20:04:41 -05:00
self.logPrefix = 'stride-'
2015-03-03 16:10:12 -06:00
ltime = 1 and time.localtime()
logSuffix = '%02d%02d%02d_%02d%02d%02d' % (ltime[0] - 2000, ltime[1], ltime[2], ltime[3], ltime[4], ltime[5])
2015-03-03 16:10:12 -06:00
2015-05-29 05:03:48 -05:00
if not os.path.exists('user/logs/'):
os.mkdir('user/logs/client/')
2015-03-03 16:10:12 -06:00
self.notify.info('Made new directory to save logs.')
2015-05-29 05:03:48 -05:00
logfile = os.path.join('user/logs', self.logPrefix + logSuffix + '.log')
2015-03-03 16:10:12 -06:00
log = open(logfile, 'a')
logOut = LogAndOutput(sys.stdout, log)
logErr = LogAndOutput(sys.stderr, log)
sys.stdout = logOut
sys.stderr = logErr
def getPlayToken(self):
2015-05-16 20:04:41 -05:00
return self.getValue('TTS_PLAYCOOKIE')
2015-03-03 16:10:12 -06:00
def getGameServer(self):
2015-05-16 20:04:41 -05:00
return self.getValue('TTS_GAMESERVER')
2015-05-15 07:27:32 -05:00
def getValue(self, key, default = None):
return os.environ.get(key, default)
def setPandaErrorCode(self):
2015-03-03 16:10:12 -06:00
pass
2015-06-15 19:56:12 -05:00
def setDisconnectDetails(self, disconnectCode, disconnectMsg):
self.disconnectCode = disconnectCode
self.disconnectMsg = disconnectMsg
2015-06-15 19:56:12 -05:00
def setDisconnectDetailsNormal(self):
2015-04-28 02:07:50 -05:00
self.setDisconnectDetails(0, 'normal')