int forestfights; // Forest fights per day
int maxafightdistance; // Max levels above a player they can fight player->player
int maxbfightdistance; // Max levels below a player they can fight player->player
+int maxidletime; // Max time (in seconds) a player can be idle for
+int idlecheckperiod; // Period for checking every player's idle time
// Remote server stuff. This is used for the outgoing connection gameserv needs to make
// to a real ircd.
{
char *buf, *directive, *value;
- #define numdirectives 19
+ #define numdirectives 21
unload_config_file();
"that you can fight player->player";
directives[18].desc = "MAXBFIGHTDISTANCE - The maximum number of levels below you "\
"that you can fight player->player";
+ directives[19].desc = "MAXIDLETIME - The maximum amount of time (in seconds) "\
+ "that a player can be idle before something happens";
+ directives[20].desc = "IDLECHECKPERIOD - The period (in seconds) in which the entire "\
+ "players list will be checked for idlers. See also: "\
+ "MAXIDLETIME";
for (int count = 0; count < numdirectives; count++)
{
maxbfightdistance = stringtoint(value);
directives[18].done = true;
}
+ else if (stricmp(directive, "MAXIDLETIME") == 0)
+ {
+ value = strtok(NULL, " ");
+ maxidletime = stringtoint(value);
+ directives[19].done = true;
+ }
+ else if (stricmp(directive, "IDLECHECKPERIOD") == 0)
+ {
+ value = strtok(NULL, " ");
+ idlecheckperiod = stringtoint(value);
+ directives[20].done = true;
+ }
else
{
#ifdef DEBUGMODE
/********** GameServ Booleans **********/
bool shuttingdown;
+bool timedOut(Player *p);
+void updateTS(Player *p);
+void timeOutEvent(Player *p);
+
bool is_playing(char *u); // True if the given nickname in the clients list is playing.
bool is_playing(aClient *user);
char *spaces(int len, char *seperator);
void refresh(Player *p);
void refreshall();
+void updateTS(Player *p);
void reset(Player *p);
void init_masters();
void init_monsters();
void do_register(char *u)
{
char *password, *name;
- aClient *user, *p;
+ aClient *user;
name = strtok(NULL, " ");
password = strtok(NULL, " ");
}
else if ((user = find(u)))
{
- p = findplayer(u);
- if (!user->stats && !p)
+ if (!user->stats)
{
user->stats = new Player(user);
user->stats->client = user; // Set the backwards pointer
strcpy(user->stats->password, crypt(password, salt));
strcpy(user->stats->name, name);
unsigned long hv = HASH((unsigned char *) name, U_TABLE_SIZE);
+ updateTS(user->stats);
players[hv].insertAtBack(user);
notice(s_GameServ, u, "Player %s registered with password %s.", user->stats->name, password);
notice(s_GameServ, u, "Write this password down. If you lose it, there is no way to retrieve it!");
#ifdef DEBUGMODE
log("Setting data for identified");
#endif
+ updateTS(user->stats);
+
user->stats->setData(p->stats);
#ifdef DEBUGMODE
return;
}
else
+ {
+ updateTS(user->stats);
showstats(u, user->stats->name);
+ }
}
else
showstats(u, nick);
{
aClient *user;
if (!(user = find(u)))
- {
return false;
- }
else
- {
- return user->stats != NULL;
- }
+ return is_playing(user);
}
bool is_playing(aClient *user)
{
- return user->stats != NULL && (stricmp(user->getNick(), "!NULL!") != 0);
+ return user->stats != NULL;
}
bool is_fighting(char *u)
aClient *user;
if (!(user = find(u)))
- {
return false;
- }
- else if (user->stats)
- {
- return user->stats->fight != NULL || user->stats->battle != NULL
- || user->stats->master != NULL;
- }
else
- return false;
+ return is_fighting(user);
}
+
bool is_fighting(aClient *user)
{
if (!is_playing(user))
if (!(user = find(u)))
return false;
- else if (user->stats)
- return user->stats->battle != NULL;
- else
- return false;
+ else
+ return player_fight(user);
}
bool player_fight(aClient *user)
{
if (!(user = find(u)))
return false;
- else if (user->stats)
- return user->stats->master != NULL;
else
- return false;
+ return master_fight(user);
}
+
bool master_fight(aClient *user)
{
if (!is_playing(user))
if (!nick)
{
notice(s_GameServ, u, "SYNTAX: /msg %S FIGHT PLAYER");
+ return;
}
else if (!(ni = find(u)))
{
notice(s_GameServ, u, "Fatal error. Contact a(n) %S admin. buf: %s", strtok(NULL, ""));
+ return;
}
else if (!is_playing(ni))
{
notice(s_GameServ, u, "You are not playing!");
+ return;
}
- else if (ni->stats->player_fights <= 0)
+
+ updateTS(ni->stats);
+
+ if (ni->stats->player_fights <= 0)
{
ni->stats->player_fights = 0; // just to be safe
notice(s_GameServ, u, "You are out of player fights for the "\
display_players(ni);
}
}
+
void do_use(char *u)
{
aClient *user;
return;
}
+ updateTS(user->stats);
+
p = &user->stats->inventory;
if (stricmp(item, "HEALTH") == 0)
return;
}
+ updateTS(user->stats);
p = user->stats;
if (p->battle)
// One has to be !NULL based on the previous else if
// We wouldn't be here if they were all NULL
}
+ updateTS(ni->stats);
if (!player_fight(ni))
{
if (!amount)
{
notice(s_GameServ, u, "SYNTAX: /msg %S HEAL {ALL | #}");
+ return;
}
else if (!(ni = find(u)))
{
else if (is_fighting(ni))
{
notice(s_GameServ, u, "You can't heal in battle!");
+ return;
}
else if (ni->stats->hp >= ni->stats->maxhp)
{
notice(s_GameServ, u, "You don't need healing!");
+ return;
}
- else if (stricmp(amount, "ALL") == 0)
+
+ updateTS(ni->stats);
+ if (stricmp(amount, "ALL") == 0)
{
price = ni->stats->level * 3;
if (ni->stats->gold < (ni->stats->maxhp - ni->stats->hp) * price)
notice(s_GameServ, u, "SYNTAX: STORE LIST {ARMOR | WEAPONS}");
notice(s_GameServ, u, " \ 2STORE SELL {ARMOR | WEAPON}\ 2");
notice(s_GameServ, u, " \ 2STORE BUY {ARMOR | WEAPON} \1fNUMBER\1f\ 2");
+ return;
}
else if (!(user = find(u)) || !is_playing(user))
+ {
notice(s_GameServ, u, "You must be playing to use the store!");
+ return;
+ }
else if (!isAlive(user->stats))
{
notice(s_GameServ, u, "You are dead. Wait until tomorrow to purchase weapons and armor!");
return;
}
- else if (stricmp(cmd, "LIST") == 0)
+ updateTS(user->stats);
+
+ if (stricmp(cmd, "LIST") == 0)
{
if (stricmp(item, "WEAPONS") == 0)
{
notice(s_GameServ, u, "You must be playing to check your inventory!");
return;
}
+ updateTS(user->stats);
showinventory(user, user);
}
void showinventory(aClient *from, aClient *to)
notice(s_GameServ, u, "You cannot go to the Tavern during a fight!");
return;
}
+
+ updateTS(user->stats);
p = user->stats;
+
if (!cmd)
{
notice(s_GameServ, u, "Welcome to Boot Liquors Mystic Apothecary");
notice (s_GameServ, u, "BANK BALANCE");
return;
}
-
- user = find(u);
- if (!is_playing(user))
+ else if (!(user = find(u)))
+ {
+ notice(s_GameServ, u, "Fatal Error. Couldn't find your aClient. Contact a(n) %S "\
+ " admin for help");
+ log("Fatal Error. Couldn't find %s while executing do_bank()", u);
+ return;
+ }
+ else if (!is_playing(user))
{
notice(s_GameServ, u, "You must be playing to use the bank!");
return;
}
- else if (stricmp(cmd, "BALANCE") == 0)
+
+ updateTS(user->stats);
+ if (stricmp(cmd, "BALANCE") == 0)
{
showBankBalance(u);
return;
notice(s_GameServ, u, "You must be playing to see your master!");
return;
}
-
+
+ updateTS(user->stats);
char *cmd = strtok(NULL, " ");
Player *p = user->stats;
long int need = 0;
p->reset();
}
+void updateTS(Player *p)
+{
+ if (!p)
+ return;
+ p->lastcommand = time(NULL);
+}
+
+bool timedOut(Player *p)
+{
+ if (!p)
+ return false;
+ else
+ return ((time(NULL) - p->lastcommand) >= maxidletime);
+}
+
+void timeOutEvent(Player *p)
+{
+ aClient *user = p->client;
+
+ if (!user) // then they're not playing
+ return;
+
+ char *nick = user->getNick();
+
+ notice(s_GameServ, nick, "You just idle timed out");
+ logout(user);
+}
+
void do_reset(char *u)
{
char *nick = strtok(NULL, " ");