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
675
676
677
678
679
680
681
682
683
684
685
686
|
/*
Plugin of Miranda IM for communicating with users of the AIM protocol.
Copyright (c) 2008-2012 Boris Krasnovskiy
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"
CAimProto::CAimProto(const char* aProtoName, const TCHAR* aUserName) :
PROTO<CAimProto>(aProtoName, aUserName),
m_chat_rooms(5)
{
debugLogA("Setting protocol/module name to '%s'", m_szModuleName);
//create some events
m_hAvatarEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
m_hChatNavEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
m_hAdminEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
CreateProtoService(PS_CREATEACCMGRUI, &CAimProto::SvcCreateAccMgrUI);
CreateProtoService(PS_GETMYAWAYMSG, &CAimProto::GetMyAwayMsg);
CreateProtoService(PS_GETAVATARINFO, &CAimProto::GetAvatarInfo);
CreateProtoService(PS_GETMYAVATAR, &CAimProto::GetAvatar);
CreateProtoService(PS_SETMYAVATAR, &CAimProto::SetAvatar);
CreateProtoService(PS_GETAVATARCAPS, &CAimProto::GetAvatarCaps);
CreateProtoService(PS_JOINCHAT, &CAimProto::OnJoinChat);
CreateProtoService(PS_LEAVECHAT, &CAimProto::OnLeaveChat);
HookProtoEvent(ME_CLIST_PREBUILDCONTACTMENU, &CAimProto::OnPreBuildContactMenu);
HookProtoEvent(ME_CLIST_GROUPCHANGE, &CAimProto::OnGroupChange);
HookProtoEvent(ME_OPT_INITIALISE, &CAimProto::OnOptionsInit);
offline_contacts();
TCHAR descr[MAX_PATH];
NETLIBUSER nlu = { 0 };
nlu.cbSize = sizeof(nlu);
nlu.flags = NUF_OUTGOING | NUF_HTTPCONNS | NUF_TCHAR;
nlu.szSettingsModule = m_szModuleName;
mir_sntprintf(descr, TranslateT("%s server connection"), m_tszUserName);
nlu.ptszDescriptiveName = descr;
m_hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
char szP2P[128];
mir_snprintf(szP2P, _countof(szP2P), "%sP2P", m_szModuleName);
nlu.flags = NUF_OUTGOING | NUF_INCOMING | NUF_TCHAR;
mir_sntprintf(descr, TranslateT("%s Client-to-client connection"), m_tszUserName);
nlu.szSettingsModule = szP2P;
nlu.minIncomingPorts = 1;
m_hNetlibPeer = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
}
CAimProto::~CAimProto()
{
if (m_hServerConn)
Netlib_CloseHandle(m_hServerConn);
if (m_hAvatarConn && m_hAvatarConn != (HANDLE)1)
Netlib_CloseHandle(m_hAvatarConn);
if (m_hChatNavConn && m_hChatNavConn != (HANDLE)1)
Netlib_CloseHandle(m_hChatNavConn);
if (m_hAdminConn && m_hAdminConn != (HANDLE)1)
Netlib_CloseHandle(m_hAdminConn);
close_chat_conn();
Netlib_CloseHandle(m_hNetlibUser);
Netlib_CloseHandle(m_hNetlibPeer);
CloseHandle(m_hAvatarEvent);
CloseHandle(m_hChatNavEvent);
CloseHandle(m_hAdminEvent);
for (int i = 0; i < 9; ++i)
mir_free(m_modeMsgs[i]);
mir_free(m_pref2_flags);
mir_free(m_pref2_set_flags);
mir_free(COOKIE);
mir_free(MAIL_COOKIE);
mir_free(AVATAR_COOKIE);
mir_free(CHATNAV_COOKIE);
mir_free(ADMIN_COOKIE);
mir_free(m_username);
}
////////////////////////////////////////////////////////////////////////////////////////
// OnModulesLoadedEx - performs hook registration
int CAimProto::OnModulesLoaded(WPARAM, LPARAM)
{
HookProtoEvent(ME_IDLE_CHANGED, &CAimProto::OnIdleChanged);
HookProtoEvent(ME_MSG_WINDOWEVENT, &CAimProto::OnWindowEvent);
HookProtoEvent(ME_USERINFO_INITIALISE, &CAimProto::OnUserInfoInit);
chat_register();
InitContactMenus();
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////
// AddToList - adds a contact to the contact list
MCONTACT CAimProto::AddToList(int flags, PROTOSEARCHRESULT* psr)
{
if (m_state != 1)
return 0;
TCHAR *id = psr->id.t ? psr->id.t : psr->nick.t;
char *sn = psr->flags & PSR_UNICODE ? mir_u2a((wchar_t*)id) : mir_strdup((char*)id);
MCONTACT hContact = contact_from_sn(sn, true, (flags & PALF_TEMPORARY) != 0);
mir_free(sn);
return hContact; //See authrequest for serverside addition
}
////////////////////////////////////////////////////////////////////////////////////////
// PSS_AUTHREQUEST
int __cdecl CAimProto::AuthRequest(MCONTACT hContact, const TCHAR*)
{
//Not a real authrequest- only used b/c we don't know the group until now.
if (m_state != 1)
return 1;
DBVARIANT dbv;
if (!db_get_utf(hContact, MOD_KEY_CL, OTH_KEY_GP, &dbv) && dbv.pszVal[0]) {
add_contact_to_group(hContact, dbv.pszVal);
db_free(&dbv);
}
else add_contact_to_group(hContact, AIM_DEFAULT_GROUP);
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////
// FileAllow - starts a file transfer
HANDLE __cdecl CAimProto::FileAllow(MCONTACT, HANDLE hTransfer, const TCHAR *szPath)
{
file_transfer *ft = (file_transfer*)hTransfer;
if (ft && m_ft_list.find_by_ft(ft)) {
char *path = mir_utf8encodeT(szPath);
if (ft->pfts.totalFiles > 1 && ft->file[0]) {
size_t path_len = mir_strlen(path);
size_t len = mir_strlen(ft->file) + 2;
path = (char*)mir_realloc(path, path_len + len);
mir_snprintf(&path[path_len], len, "%s\\", ft->file);
}
mir_free(ft->file);
ft->file = path;
ForkThread(&CAimProto::accept_file_thread, ft);
return ft;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////
// FileCancel - cancels a file transfer
int __cdecl CAimProto::FileCancel(MCONTACT, HANDLE hTransfer)
{
file_transfer *ft = (file_transfer*)hTransfer;
if (!m_ft_list.find_by_ft(ft))
return 0;
debugLogA("We are cancelling a file transfer.");
aim_chat_deny(m_hServerConn, m_seqno, ft->sn, ft->icbm_cookie);
if (ft->hConn) {
Netlib_Shutdown(ft->hConn);
SetEvent(ft->hResumeEvent);
}
else m_ft_list.remove_by_ft(ft);
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////
// FileDeny - denies a file transfer
int __cdecl CAimProto::FileDeny(MCONTACT, HANDLE hTransfer, const TCHAR* /*szReason*/)
{
file_transfer *ft = (file_transfer*)hTransfer;
if (!m_ft_list.find_by_ft(ft))
return 0;
debugLogA("We are denying a file transfer.");
aim_chat_deny(m_hServerConn, m_seqno, ft->sn, ft->icbm_cookie);
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////
// FileResume - processes file renaming etc
int __cdecl CAimProto::FileResume(HANDLE hTransfer, int* action, const TCHAR** szFilename)
{
file_transfer *ft = (file_transfer*)hTransfer;
if (!m_ft_list.find_by_ft(ft))
return 0;
switch (*action) {
case FILERESUME_RESUME:
{
struct _stati64 statbuf;
_tstati64(ft->pfts.tszCurrentFile, &statbuf);
ft->pfts.currentFileProgress = statbuf.st_size;
}
break;
case FILERESUME_RENAME:
mir_free(ft->pfts.tszCurrentFile);
ft->pfts.tszCurrentFile = mir_tstrdup(*szFilename);
break;
case FILERESUME_OVERWRITE:
ft->pfts.currentFileProgress = 0;
break;
case FILERESUME_SKIP:
mir_free(ft->pfts.tszCurrentFile);
ft->pfts.tszCurrentFile = NULL;
break;
default:
aim_file_ad(m_hServerConn, m_seqno, ft->sn, ft->icbm_cookie, true, ft->max_ver);
break;
}
SetEvent(ft->hResumeEvent);
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////
// GetCaps - return protocol capabilities bits
DWORD_PTR __cdecl CAimProto::GetCaps(int type, MCONTACT)
{
switch (type) {
case PFLAGNUM_1:
return PF1_IM | PF1_MODEMSG | PF1_BASICSEARCH | PF1_SEARCHBYEMAIL | PF1_FILE;
case PFLAGNUM_2:
#ifdef ALLOW_BUSY
return PF2_ONLINE | PF2_INVISIBLE | PF2_SHORTAWAY | PF2_ONTHEPHONE | PF2_LIGHTDND;
#else
return PF2_ONLINE | PF2_INVISIBLE | PF2_SHORTAWAY | PF2_ONTHEPHONE;
#endif
case PFLAGNUM_3:
#ifdef ALLOW_BUSY
return PF2_ONLINE | PF2_SHORTAWAY | PF2_INVISIBLE | PF2_LIGHTDND;
#else
return PF2_ONLINE | PF2_SHORTAWAY | PF2_INVISIBLE;
#endif
case PFLAGNUM_4:
return PF4_SUPPORTTYPING | PF4_FORCEAUTH | PF4_NOCUSTOMAUTH | PF4_FORCEADDED |
PF4_SUPPORTIDLE | PF4_AVATARS | PF4_IMSENDOFFLINE;
case PFLAGNUM_5:
return PF2_ONTHEPHONE;
case PFLAG_MAXLENOFMESSAGE:
return MAX_MESSAGE_LENGTH;
case PFLAG_UNIQUEIDTEXT:
return (DWORD_PTR) "Screen Name";
case PFLAG_UNIQUEIDSETTING:
return (DWORD_PTR)AIM_KEY_SN;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////
// SearchBasic - searches the contact by JID
void __cdecl CAimProto::basic_search_ack_success(void *p)
{
char *sn = normalize_name((char*)p);
if (sn) { // normalize it
if (mir_strlen(sn) > 32)
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
else {
PROTOSEARCHRESULT psr = { 0 };
psr.cbSize = sizeof(psr);
psr.id.t = (TCHAR*)sn;
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)1, (LPARAM)& psr);
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
}
}
mir_free(sn);
mir_free(p);
}
HANDLE __cdecl CAimProto::SearchBasic(const TCHAR *szId)
{
if (m_state != 1)
return 0;
//duplicating the parameter so that it isn't deleted before it's needed- e.g. this function ends before it's used
ForkThread(&CAimProto::basic_search_ack_success, mir_t2a(szId));
return (HANDLE)1;
}
////////////////////////////////////////////////////////////////////////////////////////
// SearchByEmail - searches the contact by its e-mail
HANDLE __cdecl CAimProto::SearchByEmail(const TCHAR *email)
{
// Maximum email size should really be 320, but the char string is limited to 255.
if (m_state != 1 || email == NULL || mir_tstrlen(email) >= 254)
return NULL;
char *szEmail = mir_t2a(email);
aim_search_by_email(m_hServerConn, m_seqno, szEmail);
mir_free(szEmail);
return (HANDLE)1;
}
////////////////////////////////////////////////////////////////////////////////////////
// RecvMsg
int __cdecl CAimProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT *pre)
{
char *omsg = pre->szMessage;
char *bbuf = NULL;
if (getByte(AIM_KEY_FI, 1)) {
debugLogA("Converting from html to bbcodes then stripping leftover html.");
pre->szMessage = bbuf = html_to_bbcodes(pre->szMessage);
}
debugLogA("Stripping html.");
html_decode(pre->szMessage);
INT_PTR res = Proto_RecvMessage(hContact, pre);
mir_free(bbuf);
pre->szMessage = omsg;
return (int)res;
}
////////////////////////////////////////////////////////////////////////////////////////
// SendFile - sends a file
HANDLE __cdecl CAimProto::SendFile(MCONTACT hContact, const TCHAR* szDescription, TCHAR** ppszFiles)
{
if (m_state != 1)
return 0;
if (hContact && szDescription && ppszFiles) {
DBVARIANT dbv;
if (!getString(hContact, AIM_KEY_SN, &dbv)) {
file_transfer *ft = new file_transfer(hContact, dbv.pszVal, NULL);
bool isDir = false;
int count = 0;
while (ppszFiles[count] != NULL) {
struct _stati64 statbuf;
if (_tstati64(ppszFiles[count++], &statbuf) == 0) {
if (statbuf.st_mode & _S_IFDIR) {
if (ft->pfts.totalFiles == 0) isDir = true;
}
else {
ft->pfts.totalBytes += statbuf.st_size;
++ft->pfts.totalFiles;
}
}
}
if (ft->pfts.totalFiles == 0) {
delete ft;
return NULL;
}
ft->pfts.flags |= PFTS_SENDING;
ft->pfts.ptszFiles = ppszFiles;
ft->file = ft->pfts.totalFiles == 1 || isDir ? mir_utf8encodeT(ppszFiles[0]) : (char*)mir_calloc(1);
ft->sending = true;
ft->message = szDescription[0] ? mir_utf8encodeT(szDescription) : NULL;
ft->me_force_proxy = getByte(AIM_KEY_FP, 0) != 0;
ft->requester = true;
m_ft_list.insert(ft);
if (ft->me_force_proxy) {
debugLogA("We are forcing a proxy file transfer.");
ForkThread(&CAimProto::accept_file_thread, ft);
}
else {
ft->listen(this);
aim_send_file(m_hServerConn, m_seqno, m_detected_ip, ft->local_port, false, ft);
}
db_free(&dbv);
return ft;
}
}
return NULL;
}
////////////////////////////////////////////////////////////////////////////////////////
// SendMessage - sends a message
void __cdecl CAimProto::msg_ack_success(void* param)
{
msg_ack_param *msg_ack = (msg_ack_param*)param;
Sleep(150);
ProtoBroadcastAck(msg_ack->hContact, ACKTYPE_MESSAGE,
msg_ack->success ? ACKRESULT_SUCCESS : ACKRESULT_FAILED,
(HANDLE)msg_ack->id, (LPARAM)msg_ack->msg);
mir_free(msg_ack);
}
int __cdecl CAimProto::SendMsg(MCONTACT hContact, int, const char* pszSrc)
{
if (pszSrc == NULL)
return 0;
if (m_state != 1) {
msg_ack_param *msg_ack = (msg_ack_param*)mir_calloc(sizeof(msg_ack_param));
msg_ack->hContact = hContact;
msg_ack->msg = "Message cannot be sent, when protocol offline";
ForkThread(&CAimProto::msg_ack_success, msg_ack);
}
char *sn = getStringA(hContact, AIM_KEY_SN);
if (sn == NULL) {
msg_ack_param *msg_ack = (msg_ack_param*)mir_calloc(sizeof(msg_ack_param));
msg_ack->hContact = hContact;
msg_ack->msg = "Screen Name for the contact not available";
ForkThread(&CAimProto::msg_ack_success, msg_ack);
}
char *smsg = html_encode(pszSrc), *msg;
if (getByte(AIM_KEY_FO, 1)) {
msg = bbcodes_to_html(smsg);
mir_free(smsg);
}
else msg = smsg;
bool blast = getBool(hContact, AIM_KEY_BLS, false);
int res = aim_send_message(m_hServerConn, m_seqno, sn, msg, false, blast);
mir_free(msg);
mir_free(sn);
if (!res || blast || 0 == getByte(AIM_KEY_DC, 1)) {
msg_ack_param *msg_ack = (msg_ack_param*)mir_alloc(sizeof(msg_ack_param));
msg_ack->hContact = hContact;
msg_ack->msg = NULL;
msg_ack->id = res;
msg_ack->success = res != 0;
ForkThread(&CAimProto::msg_ack_success, msg_ack);
}
return res;
}
////////////////////////////////////////////////////////////////////////////////////////
// SetStatus - sets the protocol m_iStatus
int __cdecl CAimProto::SetStatus(int iNewStatus)
{
switch (iNewStatus) {
case ID_STATUS_FREECHAT:
iNewStatus = ID_STATUS_ONLINE;
break;
case ID_STATUS_DND:
case ID_STATUS_OCCUPIED:
case ID_STATUS_ONTHEPHONE:
#ifdef ALLOW_BUSY
iNewStatus = ID_STATUS_OCCUPIED;
break;
#endif
case ID_STATUS_OUTTOLUNCH:
case ID_STATUS_NA:
iNewStatus = ID_STATUS_AWAY;
break;
}
if (iNewStatus == m_iStatus)
return 0;
if (iNewStatus == ID_STATUS_OFFLINE) {
broadcast_status(ID_STATUS_OFFLINE);
return 0;
}
m_iDesiredStatus = iNewStatus;
if (m_iStatus == ID_STATUS_OFFLINE) {
broadcast_status(ID_STATUS_CONNECTING);
ForkThread(&CAimProto::start_connection, (void*)iNewStatus);
}
else if (m_iStatus > ID_STATUS_OFFLINE) {
switch (iNewStatus) {
case ID_STATUS_ONLINE:
aim_set_status(m_hServerConn, m_seqno, AIM_STATUS_ONLINE);
broadcast_status(ID_STATUS_ONLINE);
break;
case ID_STATUS_INVISIBLE:
aim_set_status(m_hServerConn, m_seqno, AIM_STATUS_INVISIBLE);
broadcast_status(ID_STATUS_INVISIBLE);
break;
case ID_STATUS_OCCUPIED:
aim_set_status(m_hServerConn, m_seqno, AIM_STATUS_BUSY | AIM_STATUS_AWAY);
broadcast_status(ID_STATUS_OCCUPIED);
break;
case ID_STATUS_AWAY:
aim_set_status(m_hServerConn, m_seqno, AIM_STATUS_AWAY);
broadcast_status(ID_STATUS_AWAY);
break;
}
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////
// GetAwayMsg - returns a contact's away message
void __cdecl CAimProto::get_online_msg_thread(void* arg)
{
Sleep(150);
MCONTACT hContact = (UINT_PTR)arg;
DBVARIANT dbv;
if (!db_get_ts(hContact, MOD_KEY_CL, OTH_KEY_SM, &dbv)) {
ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)1, (LPARAM)dbv.ptszVal);
db_free(&dbv);
}
else ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)1, 0);
}
HANDLE __cdecl CAimProto::GetAwayMsg(MCONTACT hContact)
{
if (m_state != 1)
return 0;
int status = getWord(hContact, AIM_KEY_ST, ID_STATUS_OFFLINE);
switch (status) {
case ID_STATUS_AWAY:
case ID_STATUS_ONLINE:
ForkThread(&CAimProto::get_online_msg_thread, (void*)hContact);
break;
default:
return 0;
}
return (HANDLE)1;
}
////////////////////////////////////////////////////////////////////////////////////////
// PSR_AWAYMSG
int __cdecl CAimProto::RecvAwayMsg(MCONTACT hContact, int, PROTORECVEVENT* pre)
{
ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)1, (LPARAM)pre->szMessage);
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////
// SetAwayMsg - sets the away m_iStatus message
int __cdecl CAimProto::SetAwayMsg(int status, const TCHAR* msg)
{
char **msgptr = get_status_msg_loc(status);
if (msgptr == NULL) return 1;
char *nmsg = mir_utf8encodeT(msg);
mir_free(*msgptr); *msgptr = nmsg;
switch (status) {
case ID_STATUS_FREECHAT:
status = ID_STATUS_ONLINE;
break;
case ID_STATUS_DND:
case ID_STATUS_OCCUPIED:
case ID_STATUS_ONTHEPHONE:
#ifdef ALLOW_BUSY
status = ID_STATUS_OCCUPIED;
break;
#endif
case ID_STATUS_OUTTOLUNCH:
case ID_STATUS_NA:
status = ID_STATUS_AWAY;
break;
}
if (m_state == 1 && status == m_iStatus) {
if (!mir_strcmp(m_last_status_msg, nmsg))
return 0;
replaceStr(m_last_status_msg, nmsg);
aim_set_statusmsg(m_hServerConn, m_seqno, nmsg);
aim_set_away(m_hServerConn, m_seqno, nmsg,
status == ID_STATUS_AWAY || status == ID_STATUS_OCCUPIED);
}
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
// UserIsTyping - sends a UTN notification
int __cdecl CAimProto::UserIsTyping(MCONTACT hContact, int type)
{
if (m_state != 1)
return 0;
if (getWord(hContact, AIM_KEY_ST, ID_STATUS_OFFLINE) == ID_STATUS_ONTHEPHONE)
return 0;
DBVARIANT dbv;
if (!getBool(hContact, AIM_KEY_BLS, false) && !getString(hContact, AIM_KEY_SN, &dbv)) {
if (type == PROTOTYPE_SELFTYPING_ON)
aim_typing_notification(m_hServerConn, m_seqno, dbv.pszVal, 0x0002);
else if (type == PROTOTYPE_SELFTYPING_OFF)
aim_typing_notification(m_hServerConn, m_seqno, dbv.pszVal, 0x0000);
db_free(&dbv);
}
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
// OnEvent - maintain protocol events
int __cdecl CAimProto::OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM lParam)
{
switch (eventType) {
case EV_PROTO_ONLOAD:
return OnModulesLoaded(0, 0);
case EV_PROTO_ONMENU:
InitMainMenus();
break;
case EV_PROTO_ONOPTIONS:
return OnOptionsInit(wParam, lParam);
case EV_PROTO_ONERASE:
char szDbsettings[64];
mir_snprintf(szDbsettings, _countof(szDbsettings), "%sP2P", m_szModuleName);
CallService(MS_DB_MODULE_DELETE, 0, (LPARAM)szDbsettings);
break;
case EV_PROTO_ONCONTACTDELETED:
return OnContactDeleted(wParam, lParam);
case EV_PROTO_DBSETTINGSCHANGED:
return OnDbSettingChanged(wParam, lParam);
}
return 1;
}
|