def searchusers() -> Dict[str, Any]: # Grab card, convert it searchdetails = request.get_json()['user_search'] if len(searchdetails['card']) > 0: try: cardid = CardCipher.decode(searchdetails['card']) actual_userid = g.data.local.user.from_cardid(cardid) if actual_userid is None: # Force a non-match below actual_userid = UserID(-1) except CardCipherException: actual_userid = UserID(-1) else: actual_userid = None def match(user: User) -> bool: if actual_userid is not None: return user.id == actual_userid else: return True return { 'users': [ format_user(user) for user in g.data.local.user.get_all_users() if match(user) ], }
def addusercard(userid: int) -> Dict[str, Any]: # Cast the userID. userid = UserID(userid) # Grab card, convert it card = request.get_json()['card'] try: cardid = CardCipher.decode(card) except CardCipherException: raise Exception('Invalid card number!') user = g.data.local.user.get_user(userid) # Make sure the user ID is valid if user is None: raise Exception('Cannot find user to update!') # See if it is already claimed curuserid = g.data.local.user.from_cardid(cardid) if curuserid is not None: raise Exception('This card is already in use!') # Add it to the user's account g.data.local.user.add_card(userid, cardid) # Return new card list return { 'cards': [ CardCipher.encode(card) for card in g.data.local.user.get_cards(userid) ], }
def removeusercard(userid: int) -> Dict[str, Any]: # Cast the userID. userid = UserID(userid) # Grab card, convert it card = request.get_json()['card'] try: cardid = CardCipher.decode(card) except CardCipherException: raise Exception('Invalid card number!') user = g.data.local.user.get_user(userid) # Make sure the user ID is valid if user is None: raise Exception('Cannot find user to update!') # Remove it from the user's account g.data.local.user.destroy_card(userid, cardid) # Return new card list return { 'cards': [ CardCipher.encode(card) for card in g.data.local.user.get_cards(userid) ], }
def listuser(userid: int) -> Dict[str, Any]: # Cast the userID. userid = UserID(userid) def __format_card(card: str) -> str: try: return CardCipher.encode(card) except CardCipherException: return '????????????????' cards = [ __format_card(card) for card in g.data.local.user.get_cards(userid) ] arcades = g.data.local.machine.get_all_arcades() return { 'cards': cards, 'arcades': {arcade.id: arcade.name for arcade in arcades}, 'balances': { arcade.id: g.data.local.user.get_balance(userid, arcade.id) for arcade in arcades }, 'events': [ format_event(event) for event in g.data.local.network.get_events( userid=userid, event='paseli_transaction') ], }
def removerival() -> Dict[str, Any]: frontend = IIDXFrontend(g.data, g.config, g.cache) version = int(request.get_json()['version']) rivaltype = request.get_json()['type'] other_userid = UserID(int(request.get_json()['userid'])) userid = g.userID # Remove this rival link if rivaltype != 'sp_rival' and rivaltype != 'dp_rival': raise Exception(f'Invalid rival type {rivaltype}!') g.data.local.user.destroy_link( GameConstants.IIDX, version, userid, rivaltype, other_userid, ) # Now return updated rival info rivals, djinfo = frontend.get_rivals(userid) return { 'rivals': rivals, 'players': djinfo, }
def updateusername(userid: int) -> Dict[str, Any]: # Cast the userID. userid = UserID(userid) username = request.get_json()['username'] user = g.data.local.user.get_user(userid) # Make sure the user ID is valid if user is None: raise Exception('Cannot find user to update!') if not valid_username(username): raise Exception('Invalid username!') # Make sure this user ID isn't taken potential_userid = g.data.local.user.from_username(username) if potential_userid is not None and potential_userid != userid: raise Exception('That username is already taken!') # Update the user user.username = username g.data.local.user.put_user(user) return { 'username': username, }
def addrival() -> Dict[str, Any]: frontend = SoundVoltexFrontend(g.data, g.config, g.cache) version = int(request.get_json()['version']) other_userid = UserID(int(request.get_json()['userid'])) userid = g.userID # Add this rival link profile = g.data.remote.user.get_profile(GameConstants.SDVX, version, other_userid) if profile is None: raise Exception('Unable to find profile for rival!') g.data.local.user.put_link( GameConstants.SDVX, version, userid, 'rival', other_userid, {}, ) # Now return updated rival info rivals, playerinfo = frontend.get_rivals(userid) return { 'rivals': rivals, 'players': playerinfo, }
def removerival() -> Dict[str, Any]: frontend = DDRFrontend(g.data, g.config, g.cache) version = int(request.get_json()['version']) other_userid = UserID(int(request.get_json()['userid'])) position = int(request.get_json()['position']) userid = g.userID # Remove this rival link g.data.local.user.destroy_link( GameConstants.DDR, version, userid, f'friend_{position}', other_userid, ) profile = g.data.local.user.get_profile(GameConstants.DDR, version, userid) if profile is None: raise Exception('Unable to find profile to update!') profile = frontend.deactivate_rival(profile, position) g.data.local.user.put_profile(GameConstants.DDR, version, userid, profile) # Now return updated rival info rivals, info = frontend.get_rivals(userid) return { 'rivals': rivals, 'players': info, }
def handle_event_w_add_comment_request(self, request: Node) -> Node: extid = request.child_value('uid') userid = self.data.remote.user.from_extid(self.game, self.version, extid) if userid is None: # Anonymous comment userid = UserID(0) customize = request.child_value('customize') lid = request.child_value('lid') teamid = request.child_value('tid') teamname = request.child_value('t_name') prefecture = request.child_value('pref') comment = request.child_value('comment') is_tweet = request.child_value('is_tweet') # Link comment to user's profile self.data.local.user.put_time_based_achievement( self.game, self.version, userid, 0, # We never have an ID for this, since comments are add-only 'puzzle_comment', { 'customize': customize, 'lid': lid, 'teamid': teamid, 'teamname': teamname, 'prefecture': prefecture, 'comment': comment, 'tweet': is_tweet, }, ) return Node.void('event_w')
def addrival() -> Dict[str, Any]: frontend = IIDXFrontend(g.data, g.config, g.cache) version = int(request.get_json()['version']) rivaltype = request.get_json()['type'] other_userid = UserID(int(request.get_json()['userid'])) userid = g.userID # Add this rival link if rivaltype != 'sp_rival' and rivaltype != 'dp_rival': raise Exception(f'Invalid rival type {rivaltype}!') profile = g.data.remote.user.get_profile(GameConstants.IIDX, version, other_userid) if profile is None: raise Exception('Unable to find profile for rival!') g.data.local.user.put_link( GameConstants.IIDX, version, userid, rivaltype, other_userid, {}, ) # Now return updated rival info rivals, djinfo = frontend.get_rivals(userid) return { 'rivals': rivals, 'players': djinfo, }
def viewuser(userid: int) -> Response: # Cast the userID. userid = UserID(userid) user = g.data.local.user.get_user(userid) def __format_card(card: str) -> str: try: return CardCipher.encode(card) except CardCipherException: return '????????????????' cards = [ __format_card(card) for card in g.data.local.user.get_cards(userid) ] arcades = g.data.local.machine.get_all_arcades() return render_react( 'User', 'admin/user.react.js', { 'user': { 'email': user.email, 'username': user.username, }, 'cards': cards, 'arcades': {arcade.id: arcade.name for arcade in arcades}, 'balances': { arcade.id: g.data.local.user.get_balance(userid, arcade.id) for arcade in arcades }, 'events': [ format_event(event) for event in g.data.local.network.get_events( userid=userid, event='paseli_transaction') ], }, { 'refresh': url_for('admin_pages.listuser', userid=userid), 'removeusercard': url_for('admin_pages.removeusercard', userid=userid), 'addusercard': url_for('admin_pages.addusercard', userid=userid), 'updatebalance': url_for('admin_pages.updatebalance', userid=userid), 'updateusername': url_for('admin_pages.updateusername', userid=userid), 'updateemail': url_for('admin_pages.updateemail', userid=userid), 'updatepin': url_for('admin_pages.updatepin', userid=userid), 'updatepassword': url_for('admin_pages.updatepassword', userid=userid), }, )
def addrival() -> Dict[str, Any]: frontend = DDRFrontend(g.data, g.config, g.cache) version = int(request.get_json()['version']) other_userid = UserID(int(request.get_json()['userid'])) userid = g.userID # Find a slot to put the rival into occupied: List[Optional[Link]] = [None] * 10 for link in g.data.local.user.get_links(GameConstants.DDR, version, userid): if link.type[:7] != 'friend_': continue pos = int(link.type[7:]) if pos >= 0 and pos < 10: occupied[pos] = link # Put rival in the first slot newrivalpos = -1 for i in range(len(occupied)): if occupied[i] is None: newrivalpos = i break if newrivalpos == -1: raise Exception('No room for another rival!') # Add this rival link profile = g.data.remote.user.get_profile(GameConstants.DDR, version, other_userid) if profile is None: raise Exception('Unable to find profile for rival!') g.data.local.user.put_link( GameConstants.DDR, version, userid, f'friend_{newrivalpos}', other_userid, {}, ) # Now return updated rival info rivals, info = frontend.get_rivals(userid) return { 'rivals': rivals, 'players': info, }
def updatepin(userid: int) -> Dict[str, Any]: # Cast the userID. userid = UserID(userid) pin = request.get_json()['pin'] user = g.data.local.user.get_user(userid) # Make sure the user ID is valid if user is None: raise Exception('Cannot find user to update!') if not valid_pin(pin, 'card'): raise Exception('Invalid pin, must be exactly 4 digits!') # Update the user g.data.local.user.update_pin(userid, pin) return {}
def updateemail(userid: int) -> Dict[str, Any]: # Cast the userID. userid = UserID(userid) email = request.get_json()['email'] user = g.data.local.user.get_user(userid) # Make sure the user ID is valid if user is None: raise Exception('Cannot find user to update!') if not valid_email(email): raise Exception('Invalid email!') # Update the user user.email = email g.data.local.user.put_user(user) return { 'email': email, }
def updatebalance(userid: int) -> Dict[str, Any]: # Cast the userID. userid = UserID(userid) credits = request.get_json()['credits'] user = g.data.local.user.get_user(userid) arcades = g.data.local.machine.get_all_arcades() # Make sure the user ID is valid if user is None: raise Exception('Cannot find user to update!') # Update balances for arcadeid in credits: balance = g.data.local.user.update_balance(userid, arcadeid, credits[arcadeid]) if balance is not None: g.data.local.network.put_event( 'paseli_transaction', { 'delta': credits[arcadeid], 'balance': balance, 'reason': 'admin adjustment', }, userid=userid, arcadeid=arcadeid, ) return { 'arcades': {arcade.id: arcade.name for arcade in arcades}, 'balances': { arcade.id: g.data.local.user.get_balance(userid, arcade.id) for arcade in arcades }, 'events': [ format_event(event) for event in g.data.local.network.get_events( userid=userid, event='paseli_transaction') ], }
def removerival() -> Dict[str, Any]: frontend = SoundVoltexFrontend(g.data, g.config, g.cache) version = int(request.get_json()['version']) other_userid = UserID(int(request.get_json()['userid'])) userid = g.userID # Remove this rival link g.data.local.user.destroy_link( GameConstants.SDVX, version, userid, 'rival', other_userid, ) # Now return updated rival info rivals, playerinfo = frontend.get_rivals(userid) return { 'rivals': rivals, 'players': playerinfo, }
def updatepassword(userid: int) -> Dict[str, Any]: # Cast the userID. userid = UserID(userid) new1 = request.get_json()['new1'] new2 = request.get_json()['new2'] user = g.data.local.user.get_user(userid) # Make sure the user ID is valid if user is None: raise Exception('Cannot find user to update!') # Now, make sure that the passwords match if new1 != new2: raise Exception('Passwords do not match each other!') # Now, make sure passwords are long enough if len(new1) < 6: raise Exception('Password is not long enough!') # Update the user g.data.local.user.update_password(userid, new1) return {}