GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/utils/gmfunctions.cpp Lines: 1 43 2.3 %
Date: 2017-11-29 Branches: 2 38 5.3 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2016-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 "utils/gmfunctions.h"
22
23
#include "settings.h"
24
25
#include "being/localplayer.h"
26
27
#include "const/gui/chat.h"
28
29
#include "net/chathandler.h"
30
31
#include "debug.h"
32
33
namespace Gm
34
{
35
36
void runCommand(const std::string &command,
37
                const std::string &params)
38
{
39
    if (params.empty())
40
    {
41
        chatHandler->talk(std::string(
42
            settings.gmCommandSymbol).append(
43
            command),
44
            GENERAL_CHANNEL);
45
    }
46
    else
47
    {
48
        chatHandler->talk(std::string(
49
            settings.gmCommandSymbol).append(
50
            command).append(
51
            " ").append(
52
            params),
53
            GENERAL_CHANNEL);
54
    }
55
}
56
57
void runCommand(const std::string &command)
58
{
59
    chatHandler->talk(std::string(
60
        settings.gmCommandSymbol).append(
61
        command),
62
        GENERAL_CHANNEL);
63
}
64
65
void runCharCommand(const std::string &command,
66
                    const std::string &name,
67
                    const std::string &params)
68
{
69
    if ((localPlayer != nullptr) && name == localPlayer->getName())
70
    {
71
        if (params.empty())
72
        {
73
            chatHandler->talk(std::string(
74
                settings.gmCommandSymbol).append(
75
                command),
76
                GENERAL_CHANNEL);
77
        }
78
        else
79
        {
80
            chatHandler->talk(std::string(
81
                settings.gmCommandSymbol).append(
82
                command).append(
83
                " ").append(
84
                params),
85
                GENERAL_CHANNEL);
86
        }
87
    }
88
    else
89
    {
90
        chatHandler->talk(std::string(
91
            settings.gmCharCommandSymbol).append(
92
            command).append(
93
            " \"").append(
94
            name).append(
95
            "\" ").append(
96
            params),
97
            GENERAL_CHANNEL);
98
    }
99
}
100
101
void runCharCommand(const std::string &command,
102
                    const std::string &name)
103
{
104
    if ((localPlayer != nullptr) && name == localPlayer->getName())
105
    {
106
        chatHandler->talk(std::string(
107
            settings.gmCommandSymbol).append(
108
            command),
109
            GENERAL_CHANNEL);
110
    }
111
    else
112
    {
113
        chatHandler->talk(std::string(
114
            settings.gmCharCommandSymbol).append(
115
            command).append(
116
            " ").append(
117
            name),
118
            GENERAL_CHANNEL);
119
    }
120
}
121
122

6
}  // namespace Gm