diff --git a/dll/base.cpp b/dll/base.cpp index ec299277..3fa763c5 100644 --- a/dll/base.cpp +++ b/dll/base.cpp @@ -327,242 +327,6 @@ unsigned int file_size_(std::string full_path) return buffer.st_size; } -static void steam_auth_ticket_callback(void *object, Common_Message *msg) -{ - PRINT_DEBUG("steam_auth_ticket_callback\n"); - - Auth_Ticket_Manager *auth_ticket_manager = (Auth_Ticket_Manager *)object; - auth_ticket_manager->Callback(msg); -} - -Auth_Ticket_Manager::Auth_Ticket_Manager(class Settings *settings, class Networking *network, class SteamCallBacks *callbacks) { - this->network = network; - this->settings = settings; - this->callbacks = callbacks; - - this->network->setCallback(CALLBACK_ID_AUTH_TICKET, 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); -} - -#define STEAM_TICKET_PROCESS_TIME 0.03 - -void Auth_Ticket_Manager::launch_callback(CSteamID id, EAuthSessionResponse resp, double delay) -{ - ValidateAuthTicketResponse_t data; - data.m_SteamID = id; - data.m_eAuthSessionResponse = resp; - data.m_OwnerSteamID = id; - callbacks->addCBResult(data.k_iCallback, &data, sizeof(data), delay); -} - -void Auth_Ticket_Manager::launch_callback_gs(CSteamID id, bool approved) -{ - if (approved) { - GSClientApprove_t data; - data.m_SteamID = data.m_OwnerSteamID = id; - callbacks->addCBResult(data.k_iCallback, &data, sizeof(data)); - } else { - GSClientDeny_t data; - data.m_SteamID = id; - data.m_eDenyReason = k_EDenyNotLoggedOn; //TODO: other reasons? - callbacks->addCBResult(data.k_iCallback, &data, sizeof(data)); - } -} - -#define STEAM_ID_OFFSET_TICKET (4 + 8) -#define STEAM_TICKET_MIN_SIZE (4 + 8 + 8) -Auth_Ticket_Data Auth_Ticket_Manager::getTicketData( void *pTicket, int cbMaxTicket, uint32 *pcbTicket ) -{ - uint64 steam_id = settings->get_local_steam_id().ConvertToUint64(); - memset(pTicket, 123, cbMaxTicket); - ((char *)pTicket)[0] = 0x14; - ((char *)pTicket)[1] = 0; - ((char *)pTicket)[2] = 0; - ((char *)pTicket)[3] = 0; - memcpy((char *)pTicket + STEAM_ID_OFFSET_TICKET, &steam_id, sizeof(steam_id)); - *pcbTicket = cbMaxTicket; - - Auth_Ticket_Data ticket_data; - ticket_data.id = settings->get_local_steam_id(); - ticket_data.number = generate_steam_ticket_id(); - uint32 ttt = ticket_data.number; - - memcpy(((char *)pTicket) + sizeof(uint64), &ttt, sizeof(ttt)); - return ticket_data; -} -//Conan Exiles doesn't work with 512 or 128, 256 seems to be the good size -//Steam returns 234 -#define STEAM_AUTH_TICKET_SIZE 234 - -uint32 Auth_Ticket_Manager::getTicket( void *pTicket, int cbMaxTicket, uint32 *pcbTicket ) -{ - if (cbMaxTicket < STEAM_TICKET_MIN_SIZE) return 0; - if (cbMaxTicket > STEAM_AUTH_TICKET_SIZE) cbMaxTicket = STEAM_AUTH_TICKET_SIZE; - - Auth_Ticket_Data ticket_data = getTicketData(pTicket, cbMaxTicket, pcbTicket ); - uint32 ttt = ticket_data.number; - GetAuthSessionTicketResponse_t data; - data.m_hAuthTicket = ttt; - data.m_eResult = k_EResultOK; - callbacks->addCBResult(data.k_iCallback, &data, sizeof(data), STEAM_TICKET_PROCESS_TIME); - - outbound.push_back(ticket_data); - - return ttt; -} - -uint32 Auth_Ticket_Manager::getWebApiTicket( const char* pchIdentity ) -{ - // https://docs.unity.com/ugs/en-us/manual/authentication/manual/platform-signin-steam - GetTicketForWebApiResponse_t data{}; - uint32 cbTicket = 0; - Auth_Ticket_Data ticket_data = getTicketData(data.m_rgubTicket, STEAM_AUTH_TICKET_SIZE, &cbTicket); - data.m_cubTicket = (int)cbTicket; - uint32 ttt = ticket_data.number; - data.m_hAuthTicket = ttt; - data.m_eResult = k_EResultOK; - callbacks->addCBResult(data.k_iCallback, &data, sizeof(data), STEAM_TICKET_PROCESS_TIME); - - outbound.push_back(ticket_data); - - return ttt; -} - -CSteamID Auth_Ticket_Manager::fakeUser() -{ - Auth_Ticket_Data data = {}; - data.id = generate_steam_anon_user(); - inbound.push_back(data); - return data.id; -} - -void Auth_Ticket_Manager::cancelTicket(uint32 number) -{ - auto ticket = std::find_if(outbound.begin(), outbound.end(), [&number](Auth_Ticket_Data const& item) { return item.number == number; }); - if (outbound.end() == ticket) - return; - - Auth_Ticket *auth_ticket = new Auth_Ticket(); - auth_ticket->set_number(number); - auth_ticket->set_type(Auth_Ticket::CANCEL); - Common_Message msg; - msg.set_source_id(settings->get_local_steam_id().ConvertToUint64()); - msg.set_allocated_auth_ticket(auth_ticket); - network->sendToAll(&msg, true); - - outbound.erase(ticket); -} - -bool Auth_Ticket_Manager::SendUserConnectAndAuthenticate( uint32 unIPClient, const void *pvAuthBlob, uint32 cubAuthBlobSize, CSteamID *pSteamIDUser ) -{ - if (cubAuthBlobSize < STEAM_TICKET_MIN_SIZE) return false; - - Auth_Ticket_Data data; - uint64 id; - memcpy(&id, (char *)pvAuthBlob + STEAM_ID_OFFSET_TICKET, sizeof(id)); - uint32 number; - memcpy(&number, ((char *)pvAuthBlob) + sizeof(uint64), sizeof(number)); - data.id = CSteamID(id); - data.number = number; - if (pSteamIDUser) *pSteamIDUser = data.id; - - for (auto & t : inbound) { - if (t.id == data.id) { - //Should this return false? - launch_callback_gs(id, true); - return true; - } - } - - inbound.push_back(data); - launch_callback_gs(id, true); - return true; -} - -EBeginAuthSessionResult Auth_Ticket_Manager::beginAuth(const void *pAuthTicket, int cbAuthTicket, CSteamID steamID ) -{ - if (cbAuthTicket < STEAM_TICKET_MIN_SIZE) return k_EBeginAuthSessionResultInvalidTicket; - - Auth_Ticket_Data data; - uint64 id; - memcpy(&id, (char *)pAuthTicket + STEAM_ID_OFFSET_TICKET, sizeof(id)); - uint32 number; - memcpy(&number, ((char *)pAuthTicket) + sizeof(uint64), sizeof(number)); - data.id = CSteamID(id); - data.number = number; - data.created = std::chrono::high_resolution_clock::now(); - - for (auto & t : inbound) { - if (t.id == data.id && !check_timedout(t.created, STEAM_TICKET_PROCESS_TIME)) { - return k_EBeginAuthSessionResultDuplicateRequest; - } - } - - inbound.push_back(data); - launch_callback(steamID, k_EAuthSessionResponseOK, STEAM_TICKET_PROCESS_TIME); - return k_EBeginAuthSessionResultOK; -} - -uint32 Auth_Ticket_Manager::countInboundAuth() -{ - return inbound.size(); -} - -bool Auth_Ticket_Manager::endAuth(CSteamID id) -{ - bool erased = false; - auto t = std::begin(inbound); - while (t != std::end(inbound)) { - if (t->id == id) { - erased = true; - t = inbound.erase(t); - } else { - ++t; - } - } - - return erased; -} - -void Auth_Ticket_Manager::Callback(Common_Message *msg) -{ - if (msg->has_low_level()) { - if (msg->low_level().type() == Low_Level::CONNECT) { - - } - - if (msg->low_level().type() == Low_Level::DISCONNECT) { - PRINT_DEBUG("TICKET DISCONNECT\n"); - auto t = std::begin(inbound); - while (t != std::end(inbound)) { - if (t->id.ConvertToUint64() == msg->source_id()) { - launch_callback(t->id, k_EAuthSessionResponseUserNotConnectedToSteam); - t = inbound.erase(t); - } else { - ++t; - } - } - } - } - - if (msg->has_auth_ticket()) { - if (msg->auth_ticket().type() == Auth_Ticket::CANCEL) { - PRINT_DEBUG("TICKET CANCEL %llu\n", msg->source_id()); - uint32 number = msg->auth_ticket().number(); - auto t = std::begin(inbound); - while (t != std::end(inbound)) { - if (t->id.ConvertToUint64() == msg->source_id() && t->number == number) { - PRINT_DEBUG("TICKET CANCELED\n"); - launch_callback(t->id, k_EAuthSessionResponseAuthTicketCanceled); - t = inbound.erase(t); - } else { - ++t; - } - } - } - } -} - #ifdef EMU_EXPERIMENTAL_BUILD #ifdef __WINDOWS__ diff --git a/dll/base.h b/dll/base.h index cb4707f4..e656a7b7 100644 --- a/dll/base.h +++ b/dll/base.h @@ -399,35 +399,6 @@ public: } }; -struct Auth_Ticket_Data { - CSteamID id; - uint64 number; - std::chrono::high_resolution_clock::time_point created; -}; - -class Auth_Ticket_Manager { - class Settings *settings; - class Networking *network; - class SteamCallBacks *callbacks; - - void launch_callback(CSteamID id, EAuthSessionResponse resp, double delay=0); - void launch_callback_gs(CSteamID id, bool approved); - std::vector inbound, outbound; -public: - Auth_Ticket_Manager(class Settings *settings, class Networking *network, class SteamCallBacks *callbacks); - - void Callback(Common_Message *msg); - uint32 getTicket( void *pTicket, int cbMaxTicket, uint32 *pcbTicket ); - uint32 getWebApiTicket( const char *pchIdentity ); - void cancelTicket(uint32 number); - EBeginAuthSessionResult beginAuth(const void *pAuthTicket, int cbAuthTicket, CSteamID steamID); - bool endAuth(CSteamID id); - uint32 countInboundAuth(); - bool SendUserConnectAndAuthenticate( uint32 unIPClient, const void *pvAuthBlob, uint32 cubAuthBlobSize, CSteamID *pSteamIDUser ); - CSteamID fakeUser(); - Auth_Ticket_Data getTicketData( void *pTicket, int cbMaxTicket, uint32 *pcbTicket ); -}; - struct RunCBs { void (*function)(void *object); void *object;