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/netserver.cc | 61 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 16 deletions(-) (limited to 'src/core/netserver.cc') diff --git a/src/core/netserver.cc b/src/core/netserver.cc index 32b2d69..65388e8 100644 --- a/src/core/netserver.cc +++ b/src/core/netserver.cc @@ -562,10 +562,10 @@ void NetServer::send_player_disconnect_info(NetClient *client, Player *player) void NetServer::send_info_update(NetClient *client, Info *info) { if (!info || !info->type()) - return; + return; std::ostringstream msg; - msg << "inf " << info->type()->label() << ' ' << info->label() << ' '; + msg << "inf " << info->id() << " \"" << info->type()->label() << "\" \"" << info->label() << "\" "; info->serialize_server_update(msg); msg << '\n'; client->send_raw(msg.str()); @@ -675,24 +675,53 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me } if (command == "inf") { - std::string typelabelstr; - std::string infolabelstr; + unsigned int id; - if (!(msgstream >> typelabelstr)) { - con_warn << "^B" << client->player()->name() << "^W invalid info record request" << std::endl; - return; - } - - InfoType *infotype = InfoType::find(typelabelstr); - if (!infotype) - return; - - if (!(msgstream >> infolabelstr)) { - con_warn << "^B" << client->player()->name() << "^W invalid info record request" << std::endl; + if (!(msgstream >> id)) { + con_warn << "^B" << client->player()->name() << "^W invalid info request" << std::endl; return; } - Info *info = Info::find(infotype, infolabelstr); + Info *info = 0; + if (id == 0) { + // the client is requesting an information record by type and label + std::string typelabelstr; + std::string infolabelstr; + std::string n; + char c; + + // 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 << "^B" << client->player()->name() << "^W invalid info request" << std::endl; + return; + } + + InfoType *infotype = InfoType::find(typelabelstr); + if (!infotype) + return; + + // 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 << "^B" << client->player()->name() << "^W invalid info request" << std::endl; + return; + } + + info = Info::find(infotype, infolabelstr); + } else { + // the client is requesting an information record by id + info = Info::find(id); + } + if (info) { send_info_update(client, info); client->transmit(); -- cgit v1.2.3