diff options
author | George Hazan <ghazan@miranda.im> | 2021-01-04 21:27:45 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2021-01-04 21:27:45 +0300 |
commit | a9a97c244bf5cea6d1e7a2e48b91f08558829387 (patch) | |
tree | 2dc7edeaf2ceae48dec7b89efb39ebb59b1abef3 /protocols/Steam/src | |
parent | 8adfc2b2b5fa4aaab9fee1e8b5a38ad44da94306 (diff) |
Steam:
- global LastMessageTS field removed because it's senseless, now it's stored for each contact separately;
- options code cleaning;
- project file fix;
- version bump
Diffstat (limited to 'protocols/Steam/src')
-rw-r--r-- | protocols/Steam/src/stdafx.h | 2 | ||||
-rw-r--r-- | protocols/Steam/src/steam_events.cpp | 5 | ||||
-rw-r--r-- | protocols/Steam/src/steam_history.cpp | 41 | ||||
-rw-r--r-- | protocols/Steam/src/steam_login.cpp | 5 | ||||
-rw-r--r-- | protocols/Steam/src/steam_messages.cpp | 4 | ||||
-rw-r--r-- | protocols/Steam/src/steam_options.cpp | 152 | ||||
-rw-r--r-- | protocols/Steam/src/steam_options.h | 54 | ||||
-rw-r--r-- | protocols/Steam/src/steam_polling.cpp | 16 | ||||
-rw-r--r-- | protocols/Steam/src/steam_proto.cpp | 15 | ||||
-rw-r--r-- | protocols/Steam/src/steam_proto.h | 6 | ||||
-rw-r--r-- | protocols/Steam/src/version.h | 2 |
11 files changed, 129 insertions, 173 deletions
diff --git a/protocols/Steam/src/stdafx.h b/protocols/Steam/src/stdafx.h index cf702499fb..9f15ce8bfc 100644 --- a/protocols/Steam/src/stdafx.h +++ b/protocols/Steam/src/stdafx.h @@ -40,6 +40,7 @@ #include "version.h"
#define MODULE "Steam"
+#define DB_KEY_LASTMSGTS "LastMessageTS"
#define STEAM_API_TIMEOUT 30
#define STEAM_API_IDLEOUT_AWAY 600
@@ -62,7 +63,6 @@ extern HANDLE hExtraXStatus; #define now() time(0)
#include "steam_dialogs.h"
-#include "steam_options.h"
#include "http_request.h"
#include "api/enums.h"
diff --git a/protocols/Steam/src/steam_events.cpp b/protocols/Steam/src/steam_events.cpp index dc00158952..1db7ae6480 100644 --- a/protocols/Steam/src/steam_events.cpp +++ b/protocols/Steam/src/steam_events.cpp @@ -15,11 +15,6 @@ void CSteamProto::OnModulesLoaded() DbEvent_RegisterType(&dbEventType); } -INT_PTR CSteamProto::OnAccountManagerInit(WPARAM, LPARAM lParam) -{ - return (INT_PTR)(CSteamOptionsMain::CreateAccountManagerPage(this, (HWND)lParam))->GetHwnd(); -} - int CSteamProto::OnIdleChanged(WPARAM, LPARAM lParam) { bool idle = (lParam & IDF_ISIDLE) != 0; diff --git a/protocols/Steam/src/steam_history.cpp b/protocols/Steam/src/steam_history.cpp index 27c693cb30..50b70b562c 100644 --- a/protocols/Steam/src/steam_history.cpp +++ b/protocols/Steam/src/steam_history.cpp @@ -2,45 +2,41 @@ void CSteamProto::OnGotConversations(const JSONNode &root, void *) { - // Don't load any messages when we don't have lastMessageTS, as it may cause duplicates - if (m_lastMessageTS <= 0) - return; - if (root.isnull()) return; const JSONNode &response = root["response"]; for (auto &session : response["message_sessions"]) { long long accountId = _wtoi64(session["accountid_friend"].as_mstring()); - const char *who = AccountIdToSteamId(accountId); - - time_t lastMessageTS = _wtoi64(session["last_message"].as_mstring()); - /*node = json_get(session, "last_view"); - time_t last_view = _wtoi64(ptrW(json_as_string(node))); + const char *who = AccountIdToSteamId(accountId); + MCONTACT hContact = GetContact(who); + if (!hContact) + continue; - node = json_get(session, "unread_message_count"); - long unread_count = json_as_int(node);*/ + // Don't load any messages when we don't have lastMessageTS, as it may cause duplicates + time_t storedMessageTS = getDword(hContact, DB_KEY_LASTMSGTS); + if (storedMessageTS == 0) + continue; - if (lastMessageTS > m_lastMessageTS) { + time_t lastMessageTS = _wtoi64(session["last_message"].as_mstring()); + if (lastMessageTS > storedMessageTS) { ptrA token(getStringA("TokenSecret")); ptrA steamId(getStringA("SteamID")); - PushRequest(new GetHistoryMessagesRequest(token, steamId, who, m_lastMessageTS), &CSteamProto::OnGotHistoryMessages, mir_strdup(who)); + PushRequest(new GetHistoryMessagesRequest(token, steamId, who, storedMessageTS), &CSteamProto::OnGotHistoryMessages, (void*)hContact); } } } void CSteamProto::OnGotHistoryMessages(const JSONNode &root, void *arg) { - ptrA cSteamId((char *)arg); - - MCONTACT hContact = GetContact(cSteamId); - if (!hContact) - return; - if (root.isnull()) return; + MCONTACT hContact = UINT_PTR(arg); + time_t storedMessageTS = getDword(hContact, DB_KEY_LASTMSGTS); + time_t newTS = storedMessageTS; + const JSONNode &response = root["response"]; const JSONNode &messages = response["messages"]; for (size_t i = messages.size(); i > 0; i--) { @@ -54,7 +50,7 @@ void CSteamProto::OnGotHistoryMessages(const JSONNode &root, void *arg) time_t timestamp = _wtoi64(message["timestamp"].as_mstring()); // Ignore already existing messages - if (timestamp <= m_lastMessageTS) + if (timestamp <= storedMessageTS) continue; PROTORECVEVENT recv = { 0 }; @@ -65,5 +61,10 @@ void CSteamProto::OnGotHistoryMessages(const JSONNode &root, void *arg) recv.flags = PREF_SENT; RecvMsg(hContact, &recv); + + if (timestamp > newTS) + newTS = timestamp; } + + setDword(hContact, DB_KEY_LASTMSGTS, newTS); } diff --git a/protocols/Steam/src/steam_login.cpp b/protocols/Steam/src/steam_login.cpp index 37e046c262..63bb9a3158 100644 --- a/protocols/Steam/src/steam_login.cpp +++ b/protocols/Steam/src/steam_login.cpp @@ -349,11 +349,6 @@ void CSteamProto::OnLoggedOn(const HttpResponse &response, void *) long messageId = root["umqid"].as_int(); setDword("MessageID", messageId); - if (m_lastMessageTS <= 0) { - time_t timestamp = _wtoi64(root["utc_timestamp"].as_mstring()); - setDword("LastMessageTS", timestamp); - } - // load contact list ptrA token(getStringA("TokenSecret")); ptrA steamId(getStringA("SteamID")); diff --git a/protocols/Steam/src/steam_messages.cpp b/protocols/Steam/src/steam_messages.cpp index 27f4a08fb4..c4d9329761 100644 --- a/protocols/Steam/src/steam_messages.cpp +++ b/protocols/Steam/src/steam_messages.cpp @@ -38,8 +38,8 @@ void CSteamProto::OnMessageSent(const HttpResponse &response, void *arg) const JSONNode &time = root["utc_timestamp"];
if (time) {
timestamp = atol(node.as_string().c_str());
- if (timestamp > getDword("LastMessageTS", 0))
- setDword("LastMessageTS", timestamp);
+ if (timestamp > getDword(param->hContact, DB_KEY_LASTMSGTS))
+ setDword(param->hContact, DB_KEY_LASTMSGTS, timestamp);
}
}
diff --git a/protocols/Steam/src/steam_options.cpp b/protocols/Steam/src/steam_options.cpp index 62728a2cae..c59d90e9bb 100644 --- a/protocols/Steam/src/steam_options.cpp +++ b/protocols/Steam/src/steam_options.cpp @@ -1,79 +1,104 @@ #include "stdafx.h"
-CSteamOptionsMain::CSteamOptionsMain(CSteamProto *proto, int idDialog, HWND hwndParent) :
- CSteamDlgBase(proto, idDialog),
- m_username(this, IDC_USERNAME),
- m_password(this, IDC_PASSWORD),
- m_group(this, IDC_GROUP),
- m_biggerAvatars(this, IDC_BIGGER_AVATARS),
- m_showChatEvents(this, IDC_SHOW_CHAT_EVENTS),
- m_pollingErrorLimit(this, IDC_POLLINGERRORLIMITSPIN, 255)
+class CSteamOptionsMain : public CSteamDlgBase
{
- SetParent(hwndParent);
+ CCtrlEdit m_username, m_password, m_group;
+ CCtrlCheck m_biggerAvatars, m_showChatEvents;
+ CCtrlSpin m_pollingErrorLimit;
+
+public:
+ CSteamOptionsMain(CSteamProto *proto, int idDialog, HWND hwndParent = NULL) :
+ CSteamDlgBase(proto, idDialog),
+ m_username(this, IDC_USERNAME),
+ m_password(this, IDC_PASSWORD),
+ m_group(this, IDC_GROUP),
+ m_biggerAvatars(this, IDC_BIGGER_AVATARS),
+ m_showChatEvents(this, IDC_SHOW_CHAT_EVENTS),
+ m_pollingErrorLimit(this, IDC_POLLINGERRORLIMITSPIN, 255)
+ {
+ SetParent(hwndParent);
+
+ CreateLink(m_username, "Username", L"");
+ CreateLink(m_password, "Password", L"");
+ CreateLink(m_group, "DefaultGroup", L"Steam");
+
+ if (idDialog == IDD_OPT_MAIN) {
+ CreateLink(m_biggerAvatars, "UseBigAvatars", DBVT_BYTE, FALSE);
+ CreateLink(m_showChatEvents, "ShowChatEvents", DBVT_BYTE, TRUE);
+ CreateLink(m_pollingErrorLimit, "PollingErrorsLimit", DBVT_BYTE, STEAM_API_POLLING_ERRORS_LIMIT);
+ }
+ }
- CreateLink(m_username, "Username", L"");
- CreateLink(m_password, "Password", L"");
- CreateLink(m_group, "DefaultGroup", L"Steam");
+ bool OnInitDialog() override
+ {
+ CSteamDlgBase::OnInitDialog();
- if (idDialog == IDD_OPT_MAIN) {
- CreateLink(m_biggerAvatars, "UseBigAvatars", DBVT_BYTE, FALSE);
- CreateLink(m_showChatEvents, "ShowChatEvents", DBVT_BYTE, TRUE);
- CreateLink(m_pollingErrorLimit, "PollingErrorsLimit", DBVT_BYTE, STEAM_API_POLLING_ERRORS_LIMIT);
+ SendMessage(m_username.GetHwnd(), EM_LIMITTEXT, 64, 0);
+ SendMessage(m_password.GetHwnd(), EM_LIMITTEXT, 64, 0);
+ SendMessage(m_group.GetHwnd(), EM_LIMITTEXT, 64, 0);
+ return true;
}
-}
-
-bool CSteamOptionsMain::OnInitDialog()
-{
- CSteamDlgBase::OnInitDialog();
- SendMessage(m_username.GetHwnd(), EM_LIMITTEXT, 64, 0);
- SendMessage(m_password.GetHwnd(), EM_LIMITTEXT, 64, 0);
- SendMessage(m_group.GetHwnd(), EM_LIMITTEXT, 64, 0);
- return true;
-}
+ bool OnApply() override
+ {
+ ptrW group(m_group.GetText());
+ if (mir_wstrcmp(group, m_proto->m_defaultGroup)) {
+ m_proto->m_defaultGroup = mir_wstrdup(group);
+ Clist_GroupCreate(0, group);
+ }
+
+ if (m_proto->IsOnline()) // may be we should show message box with warning?
+ m_proto->SetStatus(ID_STATUS_OFFLINE);
+
+ if (m_username.IsChanged()) {
+ m_proto->delSetting("SteamID");
+ m_proto->delSetting("TokenSecret");
+ }
+ if (m_password.IsChanged())
+ m_proto->delSetting("TokenSecret");
+ return true;
+ }
+};
-bool CSteamOptionsMain::OnApply()
+INT_PTR CSteamProto::OnAccountManagerInit(WPARAM, LPARAM lParam)
{
- ptrW group(m_group.GetText());
- if (mir_wstrcmp(group, m_proto->m_defaultGroup)) {
- m_proto->m_defaultGroup = mir_wstrdup(group);
- Clist_GroupCreate(0, group);
- }
- if (m_proto->IsOnline())
- // may be we should show message box with warning?
- m_proto->SetStatus(ID_STATUS_OFFLINE);
- if (m_username.IsChanged()) {
- m_proto->delSetting("SteamID");
- m_proto->delSetting("TokenSecret");
- }
- if (m_password.IsChanged())
- m_proto->delSetting("TokenSecret");
- return true;
+ auto *page = new CSteamOptionsMain(this, IDD_ACCMGR, (HWND)lParam);
+ page->Show();
+ return (INT_PTR)page->GetHwnd();
}
/////////////////////////////////////////////////////////////////////////////////
-CSteamOptionsBlockList::CSteamOptionsBlockList(CSteamProto *proto)
- : CSuper(proto, IDD_OPT_BLOCK_LIST),
- m_list(this, IDC_LIST),
- m_contacts(this, IDC_CONTACTS),
- m_add(this, IDC_BLOCK)
+class CSteamOptionsBlockList : public CSteamDlgBase
{
- m_add.OnClick = Callback(this, &CSteamOptionsBlockList::OnBlock);
-}
+ typedef CSteamDlgBase CSuper;
+
+ CCtrlListView m_list;
+ CCtrlCombo m_contacts;
+ CCtrlButton m_add;
+
+public:
+ CSteamOptionsBlockList(CSteamProto *proto) :
+ CSuper(proto, IDD_OPT_BLOCK_LIST),
+ m_list(this, IDC_LIST),
+ m_contacts(this, IDC_CONTACTS),
+ m_add(this, IDC_BLOCK)
+ {
+ m_add.OnClick = Callback(this, &CSteamOptionsBlockList::OnBlock);
+ }
-bool CSteamOptionsBlockList::OnInitDialog()
-{
- m_list.SetExtendedListViewStyle(LVS_EX_SUBITEMIMAGES | LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP);
+ bool OnInitDialog() override
+ {
+ m_list.SetExtendedListViewStyle(LVS_EX_SUBITEMIMAGES | LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP);
- m_list.AddColumn(0, TranslateT("Name"), 220);
- m_list.AddColumn(1, L"", 32 - GetSystemMetrics(SM_CXVSCROLL));
- return true;
-}
+ m_list.AddColumn(0, TranslateT("Name"), 220);
+ m_list.AddColumn(1, L"", 32 - GetSystemMetrics(SM_CXVSCROLL));
+ return true;
+ }
-void CSteamOptionsBlockList::OnBlock(CCtrlButton *)
-{
-}
+ void OnBlock(CCtrlButton *)
+ {}
+};
/////////////////////////////////////////////////////////////////////////////////
@@ -85,12 +110,11 @@ int CSteamProto::OnOptionsInit(WPARAM wParam, LPARAM) odp.szGroup.w = LPGENW("Network");
odp.szTab.w = LPGENW("Account");
- odp.pDialog = CSteamOptionsMain::CreateOptionsPage(this);
+ odp.pDialog = new CSteamOptionsMain(this, IDD_OPT_MAIN);
g_plugin.addOptions(wParam, &odp);
- //odp.szTab.w = LPGENW("Blocked contacts");
- //odp.pDialog = CSteamOptionsBlockList::CreateOptionsPage(this);
- //g_plugin.addOptions(wParam, &odp);
-
+ // odp.szTab.w = LPGENW("Blocked contacts");
+ // odp.pDialog = new CSteamOptionsBlockList(this);
+ // g_plugin.addOptions(wParam, &odp);
return 0;
}
diff --git a/protocols/Steam/src/steam_options.h b/protocols/Steam/src/steam_options.h deleted file mode 100644 index a71e6ae2fa..0000000000 --- a/protocols/Steam/src/steam_options.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef _STEAM_OPTIONS_H_
-#define _STEAM_OPTIONS_H_
-
-class CSteamOptionsMain : public CSteamDlgBase
-{
-private:
- CCtrlEdit m_username;
- CCtrlEdit m_password;
- CCtrlEdit m_group;
-
- CCtrlCheck m_biggerAvatars;
- CCtrlCheck m_showChatEvents;
-
- CCtrlSpin m_pollingErrorLimit;
-
-protected:
- CSteamOptionsMain(CSteamProto *proto, int idDialog, HWND hwndParent = NULL);
-
- bool OnInitDialog() override;
- bool OnApply() override;
-
-public:
- static CDlgBase *CreateAccountManagerPage(void *param, HWND owner)
- {
- CSteamOptionsMain *page = new CSteamOptionsMain((CSteamProto*)param, IDD_ACCMGR, owner);
- page->Show();
- return page;
- }
-
- static CDlgBase *CreateOptionsPage(void *param) { return new CSteamOptionsMain((CSteamProto*)param, IDD_OPT_MAIN); }
-};
-
-/////////////////////////////////////////////////////////////////////////////////
-
-class CSteamOptionsBlockList : public CSteamDlgBase
-{
-private:
- typedef CSteamDlgBase CSuper;
-
- CCtrlListView m_list;
- CCtrlCombo m_contacts;
- CCtrlButton m_add;
-
-protected:
- bool OnInitDialog() override;
- void OnBlock(CCtrlButton*);
-
-public:
- CSteamOptionsBlockList(CSteamProto *proto);
-
- static CDlgBase *CreateOptionsPage(void *param) { return new CSteamOptionsBlockList((CSteamProto*)param); }
-};
-
-#endif //_STEAM_OPTIONS_H_
\ No newline at end of file diff --git a/protocols/Steam/src/steam_polling.cpp b/protocols/Steam/src/steam_polling.cpp index dd37ce9409..e2b5bdd3e3 100644 --- a/protocols/Steam/src/steam_polling.cpp +++ b/protocols/Steam/src/steam_polling.cpp @@ -10,7 +10,16 @@ void CSteamProto::ParsePollData(const JSONNode &data) time_t timestamp = _wtol(item["utc_timestamp"].as_mstring()); bool bIsMe = IsMe(steamId.c_str()); - MCONTACT hContact = (bIsMe) ? 0 : GetContact(steamId.c_str()); + MCONTACT hContact; + if (!bIsMe) { + hContact = GetContact(steamId.c_str()); + if (hContact == 0) + continue; + + if (timestamp > getDword(hContact, DB_KEY_LASTMSGTS)) + setDword(hContact, DB_KEY_LASTMSGTS, timestamp); + } + else hContact = 0; if (type == "personarelationship") { PersonaRelationshipAction state = (PersonaRelationshipAction)item["persona_state"].as_int(); @@ -179,11 +188,6 @@ void CSteamProto::OnGotPoll(const HttpResponse &response, void *arg) } if (error == "OK") { - // remember last message timestamp - time_t timestamp = _wtoi64(root["utc_timestamp"].as_mstring()); - if (timestamp > getDword("LastMessageTS", 0)) - setDword("LastMessageTS", timestamp); - long messageId = root["messagelast"].as_int(); setDword("MessageID", messageId); diff --git a/protocols/Steam/src/steam_proto.cpp b/protocols/Steam/src/steam_proto.cpp index 635db0c9cc..35bef1b6db 100644 --- a/protocols/Steam/src/steam_proto.cpp +++ b/protocols/Steam/src/steam_proto.cpp @@ -6,10 +6,6 @@ CSteamProto::CSteamProto(const char *protoName, const wchar_t *userName) : { CreateProtoService(PS_CREATEACCMGRUI, &CSteamProto::OnAccountManagerInit); - m_idleTS = 0; - m_lastMessageTS = 0; - isLoginAgain = false; - m_hPollingThread = nullptr; m_hRequestsQueueEvent = CreateEvent(NULL, FALSE, FALSE, NULL); // default group @@ -83,6 +79,12 @@ CSteamProto::CSteamProto(const char *protoName, const wchar_t *userName) : m_hNetlibUser = Netlib_RegisterUser(&nlu); debugLogA(__FUNCTION__":Setting protocol / module name to '%s'", m_szModuleName); + + if (DWORD iGlobalValue = getDword(DB_KEY_LASTMSGTS)) { + for (auto &cc : AccContacts()) + setDword(cc, DB_KEY_LASTMSGTS, iGlobalValue); + delSetting(DB_KEY_LASTMSGTS); + } } CSteamProto::~CSteamProto() @@ -302,13 +304,8 @@ int CSteamProto::SetStatus(int new_status) Logout(); } else if (m_hRequestQueueThread == nullptr && !IsStatusConnecting(m_iStatus)) { - // Load last message timestamp for correct loading of messages history - m_lastMessageTS = getDword("LastMessageTS", 0); - m_iStatus = ID_STATUS_CONNECTING; - m_isTerminated = false; - ForkThread(&CSteamProto::RequestQueueThread); Login(); diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h index 6ebec59789..aec2210c51 100644 --- a/protocols/Steam/src/steam_proto.h +++ b/protocols/Steam/src/steam_proto.h @@ -79,12 +79,6 @@ class CSteamProto : public PROTO<CSteamProto> std::map<HANDLE, time_t> m_mpOutMessages;
std::map<std::string, time_t> m_typingTimestamps;
- /**
- * Used only to compare in steam_history.cpp, others should write such value directly to db profile, because PollingThread
- * may start sooner than steam_history requests so it could possibly break getting history messages from server
- */
- time_t m_lastMessageTS;
-
public:
// PROTO_INTERFACE
CSteamProto(const char *protoName, const wchar_t *userName);
diff --git a/protocols/Steam/src/version.h b/protocols/Steam/src/version.h index 8602d055cb..93d250c23e 100644 --- a/protocols/Steam/src/version.h +++ b/protocols/Steam/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 95
#define __RELEASE_NUM 12
-#define __BUILD_NUM 1
+#define __BUILD_NUM 2
#include <stdver.h>
|