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 "EditorNewCharacter.h"
22 #include "EditorPlaying.h"
23 #include "EditorAccount.h"
25 #include "CharacterManager.h"
26 #include "PCharacter.h"
27 #include "PCharacterManager.h"
28 #include "StringUtilities.h"
29 #include "FieldImpls.h"
30 #include "TableImpls.h"
33 #include "RaceManager.h"
36 EditorNewCharacter::EditorNewCharacter(UBSocket
* sock
) :
40 OnLine(Global::Get()->EmptyString
);
43 EditorNewCharacter::~EditorNewCharacter(void)
47 void EditorNewCharacter::OnLine(const std::string
&line
)
49 if(!line
.compare("quit"))
52 // m_sock->SetEditor(new EditorAccount(m_sock));
60 Global::Get()->bug("EditorNewAccount::OnLine(), default m_state!\n");
61 m_sock
->Send("BUG! Disconnecting you now...\n");
62 m_sock
->SetCloseAndDelete();
73 m_sock
->Send("Enter a name for your character please: \n");
77 if(mud::Managers::Get()->Character
->IllegalName(line
))
79 m_sock
->Sendf("You cannot use the name %s, please pick another name.\n", line
.c_str());
80 OnLine(Global::Get()->EmptyString
);
86 OnLine(Global::Get()->EmptyString
);
94 m_sock
->Sendf("Create a character named %s?\n", m_name
.c_str());
98 if(!line
.compare("n") || !line
.compare("no"))
100 m_sock
->Send("Let's try again then.\n");
102 OnLine(Global::Get()->EmptyString
);
106 if(line
.compare("y") && line
.compare("yes"))
108 OnLine(Global::Get()->EmptyString
);
109 m_sock
->Send("yes/no?\n");
114 OnLine(Global::Get()->EmptyString
);
122 m_sock
->Send("Please choose a race: \n");
123 m_sock
->Send(String::Get()->box(mud::Managers::Get()->Race
->List(), "Races"));
130 int id
= mud::Managers::Get()->Race
->lookupByName(line
);
133 m_sock
->Sendf("Your race is now %s.\n", line
.c_str());
135 OnLine(Global::Get()->EmptyString
);
137 catch(RowNotFoundException
& e
)
139 m_sock
->Send("No such race.\n");
140 OnLine(Global::Get()->EmptyString
);
150 m_sock
->Send("Please hit enter to continue.\n");
154 KeysPtr
keys(new Keys(db::TableImpls::Get()->ROOMS
));
155 KeyValuePtr
key(new KeyValue(db::TableImpls::Get()->ROOMS
->ROOMID
, 1));
160 if(DatabaseMgr::Get()->CountSavable(db::TableImpls::Get()->ROOMS, keys) <= 0)
162 m_sock->Sendf("Could not fetch room 1!\n");
163 m_sock->Send("Closing your connection now.\n");
164 m_sock->SetCloseAndDelete();
169 mud::AccountPtr account
= m_sock
->GetAccount();
171 KeysPtr newchkeys
= mud::Managers::Get()->Character
->Add();
172 value_type id
= newchkeys
->first()->getIntegerValue();
176 mud::CharacterPtr character
= mud::Managers::Get()->Character
->GetByKey(id
);
179 m_sock
->Send("For some reason your new characters could not be retreived.\n");
180 m_sock
->Send("Disconnecting you now.\n");
181 m_sock
->SetCloseAndDelete();
185 character
->setName(m_name
);
186 character
->setRace(m_raceid
);
187 character
->setChunk(1);
191 mud::PCharacterPtr Ch
= mud::PCharacterManager::Get()->LoadByKey(m_sock
, id
);
193 Assert(m_sock
->hasAccount());
194 value_type accountid
= m_sock
->GetAccount()->getID();
196 RelationPtr
relation(new Relation(db::TableImpls::Get()->CHARACTERACCOUNT
));
197 relation
->addKey(db::TableImpls::Get()->CHARACTERACCOUNT
->FKACCOUNTS
, accountid
);
198 relation
->addKey(db::TableImpls::Get()->CHARACTERACCOUNT
->FKENTITIES
, id
);
201 m_sock
->Sendf("Character %s created, enjoy!\n", m_name
.c_str());
202 m_sock
->SetEditor(new EditorPlaying(m_sock
, Ch
), true);
209 void EditorNewCharacter::OnEmptyLine()
211 OnLine(Global::Get()->EmptyString
);