From 89c0bc88bd4ebdc44dfb99235609c90e968af533 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 15 Nov 2009 14:20:13 +0000 Subject: added core::Info id, changed network info message, updated entity network message to include the info id --- src/core/netconnection.cc | 62 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 11 deletions(-) (limited to 'src/core/netconnection.cc') diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc index 2975bc5..1318467 100644 --- a/src/core/netconnection.cc +++ b/src/core/netconnection.cc @@ -416,7 +416,13 @@ void NetConnection::send_ping_reply(unsigned long timestamp) void NetConnection::send_info_request(Info *info) { std::ostringstream msg; - msg << "inf " << ' ' << info->type()->label() << ' ' << info->label() << '\n'; + if (info->id()) { + msg << "inf " << info->id() << " \"\" \"\"\n"; + } else { + if (!info->type()) + return; + msg << "inf " << info->id() << " \"" << info->type()->label() << "\" \"" << info->label() << "\"\n"; + } this->send_raw(msg.str()); info->set_timestamp(application()->timestamp()); @@ -690,30 +696,64 @@ void NetConnection::parse_incoming_message(const std::string & message) } } else if (command == "inf") { - // incoming info record + unsigned int id = 0; std::string typelabelstr; std::string infolabelstr; + std::string n; + char c; - if (!(msgstream >> typelabelstr)) { + // read id + if (!(msgstream >> id)) { con_warn << "Received invalid info record message!" << std::endl; return; } - InfoType *infotype = InfoType::find(typelabelstr); - if (!infotype) { - infotype = new InfoType(typelabelstr.c_str()); + + // read type label + n.clear(); + while ((msgstream.get(c)) && (c != '"')); + while ((msgstream.get(c)) && (c != '"')) + n +=c; + + typelabelstr.assign(n); + if (!typelabelstr.size()) { + con_warn << "Received invalid info record message!" << std::endl; + return; } - if (!(msgstream >> infolabelstr)) { + // read info label + n.clear(); + while ((msgstream.get(c)) && (c != '"')); + while ((msgstream.get(c)) && (c != '"')) + n +=c; + + infolabelstr.assign(n); + if (!infolabelstr.size()) { con_warn << "Received invalid info record message for type '" << typelabelstr << "'!" << std::endl; return; } - Info *info = Info::find(infotype, infolabelstr); + + // find the InfoType instance + InfoType *infotype = InfoType::find(typelabelstr); + if (!infotype) { + infotype = new InfoType(typelabelstr.c_str()); + } + + // find the Info instance + Info *info = Info::find(id); if (!info) { - info = new Info(infotype); - info->set_label(infolabelstr); + info = Info::find(infotype, infolabelstr); } - + + // create one if necessary + if (!info) { + info = new Info(id); + } + + info->set_type(infotype); + info->set_label(infolabelstr); + info->set_id(id); + info->receive_server_update(msgstream); info->clear_timestamp(); -- cgit v1.2.3