1 //--------------------------------------------------------------------------
2 // User.cc - Source file for User class
7 // $Date: 1998/09/10 19:57:17 $
13 // Revision 1.10 1998/09/10 19:57:17 mlong
14 // lots of little bug fixes and a few new features
16 // Revision 1.9 1998/04/29 15:23:19 mlong
17 // prepairing for the move to daimi
18 // new sorting routine.
21 // Revision 1.7 1997/05/15 18:27:53 chess
22 // added pending and TourneyPlayers support
23 // added HandleGetPlayerInfo & HandleGetGameInfo
25 // Revision 1.6 1997/04/13 03:14:35 chess
26 // setstatistic and addabuse added for data manipulation
28 // Revision 1.4 1997/03/27 13:45:58 chess
29 // added functions to return user's statistics
31 // Revision 1.3 1997/03/21 15:29:53 moses
32 // changed the initial clearing of the name variable
34 // Revision 1.2 1996/10/01 20:14:43 moses
35 // added a new Method IsUser
36 // added a new Method GetManagerLevel
38 // Revision 1.1 1996/09/30 20:52:48 moses
41 //--------------------------------------------------------------------------
43 // static char RCSid[] = "$Id: User.cc,v 1.10 1998/09/10 19:57:17 mlong Exp $";
47 //- Constructors ------------------------------------------------------------
49 memset(name, '\0', NAMELEN);
51 playedTourneys = wins = losses = draws = 0;
52 firsts = seconds = thirds = 0;
53 rating = placePoints = 0.0;
68 User::User(char *path, char *inName) {
70 playedTourneys = wins = losses = draws = 0;
71 firsts = seconds = thirds = 0;
72 rating = placePoints = 0.0;
74 int i=0, length=strlen(inName);
76 lowername = new char[NAMELEN];
77 memset(name, '\0', NAMELEN);
78 memset(lowername, '\0', NAMELEN);
79 for(i = 0; i < length; i++) lowername[i] = tolower(inName[i]);
81 strncpy(name, lowername, MIN(length, NAMELEN));
83 // printf("User:%s::%s::%s\n", inName, name, path);
94 // printf("User:%s::%s::%s\n", inName, name, path);
96 if(0 == LoadPlayer(path, name))
100 //- Deconstructor ----------------------------------------------------------
105 //- IsUser -----------------------------------------------------------------
106 int User::IsUser(char *user) {
107 // printf("IsUser: %18s :: %s\n", user, name);
109 if(0 == strcasecmp(user, name))
115 //- LoadPlayer -------------------------------------------------------------
116 void User::LoadPlayer(char *filePath) {
117 char filename[MAXPATHLEN];
120 CreateDirectory(filePath, name);
121 sprintf(filename, "%s/%c/%s", filePath, name[0], name);
122 theFile.open(filename, ios::in);
124 theFile >> name >> abuse >> playedTourneys >> wins >> losses >> draws
125 >> firsts >> seconds >> thirds >> rating >> placePoints
126 >> managerLevel >> managedTourneys >> last >> tourneyLocation;
130 } //- End of LoadPlayer
132 //- LoadPlayer -------------------------------------------------------------
133 short User::LoadPlayer(char *filePath, char *user) {
134 struct stat statBuffer;
135 char filename[MAXPATHLEN];
138 int i=0, length=strlen(user);
140 // printf("LoadPlayer: %18s :: %s :: %i\n", user, filePath, length);
142 lowername = new char[NAMELEN];
143 memset(lowername, '\0', NAMELEN);
144 for(i = 0; i < length; i++) lowername[i] = tolower(user[i]);
147 sprintf(filename, "%s/%c/%s", filePath, user[0], user);
149 i = stat(filename, &statBuffer);
151 // printf("%i filename: %s :: User: %18s :: %s\n", i, filename, name, user);
154 theFile.open(filename, ios::in);
156 theFile >> name >> abuse >> playedTourneys >> wins >> losses >> draws
157 >> firsts >> seconds >> thirds >> rating >> placePoints
158 >> managerLevel >> managedTourneys >> last >> tourneyLocation;
162 // printf("%i filename: %s :: User: %18s :: %s\n", i, filename, name, user);
170 } //- End of LoadPlayer
172 //- SavePlayer -----------------------------------------------------------
173 void User::SavePlayer(char *filePath) {
174 char filename[MAXPATHLEN];
177 CreateDirectory(filePath, name);
178 sprintf(filename, "%s/%c/%s", filePath, name[0], name);
182 theFile.open(filename, ios::out);
184 printf("Saving=%s Abuse=%i\n", name, abuse);
186 theFile << name << " " << abuse << " " << playedTourneys << " "
187 << wins << " " << losses << " " << draws << " " << firsts << " "
188 << seconds << " " << thirds << " " << rating << " "
189 << placePoints << " " << managerLevel << " "
190 << managedTourneys << " " << last << " " << tourneyLocation
193 } //- End of SavePlayer
195 //- GetRating --------------------------------------------------------------
196 float User::GetRating(void) {
198 } //- End of GetRating
200 int User::GetAbuse(void) {
204 long User::GetWins(void) {
208 long User::GetLosses(void) {
212 long User::GetDraws(void) {
216 long User::GetFirsts(void) {
220 long User::GetSeconds(void) {
224 long User::GetThirds(void) {
228 float User::GetPlacePoints(void) {
232 long User::GetPlayedTourneys(void) {
233 return(playedTourneys);
236 long User::GetManagedTourneys(void) {
237 return(managedTourneys);
240 long User::GetLast(void) {
244 void User::SetLast(long n) {
248 //- AddAbuse ---------------------------------------------------------------
249 void User::AddAbuse(int num) {
253 } //- End of AddAbuse
255 //- ResetAbuse -------------------------------------------------------------
256 void User::ResetAbuse(void) {
257 abuse = ABUSE_RESET_VALUE;
258 } //- End of ResetAbuse
260 //- Start AddStat -----------------------------------------
261 void User::AddStat(double i) {
264 } else if(i == 0.5) {
266 } else if(i == 1.0) {
269 }//- End AddStat -----------------------------------------
271 //- Start AddStat -----------------------------------------
272 void User::AddStat(int i) {
286 }//- End AddStat -----------------------------------------
288 //- AddWin -----------------------------------------------------------------
289 void User::AddWin(void) {
293 //- AddLoss -----------------------------------------------------------------
294 void User::AddLoss(void) {
298 //- AddDraw -----------------------------------------------------------------
299 void User::AddDraw(void) {
303 //- AddFirst -----------------------------------------------------------------
304 void User::AddFirst(void) {
306 } //- End of AddFirst
308 //- AddSecond -----------------------------------------------------------------
309 void User::AddSecond(void) {
311 } //- End of AddSecond
313 //- AddThird -----------------------------------------------------------------
314 void User::AddThird(void) {
316 } //- End of AddThird
318 //- AddPlayedTourney -------------------------------------------------------
319 void User::AddPlayedTourney(void) {
321 } //- End of playedTourney
323 //- SetStatistic ---------------------------------------------------------------
324 int User::SetStatistic(int why, int newValue) {
328 playedTourneys = newValue;
352 rating = (float)newValue/100.0;
355 managedTourneys = newValue;
364 } //- End of SetStatistic
366 //- CalculateRating ---------------------------------------------------------
367 void User::CalculateRating(void) {
368 int games = (wins + losses + draws);
370 if((rating == 0.0) && ((wins + draws) > 0)) {
372 rating = (wins +(0.5 * draws)) / (games * 0.5);
374 } //- End of CalculateRating
376 //- CalculateRating ---------------------------------------------------------
377 void User::CalculateRating(float tourn_expect, float pre_expect) {
378 if((tourn_expect + pre_expect) > 0)
379 rating = (wins + (draws * 0.5)) / (pre_expect + tourn_expect);
380 } //-End of CalculateRating
382 //- AddManagedTourney -------------------------------------------------------
383 void User::AddManagedTourney(void) {
385 } //- End of AddManagedTourney
387 //- ChangeManagerLevel ------------------------------------------------------
388 void User::ChangeManagerLevel(int newLevel) {
389 managerLevel = newLevel;
390 } //- End of ChangeManagerLevel
392 //- CreateDirectory ---------------------------------------------------------
393 void User::CreateDirectory(char *path, char *user) {
394 struct stat statBuffer;
395 char filename[MAXPATHLEN];
397 sprintf(filename, "%s/%c", path, user[0]);
398 if(-1 == stat(filename, &statBuffer)) {
401 if(-1 == mkdir(filename, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IXOTH)) {
414 } //- End of CreateDirectory
416 //- GetMangerLevel ----------------------------------------------------------
417 int User::GetManagerLevel(void) {
418 return(managerLevel);
419 } //- End of GetManagerLevel