This repository was archived by the owner on Apr 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup.cpp
256 lines (237 loc) · 8.45 KB
/
group.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
/*
KONNferencja - obs³uga konferencji dla protoko³u Gadu-Gadu
(c)2003 Rafa³ Lindemann / www.stamina.eu.org / www.konnekt.info
Klasa group_base
Kod udostêpniany na licencji GPL, której treœæ powinna byæ dostarczona
razem z tym kodem.
Licensed under GPL.
zmodyfikowane przez skolimê
*/
#include "stdafx.h"
//skolima ADD
#include "skolimaUtilz.h"
//end skolima ADD
#include <konnekt/KONNferencja.h>
#include <konnekt/kAway.h>
#include "konnferencja.h"
void konnfer::createGroupObject(int cnt) {
// Sprawdzamy czy kontakt jest "nasz"
if (GETCNTI(cnt , CNT_NET)!= konnfer::net) return;
std::string uid = GETCNTC(cnt , CNT_UID);
int net;
size_t pos = uid.find_last_of('@');
if (pos == -1) {
net = NET_GG;
} else {
net = atoi(uid.substr(pos+1).c_str());
uid.erase(pos);
}
if (net == NET_GG) {
uin_t uins [100];
int count = 0;
//skolima ADD sortowanie uidów leksykograficzne
char KonnektOwnerUID[10],buff[65000];
sprintf(KonnektOwnerUID,"%d",GETINT(1053));//nasz uid na gadu
sprintf(buff,"%s",uid.c_str());//lista uidów jako char*
uid = cleanupUIDs(buff,KonnektOwnerUID);
sprintf(buff,"%s@%d",uid.c_str(),net);
SETCNTC(cnt , CNT_UID,buff);
ICMessage(IMC_CNT_CHANGED , cnt);
//end skolima ADD
while (uid.size()) {
// atoi sam wczyta numerek tylko do œrednika...
uins[count++] = atoi(uid.c_str());
pos = uid.find(';');
if (pos == -1) uid.clear();
else uid.erase(0 , pos+1);
}
new group_gg(cnt , count , uins);
}
}
void konnfer::destroyGroupObject(int cnt) {
groups_it it = std::find(groups.begin() , groups.end() , cnt);
if (it != groups.end()) {
delete **it;
}
}
int konnfer::getGroupUIDs(string uid , groupItems & items) {
size_t pos;
pos = uid.find_last_of('@');
int net = NET_GG;
if (pos!=-1) {
net = atoi(uid.substr(pos+1).c_str());
uid.erase(pos);
}
items.clear();
while (uid.size()) {
// atoi sam wczyta numerek tylko do œrednika...
pos = uid.find(';');
items.push_back(uid.substr(0,pos));
if (pos == -1) uid.clear();
else uid.erase(0 , pos+1);
}
return net;
}
// group_base ----------------------------------------------------
group_base::group_base() {
// wstawia siê na listê grup
cnt = -1;
groups.push_back(group_holder(this));
IMLOG("group_base() size=%d" , groups.size());
}
group_base::~group_base() {
// usuwa sam siebie z listy grup
_ASSERTE(_CrtCheckMemory());
groups_it it = std::find(groups.begin(), groups.end() , this);
if (it!=groups.end()) groups.erase(it);
_ASSERTE(_CrtCheckMemory());
}
void group_base::receiveMessage(cMessage * m , string from,string senderUID, int basicNet) {
// w m juz siedza prawie wszystkie informacje, teraz trzeba je tylko
// troche uzupelnic i wrzucic do kolejki...
m->flag |= MF_HANDLEDBYUI;// Wiadomoœæ ma zostaæ w pe³ni obs³u¿ona przez interfejs
m->net = konnfer::net;// Ustawiamy sieæ naszej wtyczki...
string uid = this->getUID();
m->fromUid = (char*)uid.c_str();// Ustawiamy te¿ odpowiedni UID
m->toUid = "";
m->type = MT_MESSAGE;// Ca³oœæ wysy³ana jest jako zwyk³a wiadomoœæ
m->notify = Ico::group_msg;
// Jako ¿e wiadomoœæ obs³ugiwana jest przez interfejs, wysy³ana
// jest jako czêœæ zwyk³ej rozmowy. UI w wersji 0.1.18 przyjmuje
// w parametrach dodatkowych MEX_DISPLAY i u¿ywa tego jako
// autora wypowiedzi...
string ext = SetExtParam(m->ext , MEX_DISPLAY , from);
m->ext = (char*)ext.c_str();
//skolima ADD -> ustawienie aktywnoœci
int cnt0 = ICMessage(IMC_FINDCONTACT , basicNet , (int)senderUID.c_str());
if(cnt0 != -1)
{
ICMessage(IMI_CNT_ACTIVITY, cnt0);
ICMessage(IMI_REFRESH_CNT, cnt0);
//end skolima ADD
//skolima ADD - obs³uga ignorowania
//najpierw ignorowanie "indywidualne"
if (ICMessage(IMC_IGN_FIND, basicNet, (int)senderUID.c_str()))
{
//wypada³oby dodaæ j¹ do histori w odpowiednim miejscu
sHISTORYADD olany;
olany.m = m;
olany.dir = "deleted";
olany.name = "ignorowani";
ICMessage(IMI_HISTORY_ADD , (int)&olany);//dodaje do historii
return;
//koñczymy, bo ignorujemy ten kontakt
}
}
//teraz ignorowanie konferencji
int cnt = ICMessage(IMC_FINDCONTACT , konnfer::net , (int)this->getUID().c_str());
ICMessage(IMI_CNT_ACTIVITY, cnt);
ICMessage(IMI_REFRESH_CNT, cnt);
if (ICMessage(IMC_IGN_FIND, konnfer::net , (int)this->getUID().c_str()))
{
//wypada³oby dodaæ j¹ do histori w odpowiednim miejscu
sHISTORYADD olany;
olany.m = m;
olany.dir = "deleted";
olany.name = "ignorowani";
ICMessage(IMI_HISTORY_ADD , (int)&olany);//dodaje do historii
if(GETINT (Cfg::respond))
{
// ustawiamy aktualny czas
__time64_t ltime;
_time64( <ime );
if ( GETCNTI64 ( cnt, Cfg::kontakt_timestamp ) + 30 >= ltime )return;//za wczesnie na odpowiedŸ - antiflood
SETCNTI64 ( cnt, Cfg::kontakt_timestamp, ltime );
string bodyBuff = GETSTR(Cfg::ignore_text,0,0);
char charBuff[10000];
sprintf(charBuff,"%s",GETCNTC( ICMessage(IMC_FINDCONTACT , m->net , (int)m->fromUid) , CNT_DISPLAY));
//replaces
bodyBuff = StringReplace(bodyBuff.c_str(),"{Display}",charBuff);
//replaces done
char bodyBuffchar[10000];
sprintf(bodyBuffchar,"%s",bodyBuff.c_str());
cMessage msg;
msg.flag = MF_SEND;//msg.flag = MF_SEND|MF_HTML;
if(GETINT (Cfg::respond_to_whom)==0)
{//tylko do nadawcy
char buff[32];
sprintf(buff,"%s",senderUID.c_str());
msg.toUid = buff;
msg.net = basicNet;
}
else if(GETINT (Cfg::respond_to_whom)==1)
{//do ca³ej konnferencji
msg.toUid = m->fromUid;
msg.net = m->net;
}
msg.time = m->time;
msg.type = m->type;
msg.body = bodyBuffchar;
sMESSAGESELECT msc;
msc.id = ICMessage ( IMC_NEWMESSAGE , (int) &msg );
if (msc.id) ICMessage ( IMC_MESSAGEQUEUE , (int) &msc );
}
return;
//koñczymy, bo ignorujemy ten kontakt
}
//end skolima ADD
sMESSAGESELECT ms;
ms.id = ICMessage(IMC_NEWMESSAGE , (int)m);
if (ms.id && ms.id != -1)
ICMessage(IMC_MESSAGEQUEUE , (int)&ms);
}
void group_base::createContact(string display , bool onList) {
this->cnt = ICMessage(IMC_CNT_ADD , konnfer::net , (int)this->getUID().c_str());
bool isUnknown = false;//skolima ADD <- this line
bool allUnknown = true;//skolima ADD <- this line
if (display.empty()) {
// Trzeba wykombinowaæ jakiœ display...
groupItems gi;
int net = getGroupUIDs(this->getUID() , gi);
for (groupItems_it it = gi.begin(); it != gi.end(); it++) {
if (!display.empty()) display+=", ";
int cnt = ICMessage(IMC_FINDCONTACT , net , (int)it->c_str());
//skolima OLD was if (cnt != -1)
if (cnt != -1 && strlen(GETCNTC(cnt , CNT_DISPLAY))!=0)
{
display += GETCNTC(cnt , CNT_DISPLAY);
//skolima ADD line
allUnknown = false;
}
else
{
display+=*it;
//skolima ADD
if (cnt ==- 1) isUnknown = true;
if (cnt >- 1) allUnknown = false;
//end skolima ADD
}
}
}
SETCNTC(this->cnt , CNT_DISPLAY , display.c_str());
SETCNTI(this->cnt , CNT_STATUS , ST_OFFLINE | (onList?0:ST_NOTINLIST));
//skolima ADD
if(onList)// -> do aktualnej grupy
SETCNTC(this->cnt,CNT_GROUP,GETSTR(CFG_CURGROUP));
//chcemy, ¿eby konnferencja NIE dostawa³a domyœlnie kAwaya
SETCNTI(this->cnt , kID_OPT_CNT_NOSILENTAWAY , 2);
SETCNTI(this->cnt , kID_OPT_CNT_NOSILENTON , 2);
SETCNTI(this->cnt , kID_OPT_CNT_NOSILENTOFF , 2);
//jeœli user tak ustawi³, domyslnie wrzucamy nowe kontakty jako ignorowane...
if(!onList && GETINT(Cfg::ignore_by_default) == 1) {
if (GETINT(Cfg::ignore_if) == ignoreAlways
|| (GETINT(Cfg::ignore_if) == ignoreIfSome && isUnknown)
|| (GETINT(Cfg::ignore_if) == ignoreIfAll && allUnknown))
{
//ignorujemy....
ICMessage(IMC_IGN_ADD, konnfer::net, (int)this->getUID().c_str());
}
}
//end skolima ADD
ICMessage(IMC_CNT_CHANGED , this->cnt);
}
void group_base::setActive(bool active) {
sIMessage_StatusChange sc(IMC_CNT_SETSTATUS , this->cnt , active?ST_ONLINE:ST_OFFLINE , 0);
Ctrl->IMessage(&sc);
ICMessage(IMI_REFRESH_CNT , this->cnt);
}