GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/tmwa/playerrecv.cpp Lines: 1 115 0.9 %
Date: 2018-11-12 Branches: 0 53 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2018  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#include "net/tmwa/playerrecv.h"
24
25
#include "configuration.h"
26
27
#include "being/beingflag.h"
28
#include "being/localplayer.h"
29
#include "being/playerinfo.h"
30
31
#include "gui/onlineplayer.h"
32
33
#include "gui/windows/statuswindow.h"
34
#include "gui/windows/whoisonline.h"
35
36
#include "net/messagein.h"
37
38
#include "resources/db/groupdb.h"
39
40
#include "debug.h"
41
42
namespace TmwAthena
43
{
44
45
void PlayerRecv::processPlayerStatUpdate5(Net::MessageIn &msg)
46
{
47
    BLOCK_START("PlayerRecv::processPlayerStatUpdate5")
48
    PlayerInfo::setAttribute(Attributes::PLAYER_CHAR_POINTS,
49
        msg.readInt16("char points"),
50
        Notify_true);
51
52
    unsigned int val = msg.readUInt8("str");
53
    PlayerInfo::setStatBase(Attributes::PLAYER_STR, val, Notify_true);
54
    if (statusWindow != nullptr)
55
    {
56
        statusWindow->setPointsNeeded(Attributes::PLAYER_STR,
57
            msg.readUInt8("str cost"));
58
    }
59
    else
60
    {
61
        msg.readUInt8("str cost");
62
    }
63
64
    val = msg.readUInt8("agi");
65
    PlayerInfo::setStatBase(Attributes::PLAYER_AGI, val, Notify_true);
66
    if (statusWindow != nullptr)
67
    {
68
        statusWindow->setPointsNeeded(Attributes::PLAYER_AGI,
69
            msg.readUInt8("agi cost"));
70
    }
71
    else
72
    {
73
        msg.readUInt8("agi cost");
74
    }
75
76
    val = msg.readUInt8("vit");
77
    PlayerInfo::setStatBase(Attributes::PLAYER_VIT, val, Notify_true);
78
    if (statusWindow != nullptr)
79
    {
80
        statusWindow->setPointsNeeded(Attributes::PLAYER_VIT,
81
            msg.readUInt8("vit cost"));
82
    }
83
    else
84
    {
85
        msg.readUInt8("vit cost");
86
    }
87
88
    val = msg.readUInt8("int");
89
    PlayerInfo::setStatBase(Attributes::PLAYER_INT, val, Notify_true);
90
    if (statusWindow != nullptr)
91
    {
92
        statusWindow->setPointsNeeded(Attributes::PLAYER_INT,
93
            msg.readUInt8("int cost"));
94
    }
95
    else
96
    {
97
        msg.readUInt8("int cost");
98
    }
99
100
    val = msg.readUInt8("dex");
101
    PlayerInfo::setStatBase(Attributes::PLAYER_DEX, val, Notify_true);
102
    if (statusWindow != nullptr)
103
    {
104
        statusWindow->setPointsNeeded(Attributes::PLAYER_DEX,
105
            msg.readUInt8("dex cost"));
106
    }
107
    else
108
    {
109
        msg.readUInt8("dex cost");
110
    }
111
112
    val = msg.readUInt8("luk");
113
    PlayerInfo::setStatBase(Attributes::PLAYER_LUK, val, Notify_true);
114
    if (statusWindow != nullptr)
115
    {
116
        statusWindow->setPointsNeeded(Attributes::PLAYER_LUK,
117
            msg.readUInt8("luk cost"));
118
    }
119
    else
120
    {
121
        msg.readUInt8("luk cost");
122
    }
123
124
    PlayerInfo::setStatBase(Attributes::PLAYER_ATK,
125
        msg.readInt16("atk"),
126
        Notify_false);
127
    PlayerInfo::setStatMod(Attributes::PLAYER_ATK,
128
        msg.readInt16("atk+"),
129
        Notify_true);
130
    PlayerInfo::updateAttrs();
131
132
    val = msg.readInt16("matk");
133
    PlayerInfo::setStatBase(Attributes::PLAYER_MATK, val, Notify_false);
134
135
    val = msg.readInt16("matk+");
136
    PlayerInfo::setStatMod(Attributes::PLAYER_MATK,
137
        val,
138
        Notify_true);
139
140
    PlayerInfo::setStatBase(Attributes::PLAYER_DEF,
141
        msg.readInt16("def"),
142
        Notify_false);
143
    PlayerInfo::setStatMod(Attributes::PLAYER_DEF,
144
        msg.readInt16("def+"),
145
        Notify_true);
146
147
    PlayerInfo::setStatBase(Attributes::PLAYER_MDEF,
148
        msg.readInt16("mdef"),
149
        Notify_false);
150
    PlayerInfo::setStatMod(Attributes::PLAYER_MDEF,
151
        msg.readInt16("mdef+"),
152
        Notify_true);
153
154
    PlayerInfo::setStatBase(Attributes::PLAYER_HIT,
155
        msg.readInt16("hit"),
156
        Notify_true);
157
158
    PlayerInfo::setStatBase(Attributes::PLAYER_FLEE,
159
        msg.readInt16("flee"),
160
        Notify_false);
161
    PlayerInfo::setStatMod(Attributes::PLAYER_FLEE,
162
        msg.readInt16("flee+"),
163
        Notify_true);
164
165
    PlayerInfo::setStatBase(Attributes::PLAYER_CRIT,
166
        msg.readInt16("crit"),
167
        Notify_true);
168
169
    PlayerInfo::setStatBase(Attributes::PLAYER_MANNER,
170
        msg.readInt16("manner"),
171
        Notify_true);
172
    msg.readInt16("unused?");
173
    BLOCK_END("PlayerRecv::processPlayerStatUpdate5")
174
}
175
176
void PlayerRecv::processWalkResponse(Net::MessageIn &msg)
177
{
178
    BLOCK_START("PlayerRecv::processWalkResponse")
179
    /*
180
      * This client assumes that all walk messages succeed,
181
      * and that the server will send a correction notice
182
      * otherwise.
183
      */
184
    uint16_t srcX;
185
    uint16_t srcY;
186
    uint16_t dstX;
187
    uint16_t dstY;
188
    msg.readInt32("tick");
189
    msg.readCoordinatePair(srcX, srcY, dstX, dstY, "move path");
190
    msg.readUInt8("unused");
191
    if (localPlayer != nullptr)
192
        localPlayer->setRealPos(dstX, dstY);
193
    BLOCK_END("PlayerRecv::processWalkResponse")
194
}
195
196
void PlayerRecv::processOnlineList(Net::MessageIn &msg)
197
{
198
    if (whoIsOnline == nullptr)
199
        return;
200
201
    BLOCK_START("PlayerRecv::processOnlineList")
202
    const int count = (msg.readInt16("len") - 4) / 31;
203
    STD_VECTOR<OnlinePlayer*> arr;
204
205
    if (count == 0)
206
    {
207
        if (whoIsOnline != nullptr)
208
            whoIsOnline->loadList(arr);
209
        BLOCK_END("PlayerRecv::processOnlineList")
210
        return;
211
    }
212
213
    for (int f = 0; f < count; f ++)
214
    {
215
        msg.readBeingId("account id");
216
        const std::string name = msg.readString(24, "name");
217
        const unsigned char level = msg.readUInt8("level");
218
        const unsigned char group = msg.readUInt8("group");
219
        GenderT gender = static_cast<GenderT>(msg.readUInt8("gender"));
220
        unsigned char status = 0;
221
        switch (gender)
222
        {
223
            case Gender::MALE:
224
                status |= BeingFlag::GENDER_MALE;
225
                break;
226
            case Gender::HIDDEN:
227
                status |= BeingFlag::GENDER_HIDDEN;
228
                break;
229
            case Gender::FEMALE:
230
            case Gender::UNSPECIFIED:
231
            default:
232
                break;
233
        }
234
        if (GroupDb::getShowBadge(group))
235
            status |= BeingFlag::GM;
236
        if (!config.getBoolValue("showgender"))
237
            gender = Gender::UNSPECIFIED;
238
        arr.push_back(new OnlinePlayer(name,
239
            status, level, gender, 0));
240
    }
241
242
    if (whoIsOnline != nullptr)
243
        whoIsOnline->loadList(arr);
244
    BLOCK_END("PlayerRecv::processOnlineList")
245
}
246
247
2
}  // namespace TmwAthena