GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/tmwa/playerrecv.cpp Lines: 1 115 0.9 %
Date: 2019-02-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-2019  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 "actormanager.h"
26
#include "configuration.h"
27
28
#include "being/beingflag.h"
29
#include "being/localplayer.h"
30
#include "being/playerinfo.h"
31
32
#include "gui/onlineplayer.h"
33
34
#include "gui/windows/statuswindow.h"
35
#include "gui/windows/whoisonline.h"
36
37
#include "net/messagein.h"
38
39
#include "debug.h"
40
41
extern unsigned int tmwServerVersion;
42
43
namespace TmwAthena
44
{
45
46
void PlayerRecv::processPlayerStatUpdate5(Net::MessageIn &msg)
47
{
48
    BLOCK_START("PlayerRecv::processPlayerStatUpdate5")
49
    PlayerInfo::setAttribute(Attributes::PLAYER_CHAR_POINTS,
50
        msg.readInt16("char points"),
51
        Notify_true);
52
53
    unsigned int val = msg.readUInt8("str");
54
    PlayerInfo::setStatBase(Attributes::PLAYER_STR, val, Notify_true);
55
    if (statusWindow != nullptr)
56
    {
57
        statusWindow->setPointsNeeded(Attributes::PLAYER_STR,
58
            msg.readUInt8("str cost"));
59
    }
60
    else
61
    {
62
        msg.readUInt8("str cost");
63
    }
64
65
    val = msg.readUInt8("agi");
66
    PlayerInfo::setStatBase(Attributes::PLAYER_AGI, val, Notify_true);
67
    if (statusWindow != nullptr)
68
    {
69
        statusWindow->setPointsNeeded(Attributes::PLAYER_AGI,
70
            msg.readUInt8("agi cost"));
71
    }
72
    else
73
    {
74
        msg.readUInt8("agi cost");
75
    }
76
77
    val = msg.readUInt8("vit");
78
    PlayerInfo::setStatBase(Attributes::PLAYER_VIT, val, Notify_true);
79
    if (statusWindow != nullptr)
80
    {
81
        statusWindow->setPointsNeeded(Attributes::PLAYER_VIT,
82
            msg.readUInt8("vit cost"));
83
    }
84
    else
85
    {
86
        msg.readUInt8("vit cost");
87
    }
88
89
    val = msg.readUInt8("int");
90
    PlayerInfo::setStatBase(Attributes::PLAYER_INT, val, Notify_true);
91
    if (statusWindow != nullptr)
92
    {
93
        statusWindow->setPointsNeeded(Attributes::PLAYER_INT,
94
            msg.readUInt8("int cost"));
95
    }
96
    else
97
    {
98
        msg.readUInt8("int cost");
99
    }
100
101
    val = msg.readUInt8("dex");
102
    PlayerInfo::setStatBase(Attributes::PLAYER_DEX, val, Notify_true);
103
    if (statusWindow != nullptr)
104
    {
105
        statusWindow->setPointsNeeded(Attributes::PLAYER_DEX,
106
            msg.readUInt8("dex cost"));
107
    }
108
    else
109
    {
110
        msg.readUInt8("dex cost");
111
    }
112
113
    val = msg.readUInt8("luk");
114
    PlayerInfo::setStatBase(Attributes::PLAYER_LUK, val, Notify_true);
115
    if (statusWindow != nullptr)
116
    {
117
        statusWindow->setPointsNeeded(Attributes::PLAYER_LUK,
118
            msg.readUInt8("luk cost"));
119
    }
120
    else
121
    {
122
        msg.readUInt8("luk cost");
123
    }
124
125
    PlayerInfo::setStatBase(Attributes::PLAYER_ATK,
126
        msg.readInt16("atk"),
127
        Notify_false);
128
    PlayerInfo::setStatMod(Attributes::PLAYER_ATK,
129
        msg.readInt16("atk+"),
130
        Notify_true);
131
    PlayerInfo::updateAttrs();
132
133
    val = msg.readInt16("matk");
134
    PlayerInfo::setStatBase(Attributes::PLAYER_MATK, val, Notify_false);
135
136
    val = msg.readInt16("matk+");
137
    PlayerInfo::setStatMod(Attributes::PLAYER_MATK,
138
        val,
139
        Notify_true);
140
141
    PlayerInfo::setStatBase(Attributes::PLAYER_DEF,
142
        msg.readInt16("def"),
143
        Notify_false);
144
    PlayerInfo::setStatMod(Attributes::PLAYER_DEF,
145
        msg.readInt16("def+"),
146
        Notify_true);
147
148
    PlayerInfo::setStatBase(Attributes::PLAYER_MDEF,
149
        msg.readInt16("mdef"),
150
        Notify_false);
151
    PlayerInfo::setStatMod(Attributes::PLAYER_MDEF,
152
        msg.readInt16("mdef+"),
153
        Notify_true);
154
155
    PlayerInfo::setStatBase(Attributes::PLAYER_HIT,
156
        msg.readInt16("hit"),
157
        Notify_true);
158
159
    PlayerInfo::setStatBase(Attributes::PLAYER_FLEE,
160
        msg.readInt16("flee"),
161
        Notify_false);
162
    PlayerInfo::setStatMod(Attributes::PLAYER_FLEE,
163
        msg.readInt16("flee+"),
164
        Notify_true);
165
166
    PlayerInfo::setStatBase(Attributes::PLAYER_CRIT,
167
        msg.readInt16("crit"),
168
        Notify_true);
169
170
    PlayerInfo::setStatBase(Attributes::PLAYER_MANNER,
171
        msg.readInt16("manner"),
172
        Notify_true);
173
    msg.readInt16("unused?");
174
    BLOCK_END("PlayerRecv::processPlayerStatUpdate5")
175
}
176
177
void PlayerRecv::processWalkResponse(Net::MessageIn &msg)
178
{
179
    BLOCK_START("PlayerRecv::processWalkResponse")
180
    /*
181
      * This client assumes that all walk messages succeed,
182
      * and that the server will send a correction notice
183
      * otherwise.
184
      */
185
    uint16_t srcX;
186
    uint16_t srcY;
187
    uint16_t dstX;
188
    uint16_t dstY;
189
    msg.readInt32("tick");
190
    msg.readCoordinatePair(srcX, srcY, dstX, dstY, "move path");
191
    msg.readUInt8("unused");
192
    if (localPlayer != nullptr)
193
        localPlayer->setRealPos(dstX, dstY);
194
    BLOCK_END("PlayerRecv::processWalkResponse")
195
}
196
197
void PlayerRecv::processOnlineList(Net::MessageIn &msg)
198
{
199
    if (whoIsOnline == nullptr)
200
        return;
201
202
    BLOCK_START("PlayerRecv::processOnlineList")
203
    const int count = (msg.readInt16("len") - 4) / 31;
204
    STD_VECTOR<OnlinePlayer*> arr;
205
206
    if (count == 0)
207
    {
208
        if (whoIsOnline != nullptr)
209
            whoIsOnline->loadList(arr);
210
        BLOCK_END("PlayerRecv::processOnlineList")
211
        return;
212
    }
213
214
    for (int f = 0; f < count; f ++)
215
    {
216
        const BeingId beingId = msg.readBeingId("account id");
217
        const std::string name = msg.readString(24, "name");
218
        const unsigned char level = msg.readUInt8("level");
219
        const unsigned char group = msg.readUInt8("group");
220
        GenderT gender = Being::intToGender(msg.readUInt8("gender"));
221
        unsigned char status = 0;
222
        switch (gender)
223
        {
224
            case Gender::MALE:
225
                status |= BeingFlag::GENDER_MALE;
226
                break;
227
            case Gender::HIDDEN:
228
                status |= BeingFlag::GENDER_HIDDEN;
229
                break;
230
            case Gender::FEMALE:
231
            case Gender::UNSPECIFIED:
232
            default:
233
                break;
234
        }
235
236
        if (!config.getBoolValue("showgender"))
237
            gender = Gender::UNSPECIFIED;
238
        arr.push_back(new OnlinePlayer(name,
239
            status, level, gender, 0, group));
240
        if (actorManager)
241
            actorManager->updateNameId(name, beingId);
242
    }
243
244
    if (whoIsOnline != nullptr)
245
        whoIsOnline->loadList(arr);
246
    BLOCK_END("PlayerRecv::processOnlineList")
247
}
248
249
2
}  // namespace TmwAthena