00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <Utility.h>
00021
00022 #include "Login.h"
00023 #include "InSocket.h"
00024 #include "Chunk.h"
00025 #include "Player.h"
00026 #include "Race.h"
00027
00028
00029 void Login::Execute(InSocket *,const std::string& params,Parse& pa)
00030 {
00031 }
00032
00033
00034 void Login::OnLine(InSocket *from,const std::string& line,int state)
00035 {
00036 Database& db = from -> GetDatabase();
00037 switch (state)
00038 {
00039 case 0:
00040 if (line.size())
00041 {
00042 Player pl(db, line);
00043 from -> SetCommandData(line);
00044 if (pl.Exists())
00045 {
00046
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:
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:
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:
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:
00112 if (!strcmp(line.c_str(), from -> GetCommandData2().c_str()))
00113 {
00114 from -> Count("Number of created logins");
00115
00116
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:
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:
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 }
00171
00172