-
Notifications
You must be signed in to change notification settings - Fork 31
Add support for GetAuthTicketForWebApi #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ int user_ref = LUA_NOREF; | |
| class CallbackListener { | ||
| private: | ||
| STEAM_CALLBACK(CallbackListener, OnAuthSessionTicketResponse, GetAuthSessionTicketResponse_t); | ||
| STEAM_CALLBACK(CallbackListener, OnTicketForWebApiResponse, GetTicketForWebApiResponse_t); | ||
| }; | ||
|
|
||
| void CallbackListener::OnAuthSessionTicketResponse(GetAuthSessionTicketResponse_t *data) { | ||
|
|
@@ -51,6 +52,36 @@ void CallbackListener::OnAuthSessionTicketResponse(GetAuthSessionTicketResponse_ | |
| } | ||
| } | ||
|
|
||
| void CallbackListener::OnTicketForWebApiResponse(GetTicketForWebApiResponse_t *data) { | ||
| if (data == nullptr) { | ||
| return; | ||
| } | ||
| lua_State* L = luasteam::global_lua_state; | ||
| if (!lua_checkstack(L, 4)) { | ||
| return; | ||
| } | ||
| lua_rawgeti(L, LUA_REGISTRYINDEX, user_ref); | ||
| lua_getfield(L, -1, "OnTicketForWebApiResponse"); | ||
| if (lua_isnil(L, -1)) { | ||
| lua_pop(L, 2); | ||
| } else { | ||
| EResult result = data->m_eResult; | ||
| uint32 handle = data->m_hAuthTicket; | ||
| uint8 *authTicket = data->m_rgubTicket; | ||
| const char *hexTicket = bufferToHex(authTicket, 2560).c_str(); | ||
|
||
|
|
||
| lua_createtable(L, 0, 1); | ||
|
||
| lua_pushinteger(L, handle); | ||
| lua_setfield(L, -2, "handle"); | ||
| lua_pushstring(L, hexTicket); | ||
| lua_setfield(L, -2, "hexTicket"); | ||
| lua_pushstring(L, steam_result_code[result]); | ||
| lua_setfield(L, -2, "result"); | ||
| lua_call(L, 1, 0); | ||
| lua_pop(L, 1); | ||
| } | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| // int GetPlayerSteamLevel(); | ||
|
|
@@ -88,6 +119,20 @@ EXTERN int luasteam_getAuthSessionTicket(lua_State *L) { | |
| return 1; | ||
| } | ||
|
|
||
| // HAuthTicket GetAuthTicketForWebApi( const char *pchIdentity ); | ||
| EXTERN int luasteam_getAuthTicketForWebApi(lua_State *L) { | ||
| const char *pchIdentity = luaL_checkstring(L, 1); | ||
| HAuthTicket ticket = SteamUser()->GetAuthTicketForWebApi(pchIdentity); | ||
| if (ticket != k_HAuthTicketInvalid) { | ||
| lua_newtable(L); | ||
| lua_pushinteger(L, ticket); | ||
| lua_setfield(L, -2, "handle"); | ||
|
||
| return 1; | ||
| } | ||
| lua_pushnil(L); | ||
| return 1; | ||
| } | ||
|
|
||
| // void CancelAuthTicket( HAuthTicket hAuthTicket ) | ||
| EXTERN int luasteam_cancelAuthTicket(lua_State *L) { | ||
| HAuthTicket ticket = luaL_checkinteger(L, 1); | ||
|
|
@@ -102,6 +147,7 @@ void add_user(lua_State *L) { | |
| add_func(L, "getPlayerSteamLevel", luasteam_getPlayerSteamLevel); | ||
| add_func(L, "getSteamID", luasteam_getSteamID); | ||
| add_func(L, "getAuthSessionTicket", luasteam_getAuthSessionTicket); | ||
| add_func(L, "getAuthTicketForWebApi", luasteam_getAuthTicketForWebApi); | ||
| add_func(L, "cancelAuthTicket", luasteam_cancelAuthTicket); | ||
| lua_pushvalue(L, -1); | ||
| user_ref = luaL_ref(L, LUA_REGISTRYINDEX); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The callback name uses PascalCase "OnTicketForWebApiResponse" while the existing callback "onAuthSessionTicketResponse" on line 41 uses camelCase. For consistency with the existing codebase, this should be "onTicketForWebApiResponse" (with lowercase 'o').