GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/clanhandler.cpp Lines: 1 18 5.6 %
Date: 2018-09-20 Branches: 0 20 0.0 %

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/clanhandler.h"
22
23
#include "being/localplayer.h"
24
25
#include "net/eathena/messageout.h"
26
#include "net/eathena/protocolout.h"
27
28
#include "debug.h"
29
30
extern int packetVersion;
31
32
namespace EAthena
33
{
34
35
ClanHandler::ClanHandler() :
36
    Net::ClanHandler()
37
{
38
    clanHandler = this;
39
}
40
41
ClanHandler::~ClanHandler()
42
{
43
    clanHandler = nullptr;
44
}
45
46
void ClanHandler::chat(const std::string &restrict text) const
47
{
48
    if (localPlayer == nullptr)
49
        return;
50
51
    if (packetVersion < 20120716)
52
        return;
53
54
    const std::string mes = std::string(localPlayer->getName()).append(
55
        " : ").append(text);
56
57
    createOutPacket(CMSG_CLAN_MESSAGE);
58
    if (packetVersion >= 20151001)
59
    {
60
        outMsg.writeInt16(CAST_S16(mes.length() + 4), "len");
61
        outMsg.writeString(mes, CAST_S32(mes.length()), "message");
62
    }
63
    else
64
    {
65
        // Added + 1 in order to let eAthena parse admin commands correctly
66
        outMsg.writeInt16(CAST_S16(mes.length() + 4 + 1), "len");
67
        outMsg.writeString(mes, CAST_S32(mes.length() + 1), "message");
68
    }
69
}
70
71
2
}  // namespace EAthena