diff options
Diffstat (limited to 'protocols/Steam/src/steam_messages.cpp')
-rw-r--r-- | protocols/Steam/src/steam_messages.cpp | 75 |
1 files changed, 40 insertions, 35 deletions
diff --git a/protocols/Steam/src/steam_messages.cpp b/protocols/Steam/src/steam_messages.cpp index 563923c919..fc49c7b0e8 100644 --- a/protocols/Steam/src/steam_messages.cpp +++ b/protocols/Steam/src/steam_messages.cpp @@ -1,17 +1,38 @@ #include "stdafx.h"
-//void CSteamProto::SendTypingThread(void *arg)
-//{
-// MCONTACT hContact = (MCONTACT)arg;
-//
-// ptrA token(getStringA("TokenSecret"));
-// ptrA umqId(getStringA("UMQID"));
-// ptrA steamId(getStringA(hContact, "SteamID"));
-//
-// MessageApi::SendResult sendResult;
-// debugLogA("CSteamProto::SendTypingThread: call PollApi::MessageApi::SendMessage");
-// MessageApi::SendTyping(m_hNetlibUser, token, umqId, steamId, &sendResult);
-//}
+struct SendMessageParam
+{
+ MCONTACT hContact;
+ HANDLE hMessage;
+ char *message;
+};
+
+void MessageParamFree(void *arg)
+{
+ SendMessageParam *param = (SendMessageParam*)arg;
+ mir_free(param->message);
+ mir_free(param);
+}
+
+int CSteamProto::OnSendMessage(MCONTACT hContact, const char* message)
+{
+ UINT hMessage = InterlockedIncrement(&hMessageProcess); + + SendMessageParam *param = (SendMessageParam*)mir_calloc(sizeof(SendMessageParam)); + param->hContact = hContact; + param->hMessage = (HANDLE)hMessage; + param->message = mir_strdup(message); + + ptrA token(getStringA("TokenSecret")); + ptrA umqid(getStringA("UMQID")); + ptrA steamId(getStringA(hContact, "SteamID")); + PushRequest( + new SendMessageRequest(token, umqid, steamId, message), + &CSteamProto::OnMessageSent, + param, MessageParamFree); + + return hMessage;
+}
void CSteamProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg)
{
@@ -20,7 +41,7 @@ void CSteamProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg) ptrT error(mir_tstrdup(TranslateT("Unknown error")));
ptrT steamId(getTStringA(param->hContact, "SteamID"));
- if (response != NULL && response->resultCode == HTTP_STATUS_OK)
+ if (response != NULL && response->resultCode == HTTP_CODE_OK)
{
JSONROOT root(response->pData);
JSONNode *node = json_get(root, "error");
@@ -28,29 +49,13 @@ void CSteamProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg) error = json_as_string(node);
}
- int status = ACKRESULT_FAILED;
-
- if (!mir_tstrcmpi(error, _T("OK")))
+ if (mir_tstrcmpi(error, _T("OK")) != 0)
{
- status = ACKRESULT_SUCCESS;
- error = NULL;
+ ptrA errorA(mir_t2a(error));
+ debugLogA("CSteamProto::OnMessageSent: failed to send message for %s (%s)", steamId, errorA);
+ ProtoBroadcastAck(param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hMessage, (LPARAM)errorA);
+ return;
}
- else
- debugLog(_T("CSteamProto::OnMessageSent: failed to send message for %s (%s)"), steamId, error);
-
- ptrA errorA(mir_t2a(error));
-
- ProtoBroadcastAck(
- param->hContact,
- ACKTYPE_MESSAGE,
- status,
- param->hMessage,
- (LPARAM) errorA);
-}
-void CSteamProto::MessageParamFree(void *arg)
-{
- SendMessageParam *param = (SendMessageParam*)arg;
- mir_free(param->message);
- mir_free(param);
+ ProtoBroadcastAck(param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hMessage, 0);
}
\ No newline at end of file |