summaryrefslogtreecommitdiff
path: root/protocols/Dummy/src/dummy_proto.cpp
blob: f7c6c6396d34f23c1c399dbcdc4ac1690e53cfde (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
Copyright (c) 2014 Robert Pösel

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 version 2
of the License.

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 CDummyProto::SendMsgAck(void *param)
{
	MCONTACT hContact = (MCONTACT)param;
	Sleep(100);
	ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)0, (LPARAM)Translate("Dummy protocol is too dumb to send messages."));
}

static int sttCompareProtocols(const CDummyProto *p1, const CDummyProto *p2)
{
	return mir_tstrcmp(p1->m_tszUserName, p2->m_tszUserName);
}

LIST<CDummyProto> dummy_Instances(1, sttCompareProtocols);

CDummyProto::CDummyProto(const char *szModuleName, const TCHAR *ptszUserName) :
	PROTO<CDummyProto>(szModuleName, ptszUserName)
{
	CreateProtoService(PS_CREATEACCMGRUI, &CDummyProto::SvcCreateAccMgrUI);

	uniqueIdText[0] = '\0';
	uniqueIdSetting[0] = '\0';

	dummy_Instances.insert(this);
}

CDummyProto::~CDummyProto()
{
	Netlib_CloseHandle(m_hNetlibUser); m_hNetlibUser = NULL;
	dummy_Instances.remove(this);
}

//////////////////////////////////////////////////////////////////////////////

DWORD_PTR CDummyProto::GetCaps(int type, MCONTACT)
{
	switch(type) {
	case PFLAGNUM_1:
		return PF1_IM;

	case PFLAGNUM_2:
		return PF2_ONLINE | PF2_INVISIBLE | PF2_SHORTAWAY | PF2_LONGAWAY | PF2_LIGHTDND | PF2_HEAVYDND | PF2_FREECHAT | PF2_OUTTOLUNCH | PF2_ONTHEPHONE;

	case PFLAGNUM_3:
		return 0;

	case PFLAGNUM_4:
		return 0;

	case PFLAGNUM_5:
		return PF2_ONLINE | PF2_INVISIBLE | PF2_SHORTAWAY | PF2_LONGAWAY | PF2_LIGHTDND | PF2_HEAVYDND | PF2_FREECHAT | PF2_OUTTOLUNCH | PF2_ONTHEPHONE;

	case PFLAG_MAXLENOFMESSAGE:
		return 0;

	case PFLAG_UNIQUEIDTEXT:
		if (uniqueIdSetting[0] == '\0') {
			ptrA setting(getStringA(DUMMY_ID_TEXT));
			if (setting != NULL)
				strncpy_s(uniqueIdSetting, setting, _TRUNCATE);
		}
		return (DWORD_PTR)uniqueIdSetting;

	case PFLAG_UNIQUEIDSETTING:
		if (uniqueIdText[0] == '\0') {
			ptrA setting(getStringA(DUMMY_ID_SETTING));
			if (setting != NULL)
				strncpy_s(uniqueIdText, setting, _TRUNCATE);
		}
		return (DWORD_PTR)uniqueIdText;
	}
	return 0;
}

//////////////////////////////////////////////////////////////////////////////

int CDummyProto::SendMsg(MCONTACT hContact, int, const char*)
{
	ForkThread(&CDummyProto::SendMsgAck, (void*)hContact);
	return 0;
}

int CDummyProto::SetStatus(int)
{
	return 0;
}