summaryrefslogtreecommitdiff
path: root/protocols/Steam/src
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2014-05-02 22:22:41 +0000
committerAlexander Lantsev <aunsane@gmail.com>2014-05-02 22:22:41 +0000
commit70436074ae8f66a092d0212fb8b99b94d0fd03a6 (patch)
tree694fd4a013fd9b81e393bc0cf2d83b51920e009c /protocols/Steam/src
parent9b111dc84cd76cdbdb3f820237d3de0b1555deb1 (diff)
Steam: improved contact management
git-svn-id: http://svn.miranda-ng.org/main/trunk@9108 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Steam/src')
-rw-r--r--protocols/Steam/src/Steam/authorization.h2
-rw-r--r--protocols/Steam/src/Steam/friend_list.h8
-rw-r--r--protocols/Steam/src/Steam/login.h1
-rw-r--r--protocols/Steam/src/Steam/message.h3
-rw-r--r--protocols/Steam/src/Steam/pending.h3
-rw-r--r--protocols/Steam/src/Steam/poll.h1
-rw-r--r--protocols/Steam/src/http_request.h6
-rw-r--r--protocols/Steam/src/steam_account.cpp10
-rw-r--r--protocols/Steam/src/steam_contacts.cpp31
-rw-r--r--protocols/Steam/src/steam_proto.cpp55
-rw-r--r--protocols/Steam/src/steam_proto.h2
-rw-r--r--protocols/Steam/src/steam_thread.cpp6
12 files changed, 85 insertions, 43 deletions
diff --git a/protocols/Steam/src/Steam/authorization.h b/protocols/Steam/src/Steam/authorization.h
index baa5d2c93f..a8911034a0 100644
--- a/protocols/Steam/src/Steam/authorization.h
+++ b/protocols/Steam/src/Steam/authorization.h
@@ -82,7 +82,6 @@ namespace SteamWebApi
time(NULL));
SecureHttpPostRequest request(hConnection, STEAM_COM_URL "/mobilelogin/dologin");
- request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.ResetFlags(NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMP);
request.SetData(data, strlen(data));
@@ -149,7 +148,6 @@ namespace SteamWebApi
authResult->cookie.c_str());
SecureHttpPostRequest second_request(hConnection, STEAM_COM_URL "/mobileloginsucceeded");
- second_request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
second_request.ResetFlags(NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMP);
second_request.SetData(data, strlen(data));
diff --git a/protocols/Steam/src/Steam/friend_list.h b/protocols/Steam/src/Steam/friend_list.h
index 78a30333a0..4ce1ae1aec 100644
--- a/protocols/Steam/src/Steam/friend_list.h
+++ b/protocols/Steam/src/Steam/friend_list.h
@@ -47,6 +47,7 @@ namespace SteamWebApi
SecureHttpGetRequest request(hConnection, STEAM_API_URL "/ISteamUserOAuth/GetFriendList/v0001");
request.AddParameter("access_token", token);
request.AddParameter("steamid", steamId);
+ request.AddParameter("relationship=friend,ignoredfriend,requestrecipient");
//relationship = friend, requestrecipient
mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
@@ -111,7 +112,6 @@ namespace SteamWebApi
who);
SecureHttpPostRequest request(hConnection, STEAM_COM_URL "/actions/AddFriendAjax");
- request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddHeader("Cookie", cookie);
request.SetData(data, strlen(data));
@@ -119,7 +119,10 @@ namespace SteamWebApi
if (!response)
return;
- if ((result->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK || lstrcmpiA(response->pData, "true"))
+ JSONNODE *root = json_parse(response->pData), *node;
+ node = json_get(root, "success");
+
+ if ((result->status = (HTTP_STATUS)response->resultCode) != HTTP_STATUS_OK || json_as_int(node) == 0)
return;
result->success = true;
@@ -142,7 +145,6 @@ namespace SteamWebApi
who);
SecureHttpPostRequest request(hConnection, STEAM_COM_URL "/actions/RemoveFriendAjax");
- request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddHeader("Cookie", cookie);
request.SetData(data, strlen(data));
diff --git a/protocols/Steam/src/Steam/login.h b/protocols/Steam/src/Steam/login.h
index 30593d9c14..84d29ef2f2 100644
--- a/protocols/Steam/src/Steam/login.h
+++ b/protocols/Steam/src/Steam/login.h
@@ -30,7 +30,6 @@ namespace SteamWebApi
mir_snprintf(data, SIZEOF(data), "access_token=%s", token);
SecureHttpPostRequest request(hConnection, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Logon/v0001");
- request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.SetData(data, strlen(data));
mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
diff --git a/protocols/Steam/src/Steam/message.h b/protocols/Steam/src/Steam/message.h
index c3c95a28bb..bb9fec3bc1 100644
--- a/protocols/Steam/src/Steam/message.h
+++ b/protocols/Steam/src/Steam/message.h
@@ -31,7 +31,6 @@ namespace SteamWebApi
state);
SecureHttpPostRequest request(hConnection, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Message/v0001");
- request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.SetData(data, strlen(data));
mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
@@ -57,7 +56,6 @@ namespace SteamWebApi
ptrA(mir_urlEncode(text)));
SecureHttpPostRequest request(hConnection, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Message/v0001");
- request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.SetData(data, strlen(data));
mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
@@ -93,7 +91,6 @@ namespace SteamWebApi
steamId);
SecureHttpPostRequest request(hConnection, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Message/v0001");
- request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.SetData(data, strlen(data));
mir_ptr<NETLIBHTTPREQUEST> response(request.Send());
diff --git a/protocols/Steam/src/Steam/pending.h b/protocols/Steam/src/Steam/pending.h
index d010e6982b..ea65627b32 100644
--- a/protocols/Steam/src/Steam/pending.h
+++ b/protocols/Steam/src/Steam/pending.h
@@ -23,7 +23,6 @@ namespace SteamWebApi
mir_snprintf(data, SIZEOF(data), "sessionID=%s&id=%s&perform=accept&action=approvePending&itype=friend&json=1&xml=0", sessionId, who);
SecureHttpPostRequest request(hConnection, url);
- request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddHeader("Cookie", cookie);
request.SetData(data, strlen(data));
@@ -54,7 +53,6 @@ namespace SteamWebApi
mir_snprintf(data, SIZEOF(data), "sessionID=%s&id=%s&perform=ignore&action=approvePending&itype=friend&json=1&xml=0", sessionId, who);
SecureHttpPostRequest request(hConnection, url);
- request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddHeader("Cookie", cookie);
request.SetData(data, strlen(data));
@@ -85,7 +83,6 @@ namespace SteamWebApi
mir_snprintf(data, SIZEOF(data), "sessionID=%s&id=%s&perform=block&action=approvePending&itype=friend&json=1&xml=0", sessionId, who);
SecureHttpPostRequest request(hConnection, url);
- request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddHeader("Cookie", cookie);
request.SetData(data, strlen(data));
diff --git a/protocols/Steam/src/Steam/poll.h b/protocols/Steam/src/Steam/poll.h
index be90890725..c6f40cf749 100644
--- a/protocols/Steam/src/Steam/poll.h
+++ b/protocols/Steam/src/Steam/poll.h
@@ -93,7 +93,6 @@ namespace SteamWebApi
mir_snprintf(data, SIZEOF(data), "access_token=%s&umqid=%s&message=%u", token, umqId, messageId);
SecureHttpPostRequest request(hConnection, STEAM_API_URL "/ISteamWebUserPresenceOAuth/Poll/v0001");
- request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.SetData(data, strlen(data));
request.SetTimeout(90000); // may need to encrease timeout
diff --git a/protocols/Steam/src/http_request.h b/protocols/Steam/src/http_request.h
index c08bd1434a..b4f312111b 100644
--- a/protocols/Steam/src/http_request.h
+++ b/protocols/Steam/src/http_request.h
@@ -115,7 +115,6 @@ public:
NETLIBHTTPREQUEST *response = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNetlibUser, (LPARAM)this);
mir_free(szUrl);szUrl = NULL;
return response;
-
}
private:
@@ -156,7 +155,10 @@ class SecureHttpPostRequest : public SecureHttpRequest
{
public:
SecureHttpPostRequest(HANDLE hNetlibUser, LPCSTR url)
- : SecureHttpRequest(hNetlibUser, REQUEST_POST, url) { }
+ : SecureHttpRequest(hNetlibUser, REQUEST_POST, url)
+ {
+ AddHeader("Content-Type", "application/x-www-form-urlencoded");
+ }
};
#endif //_HTTP_REQUEST_H_ \ No newline at end of file
diff --git a/protocols/Steam/src/steam_account.cpp b/protocols/Steam/src/steam_account.cpp
index 0335d40b1d..13708c50f7 100644
--- a/protocols/Steam/src/steam_account.cpp
+++ b/protocols/Steam/src/steam_account.cpp
@@ -146,7 +146,7 @@ void CSteamProto::LogInThread(void* param)
token = mir_strdup(authResult.GetToken());
setString("TokenSecret", token);
- setString("Cookie", authResult.GetCookie());
+ //setString("Cookie", authResult.GetCookie());
setString("SteamID", authResult.GetSteamid());
setString("SessionID", authResult.GetSessionId());
}
@@ -180,7 +180,7 @@ void CSteamProto::LogInThread(void* param)
m_iStatus = m_iDesiredStatus;
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus);
- ptrA sessionId(getStringA("SessionID"));
+ /*ptrA sessionId(getStringA("SessionID"));
if (!sessionId || lstrlenA(sessionId) == 0)
{
SteamWebApi::SessionApi::SessionId result;
@@ -188,7 +188,7 @@ void CSteamProto::LogInThread(void* param)
SteamWebApi::SessionApi::GetSessionId(m_hNetlibUser, token, loginResult.GetSteamId(), &result);
if (result.IsSuccess())
setString("SessionID", result.GetSessionId());
- }
+ }*/
// load contact list
LoadContactListThread(NULL);
@@ -206,8 +206,8 @@ void CSteamProto::LogOutThread(void*)
ptrA token(getStringA("TokenSecret"));
ptrA umqId(getStringA("UMQID"));
- while (m_bTerminated && m_hPollingThread != NULL)
- Sleep(500);
+ while (!Miranda_Terminated() && m_bTerminated && m_hPollingThread != NULL)
+ Sleep(200);
debugLogA("CSteamProto::LogOutThread: call SteamWebApi::LoginApi::Logoff");
SteamWebApi::LoginApi::Logoff(m_hNetlibUser, token, umqId);
diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp
index 2f3018a873..aaccb3bf75 100644
--- a/protocols/Steam/src/steam_contacts.cpp
+++ b/protocols/Steam/src/steam_contacts.cpp
@@ -181,7 +181,7 @@ void CSteamProto::UpdateContactsThread(void *arg)
}
}
-MCONTACT CSteamProto::AddContact(const char *steamId)
+MCONTACT CSteamProto::AddContact(const char *steamId, bool isTemporary)
{
MCONTACT hContact = this->FindContact(steamId);
if (!hContact)
@@ -195,6 +195,13 @@ MCONTACT CSteamProto::AddContact(const char *steamId)
// update info
//UpdateContact(hContact, contact);
+ if (isTemporary)
+ {
+ setByte(hContact, "Auth", 1);
+ //setByte(hContact, "Grant", 1);
+ db_set_b(hContact, "CList", "NotOnList", 1);
+ }
+
// move to default group
DBVARIANT dbv;
if (!getWString("DefaultGroup", &dbv))
@@ -216,6 +223,9 @@ void CSteamProto::RaiseAuthRequestThread(void *arg)
ptrA token(getStringA("TokenSecret"));
ptrA steamId(getStringA(hContact, "SteamID"));
+ //setByte(hContact, "Auth", 1);
+ setByte(hContact, "Grant", 1);
+
SteamWebApi::FriendApi::Summaries summaries;
debugLogA("CSteamProto::RaiseAuthRequestThread: call SteamWebApi::FriendApi::LoadSummaries");
SteamWebApi::FriendApi::LoadSummaries(m_hNetlibUser, token, steamId, &summaries);
@@ -275,6 +285,7 @@ void CSteamProto::AuthAllowThread(void *arg)
{
delSetting(hContact, "Auth");
delSetting(hContact, "Grant");
+ db_unset(hContact, "CList", "NotOnList");
/*SteamWebApi::FriendApi::Summaries summaries;
debugLogA("CSteamProto::AuthAllowThread: call SteamWebApi::FriendApi::LoadSummaries");
@@ -305,6 +316,22 @@ void CSteamProto::AuthDenyThread(void *arg)
void CSteamProto::AddContactThread(void *arg)
{
+ MCONTACT hContact = (MCONTACT)arg;
+ if (!hContact)
+ return;
+
+ ptrA token(getStringA("TokenSecret"));
+ ptrA sessionId(getStringA("SessionID"));
+ ptrA steamId(getStringA("SteamID"));
+ ptrA who(getStringA(hContact, "SteamID"));
+
+ //db_unset(hContact, "CList", "NotOnList");
+
+ SteamWebApi::FriendListApi::Result result;
+ debugLogA("CSteamProto::AddContactThread: call SteamWebApi::FriendListApi::AddFriend");
+ SteamWebApi::FriendListApi::AddFriend(m_hNetlibUser, token, sessionId, steamId, who, &result);
+
+ ProtoBroadcastAck(hContact, ACKTYPE_AUTHREQ, result.IsSuccess() ? ACKRESULT_SUCCESS : ACKRESULT_FAILED, (HANDLE)hContact, NULL);
}
void CSteamProto::RemoveContactThread(void *arg)
@@ -355,7 +382,7 @@ void CSteamProto::LoadContactListThread(void*)
{
MCONTACT hContact = FindContact(steamId);
if (!hContact)
- hContact = AddContact(steamId);
+ hContact = AddContact(steamId, true);
RaiseAuthRequestThread((void*)hContact);
}
diff --git a/protocols/Steam/src/steam_proto.cpp b/protocols/Steam/src/steam_proto.cpp
index 73dd62791b..c1258042a0 100644
--- a/protocols/Steam/src/steam_proto.cpp
+++ b/protocols/Steam/src/steam_proto.cpp
@@ -45,12 +45,26 @@ CSteamProto::~CSteamProto()
MCONTACT __cdecl CSteamProto::AddToList(int flags, PROTOSEARCHRESULT* psr)
{
- if (psr->cbSize != sizeof(STEAM_SEARCH_RESULT))
- return 0;
+ MCONTACT hContact = NULL;
+
+ if (psr->cbSize == sizeof(PROTOSEARCHRESULT))
+ {
+ char *steamId = mir_u2a(psr->id);
+ if (!FindContact(steamId))
+ {
+ hContact = AddContact(steamId, true);
+ ForkThread(&CSteamProto::UpdateContactsThread, (void*)steamId);
+ }
+ else
+ mir_free(steamId);
+ }
+ else if (psr->cbSize == sizeof(STEAM_SEARCH_RESULT))
+ {
+ STEAM_SEARCH_RESULT *ssr = (STEAM_SEARCH_RESULT*)psr;
+ hContact = AddContact(ssr->contact->GetSteamId(), true);
+ UpdateContact(hContact, ssr->contact);
+ }
- STEAM_SEARCH_RESULT *ssr = (STEAM_SEARCH_RESULT*)psr;
- MCONTACT hContact = AddContact(ssr->contact->GetSteamId());
- UpdateContact(hContact, ssr->contact);
return hContact;
}
@@ -68,7 +82,7 @@ int __cdecl CSteamProto::Authorize(HANDLE hDbEvent)
return 1;
ForkThread(&CSteamProto::AuthAllowThread, (void*)hContact);
- // todo: how to return real status?
+
return 0;
}
@@ -84,9 +98,10 @@ int __cdecl CSteamProto::AuthDeny(HANDLE hDbEvent, const TCHAR* szReason)
return 1;
ForkThread(&CSteamProto::AuthDenyThread, (void*)hContact);
- // todo: how to return real status?
+
return 0;
}
+
return 1;
}
@@ -97,25 +112,32 @@ int __cdecl CSteamProto::AuthRecv(MCONTACT hContact, PROTORECVEVENT* pre)
int __cdecl CSteamProto::AuthRequest(MCONTACT hContact, const TCHAR* szMessage)
{
- return 0;
+ if (IsOnline() && hContact)
+ {
+ ForkThread(&CSteamProto::AddContactThread, (void*)hContact);
+
+ return hContact;
+ }
+
+ return 1;
}
-HANDLE __cdecl CSteamProto::FileAllow(MCONTACT hContact, HANDLE hTransfer, const TCHAR* szPath )
+HANDLE __cdecl CSteamProto::FileAllow(MCONTACT hContact, HANDLE hTransfer, const TCHAR* szPath)
{
return 0;
}
-int __cdecl CSteamProto::FileCancel(MCONTACT hContact, HANDLE hTransfer )
+int __cdecl CSteamProto::FileCancel(MCONTACT hContact, HANDLE hTransfer)
{
return 0;
}
-int __cdecl CSteamProto::FileDeny(MCONTACT hContact, HANDLE hTransfer, const TCHAR* szReason )
+int __cdecl CSteamProto::FileDeny(MCONTACT hContact, HANDLE hTransfer, const TCHAR* szReason)
{
return 0;
}
-int __cdecl CSteamProto::FileResume( HANDLE hTransfer, int* action, const TCHAR** szFilename )
+int __cdecl CSteamProto::FileResume(HANDLE hTransfer, int* action, const TCHAR** szFilename)
{
return 0;
}
@@ -125,11 +147,11 @@ DWORD_PTR __cdecl CSteamProto:: GetCaps(int type, MCONTACT hContact)
switch(type)
{
case PFLAGNUM_1:
- return PF1_IM | PF1_BASICSEARCH | PF1_SEARCHBYNAME;
+ return PF1_IM | PF1_BASICSEARCH | PF1_SEARCHBYNAME | PF1_AUTHREQ | PF1_SERVERCLIST;
case PFLAGNUM_2:
return PF2_ONLINE | PF2_SHORTAWAY | PF2_HEAVYDND | PF2_OUTTOLUNCH;
case PFLAGNUM_4:
- return PF4_NOCUSTOMAUTH | PF4_AVATARS | PF4_NOAUTHDENYREASON;
+ return PF4_NOCUSTOMAUTH | PF4_AVATARS | PF4_NOAUTHDENYREASON;// | PF4_FORCEAUTH | PF4_FORCEADDED;
case PFLAGNUM_5:
return PF2_SHORTAWAY | PF2_HEAVYDND | PF2_OUTTOLUNCH;
case PFLAG_UNIQUEIDTEXT:
@@ -190,7 +212,7 @@ int __cdecl CSteamProto::RecvFile(MCONTACT hContact, PROTORECVFILET* pre)
int __cdecl CSteamProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT* pre)
{
- return (INT_PTR)AddDBEvent(hContact, EVENTTYPE_MESSAGE, time(NULL), DBEF_UTF, lstrlenA(pre->szMessage), (BYTE*)pre->szMessage);
+ return (INT_PTR)AddDBEvent(hContact, EVENTTYPE_MESSAGE, pre->timestamp, DBEF_UTF, lstrlenA(pre->szMessage), (BYTE*)pre->szMessage);
}
int __cdecl CSteamProto::RecvUrl(MCONTACT hContact, PROTORECVEVENT *) { return 0; }
@@ -278,7 +300,8 @@ int __cdecl CSteamProto::OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM
return this->OnOptionsInit(wParam, lParam);*/
case EV_PROTO_ONCONTACTDELETED:
- ForkThread(&CSteamProto::RemoveContactThread, (void*)getStringA(wParam, "SteamID"));
+ if (this->IsOnline())
+ ForkThread(&CSteamProto::RemoveContactThread, (void*)getStringA(wParam, "SteamID"));
return 0;
/*case EV_PROTO_ONMENU:
diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h
index 402338b2c7..7f188cca14 100644
--- a/protocols/Steam/src/steam_proto.h
+++ b/protocols/Steam/src/steam_proto.h
@@ -136,7 +136,7 @@ protected:
void __cdecl UpdateContactsThread(void*);
MCONTACT FindContact(const char *steamId);
- MCONTACT AddContact(const char *steamId);
+ MCONTACT AddContact(const char *steamId, bool isTemporary = false);
void __cdecl RaiseAuthRequestThread(void*);
void __cdecl AuthAllowThread(void*);
diff --git a/protocols/Steam/src/steam_thread.cpp b/protocols/Steam/src/steam_thread.cpp
index a9deac4e74..91f202a955 100644
--- a/protocols/Steam/src/steam_thread.cpp
+++ b/protocols/Steam/src/steam_thread.cpp
@@ -116,10 +116,8 @@ void CSteamProto::PollServer(const char *token, const char *umqId, UINT32 messag
MCONTACT hContact = FindContact(steamId);
if (!hContact)
- hContact = AddContact(steamId);
+ hContact = AddContact(steamId, true);
- setByte(hContact, "Auth", 1);
- setByte(hContact, "Grant", 1);
RaiseAuthRequestThread((void*)hContact);
}
break;
@@ -158,7 +156,7 @@ void CSteamProto::PollingThread(void*)
if (pollResult.GetStatus() == HTTP_STATUS_UNAUTHORIZED)
{
delSetting("TokenSecret");
- delSetting("Cookie");
+ //delSetting("Cookie");
}
break;