TrinityCore
ClubMembershipService.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
20#include "CharacterCache.h"
21#include "ClubService.h"
22#include "ClubUtils.h"
23#include "Guild.h"
24#include "Player.h"
25
26namespace Battlenet::Services
27{
29
30uint32 ClubMembershipService::HandleSubscribe(club::v1::membership::SubscribeRequest const* /*request*/, club::v1::membership::SubscribeResponse* response,
31 std::function<void(ServiceBase*, uint32, google::protobuf::Message const*)>& /*continuation*/)
32{
33 Player const* player = _session->GetPlayer();
34
35 if (!player)
36 return ERROR_INTERNAL;
37
38 Guild const* guild = player->GetGuild();
39
40 if (!guild)
41 return ERROR_OK;
42
43 club::v1::ClubMembershipDescription* description = response->mutable_state()->add_description();
44 description->set_allocated_member_id(CreateClubMemberId(player->GetGUID()).release());
45
46 club::v1::ClubDescription* club = description->mutable_club();
47 club->set_id(guild->GetId());
48 club->set_allocated_type(ClubService::CreateGuildClubType().release());
49 club->set_name(guild->GetName());
50 club->set_privacy_level(club::v1::PrivacyLevel::PRIVACY_LEVEL_OPEN);
51 club->set_visibility_level(club::v1::VISIBILITY_LEVEL_PRIVATE);
52 club->set_member_count(guild->GetMembersCount());
53 club->set_creation_time(
54 std::chrono::duration_cast<std::chrono::microseconds>(SystemTimePoint::clock::from_time_t(guild->GetCreatedDate()).time_since_epoch()).count());
55
56 // Not setting these can cause issues.
57 club->set_timezone("");
58 club->set_locale("");
59
60 club::v1::MemberDescription* leader = club->add_leader();
61
62 leader->set_allocated_id(CreateClubMemberId(guild->GetLeaderGUID()).release());
63
64 response->mutable_state()->mutable_mention_view()->set_last_read_time(0);
65 response->mutable_state()->mutable_mention_view()->set_last_message_time(0);
66
67 return ERROR_OK;
68}
69
70uint32 ClubMembershipService::HandleUnsubscribe(club::v1::membership::UnsubscribeRequest const* /*request*/, NoData* /*response*/,
71 std::function<void(ServiceBase*, uint32, google::protobuf::Message const*)>& /*continuation*/)
72{
73 // We just have to signal the client that the unsubscribe request came through.
74 return ERROR_OK;
75}
76
77std::unique_ptr<club::v1::MemberId> ClubMembershipService::CreateClubMemberId(ObjectGuid guid)
78{
79 std::unique_ptr<club::v1::MemberId> id = std::make_unique<club::v1::MemberId>();
80 id->mutable_account_id()->set_id(sCharacterCache->GetCharacterAccountIdByGuid(guid));
81 id->set_unique_id(Clubs::CreateClubMemberId(guid));
82 return id;
83}
84}
@ ERROR_INTERNAL
#define sCharacterCache
uint32_t uint32
Definition: Define.h:142
uint32 HandleUnsubscribe(club::v1::membership::UnsubscribeRequest const *request, NoData *response, std::function< void(ServiceBase *, uint32, ::google::protobuf::Message const *)> &continuation) override
static std::unique_ptr< club::v1::MemberId > CreateClubMemberId(ObjectGuid guid)
uint32 HandleSubscribe(club::v1::membership::SubscribeRequest const *request, club::v1::membership::SubscribeResponse *response, std::function< void(ServiceBase *, uint32, ::google::protobuf::Message const *)> &continuation) override
static std::unique_ptr< club::v1::UniqueClubType > CreateGuildClubType()
Definition: Guild.h:329
ObjectGuid GetLeaderGUID() const
Definition: Guild.h:754
ObjectGuid::LowType GetId() const
Definition: Guild.h:752
std::string const & GetName() const
Definition: Guild.h:755
time_t GetCreatedDate() const
Definition: Guild.h:758
uint32 GetMembersCount() const
Definition: Guild.h:850
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:159
Guild * GetGuild()
Definition: Player.cpp:29432
Player session in the World.
Definition: WorldSession.h:963
Player * GetPlayer() const
uint64 CreateClubMemberId(ObjectGuid guid)
Definition: ClubUtils.cpp:22