Esempio n. 1
0
def authenticate(communion):
	failures = 0
	username = None
	while True:
		if not username:
			username = input('username: '******'password: '******'authenticate', '{};{}'.format(username, password))

		if response.consequence == 'success':
			print('Welcome to Isengard, {}'.format(username))
			break
		elif response.consequence == 'invalid':
			if response.body == 'username':
				username = None
				print('{} is an invalid wizard name'.format(username))
			elif response.body == 'password':
				failures += 1
				if failures >= 3:
					username = None
					failures = 0
				print('Invalid password')
		elif response.consequence == 'not found':
			print('{} is not known of at Isengard'.format(username))
			answer = input('Would you like to register {} [Y/n]'.format(username))
			if not re.match('no?', answer.lower()):
				register(communion, username, password)
			username = None
		elif response.consequence == 'conflict':
			print('{} has already arrived at Isengard!'.format(username))
			username = None
		elif response.consequence == 'failure':
			print('Invalid password')
			failures += 1
			if failures >= 3:
				username = None
				failures = 0
		else:
			raise ValueError('Unprocessed authentication response {}'.format(response.consequence))
Esempio n. 2
0
def register(communion, username, password):
	failures = 0
	repeat = None
	while True:
		repeat = getpass('repeat password: '******'register', '{};{}'.format(username, password))

			if response.consequence == 'success':
				print('Wizard {} registered at Isengard!'.format(username))
				return True
			elif response.consequence == 'invalid':
				print('Invalid registration error')
				return False
			elif response.consequence == 'failure':
				print('Wizard {} already known at Isengard!'.format(username))
				return False

		else:
			print('Passwords do not match')
			failures += 1
			if failures >= 3:
				return False
Esempio n. 3
0
def chat(communion):
	lobby = False
	while True:
		text = input()

		if lobby:
			if text:
				if text[0] == '/':
					text = text[1:]
				else:
					response = communion.commune('message', text)
					continue
			else:
				continue

		try:
			command, *args = text.split()
		except ValueError:
			continue

		if command == 'list':
			response = communion.commune('list')
			if response.consequence == 'success':
				print('Current Lobbies:')
				print(response.body)
			elif response.consequence == 'failure':
				print('No lobbies found')
		elif command == 'host':
			try:
				response = communion.commune('host', args[0])
				if response.consequence == 'success':
					lobby = True
					print('Created lobby {}'.format(args[0]))
				elif response.consequence == 'invalid':
					print('{} invalid lobby name'.format(args[0]))
				elif response.consequence == 'conflict':
					print('Lobby {} already exists'.format(args[0]))
				elif response.consequence == 'failure':
					lobby = True
					print('Already in a lobby...')
			except IndexError:
				print('host requires a lobby name')
		elif command == 'join':
			try:
				response = communion.commune('join', args[0])
				if response.consequence == 'success':
					lobby = True
					print('Joined lobby {}'.format(args[0]))
				if response.consequence == 'invalid':
					print('{} invalid lobby name'.format(args[0]))
				if response.consequence == 'not found':
					print('Lobby {} doesn\'t exist'.format(args[0]))
				elif response.consequence == 'failure':
					lobby = True
					print('Already in a lobby...')
			except IndexError:
				print('join requires a lobby name')

		elif command == 'leave':
			response = communion.commune('leave')

			lobby = False
			if response.consequence == 'success':
				print('Left lobby')
			elif response.consequence == 'failure':
				print('Not in a lobby...')

		elif command == 'help':
			print(help_text)

		elif command == 'exit':
			print('Leaving Isengard')
			return

		else:
			print('{} is not a recognised command'.format(command))