Beispiel #1
0
def client_customization() -> TarkovSuccessResponse[dict]:
    customization = {}
    for customization_file_path in (db_dir / "customization").glob("*"):
        customization_data = ujson.load(
            customization_file_path.open("r", encoding="utf8"))
        customization_id = customization_data["_id"]
        customization[customization_id] = customization_data

    return TarkovSuccessResponse(data=customization)
Beispiel #2
0
def client_languages() -> TarkovSuccessResponse[list]:
    languages_data_list = []
    languages_dir = db_dir / "locales"
    for dir_ in languages_dir.glob("*"):
        language_file = dir_ / f"{dir_.stem}.json"
        languages_data_list.append(
            ujson.load(language_file.open("r", encoding="utf8")))

    return TarkovSuccessResponse(data=languages_data_list)
Beispiel #3
0
async def trading_api_get_trader(
    trader_id: str,
    profile: Profile = Depends(with_profile),
    trader_manager: TraderManager = Depends(
        Provide[AppContainer.trader.manager]),
) -> TarkovSuccessResponse[dict]:
    trader = trader_manager.get_trader(TraderType(trader_id))
    trader_view = trader.view(player_profile=profile)
    return TarkovSuccessResponse(data=trader_view.base.dict(exclude_none=True))
Beispiel #4
0
def client_globals(
    flea_config: FleaMarketConfig = Depends(
        Provide[AppContainer.config.flea_market]),
) -> TarkovSuccessResponse[dict]:
    globals_path = db_dir.joinpath("base", "globals.json")
    globals_base = ujson.load(globals_path.open(encoding="utf8"))
    globals_base["time"] = int(datetime.datetime.now().timestamp())
    globals_base["config"]["RagFair"][
        "minUserLevel"] = flea_config.level_required
    return TarkovSuccessResponse(data=globals_base)
Beispiel #5
0
def client_locations() -> TarkovSuccessResponse[dict]:
    locations_base_path = db_dir.joinpath("base", "locations.json")
    locations_base: dict = ujson.load(locations_base_path.open())

    for file in (db_dir / "locations").glob("*.json"):
        map_data = ujson.load(file.open("r"))
        map_id = map_data["base"]["_Id"]
        locations_base["locations"][map_id] = map_data["base"]

    return TarkovSuccessResponse(data=locations_base)
Beispiel #6
0
def singleplayer_raid_profile_list() -> TarkovSuccessResponse[dict]:
    # TODO: Put that into the config file !
    return TarkovSuccessResponse(
        data={
            "aiAmount": "AsOnline",
            "aiDifficulty": "AsOnline",
            "bossEnabled": True,
            "scavWars": False,
            "taggedAndCursed": False,
        })
Beispiel #7
0
def client_game_profile_list_select(request: Request) -> TarkovSuccessResponse[dict]:
    return TarkovSuccessResponse(
        data={
            "status": "ok",
            "notifier": {
                "server": get_request_url_root(request),
                "channel_id": "testChannel",
            },
        }
    )
Beispiel #8
0
async def customization_storage(
    profile_id: Optional[str] = Cookie(alias="PHPSESSID", default=None),
) -> Union[TarkovSuccessResponse[dict], TarkovErrorResponse]:
    if profile_id is None:
        return TarkovErrorResponse(data="",
                                   err=True,
                                   errmsg="No session cookie provided")
    # customization_data = ujson.load(
    #     root_dir.joinpath('resources', 'profiles', profile_id, 'storage.json').open('r', encoding='utf8')
    # )
    return TarkovSuccessResponse(data={})
Beispiel #9
0
async def get_trader_list(
    profile: Profile = Depends(profile_manager.with_profile),
    trader_manager: TraderManager = Depends(Provide[AppContainer.trader.manager]),
) -> TarkovSuccessResponse[List[dict]]:
    response = []
    for trader_type in TraderType:
        trader = trader_manager.get_trader(trader_type)
        trader_view = trader.view(profile)
        response.append(trader_view.base.dict(exclude_none=True))
    response.sort(key=lambda base: base["_id"])
    return TarkovSuccessResponse(data=response)
Beispiel #10
0
def create_profile(
    profile_id: str = Cookie(..., alias="PHPSESSID"),
    side: str = Body(..., embed=True),
    nickname: str = Body(..., embed=True),
    profile_service: ProfileService = Depends(Provide[AppContainer.profile.service]),
) -> TarkovSuccessResponse[dict]:
    profile = profile_service.create_profile(
        profile_id=profile_id,
        nickname=nickname,
        side=side,
    )
    return TarkovSuccessResponse(data={"uid": profile.id})
Beispiel #11
0
def nickname_validate(
    nickname: str = Body(..., embed=True),
    account_service: AccountService = Depends(
        Provide[AppContainer.launcher.account_service]),
) -> Union[TarkovSuccessResponse, TarkovErrorResponse]:
    if len(nickname) < 3:
        return TarkovErrorResponse(errmsg="Nickname is too short", err=256)

    if account_service.is_nickname_taken(nickname):
        return TarkovErrorResponse(errmsg="Nickname is taken", err=255)

    return TarkovSuccessResponse(data={"status": "ok"})
Beispiel #12
0
async def health_sync(
        request: Request,
        profile: Profile = Depends(with_profile),
) -> TarkovSuccessResponse:
    body = await request.json()

    profile.pmc.Health["Hydration"]["Current"] = body["Hydration"]
    profile.pmc.Health["Energy"]["Current"] = body["Energy"]

    for limb, health in body["Health"].items():
        profile.pmc.Health["BodyParts"][limb]["Health"] = health

    return TarkovSuccessResponse(data=None)
Beispiel #13
0
async def customization(
        trader_id: str,  # pylint: disable=unused-argument
) -> TarkovSuccessResponse:
    # suits_path = db_dir.joinpath('assort', trader_id, 'suits.json')
    # if not suits_path.exists():
    #     return TarkovError(600, "This Trader Doesn't have any suits for sale")
    # profile_data = {"Info": {"Side": "Bear"}}  # TODO: After making profile handler load profile here
    # suits_data = ujson.load(suits_path.open('r', encoding='utf8'))
    # for suit in suits_data:
    #     is_suit = suit_side for suit_side in suits_data[suit]['_props']['Side']
    #       if suit_side == profile_data['Info']['Side']:
    # output is { "item._id": [[{ "_tpl": "", "count": 0 }]] }
    return TarkovSuccessResponse(data=[])
Beispiel #14
0
async def get_trader_assort(
    trader_id: str,
    profile: Profile = Depends(profile_manager.with_profile_readonly),
    trader_manager: TraderManager = Depends(Provide[AppContainer.trader.manager]),
) -> Union[TarkovSuccessResponse[TraderAssortResponse], TarkovErrorResponse]:
    trader = trader_manager.get_trader(TraderType(trader_id))
    view = trader.view(player_profile=profile)

    assort_response = TraderAssortResponse(
        barter_scheme=view.barter_scheme.__root__,
        items=view.assort,
        loyal_level_items=view.loyal_level_items,
    )
    return TarkovSuccessResponse(data=assort_response)
Beispiel #15
0
def client_profile_status(
    profile: Profile = Depends(profile_manager.with_profile),
) -> Union[TarkovSuccessResponse[List[dict]], TarkovErrorResponse]:
    response = []
    for profile_type in ("scav", "pmc"):
        response.append({
            "profileid": f"{profile_type}{profile.profile_id}",
            "status": "Free",
            "sid": "",
            "ip": "",
            "port": 0,
        })
    print(response)

    return TarkovSuccessResponse(data=response)
Beispiel #16
0
def client_notifier_channel_create(
    request: Request,
    profile_id: Optional[str] = Cookie(alias="PHPSESSID", default=None),
) -> TarkovSuccessResponse[dict]:
    url_root = get_request_url_root(request).rstrip("/")
    notifier_server_url = f"{url_root}/notifierServer/get/{profile_id}"
    response = {
        "notifier": {
            "server": f"{url_root}/",
            "channel_id": "testChannel",
            "url": notifier_server_url,
        },
        "notifierServer": notifier_server_url,
    }
    return TarkovSuccessResponse(data=response)
Beispiel #17
0
async def join(
    request: Request,
    profile: Profile = Depends(profile_manager.with_profile),
) -> Union[TarkovSuccessResponse[list], TarkovErrorResponse]:
    request_data: dict = await request.json()
    return TarkovSuccessResponse(data=[{
        "profileid": profile.pmc.id,
        "status": "busy",
        "sid": "",
        "ip": "127.0.0.1",
        "port": 9909,
        "version": "live",
        "location``": request_data["location"],
        "gamemode": "deathmatch",
        "shortid": "TEST",
    }])
Beispiel #18
0
def singleplayer_raid_profile_save(
    request: OffraidSaveRequest,
    profile: Profile = Depends(profile_manager.with_profile),
    offraid_service: OffraidSaveService = Depends(
        Provide[AppContainer.offraid.service]),
) -> TarkovSuccessResponse:
    if request.is_player_scav:
        raise NotImplementedError

    offraid_service.update_profile(
        profile=profile,
        raid_profile=request.profile,
        raid_health=request.health,
    )

    return TarkovSuccessResponse(data=None)
Beispiel #19
0
async def generate_bots(
    request: Request,
    bot_generator: BotGenerator = Depends(Provide[BotContainer.bot_generator]),
) -> TarkovSuccessResponse[List[dict]]:
    bots: List[dict] = []
    request_data: dict = await request.json()

    logger.debug(request_data)
    for condition in request_data["conditions"]:
        bot_limit = condition["Limit"]

        for _ in range(bot_limit):
            bot = bot_generator.generate(bot_role="assault")
            bots.append(bot)

    return TarkovSuccessResponse(data=bots)
Beispiel #20
0
async def items_list_cost(
    request: InsuranceListCostRequest,
    profile: Profile = Depends(with_profile),
    trader_manager: TraderManager = Depends(
        Provide[AppContainer.trader.manager]),
) -> Union[TarkovSuccessResponse[Dict[str, dict]], TarkovErrorResponse]:
    insurance_data: Dict[str, dict] = {}

    for trader_id in request.traders:
        trader = trader_manager.get_trader(TraderType(trader_id))
        trader_view = trader.view(player_profile=profile)
        trader_items: Dict[TemplateId, int] = {}

        for item_id in request.items:
            item = profile.inventory.get(item_id)
            trader_items[item.tpl] = trader_view.insurance_price([item])

        insurance_data[trader_id] = trader_items

    return TarkovSuccessResponse(data=insurance_data)
Beispiel #21
0
def client_weather() -> TarkovSuccessResponse[dict]:
    weather_dir = db_dir.joinpath("weather")
    weather_files = list(weather_dir.glob("*"))
    weather_data: dict = ujson.load(
        random.choice(weather_files).open("r", encoding="utf8"))

    current_datetime = datetime.datetime.now()
    delta = current_datetime - start_time
    current_datetime = current_datetime + delta * weather_data["acceleration"]

    timestamp = int(current_datetime.timestamp())
    date_str = current_datetime.strftime("%Y-%m-%d")
    time_str = current_datetime.strftime("%H:%M:%S")

    weather_data["weather"]["timestamp"] = timestamp
    weather_data["weather"]["date"] = date_str
    weather_data["weather"]["time"] = f"{date_str} {time_str}"
    weather_data["date"] = date_str
    weather_data["time"] = time_str

    return TarkovSuccessResponse(data=weather_data)
Beispiel #22
0
async def get_user_assort_price(
    trader_id: str,
    profile: Profile = Depends(profile_manager.with_profile_readonly),
    trader_manager: TraderManager = Depends(Provide[AppContainer.trader.manager]),
) -> Union[TarkovSuccessResponse[Dict[ItemId, List[List[dict]]]], TarkovErrorResponse]:
    trader = trader_manager.get_trader(TraderType(trader_id))
    items = {}

    for item in profile.inventory.items.values():
        if item.parent_id != profile.inventory.root_id:
            continue
        if not trader.can_sell(item):
            continue

        children_items = profile.inventory.iter_item_children_recursively(item)
        price = trader.get_sell_price(item, children_items=children_items)
        items[item.id] = [[{"_tpl": price.template_id, "count": price.amount}]]

    # TODO: Calculate price for items to sell in specified trader
    # output is { "item._id": [[{ "_tpl": "", "count": 0 }]] }
    return TarkovSuccessResponse(data=items)
Beispiel #23
0
def client_game_start() -> TarkovSuccessResponse[Type[None]]:
    return TarkovSuccessResponse(
        data=None)  # TODO Add account data, check if character exists
Beispiel #24
0
def hideout_production_scav_recipes(
) -> TarkovSuccessResponse[List[ScavcaseProductionModel]]:
    return TarkovSuccessResponse(
        data=hideout_repositories.scavcase_production_repository.production)
Beispiel #25
0
def client_hideout_production_recipes(
) -> TarkovSuccessResponse[List[HideoutProductionModel]]:
    return TarkovSuccessResponse(
        data=hideout_repositories.production_repository.production)
Beispiel #26
0
def hideout_settings() -> TarkovSuccessResponse[HideoutSettingsModel]:
    return TarkovSuccessResponse(data=hideout_repositories.settings)
Beispiel #27
0
def hideout_areas() -> TarkovSuccessResponse[List[HideoutAreaTemplate]]:
    return TarkovSuccessResponse(
        data=hideout_repositories.areas_repository.areas)
Beispiel #28
0
def client_game_version_validate() -> TarkovSuccessResponse[Type[None]]:
    return TarkovSuccessResponse(data=None)
Beispiel #29
0
def singleplayer_raid_menu_name() -> TarkovSuccessResponse:
    # TODO: This should get a Map Name and store that with profile ID(session id)
    return TarkovSuccessResponse(data=None)
Beispiel #30
0
def client_items(
    templates_repository: ItemTemplatesRepository = Depends(
        Provide[AppContainer.repos.templates]),
) -> TarkovSuccessResponse[Dict[TemplateId, Union[AnyTemplate]]]:
    return TarkovSuccessResponse(data=templates_repository.client_items_view)