From df415da4e67d518d8e9281cd048e8f5c002edba3 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 3 May 2025 15:53:41 +0300 Subject: minor code cleaning --- protocols/Steam/src/steam_chats.cpp | 48 ++++++-------- protocols/Steam/src/steam_contacts.cpp | 111 +++++++++++++++++---------------- protocols/Steam/src/steam_menus.cpp | 47 ++++++++++---- protocols/Steam/src/steam_proto.h | 5 +- 4 files changed, 114 insertions(+), 97 deletions(-) (limited to 'protocols/Steam/src') diff --git a/protocols/Steam/src/steam_chats.cpp b/protocols/Steam/src/steam_chats.cpp index 60aebc5487..b6c4663f2e 100644 --- a/protocols/Steam/src/steam_chats.cpp +++ b/protocols/Steam/src/steam_chats.cpp @@ -43,13 +43,9 @@ void CSteamProto::OnGetMyChats(const CChatRoomGetMyChatRoomGroupsResponse &reply } // clean garbage - for (auto &cc : AccContacts()) { - if (!Contact::IsGroupChat(cc)) - continue; - - if (chatIds.find(cc) == chatIds.end()) + for (auto &cc : AccContacts()) + if (getByte(cc, "ChatRoom") == GCW_CHATROOM && chatIds.find(cc) == chatIds.end()) db_delete_contact(cc, CDF_DEL_CONTACT); - } } ///////////////////////////////////////////////////////////////////////////////////////// @@ -181,30 +177,22 @@ void CSteamProto::OnGotClanInfo(const CMsgClientClanState &reply, const CMsgProt GCEVENT gce = { si, GC_EVENT_INFORMATION }; gce.time = time(0); - if (reply.name_info) { - if (reply.name_info->has_sha_avatar) { - CMStringA szHash; szHash.Preallocate((int)reply.name_info->sha_avatar.len * 2); - bin2hex(reply.name_info->sha_avatar.data, reply.name_info->sha_avatar.len, szHash.GetBuffer()); - CheckAvatarChange(si->hContact, szHash); - } - - if (reply.user_counts) { - CMStringW wszText; - auto &C = *reply.user_counts; - - if (C.has_members) - wszText.AppendFormat(L"%d %s\r\n", C.members, TranslateT("total members")); - if (C.has_online) - wszText.AppendFormat(L"%d %s\r\n", C.online, TranslateT("online members")); - if (C.has_chatting) - wszText.AppendFormat(L"%d %s\r\n", C.chatting, TranslateT("chatting")); - if (C.has_in_game) - wszText.AppendFormat(L"%d %s\r\n", C.in_game, TranslateT("in game")); - - if (!wszText.IsEmpty()) { - gce.pszText.w = wszText; - Chat_Event(&gce); - } + if (reply.user_counts) { + CMStringW wszText; + auto &C = *reply.user_counts; + + if (C.has_members) + wszText.AppendFormat(L"%d %s\r\n", C.members, TranslateT("total members")); + if (C.has_online) + wszText.AppendFormat(L"%d %s\r\n", C.online, TranslateT("online members")); + if (C.has_chatting) + wszText.AppendFormat(L"%d %s\r\n", C.chatting, TranslateT("chatting")); + if (C.has_in_game) + wszText.AppendFormat(L"%d %s\r\n", C.in_game, TranslateT("in game")); + + if (!wszText.IsEmpty()) { + gce.pszText.w = wszText; + Chat_Event(&gce); } } diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp index f34886c723..462bd6cb1f 100644 --- a/protocols/Steam/src/steam_contacts.cpp +++ b/protocols/Steam/src/steam_contacts.cpp @@ -98,36 +98,38 @@ void CSteamProto::OnGotFriendInfo(const CMsgClientPersonaState &reply, const CMs } // set name - if (F->player_name) { - CMStringW realName(Utf2T(F->player_name)); - - // set a nickname for group chat user? - if (si) { - CMStringW wszUserId(FORMAT, L"%lld", F->friendid); - GCEVENT gce = { si, GC_EVENT_NICK }; - gce.pszUID.w = wszUserId; - gce.pszText.w = realName; - Chat_Event(&gce); - continue; - } + if (!F->clan_data) { + if (F->player_name) { + CMStringW realName(Utf2T(F->player_name)); + + // set a nickname for group chat user? + if (si) { + CMStringW wszUserId(FORMAT, L"%lld", F->friendid); + GCEVENT gce = { si, GC_EVENT_NICK }; + gce.pszUID.w = wszUserId; + gce.pszText.w = realName; + Chat_Event(&gce); + continue; + } - setWString(hContact, "Nick", realName); + setWString(hContact, "Nick", realName); - int pos = realName.Find(L' ', 1); - if (pos != -1) { - setWString(hContact, "FirstName", realName.Mid(0, pos)); - setWString(hContact, "LastName", realName.Mid(pos + 1)); + int pos = realName.Find(L' ', 1); + if (pos != -1) { + setWString(hContact, "FirstName", realName.Mid(0, pos)); + setWString(hContact, "LastName", realName.Mid(pos + 1)); + } + else { + setWString(hContact, "FirstName", realName); + delSetting(hContact, "LastName"); + } } else { - setWString(hContact, "FirstName", realName); + delSetting(hContact, "Nick"); + delSetting(hContact, "FirstName"); delSetting(hContact, "LastName"); } } - else { - delSetting(hContact, "Nick"); - delSetting(hContact, "FirstName"); - delSetting(hContact, "LastName"); - } // avatar if (F->avatar_hash.len != 0) { @@ -158,37 +160,28 @@ void CSteamProto::OnGotFriendInfo(const CMsgClientPersonaState &reply, const CMs } // client - auto stateflags = F->persona_state_flags; - 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 (stateflags & PersonaStateFlag::InJoinableGame) { - // game - setWString(hContact, "MirVer", L"Steam (in game)"); - } - else if (stateflags & PersonaStateFlag::ClientTypeWeb) { - // on website - setWString(hContact, "MirVer", L"Steam (website)"); - } - else if (stateflags & PersonaStateFlag::ClientTypeMobile) { - // on mobile - setWString(hContact, "MirVer", L"Steam (mobile)"); - } - else if (stateflags & PersonaStateFlag::ClientTypeBigPicture) { - // on big picture - setWString(hContact, "MirVer", L"Steam (Big Picture)"); - } - else if (stateflags & PersonaStateFlag::ClientTypeVR) { - // on VR - setWString(hContact, "MirVer", L"Steam (VR)"); - } - else { - // none/unknown (e.g. when contact is offline) - delSetting(hContact, "MirVer"); + if (F->has_persona_state_flags) { + auto stateflags = F->persona_state_flags; + 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 (stateflags & PersonaStateFlag::InJoinableGame) // game + setWString(hContact, "MirVer", L"Steam (in game)"); + else if (stateflags & PersonaStateFlag::ClientTypeWeb) // on website + setWString(hContact, "MirVer", L"Steam (website)"); + else if (stateflags & PersonaStateFlag::ClientTypeMobile) // on mobile + setWString(hContact, "MirVer", L"Steam (mobile)"); + else if (stateflags & PersonaStateFlag::ClientTypeBigPicture) // on big picture + setWString(hContact, "MirVer", L"Steam (Big Picture)"); + else if (stateflags & PersonaStateFlag::ClientTypeVR) // on VR + setWString(hContact, "MirVer", L"Steam (VR)"); + else // none/unknown (e.g. when contact is offline) + delSetting(hContact, "MirVer"); } + else delSetting(hContact, "MirVer"); // playing game auto gameId = F->has_game_played_app_id ? F->game_played_app_id : 0; @@ -232,6 +225,18 @@ void CSteamProto::OnGotFriendInfo(const CMsgClientPersonaState &reply, const CMs SetContactExtraIcon(hContact, NULL); } + + // clan information + if (auto *cd = F->clan_data) { + if (F->player_name) + setUString(hContact, "Nick", F->player_name); + + setByte(hContact, "ChatRoom", GCW_SERVER); + if (cd->has_chat_group_id) + SetId(hContact, DBKEY_CHAT_ID, cd->chat_group_id); + else + delSetting(hContact, DBKEY_CHAT_ID); + } } } diff --git a/protocols/Steam/src/steam_menus.cpp b/protocols/Steam/src/steam_menus.cpp index 110cb8f10a..a1b5df2edc 100644 --- a/protocols/Steam/src/steam_menus.cpp +++ b/protocols/Steam/src/steam_menus.cpp @@ -26,7 +26,7 @@ INT_PTR CSteamProto::UnblockCommand(WPARAM hContact, LPARAM) return 0; } -INT_PTR CSteamProto::JoinToGameCommand(WPARAM hContact, LPARAM) +INT_PTR CSteamProto::JoinGameCommand(WPARAM hContact, LPARAM) { char url[MAX_PATH]; uint32_t gameId = getDword(hContact, "GameID", 0); @@ -35,6 +35,15 @@ INT_PTR CSteamProto::JoinToGameCommand(WPARAM hContact, LPARAM) return 0; } +INT_PTR CSteamProto::JoinChatCommand(WPARAM hContact, LPARAM) +{ + CChatRoomJoinChatRoomGroupRequest request; + request.chat_group_id = GetId(hContact, DBKEY_STEAM_ID); request.has_chat_group_id = true; + request.chat_id = getDword(hContact, DBKEY_CHAT_ID); request.has_chat_id = true; + WSSendService(JoinChatRoomGroup, request); + return 0; +} + INT_PTR CSteamProto::OpenBlockListCommand(WPARAM, LPARAM) { // SendRequest(new GetFriendListRequest(m_szAccessToken, m_iSteamId, "ignoredfriend"), &CSteamProto::OnGotBlockList); @@ -52,17 +61,21 @@ int CSteamProto::OnPrebuildContactMenu(WPARAM hContact, LPARAM) bool ctrlPressed = (GetKeyState(VK_CONTROL) & 0x8000) != 0; if (!Contact::IsGroupChat(hContact)) { - bool authNeeded = getBool(hContact, "Auth", 0); + bool authNeeded = getBool(hContact, "Auth"); Menu_ShowItem(GetMenuItem(PROTO_MENU_REQ_AUTH), authNeeded || ctrlPressed); Menu_ShowItem(GetMenuItem(PROTO_MENU_REVOKE_AUTH), !authNeeded || ctrlPressed); } - bool isBlocked = getBool(hContact, "Block", 0); + bool isBlocked = getBool(hContact, "Block"); Menu_ShowItem(contactMenuItems[CMI_BLOCK], !isBlocked || ctrlPressed); Menu_ShowItem(contactMenuItems[CMI_UNBLOCK], isBlocked || ctrlPressed); - uint32_t gameId = getDword(hContact, "GameID", 0); + uint32_t gameId = getDword(hContact, "GameID"); Menu_ShowItem(contactMenuItems[CMI_JOIN_GAME], gameId || ctrlPressed); + + int chatType = getByte(hContact, "ChatRoom"); + int64_t chatId = GetId(hContact, DBKEY_CHAT_ID); + Menu_ShowItem(contactMenuItems[CMI_JOIN_CHAT], chatId && chatType == GCW_SERVER); return 0; } @@ -92,21 +105,20 @@ void CSteamProto::OnInitStatusMenu() void CSteamProto::InitMenus() { CMenuItem mi(&g_plugin); - mi.flags = CMIF_UNICODE; - // "Block" + // Block SET_UID(mi, 0xc6169b8f, 0x53ab, 0x4242, 0xbe, 0x90, 0xe2, 0x4a, 0xa5, 0x73, 0x88, 0x32); mi.pszService = MODULENAME "/Block"; - mi.name.w = LPGENW("Block"); + mi.name.a = LPGEN("Block"); mi.position = -201001001 + CMI_BLOCK; mi.hIcolibItem = Skin_GetIconHandle(SKINICON_OTHER_OFF); contactMenuItems[CMI_BLOCK] = Menu_AddContactMenuItem(&mi); CreateServiceFunction(mi.pszService, GlobalService<&CSteamProto::BlockCommand>); - // "Unblock" + // Unblock SET_UID(mi, 0xc6169b8f, 0x53ab, 0x4242, 0xbe, 0x90, 0xe2, 0x4a, 0xa5, 0x73, 0x88, 0x32); mi.pszService = MODULENAME "/Unblock"; - mi.name.w = LPGENW("Unblock"); + mi.name.a = LPGEN("Unblock"); mi.position = -201001001 + CMI_UNBLOCK; mi.hIcolibItem = Skin_GetIconHandle(SKINICON_OTHER_ON); contactMenuItems[CMI_UNBLOCK] = Menu_AddContactMenuItem(&mi); @@ -114,14 +126,23 @@ void CSteamProto::InitMenus() mi.flags |= CMIF_NOTOFFLINE; - // "Join to game" + // Join to game SET_UID(mi, 0x1a6aaab7, 0xba31, 0x4b47, 0x8e, 0xce, 0xf8, 0x8e, 0xf4, 0x62, 0x4f, 0xd7); - mi.pszService = MODULENAME "/JoinToGame"; - mi.name.w = LPGENW("Join to game"); + mi.pszService = MODULENAME "/JoinGame"; + mi.name.a = LPGEN("Join the game"); mi.position = -200001000 + CMI_JOIN_GAME; mi.hIcolibItem = nullptr; contactMenuItems[CMI_JOIN_GAME] = Menu_AddContactMenuItem(&mi); - CreateServiceFunction(mi.pszService, GlobalService<&CSteamProto::JoinToGameCommand>); + CreateServiceFunction(mi.pszService, GlobalService<&CSteamProto::JoinGameCommand>); + + // Join clan's chat + SET_UID(mi, 0x4da0c3d3, 0x6fca, 0x42ba, 0xac, 0x72, 0x5c, 0xc9, 0x42, 0x5a, 0x70, 0x4e); + mi.pszService = MODULENAME "/JoinChat"; + mi.name.a = LPGEN("Join group chat"); + mi.position = -200001002 + CMI_JOIN_GAME; + mi.hIcolibItem = Skin_GetIconHandle(SKINICON_CHAT_JOIN); + contactMenuItems[CMI_JOIN_CHAT] = Menu_AddContactMenuItem(&mi); + CreateServiceFunction(mi.pszService, GlobalService<&CSteamProto::JoinChatCommand>); HookEvent(ME_CLIST_PREBUILDCONTACTMENU, &CSteamProto::PrebuildContactMenu); } diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h index a158011cd2..f28bc41407 100644 --- a/protocols/Steam/src/steam_proto.h +++ b/protocols/Steam/src/steam_proto.h @@ -35,6 +35,7 @@ #define GetMyChatRoomGroups "ChatRoom.GetMyChatRoomGroups#1" #define GetChatHistory "ChatRoom.GetMessageHistory#1" #define SendChatMessage "ChatRoom.SendChatMessage#1" +#define JoinChatRoomGroup "ChatRoom.JoinChatRoomGroup#1" #define LeaveChatGroup "ChatRoom.LeaveChatRoomGroup#1" #define AckChatMessage "ChatRoom.AckChatMessage#1" #define DeleteChatMessage "ChatRoom.DeleteChatMessages#1" @@ -63,6 +64,7 @@ enum CMI_BLOCK, CMI_UNBLOCK, CMI_JOIN_GAME, + CMI_JOIN_CHAT, CMI_MAX // this item shall be the last one }; @@ -316,7 +318,8 @@ class CSteamProto : public PROTO INT_PTR __cdecl BlockCommand(WPARAM, LPARAM); INT_PTR __cdecl UnblockCommand(WPARAM, LPARAM); - INT_PTR __cdecl JoinToGameCommand(WPARAM, LPARAM); + INT_PTR __cdecl JoinGameCommand(WPARAM, LPARAM); + INT_PTR __cdecl JoinChatCommand(WPARAM, LPARAM); INT_PTR __cdecl OpenBlockListCommand(WPARAM, LPARAM); -- cgit v1.2.3