Skip to content
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

Add support for GetAuthTicketForWebApi #43

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "UGC.hpp"
#include "extra.hpp"
#include "friends.hpp"
#include "user.hpp"
#include "user_stats.hpp"
#include "utils.hpp"
#include "apps.hpp"
Expand All @@ -19,6 +20,7 @@ EXTERN int luasteam_init(lua_State *L) {
if (success) {
luasteam::init_common(L);
luasteam::init_friends(L);
luasteam::init_user(L);
luasteam::init_user_stats(L);
luasteam::init_utils(L);
luasteam::init_UGC(L);
Expand All @@ -45,6 +47,7 @@ EXTERN int luasteam_shutdown(lua_State *L) {
luasteam::shutdown_extra(L);
luasteam::shutdown_UGC(L);
luasteam::shutdown_utils(L);
luasteam::shutdown_user(L);
luasteam::shutdown_user_stats(L);
luasteam::shutdown_friends(L);
luasteam::shutdown_common(L);
Expand Down
46 changes: 46 additions & 0 deletions src/user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down