#include "player.h"
#include "pouch.h"
#include "flags.h"
-#include "list.h"
#include "level.h"
#include "sockhelp.h"
#include "item.h"
void logout(aClient *user)
{
- if (is_playing(user))
+ if (user != NULL)
{
- list<Player*>::iterator iter;
- unsigned long hv = iHASH((unsigned char *) user->stats->getName().c_str());
- iter = find(players[hv].begin(), players[hv].end(), user->stats);
-
- if (iter == players[hv].end())
- {
- notice(s_GameServ, user->getNick(), "Fatal error. Contact "\
- "%S Admin. Cannot find you in the players list. This should NEVER happen");
- log("Error on logout(). Can't find %s in the players list",
+ if (user->stats != NULL)
+ {
+
+ list<Player*>::iterator iter;
+ unsigned long hv = iHASH((unsigned char *) user->stats->getName().c_str());
+ iter = find(players[hv].begin(), players[hv].end(), user->stats);
+
+ if (iter == players[hv].end())
+ {
+ notice(s_GameServ, user->getNick(), "Fatal error. Contact "\
+ "%S Admin. Cannot find you in the players list. This should NEVER happen");
+ log("Error on logout(). Can't find %s in the players list",
#ifdef P10
- user->getRealNick()
+ user->getRealNick()
#else
- user->getNick()
+ user->getNick()
#endif
- );
- return;
- }
- user->stats->delMonster();
- user->stats->delMaster();
- user->stats->delBattle();
- clearDragonFight(user->stats);
- clearYourTurn(user->stats);
- clearPlaying(user);
-
- user->stats->setClient(NULL);
- user->stats = NULL;
-
- if (player_fight(user))
- {
- clearYourTurn(user->stats->getBattle()->stats);
- user->stats->getBattle()->stats->delBattle();
- }
-
+ );
+ user->stats = NULL;
+
+ return;
+ }
+ user->stats->delMonster();
+ user->stats->delMaster();
+ user->stats->delBattle();
+ clearDragonFight(user->stats);
+ clearYourTurn(user->stats);
+ clearPlaying(user);
+
+ user->stats->setClient(NULL);
+
+
+ if (player_fight(user))
+ {
+ clearYourTurn(user->stats->getBattle()->stats);
+ user->stats->getBattle()->stats->delBattle();
+ }
+
#ifdef DEBUGMODE
- log("Logged out player %s",
+ log("Logged out player %s",
#ifdef P10
- user->getRealNick()
+ user->getRealNick()
#else
- user->getNick()
+ user->getNick()
#endif
- );
+ );
#endif
- }
-
+ }
+ }
+ if (user)
+ user->stats = NULL;
}
void do_register(char *u)
{
notice(s_GameServ, u, "SYNTAX: /msg %S REGISTER NAME PASSWORD");
}
+ else if (strlen(name) > maxnicklen)
+ {
+ notice(s_GameServ, u, "Name too long. Maximum length: %d", maxnicklen);
+ }
else if (!alphaNumeric(name))
{
notice(s_GameServ, u, "That is not a valid name. Please use only AlphaNumeric (A-Z, 0-9) characters!");
// Log the player in
setPlaying(user);
+ // Start the player at the beginning
+ reset(user->stats);
+
// Add the stick and clothes
tempItem = findItemByID(3001);
user->stats->inventory->addItem((*Items.begin()))->use(user->stats); // Add the stick
}
else
{
- updateTS(user->stats);
+ if (!is_fighting(user))
+ updateTS(user->stats);
showstats(u, user->stats->getName().c_str());
}
}
bool is_playing(aClient *user)
{
-
- if (!user || !user->stats)
+ if (!user)
{
return false;
}
- else if (user->stats->getClient() != user)
+ else if (!user->stats)
+ {
+ return false;
+ }
+ else if (!FL_is_playing(user))
{
return false;
}
- else if (!FL_is_playing(user))
+ else if (user->stats->getClient() != user)
{
return false;
}
{
if (!is_playing(user))
return false;
- else if (user->stats->getBattle() != NULL && is_playing(user->stats->getBattle()))
+ else if (is_playing(user->stats->getBattle()))
{
- return user->stats->getBattle()->stats != NULL;
+ return true;
}
return false;
}
return;
}
id = stringtoint(item);
- updateTS(user->stats);
+ if (!is_fighting(user))
+ updateTS(user->stats);
p = user->stats->inventory;
equip->use(user->stats);
}
}
+
void do_use(char *u)
{
aClient *user;
p->setExp(stringtoint(strtok(NULL, " ")));
p->setGold(stringtoint(strtok(NULL, " ")));
p->setBank(stringtoint(strtok(NULL, " ")));
- p->setHP(stringtoint(strtok(NULL, " ")));
+ tempnum = stringtoint(strtok(NULL, " "));
p->setMaxHP(stringtoint(strtok(NULL, " ")));
+ p->setHP(tempnum);
p->setStrength(stringtoint(strtok(NULL, " ")));
p->setDefense(stringtoint(strtok(NULL, " ")));
p->setForestFights(stringtoint(strtok(NULL, " ")));
notice(s_GameServ, u, "You must be playing to check your inventory!");
return;
}
- updateTS(user->stats);
+ if (!is_fighting(user))
+ updateTS(user->stats);
showinventory(user->stats, user);
}
notice(s_GameServ, u, "Just then you notice the eye begin to "\
"glare orange! The tooth is moving... but it is still too "\
"dark for you to make out.... THE DRAGON! You see it!");
- p->setMonster(new Monster(dragon));
+ p->setMonster(&dragon);
setDragonFight(p);
display_monster(u);
}
if (!is_fighting(user) && is_playing(user))
{
- Monster *temp;
Player *p = user->stats;
- temp = new Monster(levels[p->getLevel() - 1].master);
- p->setMyMaster(temp);
- p->setMonster(temp);
+ p->setMyMaster(&levels[p->getLevel() - 1].master);
+ p->setMonster(&levels[p->getLevel() - 1].master);
display_monster(u); // Since master is the same structure, use this function
}
}
void reset(Player *p)
{
item *tempItem;
+
if (!p)
return;
p->reset();
+ // Add the stick and clothes
tempItem = findItemByID(3001);
p->inventory->addItem((*Items.begin()))->use(p); // Add the stick
- p->inventory->addItem(tempItem)->use(p); // Add Clothes
-
+ p->inventory->addItem(tempItem)->use(p); // Add Clothes
}
void updateTS(Player *p)
#ifdef DEBUGMODE
log("New timestamp for %s: %ld", p->getName().c_str(), p->lastcommand);
#endif
+ PF_cleartimedout(p);
}
return;
char *nick = p->getClient()->getNick();
-
+
if (player_fight(p->getClient()) && isYourTurn(p))
{
// Check to see if they were the idler or if it was the other
// person
- if (p->lastcommand != p->getBattle()->stats->lastcommand)
+ if (!PF_timedout(p->getBattle()->stats))
{
// This person's last command was given earlier,
// so this person is the idler
// Chance to wake up, but if the other player doesn't
// Attack now, they both get logged out.
updateTS(p);
- p->getBattle()->stats->lastcommand = p->lastcommand;
+ PF_settimedout(p);
display_players(p->getBattle());
return;
}
{
sprintf(filename, "data/levels/level%d.dat", x);
if (levels[x - 1].loadLevel(filename) == false)
- return false;
+ {
+ delete []filename;
+ return false;
+ }
}
delete []filename;
if (!infile)
{
log("Error opening %s", filename);
+ delete []filename;
+ delete []buf;
return false;
}