X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;ds=inline;f=Source%2FAccount.cpp;h=d132c2123d602945454e79d7f87e7d96c3315e9e;hb=3de67c0db8c3c74f5fb487579936a07770d253a1;hp=f650330a0f87bcbb3d9c456eb03488bf3fca5d88;hpb=757fd9c1ec8d263225df90ef486051712f448483;p=lugaru.git
diff --git a/Source/Account.cpp b/Source/Account.cpp
index f650330..d132c21 100644
--- a/Source/Account.cpp
+++ b/Source/Account.cpp
@@ -27,9 +27,10 @@ along with Lugaru. If not, see .
using namespace std;
-extern bool debugmode;
+extern bool devtools;
vector Account::accounts = vector();
+Account* Account::active = nullptr;
Account::Account(const string& name) : name(name), campaignProgress()
{
@@ -75,7 +76,7 @@ Account* Account::destroy(Account* a)
return NULL;
}
}
- printf("Unexpected error : User %s not found\n", a->getName());
+ printf("Unexpected error : User %s not found\n", a->getName().c_str());
return accounts.front();
}
@@ -100,7 +101,7 @@ void Account::winCampaignLevel(int choice, float score, float time)
void Account::winLevel(int level, float score, float time)
{
- if (!debugmode) {
+ if (!devtools) {
if (score > highscore[level])
highscore[level] = score;
if (time < fasttime[level] || fasttime[level] == 0)
@@ -114,13 +115,14 @@ Account* Account::loadFile(string filename)
{
FILE *tfile;
int numaccounts;
- int accountactive;
+ int iactive;
+ errno = 0;
tfile = fopen(filename.c_str(), "rb" );
if (tfile) {
funpackf(tfile, "Bi", &numaccounts);
- funpackf(tfile, "Bi", &accountactive);
+ funpackf(tfile, "Bi", &iactive);
printf("number of accounts %d\n", numaccounts);
for (int i = 0; i < numaccounts; i++) {
printf("loading account %d/%d\n", i, numaccounts);
@@ -184,26 +186,26 @@ Account* Account::loadFile(string filename)
}
fclose(tfile);
- return get(accountactive);
+ return get(iactive);
} else {
perror(("Couldn't load users from " + filename).c_str());
return NULL;
}
}
-void Account::saveFile(string filename, Account* accountactive)
+void Account::saveFile(string filename)
{
FILE *tfile;
+ errno = 0;
tfile = fopen(filename.c_str(), "wb" );
if (tfile) {
- printf("writing %d accounts :\n", getNbAccounts());
fpackf(tfile, "Bi", getNbAccounts());
- fpackf(tfile, "Bi", indice(accountactive));
+ fpackf(tfile, "Bi", indice(Account::active));
for (int i = 0; i < getNbAccounts(); i++) {
Account* a = Account::get(i);
- printf("writing account %d/%d (%s)\n", i + 1, getNbAccounts(), a->getName());
+ printf("writing account %d/%d (%s)\n", i + 1, getNbAccounts(), a->getName().c_str());
fpackf(tfile, "Bi", a->difficulty);
fpackf(tfile, "Bi", a->progress);
fpackf(tfile, "Bi", a->campaignProgress.size());