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
|
#include "skype_proto.h"
int CSkypeProto::OnModulesLoaded(WPARAM, LPARAM)
{
this->InitChat();
this->HookEvent(ME_OPT_INITIALISE, &CSkypeProto::OnOptionsInit);
this->HookEvent(ME_USERINFO_INITIALISE, &CSkypeProto::OnUserInfoInit);
this->login = ::DBGetString(NULL, this->m_szModuleName, "sid");
this->rememberPassword = this->GetSettingByte("RememberPassword") > 0;
return 0;
}
int CSkypeProto::OnPreShutdown(WPARAM, LPARAM)
{
this->SetStatus(ID_STATUS_OFFLINE);
return 0;
}
int CSkypeProto::OnContactDeleted(WPARAM wParam, LPARAM lParam)
{
HANDLE hContact = (HANDLE)wParam;
if (hContact && this->IsOnline())
{
if (this->IsChatRoom(hContact))
{
char *chatID = ::DBGetString(hContact, this->m_szModuleName, "ChatRoomID");
this->LeaveChat(chatID);
CConversation::Ref conversation;
g_skype->GetConversationByIdentity(chatID, conversation);
conversation->Delete();
}
else
this->RevokeAuth(wParam, lParam);
}
return 0;
}
void CSkypeProto::OnMessageSended(CConversation::Ref conversation, CMessage::Ref message)
{
SEString data;
uint timestamp;
message->GetPropTimestamp(timestamp);
message->GetPropAuthor(data);
char *sid = ::mir_strdup((const char*)data);
message->GetPropBodyXml(data);
char *text = ::mir_utf8decodeA((const char*)data);
CConversation::TYPE type;
conversation->GetPropType(type);
if (type == CConversation::DIALOG)
{
CParticipant::Refs participants;
conversation->GetParticipants(participants, CConversation::OTHER_CONSUMERS);
for (uint i = 0; i < participants.size(); i ++)
{
participants[i]->GetPropIdentity(data);
char *contactSid = ::mir_strdup((const char *)data);
//todo: get nickname
this->RaiseMessageSendedEvent(
timestamp,
contactSid,
contactSid,
text);
}
}
else
{
conversation->GetPropIdentity(data);
char *cid = ::mir_strdup((const char*)data);
/*HANDLE hContact = this->GetChatRoomByID(cid);
if ( !hContact || ::DBGetContactSettingWord(hContact, this->m_szModuleName, "Status", ID_STATUS_OFFLINE) == ID_STATUS_OFFLINE)
{
this->JoinChat(cid);
}*/
this->SendChatMessage(cid, sid, text);
::mir_free(cid);
}
}
void CSkypeProto::OnMessageReceived(CConversation::Ref conversation, CMessage::Ref message)
{
SEString data;
uint timestamp;
message->GetPropTimestamp(timestamp);
message->GetPropAuthor(data);
char *sid = ::mir_strdup((const char*)data);
message->GetPropBodyXml(data);
char *text = ::mir_utf8decodeA((const char*)data);
CConversation::TYPE type;
conversation->GetPropType(type);
if (type == CConversation::DIALOG)
{
message->GetPropAuthorDisplayname(data);
char *nick = ::mir_utf8encode((const char*)data);
this->RaiseMessageReceivedEvent(
(DWORD)timestamp,
sid,
nick,
text);
}
else
{
conversation->GetPropIdentity(data);
char *cid = ::mir_strdup((const char*)data);
/*HANDLE hContact = this->GetChatRoomByID(cid);
if ( !hContact || ::DBGetContactSettingWord(hContact, this->m_szModuleName, "Status", ID_STATUS_OFFLINE) == ID_STATUS_OFFLINE)
{
this->JoinChat(cid);
}*/
this->SendChatMessage(cid, sid, text);
::mir_free(cid);
}
/*const char *msg = (const char*)propValues[2];
int len = ::strlen(msg) + 8;
wchar_t *xml = new wchar_t[len];
::mir_sntprintf(xml, len, L"<m>%s</m>", ::mir_utf8decodeW(msg));
int bytesProcessed = 0;
HXML hXml = xi.parseString(xml, &bytesProcessed, NULL);*/
}
void CSkypeProto::OnMessage(CConversation::Ref conversation, CMessage::Ref message)
{
CMessage::TYPE messageType;
message->GetPropType(messageType);
CMessage::SENDING_STATUS sendingStatus;
message->GetPropSendingStatus(sendingStatus);
switch (messageType)
{
case CMessage::POSTED_EMOTE:
case CMessage::POSTED_TEXT:
if (sendingStatus == CMessage::SENT)
this->OnMessageSended(conversation, message);
else if (!sendingStatus)
this->OnMessageReceived(conversation, message);
break;
case CMessage::ADDED_CONSUMERS:
{
SEString data;
conversation->GetPropIdentity(data);
char *cid = ::mir_strdup(data);
HANDLE hContact = this->GetChatRoomByID(cid);
if ( !hContact || ::DBGetContactSettingWord(hContact, this->m_szModuleName, "Status", ID_STATUS_OFFLINE) == ID_STATUS_OFFLINE)
{
this->StartChat(cid);
CParticipant::Refs participants;
conversation->GetParticipants(participants, CConversation::OTHER_CONSUMERS);
for (uint i = 0; i < participants.size(); i++)
{
participants[i]->GetPropIdentity(data);
this->AddChatContact(cid, data);
}
}
{
message->GetPropIdentities(data);
StringList alreadyInChat(this->GetChatUsers(cid), " ");
StringList needToAdd(data, " ");
for (int i = 0; i < needToAdd.getCount(); i++)
{
char *sid = needToAdd[i];
if (::stricmp(sid, this->login) != 0 && !alreadyInChat.contains(sid))
this->AddChatContact(cid, sid);
}
}
}
break;
case CMessage::RETIRED:
{
SEString data;
conversation->GetPropIdentity(data);
char *cid = ::mir_strdup(data);
StringList alreadyInChat(this->GetChatUsers(cid), " ");
message->GetPropAuthor(data);
char *sid = ::mir_strdup(data);
if (::stricmp(sid, this->login) != 0 && alreadyInChat.contains(sid))
this->RemoveChatContact(cid, sid);
}
break;
case CMessage::RETIRED_OTHERS:
{
SEString data;
conversation->GetPropIdentity(data);
char *cid = ::mir_strdup(data);
message->GetPropIdentities(data);
StringList alreadyInChat(this->GetChatUsers(cid), " ");
StringList needToKick(data, " ");
for (int i = 0; i < needToKick.getCount(); i++)
{
char *sid = needToKick[i];
if (::stricmp(sid, this->login) != 0 && !alreadyInChat.contains(sid))
this->KickChatContact(cid, sid);
}
}
break;
case CMessage::SPAWNED_CONFERENCE:
{
SEString data;
conversation->GetPropIdentity(data);
char *cid = ::mir_strdup(data);
/*HANDLE hContact = this->GetChatRoomByID(cid);
if ( !hContact || ::DBGetContactSettingWord(hContact, this->m_szModuleName, "Status", ID_STATUS_OFFLINE) == ID_STATUS_OFFLINE)
{
this->JoinChat(cid);
}*/
}
break;
//case CMessage::REQUESTED_AUTH:
// break;
//case CMessage::GRANTED_AUTH:
// break;
//case CMessage::BLOCKED:
// break;
}
}
|