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"
31 EditorNewAccount::EditorNewAccount(UBSocket
* sock
) :
35 OnLine(Global::Get()->EmptyString
);
38 EditorNewAccount::~EditorNewAccount(void)
42 void EditorNewAccount::OnLine(const std::string
&line
)
44 if(!line
.compare("quit"))
46 m_sock
->Send("Allright, quitting!\n");
47 m_sock
->SetCloseAndDelete();
55 Global::Get()->bug("EditorNewAccount::OnLine(), default m_state!\n");
56 m_sock
->Send("BUG! Disconnecting you now...\n");
57 m_sock
->SetCloseAndDelete();
71 m_sock
->Send("Enter a name for your account please: \n");
75 if(mud::AccountManager::Get()->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 an account 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
);
114 } /* case M_NAMECONFIRM: */
120 m_sock
->Send("Please choose a password: \n");
126 OnLine(Global::Get()->EmptyString
);
128 } /* case M_PASSWORD: */
130 case M_PASSWORDCONFIRM
:
134 m_sock
->Send("Please confirm your password: \n");
138 if(m_password
.compare(line
))
140 m_sock
->Send("Passwords do not match, let's try again!\n");
141 m_state
= M_PASSWORD
;
142 OnLine(Global::Get()->EmptyString
);
146 m_sock
->Sendf("Your password is set.\n", line
.c_str());
147 m_sock
->Send("Please hit enter to continue.\n");
150 } /* case M_PASSWORDCONFIRM: */
156 m_sock
->Send("Please hit enter to continue.\n");
160 KeysPtr newaccountkeys
= mud::AccountManager::Get()->Add();
161 value_type id
= newaccountkeys
->first()->getIntegerValue();
164 m_sock
->Send("Could not create a new account.\n");
165 m_sock
->SetCloseAndDelete();
169 mud::AccountPtr Acc
= mud::AccountManager::Get()->GetByKey(id
);
170 Acc
->setName(m_name
);
171 Acc
->setPassword(m_password
);
174 m_sock
->Sendf("Account %s created, enjoy!\n", m_name
.c_str());
175 m_sock
->SetAccount(Acc
);
176 m_sock
->SetEditor(new EditorAccount(m_sock
), true);
180 } /* switch(state) */
184 void EditorNewAccount::OnEmptyLine()
186 OnLine(Global::Get()->EmptyString
);
190 bool EditorNewAccount::canReceiveChannel(mud::ChannelPtr channel
) const
192 if(!channel
->needLogin())
198 bool EditorNewAccount::supportPrefixes() const