Make auth stuff behave more like real steam.

This commit is contained in:
Mr_Goldberg 2019-07-15 10:07:34 -04:00
parent 0677b8e2ff
commit e252f83e8a
No known key found for this signature in database
GPG key ID: 8597D87419DEF278
3 changed files with 22 additions and 11 deletions

View file

@ -256,13 +256,15 @@ Auth_Ticket_Manager::Auth_Ticket_Manager(class Settings *settings, class Network
this->network->setCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &steam_auth_ticket_callback, this); this->network->setCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &steam_auth_ticket_callback, this);
} }
void Auth_Ticket_Manager::launch_callback(CSteamID id, EAuthSessionResponse resp) #define STEAM_TICKET_PROCESS_TIME 0.02
void Auth_Ticket_Manager::launch_callback(CSteamID id, EAuthSessionResponse resp, double delay)
{ {
ValidateAuthTicketResponse_t data; ValidateAuthTicketResponse_t data;
data.m_SteamID = id; data.m_SteamID = id;
data.m_eAuthSessionResponse = resp; data.m_eAuthSessionResponse = resp;
data.m_OwnerSteamID = id; data.m_OwnerSteamID = id;
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data)); callbacks->addCBResult(data.k_iCallback, &data, sizeof(data), delay);
} }
void Auth_Ticket_Manager::launch_callback_gs(CSteamID id, bool approved) void Auth_Ticket_Manager::launch_callback_gs(CSteamID id, bool approved)
@ -383,15 +385,16 @@ EBeginAuthSessionResult Auth_Ticket_Manager::beginAuth(const void *pAuthTicket,
memcpy(&number, ((char *)pAuthTicket) + sizeof(uint64), sizeof(number)); memcpy(&number, ((char *)pAuthTicket) + sizeof(uint64), sizeof(number));
data.id = CSteamID(id); data.id = CSteamID(id);
data.number = number; data.number = number;
data.created = std::chrono::high_resolution_clock::now();
for (auto & t : inbound) { for (auto & t : inbound) {
if (t.id == data.id) { if (t.id == data.id && !check_timedout(t.created, STEAM_TICKET_PROCESS_TIME)) {
return k_EBeginAuthSessionResultDuplicateRequest; return k_EBeginAuthSessionResultDuplicateRequest;
} }
} }
inbound.push_back(data); inbound.push_back(data);
launch_callback(steamID, k_EAuthSessionResponseOK); launch_callback(steamID, k_EAuthSessionResponseOK, STEAM_TICKET_PROCESS_TIME);
return k_EBeginAuthSessionResultOK; return k_EBeginAuthSessionResultOK;
} }
@ -402,12 +405,18 @@ uint32 Auth_Ticket_Manager::countInboundAuth()
bool Auth_Ticket_Manager::endAuth(CSteamID id) bool Auth_Ticket_Manager::endAuth(CSteamID id)
{ {
auto ticket = std::find_if(inbound.begin(), inbound.end(), [&id](Auth_Ticket_Data const& item) { return item.id == id; }); bool erased = false;
if (inbound.end() == ticket) auto t = std::begin(inbound);
return false; while (t != std::end(inbound)) {
if (t->id == id) {
erased = true;
t = inbound.erase(t);
} else {
++t;
}
}
inbound.erase(ticket); return erased;
return true;
} }
void Auth_Ticket_Manager::Callback(Common_Message *msg) void Auth_Ticket_Manager::Callback(Common_Message *msg)
@ -438,6 +447,7 @@ void Auth_Ticket_Manager::Callback(Common_Message *msg)
auto t = std::begin(inbound); auto t = std::begin(inbound);
while (t != std::end(inbound)) { while (t != std::end(inbound)) {
if (t->id.ConvertToUint64() == msg->source_id() && t->number == number) { if (t->id.ConvertToUint64() == msg->source_id() && t->number == number) {
PRINT_DEBUG("TICKET CANCELED\n");
launch_callback(t->id, k_EAuthSessionResponseAuthTicketCanceled); launch_callback(t->id, k_EAuthSessionResponseAuthTicketCanceled);
t = inbound.erase(t); t = inbound.erase(t);
} else { } else {

View file

@ -413,6 +413,7 @@ public:
struct Auth_Ticket_Data { struct Auth_Ticket_Data {
CSteamID id; CSteamID id;
uint64 number; uint64 number;
std::chrono::high_resolution_clock::time_point created;
}; };
class Auth_Ticket_Manager { class Auth_Ticket_Manager {
@ -420,7 +421,7 @@ class Auth_Ticket_Manager {
class Networking *network; class Networking *network;
class SteamCallBacks *callbacks; class SteamCallBacks *callbacks;
void launch_callback(CSteamID id, EAuthSessionResponse resp); void launch_callback(CSteamID id, EAuthSessionResponse resp, double delay=0);
void launch_callback_gs(CSteamID id, bool approved); void launch_callback_gs(CSteamID id, bool approved);
std::vector<struct Auth_Ticket_Data> inbound, outbound; std::vector<struct Auth_Ticket_Data> inbound, outbound;
public: public:

View file

@ -760,7 +760,7 @@ const char *GetLobbyData( CSteamID steamIDLobby, const char *pchKey )
// other users in the lobby will receive notification of the lobby data change via a LobbyDataUpdate_t callback // other users in the lobby will receive notification of the lobby data change via a LobbyDataUpdate_t callback
bool SetLobbyData( CSteamID steamIDLobby, const char *pchKey, const char *pchValue ) bool SetLobbyData( CSteamID steamIDLobby, const char *pchKey, const char *pchValue )
{ {
PRINT_DEBUG("SetLobbyData %s %s\n", pchKey, pchValue); PRINT_DEBUG("SetLobbyData %llu %s %s\n", steamIDLobby.ConvertToUint64(), pchKey, pchValue);
if (!pchKey) return false; if (!pchKey) return false;
char empty_string[] = ""; char empty_string[] = "";
if (!pchValue) pchValue = empty_string; if (!pchValue) pchValue = empty_string;