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/entity.cc3
-rw-r--r--src/core/entity.h5
-rw-r--r--src/core/netserver.cc11
-rw-r--r--src/core/zone.cc11
-rw-r--r--src/core/zone.h3
5 files changed, 27 insertions, 6 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 0a6a201..bed17fb 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -110,11 +110,14 @@ Entity::Entity(unsigned int flags) :
entity_zone = 0;
entity_oldzone = 0;
+ entity_serverside = false;
+
add(this);
}
Entity::Entity(std::istream & is)
{
+ entity_serverside = false;
entity_id = 0;
entity_zone = 0;
entity_oldzone = 0;
diff --git a/src/core/entity.h b/src/core/entity.h
index 180d535..c988143 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -114,6 +114,9 @@ public:
/// base radius of the entity
inline float radius() const { return entity_radius; }
+ /// indicates a server-side entity
+ inline bool serverside() const { return entity_serverside; }
+
/*----- serializers ----------------------------------------------- */
/// serialize the entity to a stream
@@ -205,6 +208,8 @@ protected:
// the previous zone the entity belonged too
Zone *entity_oldzone;
+ bool entity_serverside;
+
private:
// add an entity to the registry
static void add(Entity *ent);
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index dcc152f..93d4682 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -468,7 +468,7 @@ void NetServer::send_frame_marker(NetClient *client, float timestamp, float prev
// send a "ent" create entity message to all clients
void NetServer::send_entity_create(NetClient *client, Entity *entity)
{
- if (client->state() == NetClient::Connected) {
+ if ((client->state() == NetClient::Connected) && !entity->serverside()) {
std::ostringstream msg;
msg << "ent " << entity->id() << " " << entity->type() << " ";
entity->serialize_server_create(msg);
@@ -480,10 +480,9 @@ void NetServer::send_entity_create(NetClient *client, Entity *entity)
// send a "die" delete entity message to a client
void NetServer::send_entity_delete(NetClient *client, Entity *entity)
{
- std::ostringstream msg("");
- msg << "die " << entity->id() << '\n';
-
- if (client->state() == NetClient::Connected) {
+ if ((client->state() == NetClient::Connected) && !entity->serverside()) {
+ std::ostringstream msg("");
+ msg << "die " << entity->id() << '\n';
client->send_raw(msg.str());
}
}
@@ -491,7 +490,7 @@ void NetServer::send_entity_delete(NetClient *client, Entity *entity)
// broadcast a "sup" server update entity message to all clients
void NetServer::send_entity_update(NetClient *client, Entity *entity)
{
- if (client->state() == NetClient::Connected) {
+ if ((client->state() == NetClient::Connected) && !entity->serverside()) {
std::ostringstream msg;
msg << "sup " << entity->id() << " ";
entity->serialize_server_update(msg);
diff --git a/src/core/zone.cc b/src/core/zone.cc
index 87ab9b4..2dfc5c2 100644
--- a/src/core/zone.cc
+++ b/src/core/zone.cc
@@ -181,6 +181,17 @@ Entity *Zone::find_entity(unsigned int id)
return 0;
}
+Entity *Zone::find_entity(const std::string & label)
+{
+ for (Content::iterator it = zone_content.begin(); it != zone_content.end(); it++) {
+ if ((*it)->label().compare(label) == 0) {
+ return (*it);
+ }
+ }
+
+ return 0;
+}
+
void Zone::serialize_server_update(std::ostream & os) const
{
os << zone_label << " ";
diff --git a/src/core/zone.h b/src/core/zone.h
index cd1fec2..bb2074e 100644
--- a/src/core/zone.h
+++ b/src/core/zone.h
@@ -98,6 +98,9 @@ public:
/// find an entity inside a zone
Entity *find_entity(unsigned int id);
+ /// find a labeled entity inside a zone
+ Entity *find_entity(const std::string & label);
+
/* ---- mutators ------------------------------------------- */
/// set the Zone label