GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/net/eathena/clanrecv.cpp Lines: 0 48 0.0 %
Date: 2018-05-24 20:11:55 Branches: 0 48 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/clanrecv.h"
22
23
#include "configuration.h"
24
25
#include "being/localclan.h"
26
27
#include "gui/widgets/tabs/chat/clantab.h"
28
29
#include "gui/windows/chatwindow.h"
30
#include "gui/windows/clanwindow.h"
31
32
#include "net/messagein.h"
33
34
#include "utils/checkutils.h"
35
#include "utils/delete2.h"
36
37
#include "resources/claninfo.h"
38
39
#include "resources/db/clandb.h"
40
41
#include "debug.h"
42
43
namespace EAthena
44
{
45
46
void ClanRecv::processClanInfo(Net::MessageIn &msg)
47
{
48
    msg.readInt16("len");
49
    localClan.id = msg.readInt32("clan id");
50
    localClan.name = msg.readString(24, "clan name");
51
    localClan.masterName = msg.readString(24, "master name");
52
    localClan.mapName = msg.readString(16, "map name");
53
    const int allyCount = msg.readUInt8("ally clans count");
54
    const int antagonistCount = msg.readUInt8("antagonist clans count");
55
    for (int f = 0; f < allyCount; f ++)
56
    {
57
        localClan.allyClans.push_back(
58
            msg.readString(24, "ally clan name"));
59
    }
60
    for (int f = 0; f < antagonistCount; f ++)
61
    {
62
        localClan.antagonistClans.push_back(
63
            msg.readString(24, "antagonist clan name"));
64
    }
65
    const ClanInfo *const info = ClanDb::get(localClan.id);
66
    if (info == nullptr)
67
    {
68
        reportAlways("missing clan %d in clandb",
69
            localClan.id);
70
    }
71
    else
72
    {
73
        localClan.stats = info->stats;
74
    }
75
    createTab();
76
    clanWindow->updateClan();
77
}
78
79
void ClanRecv::processClanOnlineCount(Net::MessageIn &msg)
80
{
81
    localClan.onlineMembers = msg.readInt16("online members count");
82
    localClan.totalMembers = msg.readInt16("total members count");
83
    clanWindow->updateClanMembers();
84
}
85
86
void ClanRecv::processClanLeave(Net::MessageIn &msg A_UNUSED)
87
{
88
    delete2(clanTab);
89
    localClan.clear();
90
    clanWindow->resetClan();
91
}
92
93
void ClanRecv::processClanChat(Net::MessageIn &msg)
94
{
95
    const int chatMsgLength = msg.readInt16("len") - 4 - 24;
96
    if (chatMsgLength <= 0)
97
        return;
98
    msg.readString(24, "player name (unused)");
99
    std::string chatMsg = msg.readString(chatMsgLength, "message");
100
    if (clanTab == nullptr)
101
    {
102
        reportAlways("received clan chat messages without clan.");
103
        return;
104
    }
105
    const size_t pos = chatMsg.find(" : ", 0);
106
    if (pos != std::string::npos)
107
    {
108
        const std::string sender_name = chatMsg.substr(0, pos);
109
        chatMsg.erase(0, pos + 3);
110
        trim(chatMsg);
111
        clanTab->chatLog(sender_name, chatMsg);
112
    }
113
    else
114
    {
115
        clanTab->chatLog(chatMsg,
116
            ChatMsgType::BY_SERVER,
117
            IgnoreRecord_false,
118
            TryRemoveColors_true);
119
    }
120
}
121
122
void ClanRecv::createTab()
123
{
124
    if (clanTab != nullptr)
125
        return;
126
    clanTab = new ClanTab(chatWindow);
127
    if (config.getBoolValue("showChatHistory"))
128
        clanTab->loadFromLogFile("#Clan");
129
}
130
131
}  // namespace EAthena