Attached a basic code for password.
Adds a field in the character creation screen for password.
When loading a character it checks if it is nonblank and prompts for it in that case, exits if it doesnt match with the char's passwd.
The password is stored as plain text in the .sav, so it is only useful for remote servers.
diff --git a/game.cpp b/game.cpp
index 1c114fb..9b0bd77 100644
--- a/game.cpp
+++ b/game.cpp
@@ -395,8 +395,8 @@ xxxx@xxx.xxx.");
}
if (ch == 'l' || ch == '\n' || ch == '>') {
if (sel2 > 0 && savegames.size() > 0) {
- load(savegames[sel2 - 1]);
- start = true;
+ if (load(savegames[sel2 - 1]))
+ start = true;
ch = 0;
}
}
@@ -1207,7 +1207,7 @@ bool game::load_master()
return true;
}
-void game::load(std::string name)
+bool game::load(std::string name)
{
std::ifstream fin;
std::stringstream playerfile;
@@ -1216,7 +1216,7 @@ void game::load(std::string name)
// First, read in basic game state information.
if (!fin.is_open()) {
debugmsg("No save game exists!");
- return;
+ return false;
}
u = player();
u.name = name;
@@ -1257,6 +1257,11 @@ void game::load(std::string name)
fin.get(junk); // Chomp that pesky endline
getline(fin, data);
u.load_info(this, data);
+ if (u.password != "") {
+ std::string prompt = string_input_popup("Password for user %s ?", u.name.c_str());
+ if (u.password != prompt)
+ return false;
+ }
// And the player's inventory...
char item_place;
std::string itemdata;
@@ -1283,6 +1288,7 @@ void game::load(std::string name)
// Now load up the master game data; factions (and more?)
load_master();
draw();
+ return true;
}
void game::save()
@@ -5296,3 +5302,4 @@ bottom of your window downward so you get an extra line.\n");
delwin(tmp);
erase();
}
+
diff --git a/game.h b/game.h
index d7772f0..82ba0f0 100644
--- a/game.h
+++ b/game.h
@@ -139,7 +139,7 @@ class game
// Game-start procedures
bool opening_screen();// Warn about screen size, then present the main menu
bool load_master(); // Load the master data file, with factions &c
- void load(std::string name); // Load a player-specific save file
+ bool load(std::string name); // Load a player-specific save file
void start_game(); // Starts a new game
void start_tutorial(tut_type type); // Starts a new tutorial
@@ -239,7 +239,6 @@ class game
void mondebug(); // Debug monster behavior directly
void groupdebug(); // Get into on monster groups
-
// ########################## DATA ################################
signed char last_target;// The last monster targeted
diff --git a/newcharacter.cpp b/newcharacter.cpp
index a422670..c4d5d0d 100644
--- a/newcharacter.cpp
+++ b/newcharacter.cpp
@@ -788,6 +788,8 @@ Gender: Male Female (Press spacebar to toggle)");
mvwprintz(w,10, 2, c_ltgray, "\
When your character is finished and you're ready to start playing, press '>'.");
mvwprintz(w,12, 2, c_ltgray, "\
+Password: __________________________");
+ mvwprintz(w,14, 2, c_ltgray, "\
To go back and review your character, press '<'.");
int line = 1;
@@ -808,10 +810,16 @@ To go back and review your character, press '<'.");
if (line == 1)
wprintz(w, h_ltgray, "_");
}
- if (line == 2)
- mvwprintz(w, 8, 2, h_ltgray, "Gender:");
- else
- mvwprintz(w, 8, 2, c_ltgray, "Gender:");
+ if (u->password != "")
+ mvwprintz(w, 12, 12, c_ltgray, u->password.c_str());
+ if (line == 2) {
+ mvwprintz(w, 8, 2, h_ltgray, "Gender:");
+ } else if (line == 3) {
+ mvwprintz(w, 12, 12 + u->password.size(), h_ltgray, "_");
+ mvwprintz(w, 8, 2, c_ltgray, "Gender:");
+ } else {
+ mvwprintz(w, 8, 2, c_ltgray, "Gender:");
+ }
wrefresh(w);
ch = input();
@@ -853,8 +861,20 @@ Points left: %d You must use the rest of your points!", points);
if (ch == ' ')
u->male = !u->male;
else if (ch == 'k' || ch == '\t') {
- line = 1;
- mvwprintz(w, 8, 8, c_ltgray, ":");
+ line = 3;
+ //mvwprintz(w, 8, 8, c_ltgray, ":");
+ }
+ break;
+ case 3:
+ if ((ch == KEY_BACKSPACE || ch == 127) && u->password.size() > 0) {
+ mvwprintz(w, 12, 12 + u->password.size(), c_ltgray, "_");
+ u->password.erase(u->password.end() - 1);
+ } else if (ch == '\t') {
+ line = 1;
+ mvwprintz(w, 12, 12 + u->password.size(), c_ltgray, "_");
+ } else if (((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
+ ch == ' ') && u->password.size() < 30) {
+ u->password.push_back(ch);
}
break;
}
diff --git a/player.cpp b/player.cpp
index 751b940..977500a 100644
--- a/player.cpp
+++ b/player.cpp
@@ -37,6 +37,7 @@ player::player()
recoil = 0;
scent = 500;
name = "";
+ password = "";
male = true;
inv_sorted = true;
moves = 100;
@@ -261,12 +262,13 @@ void player::load_info(game *g, std::string data)
{
std::stringstream dump;
dump << data;
- dump >> posx >> posy >> str_cur >> str_max >> dex_cur >> dex_max >>
+ dump >> password >> posx >> posy >> str_cur >> str_max >> dex_cur >> dex_max >>
int_cur >> int_max >> per_cur >> per_max >> power_level >>
max_power_level >> hunger >> thirst >> fatigue >> stim >>
pain >> pkill >> radiation >> cash >> recoil >> scent >> moves >>
underwater >> can_dodge >> oxygen >> active_mission >> xp_pool >>
male;
+ password = password.substr(1,password.size()-2); // remove ''
for (int i = 0; i < PF_MAX2; i++)
dump >> my_traits[i];
@@ -323,6 +325,7 @@ void player::load_info(game *g, std::string data)
std::string player::save_info()
{
std::stringstream dump;
+ dump << "'" << password << "' ";
dump << posx << " " << posy << " " << str_cur << " " << str_max << " " <<
dex_cur << " " << dex_max << " " << int_cur << " " << int_max << " " <<
per_cur << " " << per_max << " " << power_level << " " <<
diff --git a/player.h b/player.h
index 5524004..0fdbf27 100644
--- a/player.h
+++ b/player.h
@@ -182,6 +182,7 @@ public:
int active_mission;
std::string name;
+ std::string password;
bool male;
bool my_traits[PF_MAX2];
std::vector<bionic> my_bionics;