def table_rpc(request, tableid): body = json.loads(request.body) req_id = body.get('id', 0) if body.get('jsonrpc') != '2.0': return bad_rpc_response(req_id, 'Wrong RPC version') method = body.get('method') params = body.get('params') if not method: return bad_rpc_response(req_id, 'Bad RPC method') wwg = WordwallsGame() permitted = wwg.allow_access(request.user, tableid) if not permitted: return bad_rpc_response(req_id, 'No access to table {}'.format(tableid)) handler = method_lookup(method) if not handler: return bad_rpc_response(req_id, 'RPC method {} does not exist.'.format(method)) try: ret = handler(request.user, tableid, params) except RPCError as e: return bad_rpc_response(req_id, str(e)) return rpc_response(req_id, ret)
def table(request, tableid=None): if request.method == 'POST': return handle_table_post(request, tableid) # Otherwise, it's a GET wwg = WordwallsGame() if tableid: # Check if the user is allowed to enter this table. permitted = wwg.allow_access(request.user, tableid) if gargoyle.is_active('disable_games', request): permitted = False if not permitted: return render(request, 'wordwalls/notPermitted.html', {'tablenum': tableid}) params = wwg.get_add_params(tableid) # Add styling params from user's profile (for styling table # tiles, backgrounds, etc) profile = request.user.aerolithprofile style = profile.customWordwallsStyle if style != "": params['style'] = style meta_info = get_create_meta_info() usermeta = get_user_meta_info(request.user) wgm = None if tableid: wgm = wwg.get_wgm(tableid, False) return render( request, 'wordwalls/table.html', { 'tablenum': tableid if tableid else 0, 'current_host': wgm.host.username if wgm else '', 'multiplayer': (json.dumps(wgm.playerType == WordwallsGameModel. MULTIPLAYER_GAME if wgm else False)), 'user': json.dumps(usermeta), 'addParams': json.dumps(params), 'avatarUrl': profile.avatarUrl, 'lexicon': wgm.lexicon.lexiconName if wgm else None, 'default_lexicon': profile.defaultLexicon.pk, 'challenge_info': json.dumps(meta_info['challenge_info']), 'available_lexica': json.dumps(meta_info['lexica']), 'intercom_app_id': settings.INTERCOM_APP_ID, # Use the webpack server if DEBUG is on. XXX This might not actually # be a good test; consider using an IS_PRODUCTION flag. 'STATIC_SRV': (settings.WEBPACK_DEV_SERVER_URL if (settings.USE_WEBPACK_DEV_SERVER and settings.DEBUG) else '') })
def access_to_table(tablenum, user): """Return whether user has access to table. For now we just use the wordwalls game model. We should fix the logic for multiplayer afterwards.""" if tablenum == 0: # A table num of 0 implies that the user is not currently in a # table. Return true to allow the logic to proceed. return True game = WordwallsGame() return game.allow_access(user, tablenum)