Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/netconnection.cc')
-rw-r--r--src/core/netconnection.cc62
1 files changed, 51 insertions, 11 deletions
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();