Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2013-11-07 22:52:17 +0000
committerStijn Buys <ingar@osirion.org>2013-11-07 22:52:17 +0000
commit3aa51da4ec976665a7e74bb659868d474400a101 (patch)
tree8996920adcb3af1e933feef24456116eb7911cdc /src/core
parent87d5637c09dca61a650fe81d83ef328943176503 (diff)
Track the amount of time the player has spent,
make the 'impulse' command disable the autopilot.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/gameinterface.cc17
-rw-r--r--src/core/player.cc49
-rw-r--r--src/core/player.h27
3 files changed, 74 insertions, 19 deletions
diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc
index e7d7a31..a2d7fba 100644
--- a/src/core/gameinterface.cc
+++ b/src/core/gameinterface.cc
@@ -194,8 +194,6 @@ Player *GameInterface::find_player(const int playerid)
Player *GameInterface::find_player(const std::string &search)
{
- using aux::lowercase;
-
std::istringstream searchstr(search);
int id = 0;
if (searchstr >> id) {
@@ -210,7 +208,7 @@ Player *GameInterface::find_player(const std::string &search)
return 0;
for (std::list<Player *>:: iterator it = game_players.begin(); it != game_players.end(); it++) {
- if (aux::text_strip_lowercase((*it)->name()).find(lowercase(search)) != std::string::npos)
+ if (aux::text_strip_lowercase((*it)->name()).find(aux::lowercase(search)) != std::string::npos)
return (*it);
}
@@ -219,21 +217,20 @@ Player *GameInterface::find_player(const std::string &search)
void GameInterface::list_players()
{
- using namespace std;
int count = 0;
for (Players::iterator it = game_players.begin(); it != game_players.end(); it++) {
const Player *player = (*it);
- con_print << " "
- << aux::pad_left(player->name(), 24) << "^N "
- << "id^B" << setw(4) << player->id() << " "
- << "ping^B" << setw(4) << player->ping() << "^N "
- << "level^B" << setw(4) << player->level() << "^N";
+ con_print << " " << std::setfill(' ')
+ << aux::pad_left(player->name(), 24) << "^N "
+ << "id^B" << std::setw(4) << player->id() << " "
+ << "ping^B" << std::setw(4) << player->ping() << "^N "
+ << "level^B" << std::setw(4) << player->level() << "^N";
if (player->zone())
con_print << aux::pad_left(player->zone()->name(), 24) << "^N";
- con_print << std::endl;
+ con_print << std::endl;
count++;
}
diff --git a/src/core/player.cc b/src/core/player.cc
index eb5f08e..f744766 100644
--- a/src/core/player.cc
+++ b/src/core/player.cc
@@ -5,6 +5,7 @@
*/
#include <sstream>
+#include <iomanip>
#include "auxiliary/functions.h"
#include "sys/sys.h"
@@ -52,6 +53,9 @@ void Player::clear()
player_npckills = 0;
player_pvpkills = 0;
+
+ player_time_wasted = 0;
+ player_time_joined = 0;
}
@@ -59,14 +63,35 @@ void Player::print() const
{
con_print << "id: ^B" << id() << "^N name: ^B" << name() << "^N" << std::endl;
if (zone()) {
- con_print << " zone ^B" << zone()->name() << std::endl;
+ con_print << " zone ^B" << zone()->name() << std::endl;
}
- con_print << " color ^B" << color() << std::endl;
- con_print << " ping ^B" << ping() << std::endl;
- con_print << " credits ^B" << credits() << std::endl;
- con_print << " level ^B" << level() << std::endl;
- con_print << " npc kills ^B" << npckills() << std::endl;
- con_print << " pvp kills ^B" << pvpkills() << std::endl;
+ con_print << " color ^B" << color() << std::endl;
+ con_print << " ping ^B" << ping() << std::endl;
+ con_print << " credits ^B" << credits() << std::endl;
+ con_print << " level ^B" << level() << std::endl;
+ con_print << " npc kills ^B" << npckills() << std::endl;
+ con_print << " pvp kills ^B" << pvpkills() << std::endl;
+
+ con_print << " time wasted ^B";
+
+ long time_wasted = (player_time_wasted + server()->timestamp() - player_time_joined) / 1000;
+ const long time_wasted_seconds = time_wasted % 60;
+
+ time_wasted = (time_wasted - time_wasted_seconds) / 60;
+ const long time_wasted_minutes = time_wasted % 60;
+
+ time_wasted = (time_wasted - time_wasted_minutes) / 60;
+ const long time_wasted_hours = time_wasted % 24;
+
+ const long time_wasted_days = (time_wasted - time_wasted_hours) / 24;
+
+ if (time_wasted_days > 0) {
+ con_print << time_wasted_days << aux::plural("day", time_wasted_days) << " ";
+ }
+
+ con_print << std::setfill('0') << std::setw(2) << time_wasted_hours << ":"
+ << std::setfill('0') << std::setw(2) << time_wasted_minutes << ":"
+ << std::setfill('0') << std::setw(2) << time_wasted_seconds << std::endl;
}
void Player::message(Message::Channel channel, const std::string text)
@@ -156,6 +181,16 @@ void Player::set_pvpkills(const long kills)
player_pvpkills = kills;
}
+void Player::set_time_wasted(const long time_wasted)
+{
+ player_time_wasted = time_wasted;
+}
+
+void Player::set_time_joined()
+{
+ player_time_joined = server()->timestamp();
+}
+
void Player::update_info()
{
Cvar *cl_name = Cvar::find("cl_name");
diff --git a/src/core/player.h b/src/core/player.h
index 8b60eee..8d614ee 100644
--- a/src/core/player.h
+++ b/src/core/player.h
@@ -172,6 +172,23 @@ public:
{
return player_pvpkills;
}
+
+ /**
+ * @brief amount of time the player has previously spent in the game
+ * */
+ inline const long time_wasted() const
+ {
+ return player_time_wasted;
+ }
+
+ /**
+ * @brief timestamp of the the moment the player joined the game
+ * */
+ inline const long time_joined() const
+ {
+ return player_time_joined;
+ }
+
/*----- server-side mesage functions ------------------------------ */
@@ -236,6 +253,12 @@ public:
/// set the amount of credits the players has
void set_credits(const long amount);
+
+ /// set the amount of time the player has previously spent in the game
+ void set_time_wasted(const long time_wasted);
+
+ /// set the timestamp the player joined to the current server time
+ void set_time_joined();
/**
* @brief add an amount to the player's credits
@@ -336,9 +359,9 @@ private:
long player_pvpkills;
- unsigned long player_time_previously_wasted;
+ unsigned long player_time_wasted;
- unsigned long player_time_last_joined;
+ unsigned long player_time_joined;
};