def updatearcade(arcadeid: int, attribute: str) -> Dict[str, Any]: # Cast the ID for type safety. arcadeid = ArcadeID(arcadeid) # Attempt to look this arcade up new_value = request.get_json()['value'] arcade = g.data.local.machine.get_arcade(arcadeid) if arcade is None: raise Exception('Unable to find arcade to update!') if g.userID not in arcade.owners: raise Exception('You don\'t own this arcade, refusing to update!') if attribute == 'paseli_enabled': arcade.data.replace_bool('paseli_enabled', new_value) elif attribute == 'paseli_infinite': arcade.data.replace_bool('paseli_infinite', new_value) elif attribute == 'mask_services_url': arcade.data.replace_bool('mask_services_url', new_value) else: raise Exception(f'Unknown attribute {attribute} to update!') g.data.local.machine.put_arcade(arcade) # Return the updated value return { 'value': new_value, }
def updatebalance(arcadeid: int) -> Dict[str, Any]: # Cast the ID for type safety. arcadeid = ArcadeID(arcadeid) credits = request.get_json()['credits'] # Make sure the arcade is valid arcade = g.data.local.machine.get_arcade(arcadeid) if arcade is None: raise Exception('Unable to find arcade to update!') if g.userID not in arcade.owners: raise Exception('You don\'t own this arcade, refusing to update!') # Update balances for userid in credits: balance = g.data.local.user.update_balance(userid, arcadeid, credits[userid]) if balance is not None: g.data.local.network.put_event( 'paseli_transaction', { 'delta': credits[userid], 'balance': balance, 'reason': 'arcade operator adjustment', }, userid=userid, arcadeid=arcadeid, ) return { 'balances': {balance[0]: balance[1] for balance in g.data.local.machine.get_balances(arcadeid)}, 'users': {user.id: user.username for user in g.data.local.user.get_all_users()}, 'events': [format_event(event) for event in g.data.local.network.get_events(arcadeid=arcadeid, event='paseli_transaction')], }
def viewarcade(arcadeid: int) -> Response: # Cast the ID for type safety. arcadeid = ArcadeID(arcadeid) arcade = g.data.local.machine.get_arcade(arcadeid) if g.userID not in arcade.owners: abort(403) machines = [ format_machine(machine) for machine in g.data.local.machine.get_all_machines(arcade.id) ] return render_react( arcade.name, 'arcade/arcade.react.js', { 'arcade': format_arcade(arcade), 'machines': machines, 'game_settings': get_game_settings(arcade), 'balances': {balance[0]: balance[1] for balance in g.data.local.machine.get_balances(arcadeid)}, 'users': {user.id: user.username for user in g.data.local.user.get_all_users()}, 'events': [format_event(event) for event in g.data.local.network.get_events(arcadeid=arcadeid, event='paseli_transaction')], 'enforcing': g.config['server']['enforce_pcbid'], }, { 'refresh': url_for('arcade_pages.listarcade', arcadeid=arcadeid), 'viewuser': url_for('admin_pages.viewuser', userid=-1), 'paseli_enabled': url_for('arcade_pages.updatearcade', arcadeid=arcadeid, attribute='paseli_enabled'), 'paseli_infinite': url_for('arcade_pages.updatearcade', arcadeid=arcadeid, attribute='paseli_infinite'), 'mask_services_url': url_for('arcade_pages.updatearcade', arcadeid=arcadeid, attribute='mask_services_url'), 'update_settings': url_for('arcade_pages.updatesettings', arcadeid=arcadeid), 'add_balance': url_for('arcade_pages.addbalance', arcadeid=arcadeid), 'update_balance': url_for('arcade_pages.updatebalance', arcadeid=arcadeid), 'update_pin': url_for('arcade_pages.updatepin', arcadeid=arcadeid), }, )
def updatesettings(arcadeid: int) -> Dict[str, Any]: # Cast the ID for type safety. arcadeid = ArcadeID(arcadeid) # Attempt to look this arcade up arcade = g.data.local.machine.get_arcade(arcadeid) if arcade is None: raise Exception('Unable to find arcade to update!') if g.userID not in arcade.owners: raise Exception('You don\'t own this arcade, refusing to update!') game = request.get_json()['game'] version = request.get_json()['version'] for setting_type, update_function in [ ('bools', 'replace_bool'), ('ints', 'replace_int'), ('strs', 'replace_str'), ('longstrs', 'replace_str'), ]: for game_setting in request.get_json()[setting_type]: # Grab the value to update category = game_setting['category'] setting = game_setting['setting'] new_value = game_setting['value'] # Update the value current_settings = g.data.local.machine.get_settings(arcade.id, game, version, category) if current_settings is None: current_settings = ValidatedDict() getattr(current_settings, update_function)(setting, new_value) # Save it back g.data.local.machine.put_settings(arcade.id, game, version, category, current_settings) # Return the updated value return { 'game_settings': [ gs for gs in get_game_settings(arcade) if gs['game'] == game and gs['version'] == version ][0], }
def listarcade(arcadeid: int) -> Dict[str, Any]: # Cast the ID for type safety. arcadeid = ArcadeID(arcadeid) # Make sure the arcade is valid arcade = g.data.local.machine.get_arcade(arcadeid) if arcade is None: raise Exception('Unable to find arcade to list!') if g.userID not in arcade.owners: raise Exception('You don\'t own this arcade, refusing to list!') machines = [ format_machine(machine) for machine in g.data.local.machine.get_all_machines(arcade.id) ] return { 'machines': machines, 'balances': {balance[0]: balance[1] for balance in g.data.local.machine.get_balances(arcadeid)}, 'users': {user.id: user.username for user in g.data.local.user.get_all_users()}, 'events': [format_event(event) for event in g.data.local.network.get_events(arcadeid=arcadeid, event='paseli_transaction')], }
def updatepin(arcadeid: int) -> Dict[str, Any]: # Cast the ID for type safety. arcadeid = ArcadeID(arcadeid) pin = request.get_json()['pin'] # Make sure the arcade is valid arcade = g.data.local.machine.get_arcade(arcadeid) if arcade is None: raise Exception('Unable to find arcade to update!') if g.userID not in arcade.owners: raise Exception('You don\'t own this arcade, refusing to update!') if not valid_pin(pin, 'arcade'): raise Exception('Invalid PIN, must be exactly 8 digits!') # Update and save arcade.pin = pin g.data.local.machine.put_arcade(arcade) # Return nothing return {'pin': pin}