summaryrefslogtreecommitdiff
path: root/protocols/Skype/src/skype_proto.cpp
blob: 508c0684f9bcaa3826c992620b844be2b2b27f94 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
#include "skype.h"
#include "skype_chat.h"

CSkypeProto::CSkypeProto(const char* protoName, const TCHAR* userName) :
	PROTO<CSkypeProto>(protoName, userName),
	Skype(1), 
	skypeKitPort(8963),
	chatRooms(5)
{
	this->rememberPassword = false;

	::InitializeCriticalSection(&this->contact_search_lock);

	this->SetAllContactStatus(ID_STATUS_OFFLINE);

	DBEVENTTYPEDESCR dbEventType = { sizeof(dbEventType) };
	dbEventType.module = this->m_szModuleName;
	dbEventType.flags = DETF_HISTORY | DETF_MSGWINDOW;

	dbEventType.eventType = SKYPE_DB_EVENT_TYPE_EMOTE;
	dbEventType.descr = "Skype emote";
	::CallService(MS_DB_EVENT_REGISTERTYPE, 0, (LPARAM)&dbEventType);

	dbEventType.eventType = SKYPE_DB_EVENT_TYPE_CONTACTS;
	dbEventType.descr = "Skype contacts";
	dbEventType.eventIcon = CSkypeProto::GetSkinIconHandle("sendContacts");
	::CallService(MS_DB_EVENT_REGISTERTYPE, 0, (LPARAM)&dbEventType);

	dbEventType.eventType = SKYPE_DB_EVENT_TYPE_CALL;
	dbEventType.descr = "Skype call";
	dbEventType.eventIcon = CSkypeProto::GetSkinIconHandle("call");
	::CallService(MS_DB_EVENT_REGISTERTYPE, 0, (LPARAM)&dbEventType);

	this->InitInstanceServiceList();
}

CSkypeProto::~CSkypeProto()
{
	::DeleteCriticalSection(&this->contact_search_lock);

	::mir_free(this->login);
	if (this->password)
	{
		::mir_free(this->password);
		this->password = NULL;
	}
}

MCONTACT __cdecl CSkypeProto::AddToList(int flags, PROTOSEARCHRESULT* psr)
{
	CContact::Ref contact;
	this->GetContact((char *)mir_ptr<char>(::mir_utf8encodeW(psr->id)), contact);
	return this->AddContact(contact);
}

MCONTACT __cdecl CSkypeProto::AddToListByEvent(int flags, int iContact, HANDLE hDbEvent)
{
	DBEVENTINFO dbei = {0};
	dbei.cbSize = sizeof(dbei);

	/*if ((dbei.cbBlob = CallService(MS_DB_EVENT_GETBLOBSIZE, (WPARAM)hDbEvent, 0)) != -1)
	{
	dbei.pBlob = (PBYTE)alloca(dbei.cbBlob);
	if (CallService(MS_DB_EVENT_GET, (WPARAM)hDbEvent, (LPARAM)&dbei) == 0 &&
	!strcmp(dbei.szModule, m_szModuleName) &&
	(dbei.eventType == EVENTTYPE_AUTHREQUEST || dbei.eventType == EVENTTYPE_CONTACTS))
	{
	char *nick = (char*)(dbei.pBlob + sizeof(DWORD) * 2);
	char *firstName = nick + strlen(nick) + 1;
	char *lastName = firstName + strlen(firstName) + 1;
	char *skypeName = lastName + strlen(lastName) + 1;
	return AddContactBySkypeName(::mir_a2u(skypeName), ::mir_a2u(nick), 0);
	}
	}*/
	return 0;
}

int __cdecl CSkypeProto::Authorize(HANDLE hDbEvent)
{
	if (this->IsOnline() && hDbEvent)
	{
		MCONTACT hContact = this->GetContactFromAuthEvent(hDbEvent);
		if (hContact == INVALID_CONTACT_ID)
			return 1;

		return CSkypeProto::GrantAuth((WPARAM)hContact, NULL);
	}

	return 1;
}

int __cdecl CSkypeProto::AuthDeny(HANDLE hDbEvent, const TCHAR* szReason)
{
	if (this->IsOnline())
	{
		MCONTACT hContact = this->GetContactFromAuthEvent(hDbEvent);
		if (hContact == INVALID_CONTACT_ID)
			return 1;

		return CSkypeProto::RevokeAuth((WPARAM)hContact, NULL);
	}

	return 1;
}

int __cdecl CSkypeProto::AuthRecv(MCONTACT hContact, PROTORECVEVENT* pre)
{
	DWORD flags = 0;

	if (pre->flags & PREF_CREATEREAD)
		flags |= DBEF_READ;

	if (pre->flags & PREF_UTF)
		flags |= DBEF_UTF;

	this->AddDBEvent(
		hContact,
		EVENTTYPE_AUTHREQUEST,
		pre->timestamp,
		flags,
		pre->lParam,
		(PBYTE)pre->szMessage);

	return 0;
}

int __cdecl CSkypeProto::AuthRequest(MCONTACT hContact, const TCHAR* szMessage)
{
	if (this->IsOnline() && hContact)
	{
		CContact::Ref contact;
		SEString sid(_T2A(::db_get_wsa(hContact, this->m_szModuleName, SKYPE_SETTINGS_SID)));
		if (this->GetContact(sid, contact))
		{
			contact->SetBuddyStatus(Contact::AUTHORIZED_BY_ME);
			contact->SendAuthRequest(::mir_utf8encodeW(szMessage));
		}

		return 0;
	}

	return 1;
}

HANDLE __cdecl CSkypeProto::ChangeInfo( int iInfoType, void* pInfoData ) { return 0; }

HANDLE __cdecl CSkypeProto::FileAllow(MCONTACT hContact, HANDLE hTransfer, const TCHAR* szPath ) 
{ 
	uint oid = (uint)hTransfer;

	this->debugLogW(L"Incoming file transfer is accepted");

	bool success;
	wchar_t fullPath[MAX_PATH] = {0};

	SEString data;
	MessageRef msgRef(oid);
	TransferRefs transfers;
	msgRef->GetTransfers(transfers);
	for (uint i = 0; i < transfers.size(); i++)
	{
		auto transfer = transfers[i];
		transfer->GetPropFilename(data);
		ptrW name(::mir_utf8decodeW(data));
		::mir_sntprintf(fullPath, MAX_PATH, L"%s%s", szPath, name);

		auto fOid = transfer->getOID();
		FileTransferParam ftp = this->transferts[oid];

		//PROTOFILETRANSFERSTATUS pfts = { sizeof(pfts) };
		//pfts.hContact = hContact;
		//pfts.flags = PFTS_UNICODE | PFTS_RECEIVING;
		//pfts.ptszFiles = ftp.pfts.ptszFiles;
		//pfts.totalFiles = ftp.pfts.totalFiles;
		//pfts.currentFileNumber = i;
		//pfts.totalBytes = ftp.files[fOid].size;
		//pfts.totalProgress = ftp.files[fOid].transfered;
		//pfts.tszWorkingDir = mir_wstrdup(szPath);
		//pfts.currentFileNumber = 0;
		//pfts.tszCurrentFile = mir_wstrdup(fullPath);
		////pfts.tszCurrentFile = ::mir_utf8decodeW(data);
		//pfts.currentFileSize = ftp.files[fOid].size;
		//pfts.currentFileProgress = ftp.files[fOid].transfered;

		//if ( !ProtoBroadcastAck(hContact, ACKTYPE_FILE, ACKRESULT_FILERESUME, (HANDLE)oid, (LPARAM)&pfts))
			if ( !transfer->Accept((char *)ptrA(::mir_utf8encodeW(fullPath)), success) || !success)
			{
				this->debugLogW(L"Cannot accept file transfer");
				this->transferList.remove_val(transfer);
			}
	}

	return hTransfer; 
}

int    __cdecl CSkypeProto::FileCancel(MCONTACT hContact, HANDLE hTransfer ) 
{
	uint oid = (uint)hTransfer;

	MessageRef msgRef(oid);
	TransferRefs transfers;
	Transfer::STATUS transferStatus;
	msgRef->GetTransfers(transfers);
	for (uint i = 0; i < transfers.size(); i++)
	{
		auto transfer = transfers[i];
		transfer->GetPropStatus(transferStatus);
		if (transferStatus <= Transfer::CANCELLED && this->transferList.contains(transfer))
		{
			if ( !transfer->Cancel())
				this->debugLogW(L"Incoming file transfer is cancelled");
			this->transferList.remove_val(transfer);
		}
	}
	this->transferts.erase(this->transferts.find(oid));

	return 1; 
}

int    __cdecl CSkypeProto::FileDeny(MCONTACT hContact, HANDLE hTransfer, const TCHAR* szReason )
{
	uint oid = (uint)hTransfer;

	MessageRef msgRef(oid);
	TransferRefs transfers;
	Transfer::STATUS transferStatus;
	msgRef->GetTransfers(transfers);
	for (uint i = 0; i < transfers.size(); i++)
	{
		auto transfer = transfers[i];
		transfer->GetPropStatus(transferStatus);
		if (transferStatus <= Transfer::CANCELLED && this->transferList.contains(transfer))
		{
			if ( !transfer->Cancel())
				this->debugLogW(L"Incoming file transfer is denied");
			this->transferList.remove_val(transfer);
		}
	}
	this->transferts.erase(this->transferts.find(oid));

	return 1;
}

int    __cdecl CSkypeProto::FileResume( HANDLE hTransfer, int* action, const TCHAR** szFilename )
{
	if ( !this->IsOnline())
		return 1;

	uint oid = (uint)hTransfer;

	//auto fOid = transfers[i]->getOID();
	FileTransferParam ftp = this->transferts[oid];

	MessageRef msgRef(oid);
	TransferRefs transfers;
	msgRef->GetTransfers(transfers);
	for (uint i = 0; i < transfers.size(); i++){}

	switch (*action)
	{
	case FILERESUME_SKIP:
		/*if (ft->p2p_appID != 0)
		p2p_sendStatus(ft, 603);
		else
		msnftp_sendAcceptReject (ft, false);*/
		break;

	case FILERESUME_RESUME:
		//replaceStrT(ft->std.tszCurrentFile, *szFilename);
		break;

	case FILERESUME_RENAME:
		//replaceStrT(ft->std.tszCurrentFile, *szFilename);
		break;

	default:
		/*bool fcrt = ft->create() != -1;
		if (ft->p2p_appID != 0)
		{
		if (fcrt)
		p2p_sendFeedStart(ft);

		p2p_sendStatus(ft, fcrt ? 200 : 603);
		}
		else
		msnftp_sendAcceptReject (ft, fcrt);*/

		//ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, ft, 0);
		break;
	}

	return 0;
}

DWORD_PTR __cdecl CSkypeProto:: GetCaps(int type, MCONTACT hContact)
{
	switch(type)
	{
	case PFLAGNUM_1:
		return PF1_IM | PF1_FILE | PF1_BASICSEARCH | PF1_ADDSEARCHRES | PF1_SEARCHBYEMAIL | PF1_SEARCHBYNAME |
			PF1_AUTHREQ | PF1_CHAT | PF1_SERVERCLIST | PF1_CONTACT/* | PF1_ADDSEARCHRES*/;
	case PFLAGNUM_2:
	case PFLAGNUM_3:
		return PF2_ONLINE | PF2_SHORTAWAY | PF2_HEAVYDND | PF2_INVISIBLE | PF2_ONTHEPHONE;
	case PFLAGNUM_4:
		return PF4_FORCEAUTH | PF4_FORCEADDED | PF4_SUPPORTTYPING | PF4_AVATARS | 
			/*PF4_OFFLINEFILES | */PF4_IMSENDUTF | PF4_IMSENDOFFLINE | PF4_NOAUTHDENYREASON;
	case PFLAGNUM_5:
		return PF2_ONTHEPHONE;
	case PFLAG_UNIQUEIDTEXT:
		return (DWORD_PTR)::Translate("Skype name");
	case PFLAG_MAXCONTACTSPERPACKET:
		return 1024;
	case PFLAG_UNIQUEIDSETTING:
		return (DWORD_PTR)SKYPE_SETTINGS_SID;
	default:
		return 0;
	}
}

int    __cdecl CSkypeProto::GetInfo(MCONTACT hContact, int infoType ) { return 0; }

HANDLE __cdecl CSkypeProto::SearchBasic(const TCHAR* id)
{
	if ( !this->IsOnline())
		return 0;

	this->ForkThread(&CSkypeProto::SearchBySidAsync, ::mir_tstrdup(id));

	return (HANDLE)SKYPE_SEARCH_BYSID;
}

HANDLE __cdecl CSkypeProto::SearchByEmail(const TCHAR* email)
{
	if ( !this->IsOnline())
		return 0;

	this->ForkThread(&CSkypeProto::SearchByEmailAsync, ::mir_tstrdup(email));

	return (HANDLE)SKYPE_SEARCH_BYEMAIL;
}

HANDLE __cdecl CSkypeProto::SearchByName(const TCHAR* nick, const TCHAR* firstName, const TCHAR* lastName)
{
	PROTOSEARCHRESULT *psr = new PROTOSEARCHRESULT();
	psr->cbSize = sizeof(psr);
	psr->flags = PSR_TCHAR;
	psr->nick = ::mir_wstrdup(nick);
	psr->firstName = ::mir_wstrdup(firstName);
	psr->lastName = ::mir_wstrdup(lastName);

	this->ForkThread(&CSkypeProto::SearchByNamesAsync, psr);

	return (HANDLE)SKYPE_SEARCH_BYNAMES;
}

HWND   __cdecl CSkypeProto::SearchAdvanced( HWND owner ) { return 0; }

HWND   __cdecl CSkypeProto::CreateExtendedSearchUI( HWND owner ){ return 0; }

int    __cdecl CSkypeProto::RecvContacts(MCONTACT hContact, PROTORECVEVENT* pre) 
{
	this->debugLogW(L"Incoming contacts");
	::db_unset(hContact, "CList", "Hidden");

	return (INT_PTR)this->AddDBEvent(
		hContact,
		EVENTTYPE_CONTACTS,
		pre->timestamp,
		DBEF_UTF | ((pre->flags & PREF_CREATEREAD) ? DBEF_READ : 0),
		pre->lParam,
		(PBYTE)pre->szMessage);
}

int    __cdecl CSkypeProto::RecvFile(MCONTACT hContact, PROTORECVFILET* pre) 
{ 
	this->debugLogW(L"Incoming file transfer");
	::db_unset(hContact, "CList", "Hidden");
	return ::Proto_RecvFile(hContact, pre);
}

int __cdecl CSkypeProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT* pre)
{
	this->debugLogW(L"Incoming message");
	::db_unset(hContact, "CList", "Hidden");

	ReadMessageParam *param = (ReadMessageParam*)pre->lParam;

	char *message = (char *)pre->szMessage;
	size_t msgLen = ::strlen(message) + 1;

	message = (char *)::mir_realloc(message, msgLen + param->guid.size());
	::memcpy((char *)&message[msgLen], param->guid.data(), param->guid.size());

	return (INT_PTR)this->AddDBEvent(
		hContact,
		param->msgType == CMessage::POSTED_TEXT ? EVENTTYPE_MESSAGE : SKYPE_DB_EVENT_TYPE_EMOTE,
		pre->timestamp,
		DBEF_UTF | ((pre->flags & PREF_CREATEREAD) ? DBEF_READ : 0),
		DWORD(msgLen + param->guid.size()),
		(PBYTE)message);
}

int __cdecl CSkypeProto::RecvUrl(MCONTACT hContact, PROTORECVEVENT *) { return 0; }

int __cdecl CSkypeProto::SendContacts(MCONTACT hContact, int flags, int nContacts, MCONTACT *hContactsList)
{
	if (this->IsOnline() && hContact && hContactsList)
	{
		this->debugLogW(L"Outcoming contacts");

		ConversationRef conversation;
		if ( !this->isChatRoom(hContact))
		{
			SEStringList targets;
			targets.append((char *)_T2A(::db_get_wsa(hContact, this->m_szModuleName, SKYPE_SETTINGS_SID)));

			this->GetConversationByParticipants(targets, conversation);
		}
		else
		{
			this->GetConversationByIdentity((char *)_T2A(::db_get_wsa(hContact, this->m_szModuleName, SKYPE_SETTINGS_SID)), conversation);
		}
		if ( !conversation)
			return 0; 

		ContactRefs contacts;
		for (int i = 0; i < nContacts; i++)
		{
			CContact::Ref contact;

			ptrW csid(::db_get_wsa(hContactsList[i], this->m_szModuleName, SKYPE_SETTINGS_SID));
			this->GetContact((char *)ptrA(::mir_utf8encodeW(csid)), contact);
			contacts.append(contact);
		}

		time_t timestamp = time(NULL);

		if ( !conversation->PostContacts(contacts))
			return 0;

		// todo: bad hack
		CMessage::Refs msgs;
		this->GetMessageListByType(Message::POSTED_CONTACTS, true, msgs, timestamp);

		if (msgs.size() == 0)
			return 0;

		CMessage::Ref lastMsg = msgs[msgs.size() - 1];

		return lastMsg->getOID();
	}

	return 0; 
}

HANDLE __cdecl CSkypeProto::SendFile(MCONTACT hContact, const TCHAR *szDescription, TCHAR **ppszFiles)
{
	if (this->IsOnline() && hContact && ppszFiles)
	{
		this->debugLogW(L"Outcoming file transfer");

		ConversationRef conversation;
		if ( !this->isChatRoom(hContact))
		{
			SEStringList targets;
			targets.append((char *)_T2A(::db_get_wsa(hContact, this->m_szModuleName, SKYPE_SETTINGS_SID)));

			this->GetConversationByParticipants(targets, conversation);
		}
		else
		{
			this->GetConversationByIdentity((char *)_T2A(::db_get_wsa(hContact, this->m_szModuleName, SKYPE_SETTINGS_SID)), conversation);
		}
		if ( !conversation)
			return 0; 

		FileTransferParam ftp;
		ftp.pfts.flags = PFTS_SENDING | PFTS_UNICODE;
		ftp.pfts.hContact = hContact;
		for (ftp.pfts.totalFiles = 0; ppszFiles[ftp.pfts.totalFiles]; ftp.pfts.totalFiles++);
		ftp.pfts.ptszFiles = new wchar_t*[ftp.pfts.totalFiles + 1];

		wchar_t *wd = new wchar_t[wcslen(ppszFiles[0]) + 1];
		wcscpy(wd, ppszFiles[0]);
		PathRemoveFileSpec(wd);
		ftp.pfts.tszWorkingDir = wd;

		SEFilenameList fileList;
		for (int i = 0; ppszFiles[i]; i++)
		{
			ftp.pfts.ptszFiles[i] = ::mir_wstrdup(ppszFiles[i]);
			fileList.append((char *)ptrA(::mir_utf8encodeW(ppszFiles[i])));
		}

		auto error = TRANSFER_OPEN_SUCCESS;
		SEFilename errFile;
		MessageRef msgRef;
		if ( !conversation->PostFiles(fileList, " ", error, errFile, msgRef) || error)
			return 0;		

		SEString data;
		TransferRefs transfers;
		if (msgRef->GetTransfers(transfers))
		{
			for (uint i = 0; i < transfers.size(); i++)
			{
				transfers[i].fetch();
				this->transferList.append(transfers[i]);				

				transfers[i]->GetPropFilesize(data);
				Sid::uint64 size = data.toUInt64();

				ftp.files.insert(std::make_pair(transfers[i]->getOID(), FileParam(size)));
				ftp.pfts.totalBytes += size;
			}
		}

		auto oid = msgRef->getOID();
		this->transferts.insert(std::make_pair(oid, ftp));

		return (HANDLE)oid;
	}

	return 0; 
}

int __cdecl CSkypeProto::SendMsg(MCONTACT hContact, int flags, const char *msg)
{
	this->debugLogW(L"Outcoming message");
	SEStringList targets;
	targets.append((char *)_T2A(::db_get_wsa(hContact, this->m_szModuleName, SKYPE_SETTINGS_SID)));

	CConversation::Ref conversation;
	this->GetConversationByParticipants(targets, conversation);

	if (conversation)
	{
		CMessage::Ref message;
		if (!conversation->PostText(msg, message))
			return 0;

		return message->getOID();
	}

	return 0;
}

int __cdecl CSkypeProto::SendUrl(MCONTACT hContact, int flags, const char *url) { return 0; }

int __cdecl CSkypeProto::SetApparentMode(MCONTACT hContact, int mode) { return 0; }

int CSkypeProto::SetStatus(int new_status)
{
	switch (new_status)
	{
	case ID_STATUS_OCCUPIED:
		new_status = ID_STATUS_DND;
		break;
	case ID_STATUS_FREECHAT:
		new_status = ID_STATUS_ONLINE;
		break;
	case ID_STATUS_ONTHEPHONE:
	case ID_STATUS_OUTTOLUNCH:
	case ID_STATUS_NA:
		new_status = ID_STATUS_AWAY;
		break;
	}

	if (new_status == this->m_iDesiredStatus)
		return 0;

	int old_status = this->m_iStatus;
	this->m_iDesiredStatus = new_status;

	if (new_status == ID_STATUS_OFFLINE)
	{
		this->LogOut();
		this->m_iStatus = this->m_iDesiredStatus = ID_STATUS_OFFLINE;

		this->SendBroadcast(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);

		if ( !::Miranda_Terminated())
		{
			this->SetAllContactStatus(ID_STATUS_OFFLINE);
			this->CloseAllChatSessions();
		}

		return 0;
	}
	else
	{
		if (old_status == ID_STATUS_OFFLINE && !this->IsOnline())
		{
			this->m_iStatus = ID_STATUS_CONNECTING;
			if ( !this->LogIn())
				return 0;
		}
		else
		{
			if ( this->account->IsOnline())
			{
				SetServerStatus(new_status);
				return 0;
			}

			this->SendBroadcast(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
			return 0;
		}
	}

	this->SendBroadcast(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
	return 0;
}

HANDLE __cdecl CSkypeProto::GetAwayMsg(MCONTACT hContact) { return 0; }
int    __cdecl CSkypeProto::RecvAwayMsg(MCONTACT hContact, int mode, PROTORECVEVENT *evt) { return 0; }
int    __cdecl CSkypeProto::SetAwayMsg(int m_iStatus, const TCHAR *msg) { return 0; }

int __cdecl CSkypeProto::UserIsTyping(MCONTACT hContact, int type)
{
	if (hContact && this->IsOnline() && this->m_iStatus != ID_STATUS_INVISIBLE)
	{
		ptrW sid(::db_get_wsa(hContact, this->m_szModuleName, SKYPE_SETTINGS_SID));
		if (sid != NULL && ::wcsicmp(sid, this->login) != 0)
		{
			SEStringList targets;
			targets.append((char *)ptrA(::mir_utf8encodeW(sid)));

			CConversation::Ref conversation;
			this->GetConversationByParticipants(targets, conversation);

			if (conversation)
			{
				switch (type)
				{
				case PROTOTYPE_SELFTYPING_ON:
					conversation->SetMyTextStatusTo(Participant::WRITING);
					return 0;

				case PROTOTYPE_SELFTYPING_OFF:
					conversation->SetMyTextStatusTo(Participant::READING); //todo: mb TEXT_UNKNOWN?
					return 0;
				}
			}
		}
	}

	return 1;
}

int __cdecl CSkypeProto::OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM lParam)
{
	switch (eventType)
	{
	case EV_PROTO_ONLOAD:
		return this->OnProtoModulesLoaded(wParam, lParam);

	case EV_PROTO_ONEXIT:
		return this->OnPreShutdown(wParam, lParam);

	case EV_PROTO_ONOPTIONS:
		return this->OnOptionsInit(wParam,lParam);

	case EV_PROTO_ONCONTACTDELETED:
		return this->OnContactDeleted(wParam, lParam);

	case EV_PROTO_ONMENU:
		this->OnInitStatusMenu();
		break;
	}

	return 1;
}