Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2010-02-21 12:36:17 +0000
committerStijn Buys <ingar@osirion.org>2010-02-21 12:36:17 +0000
commit730c452ff5896ed66114e6b2153add9379edef5c (patch)
tree353c7c0449deb41f3396d776c0437a4141383d01 /src/core/gameconnection.cc
parent745b4e04e5f23a02e5d9b12ebabf38d6dd034136 (diff)
network info messages bugfixes
Diffstat (limited to 'src/core/gameconnection.cc')
-rw-r--r--src/core/gameconnection.cc53
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;
}