GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/utils/gmfunctions.cpp Lines: 1 36 2.8 %
Date: 2018-09-20 Branches: 0 44 0.0 %

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