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 ***************************************************************************/
22 #include "CharacterManager.h"
23 #include "EditorAccount.h"
24 #include "EditorNewCharacter.h"
25 #include "EditorPlaying.h"
26 #include "FieldImpls.h"
28 #include "PCharacter.h"
29 #include "PCharacterManager.h"
31 #include "RaceManager.h"
32 #include "StringUtilities.h"
33 #include "TableImpls.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 Assert(m_state
!= m_state
);
71 m_sock
->Send("Enter a name for your character please: \n");
75 if(mud::Managers::Get()->Character
->IllegalName(line
))
77 m_sock
->Sendf("You cannot use the name %s, please pick another name.\n", line
.c_str());
78 OnLine(Global::Get()->EmptyString
);
84 OnLine(Global::Get()->EmptyString
);
92 m_sock
->Sendf("Create a character named %s?\n", m_name
.c_str());
96 if(!line
.compare("n") || !line
.compare("no"))
98 m_sock
->Send("Let's try again then.\n");
100 OnLine(Global::Get()->EmptyString
);
104 if(line
.compare("y") && line
.compare("yes"))
106 OnLine(Global::Get()->EmptyString
);
107 m_sock
->Send("yes/no?\n");
112 OnLine(Global::Get()->EmptyString
);
120 m_sock
->Send("Please choose a race: \n");
121 m_sock
->Send(String::Get()->box(mud::Managers::Get()->Race
->List(), "Races"));
128 int id
= mud::Managers::Get()->Race
->lookupByName(line
);
131 m_sock
->Sendf("Your race is now %s.\n", line
.c_str());
133 OnLine(Global::Get()->EmptyString
);
135 catch(RowNotFoundException
& e
)
137 m_sock
->Send("No such race.\n");
138 OnLine(Global::Get()->EmptyString
);
148 m_sock
->Send("Please hit enter to continue.\n");
152 KeysPtr
keys(new Keys(db::TableImpls::Get()->ROOMS
));
153 KeyValuePtr
key(new KeyValue(db::TableImpls::Get()->ROOMS
->ROOMID
, 1));
158 if(DatabaseMgr::Get()->CountSavable(db::TableImpls::Get()->ROOMS, keys) <= 0)
160 m_sock->Sendf("Could not fetch room 1!\n");
161 m_sock->Send("Closing your connection now.\n");
162 m_sock->SetCloseAndDelete();
167 mud::AccountPtr account
= m_sock
->GetAccount();
169 KeysPtr newchkeys
= mud::Managers::Get()->Character
->Add();
170 value_type id
= newchkeys
->first()->getIntegerValue();
174 mud::CharacterPtr character
= mud::Managers::Get()->Character
->GetByKey(id
);
177 m_sock
->Send("For some reason your new characters could not be retreived.\n");
178 m_sock
->Send("Disconnecting you now.\n");
179 m_sock
->SetCloseAndDelete();
183 character
->setName(m_name
);
184 character
->setRace(m_raceid
);
185 character
->setChunk(1);
189 mud::PCharacterPtr Ch
= mud::PCharacterManager::Get()->LoadByKey(m_sock
, id
);
191 Assert(m_sock
->hasAccount());
192 value_type accountid
= m_sock
->GetAccount()->getID();
194 RelationPtr
relation(new Relation(db::TableImpls::Get()->CHARACTERACCOUNT
));
195 relation
->addKey(db::TableImpls::Get()->CHARACTERACCOUNT
->FKACCOUNTS
, accountid
);
196 relation
->addKey(db::TableImpls::Get()->CHARACTERACCOUNT
->FKENTITIES
, id
);
199 m_sock
->Sendf("Character %s created, enjoy!\n", m_name
.c_str());
200 m_sock
->SetEditor(new EditorPlaying(m_sock
, Ch
), true);
207 void EditorNewCharacter::OnEmptyLine()
209 OnLine(Global::Get()->EmptyString
);