diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2014-06-21 17:25:31 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2014-06-21 17:25:31 +0000 |
commit | 13ec12177636fb42c9692664d0f48bd3be2a7fc0 (patch) | |
tree | 48a33ed40ec1e4dc9c5a8b4aa192ed1ec853c2f1 | |
parent | ee8b6d3e7acadbd3bd87a1c3cfb06e7b7af88c64 (diff) |
Steam: added block command to contact menu
git-svn-id: http://svn.miranda-ng.org/main/trunk@9545 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/Steam/src/Steam/friend_list.h | 23 | ||||
-rw-r--r-- | protocols/Steam/src/steam_contacts.cpp | 25 | ||||
-rw-r--r-- | protocols/Steam/src/steam_menus.cpp | 32 | ||||
-rw-r--r-- | protocols/Steam/src/steam_pooling.cpp | 5 | ||||
-rw-r--r-- | protocols/Steam/src/steam_proto.h | 4 |
5 files changed, 79 insertions, 10 deletions
diff --git a/protocols/Steam/src/Steam/friend_list.h b/protocols/Steam/src/Steam/friend_list.h index a727bcf1d6..f13fe6c56c 100644 --- a/protocols/Steam/src/Steam/friend_list.h +++ b/protocols/Steam/src/Steam/friend_list.h @@ -38,6 +38,29 @@ namespace SteamWebApi }
};
+ class BlockFriendRequest : public HttpsPostRequest
+ {
+ public:
+ BlockFriendRequest(const char *token, const char *sessionId, const char *steamId, const char *who) :
+ HttpsPostRequest(STEAM_COM_URL "/actions/BlockUserAjax")
+ {
+ char login[MAX_PATH];
+ mir_snprintf(login, SIZEOF(login), "%s||oauth:%s", steamId, token);
+
+ char cookie[MAX_PATH];
+ mir_snprintf(cookie, SIZEOF(cookie), "steamLogin=%s;sessionid=%s;forceMobile=1", login, sessionId);
+
+ char data[128];
+ mir_snprintf(data, SIZEOF(data),
+ "sessionID=%s&action=ignore&steamid=%s",
+ sessionId,
+ who);
+
+ SetData(data, strlen(data));
+ AddHeader("Cookie", cookie);
+ }
+ };
+
class RemoveFriendRequest : public HttpsPostRequest
{
public:
diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp index 9713f3d1cf..29a4366523 100644 --- a/protocols/Steam/src/steam_contacts.cpp +++ b/protocols/Steam/src/steam_contacts.cpp @@ -202,9 +202,16 @@ void CSteamProto::OnGotFriendList(const NETLIBHTTPREQUEST *response, void *arg) node = json_get(child, "steamid");
ptrA steamId(mir_u2a(json_as_string(node)));
+ MCONTACT hContact = FindContact(steamId);
+ if (!hContact)
+ {
+ hContact = AddContact(steamId);
+ steamIds.append(steamId).append(",");
+ }
+
node = json_get(child, "relationship");
ptrA relationship(mir_u2a(json_as_string(node)));
- if (!lstrcmpiA(relationship, "friend"))
+ /*if (!lstrcmpiA(relationship, "friend"))
{
if (!FindContact(steamId))
{
@@ -212,16 +219,14 @@ void CSteamProto::OnGotFriendList(const NETLIBHTTPREQUEST *response, void *arg) steamIds.append(steamId).append(",");
}
}
- else if (!lstrcmpiA(relationship, "ignoredfriend"))
+ else */if (!lstrcmpiA(relationship, "ignoredfriend"))
{
// todo
+ setByte(hContact, "Block", 1);
}
else if (!lstrcmpiA(relationship, "requestrecipient"))
{
- MCONTACT hContact = FindContact(steamId);
- if (!hContact)
- hContact = AddContact(steamId, true);
-
+ // todo
//RaiseAuthRequestThread((void*)hContact);
}
else continue;
@@ -312,6 +317,14 @@ void CSteamProto::OnFriendAdded(const NETLIBHTTPREQUEST *response, void *arg) ProtoBroadcastAck(param->hContact, ACKTYPE_AUTHREQ, ACKRESULT_SUCCESS, param->hAuth, 0);
}
+void CSteamProto::OnFriendBlocked(const NETLIBHTTPREQUEST *response, void *arg)
+{
+ if (response == NULL || response->resultCode != HTTP_STATUS_OK || lstrcmpiA(response->pData, "true"))
+ {
+ debugLogA("CSteamProto::OnFriendIgnored: failed to ignore friend %s", ptrA((char*)arg));
+ }
+}
+
void CSteamProto::OnFriendRemoved(const NETLIBHTTPREQUEST *response, void *arg)
{
if (response == NULL || response->resultCode != HTTP_STATUS_OK || lstrcmpiA(response->pData, "true"))
diff --git a/protocols/Steam/src/steam_menus.cpp b/protocols/Steam/src/steam_menus.cpp index be3a2ed181..f0a2e19b21 100644 --- a/protocols/Steam/src/steam_menus.cpp +++ b/protocols/Steam/src/steam_menus.cpp @@ -25,6 +25,21 @@ int CSteamProto::AuthRequestCommand(WPARAM hContact, LPARAM) return 0;
}
+int CSteamProto::BlockCommand(WPARAM hContact, LPARAM)
+{
+ ptrA token(getStringA("TokenSecret"));
+ ptrA sessionId(getStringA("SessionID"));
+ ptrA steamId(getStringA("SteamID"));
+ char *who = getStringA(hContact, "SteamID");
+
+ PushRequest(
+ new SteamWebApi::BlockFriendRequest(token, sessionId, steamId, who),
+ &CSteamProto::OnFriendBlocked,
+ who);
+
+ return 0;
+}
+
int CSteamProto::JoinToGameCommand(WPARAM hContact, LPARAM)
{
char url[MAX_PATH];
@@ -49,6 +64,9 @@ int CSteamProto::OnPrebuildContactMenu(WPARAM wParam, LPARAM) bool authNeeded = getBool(hContact, "Auth", 0);
Menu_ShowItem(contactMenuItems[CMI_AUTH_REQUEST], authNeeded);
+ bool isBlocked = getBool(hContact, "Block", 0);
+ Menu_ShowItem(contactMenuItems[CMI_BLOCK], !isBlocked);
+
DWORD gameId = getDword(hContact, "GameID", 0);
Menu_ShowItem(contactMenuItems[CMI_JOIN_GAME], gameId > 0);
@@ -74,18 +92,26 @@ void CSteamProto::InitMenus() mi.cbSize = sizeof(CLISTMENUITEM);
mi.flags = CMIF_TCHAR;
- // "Join to game"
- mi.pszService = MODULE"/AuthRequest";
+ // "Request authorization"
+ mi.pszService = MODULE "/AuthRequest";
mi.ptszName = LPGENT("Request authorization");
mi.position = -201001000 + CMI_AUTH_REQUEST;
mi.icolibItem = LoadSkinnedIconHandle(SKINICON_AUTH_REQUEST);
contactMenuItems[CMI_AUTH_REQUEST] = Menu_AddContactMenuItem(&mi);
CreateServiceFunction(mi.pszService, GlobalService<&CSteamProto::AuthRequestCommand>);
+ // "Block"
+ mi.pszService = MODULE "/Block";
+ mi.ptszName = LPGENT("Block");
+ mi.position = -201001001 + CMI_BLOCK;
+ mi.icolibItem = LoadSkinnedIconHandle(SKINICON_AUTH_REQUEST);
+ contactMenuItems[CMI_BLOCK] = Menu_AddContactMenuItem(&mi);
+ CreateServiceFunction(mi.pszService, GlobalService<&CSteamProto::BlockCommand>);
+
mi.flags |= CMIF_NOTOFFLINE;
// "Join to game"
- mi.pszService = MODULE"/JoinToGame";
+ mi.pszService = MODULE "/JoinToGame";
mi.ptszName = LPGENT("Join to game");
mi.position = -200001000 + CMI_JOIN_GAME;
mi.icolibItem = NULL;
diff --git a/protocols/Steam/src/steam_pooling.cpp b/protocols/Steam/src/steam_pooling.cpp index 48755bbbc2..d780a57210 100644 --- a/protocols/Steam/src/steam_pooling.cpp +++ b/protocols/Steam/src/steam_pooling.cpp @@ -112,6 +112,11 @@ void CSteamProto::ParsePollData(JSONNODE *data) case 1:
// ignored
// todo
+ MCONTACT hContact = FindContact(steamId);
+ if (hContact)
+ {
+ setByte(hContact, "Block", 1);
+ }
break;
case 2:
diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h index 7ddaf48786..ca66962572 100644 --- a/protocols/Steam/src/steam_proto.h +++ b/protocols/Steam/src/steam_proto.h @@ -40,7 +40,7 @@ enum CMI_AUTH_REQUEST,
//CMI_AUTH_GRANT,
//CMI_AUTH_REVOKE,
- //CMI_BLOCK,
+ CMI_BLOCK,
CMI_JOIN_GAME,
CMI_MAX // this item shall be the last one
};
@@ -203,6 +203,7 @@ protected: void OnGotAvatar(const NETLIBHTTPREQUEST *response, void *arg);
void OnFriendAdded(const NETLIBHTTPREQUEST *response, void *arg);
+ void OnFriendBlocked(const NETLIBHTTPREQUEST *response, void *arg);
void OnFriendRemoved(const NETLIBHTTPREQUEST *response, void *arg);
void OnAuthRequested(const NETLIBHTTPREQUEST *response, void *arg);
@@ -224,6 +225,7 @@ protected: static HGENMENU contactMenuItems[CMI_MAX];
int __cdecl AuthRequestCommand(WPARAM, LPARAM);
+ int __cdecl BlockCommand(WPARAM, LPARAM);
int __cdecl JoinToGameCommand(WPARAM, LPARAM);
static INT_PTR MenuChooseService(WPARAM wParam, LPARAM lParam);
|