diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2014-04-11 21:04:11 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2014-04-11 21:04:11 +0000 |
commit | 481bff2e2bd0bfd1ce306a2a514e63145fb63917 (patch) | |
tree | 754850ada56aabb7535b5362ef2ea02bca2a8beb /protocols/Steam | |
parent | 50ae2aaaa5c7f935eb54fbc9fade7fdbed4a4111 (diff) |
Steam:
- fixed minor issues
- added detection of playing contacts
- added reaction on adding/removing contacts (from steam app)
git-svn-id: http://svn.miranda-ng.org/main/trunk@8961 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Steam')
-rw-r--r-- | protocols/Steam/src/Steam/friend.h | 4 | ||||
-rw-r--r-- | protocols/Steam/src/Steam/poll.h | 33 | ||||
-rw-r--r-- | protocols/Steam/src/steam_account.cpp | 8 | ||||
-rw-r--r-- | protocols/Steam/src/steam_contacts.cpp | 19 | ||||
-rw-r--r-- | protocols/Steam/src/steam_proto.cpp | 31 | ||||
-rw-r--r-- | protocols/Steam/src/steam_thread.cpp | 56 | ||||
-rw-r--r-- | protocols/Steam/src/steam_utils.cpp | 2 |
7 files changed, 93 insertions, 60 deletions
diff --git a/protocols/Steam/src/Steam/friend.h b/protocols/Steam/src/Steam/friend.h index 27985eca59..9be555a914 100644 --- a/protocols/Steam/src/Steam/friend.h +++ b/protocols/Steam/src/Steam/friend.h @@ -27,6 +27,8 @@ namespace SteamWebApi DWORD lastEvent;
public:
+ Summary() : gameId(0), created(0), lastEvent(0) { }
+
const char *GetSteamId() const { return steamId.c_str(); }
const wchar_t *GetNickname() const { return nickname.c_str(); }
const wchar_t *GetRealname() const { return realname.c_str(); }
@@ -114,7 +116,7 @@ namespace SteamWebApi item->gameInfo = json_as_string(node);
node = json_get(child, "gameid");
- item->gameId = json_as_int(node);
+ item->gameId = atol(ptrA(mir_u2a(json_as_string(node))));
summaries->items.push_back(item);
}
diff --git a/protocols/Steam/src/Steam/poll.h b/protocols/Steam/src/Steam/poll.h index ddf4894fd2..312f7336e6 100644 --- a/protocols/Steam/src/Steam/poll.h +++ b/protocols/Steam/src/Steam/poll.h @@ -13,7 +13,9 @@ namespace SteamWebApi POOL_TYPE_MYMESSAGE,
POOL_TYPE_TYPING,
POOL_TYPE_STATE,
- //POOL_TYPE_RELATIONSHIP
+ POOL_TYPE_CONTACT_AUTH,
+ POOL_TYPE_CONTACT_ADDED,
+ POOL_TYPE_CONTACT_DELETED,
};
class PoolItem// : public Result
@@ -59,6 +61,8 @@ namespace SteamWebApi const wchar_t *GetNickname() const { return nickname.c_str(); }
};
+ class Relationship : public PoolItem { friend PollApi; };
+
class PollResult : public Result
{
friend PollApi;
@@ -170,16 +174,35 @@ namespace SteamWebApi item = state;
}
- /*else if (!lstrcmpi(type, L"personarelationship"))
+ else if (!lstrcmpi(type, L"personarelationship"))
{
- type = POOL_TYPE_RELATIONSHIP;
- }*/
+ Relationship *crs = new Relationship();
+
+ node = json_get(child, "persona_state");
+ int state = json_as_int(node);
+ if (state == 0)
+ {
+ // contact was removed
+ crs->type = POOL_TYPE_CONTACT_DELETED;
+
+ }
+ else if (state == 2)
+ {
+ // auth request
+ crs->type = POOL_TYPE_CONTACT_AUTH;
+ }
+ else if (state == 3)
+ {
+ // add to list
+ crs->type = POOL_TYPE_CONTACT_ADDED;
+ }
+ }
/*else if (!lstrcmpi(type, L"leftconversation"))
{
}*/
else
{
- int z = 0;
+ continue;
}
node = json_get(child, "steamid_from");
diff --git a/protocols/Steam/src/steam_account.cpp b/protocols/Steam/src/steam_account.cpp index c580efeab0..8e72904583 100644 --- a/protocols/Steam/src/steam_account.cpp +++ b/protocols/Steam/src/steam_account.cpp @@ -123,8 +123,8 @@ void CSteamProto::Authorize(SteamWebApi::AuthorizationApi::AuthResult *authResul void CSteamProto::LogInThread(void* param)
{
- if (this->IsOnline())
- return;
+ while (m_bTerminated && m_hPollingThread != NULL)
+ Sleep(500);
ptrA token(getStringA("TokenSecret"));
if (!token || lstrlenA(token) == 0)
@@ -194,12 +194,12 @@ void CSteamProto::LogOutThread(void*) ptrA token(getStringA("TokenSecret"));
ptrA sessionId(getStringA("SessionID"));
- while (m_hPollingThread != NULL)
+ while (m_bTerminated && m_hPollingThread != NULL)
Sleep(500);
- m_bTerminated = false;
debugLogA("CSteamProto::LogOutThread: call SteamWebApi::LoginApi::Logoff");
SteamWebApi::LoginApi::Logoff(m_hNetlibUser, token, sessionId);
delSetting("SessionID");
+ m_bTerminated = false;
}
\ No newline at end of file diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp index 8742c399d1..03969ad2ff 100644 --- a/protocols/Steam/src/steam_contacts.cpp +++ b/protocols/Steam/src/steam_contacts.cpp @@ -48,17 +48,22 @@ void CSteamProto::UpdateContact(MCONTACT hContact, const SteamWebApi::FriendApi: // only for contacts
if (hContact)
{
- WORD status = SteamToMirandaStatus(contact->GetState());
- setWord(hContact, "Status", status);
setDword(hContact, "LastEventDateTS", contact->GetLastEvent());
- if (status == ID_STATUS_OUTTOLUNCH)
+ DWORD gameId = contact->GetGameId();
+ if (gameId >0)
{
+ setWord(hContact, "Status", ID_STATUS_OUTTOLUNCH);
db_set_ws(hContact, "CList", "StatusMsg", contact->GetGameInfo());
+
+ setWString(hContact, "GameInfo", contact->GetGameInfo());
setDword(hContact, "GameID", contact->GetGameId());
}
else
{
+ WORD status = SteamToMirandaStatus(contact->GetState());
+ setWord(hContact, "Status", status);
+
db_unset(hContact, "CList", "StatusMsg");
delSetting(hContact, "GameID");
}
@@ -144,6 +149,8 @@ void CSteamProto::UpdateContactsThread(void *arg) {
hContact = this->FindContact(contact->GetSteamId());
if (hContact == NULL)
+ hContact = AddContact(contact);
+ if (hContact == NULL)
return;
}
@@ -163,7 +170,7 @@ MCONTACT CSteamProto::AddContact(const SteamWebApi::FriendApi::Summary *contact) setString(hContact, "SteamID", contact->GetSteamId());
// update info
- UpdateContact(hContact, contact);
+ //UpdateContact(hContact, contact);
// move to default group
DBVARIANT dbv;
@@ -212,7 +219,9 @@ void CSteamProto::LoadContactListThread(void*) for (size_t i = 0; i < summaries.GetItemCount(); i++)
{
const SteamWebApi::FriendApi::Summary *summary = summaries.GetAt(i);
- AddContact(summary);
+ MCONTACT hContact = AddContact(summary);
+ if (hContact)
+ UpdateContact(hContact, summary);
}
}
}
diff --git a/protocols/Steam/src/steam_proto.cpp b/protocols/Steam/src/steam_proto.cpp index 02b3fd82f4..f30d47a59b 100644 --- a/protocols/Steam/src/steam_proto.cpp +++ b/protocols/Steam/src/steam_proto.cpp @@ -226,36 +226,15 @@ int CSteamProto::SetStatus(int new_status) ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
if (!Miranda_Terminated())
- {
SetAllContactsStatus(ID_STATUS_OFFLINE);
- //this->CloseAllChatSessions();
- }
-
- return 0;
}
- else
+ else if (old_status == ID_STATUS_OFFLINE)
{
- if (old_status == ID_STATUS_OFFLINE/* && !this->IsOnline()*/)
- {
- m_iStatus = ID_STATUS_CONNECTING;
- ForkThread(&CSteamProto::LogInThread, NULL);
- }
- //else
- //{
- //if (IsOnline())
- //{
- // ForkThread(&CSteamProto::SetServerStatusThread, (void*)new_status);
-
- // return 0;
- //}
-
- //ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
-
- //return 0;
- //}
- }
+ m_iStatus = ID_STATUS_CONNECTING;
+ ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
- ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
+ ForkThread(&CSteamProto::LogInThread, NULL);
+ }
return 0;
}
diff --git a/protocols/Steam/src/steam_thread.cpp b/protocols/Steam/src/steam_thread.cpp index d7bdd560c6..970cbcd628 100644 --- a/protocols/Steam/src/steam_thread.cpp +++ b/protocols/Steam/src/steam_thread.cpp @@ -68,30 +68,57 @@ void CSteamProto::PollServer(const char *token, const char *sessionId, UINT32 me if (IsMe(steamId))
{
- debugLogA("Change own status to %i", status);
- WORD oldStatus = m_iStatus;
- m_iStatus = m_iDesiredStatus = status;
- ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
+ if (status == ID_STATUS_OFFLINE)
+ continue;
+
+ if (status != m_iStatus)
+ {
+ debugLogA("Change own status to %i", status);
+ WORD oldStatus = m_iStatus;
+ m_iStatus = m_iDesiredStatus = status;
+ ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
+ }
}
- else
+ /*else
{
MCONTACT hContact = FindContact(steamId);
if (hContact)
SetContactStatus(hContact, status);
+ }*/
- }
-
if (updatedIds.IsEmpty())
updatedIds.Append(steamId);
else
updatedIds.AppendFormat(",%s", steamId);
}
break;
+
+ case SteamWebApi::PollApi::POOL_TYPE_CONTACT_ADDED:
+ {
+ SteamWebApi::PollApi::Relationship *crs = (SteamWebApi::PollApi::Relationship*)item;
+
+ const char *steamId = crs->GetSteamId();
+ if (updatedIds.IsEmpty())
+ updatedIds.Append(steamId);
+ else
+ updatedIds.AppendFormat(",%s", steamId);
+ }
+ break;
+
+ case SteamWebApi::PollApi::POOL_TYPE_CONTACT_DELETED:
+ {
+ SteamWebApi::PollApi::Relationship *crs = (SteamWebApi::PollApi::Relationship*)item;
+
+ const char *steamId = crs->GetSteamId();
+ MCONTACT hContact = FindContact(steamId);
+ if (hContact)
+ CallService(MS_DB_CONTACT_DELETE, hContact, 0);
+ }
+ break;
}
}
if (!updatedIds.IsEmpty())
- //ForkThread(&CSteamProto::UpdateContactsThread, mir_strdup(updatedIds));
UpdateContactsThread(mir_strdup(updatedIds));
}
@@ -109,17 +136,10 @@ void CSteamProto::PollingThread(void*) PollServer(token, sessionId, messageId, &pollResult);
if (pollResult.IsNeedRelogin())
+ {
debugLogA("CSteamProto::PollingThread: need to relogin");
- /*{
- SteamWebApi::LoginApi::LoginResult loginResult;
- SteamWebApi::LoginApi::Logon(m_hNetlibUser, token, &loginResult);
-
- if (!loginResult.IsSuccess())
- break;
-
- sessionId = mir_strdup(loginResult.GetSessionId());
- setString("SessionID", sessionId);
- }*/
+ SetStatus(ID_STATUS_OFFLINE);
+ }
if (!pollResult.IsSuccess())
{
diff --git a/protocols/Steam/src/steam_utils.cpp b/protocols/Steam/src/steam_utils.cpp index 862164e957..6ec2ec89f8 100644 --- a/protocols/Steam/src/steam_utils.cpp +++ b/protocols/Steam/src/steam_utils.cpp @@ -11,7 +11,7 @@ WORD CSteamProto::SteamToMirandaStatus(int state) case 3: //Away
return ID_STATUS_AWAY;
case 4: //Playing
- return PF2_OUTTOLUNCH;
+ return ID_STATUS_OUTTOLUNCH;
/*case 5: //Looking to trade
return "trade";
case 6: //Looking to play
|