From bf96f47d2c993112327f278eb2dd270b769e59aa Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 28 Jun 2009 19:41:48 +0000 Subject: Fixed remote entity owners --- src/core/entity.cc | 18 +++++++++++++----- src/core/netserver.cc | 12 ++++++++++-- 2 files changed, 23 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/core/entity.cc b/src/core/entity.cc index c62a412..5ddc149 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -12,6 +12,7 @@ #include "sys/sys.h" #include "core/entity.h" #include "core/cvar.h" +#include "core/application.h" namespace core { @@ -552,15 +553,22 @@ void EntityControlable::serialize_server_create(std::ostream & os) const void EntityControlable::receive_server_create(std::istream &is) { - unsigned int o; + int owner_id; EntityDynamic::receive_server_create(is); is >> entity_thrust; entity_thrust /= 100.0f; - is >> o; - - // FIXME resolve owner - entity_owner = 0; + if (is >> 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; + } } void EntityControlable::serialize_client_update(std::ostream & os) const diff --git a/src/core/netserver.cc b/src/core/netserver.cc index 73aa73d..2639b97 100644 --- a/src/core/netserver.cc +++ b/src/core/netserver.cc @@ -159,9 +159,17 @@ void NetServer::reap() if (client->error()) { - // notify the game server - if (client->state() == NetClient::Connected) + // notify other clients + for (Clients::iterator cit = clients.begin(); cit != clients.end(); cit++) { + if ((*cit) != (*it)) { + send_player_disconnect_info((*cit), (*it)->player()); + } + } + + if (client->state() == NetClient::Connected) { + // notify the game server server()->player_disconnect((*it)->player()); + } // remove the client delete client; -- cgit v1.2.3