babelshift / SteamWebAPI2

🎮 C# / .NET library that makes it easy to use the Steam Web API. It conveniently wraps around all of the JSON data and ugly API details with clean methods, structures and classes.
MIT License
263 stars 43 forks source link

Bug with SteamId().ToLegacyFormat() #103

Closed AlfieJPalmer closed 4 years ago

AlfieJPalmer commented 4 years ago

I've written a function to convert a Legacy Steam ID (STEAM_X:Y:Z) to the SteamId type in the API but noticing a small discrepancy. Ref: https://developer.valvesoftware.com/wiki/SteamID

Consider the following Legacy Steam ID: STEAM_0:1:123

Universe (X): 0 -> [Individual / Unspecified] ID Part (Y): 1 -> [Individual] Account Number (Z): 123

SteamId32: 247 (2 * 123 + 1)

If I create a SteamId() with the following as var sid = new SteamId(0, 1, 247)

I get the following from: sid.To64Bit() == 4503603922338039 (wrong) sid.ToLegacyFormat() == "STEAM_0:1:123" (correct) sid.ToModernFormat() == "[U:0:247]" (correct)

I notice that the SteamWebAPI2.Models.SteamUniverse Enum specifies 0=Invalid, which is wrong, so I modified my call to set it to Public: var sid = new SteamId(1, 1, 247)

I get the following from: sid.To64Bit() == 76561197960265975 (correct) sid.ToLegacyFormat() == "STEAM_1:1:123" (wrong) sid.ToModernFormat() == "[U:0:247]" (correct)

I believe the issue here is around the SteamUniverse enum, 0 and 1 correspond to Individual / Unspecified / Public account. Could you please advise?

babelshift commented 4 years ago

@AlfieJPalmer my understanding is that Universe 0 is not valid because it's no longer used in "new" Steam2 representations of Steam IDs. Most libraries that I have researched to build out my implementation were based on the assumption that Universe 0 will be automatically treated as Universe 1. Do you have any documentation clarifying this?

Example: https://dev.doctormckay.com/topic/433-whats-in-a-steamid/

This is the Steam2 format: STEAM_0:0:23071901 (or the newer Steam2 format: STEAM_1:0:23071901) 
U - This is the universe to which this SteamID belongs. Unless you work for Valve, this will always be 1. 
X - This is the universe to which this SteamID belongs. Older games use 0 to stand for public, newer ones use 1. 

Another example is the SteamKit library which treats Universe 0 as invalid as well.

After revisting this logic, it's possible that I should update the constructor that you're using to change Universe 0 to Universe 1 automatically so that it resolves identically in both examples that you've provided.

babelshift commented 4 years ago

Closing because no response from reporter.