aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Services/ClubMembershipService.cpp
blob: 1d4bf487380c5c47a6e0bb505025f40061d12516 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#include "ClubMembershipService.h"
#include "BattlenetRpcErrorCodes.h"
#include "CharacterCache.h"
#include "ClubService.h"
#include "ClubUtils.h"
#include "Guild.h"
#include "Player.h"

namespace Battlenet::Services
{
ClubMembershipService::ClubMembershipService(WorldSession* session) : BaseService(session) { }

uint32 ClubMembershipService::HandleSubscribe(club_membership::v1::client::SubscribeRequest const* /*request*/, club_membership::v1::client::SubscribeResponse* response,
    std::function<void(ServiceBase*, uint32, google::protobuf::Message const*)>& /*continuation*/)
{
    Player const* player = _session->GetPlayer();

    if (!player)
        return ERROR_INTERNAL;

    Guild const* guild = player->GetGuild();

    if (!guild)
        return ERROR_OK;

    club_membership::v1::client::ClubMembershipDescription* description = response->mutable_state()->add_description();
    description->set_allocated_member_id(CreateClubMemberId(player->GetGUID()).release());

    club::v1::ClubDescription* club = description->mutable_club();
    club->set_id(guild->GetId());
    club->set_allocated_type(ClubService::CreateGuildClubType().release());
    club->set_name(guild->GetName());
    club->set_privacy_level(club::v1::PrivacyLevel::PRIVACY_LEVEL_OPEN);
    club->set_visibility_level(club::v1::VISIBILITY_LEVEL_PRIVATE);
    club->set_member_count(guild->GetMembersCount());
    club->set_creation_time(
        std::chrono::duration_cast<std::chrono::microseconds>(SystemTimePoint::clock::from_time_t(guild->GetCreatedDate()).time_since_epoch()).count());

    // Not setting these can cause issues.
    club->set_timezone("");
    club->set_locale("");

    club::v1::client::MemberDescription* leader = club->add_leader();

    leader->set_allocated_id(CreateClubMemberId(guild->GetLeaderGUID()).release());

    response->mutable_state()->mutable_mention_view()->set_last_read_time(0);
    response->mutable_state()->mutable_mention_view()->set_last_message_time(0);

    return ERROR_OK;
}

uint32 ClubMembershipService::HandleUnsubscribe(club_membership::v1::client::UnsubscribeRequest const* /*request*/, NoData* /*response*/,
    std::function<void(ServiceBase*, uint32, google::protobuf::Message const*)>& /*continuation*/)
{
    // We just have to signal the client that the unsubscribe request came through.
    return ERROR_OK;
}

std::unique_ptr<club::v1::MemberId> ClubMembershipService::CreateClubMemberId(ObjectGuid guid)
{
    std::unique_ptr<club::v1::MemberId> id = std::make_unique<club::v1::MemberId>();
    id->set_account_id(sCharacterCache->GetCharacterAccountIdByGuid(guid));
    id->set_unique_id(Clubs::CreateClubMemberId(guid));
    return id;
}
}