Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/commandbuffer.cc6
-rw-r--r--src/core/gameinterface.cc49
-rw-r--r--src/core/gameinterface.h3
-rw-r--r--src/core/gameserver.cc29
-rw-r--r--src/core/gameserver.h4
-rw-r--r--src/core/netconnection.cc20
-rw-r--r--src/core/netserver.cc8
-rw-r--r--src/core/player.cc40
-rw-r--r--src/core/player.h59
9 files changed, 150 insertions, 68 deletions
diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc
index e042eec..21002bd 100644
--- a/src/core/commandbuffer.cc
+++ b/src/core/commandbuffer.cc
@@ -100,7 +100,7 @@ void func_set(std::string const &args)
Cvar *cvar = Cvar::set(varname.c_str(), value.c_str(), Cvar::Archive);
if (cvar->flags() && Cvar::Info) {
- localplayer()->player_dirty = true;
+ localplayer()->set_dirty();
}
con_debug << " " << cvar->name() << " " << cvar->str() << "\n";
@@ -135,7 +135,7 @@ void func_toggle(std::string const &args)
}
if (cvar->flags() && Cvar::Info) {
- localplayer()->player_dirty = true;
+ localplayer()->set_dirty();
}
con_debug << " " << cvar->name() << " " << cvar->str() << "\n";
@@ -281,7 +281,7 @@ void CommandBuffer::exec(std::string const &cmdline)
(*cvar) = value;
if (cvar->flags() && Cvar::Info) {
- localplayer()->player_dirty = true;
+ localplayer()->set_dirty();
}
}
diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc
index c566e41..1695fb0 100644
--- a/src/core/gameinterface.cc
+++ b/src/core/gameinterface.cc
@@ -23,7 +23,18 @@ namespace core
void func_list_players(std::string const &args)
{
- game()->list_players();
+
+ if (args.size()) {
+ Player *player = game()->find_player(args);
+ if (!player) {
+ con_print << "^BPlayer '" + args + "^B' not found";
+ return;
+ } else {
+ player->print();
+ }
+ } else {
+ game()->list_players();
+ }
}
const float MIN_DELTA = 10e-10;
@@ -120,15 +131,45 @@ void GameInterface::clear()
game_players.clear();
}
+
+Player *GameInterface::find_player(const std::string &search)
+{
+ using aux::lowercase;
+
+ std::istringstream searchstr(search);
+ int id = 0;
+ if (searchstr >> id) {
+ for (std::list<Player *>:: iterator it = game_players.begin(); it != game_players.end(); it++) {
+ if ((*it)->id() == id) {
+ return (*it);
+ }
+ }
+ }
+
+ if (search.size() <3)
+ 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)
+ return (*it);
+ }
+
+ return 0;
+}
+
void GameInterface::list_players()
{
using namespace std;
- stringstream msgstr;
int count = 0;
for (Players::iterator it = game_players.begin(); it != game_players.end(); it++) {
- msgstr.str("");
- con_print << setw(3) << (*it)->id() << setw(5) << (*it)->ping() << aux::pad_left((*it)->name(), 24) << std::endl;
+ const Player *player = (*it);
+ con_print << " "
+ << "id^B" << setw(5) << player->id() << " "
+ << aux::pad_left(player->name(), 24) << "^N "
+ << "ping^B" << setw(5) << player->ping() << "^N "
+ << "level^B" << setw(3) << player->level() << "^N"
+ << std::endl;
count++;
}
diff --git a/src/core/gameinterface.h b/src/core/gameinterface.h
index f188475..22b85d5 100644
--- a/src/core/gameinterface.h
+++ b/src/core/gameinterface.h
@@ -32,6 +32,9 @@ public:
inline Players & players() { return game_players; }
+ /// find the first player who's id or name matches the search string
+ Player *find_player(const std::string &search);
+
/// show a list of connected players
void list_players();
diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc
index 44b8ccb..f7838a4 100644
--- a/src/core/gameserver.cc
+++ b/src/core/gameserver.cc
@@ -24,7 +24,7 @@ Player *console_find_player(std::string const & target)
{
Player *targetplayer = server()->find_player(target);
if (!targetplayer) {
- con_print << "^BPlayer " + target + "^B not found";
+ con_print << "^BPlayer '" + target + "^B' not found";
}
return targetplayer;
}
@@ -240,31 +240,6 @@ bool GameServer::interactive() const
}
}
-Player *GameServer::find_player(std::string const search)
-{
- using aux::lowercase;
-
- std::istringstream searchstr(search);
- int id = 0;
- if (searchstr >> id) {
- for (std::list<Player *>:: iterator it = game_players.begin(); it != game_players.end(); it++) {
- if ((*it)->id() == id) {
- return (*it);
- }
- }
- }
-
- if (search.size() <3)
- 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)
- return (*it);
- }
-
- return 0;
-}
-
void GameServer::say(Player *player, std::string const &message)
{
if (!message.size())
@@ -537,7 +512,7 @@ void GameServer::frame(unsigned long timestamp)
if (localplayer()->zonechange()) {
application()->notify_zonechange();
- localplayer()->player_zonechange = false;
+ localplayer()->set_zonechange(false);
}
/*if (!Cvar::sv_dedicated->value()) {
diff --git a/src/core/gameserver.h b/src/core/gameserver.h
index 59db0c5..31cfca6 100644
--- a/src/core/gameserver.h
+++ b/src/core/gameserver.h
@@ -74,8 +74,8 @@ public:
/// a player sends a command to the game server
void exec(Player *player, std::string const &cmdline);
- /// find the first player who's id or name matches the search string
- Player *find_player(std::string const search);
+ /// time the server was started
+ inline const unsigned long startup() const { return server_startup; }
/*----- static ---------------------------------------------------- */
diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc
index a3a2a43..790b037 100644
--- a/src/core/netconnection.cc
+++ b/src/core/netconnection.cc
@@ -93,7 +93,7 @@ void NetConnection::connect(std::string const &to_host, int to_port)
connection_keepalive = application()->time();
connection_state = Pending;
- game()->localplayer()->player_dirty = true;
+ game()->localplayer()->set_dirty();
con_print << "Connecting to " << inet_ntoa(*((struct in_addr *)serverhostent->h_addr)) << ":" << to_port << "..." << std::endl;
}
@@ -350,7 +350,7 @@ void NetConnection::send_playerinfo()
localplayer()->serialize_client_update(msg);
msg << '\n';
this->send_raw(msg.str());
- localplayer()->player_dirty = false;
+ localplayer()->set_dirty(false);
}
// send a "cup" client update message to the server
@@ -628,17 +628,25 @@ void NetConnection::parse_incoming_message(const std::string & message)
}
} else {
// find player
- // FIXME player might be localplayer()
Player *player = 0;
- for (GameInterface::Players::iterator it = game()->players().begin(); it != game()->players().end() && !player; it++) {
- if( (*it)->id() == player_id) {
- player = (*it);
+
+ if (player_id == connection()->localplayer()->id()) {
+ // check localplayer
+ player = connection()->localplayer();
+ } else {
+ // search other players
+ for (GameInterface::Players::iterator it = game()->players().begin(); it != game()->players().end() && !player; it++) {
+ if( (*it)->id() == player_id) {
+ player = (*it);
+ }
}
}
+
if (!player) {
player = new Player();
game()->players().push_back(player);
}
+
player->receive_server_update(msgstream);
}
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index 0854692..dd67809 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -273,7 +273,7 @@ NetClient * NetServer::client_connect(std::string const host, int const port)
}
clients.push_back(client);
- client->player()->player_dirty = false;
+ client->player()->set_dirty(false);
return client;
}
@@ -383,8 +383,8 @@ void NetServer::frame(unsigned long timestamp)
send_player_update(client);
- client->player()->player_dirty = false;
- client->player()->player_zonechange = false;
+ client->player()->set_dirty(false);
+ client->player()->set_zonechange(false);
}
client->transmit();
}
@@ -593,7 +593,7 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
if (command == "ping") {
unsigned long timestamp;
if (msgstream >> timestamp) {
- client->player()->set_ping(server()->timestamp() - timestamp);
+ client->player()->set_ping(application()->timestamp() - server()->startup() - timestamp);
}
return;
}
diff --git a/src/core/player.cc b/src/core/player.cc
index c09cb6d..ad6641e 100644
--- a/src/core/player.cc
+++ b/src/core/player.cc
@@ -44,6 +44,20 @@ void Player::clear()
}
+void Player::print() const
+{
+ con_print << "id: ^B" << id() << "^N name: ^B" << name() << "^N" << 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;
+
+ if (zone()) {
+ con_print << " zone ^B" << zone()->name() << std::endl;
+ }
+
+}
+
void Player::send(const std::string text)
{
message(core::Message::Info, text);
@@ -95,21 +109,25 @@ void Player::set_mission_target(Entity *new_mission_target)
}
}
-void Player::set_credits(long amount)
+void Player::set_credits(const long amount)
{
player_credits = amount;
}
-void Player::add_credits(long amount)
+void Player::add_credits(const long amount)
{
player_credits += amount;
}
-void Player::set_ping(long ping)
+void Player::set_ping(const long ping)
{
player_ping = ping;
}
+void Player::set_level(const int level) {
+ player_level = level;
+}
+
void Player::update_info()
{
Cvar *cl_name = Cvar::find("cl_name");
@@ -184,12 +202,24 @@ void Player::serialize_server_update(std::ostream & os) const
unsigned int control_id = (player_control ? player_control->id() : 0);
unsigned int mission_id = (player_mission_target ? player_mission_target->id() : 0);
- os << player_id << " " << zone_id << " " << view_id << " " << control_id << " " << mission_id << " " << player_color << " ";
+ os << player_id << " "
+ << zone_id << " "
+ << view_id << " "
+ << control_id << " "
+ << mission_id << " "
+ << player_color << " ";
}
void Player::receive_server_update(std::istream &is)
{
- is >> player_id;
+ int id = 0;
+ is >> id;
+ if (!player_id) {
+ player_id = id;
+ } else if (player_id != id) {
+ con_warn << "received inconsistent player update for player " << id << "\n";
+ return;
+ }
unsigned int zone_id = 0;
is >> zone_id;
diff --git a/src/core/player.h b/src/core/player.h
index f0c4996..4620062 100644
--- a/src/core/player.h
+++ b/src/core/player.h
@@ -46,11 +46,6 @@ public:
/// the entity the Player is currently controling
inline EntityControlable *control() const { return player_control; }
- /// set the entity the player is currenty controlling
- /** This will automaticly set zone() to the zone the entity is in
- */
- void set_control(EntityControlable *entitycontrolable);
-
/// the zone the player is currently in
inline Zone *zone() const { return player_zone; }
@@ -85,6 +80,12 @@ public:
/// returns true of the player has enough credits to pay amount
inline bool has_credits(const long amount) const { return (player_credits >= amount); }
+ /// print player info to console
+ virtual void print() const;
+
+ /// player level
+ const int level() const { return player_level; }
+
/*----- messages -------------------------------------------------- */
void send(const std::string name);
@@ -125,26 +126,43 @@ public:
/// update player info from client variables
void update_info();
+ /**
+ * @brief set the entity the player is currenty controlling
+ * This will automaticly set zone() to the zone the entity is in
+ */
+ void set_control(EntityControlable *entitycontrolable);
+
+ /// set mission target
void set_mission_target(Entity *new_mission_target);
+ /// set the current view
void set_view(Entity *view);
- void set_credits(long amount);
+ /// set the amount of credits the players has
+ void set_credits(const long amount);
- void add_credits(long amount);
+ /**
+ * @brief add an amount to the player's credits
+ * @param amount the amount of credits to add, can be negative
+ */
+ void add_credits(const long amount);
- void set_ping(long ping);
+ /**
+ * @brief set the player's network ping
+ */
+ void set_ping(const long ping);
- inline void set_dirty() { player_dirty = true; }
+ /// set the player level
+ void set_level(const int level);
-/* -- should actually not be public --*/
+ /// set the dirty bit
+ inline void set_dirty(const bool dirty = true) { player_dirty = dirty; }
- /// dirty state
- bool player_dirty;
+ /// set the zonechange bit
+ inline void set_zonechange(const bool dirty = true) { player_zonechange = dirty; }
- /// player has changed zone
- bool player_zonechange;
+/* -- should actually not be public --*/
/// id of the player
int player_id;
@@ -164,12 +182,13 @@ public:
std::list<EntityControlable *> assets;
private:
- // the entity the Player is currently controling
+ // entity the Player is currently controling
EntityControlable *player_control;
- // the entity the PLayer is currently looking at
+ // entity the Player is currently looking at
Entity *player_view;
+ // current mission target
Entity *player_mission_target;
// the zone the player is currently in
@@ -178,7 +197,13 @@ private:
long player_credits;
long player_ping;
std::string player_rconpassword;
-
+ int player_level;
+
+ // dirty bit
+ bool player_dirty;
+ // bit to indicate zone has changed
+ bool player_zonechange;
+
};
}