Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/descriptions.cc36
-rw-r--r--src/core/descriptions.h26
-rw-r--r--src/core/entity.cc12
-rw-r--r--src/core/gameconnection.cc15
-rw-r--r--src/core/gameconnection.h4
-rw-r--r--src/core/gameinterface.h4
-rw-r--r--src/core/info.cc34
-rw-r--r--src/core/info.h15
-rw-r--r--src/core/inventory.h4
-rw-r--r--src/core/label.cc11
-rw-r--r--src/core/label.h3
-rw-r--r--src/core/net.h2
-rw-r--r--src/core/netconnection.cc12
-rw-r--r--src/core/netconnection.h6
-rw-r--r--src/core/netserver.cc53
15 files changed, 101 insertions, 136 deletions
diff --git a/src/core/descriptions.cc b/src/core/descriptions.cc
index 307cc87..26a5858 100644
--- a/src/core/descriptions.cc
+++ b/src/core/descriptions.cc
@@ -15,7 +15,7 @@ namespace core
ButtonDescription::ButtonDescription()
{
- button_model = 0;
+ button_info = 0;
button_align = Center;
button_commandtype = CommandNone;
}
@@ -35,16 +35,14 @@ void ButtonDescription::set_command(const std::string &command, const CommandTyp
button_command.assign(command);
}
-void ButtonDescription::set_modelname(const std::string &modelname)
+void ButtonDescription::set_alignment(Align align)
{
- button_modelname.assign(modelname);
-
- button_model = model::Model::load(modelname);
+ button_align = align;
}
-void ButtonDescription::set_alignment(Align align)
+void ButtonDescription::set_info(Info *info)
{
- button_align = align;
+ button_info = info;
}
/* ---- class MenuDescription -------------------------------------- */
@@ -92,7 +90,7 @@ void Descriptions::serialize(MenuDescription *menu, std::ostream & os)
<< button->alignment() << " "
<< button->command_type() << " "
<< "\"" << button->command() << "\" "
- << "\"" << button->modelname() << "\" ";
+ << (button->info() ? button->info()->id() : 0) << " ";
}
}
@@ -105,6 +103,7 @@ MenuDescription * Descriptions::receive(std::istream &is)
std::string n;
size_t nb;
char c;
+ long id;
// menu label
is >> n;
@@ -157,12 +156,17 @@ MenuDescription * Descriptions::receive(std::istream &is)
}
}
- // button modelname
- n.clear();
- while ((is.get(c)) && (c != '"'));
- while ((is.get(c)) && (c != '"'))
- n += c;
- if (n.size()) button->set_modelname(n);
+ // button info record id
+ Info *info = 0;
+ if (is >> id) {
+ info = Info::find(id);
+ if (id && !info) {
+ info = new Info(id);
+ }
+ } else {
+ id = 0;
+ }
+ button->set_info(info);
menu->add_button(button);
}
@@ -231,9 +235,7 @@ bool Descriptions::load_entity_menus(core::Entity *entity, const std::string &me
// default command is a game command
button->set_command(strval, ButtonDescription::CommandGame);
-
- } else if (inifile.got_key_string("model", strval)) {
- button->set_modelname(strval);
+
} else if (inifile.got_key_string("align", strval)) {
aux::to_label(strval);
if (strval.compare("left") == 0) {
diff --git a/src/core/descriptions.h b/src/core/descriptions.h
index 2b4b1e0..05e92af 100644
--- a/src/core/descriptions.h
+++ b/src/core/descriptions.h
@@ -17,8 +17,8 @@ class ButtonDescription;
class MenuDescription;
}
+#include "core/info.h"
#include "core/entity.h"
-#include "model/model.h"
#include "filesystem/inifile.h"
namespace core
@@ -52,21 +52,16 @@ public:
return button_command;
}
- /// button info view model name
- inline const std::string & modelname() const {
- return button_modelname;
- }
-
- /// button info view model
- inline const model::Model *model() {
- return button_model;
- }
-
/// button text alignment
inline Align alignment() const {
return button_align;
}
+ /// button info record
+ inline Info *info() {
+ return button_info;
+ }
+
/* -- mutators -------------------------------------------- */
/// set button text
@@ -75,19 +70,18 @@ public:
/// set button command
void set_command(const std::string &command, const CommandType command_type);
- /// set button name
- void set_modelname(const std::string &modelname);
-
/// set text alignment
void set_alignment(Align align);
+
+ /// set info record
+ void set_info(Info *info);
private:
std::string button_text;
CommandType button_commandtype;
std::string button_command;
- std::string button_modelname;
Align button_align;
- model::Model *button_model;
+ Info *button_info;
};
/// description of an entity menu
diff --git a/src/core/entity.cc b/src/core/entity.cc
index baefcea..fdcce59 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -343,11 +343,13 @@ void Entity::receive_server_create(std::istream &is)
set_modelname(n);
// read info id
- is >> o;
- if (o)
- set_info(game()->info(o));
- else
- set_info(0);
+ if(is >> o) {
+ entity_info = Info::find(o);
+ if (o && !entity_info)
+ entity_info = new Info(o);
+ } else {
+ entity_info = 0;
+ }
entity_dirty = false;
}
diff --git a/src/core/gameconnection.cc b/src/core/gameconnection.cc
index ce33dc6..3167790 100644
--- a/src/core/gameconnection.cc
+++ b/src/core/gameconnection.cc
@@ -100,20 +100,16 @@ Info *GameConnection::info(unsigned int id)
// find the info record
Info *info = Info::find(id);
- if (info) {
- if (!info->timestamp() || (connection_timestamp - info->timestamp()) < INFOTIMEOUT)
- return info;
- } else {
+ if (!info) {
info = new Info(id);
- info->add_text("Requesting information...");
}
-
+ if ( !info->timestamp() || (connection_timestamp < info->timestamp() + INFOTIMEOUT) )
+ return info;
+
// send an information request to the server
if (connection_network) {
- //con_debug << "Requesting info for " << info->id() << std::endl;
info->set_timestamp(connection_timestamp);
-
connection_network->send_info_request(info);
connection_network->transmit();
} else {
@@ -121,9 +117,9 @@ Info *GameConnection::info(unsigned int id)
info->set_timestamp(0);
}
return info;
-
}
+/*
Info *GameConnection::info(const std::string &type, const std::string &label)
{
if (!type.size()) {
@@ -166,6 +162,7 @@ Info *GameConnection::info(const std::string &type, const std::string &label)
}
return info;
}
+*/
void GameConnection::abort()
{
diff --git a/src/core/gameconnection.h b/src/core/gameconnection.h
index 90b45a0..bb615c1 100644
--- a/src/core/gameconnection.h
+++ b/src/core/gameconnection.h
@@ -57,10 +57,10 @@ public:
/// localplayer sends a private message to another player
void private_message(std::string const &args);
-
+/*
/// returns an info record
virtual Info *info(const std::string &type, const std::string &label);
-
+*/
/// returns an info record
virtual Info *info(unsigned int id);
diff --git a/src/core/gameinterface.h b/src/core/gameinterface.h
index 1460c45..11cc0de 100644
--- a/src/core/gameinterface.h
+++ b/src/core/gameinterface.h
@@ -61,10 +61,10 @@ public:
/// return the current game time
virtual unsigned long timestamp() const = 0;
-
+/*
/// returns an info record
virtual Info *info(const std::string &type, const std::string &label) = 0;
-
+*/
/// returns an info record
virtual Info *info(unsigned int id) = 0;
diff --git a/src/core/info.cc b/src/core/info.cc
index 5615f8b..1a4f68f 100644
--- a/src/core/info.cc
+++ b/src/core/info.cc
@@ -8,6 +8,7 @@
#include "core/info.h"
#include "sys/sys.h"
#include "core/info.h"
+#include "core/gameinterface.h"
#include <iomanip>
@@ -16,11 +17,8 @@ namespace core
/* ---- class InfoType --------------------------------------------- */
-InfoType::InfoType(const char *label)
+InfoType::InfoType(const char *label) : Label(label)
{
- if (label)
- set_label(label);
-
infotype_registry.push_back(this);
}
@@ -59,7 +57,7 @@ InfoType *InfoType::find(const std::string & label)
unsigned int info_id_counter = 0;
// server-side constructor, assigns an id
-Info::Info(const InfoType *type)
+Info::Info(const InfoType *type, const char *label) : Label(label)
{
info_id_counter++;
info_id = info_id_counter;
@@ -71,30 +69,19 @@ Info::Info(const InfoType *type)
info_price = 0;
}
-// client-side constructor, does not assign an id
-Info::Info(const InfoType *type, const std::string & label)
-{
- info_id = 0;
- info_type = type;
- info_registry.push_back(this);
-
- info_model = 0;
- info_timestamp = 0;
- info_price = 0;
-
- set_label(label);
-}
-
-// client-side constructor, does not assign an id
+// client-side constructor, id is passed as param
Info::Info(const unsigned int id)
{
info_id = id;
info_type = 0;
info_registry.push_back(this);
- info_model = 0;
- info_timestamp = 0;
+ info_model = 0;
info_price = 0;
+
+ info_timestamp = 1;
+
+ add_text("Requesting server information...");
}
Info::~Info()
@@ -209,6 +196,9 @@ void Info::receive_server_update(std::istream &is)
add_text(n);
}
+
+ // set timestamp to 0
+ info_timestamp = 0;
}
void Info::print() const
diff --git a/src/core/info.h b/src/core/info.h
index 8822f2f..4b9c445 100644
--- a/src/core/info.h
+++ b/src/core/info.h
@@ -64,13 +64,7 @@ public:
* @brief create a new server-side information card
* This constructor assigns an id
*/
- Info(const InfoType *type);
-
- /**
- * @brief create a new client-side information card
- * This constructor doesn not assign an id
- */
- Info(const InfoType *type, const std::string & label);
+ Info(const InfoType *type, const char *label = 0);
/**
* @brief create a new client-side information card
@@ -102,6 +96,13 @@ public:
return info_price;
}
+ /**
+ * @brief timestamp
+ * The timestamp is used client-side, a non-zero value
+ * indicates the time when the info was last requested.
+ * If the info has been received from the server, the timestamp
+ * is set to 0
+ */
inline const unsigned long &timestamp() const {
return info_timestamp;
}
diff --git a/src/core/inventory.h b/src/core/inventory.h
index da30715..c924683 100644
--- a/src/core/inventory.h
+++ b/src/core/inventory.h
@@ -55,6 +55,10 @@ public:
*/
Item *find(const Info *info);
+ inline Items &items() {
+ return inventory_items;
+ };
+
private:
Items inventory_items;
};
diff --git a/src/core/label.cc b/src/core/label.cc
index d3a7b99..d7dabc2 100644
--- a/src/core/label.cc
+++ b/src/core/label.cc
@@ -12,6 +12,17 @@ Label::Label()
{
}
+Label::Label(const char *label)
+{
+ if (label)
+ labelstr.assign(label);
+}
+
+Label::Label(const std::string & label)
+{
+ labelstr.assign(label);
+}
+
Label::~Label()
{
labelstr.clear();
diff --git a/src/core/label.h b/src/core/label.h
index 12a417c..2ca40f7 100644
--- a/src/core/label.h
+++ b/src/core/label.h
@@ -19,6 +19,9 @@ namespace core {
class Label {
public:
Label();
+ Label(const char *label);
+ Label(const std::string & label);
+
~Label();
/* --- inspectors ------------------------------------------------- */
diff --git a/src/core/net.h b/src/core/net.h
index a217d94..f6904b2 100644
--- a/src/core/net.h
+++ b/src/core/net.h
@@ -11,7 +11,7 @@ namespace core
{
/// network protocol version
-const unsigned int PROTOCOLVERSION = 18;
+const unsigned int PROTOCOLVERSION = 19;
/// maximum lenght of a (compressed) network message block
const unsigned int FRAMESIZE = 1152;
diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc
index fa959be..684e6b3 100644
--- a/src/core/netconnection.cc
+++ b/src/core/netconnection.cc
@@ -425,13 +425,11 @@ void NetConnection::send_ping_reply(unsigned long timestamp)
void NetConnection::send_info_request(Info *info)
{
std::ostringstream msg;
- if (info->id()) {
- msg << "inf " << info->id() << "\n";
- } else {
- if (!info->type())
- return;
- msg << "inf " << info->id() << " \"" << info->type()->label() << "\" \"" << info->label() << "\"\n";
+ if (!info->id()) {
+ return;
}
+
+ msg << "inf " << info->id() << "\n";
this->send_raw(msg.str());
info->set_timestamp(timestamp());
@@ -838,7 +836,7 @@ 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;
+ con_debug << "Received info for " << info->id() << " " << info->type()->label() << ":" << info->label() << std::endl;
}
}
diff --git a/src/core/netconnection.h b/src/core/netconnection.h
index 99b8794..8aa0727 100644
--- a/src/core/netconnection.h
+++ b/src/core/netconnection.h
@@ -35,7 +35,11 @@
namespace core
{
-/// a client to server connection
+/**
+ * @brief client-side network methods
+ * This class contains the necessary methods for the client-side
+ * of network communication. It handles both sending and receiving.
+ **/
class NetConnection
{
public:
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index 0e44189..c632284 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -730,54 +730,13 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
}
Info *info = 0;
- if (id == 0) {
- // the client is requesting an information record by type and label
- std::string typelabelstr;
- std::string infolabelstr;
- std::string n;
- char c;
-
- // 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 << "^B" << client->player()->name() << "^W invalid info request" << std::endl;
- return;
- }
-
- InfoType *infotype = InfoType::find(typelabelstr);
- if (!infotype)
- return;
-
- // 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 << "^B" << client->player()->name() << "^W invalid info request" << std::endl;
- return;
+ if (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();
}
-
- //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;