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>2012-10-20 16:35:26 +0000
committerStijn Buys <ingar@osirion.org>2012-10-20 16:35:26 +0000
commit75274ebd6ba90784f5aa837b7e5ea97fc6bfb720 (patch)
treea5d51a87bf3f20833df18bc40a3254b946716afb /src/core/netconnection.cc
parentf01629dc14b1ee05b44d2e38b3dffbc1441fd85f (diff)
Item id based inventory, support for weapon dealers.
Diffstat (limited to 'src/core/netconnection.cc')
-rw-r--r--src/core/netconnection.cc68
1 files changed, 55 insertions, 13 deletions
diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc
index 3c68be9..24f6a3d 100644
--- a/src/core/netconnection.cc
+++ b/src/core/netconnection.cc
@@ -754,7 +754,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
oldzone->content().clear();
}
- // short "pif" message about a different player
+ // short "pif" message about a different player
} else if (player_id != localplayer()->id()) {
// find player
@@ -895,49 +895,91 @@ void NetConnection::parse_incoming_message(const std::string & message)
} else if (command.compare("inv") == 0) {
// received inventory update
- unsigned int id = 0;
+ unsigned int entity_id = 0;
unsigned long server_timestamp;
- // read id
- if (!(msgstream >> id >> server_timestamp)) {
+ // read entity id and server timestamp
+ if (!(msgstream >> entity_id >> server_timestamp)) {
con_warn << "Received invalid inventory update message!" << std::endl;
return;
}
- Entity *entity = Entity::find(id);
+ Entity *entity = Entity::find(entity_id);
if (!entity) {
- con_warn << "Received inventory update for non-existing entity " << id << "!" << std::endl;
+ con_warn << "Received inventory update for non-existing entity " << entity_id << "!" << std::endl;
return;
}
if (!entity->inventory()) {
- con_warn << "Received inventory update for entity " << id << " without inventory!" << std::endl;
+ con_warn << "Received inventory update for entity " << entity_id << " without inventory!" << std::endl;
return;
}
- //con_debug << "CLIENT received inv message for entity " << id << " client timestamp " << entity->inventory()->timestamp() << " server timestamp " << server_timestamp << std::endl;
-
if (server_timestamp < entity->inventory()->timestamp())
return;
+ unsigned int item_id = 0;
+ unsigned int info_id = 0;
+
+ int full_update = 0;
+ if (!(msgstream >> full_update)) {
+ con_warn << "Received inventory update for entity " << entity_id << " without full update marker!" << std::endl;
+ return;
+ }
+
+ if (full_update == 1) {
+ // mark all items dirty
+ for (Inventory::Items::iterator it = entity->inventory()->items().begin(); it != entity->inventory()->items().end(); ++it) {
+ (*it)->set_dirty();
+ }
+ }
+
size_t nbitems = 0;
if (!(msgstream >> nbitems))
nbitems = 0;
//con_debug << "CLIENT number of items: " << nbitems << std::endl;
+ // receive item updates
for (size_t i = 0; i < nbitems; i++) {
- if (!(msgstream >> id)) {
- con_warn << "Received inventory update without info id for existing entity " << id << "!" << std::endl;
+ // read item id
+ if (!(msgstream >> item_id)) {
+ con_warn << "Received inventory item update for entity " << entity_id << " without item id!" << std::endl;
+ return;
+ }
+ // read info id
+ if (!(msgstream >> info_id)) {
+ con_warn << "Received inventory item update for entity " << entity_id << " without info id!" << std::endl;
return;
}
- Info *info = core::game()->request_info(id);
- Item *item = entity->inventory()->find(info);
+ Info *info = core::game()->request_info(info_id);
+ Item *item = entity->inventory()->find(item_id);
if (!item) {
item = new Item(info);
entity->inventory()->add(item);
+ item->set_id(item_id);
+ } else {
+ if (item->info() != info) {
+ item->set_info(info);
+ }
}
item->receive_server_update(msgstream);
+ item->set_dirty(false);
}
+
+ if (full_update == 1) {
+ // remove items for which no update was received
+ for (Inventory::Items::iterator it = entity->inventory()->items().begin(); it != entity->inventory()->items().end();) {
+ Item *item = (*it);
+ if (item->dirty()) {
+ delete (item);
+ (*it) = 0;
+ entity->inventory()->items().erase(it++);
+ } else {
+ ++it;
+ }
+ }
+ }
+
entity->inventory()->recalculate();
entity->inventory()->set_timestamp(server_timestamp);