-
Notifications
You must be signed in to change notification settings - Fork 2
/
YahooMsgView.cpp
2595 lines (2257 loc) · 61.6 KB
/
YahooMsgView.cpp
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
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// YahooMsgView.cpp: implementation of the CYahooMsgView class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <mshtmcid.h>
#include <no5tl\socket.h>
#include <no5tl\mystring.h>
#include "YahooMsgView.h"
#include "no5options.h"
#include "iuserlistview.h"
#include "imainframe.h"
#include "commandparser.h"
#include "no5app.h"
#include "colorfile.h"
#include "privatebox.h"
#include "resource.h"
#include "recentrooms.h"
#include "ibuddylistview.h"
#include "simpleinputdlg.h"
#include "camviewdlg.h"
#include "camupdlg.h"
#include "voicedialog.h"
#ifdef _DEBUG
#include <no5tl\clipboard.h>
#endif
#include <no5tl\winfile.h>
// fuck for some reason even using this some objects need to be declared with NO5TL
// like NO5TL::CHtmlElement
using namespace NO5TL;
using namespace NO5TL::Colors;
using namespace NO5YAHOO;
CString GetAwayString(UINT i);
// CYahooMsgViewBase
CYahooMsgViewBase::CYahooMsgViewBase(CTextStream &ts):CChatViewBase(ts)
{
m_pChat = NULL;
NO5YAHOO::YahooMessengerCreate(&m_pChat,this);
HRESULT hr = CreateChatObj(this,&m_spChat);
ATLASSERT(SUCCEEDED(hr));
unsigned short ymsg_version[] = {8,1,0,413};
CMessengerVersion v(ymsg_version);
m_pChat->SetBuildNumber(v);
}
CYahooMsgViewBase::~CYahooMsgViewBase()
{
ATLTRACE("~CYahooMsgViewBase\n");
NO5YAHOO::YahooMessengerDestroy(&m_pChat);
}
// CYahooMsgViewBase::ISocketEvents
void CYahooMsgViewBase::OnSockConnect(int iError)
{
InitTS init(m_ts);
m_ts << m_pvo->TxtNo5();
m_ts << "connected";
m_pChat->Auth(YAHOO_STATUS_AVAILABLE);
}
void CYahooMsgViewBase::OnSockConnecting(void)
{
InitTS init(m_ts);
m_ts << m_pvo->TxtNo5();
m_ts << "connecting...";
}
void CYahooMsgViewBase::OnSockClose(int iError)
{
InitTS init(m_ts);
m_ts << m_pvo->TxtNo5();
m_ts << "connection closed";
}
void CYahooMsgViewBase::OnSockError(int error)
{
InitTS init(m_ts);
m_ts << m_pvo->TxtNo5();
m_ts << "socket error: " << m_pvo->TxtError() << NO5TL::CSocket::GetErrorDesc(error);
}
void CYahooMsgViewBase::OnSockConnectTimeout(void)
{
InitTS init(m_ts);
m_ts << m_pvo->TxtNo5();
m_ts << "timed out";
}
void CYahooMsgViewBase::OnSockResolvingAddress(void)
{
InitTS init(m_ts);
m_ts << m_pvo->TxtNo5();
m_ts << "resolving server address";
}
void CYahooMsgViewBase::OnSockAddressResolved(int error)
{
if(!error){
InitTS init(m_ts);
m_ts << m_pvo->TxtNo5();
m_ts << "server address resolved";
}
}
CUser * CYahooMsgViewBase::AddUser(CYahooMsgUser &user)
{
CUser *pUser;
pUser = m_users.GetUser(user.m_name);
if(!pUser){
pUser = AddUser(user.m_name);
}
CopyUserInfo(pUser,user);
pUser->m_chat = true;
// well this isnt the time the user entered coz the user was already in room
pUser->m_tEnter = GetTickCount();
return pUser;
}
CUser * CYahooMsgViewBase::AddUser(LPCTSTR name)
{
#ifdef _DEBUG
CUser *pFound = m_users.GetUser(name);
if(pFound){
ATLTRACE("CYahooMsgViewBase::AddUser adding %s but user already there!\n",name);
}
#endif
CUser *pUser = m_users.AddUser(name);
pUser->m_ignored = m_pIgnoreList->find(name);
pUser->m_me = IsMe(name);
pUser->m_buddy = IsBuddy(name);
return pUser;
}
void CYahooMsgViewBase::AddUsers(CYahooMsgUsers &users)
{
int i;
const int count = users.GetSize();
for(i=0;i<count;i++){
AddUser(users[i]);
}
}
void CYahooMsgViewBase::CopyUserInfo(CUser *pUser,CYahooMsgUser &from)
{
ATLASSERT(pUser);
pUser->m_cam = from.Cam();
pUser->m_nick = from.m_nick;
pUser->m_location = from.m_location;
pUser->m_age = from.m_age < 0 ? 0 : from.m_age;
if(from.Male())
pUser->m_gender = CUser::USER_GENDER_MALE;
else if(from.Female())
pUser->m_gender = CUser::USER_GENDER_FEMALE;
else
pUser->m_gender = CUser::USER_GENDER_UNKNOWN;
}
void CYahooMsgViewBase::OnTextInput(LPCTSTR text)
{
CInputStream ts;
CCommandParser cp;
NO5YAHOO::CTextAtom atom;
CString smiley;
CInputParams &p = m_input_params;
ISmileyMap *psm = g_app.GetSmileyMap();
m_pFrame->InputFrame()->GetParams(p);
if(p.colorset.CompareNoCase("random") == 0)
LoadColorSet();
if(NULL != text && lstrlen(text)){
if(ParseCmd(text) && DispatchCmd()){
// it was a command
}
else if(text[0] == ':' && m_pChat->IsConnected() && !(psm->IsSmiley(text,smiley))){
m_pChat->ChatMessage(&(text[1]),false,YMSG_TEXT_EMOTE);
}
else if(m_pChat->IsConnected()){
// add info tag
if(!m_it.IsEmpty()){
//ts << InlineMode << (LPCSTR)m_it.GetCode();
// in input we can avoid all the parsing
ts.GetInfoTag() = m_it;
}
ts << Bold(p.bold) << Italic(p.italic) << Under(p.underline);
if(! (p.fade || p.blend) ){
CColor color = p.color;
ts << color;
}
if(!p.font.IsEmpty()){
if(!p.font_size)
p.font_size = 10;
ts << Font(p.font,p.font_size);
}
if(p.fade){
atom.AtomFade(m_colors);
ts.AddAtom(atom);
}
else if(p.blend){
atom.AtomAlt(m_colors);
ts.AddAtom(atom);
}
ts << InlineMode << text;
if(p.fade){
atom.AtomFadeOff();
ts.AddAtom(atom);
}
else if(p.blend){
atom.AtomAltOff();
ts.AddAtom(atom);
}
if(!p.font.IsEmpty())
ts << Font(true /* close */);
m_pChat->ChatMessage(ts.GetYahooText(),false,YMSG_TEXT_NORMAL);
}
}
}
BOOL CYahooMsgViewBase::OnCmdJoin()
{
if(m_pChat->IsConnected()){
CString room;
if(GetArgs1(room)){
CString name,id;
ParseRoomString(room,name,id);
m_pChat->ChatJoin(name,id);
}
}
return TRUE;
}
BOOL CYahooMsgViewBase::OnCmdGoto()
{
if(m_pChat->IsConnected()){
CString name;
if(GetArgs1(name))
m_pChat->GotoUser(name);
}
return TRUE;
}
BOOL CYahooMsgViewBase::OnCmdPm()
{
if(m_pChat->IsConnected()){
CString name,msg;
if(GetArgs2(name,msg))
m_pChat->SendMsg(m_pChat->GetName(),name,msg);
}
return TRUE;
}
BOOL CYahooMsgViewBase::OnCmdAway()
{
if(m_pChat->IsConnected()){
CString msg;
if(GetArgs1(msg))
m_pChat->SetStatus(YAHOO_STATUS_CUSTOM,msg);
else
m_pChat->SetStatus(YAHOO_STATUS_BRB);
}
return TRUE;
}
BOOL CYahooMsgViewBase::OnCmdBack()
{
if(m_pChat->IsConnected())
m_pChat->SetStatus(YAHOO_STATUS_AVAILABLE);
return TRUE;
}
BOOL CYahooMsgViewBase::OnCmdLeave()
{
if(m_pChat->IsConnected()){
m_pChat->ChatExit();
}
return TRUE;
}
BOOL CYahooMsgViewBase::OnCmdThink()
{
BOOL res = FALSE;
if(m_pChat->IsConnected()){
CString msg;
if(GetArgs1(msg)){
CString s = ". o O ( ";
s += msg;
s += " )";
m_pChat->ChatMessage(s,false,YMSG_TEXT_BUBBLE);
}
}
return TRUE;
}
BOOL CYahooMsgViewBase::OnCmdEmote()
{
BOOL res = FALSE;
if(m_pChat->IsConnected()){
CString msg;
if(GetArgs1(msg))
m_pChat->ChatMessage(msg,false,YMSG_TEXT_EMOTE);
}
return TRUE;
}
BOOL CYahooMsgViewBase::OnCmdBud()
{
BOOL res = FALSE;
if( m_pChat->IsConnected()){
CString name,group;
if(GetArgs2(name,group))
m_pChat->AddBuddy(m_pChat->GetName(),name,group);
else if(GetArgs1(name))
m_pChat->AddBuddy(m_pChat->GetName(),name,"no5");
}
return TRUE;
}
BOOL CYahooMsgViewBase::OnCmdInvite()
{
BOOL res = FALSE;
if(m_pChat->IsConnected()){
CString name;
if(GetArgs1(name))
m_pChat->ChatInvite(name,m_pChat->GetRoom(),m_pChat->GetRoomSpace());
}
return TRUE;
}
BOOL CYahooMsgViewBase::OnCmdViewcam()
{
if(m_pChat->IsConnected()){
CString name;
if(GetArgs1(name))
OnUserList_Cam(name);
}
return TRUE;
}
BOOL CYahooMsgViewBase::OnCmdUnknown()
{
InitTS init(m_ts);
BOOL res = TRUE;
if(!m_cmd.CompareNoCase("room"))
m_ts << m_pChat->GetRoom();
else if(!m_cmd.CompareNoCase("rmspace"))
m_ts << m_pChat->GetRoomSpace();
else if(!m_cmd.CompareNoCase("rmcat"))
m_ts << m_pChat->GetRoomCategory();
//else if(!m_cmd.CompareNoCase("vc"))
// m_ts << (m_pChat->IsVoiceEnabled() ? "true" : "false") ;
else if(!m_cmd.CompareNoCase("camserver"))
m_ts << m_pChat->GetCamServer();
else if(!m_cmd.CompareNoCase("accept")){
if(m_args.GetSize())
m_pChat->AcceptReq(m_pChat->GetName(),m_args[0],true);
}
else if(!m_cmd.CompareNoCase("noaccept")){
if(m_args.GetSize())
m_pChat->AcceptReq(m_pChat->GetName(),m_args[0],false);
}
else if(!m_cmd.CompareNoCase("reject")){
if(m_args.GetSize())
m_pChat->RejectBuddy(m_pChat->GetName(),m_args[0],"blah");
}
else if(!m_cmd.CompareNoCase("add")){
if(m_args.GetSize())
m_pChat->AddBuddy(m_pChat->GetName(),m_args[0],"no5"," can i add you? ");
}
else if(!m_cmd.CompareNoCase("deny")){
if(m_args.GetSize())
m_pChat->RejectBuddy(m_pChat->GetName(),m_args[0],"");
}
else if(!m_cmd.CompareNoCase("rejoin"))
m_pChat->ChatJoin(m_pChat->GetRoom(),m_pChat->GetRoomSpace(),true);
else if(!m_cmd.CompareNoCase("localserver")){
CString server;
int port;
m_pChat->GetLocalAddress(server,port);
server += ':';
server.Append(port);
m_ts << (LPCTSTR)server;
}
else if(!m_cmd.CompareNoCase("server")){
CString server;
int port;
m_pChat->GetRemoteAddress(server,port);
server += ':';
server.Append(port);
m_ts << (LPCTSTR)server;
}
else if(!m_cmd.CompareNoCase("cookies")){
CString s;
LPCTSTR p;
p = m_pChat->GetCookie('Y');
if(p)
m_ts << p << "\r\n";
p = m_pChat->GetCookie('T');
if(p)
m_ts << p << "\r\n";
p = m_pChat->GetCookie('C');
if(p)
m_ts << p << "\r\n";
p = m_pChat->GetCookie(61);
if(p)
m_ts << p << "\r\n";
p = m_pChat->GetCookie(130);
if(p)
m_ts << p << "\r\n";
p = m_pChat->GetCookie(149);
if(p)
m_ts << p << "\r\n";
p = m_pChat->GetCookie(150);
if(p)
m_ts << p << "\r\n";
p = m_pChat->GetCookie(151);
if(p)
m_ts << p << "\r\n";
}
else
res = FALSE;
return res;
}
void CYahooMsgViewBase::ChangeRoom(LPCTSTR room)
{
if(m_pChat->IsConnected()){
CString name,id;
ParseRoomString(room,name,id);
m_pChat->ChatJoin(name,id);
}
}
// message handlers
LRESULT CYahooMsgViewBase::OnCreate(UINT,WPARAM wParam,LPARAM lParam,BOOL &bHandled)
{
CString name;
name = m_pgo->GetLastAccountName();
ATLASSERT(!m_pao);
m_pao = IAccountOptions::CreateMe();
BOOL res = m_pao->SetFile(g_app.GetOptionsFile(),name);
ATLASSERT(res);
res = LoadInputParams();
ATLASSERT(res);
if(m_bActive){
// disable room history buttons
m_pFrame->GetChatToolbar().EnableButton(ID_ROOM_PREVIOUS,FALSE);
m_pFrame->GetChatToolbar().EnableButton(ID_ROOM_NEXT,FALSE);
}
m_it.Add("ID","NO5");
return 0;
}
LRESULT CYahooMsgViewBase::OnClose(UINT,WPARAM wParam,LPARAM lParam,BOOL &bHandled)
{
CString name = m_pChat->GetName();
if(m_pChat->IsInRoom())
m_pChat->ChatLogout();
m_pChat->Term(true);
if(m_bActive){
m_pFrame->InputFrame()->GetParams(m_input_params);
m_pFrame->UserListView()->SetSink(NULL);
m_pFrame->UserListView()->RemoveAll();
m_pFrame->ActiveView(NULL);
m_pFrame->InputFrame()->SetSink(NULL);
BOOL res = SaveInputParams();
ATLASSERT(res);
}
// tell all pm boxes to destroy themselves
m_pms.DestroyBoxes();
m_pms.RemoveAll();
// remove our id from the buddy list view
m_pFrame->BuddyListView()->RemoveAcc(name);
return 0;
}
LRESULT CYahooMsgViewBase::OnChatConnect(WORD,WORD,HWND,BOOL &bHandled)
{
if(m_pChat->IsConnected()){
if(m_pChat->IsInRoom())
m_pChat->ChatLogout();
m_pChat->Term(false);
}
else{
BOOL res = m_pChat->Init(m_pgo->GetServerYmsg(),m_pgo->GetPortYmsg(),
m_pao->GetName(),m_pao->GetPassword());
ATLASSERT(res);
}
return 0;
}
LRESULT CYahooMsgViewBase::_OnChatLeave(WORD,WORD,HWND,BOOL &bHandled)
{
if(m_pChat->IsConnected())
m_pChat->ChatLogout();
return 0;
}
LRESULT CYahooMsgViewBase::OnRoomPrevious(WORD,WORD,HWND,BOOL &bHandled)
{
if(m_RoomHistory.HasPrevious() && m_pChat->IsConnected()){
m_RoomHistory.Previous();
m_RoomHistory.m_bAdd = false;
LPCTSTR room = m_RoomHistory.GetRoom();
CString name,id;
ParseRoomString(room,name,id);
m_pChat->ChatJoin(name,id);
}
return 0;
}
LRESULT CYahooMsgViewBase::OnRoomNext(WORD,WORD,HWND,BOOL &bHandled)
{
if(m_RoomHistory.HasNext() && m_pChat->IsConnected()){
m_RoomHistory.Next();
m_RoomHistory.m_bAdd = false;
LPCTSTR room = m_RoomHistory.GetRoom();
CString name,id;
ParseRoomString(room,name,id);
m_pChat->ChatJoin(name,id);
}
return 0;
}
LRESULT CYahooMsgViewBase::OnChatCam(WORD,WORD,HWND,BOOL &bHandled)
{
if(m_pChat->IsConnected()){
m_sCamTarget = "!@#$";
m_pChat->Webcam(m_pChat->GetName());
}
return 0;
}
LRESULT CYahooMsgViewBase::OnChatVoice(WORD,WORD,HWND,BOOL &bHandled)
{
CVoiceDialog *p = new CVoiceDialog();
p->m_name = m_pChat->GetName();
p->m_server = "v12.vc.scd.yahoo.com";
p->m_room = m_pChat->GetRoom();
p->m_rmid = m_pChat->GetRoomSpace();
p->m_cookie = m_pChat->GetCookie(130);
p->Create(g_app.GetMainFrame()->GetHandle());
return 0;
}
#ifdef _DEBUG
LRESULT CYahooMsgViewBase::OnDebugAuthenticate(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled)
{
m_pChat->Auth(YAHOO_STATUS_AVAILABLE);
return 0;
}
LRESULT CYahooMsgViewBase::OnDebugAuthResp(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled)
{
m_pChat->AuthResponse(YAHOO_STATUS_AVAILABLE,true);
return 0;
}
LRESULT CYahooMsgViewBase::OnDebugChatOnline(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled)
{
m_pChat->ChatOnline();
return 0;
}
LRESULT CYahooMsgViewBase::OnDebugJoinRoom(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled)
{
m_pChat->ChatJoin("soccer:1","1600326632");
return 0;
}
LRESULT CYahooMsgViewBase::OnDebugLogoff(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled)
{
m_pChat->Logoff();
return 0;
}
LRESULT CYahooMsgViewBase::OnDebugChatLogoff(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled)
{
m_pChat->ChatLogout();
return 0;
}
LRESULT CYahooMsgViewBase::OnDebugChatLeave(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled)
{
m_pChat->ChatLeave();
return 0;
}
#endif // _DEBUG
void CYahooMsgViewBase::OnUserLogon(u_long status,CSimpleArray<CBuddyInfo> &buddies,bool bMe)
{
const int count = buddies.GetSize();
if(!bMe){
for(int i=0;i<count;i++){
m_buddies.SetBuddyStatus(buddies[i].m_name,buddies[i].m_status);
if(m_bActive){
InitTS is(m_ts);
m_pFrame->BuddyListView()->OnUserAway(buddies[i].m_name);
if(buddies[i].m_status != YAHOO_STATUS_OFFLINE){
m_ts << m_pvo->NameBuddy() << (LPCTSTR)buddies[i].m_name << \
" is online - " << (LPCTSTR) GetAwayString(buddies[i].m_status);
}
}
}
}
if(bMe)
m_pChat->ChatOnline();
}
void CYahooMsgViewBase::OnUserLogoff(u_long status,CSimpleArray<CBuddyInfo> &buddies)
{
const int count = buddies.GetSize();
for(int i=0;i<count;i++){
m_buddies.SetBuddyStatus(buddies[i].m_name,YAHOO_STATUS_OFFLINE);
if(m_bActive){
InitTS is(m_ts);
m_pFrame->BuddyListView()->OnUserAway(buddies[i].m_name);
m_ts << m_pvo->NameBuddy() << (LPCTSTR)buddies[i].m_name << " is offline";
}
}
}
void CYahooMsgViewBase::OnAuthenticate(u_long status,LPCSTR challenge,
bool ver11)
{
InitTS init(m_ts);
m_ts << m_pvo->TxtNo5();
m_ts << "authenticating...";
m_pChat->AuthResponse(YAHOO_STATUS_OFFLINE,true);
}
void CYahooMsgViewBase::OnAuthRespError(void)
{
InitTS init(m_ts);
m_ts << m_pvo->TxtNo5();
m_ts << "authentication has failed";
}
void CYahooMsgViewBase::OnChatOnline(void)
{
InitTS init(m_ts);
m_ts << m_pvo->TxtNo5();
m_ts << "chat online" << "\r\n";
m_ts << "sending request to join room: ";
CString s = m_pao->GetLastRoom();
m_ts << LPCTSTR(s) << "\r\n";
CString name,id;
ParseRoomString(s,name,id);
m_pChat->SetStatus(YAHOO_STATUS_AVAILABLE);
m_pChat->ChatJoin(name,id);
}
void CYahooMsgViewBase::OnChatJoin(LPCSTR room,LPCSTR topic)
{
_OnChatJoin(room,m_pChat->GetRoomSpace(),topic);
}
void CYahooMsgViewBase::OnUserList(CYahooMsgUsers &users,bool bMore)
{
// add new users to our internal list. this will also mark them as in chat
AddUsers(users);
if(!bMore && m_bActive){
FillUserListView();
FillQuickIgnoreView();
}
ATLTRACE("OnUserList - more = %d\n",(bMore ? 1: 0));
}
void CYahooMsgViewBase::OnText(LPCSTR user,LPCSTR msg,bool utf8)
{
CUser *pUser = _OnChatText(user,msg,utf8);
if(!pUser->IsIgnored()){
// mimic
if(( pUser->m_mimic || m_bMimicAll ) && !pUser->m_me){
m_pChat->ChatMessage(msg,utf8,YMSG_TEXT_NORMAL);
}
}
if(g_app.GetIgnoreOptions().m_auto && g_app.GetIgnoreOptions().m_ybots){
if(! ( pUser->IsIgnored() || pUser->m_me || pUser->m_buddy ) ){
u_long version = m_pChat->GetPacketIn().m_header.GetVersion();
if(version == 0x6572726F){
DoAutoIgnoreUser(pUser->m_name,true,IDS_IG_YBOT);
}
}
}
// alice bot
if(m_spBot && !pUser->m_me){
CComBSTR bname = pUser->m_name;
HRESULT hr = m_spBot->put_UserName(bname);
if(SUCCEEDED(hr)){
CInputStream is;
is << YahooMode << msg;
CString s = is.GetPlainText2();
if(m_BotTrigger.IsEmpty() || s.Find(m_BotTrigger,0) >= 0){
s.Replace(m_BotTrigger,"");
CComBSTR bstrIn = s;
CComBSTR bstrOut;
hr = m_spBot->respond(bstrIn,&bstrOut);
if(SUCCEEDED(hr)){
bstrIn.Empty();
hr = m_spBot->stripurl(bstrOut,&bstrIn);
USES_CONVERSION;
CString s = OLE2CT(bstrIn);
s.Replace("<br>","");
bstrIn = s;
m_pChat->ChatMessage(OLE2CT(bstrIn),false,YMSG_TEXT_NORMAL);
}
}
}
}
}
void CYahooMsgViewBase::OnEmote(LPCSTR user,LPCSTR msg,bool utf8)
{
CUser *pUser = _OnEmote(user,msg,utf8);
if(!pUser->IsIgnored()){
// mimic
if((pUser->m_mimic || m_bMimicAll) && !pUser->m_me ){
m_pChat->ChatMessage(msg,utf8,YMSG_TEXT_EMOTE);
}
}
}
void CYahooMsgViewBase::OnThink(LPCSTR user,LPCSTR msg,bool utf8)
{
CUser *pUser = _OnThink(user,msg,utf8);
if(!pUser->IsIgnored()){
// mimic
if((pUser->m_mimic || m_bMimicAll) && !pUser->m_me ){
m_pChat->ChatMessage(msg,utf8,YMSG_TEXT_BUBBLE);
}
}
}
void CYahooMsgViewBase::OnUserLeaves(NO5YAHOO::CYahooMsgUser &user)
{
CUser *pUser = _OnUserLeave(user.m_name);
if(pUser->m_follow)
m_pChat->GotoUser(pUser->m_name);
if(IsMe(pUser->m_name)){
m_pChat->ChatPing();
m_pFrame->AddMarqueeString("*chatping*");
}
}
void CYahooMsgViewBase::OnUserEnters(NO5YAHOO::CYahooMsgUser &user)
{
CUser *pUser = m_users.GetUser(user.m_name);
if(!pUser){
pUser = AddUser(user); // this also mark the user as in chat
}
else{
CopyUserInfo(pUser,user);
pUser->m_chat = true;
}
_OnUserEnter(pUser);
}
void CYahooMsgViewBase::OnInstantMessage(LPCSTR from,LPCSTR to,LPCSTR msg,
bool bUTF8,LPCSTR im_env,LPCSTR t)
{
CYahooMsgPacketIn &pi = m_pChat->GetPacketIn();
ULONG status;
switch(status = pi.m_header.GetStatus()){
case PM_OK:
if(from && lstrlen(from)){
_OnPrivateMsg(from,to,msg,bUTF8,t);
}
break;
case PM_USEROFF:
//
break;
default:
ATLTRACE("unknown pm status: %ld\n",status);
break;
}
}
void CYahooMsgViewBase::OnPrivateMessage(LPCSTR from,LPCSTR to,LPCSTR msg,bool utf8)
{
CYahooMsgPacketIn &pi = m_pChat->GetPacketIn();
ULONG status;
switch(status = pi.m_header.GetStatus()){
case PM_OK:
if(from && lstrlen(from))
_OnPrivateMsg(from,to,msg,utf8);
break;
case PM_USEROFF:
//
break;
default:
ATLTRACE("unknown pm status: %ld\n",status);
break;
}
}
void CYahooMsgViewBase::OnTyping(LPCTSTR from,bool bStart)
{
CUser *pUser = m_users.GetUser(from);
if(!pUser){
pUser = AddUser(from);
}
CString s;
if(bStart)
s.Format(" %s is typing ",from);
else
s.Format(" %s stopped typing ",from);
m_pFrame->AddMarqueeString(s);
// notify pmbox
CPrivateBox *pBox = m_pms.Find(from);
if(pBox)
pBox->Typing(bStart);
// script
if(m_spChat && pUser && !pUser->IsIgnored() && g_app.RunningScripts())
{
CComPtr<IDispatch> spUser;
HRESULT hr = CreateUserObj(pUser,&spUser);
if(SUCCEEDED(hr)){
g_app.GetNo5Obj()->Fire_OnTypingNotify(m_spChat,spUser,bStart ? VARIANT_TRUE : VARIANT_FALSE);
}
}
}
void CYahooMsgViewBase::OnWebcamInvite(LPCTSTR from)
{
CUser *pUser = m_users.GetUser(from);
if(!pUser){
pUser = AddUser(from);
}
if(!pUser->IsIgnored()){
if(!pUser->OnAnyPost()){
InitTS init(m_ts);
CTextAtom atom;
CString cmd("/viewcam ");
cmd += from;
m_ts.AddAtom(atom.AtomLink(cmd));
m_ts.AddAtom(atom.AtomLink(FALSE));
}
}
// script
if(m_spChat && pUser && !pUser->IsIgnored() && g_app.RunningScripts())
{
CComPtr<IDispatch> spUser;
HRESULT hr = CreateUserObj(pUser,&spUser);
if(SUCCEEDED(hr)){
g_app.GetNo5Obj()->Fire_OnCamInvitation(m_spChat,spUser);
}
}
}
void CYahooMsgViewBase::OnWebcamInviteReply(LPCTSTR from,bool bAccepted)
{
CUser *pUser = m_users.GetUser(from);
if(!pUser){
pUser = AddUser(from);
}
if(!pUser->IsIgnored()){
if(!pUser->OnAnyPost()){
InitTS init(m_ts);
m_ts << m_pvo->TxtNo5();
m_ts << from << " : ";
if(bAccepted)
m_ts << "accepted to view your cam";
else
m_ts << "denied the request to view your cam";
}
}
// script
if(m_spChat && pUser && !pUser->IsIgnored() && g_app.RunningScripts())
{
CComPtr<IDispatch> spUser;
HRESULT hr = CreateUserObj(pUser,&spUser);
if(SUCCEEDED(hr)){
g_app.GetNo5Obj()->Fire_OnWebcamInviteReply(m_spChat,spUser,
bAccepted ? VARIANT_TRUE : VARIANT_FALSE);
}
}
}
void CYahooMsgViewBase::OnNotify(LPCSTR from,LPCSTR notify_string,LPCSTR status)
{
DisplayUnknownCallback();
}
void CYahooMsgViewBase::OnAddBuddy(LPCSTR me,LPCSTR group,const CBuddyInfo &bi)
{
DisplayUnknownCallback();
CBuddy b;
b.m_name = bi.m_name;
b.m_status = bi.m_status;
CBuddy *pb = m_buddies.AddBuddy(group,b);
if(m_bActive)
m_pFrame->BuddyListView()->OnAddBuddy(group,pb);
CUser *pUser = m_users.GetUser(bi.m_name);
if(pUser)
pUser->m_buddy = true;
}
void CYahooMsgViewBase::OnRemBuddy(LPCSTR me,LPCSTR buddy,LPCSTR group)
{
DisplayUnknownCallback();
if(m_bActive)
m_pFrame->BuddyListView()->OnRemBuddy(group,buddy);
m_buddies.RemoveBuddy(group,buddy);
CUser *pUser = m_users.GetUser(buddy);
if(pUser)
pUser->m_buddy = false;
}
void CYahooMsgViewBase::OnIgnoreUser(LPCSTR who,LPCSTR me,bool ignore,LPCSTR answer)
{
DisplayUnknownCallback();
}
void CYahooMsgViewBase::OnBuddyList(LPCTSTR group,CSimpleArray<CString> &buddies)
{
CUser *pUser;
const int count = buddies.GetSize();
int i;
for(i=0;i<count;i++){
pUser = m_users.GetUser(buddies[i]);
if(pUser)
pUser->m_buddy = true;
}
CBuddyGroup *pg = m_buddies.AddBuddies(group,buddies);
if(m_bActive){
m_pFrame->BuddyListView()->SetAcc(this,m_pChat->GetName(),&m_buddies);
m_pFrame->BuddyListView()->OnBuddyGroup(pg);
}
}
void CYahooMsgViewBase::OnIgnoreList(CSimpleArray<CString> &lst)
{
}
void CYahooMsgViewBase::OnAlternateIdList(CSimpleArray<CString> &lst)
{
// todo
}
void CYahooMsgViewBase::OnChatLogout(void)
{
InitTS init(m_ts);
m_ts << m_pvo->TxtNo5();
m_ts << "you have logged out of chat";
}