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/application.cc5
-rw-r--r--src/core/application.h1
-rw-r--r--src/core/gameinterface.cc8
-rw-r--r--src/core/net.h2
-rw-r--r--src/core/netconnection.cc43
-rw-r--r--src/core/netserver.cc36
-rw-r--r--src/core/netserver.h6
-rw-r--r--src/core/player.cc12
8 files changed, 95 insertions, 18 deletions
diff --git a/src/core/application.cc b/src/core/application.cc
index be86dd6..248512e 100644
--- a/src/core/application.cc
+++ b/src/core/application.cc
@@ -551,4 +551,9 @@ void Application::func_load(std::string const &args)
Application::instance()->load(name);
}
+void Application::func_info(std::string const &args)
+{
+ // FIXME connection info etc
+}
+
}
diff --git a/src/core/application.h b/src/core/application.h
index 7e41869..f335e26 100644
--- a/src/core/application.h
+++ b/src/core/application.h
@@ -121,6 +121,7 @@ private:
static void func_msg(std::string const &args);
static void func_load(std::string const &args);
static void func_rcon(std::string const &args);
+ static void func_info(std::string const &args);
};
/// pointer to the application
diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc
index 1695fb0..f658619 100644
--- a/src/core/gameinterface.cc
+++ b/src/core/gameinterface.cc
@@ -168,8 +168,12 @@ void GameInterface::list_players()
<< "id^B" << setw(5) << player->id() << " "
<< aux::pad_left(player->name(), 24) << "^N "
<< "ping^B" << setw(5) << player->ping() << "^N "
- << "level^B" << setw(3) << player->level() << "^N"
- << std::endl;
+ << "level^B" << setw(5) << player->level() << "^N";
+
+ if (player->zone())
+ con_print << aux::pad_left(player->zone()->name(), 24) << "^N";
+
+ con_print << std::endl;
count++;
}
diff --git a/src/core/net.h b/src/core/net.h
index f3774b5..887bf1b 100644
--- a/src/core/net.h
+++ b/src/core/net.h
@@ -11,7 +11,7 @@ namespace core
{
/// network protocol version
-const unsigned int PROTOCOLVERSION = 14;
+const unsigned int PROTOCOLVERSION = 15;
/// 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 eb9ad53..fc2b6bf 100644
--- a/src/core/netconnection.cc
+++ b/src/core/netconnection.cc
@@ -628,19 +628,16 @@ void NetConnection::parse_incoming_message(const std::string & message)
}
oldzone->content().clear();
}
- } else {
+
+ } else if (player_id != localplayer()->id()) {
+
// find player
Player *player = 0;
- if (player_id == connection()->localplayer()->id()) {
- // check localplayer
- player = connection()->localplayer();
- } else {
- // search other players
- for (GameInterface::Players::iterator it = game()->players().begin(); it != game()->players().end() && !player; it++) {
- if( (*it)->id() == player_id) {
- player = (*it);
- }
+ // search other players
+ for (GameInterface::Players::iterator it = game()->players().begin(); it != game()->players().end() && !player; it++) {
+ if( (*it)->id() == player_id) {
+ player = (*it);
}
}
@@ -650,8 +647,34 @@ void NetConnection::parse_incoming_message(const std::string & message)
}
player->receive_server_update(msgstream);
+ player->set_dirty(false);
+ }
+
+ } else if (command == "pid") {
+ con_debug << "Received player disconnect info" << std::endl;
+
+ int player_id;
+ if (!(msgstream >> player_id)) {
+ con_warn << "Received illegal player disconnect message!" << std::endl;
+ return;
+ }
+
+ // find player
+ if (player_id == connection()->localplayer()->id()) {
+ // ignore disconnect messages for local client
+ return;
}
+ // search other players
+ Player *player = 0;
+ for (GameInterface::Players::iterator it = game()->players().begin(); it != game()->players().end() && !player; it++) {
+ if( (*it)->id() == player_id) {
+ // TODO find player assets and set owner to 0
+ game()->players().erase(it);
+ return;
+ }
+ }
+
} else if (command == "sup") {
if (connection_state == Connected)
{
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index dd67809..6838e34 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -358,6 +358,13 @@ void NetServer::client_frame(NetClient *client, unsigned long timestamp)
}
}
}
+
+ // send updates for other players
+ for (GameInterface::Players::iterator it = server()->players().begin(); it != server()->players().end(); it++) {
+ if (((*it)->id() != client->player()->id()) && ((*it)->dirty())) {
+ send_player_update(client, (*it));
+ }
+ }
}
// run a network server frame, send updates to clients
@@ -380,13 +387,18 @@ void NetServer::frame(unsigned long timestamp)
// update player info always gets through
if (client->player()->dirty() || client->player()->zonechange()) {
-
send_player_update(client);
-
+ }
+ client->transmit();
+ }
+
+ // clear dirty state
+ for (Clients::iterator it = clients.begin(); it != clients.end(); it++) {
+ NetClient *client = *it;
+ if (client->player()->dirty() || client->player()->zonechange()) {
client->player()->set_dirty(false);
client->player()->set_zonechange(false);
}
- client->transmit();
}
}
@@ -508,6 +520,24 @@ void NetServer::send_player_update(NetClient *client)
client->send_raw(msg.str());
}
+// send a "pif" update player information to a single player
+void NetServer::send_player_update(NetClient *client, Player *player)
+{
+ std::ostringstream msg;
+ msg << "pif " << player->id() << " ";
+ client->player()->serialize_server_update(msg);
+ msg << '\n';
+ client->send_raw(msg.str());
+}
+
+// send a "pid" player disconnect information
+void NetServer::send_player_disconnect_info(NetClient *client, Player *player)
+{
+ std::ostringstream msg;
+ msg << "pid " << player->id() << '\n';
+ client->send_raw(msg.str());
+}
+
// parse incoming client messages
/**
diff --git a/src/core/netserver.h b/src/core/netserver.h
index 7b27554..9ef0f0d 100644
--- a/src/core/netserver.h
+++ b/src/core/netserver.h
@@ -86,6 +86,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 player disconnect information message
+ void send_player_disconnect_info(NetClient *client, Player *player);
+
/// set the error state
void abort();
diff --git a/src/core/player.cc b/src/core/player.cc
index ad6641e..a642371 100644
--- a/src/core/player.cc
+++ b/src/core/player.cc
@@ -41,6 +41,7 @@ void Player::clear()
player_control = 0;
player_ping = 0;
+ player_level = 1;
}
@@ -207,7 +208,10 @@ void Player::serialize_server_update(std::ostream & os) const
<< view_id << " "
<< control_id << " "
<< mission_id << " "
- << player_color << " ";
+ << player_color << " "
+ << player_credits << " "
+ << player_level << " "
+ << player_ping;
}
void Player::receive_server_update(std::istream &is)
@@ -217,7 +221,7 @@ void Player::receive_server_update(std::istream &is)
if (!player_id) {
player_id = id;
} else if (player_id != id) {
- con_warn << "received inconsistent player update for player " << id << "\n";
+ con_warn << "received inconsistent update for player " << id << "\n";
return;
}
@@ -254,6 +258,10 @@ void Player::receive_server_update(std::istream &is)
player_mission_target = 0;
}
is >> player_color;
+ is >> player_credits;
+ is >> player_level;
+
+ is >> player_ping;
/*
std::string n;