Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/gameinterface.cc17
-rw-r--r--src/core/player.cc49
-rw-r--r--src/core/player.h27
-rw-r--r--src/game/base/game.cc116
-rw-r--r--src/game/base/savegame.cc10
5 files changed, 114 insertions, 105 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;
};
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index 79fd167..f2db00c 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -103,6 +103,10 @@ void Game::func_join(core::Player *player, std::string const &args)
player->reputation().clear();
Faction::apply_default(player->reputation());
+
+ // reset player timestamps
+ player->set_time_wasted(0);
+ player->set_time_joined();
}
player->set_dirty();
@@ -151,8 +155,15 @@ void Game::func_impulse(core::Player *player, std::string const &args)
if (player->control()->moduletype() != ship_enttype)
return;
-
+
Ship * ship = static_cast<Ship *>(player->control());
+ if (ship->has_autopilot_flag(Ship::AutoPilotEnabled)) {
+ ship->set_autopilot_target(0);
+ ship->unset_autopilot_flag(Ship::AutoPilotEnabled);
+
+ // TODO replace with "Canceled" voice
+ player->send("Autopilot canceled");
+ }
ship->func_impulse();
}
@@ -167,10 +178,13 @@ void Game::func_freeflight(core::Player *player, std::string const &args)
Ship * ship = static_cast<Ship *>(player->control());
- ship->set_autopilot_target(0);
- ship->unset_autopilot_flag(Ship::AutoPilotEnabled);
- // TODO replace with "autopilot disabled" voice
- player->send("Autopilot disabled");
+ if (ship->has_autopilot_flag(Ship::AutoPilotEnabled)) {
+ ship->set_autopilot_target(0);
+ ship->unset_autopilot_flag(Ship::AutoPilotEnabled);
+
+ // TODO replace with "Canceled" voice
+ player->send("Autopilot canceled");
+ }
}
// autopilot goto
@@ -194,85 +208,11 @@ void Game::func_target_goto(core::Player *player, core::Entity *entity)
ship->set_autopilot_flag(Ship::AutoPilotEnabled);
ship->unset_autopilot_flag(Ship::AutoPilotDock);
ship->unset_autopilot_flag(Ship::AutoPilotFormation);
+
// TODO replace with "goto" voice
player->send("Autopilot set to " + entity->name());
}
-/*
-void Game::func_target_dock(core::Player *player, core::Entity *entity)
-{
- if (!player->control())
- return;
-
- if (player->control() == entity)
- return;
-
- if (player->control()->zone() != entity->zone())
- return;
-
- if ((entity->flags() & core::Entity::Dockable) == 0)
- return;
-
- if (player->control()->moduletype() != ship_enttype)
- return;
-
- if (!(entity->flags() & core::Entity::Dockable)) {
- return;
- }
-
- Ship * ship = static_cast<Ship *>(player->control());
-
- // check distance
- float range = entity->radius() + ship->radius();
-
- if (entity->moduletype() == planet_enttype) {
- range += PLANET_SAFE_DISTANCE;
- }
-
- core::Player *owner = (entity->type() == core::Entity::Controlable ? static_cast<core::EntityControlable *>(entity)->owner() : 0 );
- if (math::distance(entity->location(), ship->location()) > range) {
- if (owner) {
- player->send("^B" + owner->name() + "^B's " + entity->name() + " is out of range");
- } else {
- player->send("^B" + entity->name() + "^B is out of range");
- }
- return;
- }
-
- if ((player->control()->state() == core::Entity::Impulse) || (player->control()->state() == core::Entity::ImpulseInitiate)) {
- player->send("^BCan not dock at impulse speed");
- return;
- }
-
- if (player->control()->state() != core::Entity::Normal)
- return;
-
- if (entity->moduletype() == jumpgate_enttype) {
- // jumpgates have their own docking function
- JumpGate *jumpgate = static_cast<JumpGate *>(entity);
- jumpgate->func_dock(ship);
- return;
- } else if (entity->moduletype() == race_enttype) {
- RaceTrack *race = static_cast<RaceTrack *>(entity);
- race->func_dock(ship);
- } else {
- ship->set_dock(entity);
-
- if (player->control() == ship) {
- player->set_view(entity);
- if (owner) {
- player->send("^BDocking at " + owner->name() + "^B's " + entity->name());
- } else {
- player->send("^BDocking at " + entity->name());
- }
- }
-
- // force save
- core::server()->module()->player_save(player);
- }
-}
-*/
-
// a player sends a docking request
void Game::func_target_dock(core::Player *player, core::Entity *entity)
{
@@ -303,10 +243,8 @@ void Game::func_target_dock(core::Player *player, core::Entity *entity)
ship->set_autopilot_flag(Ship::AutoPilotDock);
ship->unset_autopilot_flag(Ship::AutoPilotFormation);
- if (math::distance(player->control()->location(), entity->location()) > (player->control()->radius() + entity->radius() + PLANET_SAFE_DISTANCE)) {
- // TODO replace with "dock" voice
- player->send("Autopilot set to dock at " + entity->name());
- }
+ // TODO replace with "dock" voice
+ player->send("Autopilot set to dock at " + entity->name());
}
void Game::func_target_formation(core::Player *player, core::Entity *entity)
@@ -2677,6 +2615,10 @@ void Game::game_load(core::Player *player, filesystem::IniFile & inifile)
return;
}
+ // reset player timestamps
+ player->set_time_wasted(0);
+ player->set_time_joined();
+
SaveGame::load_game(player, inifile);
}
@@ -2693,7 +2635,11 @@ void Game::player_load(core::Player *player)
if (core::server()->mode() != core::GameServer::MultiPlayer) {
return;
}
-
+
+ // reset player timestamps
+ player->set_time_wasted(0);
+ player->set_time_joined();
+
std::string guid(player->guid().str());
std::string directory(guid.substr(0,4));
diff --git a/src/game/base/savegame.cc b/src/game/base/savegame.cc
index b498717..90b7956 100644
--- a/src/game/base/savegame.cc
+++ b/src/game/base/savegame.cc
@@ -12,6 +12,8 @@
#include "base/ship.h"
#include "base/weapon.h"
+#include "core/gameserver.h"
+
namespace game {
void SaveGame::load_game(core::Player *player, filesystem::IniFile & inifile)
@@ -77,7 +79,9 @@ void SaveGame::load_game(core::Player *player, filesystem::IniFile & inifile)
} else if (inifile.got_key_long("pvpkills", l)) {
player->set_pvpkills(l);
- }
+
+ } else if (inifile.got_key_long("time", l)) {
+ player->set_time_wasted(l);
} else {
inifile.unknown_key();
@@ -98,6 +102,9 @@ void SaveGame::load_game(core::Player *player, filesystem::IniFile & inifile)
} else {
player->reputation().set_reputation(faction, reputation);
}
+ } else {
+ inifile.unknown_key();
+ }
} else if (inifile.in_section("ship")) {
@@ -314,6 +321,7 @@ void SaveGame::player_to_stream(core::Player *player, std::ostream & os)
os << "credits=" << player->credits() << std::endl;
os << "npckills=" << player->npckills() << std::endl;
os << "pvpkills=" << player->pvpkills() << std::endl;
+ os << "time=" << player->time_wasted() + core::server()->timestamp() - player->time_joined() << std::endl;
os << std::endl;
// player reputation