summaryrefslogtreecommitdiff
path: root/protocols/Xfire/src/all_statusmsg.cpp
blob: 70635078799edf015d47eee9d6960eb370223647 (plain)
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
//beinhaltet funktionen zum setzen des status wenn man ingame ist

#include "stdafx.h"
#include "baseProtocol.h"
#include "m_variables.h"
#include "Xfire_gamelist.h"

extern Xfire_gamelist xgamelist;


#include <vector>

using namespace std;

#include "xdebug.h"

//vector beinhaltet statusmessages
vector<string> *olstatusmsg=NULL;
vector<string> *protoname=NULL;
vector<unsigned int> *olstatus=NULL;
vector<unsigned int> *oltostatus=NULL;
PROTOACCOUNT **temp;
int anz,statusid;
int statustype;

BOOL BackupStatusMsg() {
	DBVARIANT dbv;

	statustype=DBGetContactSettingByte(NULL,protocolname,"statuschgtype",0);

	XFireLog("Backup Status Message ...");

	//alten vector löschen
	if(olstatusmsg!=NULL)
	{
		delete olstatusmsg;
		olstatusmsg=NULL;
	}
	if(protoname!=NULL)
	{
		delete protoname;
		protoname=NULL;
	}
	if(olstatus!=NULL)
	{
		delete olstatus;
		olstatus=NULL;
	}
	if(oltostatus!=NULL)
	{
		delete oltostatus;
		oltostatus=NULL;
	}
	olstatusmsg=new vector<string>;
	protoname=new vector<string>;
	olstatus=new vector<unsigned int>;
	oltostatus=new vector<unsigned int>;

	//alle protokolle durchgehen und den status in den vector sichern
	CallService(MS_PROTO_ENUMACCOUNTS,(WPARAM)&anz,(LPARAM)&temp);
	for(int i=0;i<anz;i++)
	{
		statusid=CallProtoService(temp[i]->szModuleName,PS_GETSTATUS,0,0);
		XFireLog("Get Status of %s ...",temp[i]->szModuleName);

		char ttemp[128]="";
		sprintf_s(ttemp,128,"%s%s",temp[i]->szModuleName,PS_SETAWAYMSG);

		//xfire wird geskipped, offline prots und invs prots auch, und locked status prots auch
		if(!temp[i]->bIsEnabled||statusid==ID_STATUS_INVISIBLE||statusid==ID_STATUS_OFFLINE||!lstrcmpiA( temp[i]->szModuleName, protocolname )||!ServiceExists(ttemp)||DBGetContactSettingByte(NULL,temp[i]->szModuleName,"LockMainStatus",0)==1)
		{
			XFireLog("-> Skip %s.",temp[i]->szModuleName);

			olstatus->push_back(-1);
			olstatusmsg->push_back("");
			if(statustype) oltostatus->push_back(-1);
			protoname->push_back("");
			continue;
		}

		int dummystatusid=statusid;

		if(statustype)
		{
			if(statusid!=0)
			{
				int caps=CallProtoService(temp[i]->szModuleName,PS_GETCAPS,PFLAGNUM_2,0);

				//normale statusreihenfolge
				if(DBGetContactSettingByte(NULL,protocolname,"dndfirst",0)==0)
				{
					if(caps&PF2_LIGHTDND)
					{
						oltostatus->push_back(ID_STATUS_OCCUPIED);
						dummystatusid=ID_STATUS_OCCUPIED;
						XFireLog("%s supports OCCUPIED.",temp[i]->szModuleName);
					}
					else if(caps&PF2_HEAVYDND)
					{
						oltostatus->push_back(ID_STATUS_DND);
						dummystatusid=ID_STATUS_DND;
						XFireLog("%s supports DND.",temp[i]->szModuleName);
					}
					else if(caps&PF2_SHORTAWAY)
					{
						oltostatus->push_back(ID_STATUS_AWAY);
						dummystatusid=ID_STATUS_AWAY;
						XFireLog("%s supports AWAY.",temp[i]->szModuleName);
					}
					else
					{
						XFireLog("%s no Away???.",temp[i]->szModuleName);
						oltostatus->push_back(statusid);
						dummystatusid=statusid;
					}
				}
				else //dnd bevorzugt
				{
					if(caps&PF2_HEAVYDND)
					{
						oltostatus->push_back(ID_STATUS_DND);
						dummystatusid=ID_STATUS_DND;
						XFireLog("%s supports DND.",temp[i]->szModuleName);
					}
					else if(caps&PF2_LIGHTDND)
					{
						oltostatus->push_back(ID_STATUS_OCCUPIED);
						dummystatusid=ID_STATUS_OCCUPIED;
						XFireLog("%s supports OCCUPIED.",temp[i]->szModuleName);
					}
					else if(caps&PF2_SHORTAWAY)
					{
						oltostatus->push_back(ID_STATUS_AWAY);
						dummystatusid=ID_STATUS_AWAY;
						XFireLog("%s supports AWAY.",temp[i]->szModuleName);
					}
					else
					{
						XFireLog("%s no Away???.",temp[i]->szModuleName);
						oltostatus->push_back(statusid);
						dummystatusid=statusid;
					}
				}
			}
			else
				oltostatus->push_back(-1);
		}

		switch(statusid)
		{
		case ID_STATUS_ONLINE:
			if(DBGetContactSetting(NULL,"SRAway","OnMsg",&dbv))
				olstatusmsg->push_back(Translate("Yep, I'm here."));
			break;
		case ID_STATUS_AWAY:
			if(DBGetContactSetting(NULL,"SRAway","AwayMsg",&dbv))
				olstatusmsg->push_back(Translate("I've been away since %time%."));
			break;
		case ID_STATUS_NA:
			if(DBGetContactSetting(NULL,"SRAway","NaMsg",&dbv))
				olstatusmsg->push_back(Translate("Give it up, I'm not in!"));
			break;
		case ID_STATUS_OCCUPIED:
			if(DBGetContactSetting(NULL,"SRAway","OccupiedMsg",&dbv))
				olstatusmsg->push_back(Translate("Not right now."));
			break;
		case ID_STATUS_DND:
			if(DBGetContactSetting(NULL,"SRAway","DndMsg",&dbv))
				olstatusmsg->push_back(Translate("Give a guy some peace, would ya?"));
			break;
		case ID_STATUS_FREECHAT:
			if(DBGetContactSetting(NULL,"SRAway","FreeChatMsg",&dbv))
				olstatusmsg->push_back(Translate("Well, I would talk to you if Miranda ICQ supported chat"));
			break;
		case ID_STATUS_ONTHEPHONE:
			if(DBGetContactSetting(NULL,"SRAway","OtpMsg",&dbv))
				olstatusmsg->push_back(Translate("That'll be the phone."));
			break;
		case ID_STATUS_OUTTOLUNCH:
			if(DBGetContactSetting(NULL,"SRAway","OtlMsg",&dbv))
				olstatusmsg->push_back(Translate("Mmm...food."));
			break;
		default:
			//nix zumachn, kenn den status nicht
			olstatus->push_back(-1);
			olstatusmsg->push_back("");
			protoname->push_back("");
			continue;
		}

		//ab in den vector
		olstatus->push_back(statusid);
		if(olstatus->size()>olstatusmsg->size())
		{
			olstatusmsg->push_back(string(dbv.pszVal));
			protoname->push_back(temp[i]->szModuleName);
			//freigeben
			DBFreeVariant(&dbv);
		}
		else
			protoname->push_back(temp[i]->szModuleName);
	}

	return TRUE;
}

BOOL SetGameStatusMsg()
{
	char* statusmsg=NULL;

	//prüfe ob vector leer
	if(olstatusmsg==NULL)
		return FALSE;

	//zusetzende statusmsg erstellen
	if (ServiceExists(MS_VARS_FORMATSTRING))
	{
		DBVARIANT dbv;
		if(!DBGetContactSetting(NULL,protocolname,"setstatusmsg",&dbv)) {
			//direkte funktionen verwenden
			statusmsg = variables_parse(dbv.pszVal,NULL,0);
			if (statusmsg == NULL)
			{
				DBFreeVariant(&dbv);
				return FALSE;
			}

			DBFreeVariant(&dbv);
		}
	}
	else
	{
		//alternativ zweig ohne variables
		DBVARIANT dbv;
		if(!DBGetContactSetting(NULL,protocolname,"setstatusmsg",&dbv)) {

			DBVARIANT dbv3;

			//statusmsg rein
			xgamelist.setString(dbv.pszVal,&statusmsg);

			//mit den vars ersetzen beginnen

			//derzeitiges spiel
			if(!DBGetContactSetting(NULL,protocolname, "currentgamename",&dbv3))
			{
				xgamelist.strreplace("%myxfiregame%",dbv3.pszVal,&statusmsg);
				DBFreeVariant(&dbv3);
			}
			else
				xgamelist.strreplace("%myxfiregame%","",&statusmsg);

			//derzeitiges voiceprogram
			if(!DBGetContactSetting(NULL,protocolname, "currentvoicename",&dbv3))
			{
				xgamelist.strreplace("%myxfirevoice%",dbv3.pszVal,&statusmsg);
				DBFreeVariant(&dbv3);
			}
			else
				xgamelist.strreplace("%myxfirevoice%","",&statusmsg);

			//derzeitige voiceip
			if(!DBGetContactSetting(NULL,protocolname, "VServerIP",&dbv3))
			{
				xgamelist.strreplace("%myxfirevoiceip%",dbv3.pszVal,&statusmsg);
				DBFreeVariant(&dbv3);
			}
			else
				xgamelist.strreplace("%myxfirevoiceip%","",&statusmsg);

			//derzeitige gameip
			if(!DBGetContactSetting(NULL,protocolname, "ServerIP",&dbv3))
			{
				xgamelist.strreplace("%myxfireserverip%",dbv3.pszVal,&statusmsg);
				DBFreeVariant(&dbv3);
			}
			else
				xgamelist.strreplace("%myxfireserverip%","",&statusmsg);

		}
	}

	CallService(MS_PROTO_ENUMACCOUNTS,(WPARAM)&anz,(LPARAM)&temp);
	for(int i=0;i<anz;i++)
	{
		if(olstatus->at(i)!=-1)
		{
			if(statustype)
			{
				//newawaysys
				if(ServiceExists("NewAwaySystem/SetStateA"))
				{
					XFireLog("-> SetStatusMsg of %s with NewAwaySystem/SetStateA.",protoname->at(i).c_str());

					NAS_PROTOINFO npi = {0};
					npi.cbSize=sizeof(NAS_PROTOINFO);
					npi.szProto=(char*)protoname->at(i).c_str();
					npi.status=oltostatus->at(i);
					npi.szMsg=mir_strdup(statusmsg);
					CallService("NewAwaySystem/SetStateA", (WPARAM)&npi, (LPARAM)1);
				}
				else if(ServiceExists("NewAwaySystem/SetStateW")) {
					XFireLog("-> SetStatusMsg of %s with NewAwaySystem/SetStateW.",protoname->at(i).c_str());

					NAS_PROTOINFO npi = {0};
					npi.cbSize=sizeof(NAS_PROTOINFO);
					npi.szProto=(char*)protoname->at(i).c_str();
					npi.status=oltostatus->at(i);
					npi.szMsg=mir_strdup(statusmsg);
					CallService("NewAwaySystem/SetStateW", (WPARAM)&npi, (LPARAM)1);
				}
				else
				{
					XFireLog("-> SetStatusMsg of %s with Miranda with occupied status.",protoname->at(i).c_str());

					//statusmsg für beschäftigt setzen
					CallProtoService(temp[i]->szModuleName,PS_SETAWAYMSG,oltostatus->at(i),(LPARAM)statusmsg);
					//status auf beschäftigt wechseln
					CallProtoService(temp[i]->szModuleName,PS_SETSTATUS,oltostatus->at(i),0);
					//statusmsg für beschäftigt setzen
					if(CallProtoService(temp[i]->szModuleName,PS_GETSTATUS,0,0)!=oltostatus->at(i))
					{
						XFireLog("Set StatusMsg again, Status was not succesfully set.");
						CallProtoService(temp[i]->szModuleName,PS_SETAWAYMSG,oltostatus->at(i),(LPARAM)statusmsg);
					}
				}
			}
			else
			{
				XFireLog("-> SetStatusMsg of %s.",protoname->at(i).c_str());

				CallProtoService(temp[i]->szModuleName,PS_SETAWAYMSG,olstatus->at(i),(LPARAM)statusmsg);
			}
		}
	}

	if (ServiceExists(MS_VARS_FORMATSTRING))
		mir_free(statusmsg);
	else
		if(statusmsg) delete[] statusmsg;

	return TRUE;
}

BOOL SetOldStatusMsg()
{
	//prüfe ob vector leer
	if(olstatusmsg==NULL)
		return FALSE;

	CallService(MS_PROTO_ENUMACCOUNTS,(WPARAM)&anz,(LPARAM)&temp);
	for(int i=0;i<anz;i++)
	{
		if(olstatus->at(i)!=-1)
		{
			if(statustype)
			{
				//alten status setzen
				CallProtoService(temp[i]->szModuleName,PS_SETSTATUS,olstatus->at(i),0);
				//status wurde nicht gewechselt, dann statusmsg nachträglich setzen
				if(CallProtoService(temp[i]->szModuleName,PS_GETSTATUS,0,0)!=olstatus->at(i))
					CallProtoService(temp[i]->szModuleName,PS_SETAWAYMSG,olstatus->at(i),(LPARAM)olstatusmsg->at(i).c_str());
			}
			else
			{
				CallProtoService(temp[i]->szModuleName,PS_SETSTATUS,olstatus->at(i),0);
				CallProtoService(temp[i]->szModuleName,PS_SETAWAYMSG,olstatus->at(i),(LPARAM)olstatusmsg->at(i).c_str());
			}
		}
	}

	//alten vector löschen
	if(protoname!=NULL)
	{
		delete protoname;
		protoname=NULL;
	}
	if(olstatusmsg!=NULL)
	{
		delete olstatusmsg;
		olstatusmsg=NULL;
	}
	if(olstatus!=NULL)
	{
		delete olstatus;
		olstatus=NULL;
	}
	if(oltostatus!=NULL)
	{
		delete olstatus;
		olstatus=NULL;
	}

	return TRUE;
}