def leave_room(context): requested_room_id = context.args[0] interested_room = context.room_manager.get_room(requested_room_id) if interested_room != None: result = interested_room.remove_member(context.user) if result == Room_Status.LEAVE_SUCCESS: return Result.DEFAULT_SUCCESS() else: return Result.DEFAULT_FAILURE() else: Result.DEFAULT_FAILURE()
def create_room(context): print('create room entered') new_room = Room(id=context.room_id, host=context.user) success = context.room_manager.add_room(new_room) if success == Room_Status.CREATE_SUCCESS: print("Create Room Success") return Result.DEFAULT_SUCCESS() else: print("Create Room Failure, Code:" + str(success)) return Result.DEFAULT_FAILURE()
def join_room(context): print('join room entered') requested_room_id = context.room_id interested_room = context.room_manager.get_room(requested_room_id) if interested_room != None: result = interested_room.add_member(context.user) if result == Room_Status.JOIN_SUCCESS: return Result.DEFAULT_SUCCESS() elif result == Room_Status.JOIN_FAILURE_NAME_TAKEN: return Result(Status.FAILURE, "Name already taken") else: return Result.DEFAULT_FAILURE() else: print("Join Room Failure, Code: " + str(Room_Status.JOIN_FAILURE_INVALID_ROOM)) return Result(Status.FAILURE, "Room not found")