summaryrefslogtreecommitdiff
path: root/protocols/Steam/src/steam_account.cpp
blob: 632969ad6708fdef0a74aface8d8a00580acfe10 (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "common.h"

void CSteamProto::LogInThread(void* param)
{
	CMStringA token(getStringA("TokenSecret"));
	if (token.IsEmpty())
	{
		ptrW username(getWStringA("Username"));
		ptrA password(getStringA("Password"));

		SteamWebApi::AuthorizationApi::Authorization authResult;
		SteamWebApi::AuthorizationApi::Authorize(m_hNetlibUser, username, password, &authResult);
	
		if (authResult.IsEmailAuthNeeded()/* || authResult.captcha_needed*/)
		{
			do
			{
				if (authResult.IsEmailAuthNeeded())
				{
					GuardParam guard;

					//lstrcpy(guard.emailDomain, authResult.emaildomain);

					if (DialogBoxParam(
						g_hInstance,
						MAKEINTRESOURCE(IDD_GUARD),
						NULL,
						CSteamProto::GuardProc,
						(LPARAM)&guard) != 1)
						break;

					authResult.SetAuthCode(guard.code);
				}

				//if (result->captcha_needed)
				//	;// proto->fail

				SteamWebApi::AuthorizationApi::Authorize(m_hNetlibUser, username, password, &authResult);

			} while (authResult.IsEmailAuthNeeded()/* || auth->captcha_needed*/);
		}

		if (!authResult.IsSuccess())
		{
			m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
			ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, ID_STATUS_OFFLINE);
			return;
		}

		token = authResult.GetToken();
		setString("TokenSecret", token);
		setString("SteamID", authResult.GetSteamid());
	}

	SteamWebApi::LogInApi::LogIn login;
	SteamWebApi::LogInApi::LogOn(m_hNetlibUser, token, &login);

	if (!login.IsSuccess())
	{
		m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
		ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, ID_STATUS_OFFLINE);
		return;
	}

	setString("SessionID", login.GetSessionId());
	setString("MessageID", login.GetMessageId());

	m_iStatus = m_iDesiredStatus;
	ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iDesiredStatus);

	if (m_hPollingThread == NULL)
		m_hPollingThread = ForkThreadEx(&CSteamProto::PollingThread, NULL, NULL);

	SteamWebApi::FriendListApi::FriendList friendList;
	SteamWebApi::FriendListApi::Load(m_hNetlibUser, token, login.GetSteamId(), &friendList);
	
	if (friendList.IsSuccess())
	{
		for (int i = 0; i < friendList.GetCount(); i++)
		{
			if (!FindContact(friendList[i]))
			{
				SteamWebApi::FriendApi::Friend rFriend;
				SteamWebApi::FriendApi::LoadSummaries(m_hNetlibUser, token, friendList[i], &rFriend);
				if (!rFriend.IsSuccess()) continue;
				AddContact(rFriend);
			}
		}
	}
}