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
|
/*
WinPopup Protocol plugin for Miranda IM.
Copyright (C) 2004-2010 Nikolay Raspopov
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, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "stdafx.h"
// Îòêðûâàåò "\\Nick" ïðè ïîìîùè ShellExecute() ("Nick" èç êîíòàêòà)
// wParam=hContact
// lParam=0
// Âîçâðàùàåò 0
#define PS_EXPLORE "/Explore"
// Ïîêàçûâàåò äèàëîã äëÿ ðó÷íîãî äîáàâëåíèÿ êîíòàêòà ïî èìåíè/àäðåñó
// wParam=Position
// lParam=0
// Âîçâðàùàåò 0
#define PS_ADDDIALOG "/AddDialog"
/////////////////////////////////////////////////////////////////////////////
// Ñåðâèñíûå ôóíêöèè
// WinPopup Protocol/Explore
INT_PTR Explore(WPARAM wParam, LPARAM lParam);
// WinPopup Protocol/AddDialog
INT_PTR AddDialog(WPARAM wParam, LPARAM lParam);
// WinPopup Protocol/GetCaps
INT_PTR GetCaps(WPARAM flagNum, LPARAM lParam);
// WinPopup Protocol/GetName
INT_PTR GetName(WPARAM cchName, LPARAM szName);
// WinPopup Protocol/LoadIcon
INT_PTR LoadIcon(WPARAM whichIcon, LPARAM lParam);
// WinPopup Protocol/SetStatus
INT_PTR SetStatus(WPARAM newStatus, LPARAM lParam);
// WinPopup Protocol/SetAwayMsg
INT_PTR SetAwayMsg(WPARAM status_mode, LPARAM szMessage);
// WinPopup Protocol/GetAwayMsg
INT_PTR GetAwayMsg(WPARAM wParam, LPARAM lParam);
// WinPopup Protocol/GetStatus
INT_PTR GetStatus(WPARAM wParam, LPARAM lParam);
// WinPopup Protocol/GetInfo
INT_PTR GetInfo(WPARAM flags, LPARAM lParam);
// WinPopup Protocol/RecvMessage
INT_PTR RecvMessage(WPARAM flags, LPARAM lParam);
// WinPopup Protocol/SendMsg
INT_PTR SendMsg(WPARAM flags, LPARAM lParam);
// WinPopup Protocol/BasicSearch
INT_PTR BasicSearch(WPARAM wParam, LPARAM szId);
// WinPopup Protocol/AddToList
INT_PTR AddToList(WPARAM flags, LPARAM lParam);
// WinPopup Protocol/GetAvatarCaps
INT_PTR GetAvatarCaps(WPARAM wParam, LPARAM lParam);
// WinPopup Protocol/GetAvatarInformation
INT_PTR GetAvatarInfo(WPARAM flags, LPARAM lParam);
// WinPopup Protocol/SetMyAvatar
INT_PTR SetMyAvatar(WPARAM wParam, LPARAM lParam);
// WinPopup Protocol/GetMyAvatar
INT_PTR GetMyAvatar(WPARAM wParam, LPARAM lParam);
// WinPopup Protocol/CreateAccMgrUI
INT_PTR CreateAccMgrUI(WPARAM wParam, LPARAM lParam);
/////////////////////////////////////////////////////////////////////////////
// Ïåðåõâàò÷èêè
// Ïåðåõâàò÷èê ME_SYSTEM_MODULESLOADED
int __cdecl SYSTEM_MODULESLOADED(WPARAM wParam, LPARAM lParam);
// Ïåðåõâàò÷èê ME_SYSTEM_PRESHUTDOWN
int __cdecl SYSTEM_PRESHUTDOWN(WPARAM wParam, LPARAM lParam);
/////////////////////////////////////////////////////////////////////////////
// Äàííûå ïëàãèíà
int hLangpack;
const PROTOCOLDESCRIPTOR pluginPD =
{
sizeof( PROTOCOLDESCRIPTOR ),
modname,
PROTOTYPE_PROTOCOL
};
static PLUGININFOEX pluginInfoEx =
{
sizeof(PLUGININFOEX),
modname,
PLUGIN_MAKE_VERSION (0,0,0,18),
"Allows you to send and receive messages over Microsoft LAN. "
"WinPopup and Net Send replacement powered by Miranda IM.",
"Nikolay Raspopov",
"ryo-oh-ki@narod.ru",
"© 2004-2010 Nikolay Raspopov",
"http://www.cherubicsoft.com/miranda/",
UNICODE_AWARE,
// {DE6EE412-ACE3-45db-A329-D618FABB4291}
{0xde6ee412, 0xace3, 0x45db, {0xa3, 0x29, 0xd6, 0x18, 0xfa, 0xbb, 0x42, 0x91}}
};
extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = {MIID_PROTOCOL, MIID_LAST};
HANDLE plugin_FnGetCaps = NULL;
HANDLE plugin_FnGetName = NULL;
HANDLE plugin_FnLoadIcon = NULL;
HANDLE plugin_FnSetStatus = NULL;
HANDLE plugin_FnGetStatus = NULL;
HANDLE plugin_FnGetAwayMsg = NULL;
HANDLE plugin_FnSetAwayMsg = NULL;
HANDLE plugin_FnGetInfo = NULL;
HANDLE plugin_FnSendMsg = NULL;
HANDLE plugin_FnRecvMessage = NULL;
HANDLE plugin_FnBasicSearch = NULL;
HANDLE plugin_FnAddToList = NULL;
HANDLE plugin_FnExplore = NULL;
HANDLE plugin_FnAddDialog = NULL;
HANDLE plugin_FnGetAvatarCaps = NULL;
HANDLE plugin_FnGetAvatarInfo = NULL;
HANDLE plugin_FnSetMyAvatar = NULL;
HANDLE plugin_FnGetMyAvatar = NULL;
HANDLE plugin_FnCreateAccMgrUI = NULL;
HANDLE plugin_SYSTEM_MODULESLOADED = NULL;
HANDLE plugin_SYSTEM_PRESHUTDOWN = NULL;
HANDLE plugin_OPT_INITIALISE = NULL;
HANDLE plugin_USERINFO_INITIALISE = NULL;
/////////////////////////////////////////////////////////////////////////////
// Äèíàìè÷åñêèå ôóíêöèè çàãðóæàåìûå DllLoaderîì
DllLoader pluginNetapi32 ( _T("netapi32.dll"), false);
DllLoader pluginAdvapi32 ( _T("advapi32.dll"), false);
FuncPtrType(NET_API_STATUS (NET_API_FUNCTION *) (LMSTR, DWORD, LPBYTE*) ) fnNetWkstaGetInfo;
FuncPtrType(DWORD (NET_API_FUNCTION *) (LPVOID) ) fnNetApiBufferFree;
FuncPtrType(DWORD (NET_API_FUNCTION *) (LPCWSTR, LPCWSTR, LPCWSTR, LPBYTE, DWORD) ) fnNetMessageBufferSend;
FuncPtrType(SC_HANDLE (WINAPI *) (LPCTSTR, LPCTSTR, DWORD) ) fnOpenSCManager;
FuncPtrType(SC_HANDLE (WINAPI *) (SC_HANDLE, LPCTSTR, DWORD) ) fnOpenService;
FuncPtrType(BOOL (WINAPI *) (SC_HANDLE, DWORD, LPSERVICE_STATUS) ) fnControlService;
FuncPtrType(BOOL (WINAPI *) (SC_HANDLE, LPSERVICE_STATUS) ) fnQueryServiceStatus;
FuncPtrType(BOOL (WINAPI *) (SC_HANDLE) ) fnCloseServiceHandle;
FuncPtrType(BOOL (WINAPI *) (SC_HANDLE, DWORD, LPCTSTR*) ) fnStartService;
FuncPtrType(SC_LOCK (WINAPI *) (SC_HANDLE) ) fnLockServiceDatabase;
FuncPtrType(BOOL (WINAPI *) (SC_LOCK) ) fnUnlockServiceDatabase;
FuncPtrType(BOOL (WINAPI *) (SC_HANDLE, DWORD, DWORD, DWORD, LPCTSTR, LPCTSTR, LPDWORD, LPCTSTR, LPCTSTR, LPCTSTR, LPCTSTR) ) fnChangeServiceConfig;
#define CreateHook( hService, szName, Function ) \
_ASSERT( hService == NULL ); \
hService = HookEvent( szName, Function ); \
_ASSERT ( hService != NULL ); \
if ( ! hService ) return 1;
#define DestroyHook( hService ) \
if ( hService ) { \
UnhookEvent( hService ); \
hService = NULL; \
}
#define CreateServiceFn( hService, szName, Function ) \
_ASSERT( hService == NULL ); \
hService = CreateServiceFunction( modname szName, Function ); \
_ASSERT( hService != NULL ); \
if ( ! hService ) return 1;
#ifdef _DEBUG
#define DestroyServiceFn( hService ) \
if( hService ) { \
_ASSERT( DestroyServiceFunction( hService ) == 0 ); \
hService = NULL; \
}
#else // _DEBUG
#define DestroyServiceFn( hService ) \
if( hService ) { \
DestroyServiceFunction( hService ); \
hService = NULL; \
}
#endif // _DEBUG
INT_PTR Explore(WPARAM wParam, LPARAM /* lParam */)
{
CString sNick = GetNick( (HANDLE)wParam );
if ( pluginInstalled && ! sNick.IsEmpty() )
{
// Âûçîâ UNC èìåíè: \\Nick
CString cmd( _T("\\\\") );
cmd += sNick;
ShellExecute( NULL, NULL, cmd, NULL, NULL, SW_SHOWDEFAULT );
}
return 0;
}
INT_PTR AddDialog (WPARAM /* wParam */, LPARAM /* lParam */)
{
AddDialog( NULL );
return 0;
}
INT_PTR GetCaps (WPARAM flagNum, LPARAM /* lParam */)
{
INT_PTR nReturn = 0;
switch ( flagNum )
{
case PFLAGNUM_1:
nReturn = PF1_IM | PF1_BASICSEARCH | PF1_MODEMSG | PF1_PEER2PEER;
break;
case PFLAGNUM_2:
case PFLAGNUM_3:
nReturn = PF2_ONLINE | PF2_INVISIBLE | PF2_SHORTAWAY | PF2_LONGAWAY |
PF2_LIGHTDND | PF2_HEAVYDND | PF2_FREECHAT |
PF2_ONTHEPHONE | PF2_OUTTOLUNCH;
break;
case PFLAGNUM_4:
nReturn = PF4_AVATARS;
break;
case PFLAGNUM_5:
nReturn = 0;
break;
case PFLAG_UNIQUEIDTEXT:
nReturn = (INT_PTR)Translate ("Computer,User,Group");
break;
case PFLAG_UNIQUEIDSETTING:
nReturn = (INT_PTR)"Nick";
break;
case PFLAG_MAXLENOFMESSAGE:
// HANDLE hContact = (HANDLE) lParam;
nReturn = 0x7fffffff;
break;
}
return nReturn;
}
INT_PTR GetName(WPARAM cchName, LPARAM szName)
{
lstrcpynA( (char*) szName, modtitle, static_cast <int>( cchName ) );
return 0;
}
INT_PTR LoadIcon(WPARAM whichIcon, LPARAM /* lParam */)
{
UINT id;
switch ( whichIcon & 0xFFFF )
{
case PLI_PROTOCOL:
id = IDI_WINPOPUP;
break;
case PLI_ONLINE:
id = IDI_ONLINE;
break;
case PLI_OFFLINE:
id = IDI_OFFLINE;
break;
default:
return 0;
}
return (INT_PTR)LoadImage (pluginModule, MAKEINTRESOURCE (id), IMAGE_ICON,
(whichIcon & PLIF_SMALL ? 16 : 32), (whichIcon & PLIF_SMALL ? 16 : 32), 0);
}
INT_PTR SetStatus (WPARAM newStatus, LPARAM /* lParam */)
{
if ( pluginInstalled && pluginCurrentStatus != (int)newStatus )
{
LOG ("SetStatus from \"%s\" to \"%s\"",
STATUS2TEXT(pluginCurrentStatus), STATUS2TEXT(newStatus));
pluginRequestedStatus = newStatus;
switch (newStatus) {
case ID_STATUS_OFFLINE:
GotoOffline ();
break;
case ID_STATUS_FREECHAT:
case ID_STATUS_INVISIBLE:
newStatus = ID_STATUS_ONLINE;
case ID_STATUS_ONLINE:
case ID_STATUS_AWAY:
case ID_STATUS_DND:
case ID_STATUS_NA:
case ID_STATUS_OCCUPIED:
case ID_STATUS_ONTHEPHONE:
case ID_STATUS_OUTTOLUNCH:
default:
GotoOnline ();
break;
}
}
return 0;
}
INT_PTR SetAwayMsg (WPARAM status_mode, LPARAM szMessage)
{
pluginStatusMessage[ status_mode ] = ( szMessage ? (LPCSTR) szMessage : "" );
return 0;
}
INT_PTR GetAwayMsg(WPARAM /* wParam */, LPARAM lParam)
{
CCSDATA *ccs = (CCSDATA*)lParam;
if ( pluginInstalled && ccs && ccs->hContact )
{
if ( ContactData* data = new ContactData )
{
data->hContact = ccs->hContact;
HANDLE cookie = data->cookie = GenerateCookie();
mir_forkthread( GetAwayMsgThread, data );
return (INT_PTR)cookie;
}
}
return 0;
}
INT_PTR GetStatus (WPARAM /* wParam */, LPARAM /* lParam */)
{
return (INT_PTR)pluginCurrentStatus;
}
INT_PTR GetInfo (WPARAM /* flags */, LPARAM lParam)
{
CCSDATA* ccs = (CCSDATA*)lParam;
if ( pluginInstalled && ccs && ccs->hContact )
{
mir_forkthread( GetInfoThread, ccs->hContact );
return 0;
}
return 1;
}
INT_PTR RecvMessage (WPARAM /* flags */, LPARAM lParam)
{
CCSDATA* ccs = (CCSDATA*) lParam;
if ( pluginInstalled && ccs && ccs->hContact && ccs->lParam)
{
PROTORECVEVENT *pre = (PROTORECVEVENT*) ccs->lParam;
// Äîáàâëåíèå ñîîáùåíèÿ
DBDeleteContactSetting (ccs->hContact, "CList", "Hidden");
DBEVENTINFO ei = { 0 };
ei.cbSize = sizeof (DBEVENTINFO);
ei.szModule = modname;
ei.timestamp = pre->timestamp;
ei.flags = (pre->flags & PREF_CREATEREAD) ? DBEF_READ : 0u;
ei.eventType = EVENTTYPE_MESSAGE;
ei.cbBlob = (DWORD)( lstrlenA (pre->szMessage) + 1 );
ei.pBlob = (PBYTE) pre->szMessage;
CallService (MS_DB_EVENT_ADD, (WPARAM) ccs->hContact, (LPARAM) &ei);
}
return 0;
}
INT_PTR SendMsg(WPARAM /* flags */, LPARAM lParam)
{
CCSDATA* ccs = (CCSDATA*) lParam;
if ( pluginInstalled && ccs && ccs->hContact && ccs->lParam )
{
if ( SendMsgData* data = new SendMsgData )
{
data->hContact = ccs->hContact;
data->text = (LPCSTR)ccs->lParam;
HANDLE cookie = data->cookie = GenerateCookie();
mir_forkthread( SendMsgThread, data );
return (INT_PTR)cookie;
}
}
return 0;
}
INT_PTR BasicSearch(WPARAM /* wParam */, LPARAM szId)
{
if ( pluginInstalled && szId )
{
return pluginSearch.StartSearch( CA2T( (LPCSTR)szId ) );
}
return 0;
}
INT_PTR AddToList(WPARAM flags, LPARAM lParam)
{
PROTOSEARCHRESULT* psr = (PROTOSEARCHRESULT*) lParam;
if ( psr && psr->cbSize >= sizeof (PROTOSEARCHRESULT) && psr->nick && *psr->nick )
{
CString sName( psr->nick );
CString sNotes( psr->firstName );
return (INT_PTR)AddToListByName( sName, flags, sNotes, false, false );
}
return 0;
}
INT_PTR GetAvatarCaps(WPARAM wParam, LPARAM lParam)
{
switch ( wParam )
{
case AF_MAXSIZE:
if ( POINT* size = (POINT*)lParam )
{
size->x = 300; // -1 - íå ðàáîòàåò èç-çà íåñîîòâåòñòâèÿ avs.dll ñòàíäàðòó
size->y = 300; // -1 - íå ðàáîòàåò èç-çà íåñîîòâåòñòâèÿ avs.dll ñòàíäàðòó
}
break;
case AF_PROPORTION:
return PIP_NONE;
case AF_FORMATSUPPORTED:
switch ( lParam )
{
case PA_FORMAT_UNKNOWN:
case PA_FORMAT_PNG:
case PA_FORMAT_JPEG:
case PA_FORMAT_ICON:
case PA_FORMAT_BMP:
case PA_FORMAT_GIF:
case PA_FORMAT_SWF:
case PA_FORMAT_XML:
return 1;
}
break;
case AF_ENABLED:
return 1;
case AF_DONTNEEDDELAYS:
return 1;
case AF_MAXFILESIZE:
return MAX_AVATAR_SIZE;
case AF_DELAYAFTERFAIL:
return 10 * 60 * 1000; // 10 ìèíóò
}
return 0;
}
INT_PTR GetAvatarInfo(WPARAM /*flags*/, LPARAM lParam)
{
PROTO_AVATAR_INFORMATION* pai = (PROTO_AVATAR_INFORMATION*)lParam;
if ( pai && pai->cbSize >= sizeof( PROTO_AVATAR_INFORMATION ) )
{
if ( ContactData* data = new ContactData )
{
data->hContact = pai->hContact;
/*HANDLE cookie =*/ data->cookie = GenerateCookie();
mir_forkthread( GetAvatarInfoThread, data );
return GAIR_WAITFOR;
}
}
return GAIR_NOAVATAR;
}
INT_PTR SetMyAvatar(WPARAM /*wParam*/, LPARAM lParam)
{
CA2T szFilename( (LPCSTR)lParam );
TCHAR szPath[ MAX_PATH ];
GetAvatarCache( szPath );
if ( szFilename )
{
// Ñîõðàíåíèå àâàòàðà
lstrcat( szPath, _T("MyAvatar") );
lstrcat( szPath, _tcsrchr( szFilename, _T('.') ) );
if ( lstrcmpi( szPath, szFilename ) == 0 )
{
// Òîò æå ñàìûé ôàéë - íè÷åãî íå äåëàåì
}
else
{
// Äðóãîé ôàéë - êîïèðîâàíèå àâàòàðà ê ñåáå
SHFILEOPSTRUCT sfo = {};
sfo.hwnd = GetDesktopWindow();
sfo.wFunc = FO_COPY;
TCHAR szFrom[ MAX_PATH ] = {};
lstrcpy( szFrom, szFilename );
sfo.pFrom = szFrom;
sfo.pTo = szPath;
sfo.fFlags = FOF_ALLOWUNDO | FOF_FILESONLY | FOF_NORECURSION |
FOF_NOCONFIRMATION;
SHFileOperation( &sfo );
}
DBWriteContactSettingTString( NULL, modname, "AvatarFile",
_tcsrchr( szPath, _T('\\') ) + 1 );
}
else
{
// Óäàëåíèå àâàòàðà â êîðçèíó
DBVARIANT dbv = {};
if ( ! DBGetContactSettingTString( NULL, modname, "AvatarFile", &dbv ) )
{
lstrcat( szPath, dbv.ptszVal );
SHFILEOPSTRUCT sfo = {};
sfo.hwnd = GetDesktopWindow();
sfo.wFunc = FO_DELETE;
sfo.pFrom = szPath;
sfo.fFlags = FOF_ALLOWUNDO | FOF_FILESONLY | FOF_NORECURSION |
FOF_NOCONFIRMATION;
SHFileOperation( &sfo );
DBFreeVariant( &dbv );
DBDeleteContactSetting( NULL, modname, "AvatarFile" );
}
}
return 0;
}
INT_PTR GetMyAvatar(WPARAM wParam, LPARAM lParam)
{
LPSTR szFilename = (LPSTR)wParam;
int nLength = (int)lParam;
bool ret = false;
if ( szFilename == NULL || nLength < MAX_PATH )
return -1;
TCHAR szPath[ MAX_PATH ];
GetAvatarCache( szPath );
DBVARIANT dbv = {};
if ( ! DBGetContactSettingTString( NULL, modname, "AvatarFile", &dbv ) )
{
lstrcat( szPath, dbv.ptszVal );
ret = ( GetFileAttributes( szPath ) != INVALID_FILE_ATTRIBUTES );
DBFreeVariant( &dbv );
}
if ( ! ret )
return -1;
lstrcpyA( szFilename, CT2A( szPath ) );
return 0;
}
static INT_PTR CALLBACK DlgProcCreateAccMgrUI(HWND hwndDlg, UINT Msg,
WPARAM /*wParam*/, LPARAM /*lParam*/)
{
switch ( Msg )
{
case WM_INITDIALOG:
{
TranslateDialogDefault( hwndDlg );
return TRUE;
}
}
return FALSE;
}
INT_PTR CreateAccMgrUI(WPARAM /*wParam*/, LPARAM lParam)
{
return (INT_PTR)CreateDialogParam( pluginModule, MAKEINTRESOURCE( IDD_CREATE ),
(HWND)lParam, DlgProcCreateAccMgrUI, 0 );
}
/////////////////////////////////////////////////////////////////////////////
// Èíòåðôåéñû ïëàãèíà
extern "C" __declspec(dllexport) PLUGININFOEX *MirandaPluginInfoEx(DWORD mirandaVersion)
{
return &pluginInfoEx;
}
extern "C" int __declspec(dllexport) Load(void)
{
mir_getLP(&pluginInfoEx);
GetVersionEx( &pluginOS );
if (pluginNetapi32.LoadLibrary (pluginModule))
{
pluginNetapi32.LoadFunc (fnNetWkstaGetInfo, "NetWkstaGetInfo");
pluginNetapi32.LoadFunc (fnNetApiBufferFree, "NetApiBufferFree");
pluginNetapi32.LoadFunc (fnNetMessageBufferSend, "NetMessageBufferSend");
}
if (pluginAdvapi32.LoadLibrary (pluginModule))
{
pluginAdvapi32.LoadFunc (fnOpenSCManager, "OpenSCManagerW");
pluginAdvapi32.LoadFunc (fnOpenService, "OpenServiceW");
pluginAdvapi32.LoadFunc (fnStartService, "StartServiceW");
pluginAdvapi32.LoadFunc (fnChangeServiceConfig, "ChangeServiceConfigW");
pluginAdvapi32.LoadFunc (fnControlService, "ControlService");
pluginAdvapi32.LoadFunc (fnQueryServiceStatus, "QueryServiceStatus");
pluginAdvapi32.LoadFunc (fnCloseServiceHandle, "CloseServiceHandle");
pluginAdvapi32.LoadFunc (fnLockServiceDatabase, "LockServiceDatabase");
pluginAdvapi32.LoadFunc (fnUnlockServiceDatabase, "UnlockServiceDatabase");
}
_ASSERT( pluginInternalState == NULL );
pluginInternalState = CreateEvent( NULL, TRUE, TRUE, NULL );
_ASSERT( pluginInternalState != NULL );
INT_PTR retCallService = CallService (MS_PROTO_REGISTERMODULE, 0, (LPARAM) &pluginPD);
_ASSERT (retCallService != CALLSERVICE_NOTFOUND);
if ( retCallService == CALLSERVICE_NOTFOUND ) return 1;
CreateServiceFn( plugin_FnGetCaps, PS_GETCAPS, GetCaps );
CreateServiceFn( plugin_FnGetName, PS_GETNAME, GetName );
CreateServiceFn( plugin_FnLoadIcon, PS_LOADICON, LoadIcon );
CreateServiceFn( plugin_FnSetStatus, PS_SETSTATUS, SetStatus );
CreateServiceFn( plugin_FnGetStatus, PS_GETSTATUS, GetStatus );
CreateServiceFn( plugin_FnSetAwayMsg, PS_SETAWAYMSG, SetAwayMsg );
CreateServiceFn( plugin_FnGetAwayMsg, PSS_GETAWAYMSG, GetAwayMsg );
CreateServiceFn( plugin_FnGetInfo, PSS_GETINFO, GetInfo );
CreateServiceFn( plugin_FnSendMsg, PSS_MESSAGE, SendMsg );
CreateServiceFn( plugin_FnRecvMessage, PSR_MESSAGE, RecvMessage );
CreateServiceFn( plugin_FnBasicSearch, PS_BASICSEARCH, BasicSearch );
CreateServiceFn( plugin_FnAddToList, PS_ADDTOLIST, AddToList );
CreateServiceFn( plugin_FnExplore, PS_EXPLORE, Explore );
CreateServiceFn( plugin_FnAddDialog, PS_ADDDIALOG, AddDialog);
CreateServiceFn( plugin_FnGetAvatarCaps, PS_GETAVATARCAPS, GetAvatarCaps );
CreateServiceFn( plugin_FnGetAvatarInfo, PS_GETAVATARINFO, GetAvatarInfo );
CreateServiceFn( plugin_FnSetMyAvatar, PS_SETMYAVATAR, SetMyAvatar );
CreateServiceFn( plugin_FnGetMyAvatar, PS_GETMYAVATAR, GetMyAvatar );
CreateServiceFn( plugin_FnCreateAccMgrUI, PS_CREATEACCMGRUI, CreateAccMgrUI );
CreateHook( plugin_SYSTEM_MODULESLOADED, ME_SYSTEM_MODULESLOADED, SYSTEM_MODULESLOADED );
CreateHook( plugin_SYSTEM_PRESHUTDOWN, ME_SYSTEM_PRESHUTDOWN, SYSTEM_PRESHUTDOWN );
return 0;
}
extern "C" int __declspec(dllexport) Unload()
{
#ifdef CHAT_ENABLED
ChatUnregister();
#endif // CHAT_ENABLED
DestroyHook( plugin_USERINFO_INITIALISE );
DestroyHook( plugin_OPT_INITIALISE );
DestroyHook( plugin_SYSTEM_PRESHUTDOWN );
DestroyHook( plugin_SYSTEM_MODULESLOADED );
DestroyServiceFn( plugin_FnExplore );
DestroyServiceFn( plugin_FnAddDialog );
DestroyServiceFn( plugin_FnGetCaps );
DestroyServiceFn( plugin_FnGetName );
DestroyServiceFn( plugin_FnLoadIcon );
DestroyServiceFn( plugin_FnSetStatus );
DestroyServiceFn( plugin_FnGetStatus );
DestroyServiceFn( plugin_FnSetAwayMsg );
DestroyServiceFn( plugin_FnGetAwayMsg );
DestroyServiceFn( plugin_FnGetInfo );
DestroyServiceFn( plugin_FnSendMsg );
DestroyServiceFn( plugin_FnRecvMessage );
DestroyServiceFn( plugin_FnBasicSearch );
DestroyServiceFn( plugin_FnAddToList );
DestroyServiceFn( plugin_FnGetAvatarCaps );
DestroyServiceFn( plugin_FnGetAvatarInfo );
DestroyServiceFn( plugin_FnSetMyAvatar );
DestroyServiceFn( plugin_FnGetMyAvatar );
DestroyServiceFn( plugin_FnCreateAccMgrUI );
if ( pluginNetLibUser != NULL )
Netlib_CloseHandle( pluginNetLibUser );
pluginNetLibUser = NULL;
if ( pluginInternalState != NULL )
CloseHandle( pluginInternalState );
pluginInternalState = NULL;
pluginNetapi32.FreeLibrary();
pluginAdvapi32.FreeLibrary();
return 0;
}
/////////////////////////////////////////////////////////////////////////////
// Ïåðåõâàò÷èêè
int __cdecl SYSTEM_MODULESLOADED (WPARAM /* wParam */, LPARAM /* lParam */)
{
_ASSERT (pluginInstalled == true);
_ASSERT (pluginInitialized == false);
_ASSERT (pluginNetLibUser == NULL);
const NETLIBUSER nlu =
{
sizeof( NETLIBUSER ),
modname,
modname,
0,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
0
};
pluginNetLibUser = (HANDLE)CallService( MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu );
_ASSERT (pluginNetLibUser);
CreateHook( plugin_OPT_INITIALISE, ME_OPT_INITIALISE, OPT_INITIALISE );
CreateHook( plugin_USERINFO_INITIALISE, ME_USERINFO_INITIALISE, USERINFO_INITIALISE );
// Óñòàíîâêà èêîíîê ñòàòóñîâ
struct
{
int icon_id;
int status;
}
const StatusIcons [] =
{
{ IDI_OFFLINE, ID_STATUS_OFFLINE },
{ IDI_ONLINE, ID_STATUS_ONLINE },
{ IDI_AWAY, ID_STATUS_AWAY },
{ IDI_DND, ID_STATUS_DND },
{ IDI_NA, ID_STATUS_NA },
{ IDI_OCCUPIED, ID_STATUS_OCCUPIED },
{ IDI_FREECHAT, ID_STATUS_FREECHAT },
{ IDI_INVISIBLE, ID_STATUS_INVISIBLE },
{ IDI_ONTHEPHONE, ID_STATUS_ONTHEPHONE },
{ IDI_OUTTOLUNCH, ID_STATUS_OUTTOLUNCH },
{ 0, 0 }
};
TCHAR path [ MAX_PATH * 2 ] = { 0 };
TCHAR icon [ 32 ] = { 0 };
DWORD len = GetModuleFileName (pluginModule, path, MAX_PATH);
lstrcpy( path + len, _T(",-") );
len += 2;
for (int i = 0; StatusIcons[i].icon_id ; i++)
{
wsprintf( path + len, _T("%d"), StatusIcons[i].icon_id );
wsprintf( icon, modname_t _T("%d"), StatusIcons[i].status );
DBVARIANT dbv = {};
if ( ! DBGetContactSetting( NULL, "Icons", CT2A( icon ), &dbv ) )
DBFreeVariant( &dbv );
else
DBWriteContactSettingTString( NULL, "Icons", CT2A( icon ), path );
}
// Îïðåäåëåíèå èìåíè êîìïüþòåðà
DWORD iMachineNameLength = MAX_COMPUTERNAME_LENGTH + 2;
GetComputerName(
pluginMachineName.GetBuffer( (int)iMachineNameLength ), &iMachineNameLength );
pluginMachineName.ReleaseBuffer();
SetNick( NULL, pluginMachineName );
// Îïðåäåëåíèå èìåíè ïîëüçîâàòåëÿ
DWORD iUserNameLength = UNLEN + 2;
GetUserName(
pluginUserName.GetBuffer( (int)iUserNameLength ), &iUserNameLength );
pluginUserName.ReleaseBuffer();
DBWriteContactSettingTString( NULL, modname, "User", pluginUserName );
// Îïðåäåëåíèå èìåíè ðàáî÷åé ãðóïïû
if ( pluginOS.dwPlatformId == VER_PLATFORM_WIN32_NT )
{
WKSTA_INFO_100* info = NULL;
NET_API_STATUS err = fnNetWkstaGetInfo (NULL, 100, (LPBYTE*) &info);
if (err == NERR_Success && info)
{
LPTSTR langroup = mir_u2t( info->wki100_langroup );
pluginDomainName = langroup;
fnNetApiBufferFree (info);
mir_free( langroup );
}
// Àëüòåðíàòèâà?
// HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
// DefaultDomainName
}
else
{
HKEY hKey = NULL;
if (ERROR_SUCCESS == RegOpenKeyEx (HKEY_LOCAL_MACHINE,
_T("System\\CurrentControlSet\\Services\\VxD\\VNETSUP"), 0, KEY_READ, &hKey))
{
DWORD type, size = MAX_PATH;
RegQueryValueEx (hKey, _T("Workgroup"), 0, &type,
(LPBYTE) pluginDomainName.GetBuffer (MAX_PATH + 1), &size);
pluginDomainName.ReleaseBuffer( (int)size );
RegCloseKey (hKey);
}
}
DBWriteContactSettingTString (NULL, modname, "Workgroup", pluginDomainName);
// Ðåãèñòðàöèÿ â Chat
#ifdef CHAT_ENABLED
pluginChatEnabled = ChatRegister();
#endif // CHAT_ENABLED
// Äîáàâëåíèå ìåíþ
CLISTMENUITEM miExplore =
{
sizeof( CLISTMENUITEM ),
(LPSTR)TranslateT( "Explore" ),
CMIF_TCHAR,
0,
(HICON)LoadImage( pluginModule, MAKEINTRESOURCE( IDI_EXPLORE ),
IMAGE_ICON, 16, 16, LR_SHARED ),
modname PS_EXPLORE,
NULL,
0,
0,
modname
};
Menu_AddContactMenuItem(&miExplore);
CLISTMENUITEM miAddContact =
{
sizeof( CLISTMENUITEM ),
NULL,
CMIF_TCHAR,
500090000,
(HICON)LoadImage( pluginModule, MAKEINTRESOURCE( IDI_WINPOPUP ),
IMAGE_ICON, 16, 16, LR_SHARED ),
modname PS_ADDDIALOG,
NULL,
0,
0,
NULL
};
miAddContact.ptszName = (LPTSTR)TranslateT( "Add contact..." );
miAddContact.ptszPopupName = (LPTSTR)modtitle_t;
HANDLE hMenuItem = Menu_AddMainMenuItem(&miAddContact);
// Çàìåíà èêîíêè
miAddContact.flags = CMIM_ICON;
miAddContact.hIcon = (HICON)LoadImage( pluginModule,
MAKEINTRESOURCE( IDI_ADD_COMPUTER ), IMAGE_ICON, 16, 16, LR_SHARED ),
CallService( MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuItem, (LPARAM)&miAddContact );
// Ðàçðåøåíèå íà àêòèâíûå äåéñòâèÿ (íàïðèìåð, ïåðåõîä â îíëàéí)
pluginInitialized = true;
// Âîññòàíîâëåíèå ñòàòóñà êîòîðûé ìîã áûòü ïðîèãíîðèðîâàí
SetStatus( pluginRequestedStatus, 0 );
return 0;
}
int __cdecl SYSTEM_PRESHUTDOWN (WPARAM /* wParam */, LPARAM /* lParam */)
{
// Çàïðåò íà àêòèâíûå äåéñòâèÿ (íàïðèìåð, ïåðåõîä â îíëàéí)
pluginInstalled = false;
// Îæèäàíèå ïîäòâåðæäåíèÿ îñòàíîâà, ò.ê. ïåðåõîä â îôôëàéí âûïîëíÿåòñÿ àñèíõðîííî
// Âûçîâ èç ïîòîêà ìèðàíäû, ãäå áûëî ñîçäàíî îêíî
do
{
MSG msg;
while ( PeekMessage( &msg, NULL, NULL, NULL, PM_REMOVE ) )
{
if ( IsDialogMessage( msg.hwnd, &msg ) ) continue;
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
while ( MsgWaitForMultipleObjects( 1, &pluginInternalState, FALSE,
INFINITE, QS_ALLINPUT ) == WAIT_OBJECT_0 + 1 );
return 0;
}
|