-
Notifications
You must be signed in to change notification settings - Fork 0
/
User.h
55 lines (44 loc) · 1.15 KB
/
User.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#pragma once
#include <map>
#include "Entity.h"
#include "VyHub.h"
#include "Api.h"
#include <API/ARK/Ark.h>
#pragma comment(lib, "AsaApi.lib")
namespace User
{
inline std::unique_ptr<Entity::VyHubUser> getUser(std::string eosId, std::optional<std::string> username)
{
// Find the VyHubUser in the map based on the user ID
auto userIterator = VyHub::users.find(eosId);
if (userIterator != VyHub::users.end())
{
// return found user
const Entity::VyHubUser& user = userIterator->second;
return std::make_unique<Entity::VyHubUser>(user);
}
else {
// user not found, query user from API
std::unique_ptr<Entity::VyHubUser> vyhub_user = Api::getUser(eosId);
if (!vyhub_user)
{
// user not found, create user
vyhub_user = Api::createUser(eosId, username);
if (!vyhub_user)
{
// User creation failed
return NULL;
}
}
return vyhub_user;
}
}
inline std::unique_ptr<Entity::VyHubUser> getUser(std::string eosId)
{
return getUser(eosId, std::nullopt);
}
inline std::unique_ptr<Entity::VyHubUser> getUser(FString eosId)
{
return getUser(std::string(TCHAR_TO_UTF8(*eosId)), std::nullopt);
}
}