diff options
author | George Hazan <ghazan@miranda.im> | 2016-12-27 22:06:02 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2016-12-27 22:06:02 +0300 |
commit | 8db6b3f25e173f7c305580fad8cbd67a7121b169 (patch) | |
tree | e12f6518d302efc46f159c6a3bf35fce471076a6 /protocols/Discord/src | |
parent | cd689cb08d614fb2f405167debec66c7c2ef6843 (diff) |
implementation of CDiscordProto::SetStatus
Diffstat (limited to 'protocols/Discord/src')
-rw-r--r-- | protocols/Discord/src/connection.cpp | 23 | ||||
-rw-r--r-- | protocols/Discord/src/main.cpp | 2 | ||||
-rw-r--r-- | protocols/Discord/src/options.cpp | 8 | ||||
-rw-r--r-- | protocols/Discord/src/proto.cpp | 58 | ||||
-rw-r--r-- | protocols/Discord/src/proto.h | 11 | ||||
-rw-r--r-- | protocols/Discord/src/utils.cpp | 25 |
6 files changed, 107 insertions, 20 deletions
diff --git a/protocols/Discord/src/connection.cpp b/protocols/Discord/src/connection.cpp new file mode 100644 index 0000000000..a7e3babd41 --- /dev/null +++ b/protocols/Discord/src/connection.cpp @@ -0,0 +1,23 @@ +/* +Copyright © 2016 Miranda NG team + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "stdafx.h" + +void CDiscordProto::ServerThread(void*) +{ + +} diff --git a/protocols/Discord/src/main.cpp b/protocols/Discord/src/main.cpp index 9779dd8817..340ce425bb 100644 --- a/protocols/Discord/src/main.cpp +++ b/protocols/Discord/src/main.cpp @@ -55,7 +55,7 @@ extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOC static PROTO_INTERFACE* protoInit(const char *proto_name, const wchar_t *username) { - return new ÑDiscordProto(proto_name, username); + return new CDiscordProto(proto_name, username); } static int protoUninit(PROTO_INTERFACE *proto) diff --git a/protocols/Discord/src/options.cpp b/protocols/Discord/src/options.cpp index 6b9fe9b497..2f16811b6a 100644 --- a/protocols/Discord/src/options.cpp +++ b/protocols/Discord/src/options.cpp @@ -17,13 +17,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "stdafx.h" -class CDiscardAccountOptions : public CProtoDlgBase<ÑDiscordProto> +class CDiscardAccountOptions : public CProtoDlgBase<CDiscordProto> { CCtrlEdit m_edGroup, m_edUserName, m_edPassword; public: - CDiscardAccountOptions(ÑDiscordProto *ppro) : - CProtoDlgBase<ÑDiscordProto>(ppro, IDD_OPTIONS_ACCOUNT), + CDiscardAccountOptions(CDiscordProto *ppro) : + CProtoDlgBase<CDiscordProto>(ppro, IDD_OPTIONS_ACCOUNT), m_edGroup(this, IDC_GROUP), m_edUserName(this, IDC_USERNAME), m_edPassword(this, IDC_PASSWORD) @@ -56,7 +56,7 @@ public: } }; -int ÑDiscordProto::OnOptionsInit(WPARAM wParam, LPARAM) +int CDiscordProto::OnOptionsInit(WPARAM wParam, LPARAM) { OPTIONSDIALOGPAGE odp = { 0 }; odp.hInstance = g_hInstance; diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index c0af3fe2bd..1c557daaa7 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -17,22 +17,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "stdafx.h" -ÑDiscordProto::ÑDiscordProto(const char *proto_name, const wchar_t *username) : - PROTO<ÑDiscordProto>(proto_name, username) +CDiscordProto::CDiscordProto(const char *proto_name, const wchar_t *username) : + PROTO<CDiscordProto>(proto_name, username) { // Services - CreateProtoService(PS_GETNAME, &ÑDiscordProto::GetName); - CreateProtoService(PS_GETSTATUS, &ÑDiscordProto::GetStatus); + CreateProtoService(PS_GETNAME, &CDiscordProto::GetName); + CreateProtoService(PS_GETSTATUS, &CDiscordProto::GetStatus); // Events - HookProtoEvent(ME_OPT_INITIALISE, &ÑDiscordProto::OnOptionsInit); + HookProtoEvent(ME_OPT_INITIALISE, &CDiscordProto::OnOptionsInit); } -ÑDiscordProto::~ÑDiscordProto() +CDiscordProto::~CDiscordProto() { } -DWORD_PTR ÑDiscordProto::GetCaps(int type, MCONTACT) +DWORD_PTR CDiscordProto::GetCaps(int type, MCONTACT) { switch (type) { case PFLAGNUM_1: @@ -51,32 +51,66 @@ DWORD_PTR ÑDiscordProto::GetCaps(int type, MCONTACT) return 0; } -INT_PTR ÑDiscordProto::GetName(WPARAM wParam, LPARAM lParam) +INT_PTR CDiscordProto::GetName(WPARAM wParam, LPARAM lParam) { mir_strncpy((char*)lParam, m_szModuleName, (int)wParam); return 0; } -INT_PTR ÑDiscordProto::GetStatus(WPARAM, LPARAM) +INT_PTR CDiscordProto::GetStatus(WPARAM, LPARAM) { return m_iStatus; } +int CDiscordProto::SetStatus(int iNewStatus) +{ + if (iNewStatus == m_iStatus) + return 0; + + m_iDesiredStatus = iNewStatus; + int iOldStatus = m_iStatus; + + // all statuses but offline are treated as online + if (iNewStatus >= ID_STATUS_ONLINE && iNewStatus <= ID_STATUS_OUTTOLUNCH) { + m_iDesiredStatus = ID_STATUS_ONLINE; + + // if we're already connecting and they want to go online + if (IsStatusConnecting(m_iStatus)) + return 0; + + // if we're already connected, don't try to reconnect + if (m_iStatus >= ID_STATUS_ONLINE && m_iStatus <= ID_STATUS_OUTTOLUNCH) + return 0; + + m_iStatus = ID_STATUS_CONNECTING; + ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)iOldStatus, m_iStatus); + ForkThread(&CDiscordProto::ServerThread, this); + } + else if (iNewStatus == ID_STATUS_OFFLINE) { + m_iStatus = m_iDesiredStatus; + SetAllContactStatuses(ID_STATUS_OFFLINE); + + ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)iOldStatus, m_iStatus); + } + + return 0; +} + ///////////////////////////////////////////////////////////////////////////////////////// -int ÑDiscordProto::OnModulesLoaded(WPARAM, LPARAM) +int CDiscordProto::OnModulesLoaded(WPARAM, LPARAM) { return 0; } -int ÑDiscordProto::OnPreShutdown(WPARAM, LPARAM) +int CDiscordProto::OnPreShutdown(WPARAM, LPARAM) { return 0; } ///////////////////////////////////////////////////////////////////////////////////////// -int ÑDiscordProto::OnEvent(PROTOEVENTTYPE event, WPARAM wParam, LPARAM lParam) +int CDiscordProto::OnEvent(PROTOEVENTTYPE event, WPARAM wParam, LPARAM lParam) { switch (event) { case EV_PROTO_ONLOAD: return OnModulesLoaded(wParam, lParam); diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index e0c7e2c073..26466bcfae 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -1,14 +1,19 @@ -class ÑDiscordProto : public PROTO<ÑDiscordProto> +class CDiscordProto : public PROTO<CDiscordProto> { + void __cdecl ServerThread(void*); + + void SetAllContactStatuses(int iStatus); public: - ÑDiscordProto(const char*,const wchar_t*); - ~ÑDiscordProto(); + CDiscordProto(const char*,const wchar_t*); + ~CDiscordProto(); // PROTO_INTERFACE virtual DWORD_PTR __cdecl GetCaps(int, MCONTACT = 0) override; + virtual int __cdecl SetStatus(int iNewStatus) override; + virtual int __cdecl OnEvent(PROTOEVENTTYPE, WPARAM, LPARAM) override; // Services diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp new file mode 100644 index 0000000000..a542a4a7c5 --- /dev/null +++ b/protocols/Discord/src/utils.cpp @@ -0,0 +1,25 @@ +/* +Copyright © 2016 Miranda NG team + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "stdafx.h" + +void CDiscordProto::SetAllContactStatuses(int status) +{ + for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) + if (!getByte(hContact, "ChatRoom")) + setWord(hContact, "Status", (WORD)status); +} |