diff options
Diffstat (limited to 'protocols/Tox/src')
-rw-r--r-- | protocols/Tox/src/tox_contacts.cpp | 7 | ||||
-rw-r--r-- | protocols/Tox/src/tox_events.cpp | 20 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.cpp | 11 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.h | 7 | ||||
-rw-r--r-- | protocols/Tox/src/tox_utils.cpp | 13 |
5 files changed, 49 insertions, 9 deletions
diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp index ddd880b631..7249bc47ab 100644 --- a/protocols/Tox/src/tox_contacts.cpp +++ b/protocols/Tox/src/tox_contacts.cpp @@ -5,7 +5,7 @@ bool CToxProto::IsProtoContact(MCONTACT hContact) return ::lstrcmpiA(::GetContactProto(hContact), m_szModuleName) == 0;
}
-MCONTACT CToxProto::GetContactByClientId(const char *clientId)
+MCONTACT CToxProto::FindContact(const char *clientId)
{
MCONTACT hContact = NULL;
@@ -25,7 +25,7 @@ MCONTACT CToxProto::GetContactByClientId(const char *clientId) MCONTACT CToxProto::AddContact(const char *clientId, const char *nick, bool isHidden)
{
- MCONTACT hContact = GetContactByClientId(clientId);
+ MCONTACT hContact = FindContact(clientId);
if (!hContact)
{
hContact = (MCONTACT)::CallService(MS_DB_CONTACT_ADD, 0, 0);
@@ -58,10 +58,11 @@ void CToxProto::LoadContactList() {
tox_get_client_id(tox, friends[i], &clientId[0]);
std::string toxId = DataToHexString(clientId);
+
tox_get_name(tox, friends[i], &username[0]);
std::string nick(username.begin(), username.end());
- AddContact(toxId.c_str(), nick.c_str());
+ MCONTACT hContact = AddContact(toxId.c_str(), nick.c_str());
}
}
}
diff --git a/protocols/Tox/src/tox_events.cpp b/protocols/Tox/src/tox_events.cpp index 45060ab170..28f2983a4d 100644 --- a/protocols/Tox/src/tox_events.cpp +++ b/protocols/Tox/src/tox_events.cpp @@ -44,8 +44,24 @@ void CToxProto::OnFriendRequest(Tox *tox, const uint8_t *userId, const uint8_t * {
}
-void CToxProto::OnFriendMessage(Tox *tox, const int friendId, const uint8_t *message, const uint16_t messageSize, void *arg)
+void CToxProto::OnFriendMessage(Tox *tox, const int friendnumber, const uint8_t *message, const uint16_t messageSize, void *arg)
{
+ CToxProto *proto = (CToxProto*)arg;
+
+ std::vector<uint8_t> clientId(TOX_CLIENT_ID_SIZE);
+ tox_get_client_id(tox, friendnumber, &clientId[0]);
+ std::string toxId = proto->DataToHexString(clientId);
+
+ MCONTACT hContact = proto->FindContact(toxId.c_str());
+ if (hContact)
+ {
+ PROTORECVEVENT recv = { 0 };
+ recv.flags = PREF_UTF;
+ recv.timestamp = time(NULL);
+ recv.szMessage = mir_strdup((char*)message);
+
+ ProtoChainRecvMsg(hContact, &recv);
+ }
}
void CToxProto::OnFriendNameChange(Tox *tox, const int friendId, const uint8_t *name, const uint16_t nameSize, void *arg)
@@ -76,7 +92,7 @@ void CToxProto::OnReadReceipt(Tox *tox, int32_t friendnumber, uint32_t receipt, tox_get_client_id(tox, friendnumber, &clientId[0]);
std::string toxId = proto->DataToHexString(clientId);
- MCONTACT hContact = proto->GetContactByClientId(toxId.c_str());
+ MCONTACT hContact = proto->FindContact(toxId.c_str());
proto->ProtoBroadcastAck(
hContact,
diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp index e2734d8aca..676039ce76 100644 --- a/protocols/Tox/src/tox_proto.cpp +++ b/protocols/Tox/src/tox_proto.cpp @@ -21,6 +21,8 @@ CToxProto::CToxProto(const char* protoName, const TCHAR* userName) : tox_callback_connection_status(tox, OnConnectionStatusChanged, this);
CreateProtoService(PS_CREATEACCMGRUI, &CToxProto::OnAccountManagerInit);
+
+ hMessageProcess = 1;
}
CToxProto::~CToxProto()
@@ -93,7 +95,10 @@ HWND __cdecl CToxProto::CreateExtendedSearchUI(HWND owner) { return 0; } int __cdecl CToxProto::RecvContacts(MCONTACT hContact, PROTORECVEVENT*) { return 0; }
int __cdecl CToxProto::RecvFile(MCONTACT hContact, PROTOFILEEVENT*) { return 0; }
-int __cdecl CToxProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT*) { return 0; }
+int __cdecl CToxProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT *pre)
+{
+ return (INT_PTR)AddDbEvent(hContact, EVENTTYPE_MESSAGE, pre->timestamp, DBEF_UTF, lstrlenA(pre->szMessage), (BYTE*)pre->szMessage);
+}
int __cdecl CToxProto::RecvUrl(MCONTACT hContact, PROTORECVEVENT*) { return 0; }
int __cdecl CToxProto::SendContacts(MCONTACT hContact, int flags, int nContacts, MCONTACT* hContactsList) { return 0; }
@@ -111,7 +116,9 @@ int __cdecl CToxProto::SendMsg(MCONTACT hContact, int flags, const char* msg) uint32_t number = tox_get_friend_number(tox, clientId.data());
- int messageId = tox_send_message(tox, number, (uint8_t*)msg, strlen(msg));
+ ULONG messageId = InterlockedIncrement(&hMessageProcess);
+
+ tox_send_message_withid(tox, number, messageId, (uint8_t*)msg, strlen(msg));
return messageId;
}
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index 81ee596e7f..f443528421 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -77,6 +77,7 @@ private: HANDLE poolingThread;
bool isTerminated;
bool isConnected;
+ ULONG hMessageProcess;
// instances
static LIST<CToxProto> instanceList;
@@ -97,7 +98,7 @@ private: static int __cdecl OnOptionsInit(void *obj, WPARAM wParam, LPARAM lParam);
static void OnFriendRequest(Tox *tox, const uint8_t *userId, const uint8_t *message, const uint16_t messageSize, void *arg);
- static void OnFriendMessage(Tox *tox, const int friendId, const uint8_t *message, const uint16_t messageSize, void *arg);
+ static void OnFriendMessage(Tox *tox, const int friendnumber, const uint8_t *message, const uint16_t messageSize, void *arg);
static void OnFriendNameChange(Tox *tox, const int friendId, const uint8_t *name, const uint16_t nameSize, void *arg);
static void OnStatusMessageChanged(Tox *tox, const int friendId, const uint8_t* message, const uint16_t messageSize, void *arg);
static void OnUserStatusChanged(Tox *tox, int32_t friendnumber, uint8_t TOX_USERSTATUS, void *userdata);
@@ -107,7 +108,7 @@ private: // contacts
bool IsProtoContact(MCONTACT hContact);
- MCONTACT GetContactByClientId(const char *clientId);
+ MCONTACT FindContact(const char *clientId);
MCONTACT AddContact(const char *clientId, const char *nick, bool isHidden = false);
void LoadContactList();
@@ -120,6 +121,8 @@ private: // utils
TOX_USERSTATUS MirandaToToxStatus(int status);
+
+ HANDLE AddDbEvent(MCONTACT hContact, WORD type, DWORD timestamp, DWORD flags, DWORD cbBlob, PBYTE pBlob);
std::vector<uint8_t> HexStringToData(std::string hex);
std::string DataToHexString(std::vector<uint8_t>);
diff --git a/protocols/Tox/src/tox_utils.cpp b/protocols/Tox/src/tox_utils.cpp index b8eed67c68..bd26d9136b 100644 --- a/protocols/Tox/src/tox_utils.cpp +++ b/protocols/Tox/src/tox_utils.cpp @@ -21,6 +21,19 @@ TOX_USERSTATUS CToxProto::MirandaToToxStatus(int status) return userstatus;
}
+HANDLE CToxProto::AddDbEvent(MCONTACT hContact, WORD type, DWORD timestamp, DWORD flags, DWORD cbBlob, PBYTE pBlob)
+{
+ DBEVENTINFO dbei = { sizeof(dbei) };
+ dbei.szModule = m_szModuleName;
+ dbei.timestamp = timestamp;
+ dbei.eventType = type;
+ dbei.cbBlob = cbBlob;
+ dbei.pBlob = pBlob;
+ dbei.flags = flags;
+
+ return db_event_add(hContact, &dbei);
+}
+
std::vector<uint8_t> CToxProto::HexStringToData(std::string hex)
{
std::stringstream ss;
|