Only allow this language: ((n|s)!(w|e)!(u|d)!;)+ for directions.
[UnsignedByte.git] / src / Core / Editors / EditorAccountLogin.cpp
blobb47c0b3e92c38cc9a4039a8f4c684b87d1ffcf0c
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 Global::Get()->bug("EditorAccountLogin::OnLine(), default m_state!\n");
59 m_sock->Send("BUG! Disconnecting you now...\n");
60 m_sock->SetCloseAndDelete();
61 return;
62 } /* default */
64 case M_FIRST:
66 m_state++;
67 // fallthrough
68 } /* case M_FIRST: */
70 case M_NAME:
72 if(!line.compare("new"))
74 m_sock->Send("Starting account creation...\n");
75 m_sock->SetEditor(new EditorNewAccount(m_sock));
76 return;
79 if(line.size() == 0)
81 m_sock->Send("Please enter your name:\n");
82 return;
85 try
87 m_account = mud::Managers::Get()->Account->GetByName(line);
88 m_state++;
89 OnLine(Global::Get()->EmptyString);
91 catch(RowNotFoundException& e)
93 m_sock->Send("No such account.\n");
94 OnLine(Global::Get()->EmptyString);
97 return;
98 } /* case M_NAME: */
100 case M_PASSWORD:
102 if(line.size() == 0)
104 m_sock->Send("Please enter your password: \n");
105 return;
108 if(line.compare(m_account->getPassword()))
110 m_sock->Send("Password incorrect, try again.\n");
111 // TODO: log
112 OnLine(Global::Get()->EmptyString);
113 return;
116 m_sock->Sendf("Welcome back, %s\n", m_account->getName().c_str());
117 m_sock->Send("\n");
118 m_sock->SetAccount(m_account);
119 m_sock->SetEditor(new EditorAccount(m_sock));
120 return;
121 } /* case M_PASSWORD: */
123 } /* switch(state) */
127 bool EditorAccountLogin::canReceiveChannel(mud::ChannelPtr channel) const
129 if(!channel->needLogin())
130 return true;
132 return false;
135 bool EditorAccountLogin::supportPrefixes() const
137 return false;