This repository has been archived by the owner on Aug 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.cpp
131 lines (113 loc) · 2.17 KB
/
system.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
Jordi Hoock Castro
*/
#include "headers/system.hpp"
ifstream userFile("data/users.txt");
ofstream saveFile("data/users.txt", ios::binary | ios::ate | ios::out | ios::in);
ifstream readStats("data/stats.txt");
core::core(string *n, string *p, bool debug, bool maint)
:debugMode(debug), maintence(maint)
{
user = &ud;
stat = &st;
user->name = *n;
user->password = *p;
this->canRegister = true;
/*
Initalizing user stats
*/
if (this->debugMode)
cout << "\nSystem Inicialized!\n With user: " << user->name << "\nAnd password: " << user->password << endl;
try
{
if(! userFile.is_open())
throw 0;
}
catch ( ... )
{
if (this->debugMode)
cout << "\nCRITICAL SYSTEM ERROR - ";
}
}
bool core::login()
{
try
{
while (userFile >> user->tempUser >> user->tempPass)
{
if (user->name == user->tempUser && user->password == user->tempPass)
{
this->userCorrect = true;
break;
}
else
{
this->userCorrect = false;
continue;
}
}
}
catch ( ... )
{
if(this->debugMode)
cout << "An error ocurred loggin in";
}
return (this->userCorrect);
}
bool core::reg()
{
try
{
while(userFile >> user->tempUser >> user->tempPass)
{
if(user->name == user->tempUser)
{
this->canRegister = false;
break;
}
}
if(this->canRegister)
{
if(saveFile << " " << user->name << " " << user->password)
this->isRegistered = true;
}
}
catch ( ... )
{
if(this->debugMode)
cout << "An error ocurred saving your profile";
}
return (this->isRegistered);
}
bool core::InitStats(bool print = false)
{
while(readStats >> stat->Tempname >> stat->Temptype >> stat->Tempmoney)
{
if (stat->Tempname == user->name)
{
stat->name = user->name;
stat->type = stat->Temptype;
stat->money = stat->Tempmoney;
/*
Saving in a public var for get public acces
*/
this->userstats[0] = stat->name;
this->userstats[1] = stat->type;
this->userstats[2] = stat->money;
this->STAT = true;
break;
}
else
this->STAT = false;
}
if(print)
{
cout << stat->name << " " << stat->type << " " << stat->money << endl;
}
return (this->STAT);
}
core::~core()
{
userFile.close();
saveFile.close();
}