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/Makefile.am9
-rw-r--r--src/core/descriptions.cc245
-rw-r--r--src/core/descriptions.h128
-rw-r--r--src/core/entity.cc29
-rw-r--r--src/core/entity.h19
-rw-r--r--src/core/net.h2
-rw-r--r--src/core/netclient.cc21
-rw-r--r--src/core/netclient.h7
-rw-r--r--src/core/netconnection.cc37
-rw-r--r--src/core/netserver.cc25
-rw-r--r--src/core/parser.cc16
-rw-r--r--src/core/parser.h3
-rw-r--r--src/core/player.cc48
13 files changed, 524 insertions, 65 deletions
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index 61622e0..2c90dec 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -2,9 +2,9 @@ METASOURCES = AUTO
INCLUDES = -I$(top_srcdir)/src
libcore_la_SOURCES = application.cc clientstate.cc commandbuffer.cc core.cc \
- cvar.cc entity.cc func.cc gameconnection.cc gameinterface.cc gameserver.cc \
- module.cc netclient.cc netconnection.cc netplayer.cc netserver.cc parser.cc \
- player.cc stats.cc timer.cc zone.cc
+ cvar.cc descriptions.cc entity.cc func.cc gameconnection.cc gameinterface.cc \
+ gameserver.cc module.cc netclient.cc netconnection.cc netplayer.cc netserver.cc \
+ parser.cc player.cc stats.cc timer.cc zone.cc
libcore_la_LDFLAGS = -avoid-version -no-undefined
libcore_la_LIBADD = $(top_builddir)/src/model/libmodel.la \
$(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/math/libmath.la $(top_builddir)/src/sys/libsys.la \
@@ -14,5 +14,4 @@ noinst_LTLIBRARIES = libcore.la
noinst_HEADERS = application.h clientstate.h commandbuffer.h core.h cvar.h \
entity.h func.h gameconnection.h gameinterface.h gameserver.h message.h module.h \
net.h netclient.h netconnection.h netserver.h player.h range.h stats.h \
- timer.h parser.h
-
+ timer.h parser.h descriptions.h
diff --git a/src/core/descriptions.cc b/src/core/descriptions.cc
new file mode 100644
index 0000000..fe37d2c
--- /dev/null
+++ b/src/core/descriptions.cc
@@ -0,0 +1,245 @@
+/*
+ core/descriptions.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#include "core/descriptions.h"
+#include "auxiliary/functions.h"
+#include "sys/sys.h"
+
+namespace core {
+
+/* ---- class ButtonDescription ------------------------------------ */
+
+ButtonDescription::ButtonDescription()
+{
+ button_model = 0;
+ button_align = Center;
+}
+
+ButtonDescription::~ButtonDescription()
+{
+}
+
+void ButtonDescription::set_text(const std::string &text)
+{
+ button_text.assign(text);
+}
+
+void ButtonDescription::set_command(const std::string &command)
+{
+ button_command.assign(command);
+}
+
+void ButtonDescription::set_modelname(const std::string &modelname)
+{
+ button_modelname.assign(modelname);
+
+ button_model = model::Model::load(modelname);
+}
+
+void ButtonDescription::set_alignment(Align align)
+{
+ button_align = align;
+}
+
+/* ---- class MenuDescription -------------------------------------- */
+
+MenuDescription::MenuDescription()
+{
+}
+
+MenuDescription::~MenuDescription()
+{
+ for (Buttons::iterator it = buttons().begin(); it != buttons().end(); it++) {
+ delete (*it);
+ }
+
+ buttons().clear();
+}
+
+void MenuDescription::set_text(const std::string &text)
+{
+ menu_text.assign(text);
+}
+
+void MenuDescription::set_label(const std::string &label)
+{
+ menu_label.assign(label);
+}
+
+void MenuDescription::add_button(ButtonDescription *button)
+{
+ buttons().push_back(button);
+}
+
+/* ---- class Descriptions ----------------------------------------- */
+
+
+void Descriptions::serialize(MenuDescription *menu, std::ostream & os)
+{
+ os << menu->label() << " "
+ << "\"" << menu->text() << "\" "
+ << menu->buttons().size() << " ";
+
+ for (MenuDescription::Buttons::iterator it = menu-> buttons().begin(); it != menu->buttons().end(); it++) {
+ ButtonDescription *button = (*it);
+ os << "\"" << button->text() << "\" "
+ << button->alignment() << " "
+ << "\"" << button->command() << "\" "
+ << "\"" << button->modelname() << "\" ";
+ }
+}
+
+MenuDescription * Descriptions::receive(std::istream &is)
+{
+ MenuDescription *menu = new MenuDescription();
+
+ int a;
+ std::string n;
+ size_t nb;
+ char c;
+
+ // menu label
+ is >> n;
+ menu->set_label(n);
+
+ // menu text
+ n.clear();
+ while ( (is.get(c)) && (c != '"'));
+ while ( (is.get(c)) && (c != '"'))
+ n += c;
+
+ if (n.size())
+ menu->set_text(n);
+
+ // menu buttons
+ is >> nb;
+ for (size_t i=0; i < nb; i++) {
+ ButtonDescription *button = new ButtonDescription();
+ // button text
+ n.clear();
+ while ( (is.get(c)) && (c != '"'));
+ while ( (is.get(c)) && (c != '"'))
+ n += c;
+ if (n.size()) button->set_text(n);
+
+ // button alignment
+ a = ButtonDescription::Center;
+ is >> a;
+ if (a == ButtonDescription::Left)
+ button->set_alignment(ButtonDescription::Left);
+ else if (a == ButtonDescription::Right)
+ button->set_alignment(ButtonDescription::Right);
+ else
+ button->set_alignment(ButtonDescription::Center);
+
+ // button command
+ n.clear();
+ while ( (is.get(c)) && (c != '"'));
+ while ( (is.get(c)) && (c != '"'))
+ n += c;
+ if (n.size()) button->set_command(n);
+
+ // button modelname
+ n.clear();
+ while ( (is.get(c)) && (c != '"'));
+ while ( (is.get(c)) && (c != '"'))
+ n += c;
+ if (n.size()) button->set_modelname(n);
+
+ menu->add_button(button);
+ }
+
+ return menu;
+
+}
+
+bool Descriptions::load_entity_menus(core::Entity *entity, const std::string &menufilename)
+{
+ filesystem::IniFile inifile;
+ inifile.open(menufilename);
+
+ if (!inifile.is_open()) {
+ return false;
+ }
+
+ con_debug << " " << inifile.name() << std::endl;
+
+ std::string strval;
+ MenuDescription *menu = 0;
+ ButtonDescription *button = 0;
+
+ while (inifile.getline()) {
+
+ if (inifile.got_section()) {
+ if (inifile.got_section("menu")) {
+ menu = new MenuDescription;
+ entity->add_menu(menu);
+
+ } else if (inifile.got_section("button")) {
+ if (menu) {
+ button = new ButtonDescription();
+ menu->add_button(button);
+ }
+ } else {
+ inifile.unknown_section();
+ }
+
+ } else if (inifile.got_key()) {
+
+ if (inifile.in_section("menu")) {
+
+ if (inifile.got_key_string("label", strval)) {
+ aux::to_label(strval);
+ menu->set_label(strval);
+ } else if (inifile.got_key_string("text", strval)) {
+ aux::strip_quotes(strval);
+ menu->set_text(strval);
+ } else {
+ inifile.unkown_key();
+ }
+
+ } else if (inifile.in_section("button")) {
+
+ if (!button) {
+ continue;
+ } else if (inifile.got_key_string("text", strval)) {
+ aux::strip_quotes(strval);
+ button->set_text(strval);
+ } else if (inifile.got_key_string("command", strval)) {
+ for (size_t i =0; i <= strval.size(); i++) {
+ if (strval[i] == ',') strval[i] = ';';
+ }
+ aux::strip_quotes(strval);
+ button->set_command(strval);
+ } 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) {
+ button->set_alignment(ButtonDescription::Left);
+ } else if (strval.compare("center") == 0) {
+ button->set_alignment(ButtonDescription::Center);
+ } else if (strval.compare("right") == 0) {
+ button->set_alignment(ButtonDescription::Right);
+ } else {
+ inifile.unknown_value();
+ }
+ } else {
+ inifile.unkown_key();
+ }
+
+ }
+ }
+ }
+
+ inifile.close();
+ return true;
+}
+
+}
+
+
+
diff --git a/src/core/descriptions.h b/src/core/descriptions.h
new file mode 100644
index 0000000..345d354
--- /dev/null
+++ b/src/core/descriptions.h
@@ -0,0 +1,128 @@
+/*
+ core/descriptions.h
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_CORE_DESCRIPTIONS_H__
+#define __INCLUDED_CORE_DESCRIPTIONS_H__
+
+#include <string>
+#include <list>
+#include <iostream>
+
+namespace core {
+class ButtonDescription;
+class MenuDescription;
+}
+
+#include "core/entity.h"
+#include "model/model.h"
+#include "filesystem/inifile.h"
+
+namespace core {
+
+/// description of a menu button
+class ButtonDescription
+{
+public:
+ enum Align {Center=0, Left=1, Right=2};
+
+ ButtonDescription();
+ ~ButtonDescription();
+
+ /* -- inspectors ------------------------------------------- */
+
+ /// button text
+ inline const std::string & text() const { return button_text; }
+
+ /// button command
+ inline const std::string & command() const { 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; }
+
+ /* -- mutators -------------------------------------------- */
+
+ /// set button text
+ void set_text(const std::string &text);
+
+ /// set button command
+ void set_command(const std::string &command);
+
+ /// set button name
+ void set_modelname(const std::string &modelname);
+
+ /// set text alignment
+ void set_alignment(Align align);
+
+private:
+ std::string button_text;
+ std::string button_command;
+ std::string button_modelname;
+ Align button_align;
+
+ model::Model *button_model;
+};
+
+/// description of an entity menu
+class MenuDescription
+{
+public:
+ MenuDescription();
+ ~MenuDescription();
+
+ typedef std::list<ButtonDescription *> Buttons;
+
+ /* -- inspectors ------------------------------------------- */
+
+ /// menu label
+ inline const std::string & label() const { return menu_label; }
+
+ /// menu text
+ inline const std::string & text() const { return menu_text; }
+
+ /// menu buttons
+ inline Buttons &buttons() { return menu_buttons; }
+
+ /* -- mutators -------------------------------------------- */
+
+ /// set menu text
+ void set_text(const std::string &text);
+
+ /// set menu label
+ void set_label(const std::string &label);
+
+ /// add a menu button
+ void add_button(ButtonDescription *button);
+
+private:
+ std::string menu_label;
+ std::string menu_text;
+
+ Buttons menu_buttons;
+};
+
+
+/// descriptions loader class
+class Descriptions {
+public:
+ /// read entity menus from ini file
+ static bool load_entity_menus(core::Entity *entity, const std::string &menufilename);
+ /// serialize entity menus to a stream
+ static void serialize(MenuDescription *menu, std::ostream & os);
+ /// read entity menus from a stream
+ static MenuDescription * receive(std::istream &is);
+};
+
+}
+
+#endif // __INCLUDED_CORE_DESCRIPTIONS_H__
+
+
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 9bc3f3c..e2aac1c 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -133,6 +133,12 @@ Entity::Entity(std::istream & is)
Entity::~Entity()
{
+ // delete entity menus
+ for (Menus::iterator it = menus().begin(); it != menus().end(); it++) {
+ delete (*it);
+ }
+ menus().clear();
+
if (entity_clientstate) {
delete entity_clientstate;
entity_clientstate = 0;
@@ -346,6 +352,29 @@ void Entity::frame(float seconds)
{
}
+void Entity::add_menu(MenuDescription *menu)
+{
+ entity_menus.push_back(menu);
+}
+
+MenuDescription *Entity::find_menu(std::string const &label)
+{
+ for (Menus::iterator it = menus().begin(); it != menus().end(); it++) {
+ if (label.compare((*it)->label()) == 0)
+ return (*it);
+ }
+ return 0;
+}
+
+void Entity::remove_menu(std::string const &label)
+{
+ for (Menus::iterator it = menus().begin(); it != menus().end(); it++) {
+ if (label.compare((*it)->label()) == 0)
+ menus().erase(it);
+ return;
+ }
+}
+
/* ---- class EntityDynamic ---------------------------------------- */
EntityDynamic::EntityDynamic(unsigned int flags) :
diff --git a/src/core/entity.h b/src/core/entity.h
index 09b52a1..2e3b443 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -10,6 +10,7 @@
#include <iostream>
#include <string>
#include <map>
+#include <list>
#include "model/model.h"
#include "math/axis.h"
@@ -24,6 +25,7 @@ class EntityControlable;
}
#include "core/clientstate.h"
+#include "core/descriptions.h"
#include "core/player.h"
#include "core/zone.h"
@@ -46,6 +48,9 @@ public:
/// EntityDynamic event state classes
enum Event {Normal=0, NoPower=1, ImpulseInitiate=2, Impulse=3, JumpInitiate=4, Jump=5, Docked=6};
+ /// entity menus collection typedef
+ typedef std::list<MenuDescription *> Menus;
+
/// create a new entity and add it to the registry
Entity(unsigned int flags = 0);
@@ -117,6 +122,12 @@ public:
/// general visibility
inline bool visible() const { return entity_visible; }
+ /// entity menus
+ inline Menus &menus() { return entity_menus; }
+
+ /// find a menu
+ MenuDescription *find_menu(std::string const &label);
+
/*----- serializers ----------------------------------------------- */
/// serialize the entity to a stream
@@ -191,6 +202,12 @@ public:
/// unset a flag
void unset_flag(Flags flag);
+ /// add an entity menu
+ void add_menu(MenuDescription *menu);
+
+ /// remove an entity menu
+ void remove_menu(std::string const &label);
+
/// clear all update flags
virtual void clear_updates();
@@ -252,6 +269,8 @@ private:
model::Model *entity_model;
std::string entity_modelname;
+ Menus entity_menus;
+
static Registry entity_registry;
static size_t entity_nextid;
diff --git a/src/core/net.h b/src/core/net.h
index fe264e8..f3774b5 100644
--- a/src/core/net.h
+++ b/src/core/net.h
@@ -11,7 +11,7 @@ namespace core
{
/// network protocol version
-const unsigned int PROTOCOLVERSION = 13;
+const unsigned int PROTOCOLVERSION = 14;
/// maximum lenght of a (compressed) network message block
const unsigned int FRAMESIZE = 1152;
diff --git a/src/core/netclient.cc b/src/core/netclient.cc
index f75d8f3..253cf4f 100644
--- a/src/core/netclient.cc
+++ b/src/core/netclient.cc
@@ -18,19 +18,24 @@
namespace core
{
-NetClient::NetClient(std::string host, int port) :
+NetClient::NetClient(std::string host, int port, int fd) :
client_host(host)
{
client_error = true;
client_state = Connecting;
+ client_fd = fd;
+ client_host = host;
+ client_port = port;
client_player = new NetPlayer(this);
+ if (!fd) {
+ con_warn << "Network invalid client file descriptor!" << std::endl;
+ abort();
+ return;
+ }
con_print << host << ":" << port << " connected." << std::endl;
- client_host = host;
- client_port = port;
-
client_addr.sin_family = AF_INET;
client_addr.sin_port = htons(port);
client_addr.sin_addr.s_addr = inet_addr(host.c_str());
@@ -120,10 +125,14 @@ void NetClient::send_raw(std::string const &msg)
if (error())
return;
+ if ((sendq.size()) && (sendq.size() + msg.size() >= BLOCKSIZE - 16 )) {
+ transmit();
+ }
+
sendq.append(msg);
}
-void NetClient::transmit(int serverfd)
+void NetClient::transmit()
{
if (!sendq.size()) {
if (client_keepalive + NETTIMEOUT/2 < application()->time()) {
@@ -166,7 +175,7 @@ void NetClient::transmit(int serverfd)
size_t total_sent = 0;
while (total_sent < total_size && !error()) {
- ssize_t bytes_sent = ::sendto(serverfd, data, total_size - total_sent, 0,
+ ssize_t bytes_sent = ::sendto(fd(), data, total_size - total_sent, 0,
(struct sockaddr *)&client_addr, sizeof(client_addr));
if (bytes_sent < 0) {
diff --git a/src/core/netclient.h b/src/core/netclient.h
index 6e5bcf9..c0cdf8d 100644
--- a/src/core/netclient.h
+++ b/src/core/netclient.h
@@ -43,7 +43,7 @@ namespace core
class NetClient
{
public:
- NetClient(std::string host, int port);
+ NetClient(std::string host, int port, int fd);
~NetClient();
/// the remote hostname the client is connected to
@@ -68,7 +68,7 @@ public:
void retreive(std::string & message);
/// transmit messages in the send queue to the remote client
- void transmit(int serverfd);
+ void transmit();
inline bool error() const { return client_error; }
@@ -84,9 +84,12 @@ public:
float client_keepalive;
private:
+ inline int fd() const { return client_fd; }
+
struct sockaddr_in client_addr;
std::string client_host;
int client_port;
+ int client_fd;
bool client_error;
NetPlayer *client_player;
diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc
index ba23df3..0bb33db 100644
--- a/src/core/netconnection.cc
+++ b/src/core/netconnection.cc
@@ -515,7 +515,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
entity = new EntityGlobe(msgstream);
break;
default:
- con_warn << "Received create for unknown entity type " << type << std::endl;
+ con_warn << "Received create for unknown entity type " << type << "!" << std::endl;
return;
break;
}
@@ -527,6 +527,37 @@ void NetConnection::parse_incoming_message(const std::string & message)
game()->update_entity_clientstate(entity);
}
+ } else if (command == "menu") {
+
+ unsigned int id = 0;
+ if (msgstream >> id) {
+ if (!id) {
+ con_warn << "Received menu for NULL entity!" << std::endl;
+ return;
+ }
+
+ Entity *entity = Entity::find(id);
+ if (!entity) {
+ con_warn << "Received menu for unknown entity " << id << "!" << std::endl;
+ return;
+ }
+
+ MenuDescription *menu = Descriptions::receive(msgstream);
+ if (!menu->label().size()) {
+ con_warn << "Received menu without label for entity " << id << "!" << std::endl;
+ delete menu;
+ return;
+ }
+
+ // remove the menu if it already exists
+ entity->remove_menu(menu->label());
+
+ //con_debug << "receiving menu " << entity->label() << " " << menu->label() << std::endl;
+ entity->add_menu(menu);
+ } else {
+ con_warn << "Received illegal menu message!" << std::endl;
+ }
+
} else if (command.compare("zone") == 0) {
unsigned int id;
@@ -554,7 +585,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
int player_id;
if (!(msgstream >> player_id)) {
- con_warn << "Received illegal update player info for player!" << std::endl;
+ con_warn << "Received illegal player info message!" << std::endl;
return;
}
@@ -607,7 +638,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
Entity *entity = Entity::find(id);
if (!entity) {
// FIXME request entity from the server
- con_warn << "Update for unknown entity " << id << std::endl;
+ con_warn << "Update for unknown entity " << id << "!" << std::endl;
} else {
// FIXME check of the received update matches the actual entity
entity->receive_server_update(msgstream);
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index 3f0d2e8..b61ae1f 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -104,7 +104,7 @@ NetServer::~NetServer()
server()->player_disconnect((*it)->player());
(*it)->send_raw(netmsg);
- (*it)->transmit(fd());
+ (*it)->transmit();
delete (*it);
}
@@ -265,7 +265,7 @@ NetClient * NetServer::client_connect(std::string const host, int const port)
{
con_debug << "client_connect " << host << ":" << port << "\n";
- NetClient *client = new NetClient(host, port);
+ NetClient *client = new NetClient(host, port, fd());
if (client->error()) {
con_warn << client->host() << ":" << client->port() << " connection failed!\n";
delete(client);
@@ -283,7 +283,7 @@ void NetServer::client_initialize(NetClient *client) {
std::string welcome("^B");
welcome.append(Cvar::sv_name->str());
client->player()->send(welcome);
- client->transmit(fd());
+ client->transmit();
// send zones
for (Zone::Registry::iterator it = Zone::registry().begin(); it != Zone::registry().end(); it++) {
@@ -293,7 +293,7 @@ void NetServer::client_initialize(NetClient *client) {
// send connect completed
std::string connect("connect\n");
client->send_raw(connect);
- client->transmit(fd());
+ client->transmit();
// set client state to pending
client->client_state = NetClient::Pending;
@@ -373,7 +373,7 @@ void NetServer::frame(unsigned long timestamp)
for (Clients::iterator it = clients.begin(); it != clients.end(); it++) {
NetClient *client = *it;
- client->transmit(fd());
+ client->transmit();
if (client->state() == NetClient::Connected)
client_frame(client, timestamp);
@@ -386,7 +386,7 @@ void NetServer::frame(unsigned long timestamp)
client->player()->player_dirty = false;
client->player()->player_zonechange = false;
}
- client->transmit(fd());
+ client->transmit();
}
}
@@ -425,7 +425,7 @@ void NetServer::send_message(NetClient *client, const char *channel, std::string
void NetServer::send_disconnect(NetClient *client)
{
client->send_raw("disconnect\n");
- client->transmit(netserver_fd);
+ client->transmit();
client->abort();
}
@@ -450,6 +450,17 @@ void NetServer::send_entity_create(NetClient *client, Entity *entity)
entity->serialize_server_create(msg);
msg << '\n';
client->send_raw(msg.str());
+
+ // send entity menus
+ for (Entity::Menus::iterator it = entity->menus().begin(); it != entity->menus().end(); it++) {
+ msg.clear();
+ msg.str("");
+ msg << "menu " << entity->id() << " ";
+ Descriptions::serialize((*it), msg);
+ msg << '\n';
+ client->send_raw(msg.str());
+ // con_debug << "sending menu " << entity->label() << " " << (*it)->label() << std::endl;
+ }
}
}
diff --git a/src/core/parser.cc b/src/core/parser.cc
index 6af3903..1b35592 100644
--- a/src/core/parser.cc
+++ b/src/core/parser.cc
@@ -4,26 +4,12 @@
the terms of the GNU General Public License version 2
*/
-#include "core/parser.h"
#include "auxiliary/functions.h"
+#include "core/parser.h"
#include "sys/sys.h"
namespace core {
-bool Parser::read_entity_menu(core::Entity *entity, const std::string &menufilename)
-{
- filesystem::IniFile inifile;
- inifile.open(menufilename);
-
- if (!inifile.is_open()) {
- return false;
- }
-
- con_debug << " " << inifile.name() << std::endl;
-
- inifile.close();
- return true;
-}
bool Parser::got_entity_key(filesystem::IniFile &inifile, core::Entity *entity)
{
diff --git a/src/core/parser.h b/src/core/parser.h
index fec27c4..78a1087 100644
--- a/src/core/parser.h
+++ b/src/core/parser.h
@@ -18,9 +18,6 @@ class Parser {
public:
/// read default entity keys from an ini file
static bool got_entity_key(filesystem::IniFile &inifile, core::Entity *entity);
-
- /// read entity menus
- static bool read_entity_menu(core::Entity *entity, const std::string &menufilename);
};
}
diff --git a/src/core/player.cc b/src/core/player.cc
index ca985ab..f968fc3 100644
--- a/src/core/player.cc
+++ b/src/core/player.cc
@@ -133,7 +133,7 @@ void Player::serialize_client_update(std::ostream & os)
os << player_color << " "
<< player_color_second << " "
<< "\"" << player_name << "\" "
- << "\"" << player_rconpassword << "\"";
+ << "\"" << player_rconpassword << "\" ";
}
@@ -162,52 +162,53 @@ void Player::receive_client_update(std::istream &is)
void Player::serialize_server_update(std::ostream & os) const
{
- unsigned int zo = (zone() ? zone()->id() : 0);
- unsigned int co = (player_control ? player_control->id() : 0);
- unsigned int mission = (player_mission_target ? player_mission_target->id() : 0);
- unsigned int view = (player_view ? player_view->id() : 0);
+ unsigned int zone_id = (zone() ? zone()->id() : 0);
+ unsigned int view_id = (player_view ? player_view->id() : 0);
+ unsigned int control_id = (player_control ? player_control->id() : 0);
+ unsigned int mission_id = (player_mission_target ? player_mission_target->id() : 0);
- os << player_id << " " << zo << " " << view << " " << co << " " << mission << " " << player_color << " \"" << player_name << "\"";
+ os << player_id << " " << zone_id << " " << view_id << " " << control_id << " " << mission_id << " " << player_color << " ";
}
void Player::receive_server_update(std::istream &is)
{
is >> player_id;
- unsigned int zo = 0;
- is >> zo;
- set_zone(Zone::find(zo));
+ unsigned int zone_id = 0;
+ is >> zone_id;
+ set_zone(Zone::find(zone_id));
- unsigned int view = 0;
- is >> view;
- set_view(Entity::find(view));
+ unsigned int view_id = 0;
+ is >> view_id;
+ set_view(Entity::find(view_id));
- unsigned int co = 0;
- is >> co;
- if (co) {
- Entity *e = Entity::find(co);
+ unsigned int control_id = 0;
+ is >> control_id;
+ if (control_id) {
+ Entity *e = Entity::find(control_id);
if (e && e->type() == Entity::Controlable) {
player_control = static_cast<EntityControlable *>(e);
} else {
player_control = 0;
- con_warn << "control set to unknown entity " << co << "\n";
+ con_warn << "control set to unknown entity " << control_id << "\n";
}
} else {
player_control = 0;
}
- unsigned int mission = 0;
- is >> mission;
- if (mission) {
- player_mission_target = Entity::find(mission);
+ unsigned int mission_id = 0;
+ is >> mission_id;
+ if (mission_id) {
+ player_mission_target = Entity::find(mission_id);
if (!player_mission_target) {
- con_warn << "mission target set to unknown entity " << co << "\n";
+ con_warn << "mission target set to unknown entity " << mission_id << "\n";
}
} else {
player_mission_target = 0;
}
is >> player_color;
-
+
+ /*
std::string n;
char c;
while ( (is.get(c)) && (c != '"'));
@@ -216,6 +217,7 @@ void Player::receive_server_update(std::istream &is)
if (n.size())
player_name = n;
+ */
}
void Player::add_asset(EntityControlable *entity)