GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/familyrecv.cpp Lines: 2 38 5.3 %
Date: 2021-03-17 Branches: 2 44 4.5 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2019  The ManaPlus Developers
4
 *  Copyright (C) 2019-2021  Andrei Karas
5
 *
6
 *  This file is part of The ManaPlus Client.
7
 *
8
 *  This program is free software; you can redistribute it and/or modify
9
 *  it under the terms of the GNU General Public License as published by
10
 *  the Free Software Foundation; either version 2 of the License, or
11
 *  any later version.
12
 *
13
 *  This program is distributed in the hope that it will be useful,
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *  GNU General Public License for more details.
17
 *
18
 *  You should have received a copy of the GNU General Public License
19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
#include "net/eathena/familyrecv.h"
23
24
#include "notifymanager.h"
25
#include "party.h"
26
27
#include "being/localplayer.h"
28
29
#include "const/sound.h"
30
31
#include "enums/resources/notifytypes.h"
32
33
#include "gui/widgets/createwidget.h"
34
35
#include "utils/gettext.h"
36
#include "utils/stringutils.h"
37
38
#include "listeners/requestadoptchildlistener.h"
39
40
#include "net/messagein.h"
41
42
#include "debug.h"
43
44
namespace EAthena
45
{
46
47
namespace FamilyRecv
48
{
49
    ConfirmDialog *confirmDlg = nullptr;
50
1
    RequestAdoptChildListener listener;
51
    BeingId mParent1 = BeingId_zero;
52
    BeingId mParent2 = BeingId_zero;
53
}  // namespace FamilyRecv
54
55
void FamilyRecv::processAskForChild(Net::MessageIn &msg)
56
{
57
    if (localPlayer == nullptr)
58
    {
59
        mParent1 = msg.readBeingId("account id who ask");
60
        mParent2 = msg.readBeingId("acoount id for other parent");
61
        msg.readString(24, "name who ask");
62
        return;
63
    }
64
    mParent1 = msg.readBeingId("account id who ask");
65
    mParent2 = msg.readBeingId("acoount id for other parent");
66
    const std::string name1 = msg.readString(24, "name who ask");
67
    const Party *const party = localPlayer->getParty();
68
    if (party != nullptr)
69
    {
70
        const PartyMember *const member = party->getMember(mParent2);
71
        if (member != nullptr)
72
        {
73
            const std::string name2 = member->getName();
74
            CREATEWIDGETV(confirmDlg, ConfirmDialog,
75
                // TRANSLATORS: adopt child message
76
                _("Request parents"),
77
                // TRANSLATORS: adopt child message
78
                strprintf(_("Do you accept %s and %s as parents?"),
79
                name1.c_str(), name2.c_str()),
80
                SOUND_REQUEST,
81
                false,
82
                Modal_false,
83
                nullptr);
84
            confirmDlg->addActionListener(&listener);
85
        }
86
    }
87
}
88
89
void FamilyRecv::processCallPartner(Net::MessageIn &msg)
90
{
91
    const std::string name = msg.readString(24, "name");
92
    if ((localPlayer != nullptr) && name == localPlayer->getName())
93
    {
94
        NotifyManager::notify(NotifyTypes::CALLED_PARTNER);
95
    }
96
    else
97
    {
98
        NotifyManager::notify(NotifyTypes::CALLING_PARTNER, name.c_str());
99
    }
100
}
101
102
void FamilyRecv::processDivorced(Net::MessageIn &msg)
103
{
104
    const std::string name = msg.readString(24, "name");
105
    NotifyManager::notify(NotifyTypes::DIVORCED, name.c_str());
106
}
107
108
void FamilyRecv::processAskForChildReply(Net::MessageIn &msg)
109
{
110
    const int type = msg.readInt32("type");
111
    switch (type)
112
    {
113
        case 0:
114
            NotifyManager::notify(NotifyTypes::ADOPT_CHILD_ERROR_HAVE_BABY);
115
            break;
116
        case 1:
117
            NotifyManager::notify(NotifyTypes::ADOPT_CHILD_ERROR_LEVEL);
118
            break;
119
        case 2:
120
            NotifyManager::notify(NotifyTypes::ADOPT_CHILD_ERROR_BABY_MARRIED);
121
            break;
122
        default:
123
            UNIMPLEMENTEDPACKETFIELD(type);
124
            break;
125
    }
126
}
127
128

3
}  // namespace EAthena