async def change_location(sid: int, data: Dict[str, str]): pr: PlayerRoom = game_state.get(sid) if pr.role != Role.DM: logger.warning(f"{pr.player.name} attempted to change location") return # Send an anouncement to show loading state for room_player in pr.room.players: if not room_player.player.name in data["users"]: continue for psid in game_state.get_sids(player=room_player.player, room=pr.room): await sio.emit("Location.Change.Start", room=psid, namespace="/planarally") new_location = Location[data["location"]] for room_player in pr.room.players: if not room_player.player.name in data["users"]: continue for psid in game_state.get_sids(player=room_player.player, room=pr.room): sio.leave_room( psid, room_player.active_location.get_path(), namespace="/planarally" ) sio.enter_room(psid, new_location.get_path(), namespace="/planarally") await load_location(psid, new_location) room_player.active_location = new_location room_player.save()
async def change_location(sid, location): sid_data = state.sid_map[sid] user = sid_data["user"] room = sid_data["room"] if room.creator != user: logger.warning(f"{user.name} attempted to change location") return old_location = room.get_active_location(dm=True) sio.leave_room(sid, old_location.get_path(), namespace="/planarally") room.dm_location = location new_location = room.get_active_location(dm=True) sio.enter_room(sid, new_location.get_path(), namespace="/planarally") await load_location(sid, new_location) room.player_location = location for room_player in room.players: for psid in state.get_sids(user=room_player.player, room=room): sio.leave_room(psid, old_location.get_path(), namespace="/planarally") sio.enter_room(psid, new_location.get_path(), namespace="/planarally") await load_location(psid, new_location)
async def change_location(sid: str, data: LocationChangeData): pr: PlayerRoom = game_state.get(sid) if pr.role != Role.DM: logger.warning(f"{pr.player.name} attempted to change location") return # Send an anouncement to show loading state for room_player in pr.room.players: if not room_player.player.name in data["users"]: continue for psid in game_state.get_sids(player=room_player.player, room=pr.room): await sio.emit("Location.Change.Start", room=psid, namespace=GAME_NS) new_location = Location.get_by_id(data["location"]) for room_player in pr.room.players: if not room_player.player.name in data["users"]: continue for psid in game_state.get_sids(player=room_player.player, room=pr.room): try: sio.leave_room(psid, room_player.active_location.get_path(), namespace=GAME_NS) sio.enter_room(psid, new_location.get_path(), namespace=GAME_NS) except KeyError: await game_state.remove_sid(psid) continue await load_location(psid, new_location) # We could send this to all users in the new location, BUT # loading times might vary and we don't want to snap people back when they already move around # And it's possible that there are already users on the new location that don't want to be moved to this new position if "position" in data: await sio.emit( "Position.Set", data=data["position"], room=psid, namespace=GAME_NS, ) room_player.active_location = new_location room_player.save()
async def add_new_location(sid: str, location: str): pr: PlayerRoom = game_state.get(sid) if pr.role != Role.DM: logger.warning(f"{pr.player.name} attempted to add a new location") return new_location = Location.create(room=pr.room, name=location, index=pr.room.locations.count()) new_location.create_floor() for psid in game_state.get_sids(player=pr.player, active_location=pr.active_location): sio.leave_room(psid, pr.active_location.get_path(), namespace=GAME_NS) sio.enter_room(psid, new_location.get_path(), namespace=GAME_NS) await load_location(psid, new_location) pr.active_location = new_location pr.save()
async def handle_leave_room(sid, json): if 'X-Token' not in json: return if await Auth.is_user_authenticated(json['X-Token']): org_team = get_room_id_by_json(json) sio.leave_room(sid, org_team)