From f497c3d011379c927811a88074073124bebcf084 Mon Sep 17 00:00:00 2001 From: Open Toontown Date: Fri, 8 Nov 2019 20:23:35 -0500 Subject: [PATCH] general: Some small fixes --- astron/.gitignore | 1 + otp/login/LoginScreen.py | 6 ++-- otp/otpbase/PythonUtil.py | 53 ++++++++++++++++++++++++++++++ toontown/toonbase/ToonBase.py | 7 ++-- toontown/toonbase/ToontownStart.py | 2 +- 5 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 astron/.gitignore diff --git a/astron/.gitignore b/astron/.gitignore new file mode 100644 index 0000000..e660fd9 --- /dev/null +++ b/astron/.gitignore @@ -0,0 +1 @@ +bin/ diff --git a/otp/login/LoginScreen.py b/otp/login/LoginScreen.py index 9a1f92b..3cc92dd 100644 --- a/otp/login/LoginScreen.py +++ b/otp/login/LoginScreen.py @@ -64,9 +64,9 @@ class LoginScreen(StateData.StateData, GuiScreen.GuiScreen): linePos -= buttonLineHeight self.dialogDoneEvent = 'loginDialogAck' dialogClass = OTPGlobals.getGlobalDialogClass() - self.dialog = dialogClass(dialogName='loginDialog', doneEvent=self.dialogDoneEvent, message='', style=OTPDialog.Acknowledge, sortOrder=NO_FADE_SORT_INDEX + 100) + self.dialog = dialogClass(dialogName='loginDialog', doneEvent=self.dialogDoneEvent, message='', style=OTPDialog.Acknowledge, sortOrder=DGG.NO_FADE_SORT_INDEX + 100) self.dialog.hide() - self.failDialog = DirectFrame(parent=aspect2dp, relief=DGG.RAISED, borderWidth=(0.01, 0.01), pos=(0, 0.1, 0), text='', text_scale=0.08, text_pos=(0.0, 0.3), text_wordwrap=15, sortOrder=NO_FADE_SORT_INDEX) + self.failDialog = DirectFrame(parent=aspect2dp, relief=DGG.RAISED, borderWidth=(0.01, 0.01), pos=(0, 0.1, 0), text='', text_scale=0.08, text_pos=(0.0, 0.3), text_wordwrap=15, sortOrder=DGG.NO_FADE_SORT_INDEX) linePos = -.05 self.failTryAgainButton = DirectButton(parent=self.failDialog, relief=DGG.RAISED, borderWidth=(0.01, 0.01), pos=(0, 0, linePos), scale=0.9, text=OTPLocalizer.LoginScreenTryAgain, text_scale=0.06, text_pos=(0, -.02), command=self.__handleFailTryAgain) linePos -= buttonLineHeight @@ -75,7 +75,7 @@ class LoginScreen(StateData.StateData, GuiScreen.GuiScreen): self.failDialog.hide() self.connectionProblemDialogDoneEvent = 'loginConnectionProblemDlgAck' dialogClass = OTPGlobals.getGlobalDialogClass() - self.connectionProblemDialog = dialogClass(dialogName='connectionProblemDialog', doneEvent=self.connectionProblemDialogDoneEvent, message='', style=OTPDialog.Acknowledge, sortOrder=NO_FADE_SORT_INDEX + 100) + self.connectionProblemDialog = dialogClass(dialogName='connectionProblemDialog', doneEvent=self.connectionProblemDialogDoneEvent, message='', style=OTPDialog.Acknowledge, sortOrder=DGG.NO_FADE_SORT_INDEX + 100) self.connectionProblemDialog.hide() return diff --git a/otp/otpbase/PythonUtil.py b/otp/otpbase/PythonUtil.py index f7dcf7e..c15e413 100644 --- a/otp/otpbase/PythonUtil.py +++ b/otp/otpbase/PythonUtil.py @@ -1,4 +1,7 @@ import __builtin__ +import sys + +__all__ = ['describeException', 'pdir'] # class 'decorator' that records the stack at the time of creation # be careful with this, it creates a StackTrace, and that can take a @@ -22,6 +25,56 @@ def recordCreationStack(cls): cls.printCreationStackTrace = printCreationStackTrace return cls +def describeException(backTrace = 4): + # When called in an exception handler, returns a string describing + # the current exception. + + def byteOffsetToLineno(code, byte): + # Returns the source line number corresponding to the given byte + # offset into the indicated Python code module. + + import array + lnotab = array.array('B', code.co_lnotab) + + line = code.co_firstlineno + for i in range(0, len(lnotab), 2): + byte -= lnotab[i] + if byte <= 0: + return line + line += lnotab[i+1] + + return line + + infoArr = sys.exc_info() + exception = infoArr[0] + exceptionName = getattr(exception, '__name__', None) + extraInfo = infoArr[1] + trace = infoArr[2] + + stack = [] + while trace.tb_next: + # We need to call byteOffsetToLineno to determine the true + # line number at which the exception occurred, even though we + # have both trace.tb_lineno and frame.f_lineno, which return + # the correct line number only in non-optimized mode. + frame = trace.tb_frame + module = frame.f_globals.get('__name__', None) + lineno = byteOffsetToLineno(frame.f_code, frame.f_lasti) + stack.append("%s:%s, " % (module, lineno)) + trace = trace.tb_next + + frame = trace.tb_frame + module = frame.f_globals.get('__name__', None) + lineno = byteOffsetToLineno(frame.f_code, frame.f_lasti) + stack.append("%s:%s, " % (module, lineno)) + + description = "" + for i in range(len(stack) - 1, max(len(stack) - backTrace, 0) - 1, -1): + description += stack[i] + + description += "%s: %s" % (exceptionName, extraInfo) + return description + def pdir(obj, str = None, width = None, fTruncate = 1, lineWidth = 75, wantPrivate = 0): # Remove redundant class entries diff --git a/toontown/toonbase/ToonBase.py b/toontown/toonbase/ToonBase.py index 7dc4737..326e0fa 100644 --- a/toontown/toonbase/ToonBase.py +++ b/toontown/toonbase/ToonBase.py @@ -148,7 +148,7 @@ class ToonBase(OTPBase.OTPBase): self.canScreenShot = 1 self.glitchCount = 0 self.walking = 0 - self.resetMusic = self.loadMusic('phase_3/audio/bgm/MIDI_Events_16channels.mid') + self.resetMusic = self.loader.loadMusic('phase_3/audio/bgm/MIDI_Events_16channels.mid') self.oldX = max(1, base.win.getXSize()) self.oldY = max(1, base.win.getYSize()) self.aspectRatio = float(self.oldX) / self.oldY @@ -308,11 +308,12 @@ class ToonBase(OTPBase.OTPBase): self.notify.info('Using gameServer from launcher: %s ' % gameServer) else: gameServer = 'localhost' - serverPort = base.config.GetInt('server-port', 6667) + serverPort = base.config.GetInt('server-port', 7198) serverList = [] for name in gameServer.split(';'): url = URLSpec(name, 1) - url.setScheme('s') + if config.GetBool('server-want-ssl', False): + url.setScheme('s') if not url.hasPort(): url.setPort(serverPort) serverList.append(url) diff --git a/toontown/toonbase/ToontownStart.py b/toontown/toonbase/ToontownStart.py index 6856a64..c7f0a55 100644 --- a/toontown/toonbase/ToontownStart.py +++ b/toontown/toonbase/ToontownStart.py @@ -112,6 +112,6 @@ if autoRun and launcher.isDummy() and (not Thread.isTrueThreads() or __name__ == except SystemExit: raise except: - from direct.showbase import PythonUtil + from otp.otpbase import PythonUtil print PythonUtil.describeException() raise