thesadru / genshin.py

API wrapper for HoYoLAB/Miyoushe API built on asyncio and pydantic.
https://thesadru.github.io/genshin.py
MIT License
405 stars 74 forks source link

Star Rail Code Redeem #110

Closed EffortlessFury closed 1 year ago

EffortlessFury commented 1 year ago

Any intention/desire to incorporate Star Rails features? One that might be worth considering would be code redemption, as from my preliminary investigation, it uses the exact same endpoint as Genshin, just with a different biz key. Implementing it would mean refactoring some assumptions, of course, but it's not a huge change.

thesadru commented 1 year ago

I don't personally plan on playing Star Rail but all that should be needed is to add a new enum entry and a new endpoint. I'll probably have to depend on someone else to add them.

EffortlessFury commented 1 year ago

I'll look into adding it. They also have a web check-in, so I'll look into that as well.

EffortlessFury commented 1 year ago

There will also need to be additions made to the UID logic. I'm not sure how to go about discovering what all of the Star Rail server IDs are (there may be a trivial way, such as an endpoint, or it may have just been crowdsourced information; perhaps you know?). Additionally, there will need to be an update to the UID detection logic. AFAIK at this point in time, Star Rail UIDs follow the exact same pattern as Genshin, so there may not be a way to automatically determine the difference.

From what I can see, there appear to be two servers, hkrpg_global and hkrpg_cn. A bit surprising, considering the CN servers don't appear to be visible in the source of Genshin's redeem page. It's entirely possible that they've simplified this to two regions, but I can't verify this is truly the case on my own.

The regions I've discovered are prod_official_usa, prod_official_eur, prod_official_asia, prod_official_cht. In this regard it seems like I'm missing any insight on the CN servers.

Do you have any suggestions on how to proceed in discovering/validating these details?

EDIT: There is always the option of rejecting non-global UIDs for the first iteration. Let me know if that's okay with you, if there isn't a trivial path to the complete data set.

thesadru commented 1 year ago

From what I can see, there appear to be two servers, hkrpg_global and hkrpg_cn

This is in line with the game_biz used for genshin, not anything out of the ordinary I think. Other ids are used for beta and dev server instances.

In this regard it seems like I'm missing any insight on the CN servers.

As far as I know, chinese servers never had the option to redeem through the website.

Star Rail UIDs follow the exact same pattern as Genshin, so there may not be a way to automatically determine the difference.

There is already the option of specifying the game for the client, since there exist collisions for genshin and honkai UIDs in some cases. It should just be a matter of deprecating usage when a game is not specified.

EffortlessFury commented 1 year ago

I'm talking with some folks I know to see if we can't figure out the rest of the info.

EffortlessFury commented 1 year ago

I think I've successfully found the info I need, but I'm trying to figure out how to verify that it is correct. I was using the "get announcements" endpoint, but it doesn't work for me even for Genshin with the code as it exists now. Is it because I'm not located within the country?

If you know of a good way to ensure I have the CN region and biz info correct, please let me know.

thesadru commented 1 year ago

If you know of a good way to ensure I have the CN region and biz info correct, please let me know.

Looking at other projects mentioning hkrpg_cn it seems correct. For example MihoyoBBSTools.

I was using the "get announcements" endpoint, but it doesn't work for me even for Genshin with the code as it exists now. Is it because I'm not located within the country?

Do you get any specific errors? It currently works for other users so I recommend opening a separate issue for that.

EffortlessFury commented 1 year ago

It doesn't error, rather, the response comes back structurally formatted, but empty of meaningful data. I did successfully manage to retrieve the announcements for Star Rail in Global using the values I found, but I can't retrieve Genshin's CN announcements.

To be fair, the current announcements endpoint in the code is hard-coded for global. There's no guarantee that changing everything that was hard-coded over to the CN counterparts would work, so that may be a part of it. That's why I was wondering if there was a feature you could suggest I use that should be useable by me, a non-CN user, successfully as a "control group."

thesadru commented 1 year ago

All of the CN are contributed by other users or copied from CN projects. I rarely go out of my way to make something also work for CN.

Though I do think that getting rid of hardcoded URLs, even if they don't support CN yet, should be a good idea.

EffortlessFury commented 1 year ago

I think what I'll do is use what I've learned and inferred and implement those, and if there are issues, we'll find out via bug reports?

EffortlessFury commented 1 year ago

Is there supposed to be a decent way of populating test data for running the tests locally? A lot of the tests fail on master locally because it seems that it's looking for a bunch of uninitialized test data.

I've got everything functional, I just need to verify no tests are broken and then write my own, but that starts with getting the tests to pass on the current master branch. XD

thesadru commented 1 year ago

You should only require an environment variable GENSHIN_COOKIES with cookies of any hoyolab account. I might try to refactor the CI at some point.

EffortlessFury commented 1 year ago

Yeah, that's what I thought...I'll have to fiddle with what format it wants them in, given I'm using Powershell. I'm setting the env variable as a json object within a string but perhaps that's not how I should be going about it. I at least know it's reading from the env var as it would error completely, complaining about a lack of cookies, whereas now it's specific tests.

thesadru commented 1 year ago

Not json objects, it expects cookie headers. Like cookie_token=ABCD; account_id=1234

EffortlessFury commented 1 year ago

Yeahhh, I just figured that out after digging into BaseCookie. It's still throwing a few errors, though, but I'll let you know if I can't figure it out.

EffortlessFury commented 1 year ago

Heh, okay, so here's the remaining issues. The first was that I have two HoYoLab accounts logged in in separate browsers and it was selectively picking up the second account. Logged out of that and more tests passed. The conftest.py file has some hardcoded UID assertions but at least, when the failures have gotten low, that can be noticed handled locally with no problem. This affects test_diary, test_diary_log, and test_notes. test_character_details checks for a specific character (which not everyone will have) And I'd never touched the lineups feature. It's acting weird regarding what characters I have, so I'm not sure I can even make any, but either way, I can fix all but the lineup one.

thesadru commented 1 year ago

Yeah the tests aren't the greatest, I'm honestly glad this project even has any.

EffortlessFury commented 1 year ago

Merged. #111