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_gg.cpp
212 lines (188 loc) · 7.68 KB
/
group_gg.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
/*
KONNferencja - obs³uga konferencji dla protoko³u Gadu-Gadu
(c)2003 Rafa³ Lindemann / www.stamina.eu.org / www.konnekt.info
Obsluga GaduGadu
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"
#include <konnekt/konnferencja.h>
#include <konnekt/gg.h>
#include "konnferencja.h"
//skolima ADD
#include "skolimaUtilz.h"
//end skolima ADD
// groupContents_gg --------------------------------------------------
void groupContents_gg::set(int count , const uin_t* uins) {
if (this->uins) delete [] this->uins;
this->uins = new uin_t[count];
this->count = count;
for (int i=0; i<count; i++)
this->uins[i] = uins[i];
}
bool groupContents_gg::exists(uin_t uin) {
if (!this->uins) return false;
for (int i=0; i<this->count; i++)
if (this->uins[i] == uin) return true;
return false;
}
void groupContents_gg::add(int count , const uin_t* uins) {
if (!this->uins) {set(count , uins); return;}
uin_t * temp = new uin_t[this->count + count];
// Kopiujemy to co by³o
for (int i=0; i<this->count; i++)
temp[i] = this->uins[i];
delete this->uins;
this->uins = temp;
// Dodajemy nowe, ale tylko jeœli siê nie powtarzaj¹
for (int i=0; i<count; i++)
if (!exists(uins[i]))
this->uins[this->count++] = uins[i];
}
groupContents_gg::~groupContents_gg() {
if (this->uins) delete [] this->uins;
}
// Zwykle porownanie, tyle ze niezaleznie od kolejnosci wystepowania kontaktow
bool groupContents_gg::operator ==(const groupContents_gg & other) const {
if (this->count != other.count) return false;
for (int i=0; i<this->count; i++) {
int j;
for (j=0; j<this->count; j++) {
// Jezeli znajdzie gdzies w srodku, sprawdza nastêpny
if (this->uins[i] == other.uins[j]) break;
}
// Skoro przelecia³ wszystkie i nie znalaz³, znaczy ¿e nie s¹ te same
if (j >= this->count) return false;
}
return true;
}
// group_gg
group_gg::group_gg(int count , const uin_t * uins , string display , bool onList) {
items.set(count , uins);
createContact(display , onList);
if (IMessage(IM_ISCONNECTED , NET_GG , IMT_PROTOCOL))
setActive(true);
}
group_gg::group_gg(int cnt, int count , const uin_t * uins) {
items.set(count , uins);
this->cnt = cnt;
}
bool group_gg::sendMessage(cMessage * m) {
// Pobieramy obiekt sesji z GG
gg_session * sess = (gg_session*) IMessage(IM_GG_GETSESSION , NET_GG , IMT_PROTOCOL);
if (sess) {
int result = -1;
if (m->flag & MF_HTML) {
char format [20000];
sIMessage_GGHtmlFormat hf( true, m->body, format, 20000);
hf.net = NET_GG;
hf.type = IMT_PROTOCOL;
if (IMessage(&hf)) {
result = gg_send_message_confer_richtext(sess, GG_CLASS_CHAT, items.getCount() , (uin_t*)items.getUins(), (unsigned char*) hf.result , (unsigned char*) hf.format , hf.formatSize);
}
}
if (result == -1) {
result = gg_send_message_confer(sess , GG_CLASS_CHAT , items.getCount() , (uin_t*)items.getUins() , (const unsigned char*)m->body);
}
// Zwalniamy obiekt sesji
IMessage(IM_GG_RELEASESESSION , NET_GG , IMT_PROTOCOL);
return result!=-1;
} else return false;
}
bool group_gg::operator==(const groupContents_gg & test) const {
return test == items;
}
string group_gg::getUID() {
if (cnt>0) return GETCNTC(cnt , CNT_UID);
// Skoro jeszcze go nie generowaliœmy, trzeba to zrobiæ po raz pierwszy...
std::stringstream uid;
for (int i=0; i<items.getCount(); i++) {
if (i) uid << ";";
uid << items.getUins()[i];
}
//skolima REMOVE uid << "@10";
//skolima ADD sortowanie uidów leksykograficzne
char KonnektOwnerUID[10],buff[65000];
sprintf(KonnektOwnerUID,"%d",GETINT(1053));//nasz uid na gadu
sprintf(buff,"%s",uid.str().c_str());//lista uidów jako char*
std::string uid_str = cleanupUIDs(buff,KonnektOwnerUID);
uid_str.append("@10");
//end skolima ADD
return uid_str;
}
// ggEvents --------------------------------------------------
int konnfer::handleGGEvent(sIMessage_GGEvent * event) {
switch (event->eventType) {
case GGER_FIRSTLOOP: case GGER_LOGOUT: {
// Ustawiamy statusy konferencji na w³¹czone i wy³¹czone...
bool active = event->eventType == GGER_FIRSTLOOP;
if (active) {
// Skoro siê po³¹czyliœmy, wypada³oby przejrzeæ kolejkê, czy nie ma czegoœ do wys³ania...
ICMessage(IMC_MESSAGEQUEUE , (int)&sMESSAGESELECT(konnfer::net , 0 , MT_MESSAGE , MF_SEND));
}
for (groups_it it=groups.begin(); it!=groups.end(); it++)
if ((*it)->getNet()==NET_GG)
(*it)->setActive(active);
break;}
case GGER_EVENT: {
gg_event * e = event->data.event;
switch (e->type) {
case GG_EVENT_MSG: {
if (e->event.msg.msgclass == GG_CLASS_CTCP
|| !e->event.msg.message
|| !*e->event.msg.message || e->event.msg.recipients_count==0) break;
/* Sprawdzamy, czy mamy grupê na liœcie...
Jeœli nie, tworzymy j¹... Pomijamy w ten sposób
obs³ugê wiadomoœci spoza listy w interfejsie,
która w naszym przypadku, mog³aby nie zadzia³aæ
najlepiej */
// Tworzymy kopiê odbiorców i dorzucamy wysy³aj¹cego do listy
groupContents_gg gc(e->event.msg.recipients_count , e->event.msg.recipients);
gc.add(1 , &e->event.msg.sender);
groups_it it = std::find(groups.begin() , groups.end() , gc);
group_gg * gr;
if (it != groups.end())
gr = static_cast<group_gg*>(**it);
else {
gr = new group_gg(gc.getCount() , gc.getUins() , "" , false);
}
cMessage m;
char * bodyBuff = 0;
m.body = (char*)e->event.msg.message;
if (e->event.msg.formats_length && e->event.msg.formats) {
sIMessage_GGHtmlFormat hf( false, m.body, (char*) e->event.msg.formats, e->event.msg.formats_length);
hf.net = NET_GG;
hf.type = IMT_PROTOCOL;
if (IMessage(&hf)) {
m.flag |= MF_HTML;
bodyBuff = strdup(hf.result);
m.body = bodyBuff;
}
}
// Ustawiamy czas nadejœcia wiadomoœci...
// Je¿eli okno rozmowy jest zamkniête, ustawiamy
// na czas ustawiony w wiadomoœci, chyba ¿e
// na komputerze jest wczeœniejsza godzina...
/*skolima changed - old was
m.time = ICMessage(IMI_MSG_WINDOWSTATE , gr->getCnt())==0?
min(_time64(0) , e->event.msg.time)
:_time64(0)
;
*/
m.time = min(_time64(0) , e->event.msg.time);
char buff [32];
itoa(e->event.msg.sender , buff , 10);
string from = GETCNTC( ICMessage(IMC_FINDCONTACT , NET_GG , (int)buff) , CNT_DISPLAY);
if (from.empty()) from = buff;
gr->receiveMessage(&m , from, buff, NET_GG);//skolima added buff, NET_GG
if (bodyBuff) {
free(bodyBuff);
}
return GGERF_ABORT;}
}
break;}
}
return 0;
}