ManaPlus
gmfunctions.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2016-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "utils/gmfunctions.h"
23 
24 #include "settings.h"
25 
26 #include "being/localplayer.h"
27 
28 #include "net/chathandler.h"
29 
30 #include "debug.h"
31 
32 namespace Gm
33 {
34 
35 void runCommand(const std::string &command,
36  const std::string &params)
37 {
38  if (params.empty())
39  {
40  chatHandler->talk(std::string(
41  settings.gmCommandSymbol).append(
42  command));
43  }
44  else
45  {
46  chatHandler->talk(std::string(
47  settings.gmCommandSymbol).append(
48  command).append(
49  " ").append(
50  params));
51  }
52 }
53 
54 void runCommand(const std::string &command)
55 {
56  chatHandler->talk(std::string(
57  settings.gmCommandSymbol).append(
58  command));
59 }
60 
61 void runCharCommand(const std::string &command,
62  const std::string &name,
63  const std::string &params)
64 {
65  if ((localPlayer != nullptr) && name == localPlayer->getName())
66  {
67  if (params.empty())
68  {
69  chatHandler->talk(std::string(
70  settings.gmCommandSymbol).append(
71  command));
72  }
73  else
74  {
75  chatHandler->talk(std::string(
76  settings.gmCommandSymbol).append(
77  command).append(
78  " ").append(
79  params));
80  }
81  }
82  else
83  {
84  chatHandler->talk(std::string(
86  command).append(
87  " \"").append(
88  name).append(
89  "\" ").append(
90  params));
91  }
92 }
93 
94 void runCharCommand(const std::string &command,
95  const std::string &name)
96 {
97  if ((localPlayer != nullptr) && name == localPlayer->getName())
98  {
99  chatHandler->talk(std::string(
100  settings.gmCommandSymbol).append(
101  command));
102  }
103  else
104  {
105  chatHandler->talk(std::string(
107  command).append(
108  " \"").append(
109  name).append(
110  "\" "));
111  }
112 }
113 
114 } // namespace Gm
Net::ChatHandler * chatHandler
Definition: net.cpp:86
const std::string & getName() const
Definition: being.h:232
virtual void talk(const std::string &text) const =0
std::string gmCharCommandSymbol
Definition: settings.h:126
std::string gmCommandSymbol
Definition: settings.h:125
LocalPlayer * localPlayer
void runCommand(const std::string &command, const std::string &params)
Definition: gmfunctions.cpp:35
void runCharCommand(const std::string &command, const std::string &name, const std::string &params)
Definition: gmfunctions.cpp:61
Settings settings
Definition: settings.cpp:32