From 730c452ff5896ed66114e6b2153add9379edef5c Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 21 Feb 2010 12:36:17 +0000 Subject: network info messages bugfixes --- src/client/buymenu.cc | 18 +++++++-------- src/core/gameconnection.cc | 53 +++++++++++++++++++++++++++++++++++---------- src/core/info.cc | 6 +++-- src/core/netconnection.cc | 8 ++++--- src/core/netserver.cc | 10 +++++++-- src/game/base/shipdealer.cc | 11 ++++++++++ src/game/base/shipmodel.cc | 6 +++++ src/game/base/shipmodel.h | 2 ++ src/render/screenshot.cc | 2 +- 9 files changed, 88 insertions(+), 28 deletions(-) diff --git a/src/client/buymenu.cc b/src/client/buymenu.cc index 7fad916..d708511 100644 --- a/src/client/buymenu.cc +++ b/src/client/buymenu.cc @@ -83,21 +83,21 @@ void BuyMenu::set_item(std::string const & itemtype, std::string const & itemnam menu_namelabel->set_text(0); menu_modelview->set_modelname(0); - core::Info *info = core::game()->info(menu_itemtype, menu_itemname); - if (info) { - menu_namelabel->set_text(info->name()); - menu_modelview->set_modelname(info->modelname()); + menu_inforecord = core::game()->info(menu_itemtype, menu_itemname); + + if (menu_inforecord) { + menu_namelabel->set_text(menu_inforecord->name()); + menu_modelview->set_modelname(menu_inforecord->modelname()); - for (core::Info::Text::iterator it = info->text().begin(); it != info->text().end(); it++) { + for (core::Info::Text::iterator it = menu_inforecord->text().begin(); it != menu_inforecord->text().end(); it++) { menu_infotext.push_back((*it)); } - menu_infotimestamp = info->timestamp(); + menu_infotimestamp = menu_inforecord->timestamp(); } else { menu_infotext.push_back("Information is not available"); menu_infotimestamp = 0; + menu_inforecord = 0; } - - menu_inforecord = info; } void BuyMenu::resize() @@ -136,7 +136,7 @@ void BuyMenu::resize() void BuyMenu::draw() { // update content if necessary - if (menu_infotimestamp && (menu_infotimestamp != menu_inforecord->timestamp())) + if (menu_infotimestamp && menu_inforecord && (menu_infotimestamp != menu_inforecord->timestamp())) set_item(menu_itemtype, menu_itemname); } 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()) { diff --git a/src/game/base/shipdealer.cc b/src/game/base/shipdealer.cc index b38855b..d825e2c 100644 --- a/src/game/base/shipdealer.cc +++ b/src/game/base/shipdealer.cc @@ -83,7 +83,18 @@ void ShipDealer::func_buy(core::Player *player, const std::string &args) } if (!shipmodel) { + // enable rcon buffering + sys::ConsoleInterface::instance()->set_rcon(true); ShipModel::list(); + + while (sys::ConsoleInterface::instance()->rconbuf().size()) { + player->send((*sys::ConsoleInterface::instance()->rconbuf().begin())); + sys::ConsoleInterface::instance()->rconbuf().pop_front(); + } + + // disable rcon buffering + sys::ConsoleInterface::instance()->set_rcon(false); + player->send("Usage: buy ship label"); return; } diff --git a/src/game/base/shipmodel.cc b/src/game/base/shipmodel.cc index dacc5a6..a6a2bf9 100644 --- a/src/game/base/shipmodel.cc +++ b/src/game/base/shipmodel.cc @@ -75,4 +75,10 @@ ShipModel *ShipModel::search(const std::string searchstr) return (ShipModel *) core::Info::search(shipmodel_infotype, searchstr); } + +void ShipModel::list() +{ + core::Info::list(shipmodel_infotype); +} + } diff --git a/src/game/base/shipmodel.h b/src/game/base/shipmodel.h index dc56033..3c7f6df 100644 --- a/src/game/base/shipmodel.h +++ b/src/game/base/shipmodel.h @@ -85,6 +85,8 @@ public: static ShipModel *find(const std::string & label); static ShipModel *search(const std::string searchstr); + + static void list(); static core::InfoType *shipmodel_infotype; diff --git a/src/render/screenshot.cc b/src/render/screenshot.cc index 45e2299..ea2659b 100644 --- a/src/render/screenshot.cc +++ b/src/render/screenshot.cc @@ -111,7 +111,7 @@ void Screenshot::save() image.flip(); if (filetype == TYPEPNG) { - render::PNG::save(filenamestr.str().c_str(), image); + render::PNG::save(filename.c_str(), image); } else if (filetype == TYPEJPG) { render::JPG::save(filename.c_str(), image, (int) screenshotquality->value()); } else if (filetype == TYPETGA) { -- cgit v1.2.3