Exemplo n.º 1
0
	def ClickLogin(self):
		cmd = "LOGIN"+" "+str(self.nameEdit.text())
		cmd = cmd.split(" ")

		if cmd_valid(cmd):
			sheet = self.client.make_sheet(cmd)

			self.client.s.send(sheet.toStr())
			self.client.login_handle(self.client.s)

			if self.client.Status['login']: 
				self.client.Username = str(self.nameEdit.text())
 				self.accept()
 			else:
 				QtGui.QMessageBox.critical(self, 'Error', 'User is online')
		else: 
			QtGui.QMessageBox.critical(self, 'Error', 'User name or password error')
Exemplo n.º 2
0
def main():

	find_MY_PORT()
	t_p2p = thread.start_new_thread(p2p_recv_station, ())

	print MY_PORT

	global Username, NameList, PROCESSING
	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	s.connect((SERVER_HOST, SERVER_PORT))



	# handshake ----------------------------------------------------
	handshake = HANDSHAKE()
	handshake.Type = "MINET"
	handshake.Hostname = SERVER_HOST
	s.send(handshake.toStr())
	handshake_str = s.recv(1024)
	handshake = handshake_toForm(handshake_str)
	# --------------------------------------------------------------

	if handshake.Type != "MIRO" or handshake.Hostname != SERVER_HOST:
		print "@@@ connection NOT from Miro!"
	else:
		print "# please enter 'LOGIN Username':"******"login"]:
			print "$",
			cmd_input = raw_input()
			cmd = cmd_input.split(" ")

			if cmd_valid(cmd) and cmd[0]=="LOGIN":
				sheet = make_sheet(cmd)
				s.send(sheet.toStr())
				login_handle(s)
			elif cmd_valid(cmd) and cmd[0]=="LEAVE":
				break
			else:
				print "# command ERROR!"
		# -------------------------------------------
				

		# have login and wait for command -----------
		if Status["login"]:
			t = thread.start_new_thread(handle, (s,))
			t_beat = thread.start_new_thread(beat_handle, (s,))

		while Status["login"]:
			if PROCESSING:
				time.sleep(0.1)
			else:
				print "["+Username+"]$",
				cmd_input = raw_input()
				cmd = cmd_input.split(" ")
				if cmd_valid(cmd):
					sheet = make_sheet(cmd)
					if sheet.Version=="CS1.0":
						s.send(sheet.toStr())
						PROCESSING = True
					elif sheet.Version=="P2P1.0":
						if NameList.has_key(cmd[1]) and NameList[cmd[1]][0]==True:
							p2p_send_station(sheet.toStr(), cmd[1])
						else:
							print "# your friend maybe OFFLINE. please GETLIST to check."
						# send to another thread to handle the p2p communication
				else:
					print "# command ERROR!"
		# -------------------------------------------	

	s.close()