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
|
#include "headers.h"
int hLangpack;
HINSTANCE hInst;
HANDLE hWindowList;
PLUGININFOEX pluginInfo={
sizeof(PLUGININFOEX),
__PLUGIN_NAME,
PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
__DESCRIPTION,
__AUTHOR,
__AUTHOREMAIL,
__COPYRIGHT,
__AUTHORWEB,
UNICODE_AWARE,
// {A9E9C114-84B9-434B-A3D5-89921D39DDFF}
{0xa9e9c114, 0x84b9, 0x434b, {0xa3, 0xd5, 0x89, 0x92, 0x1d, 0x39, 0xdd, 0xff}}
};
//========================
// WINAPI DllMain
//========================
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
hInst = hinstDLL;
return TRUE;
}
//========================
// MirandaPluginInfo
//========================
extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
{
return &pluginInfo;
}
//===================
// MainInit
//===================
int MainInit(WPARAM wParam, LPARAM lParam)
{
CLISTMENUITEM mi = {0};
mi.cbSize=sizeof(mi);
mi.position=10;
mi.flags=0;
mi.hIcon= LoadIcon(hInst,MAKEINTRESOURCE(IDI_POUNCE));
mi.pszName="&Buddy Pounce";
mi.pszService="BuddyPounce/MenuCommand";
mi.pszContactOwner=NULL;
Menu_AddContactMenuItem(&mi);
return 0;
}
int MsgAck(WPARAM wParam, LPARAM lParam)
{
ACKDATA *ack=(ACKDATA*)lParam;
if (ack && ack->cbSize==sizeof(ACKDATA)
&& ack->type==ACKTYPE_MESSAGE
&& ack->hProcess==(HANDLE)WindowList_Find(hWindowList,ack->hContact))
{
if (DBGetContactSettingByte(NULL, modname, "ShowDeliveryMessages", 1))
CreateMessageAcknowlegedWindow(ack->hContact,ack->result == ACKRESULT_SUCCESS);
if (ack->result == ACKRESULT_SUCCESS)
{
// wrtie it to the DB
DBEVENTINFO dbei = { 0 };
DBVARIANT dbv;
int reuse = DBGetContactSettingByte(ack->hContact,modname, "Reuse", 0);
if (!DBGetContactSettingTString(ack->hContact, modname, "PounceMsg", &dbv) && (dbv.ptszVal[0] != '\0'))
{
char* pszUtf = mir_utf8encodeT(dbv.ptszVal);
dbei.cbSize = sizeof(dbei);
dbei.eventType = EVENTTYPE_MESSAGE;
dbei.flags = DBEF_UTF | DBEF_SENT;
dbei.szModule = (char*)ack->szModule;
dbei.timestamp = time(NULL);
dbei.cbBlob = lstrlenA(pszUtf) + 1;
dbei.pBlob = (PBYTE)pszUtf;
CallService(MS_DB_EVENT_ADD, (WPARAM)ack->hContact, (LPARAM)&dbei);
mir_free(pszUtf);
}
// check to reuse
if (reuse > 1)
DBWriteContactSettingByte(ack->hContact, modname, "Reuse", (BYTE)(reuse-1));
else
{
DBWriteContactSettingByte(ack->hContact,modname, "Reuse", 0);
DBWriteContactSettingTString(ack->hContact, modname, "PounceMsg", _T(""));
}
}
WindowList_Remove(hWindowList,(HWND)ack->hProcess);
}
return 0;
}
int BuddyPounceOptInit(WPARAM wParam, LPARAM lParam)
{
OPTIONSDIALOGPAGE odp = {0};
odp.cbSize = sizeof(odp);
odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR;
odp.hInstance = hInst;
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS);
odp.ptszGroup = LPGENT("Message Sessions");
odp.ptszTitle = LPGENT("Buddy Pounce");
odp.pfnDlgProc = BuddyPounceOptionsDlgProc;
Options_AddPage(wParam, &odp);
return 0;
}
int statusCheck(int statusFlag, int status)
{
if (statusFlag == ANY || !statusFlag) return 1;
switch(status)
{
case ID_STATUS_OFFLINE:
return 0;
case ID_STATUS_ONLINE:
return (statusFlag & ONLINE);
case ID_STATUS_AWAY:
return (statusFlag & AWAY);
case ID_STATUS_NA:
return (statusFlag & NA);
case ID_STATUS_OCCUPIED:
return (statusFlag & OCCUPIED);
case ID_STATUS_DND:
return (statusFlag & DND);
case ID_STATUS_FREECHAT:
return (statusFlag & FFC);
case ID_STATUS_INVISIBLE:
return (statusFlag & INVISIBLE);
case ID_STATUS_OUTTOLUNCH:
return (statusFlag & LUNCH);
case ID_STATUS_ONTHEPHONE:
return (statusFlag & PHONE);
}
return 0;
}
int CheckDate(HANDLE hContact)
{
time_t curtime = time (NULL);
if(!DBGetContactSettingByte(hContact,modname,"GiveUpDays",0))
return 1;
if(DBGetContactSettingByte(hContact,modname,"GiveUpDays",0) && ( abs((time_t)DBGetContactSettingDword(hContact,modname,"GiveUpDate",0)) > curtime))
return 1;
return 0;
}
void SendPounce(TCHAR *text, HANDLE hContact)
{
char* pszUtf = mir_utf8encodeT(text);
if (HANDLE hSendId = (HANDLE)CallContactService(hContact, PSS_MESSAGE, PREF_UTF, (LPARAM)pszUtf))
WindowList_Add(hWindowList, (HWND)hSendId, hContact);
}
int UserOnlineSettingChanged(WPARAM wParam,LPARAM lParam)
{
DBCONTACTWRITESETTING *cws=(DBCONTACTWRITESETTING*)lParam;
char* szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)wParam, 0);
if((HANDLE)wParam == NULL || strcmp(cws->szSetting,"Status")) return 0;
if (szProto && (CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IM))
{
int newStatus = cws->value.wVal;
int oldStatus = DBGetContactSettingWord((HANDLE)wParam,"UserOnline","OldStatus",ID_STATUS_OFFLINE);
if ( ( newStatus != oldStatus ) && ( (HANDLE)wParam != NULL) && ( newStatus != ID_STATUS_OFFLINE) )
{
HANDLE hContact = (HANDLE)wParam;
DBVARIANT dbv;
if (!DBGetContactSettingTString(hContact, modname, "PounceMsg", &dbv) && (dbv.ptszVal[0] != '\0'))
{
// check my status
if (statusCheck(DBGetContactSettingWord(hContact, modname, "SendIfMyStatusIsFLAG", 0), CallProtoService(szProto, PS_GETSTATUS,0,0))
// check the contacts status
&& statusCheck(DBGetContactSettingWord(hContact, modname, "SendIfTheirStatusIsFLAG", 0), newStatus) )
{
// check if we r giving up after x days
if (CheckDate(hContact))
{
if (DBGetContactSettingByte(hContact, modname, "ConfirmTimeout", 0))
{
struct SendPounceDlgProcStruct *spdps = (struct SendPounceDlgProcStruct *)mir_alloc(sizeof(struct SendPounceDlgProcStruct));
TCHAR *message = mir_tstrdup(dbv.ptszVal); // will get free()ed in the send confirm window proc
spdps->hContact = hContact;
spdps->message = message;
CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_CONFIRMSEND), 0, SendPounceDlgProc, (LPARAM)spdps);
// set the confirmation window to send the msg when the timeout is done
mir_free(message);
}
else
SendPounce(dbv.ptszVal, hContact);
}
}
DBFreeVariant(&dbv);
}
}
}
return 0;
}
INT_PTR BuddyPounceMenuCommand(WPARAM wParam, LPARAM lParam)
{
if (DBGetContactSettingByte(NULL, modname, "UseAdvanced", 0) || DBGetContactSettingByte((HANDLE)wParam, modname, "UseAdvanced", 0))
CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_POUNCE),0,BuddyPounceDlgProc, wParam);
else CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_POUNCE_SIMPLE),0,BuddyPounceSimpleDlgProc, wParam);
return 0;
}
INT_PTR AddSimpleMessage(WPARAM wParam, LPARAM lParam)
{
HANDLE hContact = (HANDLE)wParam;
TCHAR* message = (TCHAR*)lParam;
time_t today = time(NULL);
DBWriteContactSettingTString(hContact, modname, "PounceMsg", message);
DBWriteContactSettingWord(hContact, modname, "SendIfMyStatusIsFLAG", (WORD)DBGetContactSettingWord(NULL, modname, "SendIfMyStatusIsFLAG",1));
DBWriteContactSettingWord(hContact, modname, "SendIfTheirStatusIsFLAG", (WORD)DBGetContactSettingWord(NULL, modname, "SendIfTheirStatusIsFLAG",1));
DBWriteContactSettingByte(hContact, modname, "Reuse", (BYTE)DBGetContactSettingByte(NULL, modname, "Reuse",0));
DBWriteContactSettingByte(hContact, modname, "GiveUpDays", (BYTE)DBGetContactSettingByte(NULL, modname, "GiveUpDays",0));
DBWriteContactSettingDword(hContact, modname, "GiveUpDate", (DWORD)(DBGetContactSettingByte(hContact, modname, "GiveUpDays",0)*SECONDSINADAY));
return 0;
}
INT_PTR AddToPounce(WPARAM wParam, LPARAM lParam)
{
HANDLE hContact = (HANDLE)wParam;
TCHAR* message = (TCHAR*)lParam;
DBVARIANT dbv;
if (!DBGetContactSettingTString(hContact, modname, "PounceMsg",&dbv))
{
TCHAR* newPounce = (TCHAR*)mir_alloc(lstrlen(dbv.ptszVal) + lstrlen(message) + 1);
if (!newPounce) return 1;
_tcscpy(newPounce, dbv.ptszVal);
_tcscat(newPounce, message);
DBWriteContactSettingTString(hContact, modname, "PounceMsg", newPounce);
mir_free(newPounce);
DBFreeVariant(&dbv);
}
else AddSimpleMessage((WPARAM)hContact, (LPARAM)message);
return 0;
}
//===========================
// Load (hook ModulesLoaded)
//===========================
extern "C" __declspec(dllexport) int Load(void)
{
mir_getLP(&pluginInfo);
HookEvent(ME_SYSTEM_MODULESLOADED, MainInit);
HookEvent(ME_DB_CONTACT_SETTINGCHANGED, UserOnlineSettingChanged);
HookEvent(ME_OPT_INITIALISE, BuddyPounceOptInit);
HookEvent(ME_PROTO_ACK, MsgAck);
CreateServiceFunction("BuddyPounce/MenuCommand", BuddyPounceMenuCommand);
hWindowList = (HANDLE)CallService(MS_UTILS_ALLOCWINDOWLIST, 0, 0);
/* service funcitons for other devs... */
CreateServiceFunction("BuddyPounce/AddSimplePounce", AddSimpleMessage); // add a simple pounce to a contact
CreateServiceFunction("BuddyPounce/AddToPounce", AddToPounce); // add to the exsisitng pounce, if there isnt 1 then add a new simple pounce.
/* ******************************************************** */
return 0;
}
extern "C" __declspec(dllexport) int Unload(void)
{
return 0;
}
|