moved functions around for a clearer context

This commit is contained in:
a 2023-12-22 09:04:25 +02:00 committed by otavepto
parent 681fbc4ecb
commit 23c435bfea
4 changed files with 51 additions and 52 deletions

View File

@ -1,5 +1,21 @@
#include "auth.h"
static inline int generate_random_int() {
int a;
randombytes((char *)&a, sizeof(a));
return a;
}
static uint32 generate_steam_ticket_id() {
/* not random starts with 2? */
static uint32 a = 1;
++a;
// this must never return 0, it is reserved for "k_HAuthTicketInvalid" when the auth APIs fail
if (a == 0) ++a;
return a;
}
static void steam_auth_manager_ticket_callback(void *object, Common_Message *msg)
{
PRINT_DEBUG("steam_auth_manager_ticket_callback\n");

View File

@ -19,8 +19,7 @@
#ifdef __WINDOWS__
static void
randombytes(char * const buf, const size_t size)
void randombytes(char *buf, size_t size)
{
// NT_SUCCESS is: return value >= 0, including Ntdef.h causes so many errors
while (BCryptGenRandom(NULL, (PUCHAR) buf, (ULONG) size, BCRYPT_USE_SYSTEM_PREFERRED_RNG) < 0) {
@ -51,7 +50,7 @@ bool set_env_variable(std::string name, std::string value)
static int fd = -1;
static void randombytes(char *buf, size_t size)
void randombytes(char *buf, size_t size)
{
int i;
@ -104,29 +103,7 @@ const std::chrono::time_point<std::chrono::system_clock> startup_time = std::chr
const std::string dbg_log_file = get_full_program_path() + "STEAM_LOG.txt";
#endif
SteamAPICall_t generate_steam_api_call_id() {
static SteamAPICall_t a;
randombytes((char *)&a, sizeof(a));
++a;
if (a == 0) ++a;
return a;
}
int generate_random_int() {
int a;
randombytes((char *)&a, sizeof(a));
return a;
}
uint32 generate_steam_ticket_id() {
/* not random starts with 2? */
static uint32 a = 1;
++a;
if (a == 0) ++a;
return a;
}
static unsigned generate_account_id()
unsigned generate_account_id()
{
int a;
randombytes((char *)&a, sizeof(a));
@ -135,16 +112,24 @@ static unsigned generate_account_id()
return a;
}
CSteamID generate_steam_id_user()
{
return CSteamID(generate_account_id(), k_unSteamUserDefaultInstance, k_EUniversePublic, k_EAccountTypeIndividual);
}
CSteamID generate_steam_anon_user()
{
return CSteamID(generate_account_id(), k_unSteamUserDefaultInstance, k_EUniversePublic, k_EAccountTypeAnonUser);
}
SteamAPICall_t generate_steam_api_call_id() {
static SteamAPICall_t a;
randombytes((char *)&a, sizeof(a));
++a;
if (a == 0) ++a;
return a;
}
CSteamID generate_steam_id_user()
{
return CSteamID(generate_account_id(), k_unSteamUserDefaultInstance, k_EUniversePublic, k_EAccountTypeIndividual);
}
CSteamID generate_steam_id_server()
{
return CSteamID(generate_account_id(), k_unSteamUserDefaultInstance, k_EUniversePublic, k_EAccountTypeGameServer);
@ -160,22 +145,6 @@ 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;

View File

@ -26,6 +26,7 @@ extern std::recursive_mutex global_mutex;
extern const std::chrono::time_point<std::chrono::high_resolution_clock> startup_counter;
extern const std::chrono::time_point<std::chrono::system_clock> startup_time;
void randombytes(char *buf, size_t size);
std::string get_env_variable(std::string name);
bool set_env_variable(std::string name, std::string value);
bool check_timedout(std::chrono::high_resolution_clock::time_point old, double timeout);
@ -94,15 +95,13 @@ struct Steam_Call_Result {
int iCallback;
};
uint32 generate_steam_ticket_id();
int generate_random_int();
unsigned generate_account_id();
CSteamID generate_steam_anon_user();
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();
@ -306,7 +305,6 @@ public:
}
};
struct Steam_Call_Back {
std::vector<class CCallbackBase *> callbacks;
std::vector<std::vector<char>> results;

View File

@ -217,6 +217,22 @@ static inline void thisThreadYieldFor(std::chrono::microseconds u)
PRINT_DEBUG("Thread finished waiting\n");
}
static 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;
}
// Emulator includes
// add them here after the inline functions definitions
#include "net.pb.h"