GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/familyrecv.cpp Lines: 2 41 4.9 %
Date: 2017-11-29 Branches: 2 40 5.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2017  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 "enums/resources/notifytypes.h"
29
30
#include "gui/widgets/createwidget.h"
31
32
#include "utils/gettext.h"
33
#include "utils/stringutils.h"
34
35
#include "listeners/requestadoptchildlistener.h"
36
37
#include "net/messagein.h"
38
39
#include "debug.h"
40
41
namespace EAthena
42
{
43
44
namespace FamilyRecv
45
{
46
    ConfirmDialog *confirmDlg = nullptr;
47
2
    RequestAdoptChildListener listener;
48
    BeingId mParent1 = BeingId_zero;
49
    BeingId mParent2 = BeingId_zero;
50
}  // namespace FamilyRecv
51
52
void FamilyRecv::processAskForChild(Net::MessageIn &msg)
53
{
54
    if (localPlayer == nullptr)
55
    {
56
        mParent1 = msg.readBeingId("account id who ask");
57
        mParent2 = msg.readBeingId("acoount id for other parent");
58
        msg.readString(24, "name who ask");
59
        return;
60
    }
61
    mParent1 = msg.readBeingId("account id who ask");
62
    mParent2 = msg.readBeingId("acoount id for other parent");
63
    const std::string name1 = msg.readString(24, "name who ask");
64
    const Party *const party = localPlayer->getParty();
65
    if (party != nullptr)
66
    {
67
        const PartyMember *const member = party->getMember(mParent2);
68
        if (member != nullptr)
69
        {
70
            const std::string name2 = member->getName();
71
            CREATEWIDGETV(confirmDlg, ConfirmDialog,
72
                // TRANSLATORS: adopt child message
73
                _("Request parents"),
74
                // TRANSLATORS: adopt child message
75
                strprintf(_("Do you accept %s and %s as parents?"),
76
                name1.c_str(), name2.c_str()),
77
                SOUND_REQUEST,
78
                false);
79
            confirmDlg->addActionListener(&listener);
80
        }
81
    }
82
}
83
84
void FamilyRecv::processCallPartner(Net::MessageIn &msg)
85
{
86
    const std::string name = msg.readString(24, "name");
87
    if ((localPlayer != nullptr) && name == localPlayer->getName())
88
    {
89
        NotifyManager::notify(NotifyTypes::CALLED_PARTNER);
90
    }
91
    else
92
    {
93
        NotifyManager::notify(NotifyTypes::CALLING_PARTNER, name.c_str());
94
    }
95
}
96
97
void FamilyRecv::processDivorced(Net::MessageIn &msg)
98
{
99
    const std::string name = msg.readString(24, "name");
100
    NotifyManager::notify(NotifyTypes::DIVORCED, name.c_str());
101
}
102
103
void FamilyRecv::processAskForChildReply(Net::MessageIn &msg)
104
{
105
    const int type = msg.readInt32("type");
106
    switch (type)
107
    {
108
        case 0:
109
            NotifyManager::notify(NotifyTypes::ADOPT_CHILD_ERROR_HAVE_BABY);
110
            break;
111
        case 1:
112
            NotifyManager::notify(NotifyTypes::ADOPT_CHILD_ERROR_LEVEL);
113
            break;
114
        case 2:
115
            NotifyManager::notify(NotifyTypes::ADOPT_CHILD_ERROR_BABY_MARRIED);
116
            break;
117
        default:
118
            UNIMPLEMENTEDPACKETFIELD(type);
119
            break;
120
    }
121
}
122
123

6
}  // namespace EAthena