mirror of
https://github.com/Detanup01/gbe_fork.git
synced 2024-11-23 11:15:34 +08:00
All Auth token support
This commit is contained in:
parent
7e189c3ee5
commit
b697c8bd2d
@ -1,3 +1,10 @@
|
||||
## 2023/12/21
|
||||
|
||||
* fixed print issues some places
|
||||
* added option to auth with new Ticket!
|
||||
|
||||
---
|
||||
|
||||
* `settings_parser.cpp`:
|
||||
- cleanup the settings parser code by split it into functions
|
||||
- increase the buffer size for `account_name` to 100 chars
|
||||
|
294
dll/auth.cpp
Normal file
294
dll/auth.cpp
Normal file
@ -0,0 +1,294 @@
|
||||
#include "auth.h"
|
||||
|
||||
static void steam_auth_manager_ticket_callback(void *object, Common_Message *msg)
|
||||
{
|
||||
PRINT_DEBUG("steam_auth_manager_ticket_callback\n");
|
||||
|
||||
Auth_Manager *auth_manager = (Auth_Manager *)object;
|
||||
auth_manager->Callback(msg);
|
||||
}
|
||||
|
||||
Auth_Manager::Auth_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_manager_ticket_callback, this);
|
||||
this->network->setCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &steam_auth_manager_ticket_callback, this);
|
||||
}
|
||||
|
||||
#define STEAM_TICKET_PROCESS_TIME 0.03
|
||||
|
||||
void Auth_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_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)
|
||||
#define STEAM_TICKET_MIN_SIZE_NEW 170
|
||||
Auth_Data Auth_Manager::getTicketData( void *pTicket, int cbMaxTicket, uint32 *pcbTicket )
|
||||
{
|
||||
Auth_Data ticket_data;
|
||||
uint64 steam_id = settings->get_local_steam_id().ConvertToUint64();
|
||||
if (settings->enable_new_app_ticket)
|
||||
{
|
||||
ticket_data.id = settings->get_local_steam_id();
|
||||
ticket_data.number = generate_steam_ticket_id();
|
||||
ticket_data.Ticket.Version = 4;
|
||||
ticket_data.Ticket.id = settings->get_local_steam_id();
|
||||
ticket_data.Ticket.AppId = settings->get_local_game_id().AppID();
|
||||
ticket_data.Ticket.ExternalIP = 16777343; //127.0.0.1
|
||||
ticket_data.Ticket.InternalIP = 16777343; //127.0.0.1
|
||||
ticket_data.Ticket.AlwaysZero = 0;
|
||||
const auto curTime = std::chrono::system_clock::now();
|
||||
const auto GenDate = std::chrono::duration_cast<std::chrono::seconds>(curTime.time_since_epoch()).count();
|
||||
ticket_data.Ticket.TicketGeneratedDate = GenDate;
|
||||
uint32_t expTime = GenDate+100000;
|
||||
ticket_data.Ticket.TicketGeneratedExpireDate = expTime;
|
||||
ticket_data.Ticket.Licenses.resize(0);
|
||||
ticket_data.Ticket.Licenses.push_back(0);
|
||||
unsigned int dlcCount = settings->DLCCount();
|
||||
ticket_data.Ticket.DLCs.resize(0); //currently set to 0
|
||||
for (int i = 0; i <= dlcCount; ++i)
|
||||
{
|
||||
DLC dlc;
|
||||
AppId_t appid;
|
||||
bool available;
|
||||
std::string name;
|
||||
if (!settings->getDLC(i, appid, available, name)) break;
|
||||
dlc.AppId = (uint32_t)appid;
|
||||
dlc.Licenses.resize(0);
|
||||
ticket_data.Ticket.DLCs.push_back(dlc);
|
||||
}
|
||||
ticket_data.HasGC = false;
|
||||
if (settings->use_gc_token)
|
||||
{
|
||||
ticket_data.HasGC = true;
|
||||
ticket_data.GC.GCToken = generate_random_int();
|
||||
ticket_data.GC.id = settings->get_local_steam_id();
|
||||
ticket_data.GC.ticketGenDate = GenDate;
|
||||
ticket_data.GC.ExternalIP = 16777343;
|
||||
ticket_data.GC.InternalIP = 16777343;
|
||||
ticket_data.GC.TimeSinceStartup = generate_random_int();
|
||||
ticket_data.GC.TicketGeneratedCount = 1;
|
||||
}
|
||||
std::vector<uint8_t> ser = ticket_data.Serialize();
|
||||
*pcbTicket = ser.size();
|
||||
memcpy(pTicket, ser.data(), ser.size());
|
||||
}
|
||||
else
|
||||
{
|
||||
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;
|
||||
|
||||
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 256 //234
|
||||
|
||||
uint32 Auth_Manager::getTicket( void *pTicket, int cbMaxTicket, uint32 *pcbTicket )
|
||||
{
|
||||
if (settings->enable_new_app_ticket)
|
||||
{
|
||||
if (cbMaxTicket < STEAM_TICKET_MIN_SIZE_NEW) return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cbMaxTicket < STEAM_TICKET_MIN_SIZE) return 0;
|
||||
if (cbMaxTicket > STEAM_AUTH_TICKET_SIZE) cbMaxTicket = STEAM_AUTH_TICKET_SIZE;
|
||||
}
|
||||
|
||||
Auth_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_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_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_Manager::fakeUser()
|
||||
{
|
||||
Auth_Data data = {};
|
||||
data.id = generate_steam_anon_user();
|
||||
inbound.push_back(data);
|
||||
return data.id;
|
||||
}
|
||||
|
||||
void Auth_Manager::cancelTicket(uint32 number)
|
||||
{
|
||||
auto ticket = std::find_if(outbound.begin(), outbound.end(), [&number](Auth_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_Manager::SendUserConnectAndAuthenticate( uint32 unIPClient, const void *pvAuthBlob, uint32 cubAuthBlobSize, CSteamID *pSteamIDUser )
|
||||
{
|
||||
if (cubAuthBlobSize < STEAM_TICKET_MIN_SIZE) return false;
|
||||
|
||||
Auth_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_Manager::beginAuth(const void *pAuthTicket, int cbAuthTicket, CSteamID steamID )
|
||||
{
|
||||
if (cbAuthTicket < STEAM_TICKET_MIN_SIZE) return k_EBeginAuthSessionResultInvalidTicket;
|
||||
|
||||
Auth_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_Manager::countInboundAuth()
|
||||
{
|
||||
return inbound.size();
|
||||
}
|
||||
|
||||
bool Auth_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_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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
182
dll/auth.h
Normal file
182
dll/auth.h
Normal file
@ -0,0 +1,182 @@
|
||||
#ifndef AUTH_INCLUDE
|
||||
#define AUTH_INCLUDE
|
||||
|
||||
#include "base.h"
|
||||
//#include "common_includes.h"
|
||||
#include "../sha/sha1.hpp"
|
||||
#include <ctime>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#define STEAM_APPTICKET_SIGLEN 128
|
||||
#define STEAM_APPTICKET_GCLen 20
|
||||
#define STEAM_APPTICKET_SESSIONLEN 24
|
||||
|
||||
struct DLC {
|
||||
uint32_t AppId;
|
||||
std::vector<uint32_t> Licenses;
|
||||
};
|
||||
|
||||
struct AppTicketGC {
|
||||
uint64 GCToken;
|
||||
CSteamID id;
|
||||
uint32_t ticketGenDate; //epoch
|
||||
uint32_t one = 1;
|
||||
uint32_t two = 2;
|
||||
uint32_t ExternalIP;
|
||||
uint32_t InternalIP;
|
||||
uint32_t TimeSinceStartup;
|
||||
uint32_t TicketGeneratedCount;
|
||||
|
||||
std::vector<uint8_t> Serialize()
|
||||
{
|
||||
std::vector<uint8_t> buffer;
|
||||
uint8_t* pBuffer;
|
||||
buffer.resize(52);
|
||||
pBuffer = buffer.data();
|
||||
PRINT_DEBUG("AppTicketGC: Token: %I64u Startup: %u count: %u", GCToken, TimeSinceStartup, TicketGeneratedCount);
|
||||
*reinterpret_cast<uint32_t*>(pBuffer) = STEAM_APPTICKET_GCLen; pBuffer += 4;
|
||||
*reinterpret_cast<uint64_t*>(pBuffer) = GCToken; pBuffer += 8;
|
||||
*reinterpret_cast<uint64_t*>(pBuffer) = id.ConvertToUint64(); pBuffer += 8;
|
||||
*reinterpret_cast<uint32_t*>(pBuffer) = ticketGenDate; pBuffer += 4;
|
||||
*reinterpret_cast<uint32_t*>(pBuffer) = STEAM_APPTICKET_SESSIONLEN; pBuffer += 4;
|
||||
*reinterpret_cast<uint32_t*>(pBuffer) = one; pBuffer += 4;
|
||||
*reinterpret_cast<uint32_t*>(pBuffer) = two; pBuffer += 4;
|
||||
*reinterpret_cast<uint32_t*>(pBuffer) = ExternalIP; pBuffer += 4;
|
||||
*reinterpret_cast<uint32_t*>(pBuffer) = InternalIP; pBuffer += 4;
|
||||
*reinterpret_cast<uint32_t*>(pBuffer) = TimeSinceStartup; pBuffer += 4;
|
||||
*reinterpret_cast<uint32_t*>(pBuffer) = TicketGeneratedCount; pBuffer += 4;
|
||||
PRINT_DEBUG("AppTicketGC SER: %s\n",uint8_vector_to_hex_string(buffer).c_str());
|
||||
return buffer;
|
||||
}
|
||||
};
|
||||
|
||||
struct AppTicket {
|
||||
uint32_t Version;
|
||||
CSteamID id;
|
||||
uint32_t AppId;
|
||||
uint32_t ExternalIP;
|
||||
uint32_t InternalIP;
|
||||
uint32_t AlwaysZero = 0; //OwnershipFlags?
|
||||
uint32_t TicketGeneratedDate;
|
||||
uint32_t TicketGeneratedExpireDate;
|
||||
std::vector<uint32_t> Licenses;
|
||||
std::vector<DLC> DLCs;
|
||||
|
||||
std::vector<uint8_t> Serialize()
|
||||
{
|
||||
std::vector<uint8_t> buffer;
|
||||
uint8_t* pBuffer;
|
||||
PRINT_DEBUG("AppTicket Licenses Size : %u, DLCs: %u\n",(uint16_t)Licenses.size(), (uint16_t)DLCs.size());
|
||||
uint32_t licSize = Licenses.size() * 4;
|
||||
uint32_t dlcSize = 0;
|
||||
for(DLC dlc_s : DLCs)
|
||||
{
|
||||
dlcSize += 4;
|
||||
dlcSize += 2;
|
||||
dlcSize += (uint32_t)dlc_s.Licenses.size() * 4;
|
||||
}
|
||||
PRINT_DEBUG("AppTicket Size: %i \n" + (42 + licSize + dlcSize));
|
||||
buffer.resize(42 + licSize+ dlcSize);
|
||||
pBuffer = buffer.data();
|
||||
*reinterpret_cast<uint32_t*>(pBuffer) = Version; pBuffer += 4;
|
||||
*reinterpret_cast<uint64_t*>(pBuffer) = id.ConvertToUint64(); pBuffer += 8;
|
||||
*reinterpret_cast<uint32_t*>(pBuffer) = AppId; pBuffer += 4;
|
||||
*reinterpret_cast<uint32_t*>(pBuffer) = ExternalIP; pBuffer += 4;
|
||||
*reinterpret_cast<uint32_t*>(pBuffer) = InternalIP; pBuffer += 4;
|
||||
*reinterpret_cast<uint32_t*>(pBuffer) = AlwaysZero; pBuffer += 4;
|
||||
*reinterpret_cast<uint32_t*>(pBuffer) = TicketGeneratedDate; pBuffer += 4;
|
||||
*reinterpret_cast<uint32_t*>(pBuffer) = TicketGeneratedExpireDate; pBuffer += 4;
|
||||
PRINT_DEBUG("AppTicket SER (before): %s\n",uint8_vector_to_hex_string(buffer).c_str());
|
||||
*reinterpret_cast<uint16_t*>(pBuffer) = (uint16_t)Licenses.size(); pBuffer += 2;
|
||||
|
||||
for(uint32_t license : Licenses)
|
||||
{
|
||||
*reinterpret_cast<uint32_t*>(pBuffer) = license; pBuffer += 4;
|
||||
}
|
||||
|
||||
*reinterpret_cast<uint16_t*>(pBuffer) = (uint16_t)DLCs.size(); pBuffer += 2;
|
||||
|
||||
for(DLC dlc : DLCs)
|
||||
{
|
||||
*reinterpret_cast<uint32_t*>(pBuffer) = dlc.AppId; pBuffer += 4;
|
||||
*reinterpret_cast<uint16_t*>(pBuffer) = (uint16_t)dlc.Licenses.size(); pBuffer += 2;
|
||||
|
||||
for(uint32_t dlc_license : dlc.Licenses)
|
||||
{
|
||||
*reinterpret_cast<uint32_t*>(pBuffer) = dlc_license; pBuffer += 4;
|
||||
}
|
||||
}
|
||||
|
||||
*reinterpret_cast<uint16_t*>(pBuffer) = (uint16_t)0; pBuffer += 2; //padding
|
||||
PRINT_DEBUG("AppTicket SER : %s\n",uint8_vector_to_hex_string(buffer).c_str());
|
||||
return buffer;
|
||||
}
|
||||
};
|
||||
struct Auth_Data {
|
||||
bool HasGC;
|
||||
AppTicketGC GC;
|
||||
AppTicket Ticket;
|
||||
//old data
|
||||
CSteamID id;
|
||||
uint64 number;
|
||||
std::chrono::high_resolution_clock::time_point created;
|
||||
|
||||
std::vector<uint8_t> Serialize()
|
||||
{
|
||||
std::vector<uint8_t> buffer;
|
||||
uint8_t* pBuffer;
|
||||
|
||||
std::vector<uint8_t> tickedData = Ticket.Serialize();
|
||||
uint32_t size = tickedData.size() + 4;
|
||||
std::vector<uint8_t> GCData;
|
||||
if (HasGC)
|
||||
{
|
||||
GCData = GC.Serialize();
|
||||
size += GCData.size() + 4;
|
||||
}
|
||||
PRINT_DEBUG("Ticket Ser Size: %u\n", size);
|
||||
buffer.resize(size+STEAM_APPTICKET_SIGLEN);
|
||||
pBuffer = buffer.data();
|
||||
if (HasGC)
|
||||
{
|
||||
memcpy(pBuffer, GCData.data(), GCData.size());
|
||||
pBuffer+= GCData.size();
|
||||
*reinterpret_cast<uint32_t*>(pBuffer) = (128+tickedData.size()+4); pBuffer += 4;
|
||||
}
|
||||
|
||||
*reinterpret_cast<uint32_t*>(pBuffer) = (tickedData.size()+4); pBuffer += 4;
|
||||
memcpy(pBuffer, tickedData.data(), tickedData.size());
|
||||
PRINT_DEBUG("Auth_Data SER : %s\n",uint8_vector_to_hex_string(buffer).c_str());
|
||||
//Todo make a signature
|
||||
return buffer;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class Auth_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<struct Auth_Data> inbound, outbound;
|
||||
public:
|
||||
Auth_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_Data getTicketData( void *pTicket, int cbMaxTicket, uint32 *pcbTicket );
|
||||
};
|
||||
|
||||
#endif
|
20
dll/base.cpp
20
dll/base.cpp
@ -118,7 +118,7 @@ int generate_random_int() {
|
||||
return a;
|
||||
}
|
||||
|
||||
static uint32 generate_steam_ticket_id() {
|
||||
uint32 generate_steam_ticket_id() {
|
||||
/* not random starts with 2? */
|
||||
static uint32 a = 1;
|
||||
++a;
|
||||
@ -140,7 +140,7 @@ CSteamID generate_steam_id_user()
|
||||
return CSteamID(generate_account_id(), k_unSteamUserDefaultInstance, k_EUniversePublic, k_EAccountTypeIndividual);
|
||||
}
|
||||
|
||||
static CSteamID generate_steam_anon_user()
|
||||
CSteamID generate_steam_anon_user()
|
||||
{
|
||||
return CSteamID(generate_account_id(), k_unSteamUserDefaultInstance, k_EUniversePublic, k_EAccountTypeAnonUser);
|
||||
}
|
||||
@ -160,6 +160,22 @@ CSteamID generate_steam_id_lobby()
|
||||
return CSteamID(generate_account_id(), k_EChatInstanceFlagLobby | k_EChatInstanceFlagMMSLobby, k_EUniversePublic, k_EAccountTypeChat);
|
||||
}
|
||||
|
||||
std::string uint8_vector_to_hex_string(std::vector<uint8_t>& v)
|
||||
{
|
||||
std::string result;
|
||||
result.reserve(v.size() * 2); // two digits per character
|
||||
|
||||
static constexpr char hex[] = "0123456789ABCDEF";
|
||||
|
||||
for (uint8_t c : v)
|
||||
{
|
||||
result.push_back(hex[c / 16]);
|
||||
result.push_back(hex[c % 16]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool check_timedout(std::chrono::high_resolution_clock::time_point old, double timeout)
|
||||
{
|
||||
if (timeout == 0.0) return true;
|
||||
|
@ -94,12 +94,15 @@ struct Steam_Call_Result {
|
||||
int iCallback;
|
||||
};
|
||||
|
||||
uint32 generate_steam_ticket_id();
|
||||
int generate_random_int();
|
||||
SteamAPICall_t generate_steam_api_call_id();
|
||||
CSteamID generate_steam_id_user();
|
||||
CSteamID generate_steam_anon_user();
|
||||
CSteamID generate_steam_id_server();
|
||||
CSteamID generate_steam_id_anonserver();
|
||||
CSteamID generate_steam_id_lobby();
|
||||
std::string uint8_vector_to_hex_string(std::vector<uint8_t>& v);
|
||||
std::string get_full_lib_path();
|
||||
std::string get_full_program_path();
|
||||
std::string get_current_path();
|
||||
|
@ -739,7 +739,7 @@ bool Local_Storage::load_json(std::string full_path, nlohmann::json& json)
|
||||
|
||||
try {
|
||||
json = std::move(nlohmann::json::parse(buffer));
|
||||
PRINT_DEBUG("Loaded json \"%s\". Loaded %u items.\n", full_path.c_str(), json.size());
|
||||
PRINT_DEBUG("Loaded json \"%s\". Loaded %zu items.\n", full_path.c_str(), json.size());
|
||||
return true;
|
||||
} catch (std::exception& e) {
|
||||
PRINT_DEBUG("Error while parsing \"%s\" json: %s\n", full_path.c_str(), e.what());
|
||||
|
@ -514,7 +514,7 @@ std::set<IP_PORT> Networking::resolve_ip(std::string dns)
|
||||
|
||||
if (getaddrinfo(dns.c_str(), NULL, NULL, &result) == 0) {
|
||||
for (struct addrinfo *res = result; res != NULL; res = res->ai_next) {
|
||||
PRINT_DEBUG("%u %u\n", res->ai_addrlen, res->ai_family);
|
||||
PRINT_DEBUG("%zu %u\n", res->ai_addrlen, res->ai_family);
|
||||
if (res->ai_family == AF_INET) {
|
||||
struct sockaddr_in *ipv4 = (struct sockaddr_in *)res->ai_addr;
|
||||
uint32 ip;
|
||||
|
@ -254,6 +254,12 @@ public:
|
||||
|
||||
//steam deck flag
|
||||
bool steam_deck = false;
|
||||
|
||||
// can use GC token for generation
|
||||
bool use_gc_token = false;
|
||||
|
||||
// use new app_ticket auth instead of old one
|
||||
bool enable_new_app_ticket = false;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -264,7 +264,7 @@ static void load_gamecontroller_settings(Settings *settings)
|
||||
}
|
||||
|
||||
settings->controller_settings.action_sets[action_set_name] = button_pairs;
|
||||
PRINT_DEBUG("Added %u action names to %s\n", button_pairs.size(), action_set_name.c_str());
|
||||
PRINT_DEBUG("Added %zu action names to %s\n", button_pairs.size(), action_set_name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@ -993,6 +993,8 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s
|
||||
bool disable_account_avatar = false;
|
||||
bool achievement_bypass = false;
|
||||
bool is_beta_branch = false;
|
||||
bool use_gc_token = false;
|
||||
bool enable_new_app_ticket = false;
|
||||
int build_id = 10;
|
||||
|
||||
bool warn_forced = false;
|
||||
@ -1040,6 +1042,10 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s
|
||||
warn_forced = parse_force_listen_port(port, steam_settings_path);
|
||||
} else if (p == "build_id.txt") {
|
||||
parse_build_id(build_id, steam_settings_path);
|
||||
} else if (p == "new_app_ticket.txt") {
|
||||
enable_new_app_ticket = true;
|
||||
} else if (p == "gc_token.txt") {
|
||||
use_gc_token = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1082,6 +1088,10 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s
|
||||
settings_server->achievement_bypass = achievement_bypass;
|
||||
settings_client->is_beta_branch = is_beta_branch;
|
||||
settings_server->is_beta_branch = is_beta_branch;
|
||||
settings_client->enable_new_app_ticket = enable_new_app_ticket;
|
||||
settings_server->enable_new_app_ticket = enable_new_app_ticket;
|
||||
settings_client->use_gc_token = use_gc_token;
|
||||
settings_server->use_gc_token = use_gc_token;
|
||||
|
||||
if (local_save) {
|
||||
settings_client->local_save = save_path;
|
||||
|
@ -26,12 +26,12 @@ Steam_GameServer::Steam_GameServer(class Settings *settings, class Networking *n
|
||||
this->settings = settings;
|
||||
server_data.set_id(settings->get_local_steam_id().ConvertToUint64());
|
||||
this->callbacks = callbacks;
|
||||
ticket_manager = new Auth_Ticket_Manager(settings, network, callbacks);
|
||||
auth_manager = new Auth_Manager(settings, network, callbacks);
|
||||
}
|
||||
|
||||
Steam_GameServer::~Steam_GameServer()
|
||||
{
|
||||
delete ticket_manager;
|
||||
delete auth_manager;
|
||||
}
|
||||
|
||||
std::vector<std::pair<CSteamID, Gameserver_Player_Info_t>>* Steam_GameServer::get_players()
|
||||
@ -369,7 +369,7 @@ bool Steam_GameServer::SendUserConnectAndAuthenticate( uint32 unIPClient, const
|
||||
PRINT_DEBUG("SendUserConnectAndAuthenticate %u %u\n", unIPClient, cubAuthBlobSize);
|
||||
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
||||
|
||||
bool res = ticket_manager->SendUserConnectAndAuthenticate(unIPClient, pvAuthBlob, cubAuthBlobSize, pSteamIDUser);
|
||||
bool res = auth_manager->SendUserConnectAndAuthenticate(unIPClient, pvAuthBlob, cubAuthBlobSize, pSteamIDUser);
|
||||
|
||||
if (res) {
|
||||
std::pair<CSteamID, Gameserver_Player_Info_t> infos;
|
||||
@ -397,7 +397,7 @@ CSteamID Steam_GameServer::CreateUnauthenticatedUserConnection()
|
||||
PRINT_DEBUG("CreateUnauthenticatedUserConnection\n");
|
||||
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
||||
|
||||
CSteamID bot_id = ticket_manager->fakeUser();
|
||||
CSteamID bot_id = auth_manager->fakeUser();
|
||||
std::pair<CSteamID, Gameserver_Player_Info_t> infos;
|
||||
infos.first = bot_id;
|
||||
infos.second.join_time = std::chrono::steady_clock::now();
|
||||
@ -427,7 +427,7 @@ void Steam_GameServer::SendUserDisconnect( CSteamID steamIDUser )
|
||||
players.erase(player_it);
|
||||
}
|
||||
|
||||
ticket_manager->endAuth(steamIDUser);
|
||||
auth_manager->endAuth(steamIDUser);
|
||||
}
|
||||
|
||||
|
||||
@ -554,7 +554,7 @@ HAuthTicket Steam_GameServer::GetAuthSessionTicket( void *pTicket, int cbMaxTick
|
||||
PRINT_DEBUG("Steam_GameServer::GetAuthSessionTicket\n");
|
||||
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
||||
|
||||
return ticket_manager->getTicket(pTicket, cbMaxTicket, pcbTicket);
|
||||
return auth_manager->getTicket(pTicket, cbMaxTicket, pcbTicket);
|
||||
}
|
||||
|
||||
|
||||
@ -572,7 +572,7 @@ EBeginAuthSessionResult Steam_GameServer::BeginAuthSession( const void *pAuthTic
|
||||
infos.second.name = "unnamed";
|
||||
players.emplace_back(std::move(infos));
|
||||
|
||||
return ticket_manager->beginAuth(pAuthTicket, cbAuthTicket, steamID );
|
||||
return auth_manager->beginAuth(pAuthTicket, cbAuthTicket, steamID );
|
||||
}
|
||||
|
||||
|
||||
@ -592,7 +592,7 @@ void Steam_GameServer::EndAuthSession( CSteamID steamID )
|
||||
players.erase(player_it);
|
||||
}
|
||||
|
||||
ticket_manager->endAuth(steamID);
|
||||
auth_manager->endAuth(steamID);
|
||||
}
|
||||
|
||||
|
||||
@ -602,7 +602,7 @@ void Steam_GameServer::CancelAuthTicket( HAuthTicket hAuthTicket )
|
||||
PRINT_DEBUG("Steam_GameServer::CancelAuthTicket\n");
|
||||
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
||||
|
||||
ticket_manager->cancelTicket(hAuthTicket);
|
||||
auth_manager->cancelTicket(hAuthTicket);
|
||||
}
|
||||
|
||||
|
||||
@ -821,7 +821,7 @@ void Steam_GameServer::RunCallbacks()
|
||||
msg.set_source_id(settings->get_local_steam_id().ConvertToUint64());
|
||||
server_data.set_appid(settings->get_local_game_id().AppID());
|
||||
msg.set_allocated_gameserver(new Gameserver(server_data));
|
||||
msg.mutable_gameserver()->set_num_players(ticket_manager->countInboundAuth());
|
||||
msg.mutable_gameserver()->set_num_players(auth_manager->countInboundAuth());
|
||||
network->sendToAllIndividuals(&msg, true);
|
||||
last_sent_server_info = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
@ -16,7 +16,8 @@
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include "base.h"
|
||||
|
||||
#include "auth.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Functions for authenticating users via Steam to play on a game server
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -62,7 +63,7 @@ public ISteamGameServer
|
||||
bool policy_response_called;
|
||||
|
||||
std::chrono::high_resolution_clock::time_point last_sent_server_info;
|
||||
Auth_Ticket_Manager *ticket_manager;
|
||||
Auth_Manager *auth_manager;
|
||||
|
||||
std::vector<struct Gameserver_Outgoing_Packet> outgoing_packets;
|
||||
public:
|
||||
|
@ -508,7 +508,7 @@ gameserveritem_t *Steam_Matchmaking_Servers::GetServerDetails( HServerListReques
|
||||
PRINT_DEBUG("equal? %p %p\n", hRequest, g->id);
|
||||
if (g->id == hRequest) {
|
||||
gameservers_filtered = g->gameservers_filtered;
|
||||
PRINT_DEBUG("found %u\n", gameservers_filtered.size());
|
||||
PRINT_DEBUG("found %zu\n", gameservers_filtered.size());
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -881,7 +881,7 @@ SteamNetworkingMessage_t *get_steam_message_connection(HSteamNetConnection hConn
|
||||
pMsg->m_pfnRelease = &delete_steam_message;
|
||||
pMsg->m_nChannel = 0;
|
||||
connect_socket->second.data.pop();
|
||||
PRINT_DEBUG("get_steam_message_connection %u %u, %u\n", hConn, size, pMsg->m_nMessageNumber);
|
||||
PRINT_DEBUG("get_steam_message_connection %u %lu, %I64\n", hConn, size, pMsg->m_nMessageNumber);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
@ -2093,13 +2093,13 @@ void Callback(Common_Message *msg)
|
||||
auto connect_socket = s->connect_sockets.find(msg->networking_sockets().connection_id());
|
||||
if (connect_socket != s->connect_sockets.end()) {
|
||||
if (connect_socket->second.remote_identity.GetSteamID64() == msg->source_id() && (connect_socket->second.status == CONNECT_SOCKET_CONNECTED)) {
|
||||
PRINT_DEBUG("Steam_Networking_Sockets: got data len %u, num %u on connection %u\n", msg->networking_sockets().data().size(), msg->networking_sockets().message_number(), connect_socket->first);
|
||||
PRINT_DEBUG("Steam_Networking_Sockets: got data len %zu, num %I64u on connection %u\n", msg->networking_sockets().data().size(), msg->networking_sockets().message_number(), connect_socket->first);
|
||||
connect_socket->second.data.push(msg->networking_sockets());
|
||||
}
|
||||
} else {
|
||||
connect_socket = std::find_if(s->connect_sockets.begin(), s->connect_sockets.end(), [msg](const auto &in) {return in.second.remote_identity.GetSteamID64() == msg->source_id() && (in.second.status == CONNECT_SOCKET_NOT_ACCEPTED || in.second.status == CONNECT_SOCKET_CONNECTED) && in.second.remote_id == msg->networking_sockets().connection_id_from();});
|
||||
if (connect_socket != s->connect_sockets.end()) {
|
||||
PRINT_DEBUG("Steam_Networking_Sockets: got data len %u, num %u on not accepted connection %u\n", msg->networking_sockets().data().size(), msg->networking_sockets().message_number(), connect_socket->first);
|
||||
PRINT_DEBUG("Steam_Networking_Sockets: got data len %zu, num %I64u on not accepted connection %u\n", msg->networking_sockets().data().size(), msg->networking_sockets().message_number(), connect_socket->first);
|
||||
connect_socket->second.data.push(msg->networking_sockets());
|
||||
}
|
||||
}
|
||||
|
@ -358,7 +358,7 @@ bool SetConnectionConfigValueString( HSteamNetConnection hConn, ESteamNetworking
|
||||
bool SetConfigValue( ESteamNetworkingConfigValue eValue, ESteamNetworkingConfigScope eScopeType, intptr_t scopeObj,
|
||||
ESteamNetworkingConfigDataType eDataType, const void *pArg )
|
||||
{
|
||||
PRINT_DEBUG("Steam_Networking_Utils::SetConfigValue %i %i %p %i %p\n", eValue, eScopeType, scopeObj, eDataType, pArg);
|
||||
PRINT_DEBUG("Steam_Networking_Utils::SetConfigValue %i %i %tf %i %p\n", eValue, eScopeType, scopeObj, eDataType, pArg);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include "base.h"
|
||||
|
||||
#include "auth.h"
|
||||
#include "appticket.h"
|
||||
|
||||
class Steam_User :
|
||||
@ -44,7 +44,7 @@ public ISteamUser
|
||||
bool recording = false;
|
||||
std::chrono::high_resolution_clock::time_point last_get_voice;
|
||||
std::string encrypted_app_ticket;
|
||||
Auth_Ticket_Manager *ticket_manager;
|
||||
Auth_Manager *auth_manager;
|
||||
|
||||
public:
|
||||
|
||||
@ -56,12 +56,12 @@ Steam_User(Settings *settings, Local_Storage *local_storage, class Networking *n
|
||||
this->callbacks = callbacks;
|
||||
this->callback_results = callback_results;
|
||||
recording = false;
|
||||
ticket_manager = new Auth_Ticket_Manager(settings, network, callbacks);
|
||||
auth_manager = new Auth_Manager(settings, network, callbacks);
|
||||
}
|
||||
|
||||
~Steam_User()
|
||||
{
|
||||
delete ticket_manager;
|
||||
delete auth_manager;
|
||||
}
|
||||
|
||||
// returns the HSteamUser this interface represents
|
||||
@ -116,7 +116,7 @@ int InitiateGameConnection( void *pAuthBlob, int cbMaxAuthBlob, CSteamID steamID
|
||||
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
||||
if (cbMaxAuthBlob < INITIATE_GAME_CONNECTION_TICKET_SIZE) return 0;
|
||||
uint32 out_size = INITIATE_GAME_CONNECTION_TICKET_SIZE;
|
||||
ticket_manager->getTicketData(pAuthBlob, INITIATE_GAME_CONNECTION_TICKET_SIZE, &out_size);
|
||||
auth_manager->getTicketData(pAuthBlob, INITIATE_GAME_CONNECTION_TICKET_SIZE, &out_size);
|
||||
return out_size;
|
||||
}
|
||||
|
||||
@ -311,7 +311,7 @@ HAuthTicket GetAuthSessionTicket( void *pTicket, int cbMaxTicket, uint32 *pcbTic
|
||||
PRINT_DEBUG("Steam_User::GetAuthSessionTicket %i\n", cbMaxTicket);
|
||||
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
||||
|
||||
return ticket_manager->getTicket(pTicket, cbMaxTicket, pcbTicket);
|
||||
return auth_manager->getTicket(pTicket, cbMaxTicket, pcbTicket);
|
||||
}
|
||||
|
||||
// Request a ticket which will be used for webapi "ISteamUserAuth\AuthenticateUserTicket"
|
||||
@ -322,7 +322,7 @@ HAuthTicket GetAuthTicketForWebApi( const char *pchIdentity )
|
||||
PRINT_DEBUG("Steam_User::GetAuthTicketForWebApi %s\n", pchIdentity);
|
||||
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
||||
|
||||
return ticket_manager->getWebApiTicket(pchIdentity);
|
||||
return auth_manager->getWebApiTicket(pchIdentity);
|
||||
}
|
||||
|
||||
// Authenticate ticket from entity steamID to be sure it is valid and isnt reused
|
||||
@ -332,7 +332,7 @@ EBeginAuthSessionResult BeginAuthSession( const void *pAuthTicket, int cbAuthTic
|
||||
PRINT_DEBUG("Steam_User::BeginAuthSession %i %llu\n", cbAuthTicket, steamID.ConvertToUint64());
|
||||
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
||||
|
||||
return ticket_manager->beginAuth(pAuthTicket, cbAuthTicket, steamID);
|
||||
return auth_manager->beginAuth(pAuthTicket, cbAuthTicket, steamID);
|
||||
}
|
||||
|
||||
// Stop tracking started by BeginAuthSession - called when no longer playing game with this entity
|
||||
@ -341,7 +341,7 @@ void EndAuthSession( CSteamID steamID )
|
||||
PRINT_DEBUG("Steam_User::EndAuthSession\n");
|
||||
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
||||
|
||||
ticket_manager->endAuth(steamID);
|
||||
auth_manager->endAuth(steamID);
|
||||
}
|
||||
|
||||
// Cancel auth ticket from GetAuthSessionTicket, called when no longer playing game with the entity you gave the ticket to
|
||||
@ -350,7 +350,7 @@ void CancelAuthTicket( HAuthTicket hAuthTicket )
|
||||
PRINT_DEBUG("Steam_User::CancelAuthTicket\n");
|
||||
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
||||
|
||||
ticket_manager->cancelTicket(hAuthTicket);
|
||||
auth_manager->cancelTicket(hAuthTicket);
|
||||
}
|
||||
|
||||
// After receiving a user's authentication data, and passing it to BeginAuthSession, use this function
|
||||
|
@ -0,0 +1 @@
|
||||
Rename this to: gc_token.txt to can generate GC inside new App Ticket
|
@ -0,0 +1 @@
|
||||
Rename this to: new_app_ticket.txt to generate new app ticket
|
Loading…
Reference in New Issue
Block a user