diff options
Diffstat (limited to 'src/core/gameconnection.cc')
-rw-r--r-- | src/core/gameconnection.cc | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/src/core/gameconnection.cc b/src/core/gameconnection.cc index 0da1803..46b50f5 100644 --- a/src/core/gameconnection.cc +++ b/src/core/gameconnection.cc @@ -14,6 +14,7 @@ namespace core { +const unsigned long INFOTIMEOUT = 2500; // 2500ms info request timeout GameConnection* GameConnection::connection_instance = 0; @@ -92,20 +93,33 @@ bool GameConnection::interactive() const Info *GameConnection::info(unsigned int id) { + if (!id) { + con_warn << "Information requested for illegal id 0!" << std::endl; + return 0; + } + // find the info record Info *info = Info::find(id); if (info) { - return info; - } - - info = new Info(id); - info->text().push_back("Requesting information..."); + if (!info->timestamp() || (connection_timestamp - info->timestamp()) < INFOTIMEOUT) + return info; + } else { + info = new Info(id); + info->text().push_back("Requesting information..."); + } + // send an information request to the server if (connection_network) { + //con_debug << "Requesting info for " << info->id() << std::endl; + info->set_timestamp(connection_timestamp); + info->set_id(0); + connection_network->send_info_request(info); + connection_network->transmit(); } else { info->text().push_back("^RNot connected."); + info->set_timestamp(0); } return info; @@ -113,6 +127,16 @@ Info *GameConnection::info(unsigned int id) Info *GameConnection::info(const std::string &type, const std::string &label) { + if (!type.size()) { + con_warn << "Information requested with empty type label!" << std::endl; + return 0; + } + + if (!label.size()) { + con_warn << "Information requested with empty label!" << std::endl; + return 0; + } + // find the info record type InfoType *infotype = InfoType::find(type); if (!infotype) { @@ -123,19 +147,26 @@ Info *GameConnection::info(const std::string &type, const std::string &label) // find the info record Info *info = Info::find(infotype, label); if (info) { - return info; + if (!info->timestamp() || (connection_timestamp - info->timestamp()) < INFOTIMEOUT) + return info; + } else { + // create a new info record and set the label + info = new Info(infotype); + info->set_label(label); + info->text().push_back("Requesting information..."); } - - // create a new info record and set the label - info = new Info(infotype); - info->set_label(label); - info->text().push_back("Requesting information..."); // send an information request to the server if (connection_network) { + //con_debug << "Requesting info for " << info->type()->label() << ":" << info->label() << std::endl; + info->set_timestamp(connection_timestamp); + info->set_id(0); + connection_network->send_info_request(info); + connection_network->transmit(); } else { info->text().push_back("^RNot connected."); + info->set_timestamp(0); } return info; } |