Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
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
parent745b4e04e5f23a02e5d9b12ebabf38d6dd034136 (diff)
network info messages bugfixes
Diffstat (limited to 'src/core')
-rw-r--r--src/core/gameconnection.cc53
-rw-r--r--src/core/info.cc6
-rw-r--r--src/core/netconnection.cc8
-rw-r--r--src/core/netserver.cc10
4 files changed, 59 insertions, 18 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;
}
diff --git a/src/core/info.cc b/src/core/info.cc
index dc7a8b3..5615f8b 100644
--- a/src/core/info.cc
+++ b/src/core/info.cc
@@ -196,9 +196,11 @@ void Info::receive_server_update(std::istream &is)
set_modelname(n);
// read info text
- clear_text();
size_t s;
- is >> s;
+ if (!(is >> s))
+ s = 0;
+
+ clear_text();
for (size_t i = 0; (i < s) && is.good(); i++) {
n.clear();
while ((is.get(c)) && (c != '"'));
diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc
index 0a816b8..fa959be 100644
--- a/src/core/netconnection.cc
+++ b/src/core/netconnection.cc
@@ -426,7 +426,7 @@ void NetConnection::send_info_request(Info *info)
{
std::ostringstream msg;
if (info->id()) {
- msg << "inf " << info->id() << " \"\" \"\"\n";
+ msg << "inf " << info->id() << "\n";
} else {
if (!info->type())
return;
@@ -434,7 +434,7 @@ void NetConnection::send_info_request(Info *info)
}
this->send_raw(msg.str());
- info->set_timestamp(application()->timestamp());
+ info->set_timestamp(timestamp());
}
// parse incoming client messages
@@ -752,7 +752,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
}
} else if (command.compare("pid") == 0) {
- con_debug << "Received player disconnect info" << std::endl;
+ //con_debug << "Received player disconnect info" << std::endl;
int player_id;
if (!(msgstream >> player_id)) {
@@ -837,6 +837,8 @@ void NetConnection::parse_incoming_message(const std::string & message)
info->receive_server_update(msgstream);
info->clear_timestamp();
+
+ //con_debug << "Received info for " << info->id() << " " << info->type()->label() << ":" << info->label() << std::endl;
}
}
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index 6ba9dc7..0e44189 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -273,7 +273,7 @@ void NetServer::receive()
NetClient * NetServer::client_connect(std::string const host, int const port)
{
- con_debug << "client_connect " << host << ":" << port << "\n";
+ con_print << "Client " << host << ":" << port << " connected\n";
NetClient *client = new NetClient(host, port, fd());
if (client->error()) {
@@ -289,7 +289,6 @@ NetClient * NetServer::client_connect(std::string const host, int const port)
void NetServer::client_initialize(NetClient *client)
{
-
// send welcome message
std::string welcome("^B");
welcome.append(Cvar::sv_name->str());
@@ -764,16 +763,23 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
return;
}
+ //con_debug << "Received info request for " << infotype << ":" << infolabelstr << std::endl;
+
info = Info::find(infotype, infolabelstr);
} else {
+ //con_debug << "Received info request for id " << id << std::endl;
+
// the client is requesting an information record by id
info = Info::find(id);
}
if (info) {
+ //con_debug << "Sending info for " << info->id() << " " << info->type()->label() << ":" << info->label() << std::endl;
+
send_info_update(client, info);
client->transmit();
}
+ return;
} else if (command.compare("rcon") == 0) {
if ((message.size() > command.size() + 1) && Cvar::sv_password->str().size()) {