def log(self, conn): """in this function, user_id is integer! first we check the basic information, then we determine whether this user has been logged or not, if yes, out the former return the basic information, if the user is in game(reconnect), return the room information""" res = conn_db.log(int(self.resolver.get_id()), self.resolver.get_password()) if res == -1: conn.send(self.generator.log_refuse('user id not exists')) sel.unregister(conn) conn.close() elif res == -2: conn.send(self.generator.log_refuse('Wrong password')) sel.unregister(conn) conn.close() else: user_info = conn_db.get_user_info(self.resolver.get_id()) # the first element of user_info is the total game number, the second is the rate print("info: ", user_info) fr_li = conn_db.get_friend_list(int(self.resolver.get_id())) print("friends: ", fr_li) # multi-log covers player = Games.Player(self.resolver.get_id(), conn, self.resolver.get_time(), user_info[0], fr_li) for i in fr_li: if fr_li[i][1] == 1: try: users[names[i]].send(self.generator.friend_online(player.get_name())) socks[users[names[i]]].friend_online(player.get_name()) except: # means user i log out pass try: u = users[self.resolver.get_id()] if u != conn: u.send(b'another one is using this account') socks[conn] = socks[u] users[self.resolver.get_id()] = conn sel.unregister(u) u.close() del socks[u] except: users[self.resolver.get_id()] = conn socks[conn] = player try: un = undetermined_list[self.resolver.get_id()] print("un: ", un) except: un = [] conn.send(self.generator.log_success(user_info, fr_li, un))
#Simple Game #Demonstrates importing modules #Evan Piercy #6.5.15 import Games, random print("Welcome to the world's simplest game!\n") again = None while again !="n": players = [] num = Games.ask_number(question = "How many players? (2 - 5): ", low = 2, high = 5) for i in range(num): name = input("Player name: ") score = random.randrange(100) + 1 player = Games.Player(name, score) players.append(player) print("\nHere are the game results: ") for player in players: print(player) again = Games.ask_yes_no("\nDo you want to play again? (y/n)") input("\n\nPress the enter key to exit.")