Beispiel #1
0
 def __init__(self, app):
     self.app = app
     self.newAccDlg = NewAccDlg(app)
     self.confirmDlg = ConfirmDlg(app)
     self.messageDlg = MessageBoxDlg(app)
     self.firstlogin = True
     self.createUI()
Beispiel #2
0
 def __init__(self, app):
     self.app = app
     self.newAccDlg = NewAccDlg(app)
     self.confirmDlg = ConfirmDlg(app)
     self.firstlogin = True
     self.versionChecked = False
     self.createUI()
Beispiel #3
0
class LoginDlg:

	def __init__(self, app):
		self.app = app
		self.newAccDlg = NewAccDlg(app)
		self.confirmDlg = ConfirmDlg(app)
		self.firstlogin = True
		self.createUI()

	def display(self, caller = None, message = None):
		self.caller = caller
		self.win.vCreate.visible = gdata.config.game.accountcreated == None
		if gdata.config.game.lastlogin != None:
			self.win.vLogin.text = gdata.config.game.lastlogin
		if gdata.config.game.lastpassword:
			self.win.vPassword.text = gdata.config.game.lastpassword
		if gdata.config.game.lastpasswordcrypted:
			self.win.vPassword.text = binascii.a2b_base64(gdata.config.game.lastpasswordcrypted)
		if not gdata.config.game.lastgameid:
			gdata.config.game.lastgameid = 'Alpha'
		self.win.vMessage.text = message
		#if gdata.config.game.autologin != 'yes':	# enable this to disable auto-login after change in options
		#	self.firstlogin = false
		self.win.show()

	def hide(self):
		self.win.hide()

	def autoLogin(self):
		if self.firstlogin:
			self.firstlogin = False
			self.win.vMessage.text = _('Auto-login in progress ...')
			login = self.win.vLogin.text
			password = self.win.vPassword.text
			gameID = gdata.config.game.lastgameid
			self.doLogin(gameID,login,password)

	def onLogin(self, widget, action, data):
		self.firstlogin = False
		login = self.win.vLogin.text
		password = self.win.vPassword.text
		gameID = gdata.config.game.lastgameid
		self.win.vMessage.text = _('Login in progress ...')
		# self.win.hide()
		self.doLogin(gameID,login,password)

	def doLogin(self,gameID,login,password):
		result = client.login(gameID, login, password)
		self.win.hide()
		if result == 1:
			gdata.config.game.lastlogin = login
			# TODO: remove in 0.6
			gdata.config.game.lastpassword = None
			#
			if gdata.savePassword:
				gdata.config.game.lastpasswordcrypted = binascii.b2a_base64(password).strip()
			else:
				gdata.config.game.lastpasswordcrypted = None
			gdata.config.game.lastgameid = gameID
			gdata.config.game.accountcreated = 1
			# write configuration
			gdata.config.save('var/osci.ini')
			gdata.config.game.lastpasswordcrypted = binascii.b2a_base64(password).strip()
			# init ruleset
			Rules.initRules(os.path.join("res", "rules", client.rulesetName))
			# check version
			if (client.lastClientVersion != version or client.lastClientRevision != revision) and version != (0,0,0,'a'):
				# wow, a different version!
				self.confirmDlg.display(
					_("Your client version does not match server version %d.%d.%d%s [Revision %d]. Do you want to continue?") % (
						client.lastClientVersion[0],
						client.lastClientVersion[1],
						client.lastClientVersion[2],
						client.lastClientVersion[3],
						client.lastClientRevision,
					),
					_('Yes'), _('No'), self.onContinueWithOld, self.app.exit)
				return
			# show main dialog
			if not gdata.mainGameDlg:
				gdata.mainGameDlg = MainGameDlg(self.app)
				gdata.mainGameDlg.display()
			client.updateDatabase()
		elif result == 2:
			pass
		else:
			# login failed
			self.win.vPassword.text = ''
			self.win.vMessage.text = _('Wrong login and/or password')
			self.win.show()

	def onCancel(self, widget, action, data):
		self.win.hide()
		if self.caller:
			self.caller.display()
		else:
			self.app.exit()

	def onContinueWithOld(self):
			# show main dialog
			self.win.hide()
			if not gdata.mainGameDlg:
				gdata.mainGameDlg = MainGameDlg(self.app)
				gdata.mainGameDlg.display()
			client.updateDatabase()

	def onCreateAccount(self, widget, action, data):
		self.win.hide()
		self.newAccDlg.display(self)

	def onOptions(self, widget, action, data):
		self.win.hide()
		gdata.config.game.lastpasswordcrypted = binascii.b2a_base64(self.win.vPassword.text).strip()
		OptionsDlg(gdata.app).display(self)

	def createUI(self):
		w, h = gdata.scrnSize
		self.win = ui.Window(self.app,
			modal = 1,
			movable = 0,
			title = _('Outer Space Login'),
			rect = ui.Rect((w - 424) / 2, (h - 124) / 2, 424, 124),
			layoutManager = ui.SimpleGridLM(),
			tabChange = True,
		)
		self.win.subscribeAction('*', self)
		ui.Label(self.win,
			text = _('Login'),
			align = ui.ALIGN_E,
			layout = (5, 0, 6, 1)
		)
		ui.Entry(self.win, id = 'vLogin',
			align = ui.ALIGN_W,
			layout = (11, 0, 10, 1),
			orderNo = 1
		)
		ui.Label(self.win,
			text = _('Password'),
			align = ui.ALIGN_E,
			layout = (5, 1, 6, 1),
		)
		ui.Entry(self.win, id = 'vPassword',
			align = ui.ALIGN_W,
			showChar = '*',
			layout = (11, 1, 10, 1),
			orderNo = 2
		)
		ui.Button(self.win, layout = (11, 2, 10, 1), text = _("Options"), action = "onOptions", id = "vOptions")
		ui.Button(self.win, layout = (11, 3, 10, 1), text = _("New account"),
			action = "onCreateAccount", id = "vCreate")
		ui.Title(self.win, layout = (0, 4, 11, 1), id = 'vMessage', align = ui.ALIGN_W)
		ui.TitleButton(self.win, layout = (11, 4, 5, 1), text = _('Exit'), action = 'onCancel')
		loginBtn = ui.TitleButton(self.win, layout = (16, 4, 5, 1), text = _('Login'), action = 'onLogin')
		ui.Label(self.win, layout = (0, 0, 5, 4), icons = ((res.loginLogoImg, ui.ALIGN_W),))
		self.win.acceptButton = loginBtn
Beispiel #4
0
class LoginDlg:
    def __init__(self, app):
        self.app = app
        self.newAccDlg = NewAccDlg(app)
        self.confirmDlg = ConfirmDlg(app)
        self.firstlogin = True
        self.versionChecked = False
        self.createUI()

    def display(self, caller=None, message=None):
        self.caller = caller
        # get game names from the server
        try:
            self.gameIDs = client.cmdProxy.getRegisteredGames()
        except IClientException:
            # server is probably down, what to do?
            self.gameIDs = {"UNDEFINED": "Not available"}
        except KeyError:
            # server does not support this call
            self.gameIDs = {"Alpha": "Alpha"}
        # show / hide new account button
        self.win.vCreate.visible = gdata.config.game.accountcreated == None
        # fill in default values
        if gdata.config.game.lastlogin != None:
            self.win.vLogin.text = gdata.config.game.lastlogin
        if gdata.config.game.lastpassword:
            self.win.vPassword.text = gdata.config.game.lastpassword
        if gdata.config.game.lastpasswordcrypted:
            self.win.vPassword.text = binascii.a2b_base64(gdata.config.game.lastpasswordcrypted)
        if not gdata.config.game.lastgameid:
            gdata.config.game.lastgameid = "Alpha"
        if gdata.config.game.lastgameid not in self.gameIDs:
            # use first gameid returned by server
            gdata.config.game.lastgameid = sorted(self.gameIDs.keys())[0]
        self.win.vUniverse.text = self.gameIDs[gdata.config.game.lastgameid]
        self.win.vUniverse.data = gdata.config.game.lastgameid
        # disable Universe selection if there's just one universe on the server
        self.win.vUniverse.enabled = len(self.gameIDs) > 1
        self.win.vMessage.text = message
        # if gdata.config.game.autologin != 'yes':    # enable this to disable auto-login after change in options
        #    self.firstlogin = false
        self.win.show()
        if gdata.config.game.autologin == "yes":
            self.autoLogin()

    def hide(self):
        self.win.hide()

    def autoLogin(self):
        if self.firstlogin:
            self.firstlogin = False
            self.win.vMessage.text = _("Auto-login in progress ...")
            login = self.win.vLogin.text
            password = self.win.vPassword.text
            gameID = self.win.vUniverse.data
            self.doLogin(gameID, login, password)

    def onLogin(self, widget, action, data):
        self.firstlogin = False
        login = self.win.vLogin.text
        password = self.win.vPassword.text
        gameID = self.win.vUniverse.data
        self.win.vMessage.text = _("Login in progress ...")
        # self.win.hide()
        self.doLogin(gameID, login, password)

    def doLogin(self, gameID, login, password):
        result = client.login(gameID, login, password)
        self.win.hide()
        if result == 1:
            gdata.config.game.lastlogin = login
            # TODO: remove in 0.6
            gdata.config.game.lastpassword = None
            #
            if gdata.savePassword:
                gdata.config.game.lastpasswordcrypted = binascii.b2a_base64(password).strip()
            else:
                gdata.config.game.lastpasswordcrypted = None
            gdata.config.game.lastgameid = gameID
            gdata.config.game.accountcreated = 1
            # write configuration
            gdata.config.save()
            gdata.config.game.lastpasswordcrypted = binascii.b2a_base64(password).strip()
            # check version
            log.debug("Comparing server and client versions", client.serverVersion, version)
            if client.serverVersion != version and not self.versionChecked:
                # don't check next time in this session
                self.versionChecked = True
                # wow, a different version!
                self.confirmDlg.display(
                    _("Your client version does not match server version %d.%d.%d%s. Do you want to continue?")
                    % (
                        client.serverVersion["major"],
                        client.serverVersion["minor"],
                        client.serverVersion["revision"],
                        client.serverVersion["status"],
                    ),
                    _("Yes"),
                    _("No"),
                    self.onContinueWithOld,
                    self.app.exit,
                )
                return
            # show main dialog
            if not gdata.mainGameDlg:
                gdata.mainGameDlg = MainGameDlg(self.app)
                gdata.mainGameDlg.display()
            client.updateDatabase()
        elif result == 2:
            pass
        else:
            # login failed
            self.win.vPassword.text = ""
            self.win.vMessage.text = _("Wrong login and/or password")
            self.win.show()

    def onCancel(self, widget, action, data):
        self.win.hide()
        if self.caller:
            self.caller.display()
        else:
            self.app.exit()

    def onContinueWithOld(self):
        # show main dialog
        self.win.hide()
        if not gdata.mainGameDlg:
            gdata.mainGameDlg = MainGameDlg(self.app)
            gdata.mainGameDlg.display()
        client.updateDatabase()

    def onCreateAccount(self, widget, action, data):
        self.win.hide()
        self.newAccDlg.display(self)

    def onOptions(self, widget, action, data):
        self.win.hide()
        gdata.config.game.lastpasswordcrypted = binascii.b2a_base64(self.win.vPassword.text).strip()
        OptionsDlg(gdata.app).display(self)

    def onUniverse(self, widget, action, data):
        # create menu
        items = list()
        index = 0
        for gameID in sorted(self.gameIDs.keys()):
            item = ui.Item(self.gameIDs[gameID], data=gameID, action="onUniverseSelected")
            items.append(item)
            index += 1
        self.universeMenu.items = items
        # show
        self.universeMenu.show((self.win.rect.x + 11 * 20 + 2, self.win.rect.y + 20 + 2))

    def onUniverseSelected(self, widget, action, data):
        self.win.vUniverse.text = self.gameIDs[data]
        self.win.vUniverse.data = data

    def createUI(self):
        w, h = gdata.scrnSize
        self.win = ui.Window(
            self.app,
            modal=1,
            movable=0,
            title=_("Outer Space Login"),
            rect=ui.Rect((w - 424) / 2, (h - 144) / 2, 424, 144),
            layoutManager=ui.SimpleGridLM(),
            tabChange=True,
        )
        self.win.subscribeAction("*", self)
        ui.Label(self.win, text=_("Universe"), align=ui.ALIGN_E, layout=(5, 0, 6, 1))
        ui.Button(self.win, id="vUniverse", align=ui.ALIGN_W, layout=(11, 0, 10, 1), action="onUniverse")
        ui.Label(self.win, text=_("Login"), align=ui.ALIGN_E, layout=(5, 1, 6, 1))
        ui.Entry(self.win, id="vLogin", align=ui.ALIGN_W, layout=(11, 1, 10, 1), orderNo=1)
        ui.Label(self.win, text=_("Password"), align=ui.ALIGN_E, layout=(5, 2, 6, 1))
        ui.Entry(self.win, id="vPassword", align=ui.ALIGN_W, showChar="*", layout=(11, 2, 10, 1), orderNo=2)
        ui.Button(self.win, layout=(11, 3, 10, 1), text=_("Options"), action="onOptions", id="vOptions")
        ui.Button(self.win, layout=(11, 4, 10, 1), text=_("New account"), action="onCreateAccount", id="vCreate")
        ui.Title(self.win, layout=(0, 5, 11, 1), id="vMessage", align=ui.ALIGN_W)
        ui.TitleButton(self.win, layout=(11, 5, 5, 1), text=_("Exit"), action="onCancel")
        loginBtn = ui.TitleButton(self.win, layout=(16, 5, 5, 1), text=_("Login"), action="onLogin")
        ui.Label(self.win, layout=(0, 0, 5, 4), icons=((res.loginLogoImg, ui.ALIGN_W),))
        self.win.acceptButton = loginBtn
        # Universe selection
        self.universeMenu = ui.Menu(self.app, title=_("Universes"), width=10)
        self.universeMenu.subscribeAction("*", self)
Beispiel #5
0
class LoginDlg:
    def __init__(self, app):
        self.app = app
        self.newAccDlg = NewAccDlg(app)
        self.confirmDlg = ConfirmDlg(app)
        self.messageDlg = MessageBoxDlg(app)
        self.firstlogin = True
        self.createUI()

    def display(self, caller=None, message=None):
        self.caller = caller

        # Show the account creation if its not specified or if its 0 or False
        account_creation_visible = False

        try:
            if (gdata.config.game.accountcreated is None
                    or bool(int(gdata.config.game.accountcreated)) is False):
                account_creation_visible = True
        except ValueError:
            account_creation_visible = False

        self.win.vCreate.visible = account_creation_visible

        if gdata.config.game.lastlogin != None:
            self.win.vLogin.text = gdata.config.game.lastlogin
        if gdata.config.game.lastpassword:
            self.win.vPassword.text = gdata.config.game.lastpassword
        if gdata.config.game.lastpasswordcrypted:
            self.win.vPassword.text = binascii.a2b_base64(
                gdata.config.game.lastpasswordcrypted)
        if not gdata.config.game.lastgameid:
            gdata.config.game.lastgameid = 'Alpha'
        self.win.vMessage.text = message
        #if gdata.config.game.autologin != 'yes':	# enable this to disable auto-login after change in options
        #	self.firstlogin = false

        self.win.vTargetServer.text = gdata.config.game.server
        self.win.show()

    def hide(self):
        self.win.hide()

    def autoLogin(self):
        if self.firstlogin:
            self.firstlogin = False
            self.win.vMessage.text = _('Auto-login in progress ...')
            login = self.win.vLogin.text
            password = self.win.vPassword.text
            gameID = gdata.config.game.lastgameid
            self.doLogin(gameID, login, password)

    def onLogin(self, widget, action, data):
        self.firstlogin = False
        login = self.win.vLogin.text
        password = self.win.vPassword.text
        gameID = gdata.config.game.lastgameid
        self.win.vMessage.text = _('Login in progress ...')
        # self.win.hide()
        self.doLogin(gameID, login, password)

    def doLogin(self, gameID, login, password):
        # Check if vTargetServer is empty
        self.win.vTargetServer.text = self.win.vTargetServer.text.strip(
        ).rstrip()

        if (len(self.win.vTargetServer.text) != 0):
            server_info = self.win.vTargetServer.text.split(":")

            server_port = 9080
            if (len(server_info) == 2):
                try:
                    server_port = int(server_info[1])
                except ValueError:
                    self.messageDlg.display(
                        "The custom server specified doesn't appear to be valid.",
                        "OK")
                    return
            elif (len(server_info) > 2):
                self.messageDlg.display(
                    "The custom server specified doesn't appear to be valid.",
                    "OK")
                return

            server_host = server_info[0]
            gdata.config.game.server = "%s:%u" % (server_host, server_port)
            client.server = gdata.config.game.server

        result = client.login(gameID, login, password)
        self.win.hide()
        if result == 1:
            gdata.config.game.lastlogin = login
            # TODO: remove in 0.6
            gdata.config.game.lastpassword = None
            #
            if gdata.savePassword:
                gdata.config.game.lastpasswordcrypted = binascii.b2a_base64(
                    password).strip()
            else:
                gdata.config.game.lastpasswordcrypted = None
            gdata.config.game.lastgameid = gameID
            gdata.config.game.accountcreated = 1
            # write configuration
            gdata.config.save('var/osci.ini')
            gdata.config.game.lastpasswordcrypted = binascii.b2a_base64(
                password).strip()
            # init ruleset
            Rules.initRules(os.path.join("res", "rules", client.rulesetName))
            # check version
            if (client.lastClientVersion != version
                    or client.lastClientRevision != revision
                ) and version != (0, 0, 0, 'a'):
                # wow, a different version!
                self.confirmDlg.display(
                    _("Your client version does not match server version %d.%d.%d%s [Revision %d]. Do you want to continue?"
                      ) % (
                          client.lastClientVersion[0],
                          client.lastClientVersion[1],
                          client.lastClientVersion[2],
                          client.lastClientVersion[3],
                          client.lastClientRevision,
                      ), _('Yes'), _('No'), self.onContinueWithOld,
                    self.app.exit)
                return
            # show main dialog
            if not gdata.mainGameDlg:
                gdata.mainGameDlg = MainGameDlg(self.app)
                gdata.mainGameDlg.display()
            client.updateDatabase()
        elif result == 2:
            pass
        else:
            # login failed
            self.win.vPassword.text = ''
            self.win.vMessage.text = _('Wrong login and/or password')
            self.win.show()

    def onCancel(self, widget, action, data):
        self.win.hide()
        if self.caller:
            self.caller.display()
        else:
            self.app.exit()

    def onContinueWithOld(self):
        # show main dialog
        self.win.hide()
        if not gdata.mainGameDlg:
            gdata.mainGameDlg = MainGameDlg(self.app)
            gdata.mainGameDlg.display()
        client.updateDatabase()

    def onCreateAccount(self, widget, action, data):
        self.win.hide()
        self.newAccDlg.display(self)

    def onOptions(self, widget, action, data):
        self.win.hide()
        gdata.config.game.lastpasswordcrypted = binascii.b2a_base64(
            self.win.vPassword.text).strip()
        OptionsDlg(gdata.app).display(self)

    def createUI(self):
        w, h = gdata.scrnSize
        self.win = ui.Window(
            self.app,
            modal=1,
            movable=0,
            title=_('Outer Space Login'),
            rect=ui.Rect((w - 424) / 2, (h - 124) / 2, 424, 145),
            layoutManager=ui.SimpleGridLM(),
            tabChange=True,
        )
        self.win.subscribeAction('*', self)
        ui.Label(self.win,
                 text=_('Login'),
                 align=ui.ALIGN_E,
                 layout=(5, 0, 6, 1))
        ui.Entry(self.win,
                 id='vLogin',
                 align=ui.ALIGN_W,
                 layout=(11, 0, 10, 1),
                 orderNo=1)
        ui.Label(
            self.win,
            text=_('Password'),
            align=ui.ALIGN_E,
            layout=(5, 1, 6, 1),
        )
        ui.Entry(self.win,
                 id='vPassword',
                 align=ui.ALIGN_W,
                 showChar='*',
                 layout=(11, 1, 10, 1),
                 orderNo=2)

        # Add a target server entry
        ui.Label(
            self.win,
            text=_('Server'),
            align=ui.ALIGN_E,
            layout=(5, 2, 6, 1),
        )
        ui.Entry(self.win,
                 id='vTargetServer',
                 align=ui.ALIGN_W,
                 layout=(11, 2, 10, 1),
                 orderNo=3)
        ui.Button(self.win,
                  layout=(11, 3, 10, 1),
                  text=_("Options"),
                  action="onOptions",
                  id="vOptions")
        ui.Button(self.win,
                  layout=(11, 4, 10, 1),
                  text=_("New account"),
                  action="onCreateAccount",
                  id="vCreate")
        ui.Title(self.win,
                 layout=(0, 5, 11, 1),
                 id='vMessage',
                 align=ui.ALIGN_W)
        ui.TitleButton(self.win,
                       layout=(11, 5, 5, 1),
                       text=_('Exit'),
                       action='onCancel')
        loginBtn = ui.TitleButton(self.win,
                                  layout=(16, 5, 5, 1),
                                  text=_('Login'),
                                  action='onLogin')
        ui.Label(self.win,
                 layout=(0, 0, 5, 4),
                 icons=((res.loginLogoImg, ui.ALIGN_W), ))
        self.win.acceptButton = loginBtn