From 9abbc99874c8558fab7995ef30a05fc40beddd81 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Tue, 3 Jun 2014 18:39:15 +0000 Subject: Steam: - add notifications - add user info updating - minor fixes git-svn-id: http://svn.miranda-ng.org/main/trunk@9407 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Steam/Steam_12.vcxproj | 2 +- protocols/Steam/src/steam_contacts.cpp | 12 ++++++------ protocols/Steam/src/steam_pooling.cpp | 36 +++++++++++++++++++++++++++------- protocols/Steam/src/steam_proto.h | 3 +++ protocols/Steam/src/steam_utils.cpp | 25 +++++++++++++++++++++++ 5 files changed, 64 insertions(+), 14 deletions(-) (limited to 'protocols') diff --git a/protocols/Steam/Steam_12.vcxproj b/protocols/Steam/Steam_12.vcxproj index 4f3259f87c..46bf63c6e8 100644 --- a/protocols/Steam/Steam_12.vcxproj +++ b/protocols/Steam/Steam_12.vcxproj @@ -19,7 +19,7 @@ - {8236EA1F-579A-4AFB-9DFE-5FA056AEDDBB} + {F5282DBC-756B-4071-B186-3E82C0E8E1F7} Steam diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp index c83eeb19d2..b3449088f5 100644 --- a/protocols/Steam/src/steam_contacts.cpp +++ b/protocols/Steam/src/steam_contacts.cpp @@ -255,6 +255,9 @@ void CSteamProto::UpdateContact(MCONTACT hContact, JSONNODE *data) // } //} + /*node = json_get(data, "timecreated"); + time_t created = json_as_int(node);*/ + // set country node = json_get(data, "loccountrycode"); if (node != NULL) @@ -295,10 +298,6 @@ void CSteamProto::UpdateContact(MCONTACT hContact, JSONNODE *data) delSetting(hContact, "GameID"); } } - - - /*node = json_get(data, "timecreated"); - time_t created = json_as_int(node);*/ } MCONTACT CSteamProto::AddContact(const char *steamId, bool isTemporary) @@ -423,7 +422,7 @@ void CSteamProto::OnFriendAdded(const NETLIBHTTPREQUEST *response, void *arg) { SendAuthParam *param = (SendAuthParam*)arg; - if (response->resultCode != HTTP_STATUS_OK || lstrcmpiA(response->pData, "true")) + if (response == NULL || response->resultCode != HTTP_STATUS_OK || lstrcmpiA(response->pData, "true")) { ptrA steamId(getStringA(param->hContact, "SteamID")); debugLogA("CSteamProto::OnFriendAdded: failed to add friend %s", steamId); @@ -442,7 +441,7 @@ void CSteamProto::OnFriendAdded(const NETLIBHTTPREQUEST *response, void *arg) void CSteamProto::OnFriendRemoved(const NETLIBHTTPREQUEST *response, void *arg) { - if (response->resultCode != HTTP_STATUS_OK || lstrcmpiA(response->pData, "true")) + if (response == NULL || response->resultCode != HTTP_STATUS_OK || lstrcmpiA(response->pData, "true")) { debugLogA("CSteamProto::OnFriendRemoved: failed to remove friend %s", ptrA((char*)arg)); } @@ -545,6 +544,7 @@ void CSteamProto::OnSearchByIdEnded(const NETLIBHTTPREQUEST *response, void *arg if (response == NULL || response->resultCode != HTTP_STATUS_OK) { ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_FAILED, (HANDLE)STEAM_SEARCH_BYID, 0); + debugLogA("CSteamProto::OnSearchByIdEnded: failed to get summaries for %s", ptrA((char*)arg)); return; } diff --git a/protocols/Steam/src/steam_pooling.cpp b/protocols/Steam/src/steam_pooling.cpp index c6f7c3c747..957a3dff68 100644 --- a/protocols/Steam/src/steam_pooling.cpp +++ b/protocols/Steam/src/steam_pooling.cpp @@ -132,6 +132,7 @@ void CSteamProto::ParsePollData(JSONNODE *data) { JSONNODE *node, *item = NULL; + std::string steamIds; for (size_t i = 0; i < json_size(data); i++) { item = json_at(data, i); @@ -171,12 +172,6 @@ void CSteamProto::ParsePollData(JSONNODE *data) if (hContact) AddDBEvent(hContact, EVENTTYPE_MESSAGE, timestamp, DBEF_UTF | DBEF_SENT, lstrlen(text), (BYTE*)mir_utf8encodeW(text)); } - - /*node = json_get(item, "text"); - if (node != NULL) message->text = json_as_string(node); - - node = json_get(item, "utc_timestamp"); - message->timestamp = atol(ptrA(mir_u2a(json_as_string(node))));*/ } /*else if (!lstrcmpi(type, L"typing")) { @@ -212,6 +207,7 @@ void CSteamProto::ParsePollData(JSONNODE *data) setWString(hContact, "Nick", json_as_string(node)); // todo: find difference between state changing and info changing + steamIds.append(steamId).append(","); } else if (!lstrcmpi(type, L"personarelationship")) { @@ -221,11 +217,26 @@ void CSteamProto::ParsePollData(JSONNODE *data) switch (state) { case 0: - // removed + {// removed + MCONTACT hContact = FindContact(steamId); + if (hContact) + { + setByte(hContact, "Auth", 1); + + wchar_t message[MAX_PATH]; + mir_sntprintf( + message, MAX_PATH, + TranslateT("%s has been removed from your contact list"), + ptrW(mir_a2u(steamId))); + + ShowNotification(L"Steam", message); + } + } break; case 1: // ignored + // todo break; case 2: @@ -247,6 +258,7 @@ void CSteamProto::ParsePollData(JSONNODE *data) case 3: // add to list + // todo break; default: continue; @@ -260,6 +272,16 @@ void CSteamProto::ParsePollData(JSONNODE *data) continue; } } + + if (!steamIds.empty()) + { + steamIds.pop_back(); + ptrA token(getStringA("TokenSecret")); + + PushRequest( + new SteamWebApi::GetUserSummariesRequest(token, steamIds.c_str()), + &CSteamProto::OnGotUserSummaries); + } } void CSteamProto::PollingThread(void*) diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h index 8e930d287a..0ce865978f 100644 --- a/protocols/Steam/src/steam_proto.h +++ b/protocols/Steam/src/steam_proto.h @@ -262,6 +262,9 @@ protected: HANDLE AddDBEvent(MCONTACT hContact, WORD type, DWORD timestamp, DWORD flags, DWORD cbBlob, PBYTE pBlob); + static void CSteamProto::ShowNotification(const wchar_t *message, int flags = 0, MCONTACT hContact = NULL); + static void CSteamProto::ShowNotification(const wchar_t *caption, const wchar_t *message, int flags = 0, MCONTACT hContact = NULL); + // options static INT_PTR CALLBACK GuardProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); static INT_PTR CALLBACK CaptchaProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); diff --git a/protocols/Steam/src/steam_utils.cpp b/protocols/Steam/src/steam_utils.cpp index 1ac29f593c..1e7d27b3ec 100644 --- a/protocols/Steam/src/steam_utils.cpp +++ b/protocols/Steam/src/steam_utils.cpp @@ -143,4 +143,29 @@ HANDLE CSteamProto::AddDBEvent(MCONTACT hContact, WORD type, DWORD timestamp, DW dbei.flags = flags; return db_event_add(hContact, &dbei); +} + +void CSteamProto::ShowNotification(const wchar_t *caption, const wchar_t *message, int flags, MCONTACT hContact) +{ + if (Miranda_Terminated()) + return; + + if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1)) + { + POPUPDATAW ppd = { 0 }; + ppd.lchContact = hContact; + wcsncpy(ppd.lpwzContactName, caption, MAX_CONTACTNAME); + wcsncpy(ppd.lpwzText, message, MAX_SECONDLINE); + ppd.lchIcon = ::Skin_GetIcon("Skype_main"); + + if (!PUAddPopupW(&ppd)) + return; + } + + MessageBoxW(NULL, message, caption, MB_OK | flags); +} + +void CSteamProto::ShowNotification(const wchar_t *message, int flags, MCONTACT hContact) +{ + ShowNotification(TranslateT(MODULE), message, flags, hContact); } \ No newline at end of file -- cgit v1.2.3