当前位置: 首页>>代码示例>>Python>>正文


Python Login.destroy方法代码示例

本文整理汇总了Python中login.Login.destroy方法的典型用法代码示例。如果您正苦于以下问题:Python Login.destroy方法的具体用法?Python Login.destroy怎么用?Python Login.destroy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在login.Login的用法示例。


在下文中一共展示了Login.destroy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Main

# 需要导入模块: from login import Login [as 别名]
# 或者: from login.Login import destroy [as 别名]
class Main(ShowBase):
	def __init__(self):
		self.created_client=False
		ShowBase.__init__(self)
		self.login=Login(self)
		self.client = Client(LOGIN_IP, LOGIN_PORT, compress=True)
		if not self.client.getConnected():
			self.login.updateStatus("Could not connect to the Login server")
			self.client=False
		
	def attempt_login(self, username, password):
		# check if processing a request already so if multiple presses of button it wont break this lol...
		# set a variable in login_packetReader() and check here
		
		# attempt to connect again if it failed on startup
		if not self.client:
			self.client = Client(LOGIN_IP, LOGIN_PORT, compress=True)
		if self.client.getConnected():
			self.username=username
			# Setup the un/up sendpacket, this will be changed. later :P
			data = {}
			data[0] = 'login_request'
			data[1] = {}
			data[1][0] = username
			data[1][1] = password
			self.client.sendData(data)
			# Add the handler for the login stage.
			taskMgr.doMethodLater(0.2, self.login_packetReader, 'Update Login')
			return True
		else:
			# client not connected to login/auth server so display message
			self.login.updateStatus("Could not connect to the Login server")
			self.client=False
	
	def create_account(self, username, password):
		# should be similar to attempt_login() but sends 'create_request' rather than 'login_request'
		# similarly need a create_packetReader() task to check for account_created success packet
		# then automatically call attempt_login with the username and password
		pass
	
	def login_packetReader(self, task):
		# setup some sort of timeout checker which will unset the checker variable in attempt_login function so it can go again
		# i think also for the 'db_reply' instead use the hex codes like you were thinking, and have each seperate code like 'already logged' 'wrong password/username' 'whatever else'
		# so on a return of a failure aswell, it will need to stop this task (return task.done)
		temp=self.client.getData()
		if temp!=[]:
			for i in range(len(temp)):
				valid_packet=False
				package=temp[i]
				if len(package)==2:
					print "Received: " + str(package)
					print "Connected to login server"
					# updates warlocks in game
					"""if package[0]=='error':
						print package
						print "User already logged"
						self.login.updateStatus(package[1])
						valid_packet=True
						break"""
					if package[0]=='db_reply':
						print "DB: "+str(package[1])
						self.login.updateStatus(package[1])
						valid_packet=True
					elif package[0]=='login_valid':
						print "Login valid: "+str(package[1])
						self.login.updateStatus(package[1][0])
						print "success: "+str(package[1][1])
						valid_packet=True
						print "I should move to main menu now..."
						taskMgr.doMethodLater(0.3, self.start_mainmenu, 'Start Main Menu')
						return task.done
					"""if not valid_packet:
						data = {}
						data[0] = "error"
						data[1] = "Fail Server"
						self.client.sendData(data)
						print "Bad packet from server"""
				else:
					print "Packet wrong size"
		return task.again
	
	def start_mainmenu(self,task):
		self.login.destroy()
		self.mainmenu=MainMenu(self)
		return task.done
		
	def join_server(self,address):
		# Store connection to lobby and chat i guess eventually
		self.lobby_con=self.client
		# attempt to connect to the game server
		self.client = Client(address, 9099, compress=True)
		if self.client.getConnected():
			print "Connected to server"
			data = {}
			data[0]="username"
			data[1]=self.username # This will end up being the selected server?
			self.client.sendData(data)
			taskMgr.doMethodLater(0.03, self.start_pregame, 'Start Pregame') # I guess this should change to Pregame.
			return True
		else:
#.........这里部分代码省略.........
开发者ID:H3LLB0Y,项目名称:Warlocks,代码行数:103,代码来源:main.py


注:本文中的login.Login.destroy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。