diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/inventory.cc | 1 | ||||
-rw-r--r-- | src/core/item.cc | 15 | ||||
-rw-r--r-- | src/core/netconnection.cc | 19 |
3 files changed, 20 insertions, 15 deletions
diff --git a/src/core/inventory.cc b/src/core/inventory.cc index 7957294..28327a3 100644 --- a/src/core/inventory.cc +++ b/src/core/inventory.cc @@ -54,7 +54,6 @@ void Inventory::add(Item *item) return; } inventory_items.push_back(item); - inventory_dirty = true; } void Inventory::remove(Item *item) diff --git a/src/core/item.cc b/src/core/item.cc index e9d9f65..8ab4784 100644 --- a/src/core/item.cc +++ b/src/core/item.cc @@ -14,12 +14,17 @@ namespace core /* ---- class Item ------------------------------------------------- */ +// Note: initializing the timestamp with 1 instead of 0 is a small hack +// since cient-side inventory timestamps are initialized at 0, setting +// the item timestamp to 0 would prevent the client from updating +// the trade window the first time it is opened on a base + Item::Item(const Info *info) { item_info = info; item_amount = 0; item_price = info->price(); - set_timestamp(game() ? game()->timestamp() : 0); + set_timestamp(game() ? game()->timestamp() : 1); } Item::~Item() @@ -31,25 +36,25 @@ Item::~Item() void Item::set_amount(const long amount) { item_amount = amount; - set_timestamp(game() ? game()->timestamp() : 0); + set_timestamp(game() ? game()->timestamp() : 1); } void Item::inc_amount(const long amount) { item_amount += amount; - set_timestamp(game() ? game()->timestamp() : 0); + set_timestamp(game() ? game()->timestamp() : 1); } void Item::dec_amount(const long amount) { item_amount -= amount; - set_timestamp(game() ? game()->timestamp() : 0); + set_timestamp(game() ? game()->timestamp() : 1); } void Item::set_price(const long price) { item_price = price; - set_timestamp(game() ? game()->timestamp() : 0); + set_timestamp(game() ? game()->timestamp() : 1); } void Item::set_timestamp(const unsigned long timestamp) diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc index 11e23c9..3318c1e 100644 --- a/src/core/netconnection.cc +++ b/src/core/netconnection.cc @@ -432,7 +432,7 @@ void NetConnection::send_info_request(Info *info) msg << "inf " << info->id() << "\n"; this->send_raw(msg.str()); - info->set_timestamp(timestamp()); + info->set_timestamp(application()->timestamp()); } // send an inventory update request @@ -871,9 +871,9 @@ void NetConnection::parse_incoming_message(const std::string & message) info->receive_server_update(msgstream); //info->clear_timestamp(); - info->set_timestamp(timestamp()); + info->set_timestamp(application()->timestamp()); - //con_debug << "Received info for " << info->id() << " " << info->type()->label() << ":" << info->label() << std::endl; + //con_debug << "CLIENT info for " << info->id() << " " << info->type()->label() << ":" << info->label() << " timestamp " << info->timestamp() << std::endl; } else if (command.compare("inv") == 0) { @@ -897,9 +897,8 @@ void NetConnection::parse_incoming_message(const std::string & message) return; } - //con_debug << "CLIENT received inv message for entity " << id << " server timestamp " << server_timestamp << " client timestamp " << entity->inventory()->timestamp() << std::endl; - - + //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; @@ -907,7 +906,7 @@ void NetConnection::parse_incoming_message(const std::string & message) if (!(msgstream >> nbitems)) nbitems = 0; - //con_debug << "CLIENT number of items: " << nbitems << std::endl; + //con_debug << "CLIENT number of items: " << nbitems << std::endl; 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; @@ -922,9 +921,11 @@ void NetConnection::parse_incoming_message(const std::string & message) } item->receive_server_update(msgstream); } - - entity->inventory()->set_timestamp(server_timestamp); + entity->inventory()->recalculate(); + entity->inventory()->set_timestamp(server_timestamp); + + //con_debug << "CLIENT inventory updated timestamp " << entity->inventory()->timestamp() << " for " << nbitems << " items" << std::endl; } } |