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 "EditorChannel.h"
22 #include "EditorString.h"
23 #include "EditorBool.h"
25 #include "StringUtilities.h"
26 #include "TableImpls.h"
30 #include "ChannelManager.h"
33 typedef EditorChannel E
;
34 typedef CommandInfoObject
<E
> O
;
35 typedef CommandBinding
<E
> B
;
37 // name function need: object lock
38 static O
editName( "Name", &E::editName
, true, true);
39 static O
editDescription("Description",&E::editDescription
,true, true);
40 static O
editNeedLogin("NeedLogin", &E::editNeedLogin
, true, true);
41 static O
showChannel( "Show", &E::showChannel
, true, false);
42 static O
saveChannel( "Save", &E::saveChannel
, true, true);
44 static B commands
[] = {
45 B("description", editDescription
),
47 B("needlogin", editNeedLogin
),
48 B("save", saveChannel
),
49 B("show", showChannel
),
52 EditorChannel::EditorChannel(UBSocket
* sock
) :
54 m_commands(commands
, array_size(commands
)),
57 listCommands(Global::Get()->EmptyString
);
60 EditorChannel::~EditorChannel(void)
65 void EditorChannel::OnFocus()
73 m_channel
->setDescription(m_value
);
77 m_channel
->setNeedLogin(m_yesno
);
84 std::string
EditorChannel::lookup(const std::string
& action
)
86 std::string name
= OLCEditor::lookup(action
);
90 const ChannelCommand
* act
= (ChannelCommand
*)m_commands
.getObject(action
);
92 return act
->getName();
94 return Global::Get()->EmptyString
;
97 void EditorChannel::dispatch(const std::string
& action
, const std::string
& argument
)
99 const ChannelCommand
* act
= (ChannelCommand
*)m_commands
.getObject(action
);
103 OLCEditor::dispatch(action
, argument
);
109 m_sock
->Send("You need to be editing an channel first.\n");
110 m_sock
->Send("(Use the 'edit' command.)\n");
118 } catch(SavableLocked
& e
) {
119 m_sock
->Send("The channel you are currently editing is locked (being edited by someone else), so you cannot edit it right now.\n");
120 m_sock
->Send("Please try again later.\n");
125 act
->Run(this, argument
);
129 SavablePtr
EditorChannel::getEditing()
134 TableImplPtr
EditorChannel::getTable()
136 return db::TableImpls::Get()->AREAS
;
139 KeysPtr
EditorChannel::addNew()
141 return mud::Managers::Get()->Channel
->Add();
144 std::vector
<std::string
> EditorChannel::getList()
146 return mud::Managers::Get()->Channel
->List();
149 void EditorChannel::setEditing(KeysPtr keys
)
157 m_channel
= mud::Managers::Get()->Channel
->GetByKey(keys
->first()->getIntegerValue());
161 std::vector
<std::string
> EditorChannel::getCommands()
163 return m_commands
.getCommandsVector();
166 void EditorChannel::editName(const std::string
& argument
)
168 if(argument
.size() == 0)
170 m_sock
->Send("Channel name can't be zero length!\n");
174 m_sock
->Sendf("Channel name changed from '%s' to '%s'.\n", m_channel
->getName().c_str(), argument
.c_str());
175 m_channel
->setName(argument
);
179 void EditorChannel::editDescription(const std::string
& argument
)
181 if(argument
.size() == 0)
183 m_sock
->Send("No argument, dropping you into the string editor!\n");
184 m_sock
->SetEditor(new EditorString(m_sock
, m_value
));
185 m_target
= M_DESCRIPTION
;
191 m_sock
->Sendf("Channel description changed from '%s' to '%s'.\n", m_channel
->getDescription().c_str(), argument
.c_str());
192 m_channel
->setDescription(argument
);
196 void EditorChannel::editNeedLogin(const std::string
& argument
)
198 if(argument
.size() == 0)
200 m_sock
->Send("Do players need to be logged in to use hear the channel?\n");
201 m_sock
->SetEditor(new EditorBool(m_sock
, m_yesno
));
202 m_target
= M_NEEDLOGIN
;
206 if(!argument
.compare("yes"))
208 m_channel
->setNeedLogin(true);
212 if(!argument
.compare("no"))
214 m_channel
->setNeedLogin(false);
218 editNeedLogin(Global::Get()->EmptyString
);
222 void EditorChannel::showChannel(const std::string
& argument
)
224 m_sock
->Send(m_channel
->toString());
227 void EditorChannel::saveChannel(const std::string
& argument
)
229 m_sock
->Sendf("Saving channel '%s'.\n", m_channel
->getName().c_str());
231 m_sock
->Send("Saved.\n");