Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/gameinterface.cc2
-rw-r--r--src/core/netconnection.cc13
-rw-r--r--src/core/netconnection.h3
-rw-r--r--src/core/netserver.cc9
-rw-r--r--src/core/player.cc7
-rw-r--r--src/core/player.h7
6 files changed, 39 insertions, 2 deletions
diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc
index 9551176..c566e41 100644
--- a/src/core/gameinterface.cc
+++ b/src/core/gameinterface.cc
@@ -128,7 +128,7 @@ void GameInterface::list_players()
for (Players::iterator it = game_players.begin(); it != game_players.end(); it++) {
msgstr.str("");
- con_print << setw(3) << (*it)->id() << aux::pad_left((*it)->name(), 24) << std::endl;
+ con_print << setw(3) << (*it)->id() << setw(5) << (*it)->ping() << aux::pad_left((*it)->name(), 24) << std::endl;
count++;
}
diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc
index 7e12ce7..267ff8f 100644
--- a/src/core/netconnection.cc
+++ b/src/core/netconnection.cc
@@ -400,6 +400,14 @@ void NetConnection::send_private_message(std::string const &text)
this->send_raw(msg);
}
+// send a ping reply
+void NetConnection::send_ping_reply()
+{
+ std::ostringstream msg;
+ msg << "ping " << timestamp() << '\n';
+ this->send_raw(msg.str());
+}
+
// parse incoming client messages
/**
* The following incoming messages are parsed;
@@ -466,11 +474,16 @@ void NetConnection::parse_incoming_message(const std::string & message)
abort();
} else if (command == "ping") {
+ unsigned long timestamp;
+ if ((msgstream >> timestamp)) {
+
+ }
} else if (command == "frame") {
unsigned long timestamp;
if ((msgstream >> timestamp)) {
connection_timestamp = timestamp;
+ send_ping_reply();
}
} else if (command == "die") {
diff --git a/src/core/netconnection.h b/src/core/netconnection.h
index e6e31f7..371ab04 100644
--- a/src/core/netconnection.h
+++ b/src/core/netconnection.h
@@ -100,6 +100,9 @@ public:
inline unsigned long timestamp() const { return connection_timestamp; }
protected:
+ /// send a ping reply
+ void send_ping_reply();
+
/// add a raw network message to the send queue
void send_raw(std::string const &msg);
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index b61ae1f..e6e85f8 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -398,8 +398,9 @@ void NetServer::frame(unsigned long timestamp)
* frame <timestamp> <previous timestamp>
* ent <id> <entity create data>
* die <id> <entity data>
+ * ping <timestamp>
* sup <entity update data>
-
+ *
* msg <channel> <text>
* supported message channels are "info" "public" "rcon" and "snd"
* "snd" is a special channel to transmit sound events
@@ -590,6 +591,12 @@ 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);
+ } else {
+ client->player()->set_ping(-1);
+ }
return;
}
diff --git a/src/core/player.cc b/src/core/player.cc
index b499003..c09cb6d 100644
--- a/src/core/player.cc
+++ b/src/core/player.cc
@@ -39,6 +39,8 @@ void Player::clear()
clear_assets();
player_control = 0;
+
+ player_ping = 0;
}
@@ -103,6 +105,11 @@ void Player::add_credits(long amount)
player_credits += amount;
}
+void Player::set_ping(long ping)
+{
+ player_ping = ping;
+}
+
void Player::update_info()
{
Cvar *cl_name = Cvar::find("cl_name");
diff --git a/src/core/player.h b/src/core/player.h
index dccd8e6..f0c4996 100644
--- a/src/core/player.h
+++ b/src/core/player.h
@@ -79,6 +79,9 @@ public:
/// credits
inline long credits() const { return player_credits; }
+ /// network ping
+ inline long ping() const { return player_ping; }
+
/// returns true of the player has enough credits to pay amount
inline bool has_credits(const long amount) const { return (player_credits >= amount); }
@@ -130,6 +133,8 @@ public:
void add_credits(long amount);
+ void set_ping(long ping);
+
inline void set_dirty() { player_dirty = true; }
@@ -171,7 +176,9 @@ private:
Zone *player_zone;
long player_credits;
+ long player_ping;
std::string player_rconpassword;
+
};
}