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 ***************************************************************************/
21 #include "EditorGrantGroup.h"
22 #include "EditorOLC.h"
24 #include "StringUtilities.h"
25 #include "TableImpls.h"
28 #include "GrantGroup.h"
29 #include "GrantGroupManager.h"
32 using mud::GrantGroup
;
34 typedef EditorGrantGroup E
;
35 typedef CommandInfoObject
<E
> O
;
36 typedef CommandBinding
<E
> B
;
38 // name function need: object lock
39 static O
editName( "Name", &E::editName
, true, true);
40 static O
editImplication("Description", &E::editImplication
, true, true);
41 static O
showGrantGroup("Show", &E::showGrantGroup
, true, false);
42 static O
saveGrantGroup("Save", &E::saveGrantGroup
, true, false);
44 static const B commands
[] = {
45 B("implication", editImplication
),
47 B("save", saveGrantGroup
),
48 B("show", showGrantGroup
),
51 EditorGrantGroup::EditorGrantGroup(UBSocket
* sock
) :
53 m_commands(commands
, array_size(commands
)),
56 listCommands(Global::Get()->EmptyString
);
59 EditorGrantGroup::~EditorGrantGroup(void)
64 std::string
EditorGrantGroup::lookup(const std::string
& action
)
66 std::string name
= OLCEditor::lookup(action
);
70 const GrantGroupCommand
* act
= (GrantGroupCommand
*)m_commands
.getObject(action
);
72 return act
->getName();
74 return Global::Get()->EmptyString
;
77 void EditorGrantGroup::dispatch(const std::string
& action
, const std::string
& argument
)
79 const GrantGroupCommand
* act
= (GrantGroupCommand
*)m_commands
.getObject(action
);
83 OLCEditor::dispatch(action
, argument
);
89 m_sock
->Send("You need to be editing a grantgroup first.\n");
90 m_sock
->Send("(Use the 'edit' command.)\n");
98 } catch(SavableLocked
& e
) {
99 m_sock
->Send("The grantgroup you are currently editing is locked (being edited by someone else), so you cannot edit it right now.\n");
100 m_sock
->Send("Please try again later.\n");
105 act
->Run(this, argument
);
109 SavablePtr
EditorGrantGroup::getEditing()
114 TableImplPtr
EditorGrantGroup::getTable()
116 return db::TableImpls::Get()->GRANTGROUPS
;
119 KeysPtr
EditorGrantGroup::addNew()
121 return mud::Managers::Get()->GrantGroup
->Add();
124 std::vector
<std::string
> EditorGrantGroup::getList()
126 return mud::Managers::Get()->GrantGroup
->List();
129 void EditorGrantGroup::setEditing(KeysPtr keys
)
133 m_grantgroup
.reset();
137 m_grantgroup
= mud::Managers::Get()->GrantGroup
->GetByKey(keys
->first()->getIntegerValue());
141 std::vector
<std::string
> EditorGrantGroup::getCommands()
143 return m_commands
.getCommandsVector();
146 void EditorGrantGroup::editName(const std::string
& argument
)
148 if(argument
.size() == 0)
150 m_sock
->Send("GrantGroup name can't be zero length!\n");
154 m_sock
->Sendf("GrantGroup name changed from '%s' to '%s'.\n", m_grantgroup
->getName().c_str(), argument
.c_str());
155 m_grantgroup
->setName(argument
);
159 void EditorGrantGroup::editImplication(const std::string
& argument
)
161 if(argument
.size() == 0)
163 m_sock
->Send("Please specify the implicated grantgroup!\n");
167 int implication
= atoi(argument
.c_str());
170 m_sock
->Sendf("Please specify an implication > 0!\n");
174 m_sock
->Sendf("GrantGroup implication changed from '%d' to '%d'.\n", m_grantgroup
->getImplication(), implication
);
175 m_grantgroup
->setImplication(implication
);
178 void EditorGrantGroup::showGrantGroup(const std::string
& argument
)
180 m_sock
->Send(m_grantgroup
->toString());
184 void EditorGrantGroup::saveGrantGroup(const std::string
& argument
)
186 m_sock
->Sendf("Saving grantgroup '%s'.\n", m_grantgroup
->getName().c_str());
187 m_grantgroup
->Save();
188 m_sock
->Send("Saved.\n");