summaryrefslogtreecommitdiff
path: root/protocols/Steam/src/steam_proto.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-05-26 19:15:20 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-05-26 19:15:20 +0000
commitab75f8e4a3968c956425844415237a4fa6fcee63 (patch)
treedf2c209dd0197dc3085546606b0581d63f9114ad /protocols/Steam/src/steam_proto.cpp
parent4e9e885747b2037c81ce809f7f6505f8bc8b0e2f (diff)
Steam: merge new api
git-svn-id: http://svn.miranda-ng.org/main/trunk@13850 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Steam/src/steam_proto.cpp')
-rw-r--r--protocols/Steam/src/steam_proto.cpp113
1 files changed, 62 insertions, 51 deletions
diff --git a/protocols/Steam/src/steam_proto.cpp b/protocols/Steam/src/steam_proto.cpp
index 2844492aa6..af5a3e677f 100644
--- a/protocols/Steam/src/steam_proto.cpp
+++ b/protocols/Steam/src/steam_proto.cpp
@@ -3,13 +3,10 @@
CSteamProto::CSteamProto(const char* protoName, const TCHAR* userName) :
PROTO<CSteamProto>(protoName, userName),
hAuthProcess(1),
- hMessageProcess(1),
- requestsQueue(1)
+ hMessageProcess(1)
{
CreateProtoService(PS_CREATEACCMGRUI, &CSteamProto::OnAccountManagerInit);
- InitQueue();
-
m_idleTS = 0;
isTerminated = false;
m_hQueueThread = NULL;
@@ -68,10 +65,9 @@ CSteamProto::CSteamProto(const char* protoName, const TCHAR* userName) :
CSteamProto::~CSteamProto()
{
- UninitQueue();
}
-MCONTACT __cdecl CSteamProto::AddToList(int, PROTOSEARCHRESULT* psr)
+MCONTACT CSteamProto::AddToList(int, PROTOSEARCHRESULT* psr)
{
MCONTACT hContact = NULL;
ptrA steamId(mir_u2a(psr->id));
@@ -85,7 +81,7 @@ MCONTACT __cdecl CSteamProto::AddToList(int, PROTOSEARCHRESULT* psr)
ptrA token(getStringA("TokenSecret"));
PushRequest(
- new SteamWebApi::GetUserSummariesRequest(token, steamId),
+ new GetUserSummariesRequest(token, steamId),
&CSteamProto::OnGotUserSummaries);
}
}
@@ -99,7 +95,7 @@ MCONTACT __cdecl CSteamProto::AddToList(int, PROTOSEARCHRESULT* psr)
return hContact;
}
-int __cdecl CSteamProto::Authorize(MEVENT hDbEvent)
+int CSteamProto::Authorize(MEVENT hDbEvent)
{
if (IsOnline() && hDbEvent)
{
@@ -115,10 +111,9 @@ int __cdecl CSteamProto::Authorize(MEVENT hDbEvent)
char *who = getStringA(hContact, "SteamID");
PushRequest(
- new SteamWebApi::ApprovePendingRequest(token, sessionId, steamId, who),
+ new ApprovePendingRequest(token, sessionId, steamId, who),
&CSteamProto::OnPendingApproved,
- who,
- ARG_MIR_FREE);
+ who, MirFreeArg);
return 0;
}
@@ -126,7 +121,7 @@ int __cdecl CSteamProto::Authorize(MEVENT hDbEvent)
return 1;
}
-int __cdecl CSteamProto::AuthDeny(MEVENT hDbEvent, const TCHAR*)
+int CSteamProto::AuthDeny(MEVENT hDbEvent, const TCHAR*)
{
if (IsOnline() && hDbEvent)
{
@@ -142,10 +137,9 @@ int __cdecl CSteamProto::AuthDeny(MEVENT hDbEvent, const TCHAR*)
char *who = getStringA(hContact, "SteamID");
PushRequest(
- new SteamWebApi::IgnorePendingRequest(token, sessionId, steamId, who),
+ new IgnorePendingRequest(token, sessionId, steamId, who),
&CSteamProto::OnPendingIgnoreded,
- who,
- ARG_MIR_FREE);
+ who, MirFreeArg);
return 0;
}
@@ -153,7 +147,7 @@ int __cdecl CSteamProto::AuthDeny(MEVENT hDbEvent, const TCHAR*)
return 1;
}
-int __cdecl CSteamProto::AuthRequest(MCONTACT hContact, const TCHAR*)
+int CSteamProto::AuthRequest(MCONTACT hContact, const TCHAR*)
{
if (IsOnline() && hContact)
{
@@ -182,10 +176,9 @@ int __cdecl CSteamProto::AuthRequest(MCONTACT hContact, const TCHAR*)
*/
PushRequest(
- new SteamWebApi::AddFriendRequest(token, sessionId, steamId, who),
+ new AddFriendRequest(token, sessionId, steamId, who),
&CSteamProto::OnFriendAdded,
- param,
- ARG_MIR_FREE);
+ param);
return hAuth;
}
@@ -193,7 +186,7 @@ int __cdecl CSteamProto::AuthRequest(MCONTACT hContact, const TCHAR*)
return 1;
}
-DWORD_PTR __cdecl CSteamProto:: GetCaps(int type, MCONTACT)
+DWORD_PTR CSteamProto:: GetCaps(int type, MCONTACT)
{
switch(type)
{
@@ -216,7 +209,7 @@ DWORD_PTR __cdecl CSteamProto:: GetCaps(int type, MCONTACT)
}
}
-HANDLE __cdecl CSteamProto::SearchBasic(const TCHAR* id)
+HANDLE CSteamProto::SearchBasic(const TCHAR* id)
{
if (!this->IsOnline())
return 0;
@@ -227,51 +220,43 @@ HANDLE __cdecl CSteamProto::SearchBasic(const TCHAR* id)
ptrA steamId(mir_t2a(id));
PushRequest(
- new SteamWebApi::GetUserSummariesRequest(token, steamId),
+ new GetUserSummariesRequest(token, steamId),
&CSteamProto::OnSearchByIdEnded,
mir_tstrdup(id),
- ARG_MIR_FREE);
+ MirFreeArg);
return (HANDLE)STEAM_SEARCH_BYID;
}
-int __cdecl CSteamProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT* pre)
+int CSteamProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT* pre)
{
return (INT_PTR)AddDBEvent(hContact, EVENTTYPE_MESSAGE, pre->timestamp, DBEF_UTF, mir_strlen(pre->szMessage), (BYTE*)pre->szMessage);
}
-int __cdecl CSteamProto::SendMsg(MCONTACT hContact, int, const char *msg)
+int CSteamProto::SendMsg(MCONTACT hContact, int flags, const char *message)
{
+ if (!IsOnline())
+ {
+ ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, NULL, (LPARAM)Translate("You cannot send messages when you are offline."));
+ return 0;
+ }
+
UINT hMessage = InterlockedIncrement(&hMessageProcess);
SendMessageParam *param = (SendMessageParam*)mir_calloc(sizeof(SendMessageParam));
param->hContact = hContact;
param->hMessage = (HANDLE)hMessage;
- param->msg = msg;
- ForkThread(&CSteamProto::SendMsgThread, (void*)param);
- return hMessage;
-}
-
-void __cdecl CSteamProto::SendMsgThread(void *arg)
-{
- SendMessageParam *param = (SendMessageParam*)arg;
-
- if (!IsOnline())
- {
- ProtoBroadcastAck(param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hMessage, (LPARAM)Translate("You cannot send messages when you are offline."));
- mir_free(param);
- return;
- }
+ param->message = mir_strdup(message);
ptrA token(getStringA("TokenSecret"));
ptrA umqid(getStringA("UMQID"));
- ptrA steamId(getStringA(param->hContact, "SteamID"));
-
+ ptrA steamId(getStringA(hContact, "SteamID"));
PushRequest(
- new SteamWebApi::SendMessageRequest(token, umqid, steamId, param->msg),
+ new SendMessageRequest(token, umqid, steamId, message),
&CSteamProto::OnMessageSent,
- param,
- ARG_MIR_FREE);
+ param, MessageParamFree);
+
+ return hMessage;
}
int CSteamProto::SetStatus(int new_status)
@@ -311,7 +296,11 @@ int CSteamProto::SetStatus(int new_status)
m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
- StopQueue();
+ ptrA token(getStringA("TokenSecret"));
+ ptrA umqid(getStringA("UMQID"));
+ SendRequest(new LogoffRequest(token, umqid));
+
+ requestQueue->Stop();
if (!Miranda_Terminated())
SetAllContactsStatus(ID_STATUS_OFFLINE);
@@ -321,7 +310,29 @@ int CSteamProto::SetStatus(int new_status)
m_iStatus = ID_STATUS_CONNECTING;
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
- StartQueue();
+ requestQueue->Start();
+
+ ptrA token(getStringA("TokenSecret"));
+ if (mir_strlen(token) > 0)
+ {
+ PushRequest(
+ new LogonRequest(token),
+ &CSteamProto::OnLoggedOn);
+ }
+ else
+ {
+ ptrA username(mir_urlEncode(ptrA(mir_utf8encodeT(getTStringA("Username")))));
+ if (username == NULL || username[0] == '\0')
+ {
+ m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
+ ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus);
+ return 0;
+ }
+
+ PushRequest(
+ new RsaKeyRequest(username),
+ &CSteamProto::OnGotRsaKey);
+ }
}
else
{
@@ -334,7 +345,8 @@ int CSteamProto::SetStatus(int new_status)
int __cdecl CSteamProto::OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM lParam)
{
- switch (eventType) {
+ switch (eventType)
+ {
case EV_PROTO_ONLOAD:
return this->OnModulesLoaded(wParam, lParam);
@@ -359,10 +371,9 @@ int __cdecl CSteamProto::OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM
return 0;
PushRequest(
- new SteamWebApi::RemoveFriendRequest(token, sessionId, steamId, who),
+ new RemoveFriendRequest(token, sessionId, steamId, who),
&CSteamProto::OnFriendRemoved,
- (void*)hContact,
- ARG_NO_FREE);
+ (void*)hContact);
}
return 0;