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 "EditorAccount.h"
22 #include "EditorOLC.h"
23 #include "EditorNewCharacter.h"
24 #include "EditorPlaying.h"
25 #include "EditorOOC.h"
27 #include "StringUtilities.h"
28 #include "TableImpls.h"
30 #include "FieldImpls.h"
33 #include "Permission.h"
34 #include "PCharacter.h"
35 #include "PCharacterManager.h"
36 #include "CharacterManager.h"
42 typedef EditorAccount E
;
43 typedef CommandInfoObject
<E
> O
;
44 typedef CommandBinding
<E
> B
;
46 // name function fullname
47 static O
listCommands( "Commands", &E::listCommands
);
48 static O
beginLogin( "Login", &E::beginLogin
);
49 static O
beginOLC( "OLC", &E::beginOLC
);
50 static O
beginOOC( "OOC", &E::beginOOC
);
51 static O
beginCreation( "New", &E::beginCreation
, true);
52 static O
quitEditor( "Quit", &E::quitEditor
, true);
53 static O
shutdownGame( "Shutdown", &E::shutdownGame
, true);
54 static O
listCharacters("List", &E::listCharacters
);
56 static B commands
[] = {
58 B("list", listCharacters
),
59 B("login", beginLogin
),
60 B("new", beginCreation
),
63 B("quit", quitEditor
),
64 B("shutdown", shutdownGame
),
67 EditorAccount::EditorAccount(UBSocket
* sock
) :
69 m_commands(commands
, array_size(commands
))
71 listCommands(Global::Get()->EmptyString
);
74 EditorAccount::~EditorAccount(void)
79 std::string
EditorAccount::lookup(const std::string
& action
)
81 const AccountCommand
* act
= (AccountCommand
*)m_commands
.getObject(action
);
83 return act
->getName();
85 return Global::Get()->EmptyString
;
88 void EditorAccount::dispatch(const std::string
& action
, const std::string
& argument
)
90 const AccountCommand
* act
= (AccountCommand
*)m_commands
.getObject(action
);
93 act
->Run(this, argument
);
96 void EditorAccount::beginLogin(const std::string
&argument
)
98 if(argument
.size() == 0)
100 m_sock
->Send("Please choose a character:\n");
101 listCharacters(Global::Get()->EmptyString
);
105 if(mud::PCharacterManager::Get()->isActive(argument
))
107 m_sock
->Send("You are already playing that character!\n");
115 id
= mud::Managers::Get()->Character
->lookupByName(argument
);
117 catch(RowNotFoundException
& e
)
119 m_sock
->Send("No such character.\n");
121 beginLogin(Global::Get()->EmptyString
);
125 KeysPtr
keys(new Keys(db::TableImpls::Get()->CHARACTERACCOUNT
));
128 key
= KeyValuePtr(new KeyValue(db::TableImpls::Get()->CHARACTERACCOUNT
->FKACCOUNTS
, id
));
130 key
= KeyValuePtr(new KeyValue(db::TableImpls::Get()->CHARACTERACCOUNT
->FKENTITIES
, m_sock
->GetAccount()->getID()));
133 bool hasAccount
= false;
136 SavableManagerPtr manager
= SavableManager::bykeys(keys
);
138 } catch(RowNotFoundException
& e
) { }
142 m_sock
->Sendf("You don't have a character named '%s'!\n", argument
.c_str());
143 beginLogin(Global::Get()->EmptyString
);
147 mud::PCharacterPtr Ch
= mud::PCharacterManager::Get()->LoadByKey(m_sock
, id
);
148 m_sock
->Sendf("Welcome back, %s\n", argument
.c_str());
149 m_sock
->SetEditor(new EditorPlaying(m_sock
, Ch
));
153 void EditorAccount::listCharacters(const std::string
&argument
)
155 Assert(m_sock
->hasAccount());
156 mud::AccountPtr account
= m_sock
->GetAccount();
158 Strings characters
= mud::Managers::Get()->Character
->List(account
);
160 if(characters
.size() == 0)
162 m_sock
->Send("You have no characters yet!\n");
166 m_sock
->Send(String::Get()->box(characters
, "Characters"));
171 void EditorAccount::listCommands(const std::string
&argument
)
173 m_sock
->Send(String::Get()->box(m_commands
.getCommandsVector(), "Account"));
178 void EditorAccount::beginOLC(const std::string
&argument
)
180 m_sock
->Send("Dropping you into OLC mode!\n");
181 m_sock
->SetEditor(new EditorOLC(m_sock
));
185 void EditorAccount::beginOOC(const std::string
& argument
)
187 m_sock
->Send("Dropping you into OOC mode!\n");
188 m_sock
->SetEditor(new EditorOOC(m_sock
));
191 void EditorAccount::beginCreation(const std::string
&argument
)
193 m_sock
->Send("Dropping you into Character Creation mode!\n");
194 m_sock
->SetEditor(new EditorNewCharacter(m_sock
));
198 void EditorAccount::quitEditor(const std::string
&argument
)
200 m_sock
->Send("Thank you for visiting.\n");
201 m_sock
->SetCloseAndDelete();
205 void EditorAccount::shutdownGame(const std::string
&argument
)
207 m_sock
->Send("Shutting down...\n");
209 m_sock
->Send("Game will shut down after this loop!\n");