1 /***************************************************************************
2 * Copyright (C) 2008 by Sverre Rabbelier *
3 * sverre@rabbelier.nl *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
26 #include "CommandManager.h"
31 #include "Permission.h"
32 #include "PermissionManager.h"
33 #include "StringUtilities.h"
36 using mud::Permission
;
39 Editor::Editor(UBSocket
* sock
) :
50 std::string
Editor::prompt()
52 return Global::Get()->EmptyString
;
55 std::string
Editor::lookup(const std::string
& action
)
57 return Global::Get()->EmptyString
;
60 void Editor::Send(const std::string
& msg
)
65 void Editor::Sendf(const char* format
, ...)
68 va_start(args
, format
);
69 Send(Global::Get()->sprint(args
, format
));
73 void Editor::Disconnect()
75 m_sock
->SetCloseAndDelete();
78 void Editor::OnLine(const std::string
& line
)
81 Assert(m_sock
->hasAccount());
84 std::string rawaction
= p
.getword();
85 std::string action
= String::Get()->tolower(rawaction
);
87 bool helpLookup
= false;
89 if(!action
.compare("help"))
92 rawaction
= p
.getword();
93 action
= String::Get()->tolower(rawaction
);
95 if(!action
.compare("help"))
97 Send("Syntax: help <command>\n");
98 Send("This command will lookup information on <command> and display it.\n");
103 std::string argument
= p
.getrest();
104 std::string actionname
= lookup(action
);
106 if(actionname
.size() == 0)
108 // TODO: Log failure?
109 Sendf("Unknown action '%s', type ? for a list of available actions.\n", action
.c_str());
113 std::string commandname
= name();
114 commandname
.append("::");
115 commandname
.append(actionname
);
117 bool hasGrant
= mud::Managers::Get()->Permission
->defaultGrant
;
118 bool hasLog
= mud::Managers::Get()->Permission
->defaultLog
;
120 bool canLowForce
= mud::Managers::Get()->Command
->defaultLowForce
;
121 bool canForce
= mud::Managers::Get()->Command
->defaultForce
;
122 bool canHighForce
= mud::Managers::Get()->Command
->defaultHighForce
;
124 bool isLowForced
= m_sock
->isLowForced();
125 bool isNormalForced
= m_sock
->isForced();
126 bool isHighForced
= m_sock
->isHighForced();
127 bool isForced
= isLowForced
|| isNormalForced
|| isHighForced
;
131 long id
= mud::Managers::Get()->Command
->lookupByName(commandname
);
132 mud::CommandPtr cmd
= mud::Managers::Get()->Command
->GetByKey(id
);
136 std::string help
= cmd
->getHelp();
139 Sendf("Sorry, we do not have help available on '%s'.\n", action
.c_str());
143 Sendf("We have the following information on '%s':\n", action
.c_str());
149 hasGrant
= cmd
->getGrant(m_sock
->GetAccount()->getID());
150 hasLog
= cmd
->getLog(m_sock
->GetAccount()->getID());
154 canHighForce
= cmd
->canHighForce();
155 canForce
= cmd
->canForce();
156 canLowForce
= cmd
->canLowForce();
159 catch(RowNotFoundException
& e
)
163 Sendf("Sorry, '%s' has not yet been added to the database, as a result no help is available for it yet.\n", action
.c_str());
171 if(isLowForced
&& !canLowForce
)
173 m_sock
->GetForcer()->Sendf("You can't make them to '%s'!\n", action
.c_str());
177 if(isForced
&& !canForce
)
179 m_sock
->GetForcer()->Sendf("You can't force them to '%s'!\n", action
.c_str());
183 if(isHighForced
&& !canHighForce
)
185 m_sock
->GetForcer()->Sendf("There is no way you can make them '%s'!\n", action
.c_str());
192 if(hasLog
|| isForced
)
204 dispatch(action
, argument
);
209 if(hasLog
|| isForced
)
213 m_sock
->GetForcer()->Sendf("They are not allowed to '%s'!\n", action
.c_str());
223 Sendf("Sorry, you do not have permission to '%s'.\n", actionname
.c_str());
228 bool Editor::canReceiveChannel(mud::ChannelPtr channel
) const
233 bool Editor::supportPrefixes() const