def google_login(data): """ Google Login """ # idinfo contains dictionary of user info userdat = data["UserInfo"] profiledat = userdat["profileObj"] em = profiledat["email"] all_email = [username.email for username in db.session.query(models.username).all()] if em not in all_email: user = models.username(email=em) db.session.add(user) db.session.commit() userid = db.session.query(models.username).filter_by(email=em).first() userlist.append(userid.id) # Used to distinguish users, for database user calls create_user_controller(em) idlist.append(em) # check if user has character userObj = flask.session["userObj"] response = {} if userObj.user_exists(): if userObj.character_counter > 0: response["has_character"] = True else: response["has_character"] = False else: response["has_character"] = False socketio.emit("google login response", response)
def event(): room = request.json['room'] g_id = request.json['g_id'] result = json.dumps(list(broken_img.find({"group_id" : g_id})),default=json_util.default) response = create_response(result) socketio.emit('crawlerstatus',response,namespace='/events',room=room) response = Response("",status=204) return response
def send_out(msg, char_id): """ Method for sending reply """ print(msg) socketio.emit("chatlog updated", {"text": msg}) dbmsg = models.chat_log( character_id=char_id, # char chat=msg) db.session.add(dbmsg) db.session.commit()
def consumo_promedio_area(identificacion_sensor, consumo): sensor = Sensor.query.filter_by( identificacion_sensor=identificacion_sensor).first() sensor_medida = SensorMedida.save({ 'sensor_id': sensor.id, 'medida_sensor': consumo }) socketio.emit('consumoPromedioGeneral', consumo_promedio(sensor.area.id, sensor.tipo_sensor.id, 'now', Sensor, SensorMedida), namespace='/area/promedio/' + sensor.tipo_sensor.slug_tipo + '/' + sensor.area.slug_area) socketio.emit('consumoGraficoReal', consumo_real(sensor.identificacion_sensor, Sensor, SensorMedida), namespace='/sensor/consumo/' + sensor.identificacion_sensor) return jsonify({'response': 'Dato guardado con exito'})
def email_login(data): print(data) create_user_controller(data) userObj = flask.session["userObj"] response = {} if userObj.user_exists(): response["user_exists"] = True if userObj.character_counter > 0: response["has_character"] = True else: response["has_character"] = False else: response["user_exists"] = False response["has_character"] = False socketio.emit("email exists", response)
def player_info(): """ Send playerinfo to js. Currently sends dummy data. """ player_data = { "user_party": ["player1", "player2", "player10"], "user_inventory": ["coins", "sword", "shield"], "user_chatlog": [ "welcome to the world", "attack", "user attacks, hitting the blob for 10pts", ], } if ITEM == 1: inv = player_data["user_inventory"] global TIMES if TIMES == 0: inv.extend(["Health Pack"]) TIMES += 1 else: inv.extend(["Health Pack"] * TIMES) TIMES += 1 print(inv) player_data["user_inventory"] = inv socketio.emit("player info", player_data)
def user_chars(): print("landed") characters = {} userObj = flask.session["userObj"] characters["char_instance"] = userObj.get_characters() socketio.emit("recieve user characters", characters)
def send_log(log): socketio.emit("user chatlog", log)
def send_inventory(inventory): socketio.emit("user inventory", inventory)
def send_chatlog(user_chatlog): socketio.emit("user chatlog", user_chatlog)
def send_party(): user_party = ["player1", "player2", "player10"] socketio.emit("user party", user_party)