#include "extern.h"
#include <cctype>
#include <fstream.h>
+#include <crypt.h>
List<aClient> players;
Monster monsters[5][12];
-// Database functions For load/save
+// Database functions
int save_gs_dbase();
int load_gs_dbase();
int strnicmp(const char *s1, const char *s2, size_t len);
// String Functions
-// GameServ Booleans
-bool is_playing(char *u);
-bool has_started(char *u);
-bool is_fighting(char *u);
-bool isnt_fighting(char *u);
-bool player_fight(char *u);
-bool master_fight(char *u);
-// GameServ Booleans
+
+/********** Password functions **********/
+
+bool passcmp(char *encrypted, char *plaintext); // Compares an encrypted pass with a plain text one
+
+bool check_password(char *name, char *plaintext); // Finds a password for the given name, and checks it with passcmp against the plaintext password given.
+
+/********** Password functions **********/
+
+
+/********** GameServ Booleans **********/
+
+bool is_playing(char *u); // True if the given nickname in the clients list is playing.
+bool has_started(char *u); // True if the given nickname in the clients list has started playing.
+bool is_fighting(char *u); // True if the given nick in the clients list is fighting anything.
+bool isnt_fighting(char *u); // True if the given nick isn't fighting. Same as !is_fighting(u).
+bool player_fight(char *u); // True if the player is fighting another player.
+bool master_fight(char *u); // True if the player is fighting their master.
+
+/********** GameServ Booleans **********/
void display_monster(char *u);
aClient *user;
password = strtok(NULL, " ");
+ static char saltChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
+ static char salt[3];
+
+ salt[0] = saltChars[rand() % strlen(saltChars)];
+ salt[1] = saltChars[rand() % strlen(saltChars)];
+ salt[3] = '\0';
+
if (!password)
{
notice(s_GameServ, u, "SYNTAX: /msg %S REGISTER PASSWORD");
user->stats = new Player(user);
user->stats->started = 1;
user->stats->user = user; // Set the backwards pointer
+ strcpy(user->stats->password, crypt(password, salt));
players.insertAtBack(user);
}
else
outfile << it->name << ' ' << it->level << ' ' << it->exp << ' ' << it->gold << ' ' << it->bank << ' '
<< it->hp << ' ' << it->maxhp << ' ' << it->strength << ' ' << it->defense << ' '
<< it->armor << ' ' << it->weapon << ' ' << (it->alive ? "alive" : "dead") << ' '
- << it->forest_fights << ' ' << it->player_fights << endl;
+ << it->forest_fights << ' ' << it->player_fights << ' '
+ << it->password << endl;
ptr = ptr->Next();
}
outfile.close();
ifstream infile;
aClient *temp;
Player *p;
- char *alive, *tempname, *buf;
+ char *alive, *tempname, *buf, *password;
buf = new char[1023];
infile.open(playerdata);
p->alive = (stricmp(alive, "ALIVE") == 0 ? true : false);
p->forest_fights = stringtoint(strtok(NULL, " "));
p->player_fights = stringtoint(strtok(NULL, " "));
+ password = strtok(NULL, " ");
+ strcpy(p->password, password);
temp->setNick("NULL");
- printf("%s %d %ld %ld %ld %d %d %d %d %d %d %s %d %d\n", p->name, p->level, p->exp, p->gold, p->bank, p->hp, p->maxhp, p->strength, p->defense, p->armor, p->weapon, alive, p->forest_fights, p->player_fights);
+ printf("%s %d %ld %ld %ld %d %d %d %d %d %d %s %d %d %s\n", p->name, p->level,
+ p->exp, p->gold, p->bank, p->hp, p->maxhp, p->strength, p->defense, p->armor, p->weapon,
+ alive, p->forest_fights, p->player_fights, p->password);
+
players.insertAtBack(temp);
delete temp;
}
delete buf;
}
+bool passcmp(char *encrypted, char *plaintext)
+{
+ char salt[3];
+ salt[0] = encrypted[0];
+ salt[1] = encrypted[1];
+ salt[3] = '\0';
+ return (strcmp(encrypted, crypt(plaintext, salt)) == 0);
+}
+
+bool check_password(char *name, char *plaintext)
+{
+ ListNode<aClient> *tempPtr = clients.First();
+
+ while (tempPtr)
+ {
+ if (stricmp(name, tempPtr->getData()->getNick()) == 0)
+ return passcmp(tempPtr->getData()->stats->password, plaintext);
+
+ tempPtr = tempPtr->Next();
+ }
+ return false;
+}