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 "EditorNewAccount.h"
22 #include "EditorAccount.h"
25 #include "AccountManager.h"
27 #include "DatabaseMgr.h"
28 #include "FieldImpls.h"
32 EditorNewAccount::EditorNewAccount(UBSocket
* sock
) :
36 OnLine(Global::Get()->EmptyString
);
39 EditorNewAccount::~EditorNewAccount(void)
43 void EditorNewAccount::OnLine(const std::string
&line
)
45 if(!line
.compare("quit"))
47 m_sock
->Send("Allright, quitting!\n");
48 m_sock
->SetCloseAndDelete();
56 Global::Get()->bug("EditorNewAccount::OnLine(), default m_state!\n");
57 m_sock
->Send("BUG! Disconnecting you now...\n");
58 m_sock
->SetCloseAndDelete();
72 m_sock
->Send("Enter a name for your account please: \n");
76 if(mud::Managers::Get()->Account
->IllegalName(line
))
78 m_sock
->Sendf("You cannot use the name %s, please pick another name.\n", line
.c_str());
79 OnLine(Global::Get()->EmptyString
);
85 OnLine(Global::Get()->EmptyString
);
93 m_sock
->Sendf("Create an account named %s?\n", m_name
.c_str());
97 if(!line
.compare("n") || !line
.compare("no"))
99 m_sock
->Send("Let's try again then.\n");
101 OnLine(Global::Get()->EmptyString
);
105 if(line
.compare("y") && line
.compare("yes"))
107 OnLine(Global::Get()->EmptyString
);
108 m_sock
->Send("yes/no?\n");
113 OnLine(Global::Get()->EmptyString
);
115 } /* case M_NAMECONFIRM: */
121 m_sock
->Send("Please choose a password: \n");
127 OnLine(Global::Get()->EmptyString
);
129 } /* case M_PASSWORD: */
131 case M_PASSWORDCONFIRM
:
135 m_sock
->Send("Please confirm your password: \n");
139 if(m_password
.compare(line
))
141 m_sock
->Send("Passwords do not match, let's try again!\n");
142 m_state
= M_PASSWORD
;
143 OnLine(Global::Get()->EmptyString
);
147 m_sock
->Sendf("Your password is set.\n", line
.c_str());
148 m_sock
->Send("Please hit enter to continue.\n");
151 } /* case M_PASSWORDCONFIRM: */
157 m_sock
->Send("Please hit enter to continue.\n");
161 KeysPtr newaccountkeys
= mud::Managers::Get()->Account
->Add();
162 value_type id
= newaccountkeys
->first()->getIntegerValue();
165 m_sock
->Send("Could not create a new account.\n");
166 m_sock
->SetCloseAndDelete();
170 mud::AccountPtr Acc
= mud::Managers::Get()->Account
->GetByKey(id
);
171 Acc
->setName(m_name
);
172 Acc
->setPassword(m_password
);
175 m_sock
->Sendf("Account %s created, enjoy!\n", m_name
.c_str());
176 m_sock
->SetAccount(Acc
);
177 m_sock
->SetEditor(new EditorAccount(m_sock
), true);
181 } /* switch(state) */
185 void EditorNewAccount::OnEmptyLine()
187 OnLine(Global::Get()->EmptyString
);
191 bool EditorNewAccount::canReceiveChannel(mud::ChannelPtr channel
) const
193 if(!channel
->needLogin())
199 bool EditorNewAccount::supportPrefixes() const