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 ***************************************************************************/
25 #include "Permission.h"
26 #include "PermissionManager.h"
28 #include "CommandManager.h"
32 #include "StringUtilities.h"
35 using mud::Permission
;
38 Editor::Editor(UBSocket
* sock
) :
49 std::string
Editor::prompt()
51 return Global::Get()->EmptyString
;
54 std::string
Editor::lookup(const std::string
& action
)
56 return Global::Get()->EmptyString
;
59 void Editor::Send(const std::string
& msg
)
64 void Editor::Sendf(const char* format
, ...)
67 va_start(args
, format
);
68 Send(Global::Get()->sprint(args
, format
));
72 void Editor::Disconnect()
74 m_sock
->SetCloseAndDelete();
77 void Editor::OnLine(const std::string
& line
)
80 std::string rawaction
= p
.getword();
81 std::string action
= String::Get()->tolower(rawaction
);
83 bool helpLookup
= false;
85 if(!action
.compare("help"))
88 rawaction
= p
.getword();
89 action
= String::Get()->tolower(rawaction
);
91 if(!action
.compare("help"))
93 Send("Syntax: help <command>\n");
94 Send("This command will lookup information on <command> and display it.\n");
99 std::string argument
= p
.getrest();
100 std::string actionname
= lookup(action
);
102 if(actionname
.size() == 0)
104 // TODO: Log failure?
105 Sendf("Unknown action '%s', type ? for a list of available actions.\n", action
.c_str());
109 std::string commandname
= name();
110 commandname
.append("::");
111 commandname
.append(actionname
);
113 bool hasGrant
= mud::PermissionManager::Get()->defaultGrant
;
114 bool hasLog
= mud::PermissionManager::Get()->defaultLog
;
116 bool canLowForce
= mud::CommandManager::Get()->defaultLowForce
;
117 bool canForce
= mud::CommandManager::Get()->defaultForce
;
118 bool canHighForce
= mud::CommandManager::Get()->defaultHighForce
;
120 bool isLowForced
= m_sock
->isLowForced();
121 bool isNormalForced
= m_sock
->isForced();
122 bool isHighForced
= m_sock
->isHighForced();
123 bool isForced
= isLowForced
|| isNormalForced
|| isHighForced
;
127 long id
= mud::CommandManager::Get()->lookupByName(commandname
);
128 mud::CommandPtr cmd
= mud::CommandManager::Get()->GetByKey(id
);
132 std::string help
= cmd
->getHelp();
135 Sendf("Sorry, we do not have help available on '%s'.\n", action
.c_str());
139 Sendf("We have the following information on '%s':\n", action
.c_str());
145 hasGrant
= cmd
->getGrant(m_sock
);
146 hasLog
= cmd
->getLog(m_sock
);
150 canHighForce
= cmd
->canHighForce();
151 canForce
= cmd
->canForce();
152 canLowForce
= cmd
->canLowForce();
155 catch(RowNotFoundException
& e
)
159 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());
167 if(isLowForced
&& !canLowForce
)
169 m_sock
->GetForcer()->Sendf("You can't make them to '%s'!\n", action
.c_str());
173 if(isForced
&& !canForce
)
175 m_sock
->GetForcer()->Sendf("You can't force them to '%s'!\n", action
.c_str());
179 if(isHighForced
&& !canHighForce
)
181 m_sock
->GetForcer()->Sendf("There is no way you can make them '%s'!\n", action
.c_str());
188 if(hasLog
|| isForced
)
200 dispatch(action
, argument
);
205 if(hasLog
|| isForced
)
209 m_sock
->GetForcer()->Sendf("They are not allowed to '%s'!\n", action
.c_str());
219 Sendf("Sorry, you do not have permission to '%s'.\n", actionname
.c_str());
224 bool Editor::canReceiveChannel(mud::ChannelPtr channel
) const
229 bool Editor::supportPrefixes() const