Logo
~Sockets~
~Examples~
~Contact~

Login Class Reference
[Commands]

Login sequence. More...

#include <Login.h>

Inheritance diagram for Login:

Inheritance graph
[legend]
Collaboration diagram for Login:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Login ()
void Execute (InSocket *, const std::string &params, Parse &)
 Execute command.
void OnLine (InSocket *, const std::string &line, int state)
 Additional callback, reply to command prompt.
std::string Category ()
 Get command category.

Detailed Description

Login sequence.

Definition at line 28 of file Login.h.


Constructor & Destructor Documentation

Login::Login (  )  [inline]

Definition at line 31 of file Login.h.

00031 : Command() {}


Member Function Documentation

void Login::Execute ( InSocket ,
const std::string &  arg,
Parse &   
) [virtual]

Execute command.

Implements Command.

Definition at line 29 of file Login.cpp.

00030 {
00031 }

void Login::OnLine ( InSocket ,
const std::string &  line,
int  state 
) [virtual]

Additional callback, reply to command prompt.

See also:
InSocket::SetPrompt

Reimplemented from Command.

Definition at line 34 of file Login.cpp.

References Race::DisplayRaces(), Player::GetDisplayName(), Player::GetName(), Player::GetPasswd(), Player::GetRace(), Player::IsWizard(), Player::LoadSteps(), Player::Save(), Player::SetDisplayName(), Player::SetName(), Player::SetPasswd(), Player::SetRace(), and Player::VerifyPos().

00035 {
00036         Database& db = from -> GetDatabase();
00037         switch (state)
00038         {
00039         case 0: // name
00040                 if (line.size())
00041                 {
00042                         Player pl(db, line);
00043                         from -> SetCommandData(line);
00044                         if (pl.Exists())
00045                         {
00046                                 // %! stealth (echo off) password
00047                                 from -> SetPrompt(this, 1, "Password? ");
00048                         }
00049                         else
00050                         {
00051                                 from -> Send("Name does not exist.\n");
00052                                 from -> SetPrompt(this, 2, "Create a new player named '" + line + "' (y/N)? ");
00053                         }
00054                 }
00055                 else
00056                 {
00057                         from -> Send("Name required (bye).\n");
00058                         from -> SetCloseAndDelete();
00059                 }
00060                 break;
00061         case 1: // password
00062                 {
00063                         Player pl(db, from -> GetCommandData());
00064                         if (!strcmp(pl.GetPasswd().c_str(), line.c_str()))
00065                         {
00066                                 from -> Count("Number of successful logins");
00067                                 from -> GlobalEvent(pl.GetDisplayName() + " enters the game.");
00068                                 pl.VerifyPos();
00069                                 pl.LoadSteps();
00070                                 from -> SetAccountName(pl.GetName());
00071                                 from -> Send("Welcome, " + pl.GetDisplayName() + "!\n");
00072                                 if (!pl.GetRace())
00073                                 {
00074                                         int n = Race::DisplayRaces(from);
00075                                         from -> SetPrompt(this, 6, "Select a race (1-" + Utility::l2string(n) + ")? ");
00076                                 }
00077                                 else
00078                                 {
00079                                         from -> SetPrompt();
00080                                 }
00081                         }
00082                         else
00083                         {
00084                                 from -> Send("Name and/or password incorrect.\n");
00085                                 from -> SetPrompt(this, 0, "Name, please? ");
00086                         }
00087                 }
00088                 break;
00089         case 2: // create (y/N)?
00090                 if (line.size() && (line[0] == 'y' || line[0] == 'Y'))
00091                 {
00092                         from -> SetPrompt(this, 3, "Enter a password: ");
00093                 }
00094                 else
00095                 {
00096                         from -> SetPrompt(this, 0, "Name, please? ");
00097                 }
00098                 break;
00099         case 3: // enter new password
00100                 if (line.size() < 4)
00101                 {
00102                         from -> Send("Enter at least 4 characters.\n");
00103                         from -> SetPrompt(this, 3, "Enter a password: ");
00104                 }
00105                 else
00106                 {
00107                         from -> SetCommandData2(line);
00108                         from -> SetPrompt(this, 4, "Repeat password: ");
00109                 }
00110                 break;
00111         case 4: // repeat password
00112                 if (!strcmp(line.c_str(), from -> GetCommandData2().c_str()))
00113                 {
00114                         from -> Count("Number of created logins");
00115                         // wizard set by Player constructor
00116                         // first created is wizard
00117                         Player pl(db, from -> GetCommandData());
00118                         pl.SetName(from -> GetCommandData());
00119                         pl.SetPasswd(line);
00120                         pl.SetDisplayName(from -> GetCommandData());
00121                         pl.VerifyPos();
00122                         pl.Save();
00123                         from -> SetAccountName(from -> GetCommandData());
00124                         from -> SetPrompt(this, 5, "Enter your email: ");
00125                 }
00126                 else
00127                 {
00128                         from -> Send("Password mismatch, please try again.\n");
00129                         from -> SetPrompt(this, 3, "Enter a password: ");
00130                 }
00131                 break;
00132         case 5: // email
00133                 if (line.size())
00134                 {
00135                         Player pl(db, from -> GetAccountName());
00136                         pl.SetEmail(line);
00137                         pl.Save();
00138                 }
00139                 from -> GlobalEvent("New player " + from -> GetCommandData() + " enters the game.");
00140                 from -> Send("Welcome, new player " + from -> GetCommandData() + "!\n");
00141                 Race::DisplayRaces(from);
00142                 from -> SetPrompt(this, 6, "Select a race: ");
00143                 break;
00144         case 6: // race
00145                 {
00146                         Player pl(db, from -> GetAccountName());
00147                         long num = atol(line.c_str());
00148                         Race r(db, num);
00149                         if (r.Exists())
00150                         {
00151                                 pl.SetRace(num);
00152                                 pl.Save();
00153                                 //
00154                                 from -> SetPrompt();
00155                         }
00156                         else
00157                         if (pl.IsWizard())
00158                         {
00159                                 from -> Send("Skipping race selection, for now..\n");
00160                                 from -> SetPrompt();
00161                         }
00162                         else
00163                         {
00164                                 Race::DisplayRaces(from);
00165                                 from -> SetPrompt(this, 6, "Select a race: ");
00166                         }
00167                 }
00168                 break;
00169         }
00170 }

std::string Login::Category (  )  [inline, virtual]

Get command category.

Implements Command.

Definition at line 36 of file Login.h.

00036 { return "General"; }


The documentation for this class was generated from the following files:
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4