Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2009-06-29 18:22:07 +0000
committerStijn Buys <ingar@osirion.org>2009-06-29 18:22:07 +0000
commit024532b748b15a92303fd20c3b6a7062a37ca2ed (patch)
treea313dee0aed03c27582a68432e40b96ab90dfbed
parentbf96f47d2c993112327f278eb2dd270b769e59aa (diff)
client player list updates, short pif network messages, bump to network proto version 17
-rw-r--r--src/client/hud.cc6
-rw-r--r--src/core/entity.cc17
-rw-r--r--src/core/gameinterface.cc6
-rw-r--r--src/core/net.h2
-rw-r--r--src/core/netconnection.cc5
-rw-r--r--src/core/netserver.cc7
-rw-r--r--src/core/player.cc52
-rw-r--r--src/core/player.h6
8 files changed, 82 insertions, 19 deletions
diff --git a/src/client/hud.cc b/src/client/hud.cc
index ca7db56..3d32d3a 100644
--- a/src/client/hud.cc
+++ b/src/client/hud.cc
@@ -194,13 +194,17 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target)
// owner name
if (entity->type() == core::Entity::Controlable) {
- render::Text::setcolor('B');
const core::EntityControlable *ec = static_cast<core::EntityControlable *>(entity);
if (ec->owner()) {
render::Text::setcolor('B');
render::Text::draw(cx-aux::text_length(entity->name()) * render::Text::fontwidth()*0.5f,
cy-r-4-2*render::Text::fontheight(), ec->owner()->name());
}
+ render::Text::setcolor('B');
+
+ } else if (entity == core::localplayer()->mission_target()) {
+ gl::color(palette()->mission());
+
} else {
render::Text::setcolor('N');
}
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 5ddc149..731b13b 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -553,21 +553,26 @@ void EntityControlable::serialize_server_create(std::ostream & os) const
void EntityControlable::receive_server_create(std::istream &is)
{
- int owner_id;
-
EntityDynamic::receive_server_create(is);
+
is >> entity_thrust;
entity_thrust /= 100.0f;
- if (is >> owner_id) {
+
+ entity_owner = 0;
+
+ int owner_id = 0;
+ is >> owner_id;
+ if (owner_id) {
for (GameInterface::Players::iterator pit = game()->players().begin(); pit != game()->players().end(); pit++ ) {
Player *player = (*pit);
if (player->id() == owner_id) {
entity_owner = player;
- player->add_asset(this);
}
}
- } else {
- entity_owner = 0;
+
+ if (!entity_owner) {
+ con_warn << "could not find owner " << owner_id << " for entity " << id() << "\n";
+ }
}
}
diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc
index 53e5715..5f3c91a 100644
--- a/src/core/gameinterface.cc
+++ b/src/core/gameinterface.cc
@@ -173,10 +173,10 @@ void GameInterface::list_players()
for (Players::iterator it = game_players.begin(); it != game_players.end(); it++) {
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(5) << player->level() << "^N";
+ << "id^B" << setw(4) << player->id() << " "
+ << "ping^B" << setw(4) << player->ping() << "^N "
+ << "level^B" << setw(4) << player->level() << "^N";
if (player->zone())
con_print << aux::pad_left(player->zone()->name(), 24) << "^N";
diff --git a/src/core/net.h b/src/core/net.h
index 01c15be..cd8e249 100644
--- a/src/core/net.h
+++ b/src/core/net.h
@@ -11,7 +11,7 @@ namespace core
{
/// network protocol version
-const unsigned int PROTOCOLVERSION = 16;
+const unsigned int PROTOCOLVERSION = 17;
/// maximum lenght of a (compressed) network message block
const unsigned int FRAMESIZE = 1152;
diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc
index dfb86f7..81f5b48 100644
--- a/src/core/netconnection.cc
+++ b/src/core/netconnection.cc
@@ -614,6 +614,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
return;
}
+ // normal "pif" message about localplayer
if (!player_id) {
Zone *oldzone = connection()->localplayer()->zone();
connection()->localplayer()->receive_server_update(msgstream);
@@ -639,6 +640,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
oldzone->content().clear();
}
+ // short "pif" message about a different player
} else if (player_id != localplayer()->id()) {
// find player
@@ -656,7 +658,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
game()->players().push_back(player);
}
- player->receive_server_update(msgstream);
+ player->receive_short_server_update(msgstream);
player->set_dirty(false);
}
@@ -679,7 +681,6 @@ void NetConnection::parse_incoming_message(const std::string & message)
Player *player = 0;
for (GameInterface::Players::iterator it = game()->players().begin(); it != game()->players().end() && !player; it++) {
if( (*it)->id() == player_id) {
- // TODO find player assets and set owner to 0
game()->players().erase(it);
return;
}
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index 2639b97..7416d9f 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -398,13 +398,14 @@ void NetServer::frame(unsigned long timestamp)
client->transmit();
+ // send game state changes
if (client->state() == NetClient::Connected)
client_frame(client, timestamp);
- // update player info always gets through
if (client->player()->dirty() || client->player()->zonechange()) {
send_player_update(client);
}
+
client->transmit();
}
@@ -537,12 +538,12 @@ void NetServer::send_player_update(NetClient *client)
client->send_raw(msg.str());
}
-// send a "pif" update player information to a single player
+// send a short "pif" update player information to a single player
void NetServer::send_player_update(NetClient *client, Player *player)
{
std::ostringstream msg;
msg << "pif " << player->id() << ' ';
- player->serialize_server_update(msg);
+ player->serialize_short_server_update(msg);
msg << '\n';
client->send_raw(msg.str());
}
diff --git a/src/core/player.cc b/src/core/player.cc
index 9a3ec9b..4276f20 100644
--- a/src/core/player.cc
+++ b/src/core/player.cc
@@ -214,7 +214,6 @@ void Player::serialize_server_update(std::ostream & os) const
<< view_id << " "
<< control_id << " "
<< mission_id << " "
- << player_color << " "
<< player_credits << " "
<< player_level << " "
<< player_ping;
@@ -263,10 +262,9 @@ void Player::receive_server_update(std::istream &is)
} else {
player_mission_target = 0;
}
- is >> player_color;
+
is >> player_credits;
is >> player_level;
-
is >> player_ping;
/*
@@ -281,6 +279,54 @@ void Player::receive_server_update(std::istream &is)
*/
}
+void Player::serialize_short_server_update(std::ostream & os) const
+{
+ unsigned int zone_id = (zone() ? zone()->id() : 0);
+
+ os << player_id << " "
+ << "\"" << player_name << "\" "
+ << zone_id << " "
+ << player_color << " "
+ << player_color_second << " "
+ << player_level << " "
+ << player_ping;
+
+}
+
+void Player::receive_short_server_update(std::istream &is)
+{
+ // read player id
+ int id = 0;
+ is >> id;
+ if (!player_id) {
+ player_id = id;
+ } else if (player_id != id) {
+ con_warn << "received inconsistent short update for player " << id << "\n";
+ return;
+ }
+
+ // read player name
+ std::string n;
+ char c;
+ while ( (is.get(c)) && (c != '"'));
+ while ( (is.get(c)) && (c != '"'))
+ n += c;
+
+ if (n.size())
+ player_name = n;
+
+ // read zone id
+ unsigned int zone_id = 0;
+ is >> zone_id;
+ set_zone(Zone::find(zone_id));
+
+ // read attributes
+ is >> player_color;
+ is >> player_color_second;
+ is >> player_level;
+ is >> player_ping;
+}
+
void Player::add_asset(EntityControlable *entity)
{
entity->entity_owner = this;
diff --git a/src/core/player.h b/src/core/player.h
index 35a2f82..fc6740d 100644
--- a/src/core/player.h
+++ b/src/core/player.h
@@ -121,6 +121,12 @@ public:
/// receive player info from a stream
void receive_client_update(std::istream &is);
+ /// serialize short player info to a stream
+ void serialize_short_server_update(std::ostream & os) const;
+
+ /// receive short player info from a stream
+ void receive_short_server_update(std::istream &is);
+
/// clear all the data
void clear();