2015-03-03 22:10:12 +00:00
|
|
|
from pandac.PandaModules import *
|
|
|
|
from direct.directnotify import DirectNotifyGlobal
|
2015-03-22 11:34:07 +00:00
|
|
|
import os, sys, time, argparse
|
2015-03-03 22:10:12 +00: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-04-08 08:56:49 +00:00
|
|
|
class TTULauncher:
|
|
|
|
notify = DirectNotifyGlobal.directNotify.newCategory('TTULauncher')
|
2015-03-03 22:10:12 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
2015-03-10 22:36:03 +00:00
|
|
|
self.logPrefix = 'united-'
|
2015-03-22 11:34:07 +00:00
|
|
|
self.http = HTTPClient()
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('token')
|
|
|
|
parser.add_argument('server')
|
|
|
|
self.args = parser.parse_args()
|
2015-03-03 22:10:12 +00:00
|
|
|
|
|
|
|
ltime = 1 and time.localtime()
|
2015-04-08 08:56:49 +00:00
|
|
|
logSuffix = '%02d%02d%02d_%02d%02d%02d' % (ltime[0] - 2000, ltime[1], ltime[2], ltime[3], ltime[4], ltime[5])
|
2015-03-03 22:10:12 +00:00
|
|
|
|
|
|
|
if not os.path.exists('logs/'):
|
|
|
|
os.mkdir('logs/')
|
|
|
|
self.notify.info('Made new directory to save logs.')
|
|
|
|
|
|
|
|
logfile = os.path.join('logs', self.logPrefix + logSuffix + '.log')
|
|
|
|
|
|
|
|
log = open(logfile, 'a')
|
|
|
|
logOut = LogAndOutput(sys.stdout, log)
|
|
|
|
logErr = LogAndOutput(sys.stderr, log)
|
|
|
|
sys.stdout = logOut
|
|
|
|
sys.stderr = logErr
|
|
|
|
|
|
|
|
def getPlayToken(self):
|
2015-03-22 11:34:07 +00:00
|
|
|
return self.args.token
|
2015-03-03 22:10:12 +00:00
|
|
|
|
|
|
|
def getGameServer(self):
|
2015-03-22 11:34:07 +00:00
|
|
|
return self.args.server
|
2015-04-08 08:56:49 +00:00
|
|
|
|
|
|
|
def setPandaErrorCode(self):
|
2015-03-03 22:10:12 +00:00
|
|
|
pass
|
2015-04-08 08:56:49 +00:00
|
|
|
|
|
|
|
def setDisconnectDetails(self, disconnectCode, disconnectMsg):
|
|
|
|
self.disconnectCode = disconnectCode
|
|
|
|
self.disconnectMsg = disconnectMsg
|
|
|
|
|
|
|
|
def setDisconnectDetailsNormal(self):
|
|
|
|
self.setDisconnectDetails(0, 'normal')
|