aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Petitions/PetitionMgr.h
blob: 1de39cc159d27758f62f598f434efb2eee0621cb (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
85
86
87
88
89
90
91
92
93
/*
 * 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/>.
 */

#ifndef _PETITIONMGR_H
#define _PETITIONMGR_H

#include "Define.h"
#include "ObjectGuid.h"
#include <string>
#include <utility>
#include <vector>

enum PetitionTurns
{
    PETITION_TURN_OK                    = 0,
    PETITION_TURN_ALREADY_IN_GUILD      = 2,
    PETITION_TURN_NEED_MORE_SIGNATURES  = 4,
    PETITION_TURN_GUILD_PERMISSIONS     = 11,
    PETITION_TURN_GUILD_NAME_INVALID    = 12,
    PETITION_TURN_HAS_RESTRICTION       = 13
};

enum PetitionSigns
{
    PETITION_SIGN_OK                        = 0,
    PETITION_SIGN_ALREADY_SIGNED            = 1,
    PETITION_SIGN_ALREADY_IN_GUILD          = 2,
    PETITION_SIGN_CANT_SIGN_OWN             = 3,
    PETITION_SIGN_NOT_SERVER                = 5,
    PETITION_SIGN_FULL                      = 8,
    PETITION_SIGN_ALREADY_SIGNED_OTHER      = 10,
    PETITION_SIGN_RESTRICTED_ACCOUNT_TRIAL  = 11,
    PETITION_SIGN_HAS_RESTRICTION           = 13
};

typedef std::pair<uint32, ObjectGuid> Signature;
typedef std::vector<Signature> SignaturesVector;

struct Petition
{
    ObjectGuid       PetitionGuid;
    ObjectGuid       OwnerGuid;
    std::string      PetitionName;
    SignaturesVector Signatures;

    bool IsPetitionSignedByAccount(uint32 accountId) const;
    void AddSignature(uint32 accountId, ObjectGuid playerGuid, bool isLoading);
    void UpdateName(std::string const& newName);
    void RemoveSignatureBySigner(ObjectGuid playerGuid);
};

class TC_GAME_API PetitionMgr
{
    public:
        PetitionMgr() = default;
        PetitionMgr(PetitionMgr const&) = delete;
        PetitionMgr(PetitionMgr&&) = delete;
        PetitionMgr& operator=(PetitionMgr const&) = delete;
        PetitionMgr& operator=(PetitionMgr&&) = delete;
        ~PetitionMgr() = default;

        static PetitionMgr* instance();

        // Load from DB
        void LoadPetitions();
        void LoadSignatures();

        // Petitions
        void AddPetition(ObjectGuid petitionGuid, ObjectGuid ownerGuid, std::string const& name, bool isLoading);
        void RemovePetition(ObjectGuid petitionGuid);
        Petition* GetPetition(ObjectGuid petitionGuid);
        Petition* GetPetitionByOwner(ObjectGuid ownerGuid);
        void RemovePetitionsByOwner(ObjectGuid ownerGuid);
        void RemoveSignaturesBySigner(ObjectGuid signerGuid);
};

#define sPetitionMgr PetitionMgr::instance()

#endif