From 26cac6b426f729c7df096cfb1614a3ee7d8eefc4 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 6 Jan 2025 15:40:45 +0300 Subject: more code cleaning --- protocols/Steam/src/api/enums.h | 111 +++++++++++++++------------------ protocols/Steam/src/steam_contacts.cpp | 21 +++---- protocols/Steam/src/steam_proto.h | 2 +- protocols/Steam/src/steam_utils.cpp | 4 +- protocols/Steam/src/steam_utils.h | 4 +- 5 files changed, 64 insertions(+), 78 deletions(-) (limited to 'protocols/Steam/src') diff --git a/protocols/Steam/src/api/enums.h b/protocols/Steam/src/api/enums.h index b93377f5a9..66626da535 100644 --- a/protocols/Steam/src/api/enums.h +++ b/protocols/Steam/src/api/enums.h @@ -1,76 +1,63 @@ #ifndef _STEAM_ENUMS_H_ #define _STEAM_ENUMS_H_ -enum class FriendRelationship : int +namespace FriendRelationship { - None = 0, - Blocked = 1, - RequestRecipient = 2, - Friend = 3, - RequestInitiator = 4, - Ignored = 5, - IgnoredFriend = 6, -}; - -enum class PersonaState : int -{ - Offline = 0, - Online = 1, - Busy = 2, - Away = 3, - Snooze = 4, - LookingToTrade = 5, - LookingToPlay = 6, - Invisible = 7, -}; - -enum class PersonaStateFlag : int -{ - None = 0, - HasRichPresence = 1, - InJoinableGame = 2, - ClientTypeWeb = 256, - ClientTypeMobile = 512, - ClientTypeBigPicture = 1024, - ClientTypeVR = 2048, -}; - -inline PersonaStateFlag operator &(PersonaStateFlag lhs, PersonaStateFlag rhs) -{ - return static_cast ( - static_cast::type>(lhs) & - static_cast::type>(rhs)); + enum { + None = 0, + Blocked = 1, + RequestRecipient = 2, + Friend = 3, + RequestInitiator = 4, + Ignored = 5, + IgnoredFriend = 6, + }; } -enum class PersonaStatusFlag : int +namespace PersonaState { - Status = 1, - PlayerName = 2, - QueryPort = 4, - SourceID = 8, - Presence = 16, - Metadata = 32, - LastSeen = 64, - ClanInfo = 128, - GameExtraInfo = 256, - GameDataBlob = 512, - ClanTag = 1024, - Facebook = 2048, - Unknown = 4096, -}; + enum { + Offline = 0, + Online = 1, + Busy = 2, + Away = 3, + Snooze = 4, + LookingToTrade = 5, + LookingToPlay = 6, + Invisible = 7, + }; +} -inline PersonaStatusFlag operator &(PersonaStatusFlag lhs, PersonaStatusFlag rhs) +namespace PersonaStateFlag { - return static_cast ( - static_cast::type>(lhs) & - static_cast::type>(rhs)); + enum { + None = 0, + HasRichPresence = 1, + InJoinableGame = 2, + ClientTypeWeb = 256, + ClientTypeMobile = 512, + ClientTypeBigPicture = 1024, + ClientTypeVR = 2048, + }; } -template -bool contains_flag(T x, T y) { - return (static_cast::type>(x) - & static_cast::type>(y)) - == static_cast::type>(y); +namespace PersonaStatusFlag +{ + enum { + Status = 1, + PlayerName = 2, + QueryPort = 4, + SourceID = 8, + Presence = 16, + Metadata = 32, + LastSeen = 64, + ClanInfo = 128, + GameExtraInfo = 256, + GameDataBlob = 512, + ClanTag = 1024, + Facebook = 2048, + Unknown = 4096, + }; } #endif //_STEAM_ENUMS_H_ diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp index 0e012d8351..2cdbdf4ccd 100644 --- a/protocols/Steam/src/steam_contacts.cpp +++ b/protocols/Steam/src/steam_contacts.cpp @@ -124,36 +124,35 @@ void CSteamProto::OnGotFriendInfo(const CMsgClientPersonaState &reply, const CMs int oldStatus = Contact::GetStatus(hContact); // so, set status only if contact is offline if (oldStatus == ID_STATUS_OFFLINE) { - uint16_t status = SteamToMirandaStatus(PersonaState(F->persona_state)); + uint16_t status = SteamToMirandaStatus(F->persona_state); SetContactStatus(hContact, status); } // client - PersonaStateFlag stateflags = (F->has_persona_state_flags) ? (PersonaStateFlag)(F->persona_state_flags) : (PersonaStateFlag)(-1); - + uint32_t stateflags = (F->has_persona_state_flags) ? F->persona_state_flags : -1; if (stateflags == PersonaStateFlag::None) { // nothing special, either standard client or in different status (only online, I want to play, I want to trade statuses support this flags) uint16_t status = getWord(hContact, "Status", ID_STATUS_OFFLINE); if (status == ID_STATUS_ONLINE || status == ID_STATUS_FREECHAT) setWString(hContact, "MirVer", L"Steam"); } - else if (contains_flag(stateflags, PersonaStateFlag::InJoinableGame)) { + else if (stateflags & PersonaStateFlag::InJoinableGame) { // game setWString(hContact, "MirVer", L"Steam (in game)"); } - else if (contains_flag(stateflags, PersonaStateFlag::ClientTypeWeb)) { + else if (stateflags & PersonaStateFlag::ClientTypeWeb) { // on website setWString(hContact, "MirVer", L"Steam (website)"); } - else if (contains_flag(stateflags, PersonaStateFlag::ClientTypeMobile)) { + else if (stateflags & PersonaStateFlag::ClientTypeMobile) { // on mobile setWString(hContact, "MirVer", L"Steam (mobile)"); } - else if (contains_flag(stateflags, PersonaStateFlag::ClientTypeBigPicture)) { + else if (stateflags & PersonaStateFlag::ClientTypeBigPicture) { // on big picture setWString(hContact, "MirVer", L"Steam (Big Picture)"); } - else if (contains_flag(stateflags, PersonaStateFlag::ClientTypeVR)) { + else if (stateflags & PersonaStateFlag::ClientTypeVR) { // on VR setWString(hContact, "MirVer", L"Steam (VR)"); } @@ -326,7 +325,7 @@ MCONTACT CSteamProto::AddContact(int64_t steamId, const wchar_t *nick, bool isTe return hContact; } -void CSteamProto::UpdateContactRelationship(MCONTACT hContact, FriendRelationship iRelationType) +void CSteamProto::UpdateContactRelationship(MCONTACT hContact, uint32_t iRelationType) { switch (iRelationType) { case FriendRelationship::Friend: @@ -351,10 +350,10 @@ void CSteamProto::OnGotFriendList(const CMsgClientFriendsList &reply, const CMsg return; } - std::map friendsMap; + std::map friendsMap; for (int i = 0; i < reply.n_friends; i++) { auto *F = reply.friends[i]; - friendsMap[F->ulfriendid] = FriendRelationship(F->efriendrelationship); + friendsMap[F->ulfriendid] = F->efriendrelationship; } // Comma-separated list of steam ids to update summaries diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h index 63473ecb9b..3683d19a89 100644 --- a/protocols/Steam/src/steam_proto.h +++ b/protocols/Steam/src/steam_proto.h @@ -238,7 +238,7 @@ class CSteamProto : public PROTO MCONTACT GetContactFromAuthEvent(MEVENT hEvent); - void UpdateContactRelationship(MCONTACT hContact, FriendRelationship); + void UpdateContactRelationship(MCONTACT hContact, uint32_t); void ContactIsRemoved(MCONTACT hContact); void ContactIsFriend(MCONTACT hContact); diff --git a/protocols/Steam/src/steam_utils.cpp b/protocols/Steam/src/steam_utils.cpp index 04610d7cc9..2b8c3263db 100644 --- a/protocols/Steam/src/steam_utils.cpp +++ b/protocols/Steam/src/steam_utils.cpp @@ -88,7 +88,7 @@ void CSteamProto::SetId(const char *pszSetting, int64_t id) ///////////////////////////////////////////////////////////////////////////////////////// // Statuses -int SteamToMirandaStatus(PersonaState state) +int SteamToMirandaStatus(uint32_t state) { switch (state) { case PersonaState::Offline: @@ -111,7 +111,7 @@ int SteamToMirandaStatus(PersonaState state) } } -PersonaState MirandaToSteamState(int status) +uint32_t MirandaToSteamState(int status) { switch (status) { case ID_STATUS_OFFLINE: diff --git a/protocols/Steam/src/steam_utils.h b/protocols/Steam/src/steam_utils.h index 6762f89f99..b183837a78 100644 --- a/protocols/Steam/src/steam_utils.h +++ b/protocols/Steam/src/steam_utils.h @@ -1,8 +1,8 @@ #ifndef _STEAM_UTILS_H_ #define _STEAM_UTILS_H_ -int SteamToMirandaStatus(PersonaState state); -PersonaState MirandaToSteamState(int status); +int SteamToMirandaStatus(uint32_t state); +uint32_t MirandaToSteamState(int status); void ShowNotification(const wchar_t *message, int flags = 0, MCONTACT hContact = NULL); void ShowNotification(const wchar_t *caption, const wchar_t *message, int flags = 0, MCONTACT hContact = NULL); -- cgit v1.2.3