Exemplo n.º 1
0
	def _do_code_chalngaccept(self, sock, message):
		plaintext = decrypt_AES(self.clients[sock].symkey, message)
		challenged, challenger = plaintext.split(',')
		players = [self.clients[sock]]

		for user in self.clients.values():
			if user == challenger:
				players.append(user)
		
		# Init new Game and put it in games dict with gameid as key
		new_game = Game(players)
		gameid = new_game.gameid()
		self.games[gameid] = new_game		

		# Set gameid for challenged in clients dict and send gameid
		self.clients[sock].set_game(gameid)
		ciphertext = encrypt_AES(self.clients[sock].symkey, str(gameid).encode())
		self.fire(write(sock, B_GAMEID+ciphertext))

		# Set gameid for challenger in clients dict and send gameid
		for socket, user in self.clients.items():
			if user == challenger:
				print("Sent B_CHALNGACCEPT to {}".format(user))
				ciphertext = encrypt_AES(user.symkey, str(gameid).encode())
				self.fire(write(socket, B_CHALNGACCEPT+ciphertext))
Exemplo n.º 2
0
    def test_str(self):
        game = Game(result=1,
                    player1_name='Pupkin, Vasily',
                    player2_name='Syutkin, Vladimir',
                    date='2010-09-??',
                    moves=['e4', 'e5', 'Nf3', 'Nc6', 'Bb5', 'a6', 'Ba4',
                           'Nf6', 'O-O', 'Be7', 'Re1', 'b5', 'Bb3', 'd6',
                           'c3', 'O-O', 'h3', 'Nb8', 'd4', 'Nbd7'],
                    tags={'Round': '13', 'Event': 'Abc'})

        s = str(game)
        self.assertTrue(s.find('1-0') >= 0)
        self.assertTrue(s.find('Pupkin') >= 0)
        self.assertTrue(s.find('Syutkin') >= 0)
        self.assertTrue(s.find('2010-09') >= 0)

        game.gameid = 239
        s = str(game)
        self.assertTrue(s.find('239') >= 0)
        self.assertTrue(s.find('1-0') >= 0)
        self.assertTrue(s.find('Pupkin') >= 0)
        self.assertTrue(s.find('Syutkin') >= 0)
        self.assertTrue(s.find('2010-09') >= 0)