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
|
/*
Wannabe OSD
This plugin tries to become miranda's standard OSD ;-)
(C) 2005 Andrej Krutak
Distributed under GNU's GPL 2 or later
*/
#include "wbOSD.h"
void logmsg2(char *str)
{
FILE *f=fopen("c:\\logm.txt", "a");
fprintf(f, "%s\n", str);
fclose(f);
}
void showmsgwnd(unsigned int param)
{
logmsg("showmsgwnd");
if (db_get_b(NULL,THIS_MODULE, "showMessageWindow", DEFAULT_SHOWMSGWIN))
CallService(MS_MSG_SENDMESSAGET, (WPARAM)param, 0);
}
LRESULT ShowOSD(TCHAR *str, int timeout, COLORREF color, MCONTACT user)
{
logmsg("ShowOSD");
if (!hwnd)
return 0;
if (timeout==0)
timeout=db_get_dw(NULL,THIS_MODULE, "timeout", DEFAULT_TIMEOUT);
osdmsg om;
om.text=str;
om.timeout=timeout;
om.color=color;
om.param=(unsigned int)user;
om.callback=showmsgwnd;
return SendMessage(hwnd, WM_USER+4, (WPARAM)&om, 0);
}
int ProtoAck(WPARAM,LPARAM lparam)
{
ACKDATA *ack=(ACKDATA *)lparam;
logmsg("ProtoAck");
if (!db_get_b(NULL,THIS_MODULE, "a_user", DEFAULT_ANNOUNCESTATUS))
return 0;
if (!(db_get_dw(NULL,THIS_MODULE,"showWhen", DEFAULT_SHOWWHEN)&(1<<(db_get_w(NULL, "CList", "Status", ID_STATUS_OFFLINE)-ID_STATUS_OFFLINE))))
return 0;
if ( ack->type == ACKTYPE_STATUS ) {
if (!db_get_b(NULL,THIS_MODULE, "showMyStatus", DEFAULT_SHOWMYSTATUS))
return 0;
if ( ack->result == ACKRESULT_SUCCESS && (LPARAM)ack->hProcess != ack->lParam ) {
DWORD ann = db_get_dw( NULL, THIS_MODULE, "announce", DEFAULT_ANNOUNCE );
if ( ann & ( 1 << ( ack->lParam - ID_STATUS_OFFLINE ))) {
TCHAR buffer[512];
mir_sntprintf(buffer, SIZEOF(buffer), TranslateT("%s is %s"), CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ack->hContact, GCDNF_TCHAR), CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION,(WPARAM) ack->lParam,GSMDF_TCHAR));
ShowOSD(buffer, 0, db_get_dw(NULL,THIS_MODULE, "clr_status", DEFAULT_CLRSTATUS), ack->hContact);
} } }
return 0;
}
int ContactSettingChanged(WPARAM wParam,LPARAM lParam)
{
MCONTACT hContact = (MCONTACT) wParam;
DBCONTACTWRITESETTING *cws=(DBCONTACTWRITESETTING*)lParam;
logmsg("ContactSettingChanged1");
if(hContact==NULL || mir_strcmp(cws->szSetting,"Status")) return 0;
WORD newStatus = cws->value.wVal;
WORD oldStatus = DBGetContactSettingRangedWord(hContact,"UserOnline","OldStatus2",ID_STATUS_OFFLINE, ID_STATUS_MIN, ID_STATUS_MAX);
if (oldStatus == newStatus) return 0;
logmsg("ContactSettingChanged2");
db_set_w(hContact,"UserOnline","OldStatus2", newStatus);
if(CallService(MS_IGNORE_ISIGNORED,wParam,IGNOREEVENT_USERONLINE)) return 0;
DWORD dwStatuses = MAKELPARAM(oldStatus, newStatus);
NotifyEventHooks(hHookContactStatusChanged, wParam, (LPARAM)dwStatuses);
return 0;
}
int ContactStatusChanged(WPARAM wParam, LPARAM lParam)
{
MCONTACT hContact = (MCONTACT) wParam;
WORD oldStatus = LOWORD(lParam);
WORD newStatus = HIWORD(lParam);
DWORD ann=db_get_dw(NULL,THIS_MODULE,"announce", DEFAULT_ANNOUNCE);
logmsg("ContactStatusChanged1");
if (!db_get_b(NULL,THIS_MODULE, "a_user", DEFAULT_ANNOUNCESTATUS))
return 0;
if (!(db_get_dw(NULL,THIS_MODULE,"showWhen", DEFAULT_SHOWWHEN)&(1<<(db_get_w(NULL, "CList", "Status", ID_STATUS_OFFLINE)-ID_STATUS_OFFLINE))))
return 0;
if (!(ann&(1<<(newStatus-ID_STATUS_OFFLINE))) )
return 0;
logmsg("ContactStatusChanged2");
if (db_get_b(hContact,"CList","NotOnList",0) || db_get_b(hContact,"CList","Hidden",0) ||
(CallService(MS_IGNORE_ISIGNORED,wParam,IGNOREEVENT_USERONLINE) && newStatus==ID_STATUS_ONLINE)
)
return 0;
TCHAR bufferW[512];
mir_sntprintf(bufferW, SIZEOF(bufferW), TranslateT("%s is %s"), CallService(MS_CLIST_GETCONTACTDISPLAYNAME, wParam, GCDNF_TCHAR), CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION,newStatus,GSMDF_TCHAR));
ShowOSD(bufferW, 0, db_get_dw(NULL,THIS_MODULE, "clr_status", DEFAULT_CLRSTATUS), hContact);
return 0;
}
int HookedNewEvent(WPARAM wParam, LPARAM hDBEvent)
{
logmsg("HookedNewEvent1");
DBEVENTINFO dbe;
dbe.cbSize = sizeof(dbe);
dbe.cbBlob = db_event_getBlobSize(hDBEvent);
if (dbe.cbBlob == -1)
return 0;
dbe.pBlob = (PBYTE) malloc(dbe.cbBlob);
if(db_event_get(hDBEvent,&dbe))
return 0;
if (dbe.flags & DBEF_SENT)
return 0;
if (db_get_b(NULL,THIS_MODULE, "messages", DEFAULT_ANNOUNCEMESSAGES)==0)
return 0;
if (!(db_get_dw(NULL,THIS_MODULE,"showWhen", DEFAULT_SHOWWHEN)&(1<<(db_get_w(NULL, "CList", "Status", ID_STATUS_OFFLINE)-ID_STATUS_OFFLINE))))
return 0;
logmsg("HookedNewEvent2");
TCHAR buf[512];
_tcsncpy(buf, DEFAULT_MESSAGEFORMAT,SIZEOF(buf));
DBVARIANT dbv;
if(!db_get_ts(NULL,THIS_MODULE,"message_format",&dbv)) {
_tcscpy(buf, dbv.ptszVal);
db_free(&dbv);
}
int i1=-1, i2=-1;
TCHAR* pbuf = buf;
while (*pbuf) {
if (*pbuf=='%') {
if (*(pbuf+1)=='n') {
if (i1==-1)
i1=1;
else i2=1;
*(pbuf+1)='s';
} else if (*(pbuf+1)=='m') {
if (i1==-1)
i1=2;
else i2=2;
*(pbuf+1)='s';
} else if (*(pbuf+1)=='l') {
*pbuf=0x0d;
*(pbuf+1)=0x0a;
}
}
pbuf++;
}
TCHAR *c1 = 0, *c2 = 0;
if ( i1 == 1 )
c1 = mir_tstrdup(( TCHAR* )CallService(MS_CLIST_GETCONTACTDISPLAYNAME, wParam, GCDNF_TCHAR));
else if ( i1 == 2 )
c1 = DbGetEventTextT( &dbe, 0 );
if ( i2 == 1 )
c2 = mir_tstrdup(( TCHAR* )CallService(MS_CLIST_GETCONTACTDISPLAYNAME, wParam, GCDNF_TCHAR));
else if ( i2 == 2 )
c2 = DbGetEventTextT( &dbe, 0 );
TCHAR buffer[512];
mir_sntprintf(buffer, SIZEOF(buffer), buf, c1, c2);
ShowOSD(buffer, 0, db_get_dw(NULL,THIS_MODULE, "clr_msg", DEFAULT_CLRMSG), wParam);
mir_free( c1 );
mir_free( c2 );
return 0;
}
|