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

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

3
}  // namespace EAthena