summaryrefslogtreecommitdiff
path: root/protocols/Steam/src/steam_messages.cpp
diff options
context:
space:
mode:
authoraunsane <aunsane@gmail.com>2017-12-28 21:21:10 +0300
committeraunsane <aunsane@gmail.com>2017-12-28 21:21:28 +0300
commit0156ed41dceeef48f070adf67f14d4ba4c4f6d61 (patch)
treed0e1dca4c2c9c3c056ae9cb69dde10ea59316481 /protocols/Steam/src/steam_messages.cpp
parentf0075f2b956969f29acd3bc9289c8a5f78faddad (diff)
Steam: refactoring
- reworking http requests - added ability to get game name by appid - another attempt to fix #633 - minor refactoring
Diffstat (limited to 'protocols/Steam/src/steam_messages.cpp')
-rw-r--r--protocols/Steam/src/steam_messages.cpp41
1 files changed, 18 insertions, 23 deletions
diff --git a/protocols/Steam/src/steam_messages.cpp b/protocols/Steam/src/steam_messages.cpp
index e5f6665a6f..7374be5208 100644
--- a/protocols/Steam/src/steam_messages.cpp
+++ b/protocols/Steam/src/steam_messages.cpp
@@ -7,14 +7,7 @@ struct SendMessageParam
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)
+int CSteamProto::OnSendMessage(MCONTACT hContact, const char *message)
{
UINT hMessage = InterlockedIncrement(&hMessageProcess);
@@ -29,40 +22,39 @@ int CSteamProto::OnSendMessage(MCONTACT hContact, const char* message)
PushRequest(
new SendMessageRequest(token, umqid, steamId, message),
&CSteamProto::OnMessageSent,
- param, MessageParamFree);
+ param);
return hMessage;
}
-void CSteamProto::OnMessageSent(const HttpResponse *response, void *arg)
+void CSteamProto::OnMessageSent(const HttpResponse &response, void *arg)
{
SendMessageParam *param = (SendMessageParam*)arg;
- ptrW error(mir_wstrdup(TranslateT("Unknown error")));
+ const char *error = Translate("Unknown error");
ptrW steamId(getWStringA(param->hContact, "SteamID"));
time_t timestamp = NULL;
- if (ResponseHttpOk(response))
+ if (response)
{
- JSONROOT root(response->pData);
- JSONNode *node = json_get(root, "error");
- if (node)
- error = json_as_string(node);
+ JSONNode root = JSONNode::parse(response.Content);
+ JSONNode node = root["error"];
+ if (!node.isnull())
+ error = node.as_string().c_str();
- node = json_get(root, "utc_timestamp");
- if (node)
+ node = root["utc_timestamp"];
+ if (!node.isnull())
{
- timestamp = atol(ptrA(mir_u2a(ptrW(json_as_string(node)))));
+ timestamp = atol(node.as_string().c_str());
if (timestamp > getDword("LastMessageTS", 0))
setDword("LastMessageTS", timestamp);
}
}
- if (mir_wstrcmpi(error, L"OK") != 0)
+ if (mir_strcmpi(error, "OK") != 0)
{
- ptrA errorA(mir_u2a(error));
- debugLogA("CSteamProto::OnMessageSent: failed to send message for %s (%s)", steamId, errorA);
- ProtoBroadcastAck(param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hMessage, (LPARAM)errorA);
+ debugLogA(__FUNCTION__ ": failed to send message for %s (%s)", steamId, error);
+ ProtoBroadcastAck(param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hMessage, (LPARAM)error);
}
else
{
@@ -73,6 +65,9 @@ void CSteamProto::OnMessageSent(const HttpResponse *response, void *arg)
ProtoBroadcastAck(param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hMessage, 0);
}
+
+ mir_free(param->message);
+ mir_free(param);
}
int CSteamProto::OnPreCreateMessage(WPARAM, LPARAM lParam)