Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2013-11-09 15:22:44 +0000
committerStijn Buys <ingar@osirion.org>2013-11-09 15:22:44 +0000
commit977a9a68d2465818a331643399a9ecc998d0cbb3 (patch)
tree5e19904a95119ebc22cfffedcf4bd7b2094e4e31 /src
parentd0b6e591fbaf3db5fc9898e75913e57a3c32169a (diff)
Bumped network protocol to version 27,
send player reputation and stats from server to client, send entity faction to clients, improved list_entity.
Diffstat (limited to 'src')
-rw-r--r--src/core/entity.cc90
-rw-r--r--src/core/entity.h6
-rw-r--r--src/core/net.h2
-rw-r--r--src/core/netconnection.cc3
-rw-r--r--src/core/netserver.cc16
-rw-r--r--src/core/netserver.h7
-rw-r--r--src/core/player.cc22
-rw-r--r--src/core/reputation.cc34
-rw-r--r--src/core/reputation.h22
-rw-r--r--src/game/base/faction.cc1
-rw-r--r--src/game/base/ship.cc5
11 files changed, 191 insertions, 17 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 4c4c35b..ff780a5 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -265,8 +265,33 @@ void Entity::print() const
// print header
print_header();
+ // type
+ con_print << " ^Ntype ^B";
+ switch (type()) {
+ case Default:
+ con_print << "entity";
+ break;
+
+ case Dynamic:
+ con_print << "dynamic";
+ break;
+
+ case Controlable:
+ con_print << "controlable";
+ break;
+
+ case Globe:
+ con_print << "globe";
+ break;
+
+ case Projectile:
+ con_print << "projectile";
+ }
+ con_print << std::endl;
+ con_print << " ^Nmodule type ^B" << moduletype() << std::endl;
+
// print entity flags
- con_print << " flags ^B";
+ con_print << " ^Nflags ^B";
if (has_flag(NonSolid)) {
con_print << " nonsolid";
}
@@ -277,17 +302,27 @@ void Entity::print() const
con_print << " dockable";
}
if (has_flag(ShowOnMap)) {
- con_print << " shwonmap";
+ con_print << " shownmap";
}
if (has_flag(KeepAlive)) {
con_print << " keepalive";
}
- con_print << std::endl;
+ con_print << std::endl;
+ if (inventory()) {
+ con_print << " ^Ninventory ^Byes" << std::endl;
+ }
+ if (faction()) {
+ con_print << " ^Nfaction ^B" << faction()->label();
+ }
}
void Entity::print_header() const
{
- con_print << " entity id ^B" << id() << " ^Nlabel ^B" << label() << " ^Nname ^B" << name() << std::endl;
+ con_print << " entity id ^B" << id() << " ^Nlabel ^B" << label() << " ^Nname ^B" << name();
+ if (!zone()) {
+ con_print << " ^Nzone ^B" << zone()->label();
+ }
+ con_print << std::endl;
}
void Entity::print_inventory() const
@@ -427,6 +462,7 @@ void Entity::serialize_server_create(std::ostream & os) const
<< "\"" <<label() << "\" "
<< "\"" << name() << "\" "
<< "\"" << (entity_model ? entity_model->name() : "") << "\" "
+ << (faction() ? faction()->id() : 0) << " "
<< (info() ? info()->id() : 0) << " "
<< (inventory() ? 1 : 0) << " ";
@@ -492,6 +528,15 @@ void Entity::receive_server_create(std::istream &is)
n += c;
set_modelname(n);
+ // read faction id
+ if(is >> o) {
+ entity_faction = Info::find(o);
+ if (o && !entity_faction)
+ entity_faction = new Info(o);
+ } else {
+ entity_faction = 0;
+ }
+
// read info id
if(is >> o) {
entity_info = Info::find(o);
@@ -749,6 +794,43 @@ EntityDynamic::~EntityDynamic()
delete entity_motionstate;
}
+void EntityDynamic::print() const
+{
+ Entity::print();
+
+ con_print << " ^Nstate ^B";
+ switch (state()) {
+ case Normal:
+ con_print << "normal";
+ break;
+
+ case ImpulseInitiate:
+ con_print << "impulseinitiate";
+ break;
+
+ case Impulse:
+ con_print << "impulse";
+ break;
+
+ case JumpInitiate:
+ con_print << "jumpinitiate";
+ break;
+
+ case Jump:
+ con_print << "jump";
+ break;
+
+ case Destroyed:
+ con_print << "destroyed";
+ break;
+
+ case NoPower:
+ con_print << "nopower";
+ break;
+ }
+ con_print << std::endl;
+
+}
void EntityDynamic::set_state(int state)
{
if (this->state() != state) {
diff --git a/src/core/entity.h b/src/core/entity.h
index a1de121..de4f210 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -598,6 +598,12 @@ public:
virtual ~EntityDynamic();
/*----- inspectors ------------------------------------------------ */
+
+ /**
+ * @brief print information about the entity
+ * */
+ virtual void print() const;
+
/// core type id
virtual inline const unsigned int type() const {
return Entity::Dynamic;
diff --git a/src/core/net.h b/src/core/net.h
index be364da..2102c7c 100644
--- a/src/core/net.h
+++ b/src/core/net.h
@@ -11,7 +11,7 @@ namespace core
{
/// network protocol version
-const unsigned int PROTOCOLVERSION = 26;
+const unsigned int PROTOCOLVERSION = 27;
/// 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 959f52e..b1a4e77 100644
--- a/src/core/netconnection.cc
+++ b/src/core/netconnection.cc
@@ -815,6 +815,9 @@ void NetConnection::parse_incoming_message(const std::string & message)
}
}
+ } else if (command.compare("rep") == 0) {
+ connection()->localplayer()->reputation().receive_server_update(msgstream);
+
} else if (command.compare("inf") == 0) {
// incoming info record
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index aae806e..84ed76c 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -407,6 +407,11 @@ void NetServer::client_frame(NetClient *client, unsigned long timestamp)
}
}
+ // send reputation updates
+ if (client->player()->reputation().dirty()) {
+ send_player_reputation(client);
+ }
+
// send inventory update for control
// FIXME this should be done for all player assets
if (client->player()->control() && client->player()->control()->inventory() && client->player()->control()->inventory()->dirty()) {
@@ -470,6 +475,7 @@ void NetServer::frame(unsigned long timestamp)
if (client->player()->dirty() || client->player()->zonechange()) {
client->player()->set_dirty(false);
client->player()->set_zonechange(false);
+ client->player()->reputation().set_dirty(false);
}
}
}
@@ -628,6 +634,16 @@ void NetServer::send_player_update(NetClient *client)
client->send_raw(msg.str());
}
+// send a "rep" update player reputation to a single player
+void NetServer::send_player_reputation(NetClient *client)
+{
+ std::ostringstream msg;
+ msg << "rep ";
+ client->player()->reputation().serialize_server_update(msg);
+ msg << '\n';
+ client->send_raw(msg.str());
+}
+
// send a short "pif" update player information to a single player
void NetServer::send_player_update(NetClient *client, Player *player)
{
diff --git a/src/core/netserver.h b/src/core/netserver.h
index a739e28..7277866 100644
--- a/src/core/netserver.h
+++ b/src/core/netserver.h
@@ -93,9 +93,12 @@ protected:
/// send an update player information message
void send_player_update(NetClient *client);
- /// send an general update player information message
- void send_player_update(NetClient *client, Player *player);
+ /// send an update player reputation message
+ void send_player_reputation(NetClient *client);
+ /// send a general update player information message
+ void send_player_update(NetClient *client, Player *player);
+
/// send player disconnect information message
void send_player_disconnect_info(NetClient *client, Player *player);
diff --git a/src/core/player.cc b/src/core/player.cc
index f744766..bf71b77 100644
--- a/src/core/player.cc
+++ b/src/core/player.cc
@@ -266,13 +266,17 @@ void Player::serialize_server_update(std::ostream & os) const
unsigned int mission_id = (player_mission_target ? player_mission_target->id() : 0);
os << player_id << " "
- << zone_id << " "
- << view_id << " "
- << control_id << " "
- << mission_id << " "
- << player_credits << " "
- << player_level << " "
- << player_ping;
+ << zone_id << " "
+ << view_id << " "
+ << control_id << " "
+ << mission_id << " "
+ << player_credits << " "
+ << player_level << " "
+ << player_npckills << " "
+ << player_pvpkills << " "
+ << player_time_wasted << " "
+ << player_time_joined << " "
+ << player_ping;
}
void Player::receive_server_update(std::istream &is)
@@ -321,6 +325,10 @@ void Player::receive_server_update(std::istream &is)
is >> player_credits;
is >> player_level;
+ is >> player_npckills;
+ is >> player_pvpkills;
+ is >> player_time_wasted;
+ is >> player_time_joined;
is >> player_ping;
/*
diff --git a/src/core/reputation.cc b/src/core/reputation.cc
index 013fd9e..b3eee43 100644
--- a/src/core/reputation.cc
+++ b/src/core/reputation.cc
@@ -5,11 +5,13 @@
*/
#include "core/reputation.h"
+#include "core/application.h"
namespace core {
Reputation::Reputation()
{
+ reputation_dirty = false;
}
Reputation::~Reputation()
@@ -24,6 +26,8 @@ void Reputation::clear()
(*it) = 0;
}
reputation_factionreps.clear();
+
+ reputation_dirty = false;
}
void Reputation::assign(const Reputation &other)
@@ -78,26 +82,52 @@ void Reputation::set_reputation(const std::string &label, const float reputation
{
for (FactionReps::const_iterator it = reputation_factionreps.begin(); it != reputation_factionreps.end(); ++it) {
if (((*it)->faction() && (label.compare((*it)->faction()->label()) == 0)) || ((*it)->label().compare(label) == 0)) {
- (*it)->set_reputation(reputation);
+ if ((*it)->reputation() != reputation) {
+ (*it)->set_reputation(reputation);
+ reputation_dirty = true;
+ }
return;
}
}
FactionRep *factionrep = new FactionRep(label, reputation);
reputation_factionreps.push_back(factionrep);
+ reputation_dirty = true;
}
void Reputation::set_reputation(const Info *faction, const float reputation)
{
for (FactionReps::const_iterator it = reputation_factionreps.begin(); it != reputation_factionreps.end(); ++it) {
if ((!(*it)->faction() && ((*it)->label().compare(faction->label()) == 0)) || ((*it)->faction() == faction)) {
- (*it)->set_reputation(reputation);
+ if ((*it)->reputation() != reputation) {
+ (*it)->set_reputation(reputation);
+ reputation_dirty = true;
+ }
return;
}
}
FactionRep *factionrep = new FactionRep(faction, reputation);
reputation_factionreps.push_back(factionrep);
+ reputation_dirty = true;
+}
+
+void Reputation::receive_server_update(std::istream &is)
+{
+ unsigned long id;
+ float reputation;
+
+ while ((is >> id) && ( is >> reputation)) {
+ // this is client side and has to create info records as required
+ set_reputation(game()->request_info(id), reputation);
+ }
+}
+
+void Reputation::serialize_server_update(std::ostream & os) const
+{
+ for (FactionReps::const_iterator it = reputation_factionreps.begin(); it != reputation_factionreps.end(); ++it) {
+ os << (*it)->faction()->id() << " " << roundf((*it)->reputation()) << " ";
+ }
}
} // namespace core \ No newline at end of file
diff --git a/src/core/reputation.h b/src/core/reputation.h
index 87d3ea9..d20a210 100644
--- a/src/core/reputation.h
+++ b/src/core/reputation.h
@@ -87,6 +87,11 @@ public:
void set_reputation(const Info *faction, const float reputation);
+ inline void set_dirty(const bool dirty = true)
+ {
+ reputation_dirty = dirty;
+ }
+
void clear();
void assign(const Reputation &other);
@@ -96,8 +101,25 @@ public:
return reputation_factionreps;
}
+ inline const bool dirty() const
+ {
+ return reputation_dirty;
+ }
+
+ /* ---- deserializers -------------------------------------- */
+
+ /// receive a server-to-client update from a stream
+ void receive_server_update(std::istream &is);
+
+ /* ---- serializers ---------------------------------------- */
+
+ /// serialize a server-to-client update on a stream
+ void serialize_server_update(std::ostream & os) const;
+
private:
FactionReps reputation_factionreps;
+
+ bool reputation_dirty;
};
} // namespace core
diff --git a/src/game/base/faction.cc b/src/game/base/faction.cc
index 8171a2d..512a8c6 100644
--- a/src/game/base/faction.cc
+++ b/src/game/base/faction.cc
@@ -220,6 +220,7 @@ void Faction::apply_default(core::Reputation & reputation)
}
}
}
+ reputation.set_dirty();
}
} // namespace game
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index 08838ad..b046d9d 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -657,7 +657,7 @@ void Ship::hit(core::Entity *other)
std::string message("^B");
message.append(owner()->name());
- if (assassin) {
+ if (assassin) {
if (assassin == owner()) {
message.append(" ^Bran into his own mine.");
} else {
@@ -667,6 +667,7 @@ void Ship::hit(core::Entity *other)
// asssissin killed a player
assassin->set_pvpkills(assassin->pvpkills() + 1);
+ assassin->set_dirty();
}
} else {
message.append(" ^Bwent boom.");
@@ -678,6 +679,7 @@ void Ship::hit(core::Entity *other)
if (assassin) {
// assissin killed an NPC
assassin->set_npckills(assassin->npckills() + 1);
+ assassin->set_dirty();
}
}
}
@@ -733,6 +735,7 @@ void Ship::hit(core::Entity *other)
// assissin killed an NPC
assassin->set_npckills(assassin->npckills() + 1);
}
+ assassin->set_dirty();
}
} else {