Removed 'not touching files if ok' since it's not working anyway.
[UnsignedByte.git] / src / Core / Editors / EditorAccountLogin.cpp
blob0fdcdb2cce92aecae5b82afb8928c4b5f4fc2364
1 /***************************************************************************
2 * Copyright (C) 2008 by Sverre Rabbelier *
3 * sverre@rabbelier.nl *
4 * *
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. *
9 * *
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. *
14 * *
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 "EditorAccountLogin.h"
23 #include "EditorAccount.h"
24 #include "UBSocket.h"
25 #include "Channel.h"
26 #include "Account.h"
27 #include "AccountManager.h"
28 #include "Global.h"
29 #include "Managers.h"
31 class DoCmd;
33 EditorAccountLogin::EditorAccountLogin(UBSocket* sock) :
34 Editor(sock),
35 m_state(M_FIRST),
36 m_account()
38 OnLine(Global::Get()->EmptyString);
41 EditorAccountLogin::~EditorAccountLogin(void)
45 void EditorAccountLogin::OnLine(const std::string &line)
47 if(!line.compare("quit"))
49 m_sock->Send("Goodbye!\n");
50 m_sock->SetCloseAndDelete();
51 return;
54 switch(m_state)
56 default:
58 Assert(m_state != m_state);
59 break;
62 case M_FIRST:
64 m_state++;
65 // fallthrough
66 } /* case M_FIRST: */
68 case M_NAME:
70 if(!line.compare("new"))
72 m_sock->Send("Starting account creation...\n");
73 m_sock->SetEditor(new EditorNewAccount(m_sock));
74 return;
77 if(line.size() == 0)
79 m_sock->Send("Please enter your name:\n");
80 return;
83 try
85 m_account = mud::Managers::Get()->Account->GetByName(line);
86 m_state++;
87 OnLine(Global::Get()->EmptyString);
89 catch(RowNotFoundException& e)
91 m_sock->Send("No such account.\n");
92 OnLine(Global::Get()->EmptyString);
95 return;
96 } /* case M_NAME: */
98 case M_PASSWORD:
100 if(line.size() == 0)
102 m_sock->Send("Please enter your password: \n");
103 return;
106 if(line.compare(m_account->getPassword()))
108 m_sock->Send("Password incorrect, try again.\n");
109 // TODO: log
110 OnLine(Global::Get()->EmptyString);
111 return;
114 m_sock->Sendf("Welcome back, %s\n", m_account->getName().c_str());
115 m_sock->Send("\n");
116 m_sock->SetAccount(m_account);
117 m_sock->SetEditor(new EditorAccount(m_sock));
118 return;
119 } /* case M_PASSWORD: */
121 } /* switch(state) */
125 bool EditorAccountLogin::canReceiveChannel(mud::ChannelPtr channel) const
127 if(!channel->needLogin())
128 return true;
130 return false;
133 bool EditorAccountLogin::supportPrefixes() const
135 return false;