How to retrieve Steam username using SteamWorks API?

☆樱花仙子☆ 提交于 2019-12-06 06:22:35

问题


How can I obtain the Steam username of the currently used (logged-in) account in my application using the Steam API (which is up and running).

The Steam id can (for example) be obtained by:

CSteamID id = SteamUser.GetSteamID();

But I cannot find a method to obtain the username.


回答1:


Account Name

Getting the account name is difficult as there is no API function as far as I know.
But there is a SteamAppData.vdf file in the <SteamInstallPath>/config folder which looks similar to this:

"SteamAppData"
{
    "RememberPassword"  "<0|1>"
    "AutoLoginUser"     "<accountName>"
}

You can get the Steam install path with the SteamAPI_GetSteamInstallPath() command defined in steam_api.h.
Then you can read the file and extract the account name out of it.

Player Name

Getting the player name is really easy:

In isteamfriends.h you'll should find this method:

// returns the local players name - guaranteed to not be NULL.
// this is the same name as on the users community profile page
// this is stored in UTF-8 format
// like all the other interface functions that return a char *, it's important that this pointer is not saved
// off; it will eventually be free'd or re-allocated
virtual const char *GetPersonaName() = 0;

So SteamFriends.GetPersonaName() should give you the player name.



来源:https://stackoverflow.com/questions/35281019/how-to-retrieve-steam-username-using-steamworks-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!