+ strcpy(p->name, myname);
+ delete [] myname;
+}
+
+void updateTS(Player *p)
+{
+ if (!p)
+ return;
+
+ #ifdef DEBUGMODE
+ log("Old timestamp for %s: %ld", p->name, p->lastcommand);
+ #endif
+ p->lastcommand = time(NULL);
+ #ifdef DEBUGMODE
+ log("New timestamp for %s: %ld", p->name, p->lastcommand);
+ #endif
+
+}
+
+bool timedOut(Player *p)
+{
+ if (!p)
+ return false;
+ else if (p->lastcommand == 0)
+ return false;
+ else
+ {
+ if ((time(NULL) - p->lastcommand) >= maxidletime)
+ return true;
+
+ return false;
+ }
+}
+
+void timeOutEvent(Player *p)
+{
+ aClient *user = findplayer(p->name);
+
+ if (!user || !p->client) // then they're not playing
+ return;
+
+ char *nick = user->getNick();
+
+ if (player_fight(user) && isYourTurn(p))
+ {
+ // Check to see if they were the idler or if it was the other
+ // person
+ if (p->lastcommand != p->battle->stats->lastcommand)
+ {
+ // This person's last command was given earlier,
+ // so this person is the idler
+ notice(s_GameServ, nick, "You timed out "\
+ "during a fight. You lose your turn!");
+ notice(s_GameServ, p->battle->getNick(),
+ "%s hesitated for too long. Your move.", p->name);
+ clearYourTurn(p);
+ setYourTurn(p->battle->stats);
+
+ // Update the TS for both players to give them another
+ // Chance to wake up, but if the other player doesn't
+ // Attack now, they both get logged out.
+ updateTS(p);
+ p->battle->stats->lastcommand = p->lastcommand;
+ display_players(p->battle);
+ return;
+ }
+ else
+ {
+ notice(s_GameServ, p->battle->getNick(),
+ "You and %s timed out at the same time."\
+ " Don't fight if you're just going to "\
+ "sit there!", p->name);
+ notice(s_GameServ, user->getNick(),
+ "You and %s timed out at the same time."\
+ " Don't fight if you're just going to "\
+ "sit there!", p->battle->stats->name);
+ logout(p->battle);
+ logout(user);
+ return;
+ }
+ }
+ else if (!player_fight(user))
+ {
+ if (isAlive(user->stats) && user->stats->gold > 0)
+ {
+ // Place fun stuff here :)
+ int randnum = 1 + rand() % 100; // 1-100
+ #define GSN(s) notice(s_GameServ, nick, s)
+ #define GSN2(s, f) notice(s_GameServ, nick, s, f)
+
+ if (randnum < 50)
+ {
+ // 35-100% of your gold goes pffft - kain
+ int stolen = (35 + (rand() % 66)) * user->stats->gold / 100;
+
+ GSN("You stop for a moment to rest on the "\
+ "street corner. All of a sudden, you "\
+ "are ambushed from all sides by a hoarde "\
+ "of knife wielding thugs.");
+ GSN2("The thugs beat you into utter submission "\
+ "and steal %d gold from you!", stolen);
+ user->stats->gold -= stolen;
+ }
+ else if (randnum >= 50 && randnum < 75)
+ {
+ // 25-65% of your gold goes pffft - kain
+ int stolen = (25 + (rand() % 41)) * user->stats->gold / 100;
+ GSN("While dilly dallying around, you lose "\
+ "your sense of time. Little did you know, "\
+ "but thieves lifted your gold while you "\
+ "weren't watching.");
+ GSN2("Better luck next time... you lose %d gold", stolen);
+ user->stats->gold -= stolen;
+ }
+ else if (randnum >= 75)
+ {
+ // 25-75% of your gold goes pffft - kain
+ int stolen = (25 + (rand() % 51)) * user->stats->gold / 100;
+ GSN("Good grief! A gaggle of gooey green ghostlike "\
+ "goblins grabbed your gold!");
+ GSN2("They stole %d gold from you!", stolen);
+ user->stats->gold -= stolen;
+ }
+ }
+
+ // Always log out the user
+ logout(user);
+ }